Om
default_atom.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_DefaultAtom_
16 
18 
19 #else
20 
22 
23  #ifndef Om_Macro_Precompilation_
24 
25  #include "boost/locale/conversion.hpp"
26 
27  #endif
28 
29 // MARK: - Om::Language::DefaultAtom
30 
31  #define Template_ \
32  template <typename ThisImplementation>
33 
34  #define Type_ \
35  Om::Language::DefaultAtom<ThisImplementation>
36 
37 // MARK: public (non-static)
38 
39 Template_
40 inline Type_::~DefaultAtom() {}
41 
42 Template_
43 inline bool Type_::operator <(DefaultAtom const & theAtom) {
44  return this->thisString < theAtom.thisString;
45 }
46 
47 Template_
48 inline void Type_::Clear() {
49  this->thisString.clear();
50 }
51 
52 Template_
53 inline bool Type_::Equals(DefaultAtom const & theAtom) const {
54  return this->thisString == theAtom.thisString;
55 }
56 
57 Template_
58 inline bool Type_::Equals(ThisImplementation const & theAtom) const {
59  return this->Equals(
60  static_cast<DefaultAtom const &>(theAtom)
61  );
62 }
63 
64 Template_
65 inline std::auto_ptr<
67 > Type_::GetElementRange() {
68  if (
69  this->IsEmpty()
70  ) {
71  return std::auto_ptr<
73  >(
75  );
76  }
77  return this->DefaultElement<
78  ThisImplementation,
79  Atom
80  >::GetElementRange();
81 }
82 
83 Template_
84 inline std::auto_ptr<
86 > Type_::GetElementRange() const {
87  if (
88  this->IsEmpty()
89  ) {
90  return std::auto_ptr<
92  >(
94  );
95  }
96  return this->DefaultElement<
97  ThisImplementation,
98  Atom
99  >::GetElementRange();
100 }
101 
102 Template_
103 inline std::string const & Type_::GetString() const {
104  return this->thisString;
105 }
106 
107 Template_
108 inline bool Type_::IsEmpty() const {
109  return this->thisString.empty();
110 }
111 
112 Template_
113 inline bool Type_::Merge(ThisImplementation & theAtom) {
114  this->TakeElement(theAtom);
115  return true;
116 }
117 
118 Template_
119 inline bool Type_::Merge(ThisImplementation const & theAtom) {
120  this->TakeElement(theAtom);
121  return true;
122 }
123 
124 Template_
125 inline void Type_::Swap(ThisImplementation & theAtom) {
126  this->thisString.swap(theAtom.thisString);
127 }
128 
129 // MARK: protected (non-static)
130 
131 Template_
132 inline Type_::DefaultAtom():
133 thisString() {}
134 
135 Template_
136 inline Type_::DefaultAtom(
137  char const theCodeUnitIterator[]
138 ):
139 thisString(theCodeUnitIterator) {
140  assert(
141  theCodeUnitIterator &&
142  "The argument cannot be null."
143  );
144  assert(
145  boost::locale::normalize(
146  this->thisString,
147  boost::locale::norm_nfd
148  ) == this->thisString &&
149  "The string must be NFD-normalized."
150  );
151 }
152 
153 Template_
154 inline Type_::DefaultAtom(char const theCodeUnit):
155 thisString(
156  1,
157  theCodeUnit
158 ) {
159  assert(
160  boost::locale::normalize(
161  this->thisString,
162  boost::locale::norm_nfd
163  ) == this->thisString &&
164  "The code unit must be NFD-normalized."
165  );
166 }
167 
168  #undef Type_
169  #undef Template_
170 
171 // MARK: - Om::Language::
172 
173  #define Template_ \
174  template <typename TheImplementation>
175 
176  #define Type_ \
177  Om::Language::DefaultAtom<TheImplementation>
178 
179 Template_
180 inline bool Om::Language::operator ==(
181  Type_ const & theFirst,
182  Type_ const & theSecond
183 ) {
184  return theFirst.Equals(theSecond);
185 }
186 
187 Template_
188 inline bool Om::Language::operator !=(
189  Type_ const & theFirst,
190  Type_ const & theSecond
191 ) {
192  return !theFirst.Equals(theSecond);
193 }
194 
195  #undef Type_
196  #undef Template_
197 
198 #endif
An empty Source.
Any object that items can be pulled from.
Definition: source.hpp:31
Om header file.
Om header file.
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)