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

Archive Download this file

Branches

Tags

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