monotone

monotone Mtn Source Tree

Root/vocab.hh

1#ifndef __VOCAB_HH__
2#define __VOCAB_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <utility>
10#include <string>
11#include <iosfwd>
12
13#include <config.h>
14
15// the purpose of this file is to wrap things which are otherwise strings
16// in a bit of typesafety, set up enumerations and tuple-types, and
17// generally describe the "vocabulary" (nouns anyways) that modules in this
18// program use.
19
20#define ENCODING(enc) \
21 \
22template<typename INNER> \
23class enc; \
24 \
25template <typename INNER> \
26std::ostream & operator<<(std::ostream &, \
27 enc<INNER> const &); \
28 \
29template <typename INNER> \
30void dump(enc<INNER> const &, std::string &); \
31 \
32template<typename INNER> \
33class enc { \
34 INNER i; \
35public: \
36 bool ok; \
37 enc() : ok(false) {} \
38 enc(std::string const & s); \
39 enc(INNER const & inner); \
40 enc(enc<INNER> const & other); \
41 std::string const & operator()() const \
42 { return i(); } \
43 bool operator<(enc<INNER> const & x) const \
44 { return i() < x(); } \
45 enc<INNER> const & \
46 operator=(enc<INNER> const & other); \
47 bool operator==(enc<INNER> const & x) const \
48 { return i() == x(); } \
49 friend std::ostream & operator<< <>(std::ostream &, \
50 enc<INNER> const &); \
51};
52
53
54#define DECORATE(dec) \
55 \
56template<typename INNER> \
57class dec; \
58 \
59template <typename INNER> \
60std::ostream & operator<<(std::ostream &, \
61 dec<INNER> const &); \
62 \
63template <typename INNER> \
64void dump(dec<INNER> const &, std::string &); \
65 \
66template<typename INNER> \
67class dec { \
68 INNER i; \
69public: \
70 bool ok; \
71 dec() : ok(false) {} \
72 dec(INNER const & inner); \
73 dec(dec<INNER> const & other); \
74 bool operator<(dec<INNER> const & x) const \
75 { return i < x.i; } \
76 INNER const & inner() const \
77 { return i; } \
78 dec<INNER> const & \
79 operator=(dec<INNER> const & other); \
80 bool operator==(dec<INNER> const & x) const \
81 { return i == x.i; } \
82 friend std::ostream & operator<< <>(std::ostream &, \
83 dec<INNER> const &); \
84};
85
86
87#define ATOMIC(ty) \
88class ty { \
89 std::string s; \
90public: \
91 bool ok; \
92 ty() : s(""), ok(false) {} \
93 ty(std::string const & str); \
94 ty(ty const & other); \
95 std::string const & operator()() const \
96 { return s; } \
97 bool operator<(ty const & other) const \
98 { return s < other(); } \
99 ty const & operator=(ty const & other); \
100 bool operator==(ty const & other) const \
101 { return s == other(); } \
102 friend void verify(ty &); \
103 friend std::ostream & operator<<(std::ostream &, \
104 ty const &); \
105}; \
106std::ostream & operator<<(std::ostream &, ty const &); \
107void dump(ty const &, std::string &);
108
109#define ATOMIC_NOVERIFY(ty) \
110ATOMIC(ty) \
111inline void verify(ty &) {}
112
113#ifdef HAVE_EXTERN_TEMPLATE
114#define EXTERN extern
115#else
116#define EXTERN /* */
117#endif
118
119#include "vocab_terms.hh"
120
121#undef ATOMIC
122#undef ATOMIC_NOVERIFY
123#undef DECORATE
124#undef ENCODING
125
126// most of the time you want to use these typedefs and forget
127// about the stuff in vocab_terms.hh
128
129typedef revision< hexenc<id> > revision_id;
130typedef manifest< hexenc<id> > manifest_id;
131typedef file< hexenc<id> > file_id;
132typedef key< hexenc<id> > key_id;
133typedef epoch< hexenc<id> > epoch_id;
134typedef epoch< hexenc<data> > epoch_data;
135
136typedef revision< data > revision_data;
137typedef manifest< data > manifest_data;
138typedef file< data > file_data;
139
140typedef manifest< delta > manifest_delta;
141typedef file< delta > file_delta;
142
143typedef std::pair<var_domain, var_name> var_key;
144
145
146struct keypair
147{
148 base64<rsa_pub_key> pub;
149 base64<rsa_priv_key> priv;
150 keypair()
151 {}
152 keypair(base64<rsa_pub_key> const & a,
153 base64<rsa_priv_key> const & b)
154 : pub(a), priv(b)
155 {}
156};
157
158// fs::path is our "generic" safe path type, pointing potentially anywhere
159// in the filesystem. if you want to *define* or work with any of these you
160// need to include boost/filesystem/path.hpp.
161
162namespace boost { namespace filesystem { struct path; } }
163namespace fs = boost::filesystem;
164
165// kludge: certs are derived types. what else can we do?
166#ifndef __CERT_HH__
167#include "cert.hh"
168EXTERN template class revision<cert>;
169EXTERN template class manifest<cert>;
170#endif
171
172#undef EXTERN
173
174// diff type
175enum diff_type
176{
177 unified_diff,
178 context_diff,
179 external_diff
180};
181
182// do these belong here?
183inline bool
184null_id(file_id const & i)
185{
186 return i.inner()().empty();
187}
188
189inline bool
190null_id(manifest_id const & i)
191{
192 return i.inner()().empty();
193}
194
195inline bool
196null_id(revision_id const & i)
197{
198 return i.inner()().empty();
199}
200
201
202#endif // __VOCAB_HH__

Archive Download this file

Branches

Tags

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