monotone

monotone Mtn Source Tree

Root/vocab.hh

1#ifndef __VOCAB_HH__
2#define __VOCAB_HH__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13#include <utility>
14#include <boost/shared_ptr.hpp>
15
16// the purpose of this file is to wrap things which are otherwise strings
17// in a bit of typesafety, set up enumerations and tuple-types, and
18// generally describe the "vocabulary" (nouns anyways) that modules in this
19// program use.
20
21// For some reason, shared_ptr copy is about a hundred times faster
22// than string refcopy on my system (g++ 4). This only happens because
23// we tell Boost not to worry about threads... but I don't recognize any
24// thread stuff in the string headers.
25namespace
26{
27 std::string empty;
28}
29
30class immutable_string
31{
32 boost::shared_ptr<std::string> _rep;
33
34public:
35 immutable_string()
36 {}
37 immutable_string(std::string const & s)
38 : _rep(new std::string(s))
39 {}
40
41 std::string const & get() const
42 {
43 if (_rep)
44 return *_rep;
45 else
46 return empty;
47 }
48};
49
50
51
52
53#include "vocab_macros.hh"
54#define ENCODING(enc) hh_ENCODING(enc)
55#define DECORATE(dec) hh_DECORATE(dec)
56#define ATOMIC(ty) hh_ATOMIC(ty)
57#define ATOMIC_NOVERIFY(ty) hh_ATOMIC_NOVERIFY(ty)
58
59inline bool is_xdigit(char x)
60{
61 return ((x >= '0' && x <= '9')
62 || (x >= 'a' && x <= 'f'));
63}
64
65inline bool is_alpha(char x)
66{
67 return ((x >= 'a' && x <= 'z')
68 || (x >= 'A' && x <= 'Z'));
69}
70
71inline bool is_alnum(char x)
72{
73 return ((x >= '0' && x <= '9')
74 || (x >= 'a' && x <= 'z')
75 || (x >= 'A' && x <= 'Z'));
76}
77
78inline bool is_space(char x)
79{
80 return (x == ' ')
81 || (x == '\n')
82 || (x == '\t')
83 || (x == '\r')
84 || (x == '\v')
85 || (x == '\f');
86}
87
88
89#ifdef HAVE_EXTERN_TEMPLATE
90#define EXTERN extern
91#else
92#define EXTERN /* */
93#endif
94
95#include "vocab_terms.hh"
96
97#undef ATOMIC
98#undef ATOMIC_NOVERIFY
99#undef DECORATE
100#undef ENCODING
101
102// most of the time you want to use these typedefs and forget
103// about the stuff in vocab_terms.hh
104
105typedef revision< hexenc<id> > revision_id;
106typedef manifest< hexenc<id> > manifest_id;
107typedef file< hexenc<id> > file_id;
108typedef key< hexenc<id> > key_id;
109typedef epoch< hexenc<id> > epoch_id;
110typedef epoch< hexenc<data> > epoch_data;
111
112typedef revision< data > revision_data;
113typedef roster< data > roster_data;
114typedef manifest< data > manifest_data;
115typedef file< data > file_data;
116
117typedef roster< delta > roster_delta;
118typedef manifest< delta > manifest_delta;
119typedef file< delta > file_delta;
120
121typedef std::pair<var_domain, var_name> var_key;
122
123
124struct keypair
125{
126 base64<rsa_pub_key> pub;
127 base64<rsa_priv_key> priv;
128 keypair()
129 {}
130 keypair(base64<rsa_pub_key> const & a,
131 base64<rsa_priv_key> const & b)
132 : pub(a), priv(b)
133 {}
134};
135
136// fs::path is our "generic" safe path type, pointing potentially anywhere
137// in the filesystem. if you want to *define* or work with any of these you
138// need to include boost/filesystem/path.hpp.
139
140//namespace boost { namespace filesystem { class path; } }
141//namespace fs = boost::filesystem;
142
143// diff type
144enum diff_type
145{
146 unified_diff,
147 context_diff,
148 external_diff
149};
150
151// do these belong here?
152inline bool
153null_id(hexenc<id> const & i)
154{
155 return i().empty();
156}
157
158inline bool
159null_id(file_id const & i)
160{
161 return i.inner()().empty();
162}
163
164inline bool
165null_id(manifest_id const & i)
166{
167 return i.inner()().empty();
168}
169
170inline bool
171null_id(revision_id const & i)
172{
173 return i.inner()().empty();
174}
175
176
177hexenc<id>
178fake_id();
179
180// Local Variables:
181// mode: C++
182// fill-column: 76
183// c-file-style: "gnu"
184// indent-tabs-mode: nil
185// End:
186// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
187
188#endif // __VOCAB_HH__

Archive Download this file

Branches

Tags

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