Menu

[r710]: / framework / trunk / base_view.cpp  Maximize  Restore  History

Download this file

120 lines (94 with data), 2.1 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
#include "base_view.h"
#include "worker_thread.h"
#include "util.h"
#include <boost/format.hpp>
namespace cppcms {
base_view::settings::settings(worker_thread *w) : worker(w) , output(&w->get_cout()) {};
base_view::settings::settings(worker_thread *w,ostream *o) : worker(w), output(o) {};
string base_view::escape(string const &s)
{
return cppcms::escape(s);
}
string base_view::urlencode(string const &s)
{
return cppcms::urlencode(s);
}
string base_view::intf(int val,string f)
{
return (format(f) % val).str();
}
string base_view::strftime(std::tm const &t,string f)
{
char buf[128];
buf[0]=0;
std::strftime(buf,sizeof(buf),f.c_str(),&t);
return buf;
}
void base_view::set_domain(char const *s)
{
tr=worker.domain_gettext(s);
}
char const *base_view::gettext(char const *s)
{
return tr->gettext(s);
}
char const *base_view::ngettext(char const *s,char const *s1,int m)
{
return tr->ngettext(s,s1,m);
}
namespace details {
views_storage &views_storage::instance() {
static views_storage this_instance;
return this_instance;
};
void views_storage::add_view(string t,string v,view_factory_t f)
{
storage[t][v]=f;
}
void views_storage::remove_views(string t)
{
storage.erase(t);
}
base_view *views_storage::fetch_view(string t,string v,base_view::settings s,base_content *c)
{
templates_t::iterator p=storage.find(t);
if(p==storage.end()) return NULL;
template_views_t::iterator p2=p->second.find(v);
if(p2==p->second.end()) return NULL;
view_factory_t &f=p2->second;
return f(s,c);
}
};
format::format(std::string const &s) :
impl(new boost::format(s))
{
impl->exceptions(0);
}
format::~format() {}
format::format(format const &f) : impl(f.impl) {}
format &format::operator % (int n)
{
*impl % n;
return *this;
}
format &format::operator % (string const &s)
{
*impl % s;
return *this;
}
format &format::operator % (char const *s)
{
*impl % s;
return *this;
}
string format::str()
{
string s=impl->str();
return s;
}
ostream &operator<<(ostream &s,format &f)
{
s << *f.impl;
return s;
}
}// CPPCMS
MongoDB Logo MongoDB