xapian-core  1.4.21
uuids.h
Go to the documentation of this file.
1 
4 /* Copyright 2008 Lemur Consulting Ltd
5  * Copyright 2009,2010,2013,2016,2018 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_UUIDS_H
23 #define XAPIAN_INCLUDED_UUIDS_H
24 
25 #include <cstring>
26 #include <string>
27 
28 class Uuid {
29  public:
31  static constexpr unsigned BINARY_SIZE = 16;
32 
34  static constexpr unsigned STRING_SIZE = 36;
35 
36  Uuid() {}
37 
38  void generate();
39 
40  void parse(const char* in);
41 
42  void parse(const std::string& in) { return parse(in.data()); }
43 
44  // Not currently used.
45  void clear() {
46  std::memset(uuid_data, 0, BINARY_SIZE);
47  }
48 
49  // Not currently used.
50  bool is_null() const {
51  for (char ch : uuid_data) {
52  if (ch)
53  return false;
54  }
55  return true;
56  }
57 
58  std::string to_string() const;
59 
60  const char* data() const {
61  return reinterpret_cast<const char*>(uuid_data);
62  }
63 
64  void assign(const char* p) { std::memcpy(uuid_data, p, BINARY_SIZE); }
65 
66  private:
68  unsigned char uuid_data[BINARY_SIZE];
69 };
70 
71 #endif /* XAPIAN_INCLUDED_UUIDS_H */
void assign(const char *p)
Definition: uuids.h:64
unsigned char uuid_data[BINARY_SIZE]
The UUID data.
Definition: uuids.h:68
static constexpr unsigned STRING_SIZE
The size of a UUID string in bytes (not including trailing &#39;\0&#39;).
Definition: uuids.h:34
void clear()
Definition: uuids.h:45
std::string to_string() const
Definition: uuids.cc:120
void parse(const char *in)
Definition: uuids.cc:111
void parse(const std::string &in)
Definition: uuids.h:42
bool is_null() const
Definition: uuids.h:50
static constexpr unsigned BINARY_SIZE
The size of a UUID in bytes.
Definition: uuids.h:31
Definition: uuids.h:28
const char * data() const
Definition: uuids.h:60
Uuid()
Definition: uuids.h:36
void generate()
Definition: uuids.cc:63