DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
unique_identifier.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_UNIQUE_IDENTIFIER_H
13 #define DOCWIRE_UNIQUE_IDENTIFIER_H
14 
15 #include "core_export.h"
16 #include <atomic>
17 #include <compare>
18 #include <functional>
19 
20 namespace docwire
21 {
22 
30 class DOCWIRE_CORE_EXPORT unique_identifier
31 {
32 public:
36  unique_identifier() : m_id(m_counter++) {}
37 
42 
47 
54  std::strong_ordering operator<=>(const unique_identifier& other) const { return m_id <=> other.m_id; }
55 
56  bool operator==(const unique_identifier& other) const = default;
57 
58 private:
59  static std::atomic<size_t> m_counter;
60  size_t m_id;
61 
62  friend struct std::hash<unique_identifier>;
63 };
64 
65 } // namespace docwire
66 
67 namespace std {
68 template<>
69 struct hash<docwire::unique_identifier> {
70  size_t operator()(const docwire::unique_identifier& id) const {
71  return std::hash<size_t>{}(id.m_id);
72  }
73 };
74 } // namespace std
75 
76 #endif // DOCWIRE_UNIQUE_IDENTIFIER_H
The class represents unique (for a single program run) identifier of an object.
std::strong_ordering operator<=>(const unique_identifier &other) const
Compare two unique identifiers.
unique_identifier(const unique_identifier &)=default
Copy constructor.
unique_identifier & operator=(const unique_identifier &)=default
Copy assignment operator.
unique_identifier()
Default constructor that generates new unique identifier.
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19