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// this generic template cannot actually be used, except with the
32// specializations given below. give a compile error instead of a link
33// error.
34template<typename XFM> std::string xform(std::string const & in)
35{
36 enum dummy { d = (sizeof(struct xform_must_be_specialized_for_this_type)
37 == sizeof(XFM)) };
38 return in; // avoid warnings about no return statement
39}
40
41// these specializations of the template are defined in transforms.hh
42template<> std::string xform<Botan::Base64_Encoder>(std::string const &);
43template<> std::string xform<Botan::Base64_Decoder>(std::string const &);
44template<> std::string xform<Botan::Hex_Encoder>(std::string const &);
45template<> std::string xform<Botan::Hex_Decoder>(std::string const &);
46template<> std::string xform<Botan::Gzip_Compression>(std::string const &);
47template<> std::string xform<Botan::Gzip_Decompression>(std::string const &);
48
49// base64 encoding
50
51template <typename T>
52void encode_base64(T const & in, base64<T> & out)
53{ out = base64<T>(T(xform<Botan::Base64_Encoder>(in()))); }
54
55template <typename T>
56void decode_base64(base64<T> const & in, T & out)
57{ out = T(xform<Botan::Base64_Decoder>(in())); }
58
59
60// hex encoding
61
62template <typename T>
63void encode_hexenc(T const & in, hexenc<T> & out)
64{ out = hexenc<T>(T(xform<Botan::Hex_Encoder>(in()))); }
65
66template <typename T>
67void decode_hexenc(hexenc<T> const & in, T & out)
68{ out = T(xform<Botan::Hex_Decoder>(in())); }
69
70inline std::string encode_hexenc(std::string const & in)
71{ return xform<Botan::Hex_Encoder>(in); }
72inline std::string decode_hexenc(std::string const & in)
73{ return xform<Botan::Hex_Decoder>(in); }
74
75
76// gzip
77
78template <typename T>
79void encode_gzip(T const & in, gzip<T> & out)
80{ out = gzip<T>(xform<Botan::Gzip_Compression>(in())); }
81
82template <typename T>
83void decode_gzip(gzip<T> const & in, T & out)
84{ out = T(xform<Botan::Gzip_Decompression>(in())); }
85
86// string variant for netsync
87template <typename T>
88void encode_gzip(std::string const & in, gzip<T> & out)
89{ out = xform<Botan::Gzip_Compression>(in); }
90
91// both at once (this is relatively common)
92// these are usable for T = data and T = delta
93
94template <typename T>
95void pack(T const & in, base64< gzip<T> > & out);
96
97template <typename T>
98void unpack(base64< gzip<T> > const & in, T & out);
99
100
101// diffing and patching
102
103void diff(data const & olddata,
104 data const & newdata,
105 delta & del);
106
107void patch(data const & olddata,
108 delta const & del,
109 data & newdata);
110
111
112// version (a.k.a. sha1 fingerprint) calculation
113
114void calculate_ident(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
126// canonicalize base64 encoding
127std::string canonical_base64(std::string const & s);
128
129
130// Local Variables:
131// mode: C++
132// fill-column: 76
133// c-file-style: "gnu"
134// indent-tabs-mode: nil
135// End:
136// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
137
138#endif // __TRANSFORMS_HH__

Archive Download this file

Branches

Tags

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