Menu

[r902]: / framework / branches / refactoring / filters.cpp  Maximize  Restore  History

Download this file

201 lines (177 with data), 5.9 kB

  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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#define CPPCMS_SOURCE
#include "filters.h"
#include "base64.h"
#include "util.h"
#include <iostream>
namespace cppcms { namespace filters {
streamable::streamable()
{
set(0,0,0,0);
}
streamable::streamable(streamable const &other)
{
set(other.ptr_,other.to_stream_,other.to_string_,other.type_);
}
streamable::~streamable()
{
}
streamable const &streamable::operator=(streamable const &other)
{
if(&other!=this)
set(other.ptr_,other.to_stream_,other.to_string_,other.type_);
return *this;
}
namespace {
void ch_to_stream(std::ostream &out,void const *p)
{
out<<reinterpret_cast<char const *>(p);
}
std::string ch_to_string(std::ios &ios,void const *p)
{
return reinterpret_cast<char const *>(p);
}
std::string s_to_string(std::ios &ios,void const *p)
{
return *reinterpret_cast<std::string const *>(p);
}
}
streamable::streamable(char const *ptr)
{
set(ptr,ch_to_stream,ch_to_string,&typeid(char const *));
}
template<>
streamable::streamable(std::string const &str)
{
set(&str,to_stream<std::string>,s_to_string,&typeid(std::string));
}
std::string streamable::get(std::ios &ios) const
{
return to_string_(ios,ptr_);
}
void streamable::operator()(std::ostream &out) const
{
to_stream_(out,ptr_);
}
void streamable::set(void const *ptr,to_stream_type tse,to_string_type tst,std::type_info const *type)
{
ptr_=ptr;
to_stream_=tse;
to_string_=tst;
type_=type;
}
std::type_info const &streamable::type() const
{
return *type_;
}
///////////////////////////////////
struct to_upper::data {};
to_upper::to_upper() {}
to_upper::~to_upper() {}
to_upper::to_upper(to_upper const &other) : obj_(other.obj_) {}
to_upper::to_upper(streamable const &obj) : obj_(obj) {}
to_upper const &to_upper::operator=(to_upper const &other){ obj_ = other.obj_; return *this; }
void to_upper::operator()(std::ostream &out) const
{
std::string tmp =obj_.get(out) ;
std::locale loc = out.getloc();
out << ::cppcms::locale::to_upper( tmp,loc);
}
struct to_lower::data {};
to_lower::to_lower() {}
to_lower::~to_lower() {}
to_lower::to_lower(to_lower const &other) : obj_(other.obj_) {}
to_lower::to_lower(streamable const &obj) : obj_(obj) {}
to_lower const &to_lower::operator=(to_lower const &other){ obj_ = other.obj_; return *this; }
void to_lower::operator()(std::ostream &out) const
{
out << locale::to_lower(obj_.get(out),out.getloc());
}
struct to_title::data {};
to_title::to_title() {}
to_title::~to_title() {}
to_title::to_title(to_title const &other) : obj_(other.obj_) {}
to_title::to_title(streamable const &obj) : obj_(obj) {}
to_title const &to_title::operator=(to_title const &other){ obj_ = other.obj_; return *this; }
void to_title::operator()(std::ostream &out) const
{
out << locale::to_title(obj_.get(out),out.getloc());
}
struct escape::data {};
escape::escape() {}
escape::~escape() {}
escape::escape(escape const &other) : obj_(other.obj_) {}
escape::escape(streamable const &obj) : obj_(obj) {}
escape const &escape::operator=(escape const &other){ obj_ = other.obj_; return *this; }
void escape::operator()(std::ostream &out) const
{
out << util::escape(obj_.get(out));
}
struct urlencode::data {};
urlencode::urlencode() {}
urlencode::~urlencode() {}
urlencode::urlencode(urlencode const &other) : obj_(other.obj_) {}
urlencode::urlencode(streamable const &obj) : obj_(obj) {}
urlencode const &urlencode::operator=(urlencode const &other){ obj_ = other.obj_; return *this; }
void urlencode::operator()(std::ostream &out) const
{
out << util::urlencode(obj_.get(out));
}
struct raw::data {};
raw::raw() {}
raw::~raw() {}
raw::raw(raw const &other) : obj_(other.obj_) {}
raw::raw(streamable const &obj) : obj_(obj) {}
raw const &raw::operator=(raw const &other){ obj_ = other.obj_; return *this; }
void raw::operator()(std::ostream &out) const
{
out << obj_;;
}
struct base64_urlencode::data {};
base64_urlencode::base64_urlencode() {}
base64_urlencode::~base64_urlencode() {}
base64_urlencode::base64_urlencode(base64_urlencode const &other) : obj_(other.obj_) {}
base64_urlencode::base64_urlencode(streamable const &obj) : obj_(obj) {}
base64_urlencode const &base64_urlencode::operator=(base64_urlencode const &other){ obj_ = other.obj_; return *this; }
void base64_urlencode::operator()(std::ostream &os) const
{
std::string const s=obj_.get(os);
using namespace cppcms::b64url;
unsigned char const *begin=reinterpret_cast<unsigned char const *>(s.c_str());
unsigned char const *end=begin+s.size();
std::vector<unsigned char> out(encoded_size(s.size())+1);
encode(begin,end,&out.front());
out.back()=0;
char const *buf=reinterpret_cast<char const *>(out.front());
os<<buf;
}
struct date::data {};
struct time::data {};
struct datetime::data {};
date::date() : time_(0) {}
datetime::datetime() : time_(0){}
time::time() : time_(0) {}
date::~date() {}
datetime::~datetime() {}
time::~time() {}
date::date(date const &other) : time_(other.time_) {}
time::time(time const &other) : time_(other.time_) {}
datetime::datetime(datetime const &other) : time_(other.time_) {}
date const &date::operator=(date const &other) { time_=other.time_; return *this; }
time const &time::operator=(time const &other) { time_=other.time_; return *this; }
datetime const &datetime::operator=(datetime const &other) { time_=other.time_; return *this; }
date::date(double t) : time_(t) {}
time::time(double t) : time_(t) {}
datetime::datetime(double t) : time_(t) {}
void date::operator()(std::ostream &out) const
{
out << format("{1,date}") % time_;
}
void time::operator()(std::ostream &out) const
{
out << format("{1,time}") % time_;
}
void datetime::operator()(std::ostream &out) const
{
out << format("{1,datetime}") % time_;
}
}} // cppcms::filters
MongoDB Logo MongoDB