monotone

monotone Mtn Source Tree

Root/transforms.hh

1#ifndef __TRANSFORMS_HH__
2#define __TRANSFORMS_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 "vocab.hh"
14
15#include <vector>
16
17// this file contans various sorts of string transformations. each
18// transformation should be self-explanatory from its type signature. see
19// transforms.cc for the implementations (most of which are delegations to
20// crypto++ and librsync)
21
22namespace Botan {
23 class Base64_Encoder;
24 class Base64_Decoder;
25 class Hex_Encoder;
26 class Hex_Decoder;
27 class Gzip_Compression;
28 class Gzip_Decompression;
29}
30
31#ifdef HAVE_EXTERN_TEMPLATE
32#define EXTERN extern
33#else
34#define EXTERN /* */
35#endif
36
37template<typename XFM> std::string xform(std::string const &);
38EXTERN template std::string xform<Botan::Base64_Encoder>(std::string const &);
39EXTERN template std::string xform<Botan::Base64_Decoder>(std::string const &);
40EXTERN template std::string xform<Botan::Hex_Encoder>(std::string const &);
41EXTERN template std::string xform<Botan::Hex_Decoder>(std::string const &);
42EXTERN template std::string xform<Botan::Gzip_Compression>(std::string const &);
43EXTERN template std::string xform<Botan::Gzip_Decompression>(std::string const &);
44
45// base64 encoding
46
47template <typename T>
48void encode_base64(T const & in, base64<T> & out)
49{ out = xform<Botan::Base64_Encoder>(in()); }
50
51template <typename T>
52void decode_base64(base64<T> const & in, T & out)
53{ out = xform<Botan::Base64_Decoder>(in()); }
54
55
56// hex encoding
57
58std::string encode_hexenc(std::string const & in);
59std::string decode_hexenc(std::string const & in);
60
61template <typename T>
62void decode_hexenc(hexenc<T> const & in, T & out)
63{ out = decode_hexenc(in()); }
64
65template <typename T>
66void encode_hexenc(T const & in, hexenc<T> & out)
67{ out = encode_hexenc(in()); }
68
69
70// gzip
71
72template <typename T>
73void encode_gzip(T const & in, gzip<T> & out)
74{ out = xform<Botan::Gzip_Compression>(in()); }
75
76template <typename T>
77void decode_gzip(gzip<T> const & in, T & out)
78{ out = xform<Botan::Gzip_Decompression>(in()); }
79
80// string variant for netsync
81template <typename T>
82void encode_gzip(std::string const & in, gzip<T> & out)
83{ out = xform<Botan::Gzip_Compression>(in); }
84
85// both at once (this is relatively common)
86
87template <typename T>
88void pack(T const & in, base64< gzip<T> > & out);
89EXTERN template void pack<data>(data const &, base64< gzip<data> > &);
90EXTERN template void pack<delta>(delta const &, base64< gzip<delta> > &);
91
92template <typename T>
93void unpack(base64< gzip<T> > const & in, T & out);
94EXTERN template void unpack<data>(base64< gzip<data> > const &, data &);
95EXTERN template void unpack<delta>(base64< gzip<delta> > const &, delta &);
96
97
98// diffing and patching
99
100void diff(data const & olddata,
101 data const & newdata,
102 delta & del);
103
104void patch(data const & olddata,
105 delta const & del,
106 data & newdata);
107
108
109// version (a.k.a. sha1 fingerprint) calculation
110
111void calculate_ident(data const & dat,
112 hexenc<id> & ident);
113
114void calculate_ident(base64< gzip<data> > const & dat,
115 hexenc<id> & ident);
116
117void calculate_ident(file_data const & dat,
118 file_id & ident);
119
120void calculate_ident(manifest_data const & dat,
121 manifest_id & ident);
122
123void calculate_ident(revision_data const & dat,
124 revision_id & ident);
125
126void calculate_ident(roster_data const & dat,
127 roster_id & ident);
128
129// canonicalize base64 encoding
130std::string canonical_base64(std::string const & s);
131
132
133// Local Variables:
134// mode: C++
135// fill-column: 76
136// c-file-style: "gnu"
137// indent-tabs-mode: nil
138// End:
139// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
140
141#endif // __TRANSFORMS_HH__

Archive Download this file

Branches

Tags

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