1 // Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2 //
3 // This program is made available under the GNU GPL version 2.0 or
4 // greater. See the accompanying file COPYING for details.
5 //
6 // This program is distributed WITHOUT ANY WARRANTY; without even the
7 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE.
9
10 #ifndef __VOCAB_HH__
11 #define __VOCAB_HH__
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.
26
27 class immutable_string
28 {
29 boost::shared_ptr<std::string> _rep;
30 static std::string empty;
31
32 public:
immutable_string()33 immutable_string()
34 {}
immutable_string(std::string const & s)35 immutable_string(std::string const & s)
36 : _rep(new std::string(s))
37 {}
38
get() const39 std::string const & get() const
40 {
41 if (_rep)
42 return *_rep;
43 else
44 return empty;
45 }
46 };
47
48 #include "vocab_macros.hh"
49 #define ENCODING(enc) hh_ENCODING(enc)
50 #define ENCODING_NOVERIFY(enc) hh_ENCODING_NOVERIFY(enc)
51 #define DECORATE(dec) hh_DECORATE(dec)
52 #define ATOMIC(ty) hh_ATOMIC(ty)
53 #define ATOMIC_HOOKED(ty,hook) hh_ATOMIC_HOOKED(ty,hook)
54 #define ATOMIC_NOVERIFY(ty) hh_ATOMIC_NOVERIFY(ty)
55 #define ATOMIC_BINARY(ty) hh_ATOMIC_BINARY(ty)
56
57 #ifdef HAVE_EXTERN_TEMPLATE
58 #define EXTERN extern
59 #else
60 #define EXTERN /* */
61 #endif
62
63 #include "vocab_terms.hh"
64
65 #undef ATOMIC
66 #undef ATOMIC_HOOKED
67 #undef ATOMIC_NOVERIFY
68 #undef ATOMIC_BINARY
69 #undef DECORATE
70 #undef ENCODING
71 #undef ENCODING_NOVERIFY
72
73 // most of the time you want to use these typedefs and forget
74 // about the stuff in vocab_terms.hh
75
76 typedef revision<id> revision_id;
77 typedef manifest<id> manifest_id;
78 typedef file<id> file_id;
79 typedef key<id> key_id;
80 typedef epoch<id> epoch_id;
81
82 typedef epoch< data > epoch_data;
83
84 typedef revision< data > revision_data;
85 typedef roster< data > roster_data;
86 typedef manifest< data > manifest_data;
87 typedef file< data > file_data;
88
89 typedef roster< delta > roster_delta;
90 typedef manifest< delta > manifest_delta;
91 typedef file< delta > file_delta;
92
93 typedef u64 file_size;
94
95 // diff type; this is here and not diff_patch.hh, because options_list.hh
96 // needs to refer to it
97 enum diff_type
98 {
99 unified_diff,
100 context_diff,
101 external_diff
102 };
103
104 // determines which kind of date format we request for date formatting
105 // only a subset of the following options are currently actually used
106 enum date_format_spec
107 {
108 date_long,
109 date_short,
110 time_long,
111 time_short,
112 date_time_long,
113 date_time_short
114 };
115
116 // to distinguish different database types
117 enum db_type
118 {
119 memory_db,
120 managed_db,
121 unmanaged_db
122 };
123
124 // to distinguish the payload type of a sync
125 enum connection_type
126 {
127 netsync_connection,
128 automate_connection
129 };
130
131 static const std::string memory_db_identifier = ":memory:";
132
133 // do these belong here?
134 inline bool
null_id(id const & i)135 null_id(id const & i)
136 {
137 return i().empty();
138 }
139
140 inline bool
null_id(hexenc<id> const & i)141 null_id(hexenc<id> const & i)
142 {
143 return i().empty();
144 }
145
146 inline bool
null_id(file_id const & i)147 null_id(file_id const & i)
148 {
149 return i.inner()().empty();
150 }
151
152 inline bool
null_id(manifest_id const & i)153 null_id(manifest_id const & i)
154 {
155 return i.inner()().empty();
156 }
157
158 inline bool
null_id(revision_id const & i)159 null_id(revision_id const & i)
160 {
161 return i.inner()().empty();
162 }
163
164
165 id
166 fake_id();
167
168 #endif // __VOCAB_HH__
169
170 // Local Variables:
171 // mode: C++
172 // fill-column: 76
173 // c-file-style: "gnu"
174 // indent-tabs-mode: nil
175 // End:
176 // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
177