monotone

monotone Mtn Source Tree

Root/vocab.hh

1#ifndef __VOCAB_HH__
2#define __VOCAB_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <utility>
10#include <string>
11#include <iosfwd>
12
13// the purpose of this file is to wrap things which are otherwise strings
14// in a bit of typesafety, set up enumerations and tuple-types, and
15// generally describe the "vocabulary" (nouns anyways) that modules in this
16// program use.
17
18#define ENCODING(enc) \
19 \
20template<typename INNER> \
21class enc; \
22 \
23template <typename INNER> \
24std::ostream & operator<<(std::ostream &, \
25 enc<INNER> const &); \
26 \
27template<typename INNER> \
28class enc { \
29 INNER i; \
30public: \
31 bool ok; \
32 enc() : ok(false) {} \
33 enc(std::string const & s); \
34 enc(INNER const & inner); \
35 enc(enc<INNER> const & other); \
36 std::string const & operator()() const \
37 { return i(); } \
38 bool operator<(enc<INNER> const & x) const \
39 { return i() < x(); } \
40 enc<INNER> const & \
41 operator=(enc<INNER> const & other); \
42 bool operator==(enc<INNER> const & x) const \
43 { return i() == x(); } \
44 friend std::ostream & operator<< <>(std::ostream &, \
45 enc<INNER> const &); \
46};
47
48
49#define DECORATE(dec) \
50 \
51template<typename INNER> \
52class dec; \
53 \
54template <typename INNER> \
55std::ostream & operator<<(std::ostream &, \
56 dec<INNER> const &); \
57 \
58template<typename INNER> \
59class dec { \
60 INNER i; \
61public: \
62 bool ok; \
63 dec() : ok(false) {} \
64 dec(INNER const & inner); \
65 dec(dec<INNER> const & other); \
66 bool operator<(dec<INNER> const & x) const \
67 { return i < x.i; } \
68 INNER const & inner() const \
69 { return i; } \
70 dec<INNER> const & \
71 operator=(dec<INNER> const & other); \
72 bool operator==(dec<INNER> const & x) const \
73 { return i == x.i; } \
74 friend std::ostream & operator<< <>(std::ostream &, \
75 dec<INNER> const &); \
76};
77
78
79#define ATOMIC(ty) \
80class ty { \
81 std::string s; \
82public: \
83 bool ok; \
84 ty() : s(""), ok(false) {} \
85 ty(std::string const & str); \
86 ty(ty const & other); \
87 std::string const & operator()() const \
88 { return s; } \
89 bool operator<(ty const & other) const \
90 { return s < other(); } \
91 ty const & operator=(ty const & other); \
92 bool operator==(ty const & other) const \
93 { return s == other(); } \
94 friend std::ostream & operator<<(std::ostream &, \
95 ty const &); \
96}; \
97std::ostream & operator<<(std::ostream &, ty const &);
98
99
100#define EXTERN extern
101
102#include "vocab_terms.hh"
103
104#undef EXTERN
105#undef ATOMIC
106#undef DECORATE
107#undef ENCODING
108
109// most of the time you want to use these typedefs and forget
110// about the stuff in vocab_terms.hh
111
112typedef revision< hexenc<id> > revision_id;
113typedef manifest< hexenc<id> > manifest_id;
114typedef file< hexenc<id> > file_id;
115typedef epoch< hexenc<id> > epoch_id;
116typedef epoch< hexenc<data> > epoch_data;
117
118typedef revision< base64< gzip<data> > > revision_data;
119typedef manifest< base64< gzip<data> > > manifest_data;
120typedef file< base64< gzip<data> > > file_data;
121
122typedef manifest< base64< gzip<delta> > > manifest_delta;
123typedef file< base64< gzip<delta> > > file_delta;
124
125typedef std::pair<var_domain, var_name> var_key;
126
127// fs::path is our "generic" safe path type, pointing potentially anywhere
128// in the filesystem. if you want to *define* or work with any of these you
129// need to include boost/filesystem/path.hpp.
130
131namespace boost { namespace filesystem { struct path; } }
132namespace fs = boost::filesystem;
133
134// kludge: certs are derived types. what else can we do?
135#ifndef __CERT_HH__
136#include "cert.hh"
137extern template class revision<cert>;
138extern template class manifest<cert>;
139#endif
140
141#endif // __VOCAB_HH__

Archive Download this file

Branches

Tags

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