otsdaq  v2_05_02_indev
TableVersion.h
1 #ifndef _ots_TableVersion_h_
2 #define _ots_TableVersion_h_
3 
4 #include <ostream>
5 
6 namespace ots
7 {
8 // TableVersion is the type used for version associated with a configuration table
9 //(whereas TableGroupKey is the type used for versions association with global
10 // configurations)
11 //
12 // Designed so that version type could be changed easily, e.g. to string
14 {
15  public:
16  static const unsigned int INVALID;
17  static const unsigned int DEFAULT;
18  static const unsigned int SCRATCH;
19 
20  explicit TableVersion(unsigned int version = INVALID);
21  explicit TableVersion(char* const& versionStr);
22  explicit TableVersion(const std::string& versionStr);
23  virtual ~TableVersion(void);
24 
25  unsigned int version(void) const;
26  bool isTemporaryVersion(void) const;
27  bool isScratchVersion(void) const;
28  bool isMockupVersion(void) const;
29  bool isInvalid(void) const;
30  std::string toString(void) const;
31 
32  // Operators
33  TableVersion& operator=(const unsigned int version);
34  bool operator==(unsigned int version) const;
35  bool operator==(const TableVersion& version) const;
36  bool operator!=(unsigned int version) const;
37  bool operator!=(const TableVersion& version) const;
38  bool operator<(const TableVersion& version) const;
39  bool operator>(const TableVersion& version) const;
40  bool operator<=(const TableVersion& version) const { return !operator>(version); }
41  bool operator>=(const TableVersion& version) const { return !operator<(version); }
42 
43  friend std::ostream& operator<<(std::ostream& out, const TableVersion& version)
44  {
45  if(version.isScratchVersion())
46  out << "ScratchVersion";
47  else if(version.isMockupVersion())
48  out << "Mock-up";
49  else if(version.isInvalid())
50  out << "InvalidVersion";
51  else
52  out << version.toString();
53  return out;
54  }
55 
56  static TableVersion getNextVersion(const TableVersion& version = TableVersion());
57  static TableVersion getNextTemporaryVersion(const TableVersion& version = TableVersion());
58 
59  private:
60  enum
61  {
62  NUM_OF_TEMP_VERSIONS = 10000
63  };
64 
65  unsigned int version_;
66  std::string versionString_;
67 };
68 } // namespace ots
69 #endif