GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
software.h
Go to the documentation of this file.
1 #ifndef SOFTWARE_H_
2 #define SOFTWARE_H_
3 
4 #include "interfaces.h"
5 #include "bytebuffer.h"
6 
7 #include <string>
8 #include <sstream>
9 #include <tuple>
10 
12 
15 class Software : public ISave, public IPrint
16 {
17 public:
18  Software(const std::string& name, int major, int minor, int revision);
19 
20  bool Save(ByteBuffer& bb) const override;
21  static Software Load(ByteBuffer& bb);
22 
24  bool operator== (const Software& other) const { return _name == other._name && _version == other._version; }
25  bool operator!= (const Software& other) const { return !(*this == other); }
26 
28  struct VersionData
29  {
31  VersionData(int major, int minor, int revision) : Major(major), Minor(minor), Revision(revision) {}
32 
34  bool operator== (const VersionData& other) const { return Major == other.Major && Minor == other.Minor && Revision == other.Revision; }
35 
36  int Major;
37  int Minor;
38  int Revision;
39 
41  std::string ToString() const
42  {
43  std::ostringstream ss("V");
44 
45  ss << Major << '.' << Minor << '.' << Revision;
46 
47  return ss.str();
48  }
49 
51  struct Hash
52  {
53  size_t operator()(const VersionData& ver) { return std::hash<std::string>()(ver.ToString()); }
54  };
55  };
56 
58  struct Hash
59  {
60  size_t operator()(const Software& sw);
61  };
62 
63  const std::string& GetName() const { return _name; }
64  const VersionData& GetVersion() const { return _version; }
65 
72  static std::tuple<bool, Software> ReadFromString(const std::string& name);
73 
74  void Print(std::ostream& os = std::cout) const override;
75  static void PrintHeader(std::ostream& os = std::cout);
76 
77 private:
78  Software() : _name(""), _version(0, 0, 0) {}
79 
80  std::string _name;
82 
84 };
85 
86 #endif // SOFTWARE_H_