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 "config.h"
14
15#include <utility>
16#include <string>
17#include <iosfwd>
18
19// the purpose of this file is to wrap things which are otherwise strings
20// in a bit of typesafety, set up enumerations and tuple-types, and
21// generally describe the "vocabulary" (nouns anyways) that modules in this
22// program use.
23
24// this template must be specialized for each type you want to dump.
25// there are a few stock dumpers in appropriate places.
26template <typename T>
27void dump(T const &, std::string &)
28{
29 // the compiler will evaluate this somewhat odd construct (and issue an
30 // error) if and only if this base template is instantiated. we do not
31 // use BOOST_STATIC_ASSERT mainly to avoid dragging it in everywhere;
32 // also we get better diagnostics this way (the error tells you what is
33 // wrong, not just that there's an assertion failure).
34 enum dummy { d = (sizeof(struct dump_must_be_specialized_for_this_type)
35 == sizeof(T)) };
36}
37
38#include "vocab_macros.hh"
39#define ENCODING(enc) hh_ENCODING(enc)
40#define DECORATE(dec) hh_DECORATE(dec)
41#define ATOMIC(ty) hh_ATOMIC(ty)
42#define ATOMIC_NOVERIFY(ty) hh_ATOMIC_NOVERIFY(ty)
43
44inline bool is_xdigit(char x)
45{
46 return ((x >= '0' && x <= '9')
47 || (x >= 'a' && x <= 'f'));
48}
49
50inline bool is_alpha(char x)
51{
52 return ((x >= 'a' && x <= 'z')
53 || (x >= 'A' && x <= 'Z'));
54}
55
56inline bool is_alnum(char x)
57{
58 return ((x >= '0' && x <= '9')
59 || (x >= 'a' && x <= 'z')
60 || (x >= 'A' && x <= 'Z'));
61}
62
63inline bool is_space(char x)
64{
65 return (x == ' ')
66 || (x == '\n')
67 || (x == '\t')
68 || (x == '\r')
69 || (x == '\v')
70 || (x == '\f');
71}
72
73
74#ifdef HAVE_EXTERN_TEMPLATE
75#define EXTERN extern
76#else
77#define EXTERN /* */
78#endif
79
80#include "vocab_terms.hh"
81
82#undef ATOMIC
83#undef ATOMIC_NOVERIFY
84#undef DECORATE
85#undef ENCODING
86
87// most of the time you want to use these typedefs and forget
88// about the stuff in vocab_terms.hh
89
90typedef revision< hexenc<id> > revision_id;
91typedef manifest< hexenc<id> > manifest_id;
92typedef file< hexenc<id> > file_id;
93typedef key< hexenc<id> > key_id;
94typedef epoch< hexenc<id> > epoch_id;
95typedef epoch< hexenc<data> > epoch_data;
96
97typedef revision< data > revision_data;
98typedef roster< data > roster_data;
99typedef manifest< data > manifest_data;
100typedef file< data > file_data;
101
102typedef roster< delta > roster_delta;
103typedef manifest< delta > manifest_delta;
104typedef file< delta > file_delta;
105
106typedef std::pair<var_domain, var_name> var_key;
107
108
109struct keypair
110{
111 base64<rsa_pub_key> pub;
112 base64<rsa_priv_key> priv;
113 keypair()
114 {}
115 keypair(base64<rsa_pub_key> const & a,
116 base64<rsa_priv_key> const & b)
117 : pub(a), priv(b)
118 {}
119};
120
121// fs::path is our "generic" safe path type, pointing potentially anywhere
122// in the filesystem. if you want to *define* or work with any of these you
123// need to include boost/filesystem/path.hpp.
124
125//namespace boost { namespace filesystem { class path; } }
126//namespace fs = boost::filesystem;
127
128// diff type
129enum diff_type
130{
131 unified_diff,
132 context_diff,
133 external_diff
134};
135
136// do these belong here?
137inline bool
138null_id(hexenc<id> const & i)
139{
140 return i().empty();
141}
142
143inline bool
144null_id(file_id const & i)
145{
146 return i.inner()().empty();
147}
148
149inline bool
150null_id(manifest_id const & i)
151{
152 return i.inner()().empty();
153}
154
155inline bool
156null_id(revision_id const & i)
157{
158 return i.inner()().empty();
159}
160
161
162hexenc<id>
163fake_id();
164
165// Local Variables:
166// mode: C++
167// fill-column: 76
168// c-file-style: "gnu"
169// indent-tabs-mode: nil
170// End:
171// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
172
173#endif // __VOCAB_HH__

Archive Download this file

Branches

Tags

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