Browse Source

Removed boost::format

master
Artyom Beilis 12 years ago
parent
commit
231526d3da
5 changed files with 131 additions and 27 deletions
  1. +2
    -0
      CMakeLists.txt
  2. +112
    -0
      private/todec.h
  3. +0
    -7
      src/base_view.cpp
  4. +14
    -17
      src/form.cpp
  5. +3
    -3
      src/forwarder.cpp

+ 2
- 0
CMakeLists.txt View File

@@ -620,6 +620,7 @@ set(ALL_TESTS
session_interface_test
secure_post_test
mount_point_test
todec_test
)

if(NOT DISABLE_TCPCACHE)
@@ -701,6 +702,7 @@ install(DIRECTORY cppcms DESTINATION include
set(CNF "${CMAKE_CURRENT_SOURCE_DIR}/tests")

add_test(base64_test base64_test)
add_test(todec_test todec_test)
add_test(encryptor_test encryptor_test "${CNF}")
add_test(storage_test storage_test)
add_test(json_test json_test)


+ 112
- 0
private/todec.h View File

@@ -0,0 +1,112 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_IMPL_TODEC_H
#define CPPCMS_IMPL_TODEC_H
#include <limits>
#include <ostream>

namespace cppcms {
namespace impl {
namespace details {
template<bool sig>
struct decimal_traits;

template<>
struct decimal_traits<false> {
template<typename T>
static void conv(T v,char *&begin,char *&buf)
{
begin = buf;
while(v!=0) {
*buf++ = '0' + v % 10;
v/=10;
}
}
};

template<>
struct decimal_traits<true> {
template<typename T>
static void conv(T v,char *&begin,char *&buf)
{
if(v<0) {
*buf++ = '-';
begin=buf;
while(v!=0) {
*buf++ = '0' - (v % 10);
v/=10;
}
}
else {
decimal_traits<false>::conv(v,begin,buf);
}
}
};
}


template<typename Integer>
void todec(Integer v,char *buf)
{
typedef std::numeric_limits<Integer> limits;
if(v == 0) {
*buf++ = '0';
*buf++ = 0;
return;
}
char *begin=0;

details::decimal_traits<limits::is_signed>::conv(v,begin,buf);
*buf-- = 0;
while(begin < buf) {
char tmp = *begin;
*begin = *buf;
*buf = tmp;
buf--;
begin++;
}
}

template<typename I>
std::string todec_string(I v)
{
char buf[std::numeric_limits<I>::digits10 + 4];
todec<I>(v,buf);
std::string tmp = buf;
return tmp;
}

namespace details {
template<typename T>
struct write_int_to_stream {
write_int_to_stream(T vi = 0) : v(vi) {}
T v;
void operator()(std::ostream &out) const
{
char buf[std::numeric_limits<T>::digits10 + 4];
todec<T>(v,buf);
out << buf;
}
};
template<typename T>
std::ostream &operator<<(std::ostream &out,write_int_to_stream<T> const &v)
{
v(out);
return out;
}
} // details

template<typename T>
details::write_int_to_stream<T> cint(T v)
{
return details::write_int_to_stream<T>(v);
}
}
}
#endif

+ 0
- 7
src/base_view.cpp View File

@@ -11,13 +11,6 @@
#include <cppcms/cppcms_error.h>

#include <vector>
#include <cppcms/config.h>
#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/format.hpp>
#else // Internal Boost
# include <cppcms_boost/format.hpp>
namespace boost = cppcms_boost;
#endif

namespace cppcms {



+ 14
- 17
src/form.cpp View File

@@ -14,17 +14,14 @@
#include <cppcms/http_file.h>
#include <cppcms/session_interface.h>
#include <stack>
#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/format.hpp>
#else // Internal Boost
# include <cppcms_boost/format.hpp>
namespace boost = cppcms_boost;
#endif

#include <booster/regex.h>

#include "todec.h"

namespace cppcms {

using impl::cint;

struct form_context::_data {};

form_context::form_context() :
@@ -421,7 +418,7 @@ void base_widget::generate(int position,form_context * /*context*/)
if(is_generation_done_)
return;
if(name_.empty()) {
name_ = (boost::format("_%1%",std::locale::classic()) % position).str();
name_ = "_" + impl::todec_string(position);
}
is_generation_done_ = 1;
}
@@ -671,10 +668,10 @@ void text::render_attributes(form_context &context)

std::ostream &output = context.out();
if(size_ >= 0)
output << boost::format("size=\"%1%\" ",std::locale::classic()) % size_;
output << "size=\"" << cint(size_) <<"\" ";
std::pair<int,int> lm=limits();
if(lm.second >= 0 && validate_charset()) {
output << boost::format("maxlength=\"%1%\" ",std::locale::classic()) % lm.second;
output << "maxlength=\"" << cint(lm.second) << "\" ";
}
}

@@ -728,11 +725,11 @@ void textarea::render_input(form_context &context)
render_attributes(context);

if(rows_ >= 0) {
output<<boost::format("rows=\"%1%\"",std::locale::classic()) % rows_;
output<<"rows=\""<< cint(rows_) << "\"";
}

if(cols_ >= 0) {
output<<boost::format("cols=\"%1%\"",std::locale::classic()) % cols_;
output<<"cols=\"" <<cint(cols_) << "\"";
}
}
else {
@@ -923,13 +920,13 @@ void select_multiple::add(locale::message const &opt,std::string const &id,bool

void select_multiple::add(std::string const &opt,bool selected)
{
std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str();
std::string id=impl::todec_string(elements_.size());
elements_.push_back(element(id,opt,selected));
}

void select_multiple::add(locale::message const &opt,bool selected)
{
std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str();
std::string id=impl::todec_string(elements_.size());
elements_.push_back(element(id,opt,selected));
}

@@ -996,7 +993,7 @@ void select_multiple::render_input(form_context &context)
else
out<<"<select multiple ";
if(rows_ > 0)
out << boost::format(" size=\"%1%\" ",std::locale::classic()) % rows_;
out << " size=\"" << cint(rows_) << "\" ";
render_attributes(context);
}
else {
@@ -1127,13 +1124,13 @@ void select_base::add(locale::message const &str,std::string const &id)

void select_base::add(std::string const &str)
{
std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str();
std::string id= impl::todec_string(elements_.size());
elements_.push_back(element(id,str));
}

void select_base::add(locale::message const &str)
{
std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str();
std::string id= impl::todec_string(elements_.size());
elements_.push_back(element(id,str));
}



+ 3
- 3
src/forwarder.cpp View File

@@ -24,16 +24,15 @@
#include <booster/enable_shared_from_this.h>
#include <scgi_header.h>

#include "todec.h"

#ifdef CPPCMS_USE_EXTERNAL_BOOST
# include <boost/bind.hpp>
# include <boost/format.hpp>
# if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(BOOST_ASIO_DISABLE_IOCP)
# define NO_CANCELIO
# endif
#else // Internal Boost
# include <cppcms_boost/bind.hpp>
# include <cppcms_boost/format.hpp>
namespace boost = cppcms_boost;
# if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(CPPCMS_BOOST_ASIO_DISABLE_IOCP)
# define NO_CANCELIO
@@ -152,7 +151,8 @@ namespace cppcms {
env_str.append(p->first.c_str(),p->first.size()+1);
env_str.append(p->second.c_str(),p->second.size()+1);
}
std::string header=(boost::format("%1%:",std::locale::classic()) % env_str.size()).str();
std::string header=todec_string(env_str.size());
header+=':';
header.reserve(header.size()+env_str.size()+addon_size);
header+=env_str;
header+=',';


Loading…
Cancel
Save