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 <boost/shared_ptr.hpp>
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// For some reason, shared_ptr copy is about a hundred times faster
21// than string refcopy on my system (g++ 4). This only happens because
22// we tell Boost not to worry about threads... but I don't recognize any
23// thread stuff in the string headers.
24namespace
25{
26 std::string empty;
27}
28
29class immutable_string
30{
31 boost::shared_ptr<std::string> _rep;
32
33public:
34 immutable_string()
35 {}
36 immutable_string(std::string const & s)
37 : _rep(new std::string(s))
38 {}
39
40 std::string const & get() const
41 {
42 if (_rep)
43 return *_rep;
44 else
45 return empty;
46 }
47};
48
49
50
51
52#include "vocab_macros.hh"
53#define ENCODING(enc) hh_ENCODING(enc)
54#define ENCODING_NOVERIFY(enc) hh_ENCODING_NOVERIFY(enc)
55#define DECORATE(dec) hh_DECORATE(dec)
56#define ATOMIC(ty) hh_ATOMIC(ty)
57#define ATOMIC_HOOKED(ty,hook) hh_ATOMIC_HOOKED(ty,hook)
58#define ATOMIC_NOVERIFY(ty) hh_ATOMIC_NOVERIFY(ty)
59#define ATOMIC_BINARY(ty) hh_ATOMIC_BINARY(ty)
60
61#ifdef HAVE_EXTERN_TEMPLATE
62#define EXTERN extern
63#else
64#define EXTERN /* */
65#endif
66
67#include "vocab_terms.hh"
68
69#undef ATOMIC
70#undef ATOMIC_HOOKED
71#undef ATOMIC_NOVERIFY
72#undef ATOMIC_BINARY
73#undef DECORATE
74#undef ENCODING
75#undef ENCODING_NOVERIFY
76
77// most of the time you want to use these typedefs and forget
78// about the stuff in vocab_terms.hh
79
80typedef revision<id> revision_id;
81typedef manifest<id> manifest_id;
82typedef file<id> file_id;
83typedef key<id> key_id;
84typedef epoch<id> epoch_id;
85
86typedef epoch< data > epoch_data;
87
88typedef revision< data > revision_data;
89typedef roster< data > roster_data;
90typedef manifest< data > manifest_data;
91typedef file< data > file_data;
92
93typedef roster< delta > roster_delta;
94typedef manifest< delta > manifest_delta;
95typedef file< delta > file_delta;
96
97// diff type; this is here and not diff_patch.hh, because options_list.hh
98// needs to refer to it
99enum diff_type
100{
101 unified_diff,
102 context_diff,
103 external_diff
104};
105
106// do these belong here?
107inline bool
108null_id(id const & i)
109{
110 return i().empty();
111}
112
113inline bool
114null_id(hexenc<id> const & i)
115{
116 return i().empty();
117}
118
119inline bool
120null_id(file_id const & i)
121{
122 return i.inner()().empty();
123}
124
125inline bool
126null_id(manifest_id const & i)
127{
128 return i.inner()().empty();
129}
130
131inline bool
132null_id(revision_id const & i)
133{
134 return i.inner()().empty();
135}
136
137
138id
139fake_id();
140
141// Local Variables:
142// mode: C++
143// fill-column: 76
144// c-file-style: "gnu"
145// indent-tabs-mode: nil
146// End:
147// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
148
149#endif // __VOCAB_HH__

Archive Download this file

Branches

Tags

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