GnuCash  4.9-162-g85be581e9+
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 extern "C" {
28 #include "guid.h"
29 }
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 (std::string const &);
53  static bool is_valid_guid (std::string const &);
54  std::string to_string () const noexcept;
55  auto begin () const noexcept -> decltype (implementation.begin ());
56  auto end () const noexcept -> decltype (implementation.end ());
57  bool operator < (GUID const &) noexcept;
58  friend bool operator == (GUID const &, GncGUID const &) noexcept;
59  friend bool operator != (GUID const &, GUID const &) noexcept;
60 };
61 
62 bool operator != (GUID const &, GUID const &) noexcept;
63 bool operator == (GUID const &, GncGUID const &) noexcept;
64 
65 
66 }
67 #endif
globally unique ID User API
The type used to store guids in C.
Definition: guid.h:75