monotone

monotone Mtn Source Tree

Root/vocab_macros.hh

1
2//HH
3
4#define hh_ENCODING(enc) \
5 \
6template<typename INNER> \
7class enc; \
8 \
9template <typename INNER> \
10std::ostream & operator<<(std::ostream &, \
11 enc<INNER> const &); \
12 \
13template <typename INNER> \
14void dump(enc<INNER> const &, std::string &); \
15 \
16template<typename INNER> \
17class enc { \
18 INNER i; \
19public: \
20 bool ok; \
21 enc() : ok(false) {} \
22 explicit enc(std::string const & s); \
23 explicit enc(INNER const & inner); \
24 enc(enc<INNER> const & other); \
25 std::string const & operator()() const \
26 { return i(); } \
27 bool operator<(enc<INNER> const & x) const \
28 { return i() < x(); } \
29 enc<INNER> const & \
30 operator=(enc<INNER> const & other); \
31 bool operator==(enc<INNER> const & x) const \
32 { return i() == x(); } \
33 bool operator!=(enc<INNER> const & x) const \
34 { return !(i() == x()); } \
35 friend std::ostream & operator<< <>(std::ostream &, \
36 enc<INNER> const &); \
37};
38
39
40#define hh_DECORATE(dec) \
41 \
42template<typename INNER> \
43class dec; \
44 \
45template <typename INNER> \
46std::ostream & operator<<(std::ostream &, \
47 dec<INNER> const &); \
48 \
49template <typename INNER> \
50void dump(dec<INNER> const &, std::string &); \
51 \
52template<typename INNER> \
53class dec { \
54 INNER i; \
55public: \
56 bool ok; \
57 dec() : ok(false) {} \
58 explicit dec(std::string const & s); \
59 explicit dec(INNER const & inner); \
60 dec(dec<INNER> const & other); \
61 bool operator<(dec<INNER> const & x) const \
62 { return i < x.i; } \
63 INNER const & inner() const \
64 { return i; } \
65 dec<INNER> const & \
66 operator=(dec<INNER> const & other); \
67 bool operator==(dec<INNER> const & x) const \
68 { return i == x.i; } \
69 bool operator!=(dec<INNER> const & x) const \
70 { return !(i == x.i); } \
71 friend std::ostream & operator<< <>(std::ostream &, \
72 dec<INNER> const &); \
73};
74
75
76#define hh_ATOMIC(ty) \
77class ty { \
78 immutable_string s; \
79public: \
80 bool ok; \
81 ty() : ok(false) {} \
82 explicit ty(std::string const & str); \
83 ty(ty const & other); \
84 std::string const & operator()() const \
85 { return s.get(); } \
86 bool operator<(ty const & other) const \
87 { return s.get() < other(); } \
88 ty const & operator=(ty const & other); \
89 bool operator==(ty const & other) const \
90 { return s.get() == other(); } \
91 bool operator!=(ty const & other) const \
92 { return s.get() != other(); } \
93 friend void verify(ty &); \
94 friend void verify_full(ty &); \
95 friend std::ostream & operator<<(std::ostream &, \
96 ty const &); \
97 struct symtab \
98 { \
99 symtab(); \
100 ~symtab(); \
101 }; \
102}; \
103std::ostream & operator<<(std::ostream &, ty const &); \
104template <> \
105void dump(ty const &, std::string &); \
106inline void verify(ty &t) \
107 { if(!t.ok) verify_full(t); };
108
109#define hh_ATOMIC_NOVERIFY(ty) \
110ATOMIC(ty) \
111inline void verify_full(ty &) {}
112
113
114//CC
115
116
117#define cc_ATOMIC(ty) \
118 \
119static symtab_impl ty ## _tab; \
120static size_t ty ## _tab_active = 0; \
121 \
122ty::ty(string const & str) : \
123 s((ty ## _tab_active > 0) \
124 ? (ty ## _tab.unique(str)) \
125 : str), \
126 ok(false) \
127{ verify(*this); } \
128 \
129ty::ty(ty const & other) : \
130 s(other.s), ok(other.ok) \
131{ verify(*this); } \
132 \
133ty const & ty::operator=(ty const & other) \
134{ s = other.s; ok = other.ok; \
135 verify(*this); return *this; } \
136 \
137 std::ostream & operator<<(std::ostream & o,\
138 ty const & a) \
139 { return (o << a.s.get()); } \
140 \
141template <> \
142void dump(ty const & obj, std::string & out) \
143{ out = obj(); } \
144 \
145ty::symtab::symtab() \
146{ ty ## _tab_active++; } \
147 \
148ty::symtab::~symtab() \
149{ \
150 I(ty ## _tab_active > 0); \
151 ty ## _tab_active--; \
152 if (ty ## _tab_active == 0) \
153 ty ## _tab.clear(); \
154}
155
156
157#define cc_ATOMIC_NOVERIFY(ty) cc_ATOMIC(ty)
158
159
160
161#define cc_ENCODING(enc) \
162 \
163template<typename INNER> \
164enc<INNER>::enc(string const & s) : i(s), ok(false) \
165 { verify(*this); } \
166 \
167template<typename INNER> \
168enc<INNER>::enc(enc<INNER> const & other) \
169 : i(other.i), ok(other.ok) { verify(*this); } \
170 \
171template<typename INNER> \
172enc<INNER>::enc(INNER const & inner) : \
173 i(inner), ok(false) \
174 { verify(*this); } \
175 \
176template<typename INNER> \
177enc<INNER> const & \
178enc<INNER>::operator=(enc<INNER> const & other) \
179 { i = other.i; ok = other.ok; \
180 verify(*this); return *this;} \
181 \
182template <typename INNER> \
183std::ostream & operator<<(std::ostream & o, \
184 enc<INNER> const & e) \
185{ return (o << e.i); } \
186 \
187template <typename INNER> \
188void dump(enc<INNER> const & obj, std::string & out) \
189{ out = obj(); }
190
191
192#define cc_DECORATE(dec) \
193 \
194template<typename INNER> \
195dec<INNER>::dec(dec<INNER> const & other) \
196 : i(other.i), ok(other.ok) { verify(*this); } \
197 \
198template<typename INNER> \
199dec<INNER>::dec(std::string const & s) \
200 : i(s), ok(false) { verify(*this); } \
201 \
202template<typename INNER> \
203dec<INNER>::dec(INNER const & inner) : \
204 i(inner), ok(false) \
205 { verify(*this); } \
206 \
207template<typename INNER> \
208dec<INNER> const & \
209dec<INNER>::operator=(dec<INNER> const & other) \
210 { i = other.i; ok = other.ok; \
211 verify(*this); return *this;} \
212 \
213template <typename INNER> \
214std::ostream & operator<<(std::ostream & o, \
215 dec<INNER> const & d) \
216{ return (o << d.i); } \
217 \
218template <typename INNER> \
219void dump(dec<INNER> const & obj, std::string & out) \
220{ dump(obj.inner(), out); }
221
222
223
224
225
226// Local Variables:
227// mode: C++
228// fill-column: 76
229// c-file-style: "gnu"
230// indent-tabs-mode: nil
231// End:
232// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
233

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status