u5e
UnicodeTextC++Library
codepoint.hpp
1 
2 #ifndef INCLUDED_U5E_CODEPOINT_HPP
3 #define INCLUDED_U5E_CODEPOINT_HPP
4 
5 #include <u5e/codepoint_traits.hpp>
6 
7 namespace u5e {
8  /**
9  * \brief Native representation of a codepoint
10  *
11  * Explicity class in order to hijack overloads, such that we only
12  * build codepoints out of known encodings and we only write to
13  * encodings out of known codepoints.
14  */
15  class codepoint {
16  public:
17  /**
18  * A codepoint has an integer value type.
19  */
21 
22  /**
23  * Default constructor, starts as NULL.
24  */
25  constexpr codepoint() : value(0) { };
26 
27  /**
28  * Implicit constructor from an integer value.
29  */
30  constexpr codepoint(int32_t v) : value(v) { };
31 
32  /**
33  * Copy constructor.
34  */
35  constexpr codepoint(const codepoint& x) = default;
36 
37  /**
38  * Assignment operator from another codepoint.
39  */
40  constexpr codepoint& operator=(const codepoint& x) = default;
41 
42  /**
43  * Assignment operator from an int.
44  */
45  constexpr codepoint& operator=(int c) { value = c; return *this; };
46 
47  /**
48  * Override int operator to return the codepoint value.
49  */
50  constexpr operator int() const { return value; };
51  };
52 
53  /**
54  * Compare two codepoints by comparing their values.
55  */
56  constexpr bool operator==(const codepoint& a, const codepoint& b) { return a.value == b.value; };
57 
58  //@{
59  /**
60  * Compare an int to a codepoint by comparing the codepoint's value
61  * with the integer.
62  */
63  constexpr bool operator==(const codepoint_traits::int_type a, const codepoint& b) { return a == b.value; };
64  constexpr bool operator==(const codepoint& a, const codepoint_traits::int_type b) { return a.value == b; };
65  //@}
66 }
67 
68 #endif
constexpr codepoint & operator=(int c)
Definition: codepoint.hpp:45
constexpr operator int() const
Definition: codepoint.hpp:50
main u5e namespace
Native representation of a codepoint.
Definition: codepoint.hpp:15
constexpr codepoint(const codepoint &x)=default
constexpr codepoint & operator=(const codepoint &x)=default
constexpr bool operator==(const codepoint &a, const codepoint_traits::int_type b)
Definition: codepoint.hpp:64
constexpr codepoint()
Definition: codepoint.hpp:25
constexpr bool operator==(const codepoint &a, const codepoint &b)
Definition: codepoint.hpp:56
constexpr codepoint(int32_t v)
Definition: codepoint.hpp:30
codepoint_traits::int_type value
Definition: codepoint.hpp:20
constexpr bool operator==(const codepoint_traits::int_type a, const codepoint &b)
Definition: codepoint.hpp:63
Type information for codepoint.