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 immutable_string s; \
19public: \
20 enc() {} \
21 explicit enc(std::string const & s); \
22 enc(enc<INNER> const & other); \
23 enc<INNER> const & \
24 operator=(enc<INNER> const & other); \
25 std::string const & operator()() const \
26 { return s.get(); } \
27 bool operator<(enc<INNER> const & x) const \
28 { return s.get() < x.s.get(); } \
29 bool operator==(enc<INNER> const & x) const \
30 { return s.get() == x.s.get(); } \
31 bool operator!=(enc<INNER> const & x) const \
32 { return s.get() != x.s.get(); } \
33 friend std::ostream & operator<< <>(std::ostream &, \
34 enc<INNER> const &); \
35};
36
37#define hh_ENCODING_NOVERIFY(enc) hh_ENCODING(enc)
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 dec() {} \
57 explicit dec(std::string const & s); \
58 explicit dec(INNER const & inner); \
59 dec(dec<INNER> const & other); \
60 bool operator<(dec<INNER> const & x) const \
61 { return i < x.i; } \
62 INNER const & inner() const \
63 { return i; } \
64 dec<INNER> const & \
65 operator=(dec<INNER> const & other); \
66 bool operator==(dec<INNER> const & x) const \
67 { return i == x.i; } \
68 bool operator!=(dec<INNER> const & x) const \
69 { return !(i == x.i); } \
70 friend std::ostream & operator<< <>(std::ostream &, \
71 dec<INNER> const &); \
72};
73
74
75#define hh_ATOMIC_HOOKED(ty, hook) \
76class ty; \
77 \
78std::ostream & operator<<(std::ostream &, ty const &); \
79 \
80template <> \
81void dump(ty const &, std::string &); \
82 \
83class ty { \
84 immutable_string s; \
85public: \
86 ty() {} \
87 explicit ty(std::string const & str); \
88 ty(ty const & other); \
89 ty const & operator=(ty const & other); \
90 std::string const & operator()() const \
91 { return s.get(); } \
92 bool operator<(ty const & x) const \
93 { return s.get() < x.s.get(); } \
94 bool operator==(ty const & x) const \
95 { return s.get() == x.s.get(); } \
96 bool operator!=(ty const & x) const \
97 { return s.get() != x.s.get(); } \
98 friend std::ostream & operator<<(std::ostream &, \
99 ty const &); \
100 hook \
101 struct symtab \
102 { \
103 symtab(); \
104 ~symtab(); \
105 }; \
106};
107
108#define hh_ATOMIC(ty) hh_ATOMIC_HOOKED(ty,)
109#define hh_ATOMIC_NOVERIFY(ty) hh_ATOMIC(ty)
110#define hh_ATOMIC_BINARY(ty) hh_ATOMIC(ty)
111
112//CC
113
114
115#define cc_ATOMIC(ty) \
116 \
117static symtab_impl ty ## _tab; \
118static size_t ty ## _tab_active = 0; \
119 \
120ty::ty(string const & str) : \
121 s((ty ## _tab_active > 0) \
122 ? (ty ## _tab.unique(str)) \
123 : str) \
124{ verify(*this); } \
125 \
126ty::ty(ty const & other) : s(other.s) {} \
127 \
128ty const & ty::operator=(ty const & other) \
129{ s = other.s; return *this; } \
130 \
131std::ostream & operator<<(std::ostream & o, \
132 ty const & a) \
133{ return (o << a.s.get()); } \
134 \
135template <> \
136void dump(ty const & obj, std::string & out) \
137{ out = obj(); } \
138 \
139ty::symtab::symtab() \
140{ ty ## _tab_active++; } \
141 \
142ty::symtab::~symtab() \
143{ \
144 I(ty ## _tab_active > 0); \
145 ty ## _tab_active--; \
146 if (ty ## _tab_active == 0) \
147 ty ## _tab.clear(); \
148}
149
150
151#define cc_ATOMIC_NOVERIFY(ty) \
152inline void verify(ty const &) {} \
153cc_ATOMIC(ty)
154
155
156#define cc_ATOMIC_BINARY(ty) \
157 \
158static symtab_impl ty ## _tab; \
159static size_t ty ## _tab_active = 0; \
160 \
161ty::ty(string const & str) : \
162 s((ty ## _tab_active > 0) \
163 ? (ty ## _tab.unique(str)) \
164 : str) \
165{ verify(*this); } \
166 \
167ty::ty(ty const & other) : s(other.s) {} \
168 \
169ty const & ty::operator=(ty const & other) \
170{ s = other.s; return *this; } \
171 \
172std::ostream & operator<<(std::ostream & o, \
173 ty const & a) \
174{ return (o << encode_hexenc(a.s.get())); } \
175 \
176ty::symtab::symtab() \
177{ ty ## _tab_active++; } \
178 \
179ty::symtab::~symtab() \
180{ \
181 I(ty ## _tab_active > 0); \
182 ty ## _tab_active--; \
183 if (ty ## _tab_active == 0) \
184 ty ## _tab.clear(); \
185}
186
187
188
189#define cc_ENCODING(enc) \
190 \
191template<typename INNER> \
192enc<INNER>::enc(string const & s) : s(s) \
193 { verify(*this); } \
194 \
195template<typename INNER> \
196enc<INNER>::enc(enc<INNER> const & other) \
197 : s(other.s) {} \
198 \
199template<typename INNER> \
200enc<INNER> const & \
201enc<INNER>::operator=(enc<INNER> const & other) \
202 { s = other.s; return *this; } \
203 \
204template <typename INNER> \
205std::ostream & operator<<(std::ostream & o, \
206 enc<INNER> const & e) \
207{ return (o << e.s.get()); } \
208 \
209template <typename INNER> \
210void dump(enc<INNER> const & obj, std::string & out) \
211{ out = obj(); }
212
213#define cc_ENCODING_NOVERIFY(enc) \
214template<typename INNER> \
215inline void verify(enc<INNER> const &) {} \
216cc_ENCODING(enc)
217
218
219
220#define cc_DECORATE(dec) \
221 \
222template<typename INNER> \
223dec<INNER>::dec(dec<INNER> const & other) \
224 : i(other.i) {} \
225 \
226template<typename INNER> \
227dec<INNER>::dec(std::string const & s) \
228 : i(s) { verify(i); } \
229 \
230template<typename INNER> \
231dec<INNER>::dec(INNER const & inner) \
232 : i(inner) {} \
233 \
234template<typename INNER> \
235dec<INNER> const & \
236dec<INNER>::operator=(dec<INNER> const & other) \
237 { i = other.i; return *this; } \
238 \
239template <typename INNER> \
240std::ostream & operator<<(std::ostream & o, \
241 dec<INNER> const & d) \
242{ return (o << d.i); } \
243 \
244template <typename INNER> \
245void dump(dec<INNER> const & obj, std::string & out) \
246{ dump(obj.inner(), out); }
247
248
249// Local Variables:
250// mode: C++
251// fill-column: 76
252// c-file-style: "gnu"
253// indent-tabs-mode: nil
254// End:
255// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
256

Archive Download this file

Branches

Tags

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