GnuCash  5.6-150-g038405b370+
guid.hpp
1 /********************************************************************
2  * guid.hpp - GncGUID struct definition. *
3  * Copyright 2016 Aaron Laws *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA gnu@gnu.org *
20  * *
21  *******************************************************************/
22 #ifndef GUID_HPP_HEADER
23 #define GUID_HPP_HEADER
24 
25 #include <boost/uuid/uuid.hpp>
26 #include <stdexcept>
27 #include <string>
28 
29 #include "guid.h"
30 
31 namespace gnc {
32 struct guid_syntax_exception : public std::invalid_argument
33 {
34  guid_syntax_exception () noexcept;
35 };
36 
37 struct GUID
38 {
39  private:
40  boost::uuids::uuid implementation;
41 
42  public:
43  GUID (boost::uuids::uuid const &) noexcept;
44  GUID (GncGUID const &) noexcept;
45  GUID (GUID const &) noexcept = default;
46  GUID () noexcept = default;
47  GUID & operator = (GUID &&) noexcept;
48 
49  operator GncGUID () const noexcept;
50  static GUID create_random () noexcept;
51  static GUID const & null_guid () noexcept;
52  static GUID from_string (const char*);
53  static GUID from_string (std::string const& s) { return from_string (s.c_str()); };
54  static bool is_valid_guid (const char*);
55  static bool is_valid_guid (std::string const &s) { return is_valid_guid (s.c_str()); };
56  std::string to_string () const noexcept;
57  auto begin () const noexcept -> decltype (implementation.begin ());
58  auto end () const noexcept -> decltype (implementation.end ());
59  bool operator < (GUID const &) noexcept;
60  friend bool operator == (GUID const &, GncGUID const &) noexcept;
61  friend bool operator != (GUID const &, GUID const &) noexcept;
62 };
63 
64 bool operator != (GUID const &, GUID const &) noexcept;
65 bool operator == (GUID const &, GncGUID const &) noexcept;
66 
67 
68 } // namespace gnc
69 
70 bool operator== (const GncGUID&, const GncGUID&);
71 #endif
globally unique ID User API
The type used to store guids in C.
Definition: guid.h:75