Om
system.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_System_
16 
17  #include "om/language/system.hpp"
18 
19 #else
20 
21  #include "om/language/lexicon.hpp"
22  #include "om/language/operator.hpp"
23 
24  #ifndef Om_Macro_Precompilation_
25 
26  #include "boost/locale/generator.hpp"
27  #include "boost/locale/info.hpp"
28 
29  #endif
30 
31 // MARK: - Om::Language::System
32 
33  #define Type_ \
34  Om::Language::System
35 
36 // MARK: public (static)
37 
38 inline Type_ & Type_::Get() {
39  static System theSystem;
40  return theSystem;
41 }
42 
43 // MARK: public (non-static)
44 
45 inline Om::Language::Lexicon const & Type_::GetLexicon() const {
46  static Lexicon theLexicon;
47  if (
48  theLexicon.IsEmpty()
49  ) {
50  this->GiveElements(theLexicon);
51  }
52  return theLexicon;
53 }
54 
55 inline void Type_::GiveElements(Consumer & theConsumer) const {
56  if (
57  !this->IsEmpty()
58  ) {
59  Map::const_iterator const theEnd = this->thisMap.end();
60  for (
61  Map::const_iterator theCurrent = this->thisMap.begin();
62  ;
63  theConsumer.TakeElement(
64  Separator::GetLineSeparator()
65  )
66  ) {
67  assert(theEnd != theCurrent);
68  Operator theOperator(theCurrent->first);
69  theConsumer.TakeElement(theOperator);
70  if (theEnd == ++theCurrent) {
71  return;
72  }
73  }
74  }
75 }
76 
77 inline void Type_::Initialize(
78  char const theLocaleCodeUnitIterator[]
79 ) {
80  // Set the global locale.
81  {
82  boost::locale::generator theGenerator;
83  theGenerator.characters(boost::locale::char_facet);
84  std::locale::global(
85  theGenerator(theLocaleCodeUnitIterator)
86  );
87  assert(
88  std::use_facet<boost::locale::info>(
89  std::locale()
90  ).utf8()
91  );
92  }
93 
94  #ifndef NDEBUG
95  // Assert that the name keys are NFD-normalized.
96  {
97  Map::const_iterator const theEnd = this->thisMap.end();
98  for (
99  Map::const_iterator theCurrent = this->thisMap.begin();
100  theEnd != theCurrent;
101  ++theCurrent
102  ) {
103  assert(
104  boost::locale::normalize(
105  theCurrent->first,
106  boost::locale::norm_nfd
107  ) == theCurrent->first
108  );
109  }
110  }
111  #endif
112 }
113 
114 inline bool Type_::IsEmpty() const {
115  return this->thisMap.empty();
116 }
117 
118 inline bool Type_::Translate(
119  Evaluation & theEvaluation,
120  Operator const & theOperator
121 ) const {
122  Map::const_iterator theIterator(
123  this->thisMap.find(
124  theOperator.GetString()
125  )
126  );
127  if (
128  this->thisMap.end() == theIterator
129  ) {
130  return false;
131  }
132  assert(theIterator->second);
133  (*theIterator->second)(theEvaluation);
134  return true;
135 }
136 
137 // MARK: private (non-static)
138 
139 inline Type_::System():
140 thisMap() {}
141 
142  #undef Type_
143 
144 // MARK: - Om::Language::System::Definition
145 
146  #define Template_ \
147  template <typename ThisOperation>
148 
149  #define Type_ \
150  Om::Language::System::Definition<ThisOperation>
151 
152 // MARK: public (non-static)
153 
154 Template_
155 inline Type_::Definition() {
156  System::Get().thisMap[
157  ThisOperation::GetName()
158  ] = &ThisOperation::Give;
159 }
160 
161  #undef Type_
162  #undef Template_
163 
164 #endif
The Lexicon Program implementation.
Definition: lexicon.hpp:67
Om header file.
std::auto_ptr< TheGiveable > Give(TheGiveable &)
Calls Move on the object.
Om header file.
Om header file.