Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JUUID.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JUUID__
2 #define __JLANG__JUUID__
3 
4 #include <uuid/uuid.h>
5 #include <istream>
6 #include <ostream>
7 
8 #include "JLang/JComparable.hh"
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JLANG {}
15 namespace JPP { using namespace JLANG; }
16 
17 namespace JLANG {
18 
19  /**
20  * Simple wrapper for UUID.
21  */
22  struct JUUID :
23  public JComparable<JUUID>
24  {
25 
26  static const int BUFFER_SIZE = 36; //!< number of characters of uuid_t without trailing '\0'
27 
28 
29  /**
30  * Default constructor.
31  */
33  {
34  clear();
35  }
36 
37 
38  /**
39  * Copy constructor.
40  *
41  * \param object UUID
42  */
43  JUUID(const JUUID& object)
44  {
45  uuid_copy(this->uuid, object.uuid);
46  }
47 
48 
49  /**
50  * Randomizde this UUID.
51  *
52  * \return this UUID
53  */
54  const JUUID& operator()()
55  {
56  uuid_generate_random(this->uuid);
57 
58  return *this;
59  }
60 
61 
62  /**
63  * Generate random UUID.
64  *
65  * \return UUID
66  */
67  static inline const JUUID& rndm()
68  {
69  static JUUID id;
70 
71  return id();
72  }
73 
74 
75  /**
76  * Clear UUID.
77  *
78  * \return true if valid; else false
79  */
80  inline bool is_valid() const
81  {
82  return uuid_is_null(this->uuid) == 0;
83  }
84 
85 
86  /**
87  * Check validity.
88  */
89  inline void clear()
90  {
91  return uuid_clear(this->uuid);
92  }
93 
94 
95  /**
96  * Less than method.
97  *
98  * \param object UUID
99  * \return true if this UUID less than given UUID; else false
100  */
101  inline bool less(const JUUID& object) const
102  {
103  return uuid_compare(this->uuid, object.uuid) < 0;
104  }
105 
106 
107  /**
108  * Extract UUID.
109  *
110  * \param buffer UUID
111  * \return UUID
112  */
113  static JUUID valueOf(const std::string& buffer)
114  {
115  JUUID object;
116 
117  uuid_parse(buffer.c_str(), object.uuid);
118 
119  return object;
120  }
121 
122 
123  /**
124  * Read object identifier from input.
125  *
126  * \param in input stream
127  * \param object object identifier
128  * \return input stream
129  */
130  friend inline std::istream& operator>>(std::istream& in, JUUID& object)
131  {
132  char buffer[BUFFER_SIZE + 1];
133 
134  if (in.read(buffer, BUFFER_SIZE)) {
135 
136  buffer[BUFFER_SIZE] = '\0';
137 
138  uuid_parse(buffer, object.uuid);
139  }
140 
141  return in;
142  }
143 
144 
145  /**
146  * Write object identifier to output.
147  *
148  * \param out output stream
149  * \param object object identifier
150  * \return output stream
151  */
152  friend inline std::ostream& operator<<(std::ostream& out, const JUUID& object)
153  {
154  char buffer[BUFFER_SIZE + 1];
155 
156  uuid_unparse_lower(object.uuid, buffer);
157 
158  return out.write(buffer, BUFFER_SIZE);
159  }
160 
161  uuid_t uuid;
162  };
163 }
164 
165 #endif
void clear()
Check validity.
Definition: JUUID.hh:89
const JUUID & operator()()
Randomizde this UUID.
Definition: JUUID.hh:54
static const JUUID & rndm()
Generate random UUID.
Definition: JUUID.hh:67
JUUID()
Default constructor.
Definition: JUUID.hh:32
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
friend std::istream & operator>>(std::istream &in, JUUID &object)
Read object identifier from input.
Definition: JUUID.hh:130
bool is_valid() const
Clear UUID.
Definition: JUUID.hh:80
JUUID(const JUUID &object)
Copy constructor.
Definition: JUUID.hh:43
Simple wrapper for UUID.
Definition: JUUID.hh:22
static const int BUFFER_SIZE
number of characters of uuid_t without trailing &#39;\0&#39;
Definition: JUUID.hh:26
static JUUID valueOf(const std::string &buffer)
Extract UUID.
Definition: JUUID.hh:113
bool less(const JUUID &object) const
Less than method.
Definition: JUUID.hh:101
uuid_t uuid
Definition: JUUID.hh:161
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
friend std::ostream & operator<<(std::ostream &out, const JUUID &object)
Write object identifier to output.
Definition: JUUID.hh:152