Bayeux  3.4.1
Core Foundation library for SuperNEMO
version_id.h
Go to the documentation of this file.
1 
3 #ifndef DATATOOLS_VERSION_ID_H
4 #define DATATOOLS_VERSION_ID_H
5 
6 // Standard Library:
7 #include <iostream>
8 #include <string>
9 
10 // Third Party:
11 // - Boost:
12 #include <boost/cstdlib.hpp>
13 
14 // Datatools:
16 
17 namespace datatools {
18 
67  class version_id
69  {
70  public:
71  // TODO: could probably all be private or in an PImpl...
72  static const int32_t INVALID_NUMBER; // = -1;
73  static const char INVALID_SYMBOL; // = '?';
74  static const char NUMERIC_SEPARATOR; // = '.';
75  static const char TAG_SEPARATOR; // = '-';
76  static const int32_t MAX_RC_NUM; // = 9999;
77  static const int32_t ALPHA_NUM; // = -10003;
78  static const int32_t BETA_NUM; // = -10002;
79  static const int32_t RC_BASE_NUM; // = -10001;
80 
81  struct tags {
82  static const std::string & alpha();
83  static const std::string & beta();
84  static const std::string & release_candidate_prefix();
85  };
86 
87  public:
88 
89  // Constructors/Destructors
90  version_id();
91 
92  explicit version_id(const std::string & tag_);
93 
94  version_id(int major_, int minor_ = -1, int revision_ = -1,
95  const std::string & tag_ = "");
96 
97  // Global operations
98  bool is_valid() const;
99 
100  bool has_numbers_only() const;
101 
102  void reset();
103 
104  // Major number operations
105  bool has_major() const;
106 
107  bool has_major_only() const;
108 
109  int get_major() const;
110 
111  void set_major(int);
112 
113  // Minor number operations
114  bool has_minor() const;
115 
116  int get_minor() const;
117 
118  void set_minor(int);
119 
120  // Revision number operations
121  bool has_revision() const;
122 
123  int get_revision() const;
124 
125  void set_revision(int);
126 
127  // Tag number operations
128  bool has_tag() const;
129 
130  bool has_tag_number() const;
131 
132  bool has_tag_only() const;
133 
134  bool has_numeric_tag() const;
135 
136  bool has_special_tag() const;
137 
138  const std::string & get_tag() const;
139 
140  int get_tag_number() const;
141 
142  void set_tag(const std::string &);
143 
144  // Comparisons
145  bool equals(const version_id &, bool ignore_tag_ = false) const;
146 
147  bool operator==(const version_id &) const;
148 
149  int compare(const version_id &, bool major_only_ = false) const;
150 
151  bool matches(const std::string & version_rules_, bool major_only_ = false) const;
152 
153  // I/O and Conversions
154  friend std::ostream & operator<<(std::ostream &, const version_id &);
155 
156  friend std::istream & operator>>(std::istream &, version_id &);
157 
158  void to_string(std::string& format_) const;
159 
160  std::string to_string() const;
161 
162  bool from_string(const std::string &);
163 
164  void dump(std::ostream & out_ = std::clog,
165  const std::string & title_ = "",
166  const std::string & indent_ = "") const;
167 
168 
169  // These could/should be free functions
170  static int compare(const version_id & vid0_,
171  const version_id & vid1_,
172  bool major_only = false);
173 
174  static bool are_orderable(const version_id & vid0_,
175  const version_id & vid1_,
176  bool major_only_ = false);
177 
179  static const version_id & invalid();
180 
181  private:
182  int32_t _major_;
183  int32_t _minor_;
184  int32_t _revision_;
185  std::string _tag_;
186  int32_t _tag_number_;
187 
190 
191  };
192 
193 } // namespace datatools
194 
195 #endif // DATATOOLS_VERSION_ID_H
196 
197 // Local Variables: --
198 // mode: c++ --
199 // c-file-style: "gnu" --
200 // tab-width: 2 --
201 // End: --
bool has_tag_only() const
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
bool from_string(const std::string &)
bool has_tag_number() const
static const std::string & alpha()
bool has_numbers_only() const
#define DATATOOLS_SERIALIZATION_DECLARATION_ADVANCED(ClassName)
Definition: i_serializable.h:371
static const int32_t ALPHA_NUM
Definition: version_id.h:77
bool has_special_tag() const
int get_revision() const
static const std::string & beta()
bool has_minor() const
friend std::istream & operator>>(std::istream &, version_id &)
friend std::ostream & operator<<(std::ostream &, const version_id &)
static const version_id & invalid()
Return an invalid version identifier.
static const int32_t BETA_NUM
Definition: version_id.h:78
bool has_tag() const
static bool are_orderable(const version_id &vid0_, const version_id &vid1_, bool major_only_=false)
bool has_numeric_tag() const
static const char NUMERIC_SEPARATOR
Definition: version_id.h:74
void set_tag(const std::string &)
bool is_valid() const
int compare(const version_id &, bool major_only_=false) const
static const int32_t RC_BASE_NUM
Definition: version_id.h:79
static const int32_t MAX_RC_NUM
Definition: version_id.h:76
Definition: version_id.h:81
static const int32_t INVALID_NUMBER
Definition: version_id.h:72
bool has_revision() const
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
void dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="") const
static const char TAG_SEPARATOR
Definition: version_id.h:75
const std::string & get_tag() const
static const char INVALID_SYMBOL
Definition: version_id.h:73
bool equals(const version_id &, bool ignore_tag_=false) const
static const std::string & release_candidate_prefix()
bool has_major_only() const
A class representing a version ID :
Definition: version_id.h:67
std::string to_string() const
int get_tag_number() const
bool matches(const std::string &version_rules_, bool major_only_=false) const
bool operator==(const version_id &) const
bool has_major() const