File: vocab.hh

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (167 lines) | stat: -rw-r--r-- 3,655 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

#ifndef __VOCAB_HH__
#define __VOCAB_HH__

#include <boost/shared_ptr.hpp>

#include "sanity.hh"

// the purpose of this file is to wrap things which are otherwise strings
// in a bit of typesafety, set up enumerations and tuple-types, and
// generally describe the "vocabulary" (nouns anyways) that modules in this
// program use.

// For some reason, shared_ptr copy is about a hundred times faster
// than string refcopy on my system (g++ 4). This only happens because
// we tell Boost not to worry about threads... but I don't recognize any
// thread stuff in the string headers.

class immutable_string
{
  boost::shared_ptr<std::string> _rep;
  static std::string empty;

public:
  immutable_string()
  {}
  immutable_string(std::string const & s)
    : _rep(new std::string(s))
  {}

  std::string const & get() const
  {
    if (_rep)
      return *_rep;
    else
      return empty;
  }
};

#include "vocab_macros.hh"
#define ENCODING(enc) hh_ENCODING(enc)
#define ENCODING_NOVERIFY(enc) hh_ENCODING_NOVERIFY(enc)
#define DECORATE(dec) hh_DECORATE(dec)
#define ATOMIC(ty) hh_ATOMIC(ty)
#define ATOMIC_HOOKED(ty,hook) hh_ATOMIC_HOOKED(ty,hook)
#define ATOMIC_NOVERIFY(ty) hh_ATOMIC_NOVERIFY(ty)
#define ATOMIC_BINARY(ty) hh_ATOMIC_BINARY(ty)

#ifdef HAVE_EXTERN_TEMPLATE
#define EXTERN extern
#else
#define EXTERN /* */
#endif

#include "vocab_terms.hh"

#undef ATOMIC
#undef ATOMIC_HOOKED
#undef ATOMIC_NOVERIFY
#undef ATOMIC_BINARY
#undef DECORATE
#undef ENCODING
#undef ENCODING_NOVERIFY

// most of the time you want to use these typedefs and forget
// about the stuff in vocab_terms.hh

typedef revision<id>  revision_id;
typedef manifest<id>  manifest_id;
typedef     file<id>      file_id;
typedef      key<id>       key_id;
typedef    epoch<id>     epoch_id;

typedef    epoch< data >      epoch_data;

typedef revision< data >   revision_data;
typedef   roster< data >     roster_data;
typedef manifest< data >   manifest_data;
typedef     file< data >       file_data;

typedef   roster< delta >    roster_delta;
typedef manifest< delta >  manifest_delta;
typedef     file< delta >      file_delta;

// diff type; this is here and not diff_patch.hh, because options_list.hh
// needs to refer to it
enum diff_type
{
  unified_diff,
  context_diff,
  external_diff
};

// determines which kind of date format we request for date formatting
// only a subset of the following options are currently actually used
enum date_format_spec
{
  date_long,
  date_short,
  time_long,
  time_short,
  date_time_long,
  date_time_short
};

// to distinguish different database types
enum db_type
{
  memory_db,
  managed_db,
  unmanaged_db
};

static const std::string memory_db_identifier = ":memory:";

// do these belong here?
inline bool
null_id(id const & i)
{
  return i().empty();
}

inline bool
null_id(hexenc<id> const & i)
{
  return i().empty();
}

inline bool
null_id(file_id const & i)
{
  return i.inner()().empty();
}

inline bool
null_id(manifest_id const & i)
{
  return i.inner()().empty();
}

inline bool
null_id(revision_id const & i)
{
  return i.inner()().empty();
}


id
fake_id();

#endif // __VOCAB_HH__

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: