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

Archive Download this file

Branches

Tags

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