bad_weak_ptr.h | bad_weak_ptr.h | |||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
// | // | |||
// boost/smart_ptr/bad_weak_ptr.hpp | // boost/smart_ptr/bad_weak_ptr.hpp | |||
// | // | |||
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. | // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#include <exception> | #include <booster/backtrace.h> | |||
#ifdef __BORLANDC__ | #ifdef __BORLANDC__ | |||
# pragma warn -8026 // Functions with excep. spec. are not expanded inl ine | # pragma warn -8026 // Functions with excep. spec. are not expanded inl ine | |||
#endif | #endif | |||
namespace booster | namespace booster | |||
{ | { | |||
// The standard library that comes with Borland C++ 5.5.1, 5.6.4 | // The standard library that comes with Borland C++ 5.5.1, 5.6.4 | |||
// defines std::exception and its members as having C calling | // defines std::exception and its members as having C calling | |||
skipping to change at line 36 | skipping to change at line 36 | |||
// is compiled with -ps, the compiler issues an error. | // is compiled with -ps, the compiler issues an error. | |||
// Hence, the temporary #pragma option -pc below. | // Hence, the temporary #pragma option -pc below. | |||
#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 | #if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 | |||
# pragma option push -pc | # pragma option push -pc | |||
#endif | #endif | |||
/// | /// | |||
/// An exeption that is throws in case of creating of shared_ptr from expir ed weak_ptr | /// An exeption that is throws in case of creating of shared_ptr from expir ed weak_ptr | |||
/// | /// | |||
class bad_weak_ptr: public std::exception | class bad_weak_ptr: public booster::exception | |||
{ | { | |||
public: | public: | |||
virtual char const * what() const throw() | virtual char const * what() const throw() | |||
{ | { | |||
return "booster::bad_weak_ptr"; | return "booster::bad_weak_ptr"; | |||
} | } | |||
}; | }; | |||
#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 | #if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
boundary.h | boundary.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <string> | #include <string> | |||
#include <locale> | #include <locale> | |||
#include <vector> | #include <vector> | |||
#include <iterator> | #include <iterator> | |||
#include <algorithm> | #include <algorithm> | |||
#include <typeinfo> | #include <typeinfo> | |||
#include <iterator> | #include <iterator> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \brief This namespae contains all operations required for bound ary analysis of text | /// \brief This namespae contains all operations required for bound ary analysis of text | |||
/// | /// | |||
namespace boundary { | namespace boundary { | |||
/// | /// | |||
skipping to change at line 111 | skipping to change at line 111 | |||
{ | { | |||
switch(t) { | switch(t) { | |||
case character: return character_mask; | case character: return character_mask; | |||
case word: return word_mask; | case word: return word_mask; | |||
case sentence: return sentence_mask; | case sentence: return sentence_mask; | |||
case line: return line_mask; | case line: return line_mask; | |||
default: return 0; | default: return 0; | |||
} | } | |||
} | } | |||
/// \cond INTERNAL | /// | |||
namespace impl { | /// This structure is used for representing boundary point | |||
/// that follows the offset. | ||||
struct break_info { | /// | |||
struct break_info { | ||||
break_info() : | /// | |||
offset(0), | /// Create empty break point at beginning | |||
mark(0) | /// | |||
{ | break_info() : | |||
} | offset(0), | |||
break_info(unsigned v) : | mark(0) | |||
offset(v), | { | |||
mark(0) | } | |||
{ | /// | |||
} | /// Create empty break point at offset v. | |||
/// it is useful for order comparison with other points. | ||||
/// | ||||
break_info(unsigned v) : | ||||
offset(v), | ||||
mark(0) | ||||
{ | ||||
} | ||||
uint32_t offset; | /// | |||
uint32_t mark; | /// Offset from the begging of the text where a break occur | |||
s. | ||||
/// | ||||
uint32_t offset; | ||||
/// | ||||
/// The identification of this break point according to | ||||
/// various break types | ||||
/// | ||||
uint32_t mark; | ||||
bool operator<(break_info const &other) const | /// | |||
{ | /// Compare two break points' offset. Allows to search with | |||
return offset < other.offset; | /// standard algorithms over the index. | |||
} | /// | |||
}; | bool operator<(break_info const &other) const | |||
{ | ||||
return offset < other.offset; | ||||
} | ||||
}; | ||||
typedef std::vector<break_info> index_type; | /// | |||
/// This type holds the alalisys of the text - all its break po | ||||
ints | ||||
/// with marks | ||||
/// | ||||
typedef std::vector<break_info> index_type; | ||||
template<typename CharType> | template<typename CharType> | |||
index_type map(boundary_type t,CharType const *begin,CharTy | class boundary_indexing; | |||
pe const *end,std::locale const &loc=std::locale()); | ||||
template<typename CharType> | /// | |||
static index_type map( | /// The facet that allows us to create an index for boundary an | |||
boundary_type t, | alisys | |||
std::basic_string<CharType> const &str, | /// of the text. | |||
std::locale const &loc=std::locale()) | /// | |||
template<> | ||||
class BOOSTER_API boundary_indexing<char> : public std::locale: | ||||
:facet { | ||||
public: | ||||
/// | ||||
/// Default constructor typical for facets | ||||
/// | ||||
boundary_indexing(size_t refs=0) : std::locale::facet(refs) | ||||
{ | { | |||
return booster::locale::boundary::impl::map<CharType>(t ,str.data(),str.data()+str.size(),loc); | ||||
} | } | |||
/// | ||||
/// Create index for boundary type \a t for text in range [ | ||||
begin,end) | ||||
/// | ||||
virtual index_type map(boundary_type t,char const *begin,ch | ||||
ar const *end) const = 0; | ||||
/// Identification of this facet | ||||
static std::locale::id id; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | ||||
}; | ||||
template<> | /// | |||
BOOSTER_API index_type | /// The facet that allows us to create an index for boundary an | |||
map(boundary_type t,char const *begin,char const *end,std:: | alisys | |||
locale const &loc); | /// of the text. | |||
/// | ||||
template<> | ||||
class BOOSTER_API boundary_indexing<wchar_t> : public std::loca | ||||
le::facet { | ||||
public: | ||||
/// | ||||
/// Default constructor typical for facets | ||||
/// | ||||
boundary_indexing(size_t refs=0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
/// | ||||
/// Create index for boundary type \a t for text in range [ | ||||
begin,end) | ||||
/// | ||||
virtual index_type map(boundary_type t,wchar_t const *begin | ||||
,wchar_t const *end) const = 0; | ||||
#ifndef BOOSTER_NO_STD_WSTRING | /// Identification of this facet | |||
template<> | static std::locale::id id; | |||
BOOSTER_API index_type | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |||
map(boundary_type t,wchar_t const *begin,wchar_t const *end | std::locale::id& __get_id (void) const { return id; } | |||
,std::locale const &loc); | ||||
#endif | #endif | |||
}; | ||||
#ifdef BOOSTER_HAS_CHAR16_T | #ifdef BOOSTER_HAS_CHAR16_T | |||
template<> | template<> | |||
BOOSTER_API index_type | class BOOSTER_API boundary_indexing<char16_t> : public std::loc | |||
map(boundary_type t,char16_t const *begin,char16_t const *e | ale::facet { | |||
nd,std::locale const &loc); | public: | |||
boundary_indexing(size_t refs=0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
virtual index_type map(boundary_type t,char16_t const *begi | ||||
n,char16_t const *end) const = 0; | ||||
static std::locale::id id; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | #endif | |||
}; | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR32_T | #ifdef BOOSTER_HAS_CHAR32_T | |||
template<> | template<> | |||
BOOSTER_API index_type | class BOOSTER_API boundary_indexing<char32_t> : public std::loc | |||
map(boundary_type t,char32_t const *begin,char32_t const *e | ale::facet { | |||
nd,std::locale const &loc); | public: | |||
boundary_indexing(size_t refs=0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
virtual index_type map(boundary_type t,char32_t const *begi | ||||
n,char32_t const *end) const = 0; | ||||
static std::locale::id id; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | #endif | |||
} // impl | }; | |||
#endif | ||||
/// \cond INTERNAL | ||||
namespace details { | namespace details { | |||
template<typename IteratorType,typename CategoryType = type name std::iterator_traits<IteratorType>::iterator_category> | template<typename IteratorType,typename CategoryType = type name std::iterator_traits<IteratorType>::iterator_category> | |||
struct mapping_traits { | struct mapping_traits { | |||
typedef typename std::iterator_traits<IteratorType>::va lue_type char_type; | typedef typename std::iterator_traits<IteratorType>::va lue_type char_type; | |||
static impl::index_type map(boundary_type t,IteratorTyp e b,IteratorType e,std::locale const &l) | static index_type map(boundary_type t,IteratorType b,It eratorType e,std::locale const &l) | |||
{ | { | |||
std::basic_string<char_type> str(b,e); | std::basic_string<char_type> str(b,e); | |||
return impl::map(t,str,l); | return std::use_facet<boundary_indexing<char_type> >(l).map(t,str.c_str(),str.c_str()+str.size()); | |||
} | } | |||
}; | }; | |||
template<typename IteratorType> | template<typename IteratorType> | |||
struct mapping_traits<IteratorType,std::random_access_itera tor_tag> { | struct mapping_traits<IteratorType,std::random_access_itera tor_tag> { | |||
typedef typename std::iterator_traits<IteratorType>::va lue_type char_type; | typedef typename std::iterator_traits<IteratorType>::va lue_type char_type; | |||
static impl::index_type map(boundary_type t,IteratorTyp e b,IteratorType e,std::locale const &l) | static index_type map(boundary_type t,IteratorType b,It eratorType e,std::locale const &l) | |||
{ | { | |||
impl::index_type result; | index_type result; | |||
// | // | |||
// Optimize for most common cases | // Optimize for most common cases | |||
// | // | |||
// C++0x requires that string is continious in memo ry and all string implementations | // C++0x requires that string is continious in memo ry and all string implementations | |||
// do this because of c_str() support. | // do this because of c_str() support. | |||
// | // | |||
if( | if( | |||
( | ( | |||
typeid(IteratorType) == typeid(typename std ::basic_string<char_type>::iterator) | typeid(IteratorType) == typeid(typename std ::basic_string<char_type>::iterator) | |||
skipping to change at line 214 | skipping to change at line 286 | |||
|| typeid(IteratorType) == typeid(typename std::vector<char_type>::const_iterator) | || typeid(IteratorType) == typeid(typename std::vector<char_type>::const_iterator) | |||
|| typeid(IteratorType) == typeid(char_type *) | || typeid(IteratorType) == typeid(char_type *) | |||
|| typeid(IteratorType) == typeid(char_type const *) | || typeid(IteratorType) == typeid(char_type const *) | |||
) | ) | |||
&& | && | |||
b!=e | b!=e | |||
) | ) | |||
{ | { | |||
char_type const *begin = &*b; | char_type const *begin = &*b; | |||
char_type const *end = begin + (e-b); | char_type const *end = begin + (e-b); | |||
impl::index_type tmp=impl::map(t,begin,end,l); | index_type tmp=std::use_facet<boundary_indexing <char_type> >(l).map(t,begin,end); | |||
result.swap(tmp); | result.swap(tmp); | |||
} | } | |||
else{ | else{ | |||
std::basic_string<char_type> str(b,e); | std::basic_string<char_type> str(b,e); | |||
impl::index_type tmp=impl::map(t,str,l); | index_type tmp = std::use_facet<boundary_indexi ng<char_type> >(l).map(t,str.c_str(),str.c_str()+str.size()); | |||
result.swap(tmp); | result.swap(tmp); | |||
} | } | |||
return result; | return result; | |||
} | } | |||
}; | }; | |||
} // details | } // details | |||
/// \endcond | /// \endcond | |||
skipping to change at line 399 | skipping to change at line 471 | |||
/// Get \a end iterator used when object was created | /// Get \a end iterator used when object was created | |||
/// | /// | |||
RangeIterator end() const | RangeIterator end() const | |||
{ | { | |||
return RangeIterator(*this,false,mask_); | return RangeIterator(*this,false,mask_); | |||
} | } | |||
private: | private: | |||
void create_mapping(boundary_type type,base_iterator begin, base_iterator end,std::locale const &loc,unsigned mask) | void create_mapping(boundary_type type,base_iterator begin, base_iterator end,std::locale const &loc,unsigned mask) | |||
{ | { | |||
impl::index_type idx=details::mapping_traits<base_itera tor>::map(type,begin,end,loc); | index_type idx=details::mapping_traits<base_iterator>:: map(type,begin,end,loc); | |||
index_.swap(idx); | index_.swap(idx); | |||
begin_ = begin; | begin_ = begin; | |||
end_ = end; | end_ = end; | |||
mask_=mask; | mask_=mask; | |||
} | } | |||
template<typename I> | template<typename I> | |||
friend class break_iterator; | friend class break_iterator; | |||
template<typename I,typename V> | template<typename I,typename V> | |||
friend class token_iterator; | friend class token_iterator; | |||
template<typename I> | template<typename I> | |||
friend class mapping; | friend class mapping; | |||
base_iterator begin_,end_; | base_iterator begin_,end_; | |||
impl::index_type index_; | index_type index_; | |||
unsigned mask_; | unsigned mask_; | |||
}; | }; | |||
/// | /// | |||
/// \brief token_iterator is an iterator that returns text chun ks between boundary positions | /// \brief token_iterator is an iterator that returns text chun ks between boundary positions | |||
/// | /// | |||
/// Token iterator may behave in two different ways: select spe cific tokens in only tide way and | /// Token iterator may behave in two different ways: select spe cific tokens in only tide way and | |||
/// select them widely. For tide selection (default) it would n ot return text chunks that | /// select them widely. For tide selection (default) it would n ot return text chunks that | |||
/// do not fit the selection mask. For example, for word iterat ion with mask "word_letters" | /// do not fit the selection mask. For example, for word iterat ion with mask "word_letters" | |||
/// for text "I met him at 7" it would return "I", "met", "him" , "at" ignoring white spaces | /// for text "I met him at 7" it would return "I", "met", "him" , "at" ignoring white spaces | |||
skipping to change at line 477 | skipping to change at line 549 | |||
/// - "to| be or ", would point to "be", | /// - "to| be or ", would point to "be", | |||
/// - "t|o be or ", would point to "to", | /// - "t|o be or ", would point to "to", | |||
/// - "to be or| ", would point to end. | /// - "to be or| ", would point to end. | |||
/// | /// | |||
/// \a p - should be in range of the original mapping. | /// \a p - should be in range of the original mapping. | |||
/// | /// | |||
token_iterator const &operator=(IteratorType p) | token_iterator const &operator=(IteratorType p) | |||
{ | { | |||
unsigned dist=std::distance(map_->begin_,p); | unsigned dist=std::distance(map_->begin_,p); | |||
impl::index_type::const_iterator b=map_->index_.begin() | index_type::const_iterator b=map_->index_.begin(),e=map | |||
,e=map_->index_.end(); | _->index_.end(); | |||
impl::index_type::const_iterator | index_type::const_iterator | |||
bound=std::upper_bound(b,e,impl::break_info(dist)); | bound=std::upper_bound(b,e,break_info(dist)); | |||
while(bound != e && (bound->mark & mask_)==0) | while(bound != e && (bound->mark & mask_)==0) | |||
bound++; | bound++; | |||
offset_ = bound - b; | offset_ = bound - b; | |||
return *this; | return *this; | |||
} | } | |||
/// | /// | |||
/// Create token iterator for mapping \a map with location at begin or end according to value of flag \a begin, | /// Create token iterator for mapping \a map with location at begin or end according to value of flag \a begin, | |||
/// and a mask \a mask | /// and a mask \a mask | |||
/// | /// | |||
skipping to change at line 531 | skipping to change at line 603 | |||
map_ = other.map_; | map_ = other.map_; | |||
offset_ = other.offset_; | offset_ = other.offset_; | |||
mask_=other.mask_; | mask_=other.mask_; | |||
full_select_ = other.full_select_; | full_select_ = other.full_select_; | |||
} | } | |||
return *this; | return *this; | |||
} | } | |||
/// | /// | |||
/// Return the token the iterator points it. Iterator must not point to the | /// Return the token the iterator points it. Iterator must not point to the | |||
/// end of the range. Throws std::out_of_range exception | /// end of the range. Throws booster::out_of_range exceptio n | |||
/// | /// | |||
/// Note, returned value is not lvalue, you can't use this iterator to assign new values to text. | /// Note, returned value is not lvalue, you can't use this iterator to assign new values to text. | |||
/// | /// | |||
ValueType operator*() const | ValueType operator*() const | |||
{ | { | |||
if(offset_ < 1 || offset_ >= map_->index_.size()) | if(offset_ < 1 || offset_ >= map_->index_.size()) | |||
throw std::out_of_range("Invalid token iterator loc ation"); | throw booster::out_of_range("Invalid token iterator location"); | |||
unsigned pos=offset_-1; | unsigned pos=offset_-1; | |||
if(full_select_) | if(full_select_) | |||
while(!valid_offset(pos)) | while(!valid_offset(pos)) | |||
pos--; | pos--; | |||
base_iterator b=map_->begin_; | base_iterator b=map_->begin_; | |||
unsigned b_off = map_->index_[pos].offset; | unsigned b_off = map_->index_[pos].offset; | |||
std::advance(b,b_off); | std::advance(b,b_off); | |||
base_iterator e=b; | base_iterator e=b; | |||
unsigned e_off = map_->index_[offset_].offset; | unsigned e_off = map_->index_[offset_].offset; | |||
std::advance(e,e_off-b_off); | std::advance(e,e_off-b_off); | |||
skipping to change at line 795 | skipping to change at line 867 | |||
/// \a p - should be in range of the original mapping. | /// \a p - should be in range of the original mapping. | |||
/// | /// | |||
break_iterator const &operator=(base_iterator p) | break_iterator const &operator=(base_iterator p) | |||
{ | { | |||
at_least(p); | at_least(p); | |||
return *this; | return *this; | |||
} | } | |||
/// | /// | |||
/// Return the underlying iterator that break_iterator poin ts it. Iterator must not point to the | /// Return the underlying iterator that break_iterator poin ts it. Iterator must not point to the | |||
/// end of the range, otherwise throws std::out_of_range ex ception | /// end of the range, otherwise throws booster::out_of_rang e exception | |||
/// | /// | |||
/// Note, returned value is not lvalue, you can't use this iterator to change underlying iterators. | /// Note, returned value is not lvalue, you can't use this iterator to change underlying iterators. | |||
/// | /// | |||
base_iterator operator*() const | base_iterator operator*() const | |||
{ | { | |||
if(offset_ >=map_->index_.size()) | if(offset_ >=map_->index_.size()) | |||
throw std::out_of_range("Invalid position of break iterator"); | throw booster::out_of_range("Invalid position of br eak iterator"); | |||
base_iterator p = map_->begin_; | base_iterator p = map_->begin_; | |||
std::advance(p, map_->index_[offset_].offset); | std::advance(p, map_->index_[offset_].offset); | |||
return p; | return p; | |||
} | } | |||
/// | /// | |||
/// Increment operator | /// Increment operator | |||
/// | /// | |||
break_iterator &operator++() | break_iterator &operator++() | |||
{ | { | |||
skipping to change at line 880 | skipping to change at line 952 | |||
offset_ --; | offset_ --; | |||
if(valid_offset(offset_)) | if(valid_offset(offset_)) | |||
break; | break; | |||
} | } | |||
} | } | |||
void at_least(IteratorType p) | void at_least(IteratorType p) | |||
{ | { | |||
unsigned diff = std::distance(map_->begin_,p); | unsigned diff = std::distance(map_->begin_,p); | |||
impl::index_type::const_iterator b=map_->index_.begin() | index_type::const_iterator b=map_->index_.begin(); | |||
; | index_type::const_iterator e=map_->index_.end(); | |||
impl::index_type::const_iterator e=map_->index_.end(); | index_type::const_iterator ptr = std::lower_bound(b,e,b | |||
impl::index_type::const_iterator ptr = std::lower_bound | reak_info(diff)); | |||
(b,e,impl::break_info(diff)); | ||||
if(ptr==map_->index_.end()) | if(ptr==map_->index_.end()) | |||
offset_=map_->index_.size()-1; | offset_=map_->index_.size()-1; | |||
else | else | |||
offset_=ptr - map_->index_.begin(); | offset_=ptr - map_->index_.begin(); | |||
while(!valid_offset(offset_)) | while(!valid_offset(offset_)) | |||
offset_ ++; | offset_ ++; | |||
} | } | |||
End of changes. 31 change blocks. | ||||
73 lines changed or deleted | 153 lines changed or added | |||
callback.h | callback.h | |||
---|---|---|---|---|
// | // | |||
// Copyright (c) 2010 Artyom Beilis (Tonkikh) | // Copyright (c) 2010 Artyom Beilis (Tonkikh) | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_CALLBACK_H | #ifndef BOOSTER_CALLBACK_H | |||
#define BOOSTER_CALLBACK_H | #define BOOSTER_CALLBACK_H | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
#include <memory> | #include <memory> | |||
#include <booster/intrusive_ptr.h> | #include <booster/intrusive_ptr.h> | |||
#include <booster/refcounted.h> | #include <booster/refcounted.h> | |||
namespace booster { | namespace booster { | |||
template<typename Type> | template<typename Type> | |||
class callback; | class callback; | |||
template<typename Type> | template<typename Type> | |||
struct callable; | struct callable; | |||
class bad_callback_call : public std::runtime_error { | /// | |||
/// \brief this exception is thrown in case of calling unassigned/em | ||||
pty | ||||
/// function | ||||
/// | ||||
class bad_callback_call : public booster::runtime_error { | ||||
public: | public: | |||
bad_callback_call() : | bad_callback_call() : | |||
std::runtime_error("bad_callback_call") | booster::runtime_error("bad_callback_call") | |||
{ | { | |||
} | } | |||
}; | }; | |||
#ifdef BOOSTER_DOXYGEN_DOCS | #ifdef BOOSTER_DOXYGEN_DOCS | |||
/// | /// | |||
/// \brief This is Booster's implementation of std::tr1::callback/bo oster::callback. | /// \brief This is Booster's implementation of std::tr1::callback/bo oster::callback. | |||
/// | /// | |||
/// This callback is created from generic object that can be "called " i.e. | /// This callback is created from generic object that can be "called " i.e. | |||
/// a class with operator() or callback pointer that has same signat ure as | /// a class with operator() or callback pointer that has same signat ure as | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 8 lines changed or added | |||
conversion.h | conversion.h | |||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \defgroup convert Text Conversions | /// \defgroup convert Text Conversions | |||
/// | /// | |||
/// This module provides various function for string manipulation like Unicode normalization, case conversion etc. | /// This module provides various function for string manipulation like Unicode normalization, case conversion etc. | |||
/// @{ | /// @{ | |||
/// | /// | |||
/// \cond INTERNAL | /// | |||
namespace impl { | /// This class provides base flags for text manipulation, it is use | |||
d as base for converter facet. | ||||
/// | ||||
class converter_base { | ||||
public: | ||||
/// | ||||
/// The flag used for facet - the type of operation to perform | ||||
/// | ||||
typedef enum { | typedef enum { | |||
normalization, | normalization, ///< Apply Unicode normalization on the tex | |||
upper_case, | t | |||
lower_case, | upper_case, ///< Convert text to upper case | |||
case_folding, | lower_case, ///< Convert text to lower case | |||
title_case | case_folding, ///< Fold case in the text | |||
title_case ///< Convert text to title case | ||||
} conversion_type; | } conversion_type; | |||
}; | ||||
BOOSTER_API std::string convert(conversion_type how,char const | template<typename CharType> | |||
*begin,char const *end,int flags,std::locale const *loc=0); | class converter; | |||
#ifndef BOOSTER_NO_STD_WSTRING | ||||
BOOSTER_API std::wstring convert(conversion_type how,wchar_t co | ||||
nst *begin,wchar_t const *end,int flags,std::locale const *loc=0); | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR16_T | ||||
BOOSTER_API std::u16string convert(conversion_type how,char16_t | ||||
const *begin,char16_t const *end,int flags,std::locale const *loc=0); | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR32_T | ||||
BOOSTER_API std::u32string convert(conversion_type how,char32_t | ||||
const *begin,char32_t const *end,int flags,std::locale const *loc=0); | ||||
#endif | ||||
} // impl | /// | |||
/// \endcond | /// The facet that implements text manipulation | |||
/// | ||||
template<> | ||||
class BOOSTER_API converter<char> : public converter_base, public s | ||||
td::locale::facet { | ||||
public: | ||||
/// Locale identification | ||||
static std::locale::id id; | ||||
/// Standard constructor | ||||
converter(size_t refs = 0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
/// | ||||
/// Convert text in range [\a begin, \a end) according to conve | ||||
rsion method \a how. Parameter | ||||
/// \a flags is used for specification of normalization method | ||||
like nfd, nfc etc. | ||||
/// | ||||
virtual std::string convert(conversion_type how,char const *beg | ||||
in,char const *end,int flags = 0) const = 0; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | ||||
}; | ||||
/// | ||||
/// The facet that implements text manipulation | ||||
/// | ||||
template<> | ||||
class BOOSTER_API converter<wchar_t> : public converter_base, publi | ||||
c std::locale::facet { | ||||
public: | ||||
/// Locale identification | ||||
static std::locale::id id; | ||||
/// Standard constructor | ||||
converter(size_t refs = 0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
/// | ||||
/// Convert text in range [\a begin, \a end) according to conve | ||||
rsion method \a how. Parameter | ||||
/// \a flags is used for specification of normalization method | ||||
like nfd, nfc etc. | ||||
/// | ||||
virtual std::wstring convert(conversion_type how,wchar_t const | ||||
*begin,wchar_t const *end,int flags = 0) const = 0; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | ||||
}; | ||||
#ifdef BOOSTER_HAS_CHAR16_T | ||||
template<> | ||||
class BOOSTER_API converter<char16_t> : public converter_base, publ | ||||
ic std::locale::facet { | ||||
public: | ||||
static std::locale::id id; | ||||
converter(size_t refs = 0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
virtual std::u16string convert(conversion_type how,char16_t con | ||||
st *begin,char16_t const *end,int flags = 0) const = 0; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | ||||
}; | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR32_T | ||||
template<> | ||||
class BOOSTER_API converter<char32_t> : public converter_base, publ | ||||
ic std::locale::facet { | ||||
public: | ||||
static std::locale::id id; | ||||
converter(size_t refs = 0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
virtual std::u32string convert(conversion_type how,char32_t con | ||||
st *begin,char32_t const *end,int flags = 0) const = 0; | ||||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | ||||
std::locale::id& __get_id (void) const { return id; } | ||||
#endif | ||||
}; | ||||
#endif | ||||
/// | /// | |||
/// Type of normalization | /// Type of normalization | |||
/// | /// | |||
typedef enum { | typedef enum { | |||
norm_nfd, ///< Canonical decomposition | norm_nfd, ///< Canonical decomposition | |||
norm_nfc, ///< Canonical decomposition followed by canonical composition | norm_nfc, ///< Canonical decomposition followed by canonical composition | |||
norm_nfkd, ///< Compatibility decomposition | norm_nfkd, ///< Compatibility decomposition | |||
norm_nfkc, ///< Compatibility decomposition followed by canoni cal composition. | norm_nfkc, ///< Compatibility decomposition followed by canoni cal composition. | |||
skipping to change at line 72 | skipping to change at line 143 | |||
} norm_type; | } norm_type; | |||
/// | /// | |||
/// Normalize Unicode string \a str according to normalization mode \a n | /// Normalize Unicode string \a str according to normalization mode \a n | |||
/// | /// | |||
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | /// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | |||
/// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | /// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | |||
/// of Unicode character set. | /// of Unicode character set. | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> normalize(std::basic_string<CharType> c onst &str,norm_type n=norm_default) | std::basic_string<CharType> normalize(std::basic_string<CharType> c onst &str,norm_type n=norm_default,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::normalization,str.data(),str.data() + str.size(),n); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::normalization,str.data(),str.data() + str.size(),n); | |||
} | } | |||
/// | /// | |||
/// Normalize NUL terminated Unicode string \a str according to nor malization mode \a n | /// Normalize NUL terminated Unicode string \a str according to nor malization mode \a n | |||
/// | /// | |||
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | /// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | |||
/// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | /// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | |||
/// of Unicode character set. | /// of Unicode character set. | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> normalize(CharType const *str,norm_type n=norm_default) | std::basic_string<CharType> normalize(CharType const *str,norm_type n=norm_default,std::locale const &loc=std::locale()) | |||
{ | { | |||
CharType const *end=str; | CharType const *end=str; | |||
while(*end) | while(*end) | |||
end++; | end++; | |||
return impl::convert(impl::normalization,str,end,n); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::normalization,str,end,n); | |||
} | } | |||
/// | /// | |||
/// Normalize Unicode string in range [begin,end) according to norm alization mode \a n | /// Normalize Unicode string in range [begin,end) according to norm alization mode \a n | |||
/// | /// | |||
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | /// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not takes | |||
/// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | /// in account the locale encoding, because Unicode decomposition a nd composition are meaningless outside | |||
/// of Unicode character set. | /// of Unicode character set. | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> normalize(CharType const *begin,CharTyp e const *end,norm_type n=norm_default) | std::basic_string<CharType> normalize(CharType const *begin,CharTyp e const *end,norm_type n=norm_default,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::normalization,begin,end,n); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::normalization,begin,end,n); | |||
} | } | |||
/////////////////////////////////////////////////// | /////////////////////////////////////////////////// | |||
/// | /// | |||
/// Convert a string \a str to upper case according to locale \a lo c | /// Convert a string \a str to upper case according to locale \a lo c | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_upper(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_upper(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::upper_case,str.data(),str.data()+str .size(),0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::upper_case,str.data(),str.data()+str.size()); | |||
} | } | |||
/// | /// | |||
/// Convert a NUL terminated string \a str to upper case according to locale \a loc | /// Convert a NUL terminated string \a str to upper case according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_upper(CharType const *str,std::local e const &loc=std::locale()) | std::basic_string<CharType> to_upper(CharType const *str,std::local e const &loc=std::locale()) | |||
{ | { | |||
CharType const *end=str; | CharType const *end=str; | |||
while(*end) | while(*end) | |||
end++; | end++; | |||
return impl::convert(impl::upper_case,str,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::upper_case,str,end); | |||
} | } | |||
/// | /// | |||
/// Convert a string in range [begin,end) to upper case according t o locale \a loc | /// Convert a string in range [begin,end) to upper case according t o locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_upper(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_upper(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::upper_case,begin,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::upper_case,begin,end); | |||
} | } | |||
/////////////////////////////////////////////////// | /////////////////////////////////////////////////// | |||
/// | /// | |||
/// Convert a string \a str to lower case according to locale \a lo c | /// Convert a string \a str to lower case according to locale \a lo c | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_lower(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_lower(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::lower_case,str.data(),str.data()+str .size(),0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::lower_case,str.data(),str.data()+str.size()); | |||
} | } | |||
/// | /// | |||
/// Convert a NUL terminated string \a str to lower case according to locale \a loc | /// Convert a NUL terminated string \a str to lower case according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_lower(CharType const *str,std::local e const &loc=std::locale()) | std::basic_string<CharType> to_lower(CharType const *str,std::local e const &loc=std::locale()) | |||
{ | { | |||
CharType const *end=str; | CharType const *end=str; | |||
while(*end) | while(*end) | |||
end++; | end++; | |||
return impl::convert(impl::lower_case,str,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::lower_case,str,end); | |||
} | } | |||
/// | /// | |||
/// Convert a string in range [begin,end) to lower case according t o locale \a loc | /// Convert a string in range [begin,end) to lower case according t o locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_lower(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_lower(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::lower_case,begin,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::lower_case,begin,end); | |||
} | } | |||
/////////////////////////////////////////////////// | /////////////////////////////////////////////////// | |||
/// | /// | |||
/// Convert a string \a str to title case according to locale \a lo c | /// Convert a string \a str to title case according to locale \a lo c | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_title(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_title(std::basic_string<CharType> co nst &str,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::title_case,str.data(),str.data()+str .size(),0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::title_case,str.data(),str.data()+str.size()); | |||
} | } | |||
/// | /// | |||
/// Convert a NUL terminated string \a str to title case according to locale \a loc | /// Convert a NUL terminated string \a str to title case according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_title(CharType const *str,std::local e const &loc=std::locale()) | std::basic_string<CharType> to_title(CharType const *str,std::local e const &loc=std::locale()) | |||
{ | { | |||
CharType const *end=str; | CharType const *end=str; | |||
while(*end) | while(*end) | |||
end++; | end++; | |||
return impl::convert(impl::title_case,str,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::title_case,str,end); | |||
} | } | |||
/// | /// | |||
/// Convert a string in range [begin,end) to title case according t o locale \a loc | /// Convert a string in range [begin,end) to title case according t o locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> to_title(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | std::basic_string<CharType> to_title(CharType const *begin,CharType const *end,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::title_case,begin,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::title_case,begin,end); | |||
} | } | |||
/////////////////////////////////////////////////// | /////////////////////////////////////////////////// | |||
/// | /// | |||
/// Fold case of a string \a str according to locale \a loc | /// Fold case of a string \a str according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> fold_case(std::basic_string<CharType> c onst &str,std::locale const &loc=std::locale()) | std::basic_string<CharType> fold_case(std::basic_string<CharType> c onst &str,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::case_folding,str.data(),str.data()+s tr.size(),0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::case_folding,str.data(),str.data()+str.size()); | |||
} | } | |||
/// | /// | |||
/// Fold case of a NUL terminated string \a str according to locale \a loc | /// Fold case of a NUL terminated string \a str according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> fold_case(CharType const *str,std::loca le const &loc=std::locale()) | std::basic_string<CharType> fold_case(CharType const *str,std::loca le const &loc=std::locale()) | |||
{ | { | |||
CharType const *end=str; | CharType const *end=str; | |||
while(*end) | while(*end) | |||
end++; | end++; | |||
return impl::convert(impl::case_folding,str,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::case_folding,str,end); | |||
} | } | |||
/// | /// | |||
/// Fold case of a string in range [begin,end) according to locale \a loc | /// Fold case of a string in range [begin,end) according to locale \a loc | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_string<CharType> fold_case(CharType const *begin,CharTyp e const *end,std::locale const &loc=std::locale()) | std::basic_string<CharType> fold_case(CharType const *begin,CharTyp e const *end,std::locale const &loc=std::locale()) | |||
{ | { | |||
return impl::convert(impl::case_folding,begin,end,0,&loc); | return std::use_facet<converter<CharType> >(loc).convert(conver ter_base::case_folding,begin,end); | |||
} | } | |||
/// | /// | |||
///@} | ///@} | |||
/// | /// | |||
} // locale | } // locale | |||
} // boost | } // boost | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
End of changes. 23 change blocks. | ||||
41 lines changed or deleted | 122 lines changed or added | |||
convert.h | convert.h | |||
---|---|---|---|---|
#ifndef BOOSTER_NOWIDE_CONVERT_H | #ifndef BOOSTER_NOWIDE_CONVERT_H | |||
#define BOOSTER_NOWIDE_CONVERT_H | #define BOOSTER_NOWIDE_CONVERT_H | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
#if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS) | #if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS) | |||
namespace booster { | namespace booster { | |||
namespace nowide { | namespace nowide { | |||
class BOOSTER_API bad_utf : public std::runtime_error { | /// | |||
/// \brief This exception is thrown if invalid UTF-8 or UTF- | ||||
16 is given as input | ||||
/// | ||||
class BOOSTER_API bad_utf : public booster::runtime_error { | ||||
public: | public: | |||
bad_utf(); | bad_utf(); | |||
}; | }; | |||
/// | ||||
/// Convert between UTF-16 and UTF-8 string, implemented onl | ||||
y on Windows platform | ||||
/// | ||||
BOOSTER_API std::string convert(wchar_t const *s); | BOOSTER_API std::string convert(wchar_t const *s); | |||
/// | ||||
/// Convert between UTF-8 and UTF-16 string, implemented onl | ||||
y on Windows platform | ||||
/// | ||||
BOOSTER_API std::wstring convert(char const *s); | BOOSTER_API std::wstring convert(char const *s); | |||
/// | ||||
/// Convert between UTF-16 and UTF-8 string, implemented onl | ||||
y on Windows platform | ||||
/// | ||||
inline std::string convert(std::wstring const &s) | inline std::string convert(std::wstring const &s) | |||
{ | { | |||
return convert(s.c_str()); | return convert(s.c_str()); | |||
} | } | |||
/// | ||||
/// Convert between UTF-8 and UTF-16 string, implemented onl | ||||
y on Windows platform | ||||
/// | ||||
inline std::wstring convert(std::string const &s) | inline std::wstring convert(std::string const &s) | |||
{ | { | |||
return convert(s.c_str()); | return convert(s.c_str()); | |||
} | } | |||
} // nowide | } // nowide | |||
} // booster | } // booster | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
2 lines changed or deleted | 22 lines changed or added | |||
cppcms_error.h | cppcms_error.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// You should have received a copy of the GNU Lesser General Public Licens e | // You should have received a copy of the GNU Lesser General Public Licens e | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#ifndef CPPCMS_ERROR_H | #ifndef CPPCMS_ERROR_H | |||
#define CPPCMS_ERROR_H | #define CPPCMS_ERROR_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <string> | #include <string> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
namespace cppcms { | namespace cppcms { | |||
/// | /// | |||
/// \brief Exception thrown by CppCMS framework. | /// \brief Exception thrown by CppCMS framework. | |||
/// | /// | |||
/// Every exception that is thrown from CppCMS modules derived from this ex ception. | /// Every exception that is thrown from CppCMS modules derived from this ex ception. | |||
/// | /// | |||
class CPPCMS_API cppcms_error : public std::runtime_error { | class CPPCMS_API cppcms_error : public booster::runtime_error { | |||
std::string strerror(int err); | std::string strerror(int err); | |||
public: | public: | |||
/// | /// | |||
/// Create an object with error code err (errno) and a message \a er ror | /// Create an object with error code err (errno) and a message \a er ror | |||
/// | /// | |||
cppcms_error(int err,std::string const &error); | cppcms_error(int err,std::string const &error); | |||
/// | /// | |||
/// Create an object with message \a error | /// Create an object with message \a error | |||
/// | /// | |||
cppcms_error(std::string const &error) : std::runtime_error(error) { }; | cppcms_error(std::string const &error) : booster::runtime_error(erro r) {}; | |||
}; | }; | |||
} | } | |||
#endif /* _HTTP_ERROR_H */ | #endif /* _HTTP_ERROR_H */ | |||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 3 lines changed or added | |||
cstdio.h | cstdio.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
namespace nowide { | namespace nowide { | |||
#ifndef BOOSTER_WIN_NATIVE | #ifndef BOOSTER_WIN_NATIVE | |||
using std::fopen; | using std::fopen; | |||
using std::freopen; | using std::freopen; | |||
using std::remove; | using std::remove; | |||
using std::rename; | using std::rename; | |||
#endif | #endif | |||
#if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS) | #if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS) | |||
/// | ||||
/// Same as C fopen, but accepts UTF-8 string as file name u | ||||
nder Windows | ||||
/// | ||||
inline FILE *fopen(char const *file_name,char const *mode) | inline FILE *fopen(char const *file_name,char const *mode) | |||
{ | { | |||
try { | try { | |||
return _wfopen(convert(file_name).c_str(),co nvert(mode).c_str()); | return _wfopen(convert(file_name).c_str(),co nvert(mode).c_str()); | |||
} | } | |||
catch(bad_utf const &e) { | catch(bad_utf const &e) { | |||
return 0; | return 0; | |||
} | } | |||
} | } | |||
/// | ||||
/// Same as C freopen, but accepts UTF-8 string as file name | ||||
under Windows | ||||
/// | ||||
inline FILE *freopen(char const *file_name,char const *mode, FILE *stream) | inline FILE *freopen(char const *file_name,char const *mode, FILE *stream) | |||
{ | { | |||
try { | try { | |||
return _wfreopen(convert(file_name).c_str(), convert(mode).c_str(),stream); | return _wfreopen(convert(file_name).c_str(), convert(mode).c_str(),stream); | |||
} | } | |||
catch(bad_utf const &e) { | catch(bad_utf const &e) { | |||
return 0; | return 0; | |||
} | } | |||
} | } | |||
/// | ||||
/// Same as C rename, but accepts UTF-8 strings as file name | ||||
s under Windows | ||||
/// | ||||
inline int rename(char const *old_name,char const *new_name) | inline int rename(char const *old_name,char const *new_name) | |||
{ | { | |||
try { | try { | |||
return _wrename(convert(old_name).c_str(),co nvert(new_name).c_str()); | return _wrename(convert(old_name).c_str(),co nvert(new_name).c_str()); | |||
} | } | |||
catch(bad_utf const &e) { | catch(bad_utf const &e) { | |||
return -1; | return -1; | |||
} | } | |||
} | } | |||
/// | ||||
/// Same as C remove, but accepts UTF-8 string as file name | ||||
under Windows | ||||
/// | ||||
inline int remove(char const *name) | inline int remove(char const *name) | |||
{ | { | |||
try { | try { | |||
return _wremove(convert(name).c_str()); | return _wremove(convert(name).c_str()); | |||
} | } | |||
catch(bad_utf const &e) { | catch(bad_utf const &e) { | |||
return -1; | return -1; | |||
} | } | |||
} | } | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
0 lines changed or deleted | 16 lines changed or added | |||
date_time.h | date_time.h | |||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
// | // | |||
#ifndef BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | #ifndef BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | |||
#define BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | #define BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <booster/locale/time_zone.h> | #include <booster/locale/hold_ptr.h> | |||
#include <booster/locale/date_time_facet.h> | ||||
#include <locale> | #include <locale> | |||
#include <vector> | #include <vector> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \defgroup date_time Date, Time, Timezone and Calendar manipulat ions | /// \defgroup date_time Date, Time, Timezone and Calendar manipulat ions | |||
/// | /// | |||
/// This module provides various calendar, timezone and date time s ervices | /// This module provides various calendar, timezone and date time s ervices | |||
/// | /// | |||
/// @{ | /// @{ | |||
/// | /// | |||
/// \brief This error is thrown in case of invalid state that occur red | /// \brief This error is thrown in case of invalid state that occur red | |||
/// | /// | |||
class date_time_error : public std::runtime_error { | class date_time_error : public booster::runtime_error { | |||
public: | public: | |||
/// | /// | |||
/// Constructor of date_time_error class | /// Constructor of date_time_error class | |||
/// | /// | |||
date_time_error(std::string const &e) : std::runtime_error(e) { } | date_time_error(std::string const &e) : booster::runtime_error( e) {} | |||
}; | }; | |||
/// | /// | |||
/// \brief Namespace that contains a enum that defines various peri | ||||
ods like years, days | ||||
/// | ||||
namespace period { | ||||
/// | ||||
/// | ||||
/// This enum provides the list of various time periods that ca | ||||
n be used for manipulation over date and time | ||||
/// Operators like +, - * defined for these period allowing to | ||||
perform easy calculations over them | ||||
/// | ||||
typedef enum { | ||||
invalid, ///< Special invalid value, sho | ||||
uld not be used directs | ||||
era, ///< Era i.e. AC, BC in Gregori | ||||
an and Julian calendar, range [0,1] | ||||
year, ///< Year, it is calendar speci | ||||
fic | ||||
extended_year, ///< Extended year for Gregoria | ||||
n/Julian calendars, where 1 BC == 0, 2 BC == -1. | ||||
month, ///< The month of year, calenda | ||||
r specific, in Gregorian [0..11] | ||||
day, ///< The day of month, calendar | ||||
specific, in Gregorian [1..31] | ||||
day_of_year, ///< The number of day in year, | ||||
starting from 1 | ||||
day_of_week, ///< Day of week, starting from | ||||
Sunday, [1..7] | ||||
day_of_week_in_month, ///< Original number of the day | ||||
of the week in month. | ||||
day_of_week_local, ///< Local day of week, for exa | ||||
mple in France Monday is 1, in US Sunday is 1, [1..7] | ||||
hour, ///< 24 clock hour [0..23] | ||||
hour_12, ///< 12 clock hour [0..11] | ||||
am_pm, ///< am or pm marker, [0..1] | ||||
minute, ///< minute [0..59] | ||||
second, ///< second [0..59] | ||||
week_of_year, ///< The week number in the yea | ||||
r | ||||
week_of_month, ///< The week number withing cu | ||||
rrent month | ||||
} period_type; | ||||
} // period | ||||
/// | ||||
/// \brief This structure provides a pair period_type and amount. | /// \brief This structure provides a pair period_type and amount. | |||
/// | /// | |||
/// Usually obtained as product of period_type and integer. | /// Usually obtained as product of period_type and integer. | |||
/// For example day*3 == date_time_period(day,3) | /// For example day*3 == date_time_period(day,3) | |||
/// | /// | |||
struct date_time_period | struct date_time_period | |||
{ | { | |||
period::period_type type; ///< The type of period, i.e. era, year, day etc. | period::period_type type; ///< The type of period, i.e. era, year, day etc. | |||
int value; ///< The value the actual number of \a periods | int value; ///< The value the actual number of \a periods | |||
/// | /// | |||
skipping to change at line 517 | skipping to change at line 488 | |||
if(basic_[3].type == period::invalid) | if(basic_[3].type == period::invalid) | |||
return 3; | return 3; | |||
return 4+periods_.size(); | return 4+periods_.size(); | |||
} | } | |||
/// | /// | |||
/// Get item at position \a n the set, n should be in range [0, size) | /// Get item at position \a n the set, n should be in range [0, size) | |||
/// | /// | |||
date_time_period const &operator[](unsigned n) const | date_time_period const &operator[](unsigned n) const | |||
{ | { | |||
if(n >= size()) | if(n >= size()) | |||
throw std::out_of_range("Invalid index to date_time_per iod"); | throw booster::out_of_range("Invalid index to date_time _period"); | |||
if(n < 4) | if(n < 4) | |||
return basic_[n]; | return basic_[n]; | |||
else | else | |||
return periods_[n-4]; | return periods_[n-4]; | |||
} | } | |||
private: | private: | |||
date_time_period basic_[4]; | date_time_period basic_[4]; | |||
std::vector<date_time_period> periods_; | std::vector<date_time_period> periods_; | |||
}; | }; | |||
skipping to change at line 567 | skipping to change at line 538 | |||
class BOOSTER_API calendar { | class BOOSTER_API calendar { | |||
public: | public: | |||
/// | /// | |||
/// Create calendar taking locale and timezone information from ios_base instance. | /// Create calendar taking locale and timezone information from ios_base instance. | |||
/// | /// | |||
calendar(std::ios_base &ios); | calendar(std::ios_base &ios); | |||
/// | /// | |||
/// Create calendar with locale \a l and time_zone \a zone | /// Create calendar with locale \a l and time_zone \a zone | |||
/// | /// | |||
calendar(std::locale const &l,time_zone const &zone); | calendar(std::locale const &l,std::string const &zone); | |||
/// | /// | |||
/// Create calendar with locale \a l and default timezone | /// Create calendar with locale \a l and default timezone | |||
/// | /// | |||
calendar(std::locale const &l); | calendar(std::locale const &l); | |||
/// | /// | |||
/// Create calendar with default locale and timezone \a zone | /// Create calendar with default locale and timezone \a zone | |||
/// | /// | |||
calendar(time_zone const &zone); | calendar(std::string const &zone); | |||
/// | /// | |||
/// Create calendar with default locale and timezone | /// Create calendar with default locale and timezone | |||
/// | /// | |||
calendar(); | calendar(); | |||
~calendar(); | ~calendar(); | |||
/// | /// | |||
/// copy calendar | /// copy calendar | |||
/// | /// | |||
calendar(calendar const &other); | calendar(calendar const &other); | |||
skipping to change at line 619 | skipping to change at line 590 | |||
/// Get first day of week for specific calendar, for example fo r US it is 1 - Sunday for France it is 2 - Monday | /// Get first day of week for specific calendar, for example fo r US it is 1 - Sunday for France it is 2 - Monday | |||
int first_day_of_week() const; | int first_day_of_week() const; | |||
/// | /// | |||
/// get calendar's locale | /// get calendar's locale | |||
/// | /// | |||
std::locale get_locale() const; | std::locale get_locale() const; | |||
/// | /// | |||
/// get calendar's time zone | /// get calendar's time zone | |||
/// | /// | |||
time_zone get_time_zone() const; | std::string get_time_zone() const; | |||
/// | /// | |||
/// Check if the calendar is Gregorian | /// Check if the calendar is Gregorian | |||
/// | /// | |||
bool is_gregorian() const; | bool is_gregorian() const; | |||
/// | /// | |||
/// Compare calendars for equivalence: i.e. calendar types, tim e zones etc. | /// Compare calendars for equivalence: i.e. calendar types, tim e zones etc. | |||
/// | /// | |||
bool operator==(calendar const &other) const; | bool operator==(calendar const &other) const; | |||
/// | /// | |||
/// Opposite of == | /// Opposite of == | |||
/// | /// | |||
bool operator!=(calendar const &other) const; | bool operator!=(calendar const &other) const; | |||
private: | private: | |||
friend class date_time; | friend class date_time; | |||
std::locale locale_; | std::locale locale_; | |||
booster::locale::time_zone tz_; | std::string tz_; | |||
void *impl_; | hold_ptr<abstract_calendar> impl_; | |||
}; | }; | |||
/// | /// | |||
/// \brief this class represents a date time and allows to perform various operation according to the | /// \brief this class represents a date time and allows to perform various operation according to the | |||
/// locale settings. | /// locale settings. | |||
/// | /// | |||
/// This class allows to manipulate various aspects of dates and ti mes easily using arithmetic operations with | /// This class allows to manipulate various aspects of dates and ti mes easily using arithmetic operations with | |||
/// periods. | /// periods. | |||
/// | /// | |||
/// General arithmetic functions: | /// General arithmetic functions: | |||
skipping to change at line 908 | skipping to change at line 879 | |||
/// swaps two dates - efficient, does not throw | /// swaps two dates - efficient, does not throw | |||
/// | /// | |||
void swap(date_time &other); | void swap(date_time &other); | |||
/// | /// | |||
/// calculate the distance from this date_time to \a other in t erms of perios \a f | /// calculate the distance from this date_time to \a other in t erms of perios \a f | |||
/// | /// | |||
int difference(date_time const &other,period::period_type f) co nst; | int difference(date_time const &other,period::period_type f) co nst; | |||
/// | /// | |||
/// calculate the distance from this date_time to \a other in t | ||||
erms of perios \a f | ||||
/// | ||||
int difference(date_time const &other,period::period_type f); | ||||
/// | ||||
/// Get minimal possible value for current time point for a per iod \a f. | /// Get minimal possible value for current time point for a per iod \a f. | |||
/// | /// | |||
int minimum(period::period_type f) const; | int minimum(period::period_type f) const; | |||
/// | /// | |||
/// Get minimal possible value for current time point for a per iod \a f. For example | /// Get minimal possible value for current time point for a per iod \a f. For example | |||
/// in February maximum(day) may be 28 or 29, in January maximu m(day)==31 | /// in February maximum(day) may be 28 or 29, in January maximu m(day)==31 | |||
/// | /// | |||
int maximum(period::period_type f) const; | int maximum(period::period_type f) const; | |||
private: | private: | |||
void *impl_; | hold_ptr<abstract_calendar> impl_; | |||
}; | }; | |||
/// | /// | |||
/// Writes date_time \a t to output stream \a out. | /// Writes date_time \a t to output stream \a out. | |||
/// | /// | |||
/// This function uses locale, calendar and time zone of the target stream \a in. | /// This function uses locale, calendar and time zone of the target stream \a in. | |||
/// | /// | |||
/// For example: | /// For example: | |||
/// \code | /// \code | |||
/// date_time now(time(0),hebrew_calendar) | /// date_time now(time(0),hebrew_calendar) | |||
skipping to change at line 1011 | skipping to change at line 977 | |||
/// | /// | |||
/// Calculates the difference between two dates, the left operand i s a later point on time line. | /// Calculates the difference between two dates, the left operand i s a later point on time line. | |||
/// Returns date_time_duration object. | /// Returns date_time_duration object. | |||
/// | /// | |||
inline date_time_duration operator-(date_time const &later,date_tim e const &earlier) | inline date_time_duration operator-(date_time const &later,date_tim e const &earlier) | |||
{ | { | |||
return date_time_duration(earlier,later); | return date_time_duration(earlier,later); | |||
} | } | |||
/// | ||||
/// \brief namespace that holds function for operating global time | ||||
zone identifier | ||||
/// | ||||
namespace time_zone { | ||||
/// | ||||
/// Get global time zone identifier. If empty, system time zone | ||||
is used | ||||
/// | ||||
BOOSTER_API std::string global(); | ||||
/// | ||||
/// Set global time zone identifier returing pervious one. If e | ||||
mpty, system time zone is used | ||||
/// | ||||
BOOSTER_API std::string global(std::string const &new_tz); | ||||
} | ||||
/// @} | /// @} | |||
} // locale | } // locale | |||
} // boost | } // boost | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
#pragma warning(pop) | #pragma warning(pop) | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 13 change blocks. | ||||
62 lines changed or deleted | 29 lines changed or added | |||
encoding.h | encoding.h | |||
---|---|---|---|---|
/////////////////////////////////////////////////////////////////////////// | ||||
//// | ||||
// | ||||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | ||||
// | // | |||
// This program is free software: you can redistribute it and/or modify | // Copyright (c) 2009-2010 Artyom Beilis (Tonkikh) | |||
// it under the terms of the GNU Lesser General Public License as publishe | ||||
d by | ||||
// the Free Software Foundation, either version 3 of the License, or | ||||
// (at your option) any later version. | ||||
// | ||||
// This program is distributed in the hope that it will be useful, | ||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
// GNU Lesser General Public License for more details. | ||||
// | // | |||
// You should have received a copy of the GNU Lesser General Public Licens | // Distributed under the Boost Software License, Version 1.0. (See | |||
e | // accompanying file LICENSE_1_0.txt or copy at | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// | #ifndef BOOSTER_LOCALE_ENCODING_H_INCLUDED | |||
//// | #define BOOSTER_LOCALE_ENCODING_H_INCLUDED | |||
#ifndef CPPCMS_ENCODING_H | ||||
#define CPPCMS_ENCODING_H | ||||
#include <string> | #include <booster/config.h> | |||
#include <map> | #ifdef BOOSTER_MSVC | |||
#include <locale> | # pragma warning(push) | |||
#include <cppcms/defs.h> | # pragma warning(disable : 4275 4251 4231 4660) | |||
#include <cppcms/config.h> | #endif | |||
#include <booster/locale/info.h> | ||||
#include <booster/cstdint.h> | ||||
#include <booster/backtrace.h> | ||||
namespace cppcms { | namespace booster { | |||
/// | namespace locale { | |||
/// \brief this Namespace holds various function for dealing with en | ||||
coding | ||||
/// | ||||
/// | ||||
namespace encoding { | ||||
/// Note: all these function assume that control characters | /// | |||
that invalid in HTML are illegal. | /// \brief Namespace that contains all functions related to charact | |||
/// For example. NUL is legal UTF-8 code but it is illegal i | er set conversion | |||
n terms of HTML validity thus, | /// | |||
/// valid_utf8 would return false. | namespace conv { | |||
/// | ||||
/// \defgroup codepage Character conversion functions | ||||
/// | ||||
/// @{ | ||||
/// | /// | |||
/// Check if string in range [begin,end) is valid in the loc | /// \brief The excepton that is thrown in case of conversion er | |||
ale \a loc and does not include | ror | |||
/// HTML illegal characters. Number of codepoints is stored | /// | |||
in \a count | class conversion_error : public booster::runtime_error { | |||
/// | public: | |||
bool CPPCMS_API valid(std::locale const &loc,char const *beg | conversion_error() : booster::runtime_error("Conversion fai | |||
in,char const *end,size_t &count); | led") {} | |||
/// | }; | |||
/// Check if string in range [begin,end) is valid UTF-8 and | ||||
does not include | ||||
/// HTML illegal characters. Number of codepoints is stored | ||||
in \a count | ||||
/// | ||||
bool CPPCMS_API valid_utf8(char const *begin,char const *end | ||||
,size_t &count); | ||||
/// | ||||
/// Check if string in range [begin,end) is valid encoding \ | ||||
a encoding and does not include | ||||
/// HTML illegal characters. Number of codepoints is stored | ||||
in \a count | ||||
/// | ||||
bool CPPCMS_API valid(char const *encoding,char const *begin | ||||
,char const *end,size_t &count); | ||||
/// | ||||
/// Check if string in range [begin,end) is valid encoding \ | ||||
a encoding and does not include | ||||
/// HTML illegal characters. Number of codepoints is stored | ||||
in \a count | ||||
/// | ||||
bool CPPCMS_API valid(std::string const &encoding,char const | ||||
*begin,char const *end,size_t &count); | ||||
#if defined(CPPCMS_HAVE_ICU) || defined(CPPCMS_HAVE_ICONV) | /// | |||
/// \brief This exception is thrown in case of use of unsupport | ||||
ed | ||||
/// or invalid character set | ||||
/// | ||||
class invalid_charset_error : public booster::runtime_error { | ||||
public: | ||||
/// | /// Create an error for charset \a charset | |||
/// Convert string in range [begin,end) from local 8 bit enc | invalid_charset_error(std::string charset) : | |||
oding according to locale \a loc to UTF-8 | booster::runtime_error("Invalid or unsupported charset: | |||
/// If illegal characters found, the conversion is aborted a | " + charset) | |||
nd only sucessefully converted part is returned. | { | |||
/// | } | |||
std::string CPPCMS_API to_utf8(std::locale const &loc,char c | }; | |||
onst *begin,char const *end); | ||||
/// | ||||
/// Convert string in range [begin,end) from local 8 bit enc | ||||
oding \a encoding to UTF-8 | ||||
/// If illegal characters found, the conversion is aborted a | ||||
nd only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API to_utf8(char const *encoding,char con | ||||
st *begin,char const *end); | ||||
/// | ||||
/// Convert string \a str from local 8 bit encoding accordin | ||||
g to locale \a loc to UTF-8 | ||||
/// If illegal characters found, the conversion is aborted a | ||||
nd only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API to_utf8(std::locale const &loc,std::s | ||||
tring const &str); | ||||
/// | ||||
/// Convert string \a str from local 8 bit encoding accordin | ||||
g to encoding \a encoding | ||||
/// If illegal characters found, the conversion is aborted a | ||||
nd only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API to_utf8(char const *encoding,std::str | ||||
ing const &str); | ||||
/// | /// | |||
/// Convert UTF-8 string in range [begin,end) to local 8 bit | /// enum that defines conversion policy | |||
encoding according to locale \a loc. | /// | |||
/// If non-convertable characters found, the conversion is a | typedef enum { | |||
borted and only sucessefully converted part is returned. | skip = 0, ///< Skip illegal/unconvertable cha | |||
/// | racters | |||
std::string CPPCMS_API from_utf8(std::locale const &loc,char | stop = 1, ///< Stop conversion and throw conv | |||
const *begin,char const *end); | ersion_error | |||
/// | default_method = skip ///< Default method - skip | |||
/// Convert UTF-8 string in range [begin,end) to local 8 bit | } method_type; | |||
encoding \a encoding. | ||||
/// If non-convertable characters found, the conversion is a | ||||
borted and only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API from_utf8(char const *encoding,char c | ||||
onst *begin,char const *end); | ||||
/// | ||||
/// Convert UTF-8 string \a str to local 8 bit encoding acco | ||||
rding to locale \a loc. | ||||
/// If non-convertable characters found, the conversion is a | ||||
borted and only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API from_utf8(std::locale const &loc,std: | ||||
:string const &str); | ||||
/// | ||||
/// Convert UTF-8 string \a str to local 8 bit encoding \a e | ||||
ncoding. | ||||
/// If non-convertable characters found, the conversion is a | ||||
borted and only sucessefully converted part is returned. | ||||
/// | ||||
std::string CPPCMS_API from_utf8(char const *encoding,std::s | ||||
tring const &str); | ||||
#endif | /// | |||
/// convert string to UTF string from text in range [begin,end) | ||||
encoded with \a charset according to policy \a how | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(char const *begin,char const | ||||
*end,std::string const &charset,method_type how=default_method); | ||||
} // encoding | /// | |||
} // cppcms | /// convert UTF text in range [begin,end) to a text encoded wit | |||
h \a charset according to policy \a how | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(CharType const *begin,CharType const *end, | ||||
std::string const &charset,method_type how=default_method); | ||||
/// | ||||
/// convert string to UTF string from text in range [begin,end) | ||||
encoded according to locale \a loc according to policy \a how | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(char const *begin,char const | ||||
*end,std::locale const &loc,method_type how=default_method) | ||||
{ | ||||
return to_utf<CharType>(begin,end,std::use_facet<info>(loc) | ||||
.encoding(),how); | ||||
} | ||||
/// | ||||
/// convert UTF text in range [begin,end) to a text encoded acc | ||||
ording to locale \a loc according to policy \a how | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(CharType const *begin,CharType const *end, | ||||
std::locale const &loc,method_type how=default_method) | ||||
{ | ||||
return from_utf(begin,end,std::use_facet<info>(loc).encodin | ||||
g(),how); | ||||
} | ||||
/// | ||||
/// convert a string \a text encoded with \a charset to UTF str | ||||
ing | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(std::string const &text,std: | ||||
:string const &charset,method_type how=default_method) | ||||
{ | ||||
return to_utf<CharType>(text.c_str(),text.c_str()+text.size | ||||
(),charset,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text from \a charset to UTF string | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(std::basic_string<CharType> const &text,st | ||||
d::string const &charset,method_type how=default_method) | ||||
{ | ||||
return from_utf(text.c_str(),text.c_str()+text.size(),chars | ||||
et,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text from \a charset to UTF string | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(char const *text,std::string | ||||
const &charset,method_type how=default_method) | ||||
{ | ||||
char const *text_end = text; | ||||
while(*text_end) | ||||
text_end++; | ||||
return to_utf<CharType>(text,text_end,charset,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text from UTF to \a charset | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(CharType const *text,std::string const &ch | ||||
arset,method_type how=default_method) | ||||
{ | ||||
CharType const *text_end = text; | ||||
while(*text_end) | ||||
text_end++; | ||||
return from_utf(text,text_end,charset,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text in locale encoding given by \a loc to UTF | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(std::string const &text,std: | ||||
:locale const &loc,method_type how=default_method) | ||||
{ | ||||
return to_utf<CharType>(text.c_str(),text.c_str()+text.size | ||||
(),loc,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text in UTF to locale encoding given by \a loc | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(std::basic_string<CharType> const &text,st | ||||
d::locale const &loc,method_type how=default_method) | ||||
{ | ||||
return from_utf(text.c_str(),text.c_str()+text.size(),loc,h | ||||
ow); | ||||
} | ||||
/// | ||||
/// Convert a \a text in locale encoding given by \a loc to UTF | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> to_utf(char const *text,std::locale | ||||
const &loc,method_type how=default_method) | ||||
{ | ||||
char const *text_end = text; | ||||
while(*text_end) | ||||
text_end++; | ||||
return to_utf<CharType>(text,text_end,loc,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text in UTF to locale encoding given by \a loc | ||||
/// | ||||
template<typename CharType> | ||||
std::string from_utf(CharType const *text,std::locale const &lo | ||||
c,method_type how=default_method) | ||||
{ | ||||
CharType const *text_end = text; | ||||
while(*text_end) | ||||
text_end++; | ||||
return from_utf(text,text_end,loc,how); | ||||
} | ||||
/// | ||||
/// Convert a text in range [begin,end) to \a to_encoding from | ||||
\a from_encoding | ||||
/// | ||||
BOOSTER_API | ||||
std::string between(char const *begin, | ||||
char const *end, | ||||
std::string const &to_encoding, | ||||
std::string const &from_encoding, | ||||
method_type how=default_method); | ||||
/// | ||||
/// Convert a \a text to \a to_encoding from \a from_encoding | ||||
/// | ||||
inline | ||||
std::string between(char const *text, | ||||
std::string const &to_encoding, | ||||
std::string const &from_encoding, | ||||
method_type how=default_method) | ||||
{ | ||||
char const *end=text; | ||||
while(*end) | ||||
end++; | ||||
return between(text,end,to_encoding,from_encoding,how); | ||||
} | ||||
/// | ||||
/// Convert a \a text to \a to_encoding from \a from_encoding | ||||
/// | ||||
inline | ||||
std::string between(std::string const &text, | ||||
std::string const &to_encoding, | ||||
std::string const &from_encoding, | ||||
method_type how=default_method) | ||||
{ | ||||
return between(text.c_str(),text.c_str()+text.size(),to_enc | ||||
oding,from_encoding,how); | ||||
} | ||||
/// @} | ||||
/// \cond INTERNAL | ||||
template<> | ||||
BOOSTER_API std::basic_string<char> to_utf(char const *begin,ch | ||||
ar const *end,std::string const &charset,method_type how); | ||||
template<> | ||||
BOOSTER_API std::string from_utf(char const *begin,char const * | ||||
end,std::string const &charset,method_type how); | ||||
template<> | ||||
BOOSTER_API std::basic_string<wchar_t> to_utf(char const *begin | ||||
,char const *end,std::string const &charset,method_type how); | ||||
template<> | ||||
BOOSTER_API std::string from_utf(wchar_t const *begin,wchar_t c | ||||
onst *end,std::string const &charset,method_type how); | ||||
#ifdef BOOSTER_HAS_CHAR16_T | ||||
template<> | ||||
BOOSTER_API std::basic_string<char16_t> to_utf(char const *begi | ||||
n,char const *end,std::string const &charset,method_type how); | ||||
template<> | ||||
BOOSTER_API std::string from_utf(char16_t const *begin,char16_t | ||||
const *end,std::string const &charset,method_type how); | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR32_T | ||||
template<> | ||||
BOOSTER_API std::basic_string<char32_t> to_utf(char const *begi | ||||
n,char const *end,std::string const &charset,method_type how); | ||||
template<> | ||||
BOOSTER_API std::string from_utf(char32_t const *begin,char32_t | ||||
const *end,std::string const &charset,method_type how); | ||||
#endif | ||||
/// \endcond | ||||
} // conv | ||||
} // locale | ||||
} // boost | ||||
#ifdef BOOSTER_MSVC | ||||
#pragma warning(pop) | ||||
#endif | ||||
#endif | #endif | |||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||||
End of changes. 14 change blocks. | ||||
138 lines changed or deleted | 285 lines changed or added | |||
filters.h | filters.h | |||
---|---|---|---|---|
skipping to change at line 423 | skipping to change at line 423 | |||
/// | /// | |||
datetime(streamable const &time,std::string const &t imezone); | datetime(streamable const &time,std::string const &t imezone); | |||
void operator()(std::ostream &out) const; | void operator()(std::ostream &out) const; | |||
private: | private: | |||
struct _data; | struct _data; | |||
streamable time_; | streamable time_; | |||
std::string tz_; | std::string tz_; | |||
booster::copy_ptr<_data> d; | booster::copy_ptr<_data> d; | |||
}; | }; | |||
inline std::ostream &operator<<(std::ostream &out,datetime c | ||||
onst &obj) | ||||
{ | ||||
obj(out); | ||||
return out; | ||||
} | ||||
/// | /// | |||
/// \brief Custom time formating filter | /// \brief Custom time formating filter | |||
/// | /// | |||
/// Formats date and time to the stream, date and time is re presented as time_t | /// Formats date and time to the stream, date and time is re presented as time_t | |||
/// | /// | |||
class CPPCMS_API strftime { | class CPPCMS_API strftime { | |||
public: | public: | |||
strftime(); | strftime(); | |||
strftime(strftime const &other); | strftime(strftime const &other); | |||
strftime const &operator=(strftime const &other); | strftime const &operator=(strftime const &other); | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 6 lines changed or added | |||
format.h | format.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <booster/locale/message.h> | #include <booster/locale/message.h> | |||
#include <booster/locale/formatting.h> | #include <booster/locale/formatting.h> | |||
#include <sstream> | #include <sstream> | |||
#include <iostream> | ||||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \defgroup format Format | /// \defgroup format Format | |||
/// | /// | |||
/// This module provides printf like functionality integrated to io streams and suitable for localization | /// This module provides printf like functionality integrated to io streams and suitable for localization | |||
/// | /// | |||
/// @{ | /// @{ | |||
skipping to change at line 101 | skipping to change at line 100 | |||
{ | { | |||
output << *reinterpret_cast<Type const *>(ptr); | output << *reinterpret_cast<Type const *>(ptr); | |||
} | } | |||
void const *pointer_; | void const *pointer_; | |||
writer_type writer_; | writer_type writer_; | |||
}; // formattible | }; // formattible | |||
class BOOSTER_API format_parser { | class BOOSTER_API format_parser { | |||
public: | public: | |||
format_parser(std::ios_base &ios); | format_parser(std::ios_base &ios,void *,void (*imbuer)(void *,std::locale const &)); | |||
~format_parser(); | ~format_parser(); | |||
unsigned get_posision(); | unsigned get_posision(); | |||
void set_one_flag(std::string const &key,std::string const &value); | void set_one_flag(std::string const &key,std::string const &value); | |||
template<typename CharType> | template<typename CharType> | |||
void set_flag_with_str(std::string const &key,std::basic_st ring<CharType> const &value) | void set_flag_with_str(std::string const &key,std::basic_st ring<CharType> const &value) | |||
{ | { | |||
if(key=="ftime" || key=="strftime") { | if(key=="ftime" || key=="strftime") { | |||
as::strftime(ios_); | as::strftime(ios_); | |||
ext_pattern(ios_,flags::datetime_pattern,value); | ios_info::get(ios_).date_time_pattern(value); | |||
} | } | |||
} | } | |||
void restore(); | void restore(); | |||
private: | private: | |||
void imbue(std::locale const &); | ||||
format_parser(format_parser const &); | format_parser(format_parser const &); | |||
void operator=(format_parser const &); | void operator=(format_parser const &); | |||
std::ios_base &ios_; | std::ios_base &ios_; | |||
struct data; | struct data; | |||
std::auto_ptr<data> d; | std::auto_ptr<data> d; | |||
}; | }; | |||
} | } | |||
skipping to change at line 244 | skipping to change at line 244 | |||
return buffer.str(); | return buffer.str(); | |||
} | } | |||
/// | /// | |||
/// write a formatted string to output stream \a out using out' s locale | /// write a formatted string to output stream \a out using out' s locale | |||
/// | /// | |||
void write(stream_type &out) const | void write(stream_type &out) const | |||
{ | { | |||
string_type format; | string_type format; | |||
if(translate_) | if(translate_) | |||
format = message_.str<CharType>(out.getloc(),ext_value( out,flags::domain_id)); | format = message_.str<CharType>(out.getloc(),ios_info:: get(out).domain_id()); | |||
else | else | |||
format = format_; | format = format_; | |||
format_output(out,format); | format_output(out,format); | |||
} | } | |||
private: | private: | |||
void format_output(stream_type &out,string_type const &sformat) const | void format_output(stream_type &out,string_type const &sformat) const | |||
skipping to change at line 285 | skipping to change at line 285 | |||
continue; | continue; | |||
} | } | |||
if(pos+1 < size && format[pos+1]==obrk) { | if(pos+1 < size && format[pos+1]==obrk) { | |||
out << obrk; | out << obrk; | |||
pos+=2; | pos+=2; | |||
continue; | continue; | |||
} | } | |||
pos++; | pos++; | |||
details::format_parser fmt(out); | details::format_parser fmt(out,reinterpret_cast<void *> (&out),&basic_format::imbue_locale); | |||
while(pos < size) { | while(pos < size) { | |||
std::string key; | std::string key; | |||
std::string svalue; | std::string svalue; | |||
string_type value; | string_type value; | |||
bool use_svalue = true; | bool use_svalue = true; | |||
for(;format[pos];pos++) { | for(;format[pos];pos++) { | |||
char_type c=format[pos]; | char_type c=format[pos]; | |||
if(c==comma || c==eq || c==cbrk) | if(c==comma || c==eq || c==cbrk) | |||
break; | break; | |||
skipping to change at line 332 | skipping to change at line 332 | |||
} | } | |||
else { | else { | |||
char_type c; | char_type c; | |||
while((c=format[pos])!=0 && c!=comma && c!= cbrk) { | while((c=format[pos])!=0 && c!=comma && c!= cbrk) { | |||
svalue+=static_cast<char>(c); | svalue+=static_cast<char>(c); | |||
pos++; | pos++; | |||
} | } | |||
} | } | |||
} | } | |||
if(use_svalue) | if(use_svalue) { | |||
fmt.set_one_flag(key,svalue); | fmt.set_one_flag(key,svalue); | |||
} | ||||
else | else | |||
fmt.set_flag_with_str(key,value); | fmt.set_flag_with_str(key,value); | |||
if(format[pos]==',') { | if(format[pos]==',') { | |||
pos++; | pos++; | |||
continue; | continue; | |||
} | } | |||
else if(format[pos]=='}') { | else if(format[pos]=='}') { | |||
unsigned position = fmt.get_posision(); | unsigned position = fmt.get_posision(); | |||
out << get(position); | out << get(position); | |||
skipping to change at line 381 | skipping to change at line 382 | |||
formattible_type get(unsigned id) const | formattible_type get(unsigned id) const | |||
{ | { | |||
if(id >= parameters_count_) | if(id >= parameters_count_) | |||
return formattible_type(); | return formattible_type(); | |||
else if(id >= base_params_) | else if(id >= base_params_) | |||
return ext_params_[id - base_params_]; | return ext_params_[id - base_params_]; | |||
else | else | |||
return parameters_[id]; | return parameters_[id]; | |||
} | } | |||
static void imbue_locale(void *ptr,std::locale const &l) | ||||
{ | ||||
reinterpret_cast<stream_type *>(ptr)->imbue(l); | ||||
} | ||||
static unsigned const base_params_ = 8; | static unsigned const base_params_ = 8; | |||
message message_; | message message_; | |||
string_type format_; | string_type format_; | |||
bool translate_; | bool translate_; | |||
formattible_type parameters_[base_params_]; | formattible_type parameters_[base_params_]; | |||
unsigned parameters_count_; | unsigned parameters_count_; | |||
std::vector<formattible_type> ext_params_; | std::vector<formattible_type> ext_params_; | |||
}; | }; | |||
skipping to change at line 409 | skipping to change at line 415 | |||
{ | { | |||
fmt.write(out); | fmt.write(out); | |||
return out; | return out; | |||
} | } | |||
/// | /// | |||
/// Definiton of char based format | /// Definiton of char based format | |||
/// | /// | |||
typedef basic_format<char> format; | typedef basic_format<char> format; | |||
#ifndef BOOSTER_NO_STD_WSTRING | ||||
/// | /// | |||
/// Definiton of wchar_t based format | /// Definiton of wchar_t based format | |||
/// | /// | |||
typedef basic_format<wchar_t> wformat; | typedef basic_format<wchar_t> wformat; | |||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR16_T | #ifdef BOOSTER_HAS_CHAR16_T | |||
/// | /// | |||
/// Definiton of char16_t based format | /// Definiton of char16_t based format | |||
/// | /// | |||
typedef basic_format<char16_t> u16format; | typedef basic_format<char16_t> u16format; | |||
#endif | #endif | |||
#ifdef BOOSTER_HAS_CHAR32_T | #ifdef BOOSTER_HAS_CHAR32_T | |||
/// | /// | |||
End of changes. 11 change blocks. | ||||
8 lines changed or deleted | 12 lines changed or added | |||
formatting.h | formatting.h | |||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_LOCALE_FORMATTING_H_INCLUDED | #ifndef BOOSTER_LOCALE_FORMATTING_H_INCLUDED | |||
#define BOOSTER_LOCALE_FORMATTING_H_INCLUDED | #define BOOSTER_LOCALE_FORMATTING_H_INCLUDED | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <booster/locale/time_zone.h> | ||||
#include <booster/cstdint.h> | #include <booster/cstdint.h> | |||
#include <booster/locale/date_time.h> | ||||
#include <ostream> | #include <ostream> | |||
#include <istream> | #include <istream> | |||
#include <string> | #include <string> | |||
#include <string.h> | ||||
#include <typeinfo> | ||||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | ||||
/// This namespace holds additional formatting | ||||
/// flags that can be set using ios_info. | ||||
/// | ||||
namespace flags { | namespace flags { | |||
/// | ||||
/// Formatting flags, each one of them has corresponding manipu | ||||
lation | ||||
/// in namespace \a as | ||||
/// | ||||
typedef enum { | typedef enum { | |||
posix = 0, | posix = 0, | |||
number = 1, | number = 1, | |||
currency = 2, | currency = 2, | |||
percent = 3, | percent = 3, | |||
date = 4, | date = 4, | |||
time = 5, | time = 5, | |||
datetime = 6, | datetime = 6, | |||
strftime = 7, | strftime = 7, | |||
spellout = 8, | spellout = 8, | |||
skipping to change at line 63 | skipping to change at line 73 | |||
date_short = 1 << 10, | date_short = 1 << 10, | |||
date_medium = 2 << 10, | date_medium = 2 << 10, | |||
date_long = 3 << 10, | date_long = 3 << 10, | |||
date_full = 4 << 10, | date_full = 4 << 10, | |||
date_flags_mask = 7 << 10, | date_flags_mask = 7 << 10, | |||
datetime_flags_mask = date_flags_mask | time_flags_mask | datetime_flags_mask = date_flags_mask | time_flags_mask | |||
} display_flags_type; | } display_flags_type; | |||
/// | ||||
/// Special string patters that can be used | ||||
/// for text formatting | ||||
/// | ||||
typedef enum { | typedef enum { | |||
datetime_pattern, | datetime_pattern, ///< strftime like formatting | |||
time_zone_id | time_zone_id ///< time zone name | |||
} pattern_type; | } pattern_type; | |||
/// | ||||
/// Special integer values that can be used for formatting | ||||
/// | ||||
typedef enum { | typedef enum { | |||
domain_id | domain_id ///< Domain code - for message formatti ng | |||
} value_type; | } value_type; | |||
} // flags | } // flags | |||
/// \cond INTERNAL | /// | |||
/// \brief This class holds an external data - beyond existing fmtf | ||||
lags that std::ios_base holds | ||||
/// | ||||
/// You almost never create this object directly, you rather access | ||||
it via ios_info::get(stream_object) | ||||
/// static member function. It automatically creates default format | ||||
ting data for that stream | ||||
/// | ||||
class BOOSTER_API ios_info { | ||||
public: | ||||
BOOSTER_API uint64_t ext_flags(std::ios_base &); | /// \cond INTERNAL | |||
BOOSTER_API uint64_t ext_flags(std::ios_base &,flags::display_flags | ||||
_type mask); | ||||
BOOSTER_API void ext_setf(std::ios_base &,flags::display_flags_type | ||||
flags,flags::display_flags_type mask); | ||||
BOOSTER_API int ext_value(std::ios_base &,flags::value_type id); | ios_info(); | |||
BOOSTER_API void ext_value(std::ios_base &,flags::value_type id,int | ios_info(ios_info const &); | |||
value); | ios_info const &operator=(ios_info const &); | |||
~ios_info(); | ||||
template<typename CharType> | /// \endcond | |||
void ext_pattern(std::ios_base &,flags::pattern_type pat,std::basic | ||||
_string<CharType> const &); | ||||
template<typename CharType> | /// | |||
std::basic_string<CharType> ext_pattern(std::ios_base &,flags::patt | /// Get ios_info instance for specific stream object | |||
ern_type pattern); | /// | |||
static ios_info &get(std::ios_base &ios); | ||||
/// Specializations | /// | |||
/// Set a flags that define a way for format data like number, | ||||
spell, currency etc. | ||||
/// | ||||
void display_flags(uint64_t flags); | ||||
template<> | /// | |||
BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | /// Set a flags that define how to format currency | |||
ttern_id, std::string const &pattern); | /// | |||
void currency_flags(uint64_t flags); | ||||
template<> | /// | |||
BOOSTER_API std::string ext_pattern(std::ios_base &,flags::pattern_ | /// Set a flags that define how to format date | |||
type pattern_id); | /// | |||
void date_flags(uint64_t flags); | ||||
#ifndef BOOSTER_NO_STD_WSTRING | /// | |||
/// Set a flags that define how to format time | ||||
/// | ||||
void time_flags(uint64_t flags); | ||||
template<> | /// | |||
BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | /// Set a flags that define how to format both date and time | |||
ttern_id, std::wstring const &pattern); | /// | |||
void datetime_flags(uint64_t flags); | ||||
template<> | /// | |||
BOOSTER_API std::wstring ext_pattern(std::ios_base &,flags::pattern | /// Set special message domain identification | |||
_type pattern_id); | /// | |||
void domain_id(int); | ||||
#endif // BOOST_NO_STD_WSTRING | /// | |||
/// Set time zone for formatting dates and time | ||||
/// | ||||
void time_zone(std::string const &); | ||||
#ifdef BOOSTER_HAS_CHAR16_T | /// | |||
template<> | /// Set date/time pattern (strftime like) | |||
BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | /// | |||
ttern_id, std::u16string const &pattern); | template<typename CharType> | |||
void date_time_pattern(std::basic_string<CharType> const &str) | ||||
{ | ||||
string_set &s = date_time_pattern_set(); | ||||
s.set<CharType>(str.c_str()); | ||||
} | ||||
template<> | /// | |||
BOOSTER_API std::u16string ext_pattern(std::ios_base &,flags::patte | /// Get a flags that define a way for format data like number, | |||
rn_type pattern_id); | spell, currency etc. | |||
#endif // char16_t, u16string | /// | |||
uint64_t display_flags() const; | ||||
#ifdef BOOSTER_HAS_CHAR32_T | /// | |||
template<> | /// Get a flags that define how to format currency | |||
BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | /// | |||
ttern_id, std::u32string const &pattern); | uint64_t currency_flags() const; | |||
template<> | /// | |||
BOOSTER_API std::u32string ext_pattern(std::ios_base &,flags::patte | /// Get a flags that define how to format date | |||
rn_type pattern_id); | /// | |||
#endif // char32_t, u32string | uint64_t date_flags() const; | |||
/// \endcond | /// | |||
/// Get a flags that define how to format time | ||||
/// | ||||
uint64_t time_flags() const; | ||||
/// | ||||
/// Get a flags that define how to format both date and time | ||||
/// | ||||
uint64_t datetime_flags() const; | ||||
/// | ||||
/// Get special message domain identification | ||||
/// | ||||
int domain_id() const; | ||||
/// | ||||
/// Get time zone for formatting dates and time | ||||
/// | ||||
std::string time_zone() const; | ||||
/// | ||||
/// Get date/time pattern (strftime like) | ||||
/// | ||||
template<typename CharType> | ||||
std::basic_string<CharType> date_time_pattern() const | ||||
{ | ||||
string_set const &s = date_time_pattern_set(); | ||||
return s.get<CharType>(); | ||||
} | ||||
/// \cond INTERNAL | ||||
void on_imbue(); | ||||
/// \endcond | ||||
private: | ||||
class string_set; | ||||
string_set const &date_time_pattern_set() const; | ||||
string_set &date_time_pattern_set(); | ||||
class BOOSTER_API string_set { | ||||
public: | ||||
string_set(); | ||||
~string_set(); | ||||
string_set(string_set const &other); | ||||
string_set const &operator=(string_set const &other); | ||||
template<typename Char> | ||||
void set(Char const *s) | ||||
{ | ||||
delete [] ptr; | ||||
ptr = 0; | ||||
type=&typeid(Char); | ||||
Char const *end = s; | ||||
while(*end!=0) end++; | ||||
size = sizeof(Char)*(end - s+1); | ||||
ptr = new char[size]; | ||||
memcpy(ptr,s,size); | ||||
} | ||||
template<typename Char> | ||||
std::basic_string<Char> get() const | ||||
{ | ||||
if(type==0 || *type!=typeid(Char)) | ||||
throw std::bad_cast(); | ||||
std::basic_string<Char> result = reinterpret_cast<Char | ||||
const *>(ptr); | ||||
return result; | ||||
} | ||||
private: | ||||
std::type_info const *type; | ||||
size_t size; | ||||
char *ptr; | ||||
}; | ||||
uint64_t flags_; | ||||
int domain_id_; | ||||
std::string time_zone_; | ||||
string_set datetime_; | ||||
struct data; | ||||
data *d; | ||||
}; | ||||
/// | /// | |||
/// \brief This namespace includes all manipulators that can be use d on IO streams | /// \brief This namespace includes all manipulators that can be use d on IO streams | |||
/// | /// | |||
namespace as { | namespace as { | |||
/// | /// | |||
/// \defgroup manipulators I/O Stream manipulators | /// \defgroup manipulators I/O Stream manipulators | |||
/// | /// | |||
/// @{ | /// @{ | |||
/// | /// | |||
/// | /// | |||
/// Format values with "POSIX" or "C" locale. Note, if locale was created with additional non-classic locale then | /// Format values with "POSIX" or "C" locale. Note, if locale was created with additional non-classic locale then | |||
/// These numbers may be localized | /// These numbers may be localized | |||
/// | /// | |||
inline std::ios_base & posix(std::ios_base & ios) | inline std::ios_base & posix(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::posix, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::posix); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format a number. Note, unlike standard number formatting, i ntegers would be treated like real numbers when std::fixed or | /// Format a number. Note, unlike standard number formatting, i ntegers would be treated like real numbers when std::fixed or | |||
/// std::scientific manipulators were applied | /// std::scientific manipulators were applied | |||
/// | /// | |||
inline std::ios_base & number(std::ios_base & ios) | inline std::ios_base & number(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::number, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::number); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format currency, number is treated like amount of money | /// Format currency, number is treated like amount of money | |||
/// | /// | |||
inline std::ios_base & currency(std::ios_base & ios) | inline std::ios_base & currency(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::currency, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::currency); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format percent, value 0.3 is treaded as 30%. | /// Format percent, value 0.3 is treaded as 30%. | |||
/// | /// | |||
inline std::ios_base & percent(std::ios_base & ios) | inline std::ios_base & percent(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::percent, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::percent); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format a date, number is treaded as POSIX time | /// Format a date, number is treaded as POSIX time | |||
/// | /// | |||
inline std::ios_base & date(std::ios_base & ios) | inline std::ios_base & date(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::date); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format a time, number is treaded as POSIX time | /// Format a time, number is treaded as POSIX time | |||
/// | /// | |||
inline std::ios_base & time(std::ios_base & ios) | inline std::ios_base & time(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::time); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Format a date and time, number is treaded as POSIX time | /// Format a date and time, number is treaded as POSIX time | |||
/// | /// | |||
inline std::ios_base & datetime(std::ios_base & ios) | inline std::ios_base & datetime(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::datetime, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::datetime); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Create formatted date time, Please note, this manipulator o nly changes formatting mode, | /// Create formatted date time, Please note, this manipulator o nly changes formatting mode, | |||
/// and not format itself, so you are probably looking for ftim e manipulator | /// and not format itself, so you are probably looking for ftim e manipulator | |||
/// | /// | |||
inline std::ios_base & strftime(std::ios_base & ios) | inline std::ios_base & strftime(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::strftime, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::strftime); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Spell the number, like "one hundred and ten" | /// Spell the number, like "one hundred and ten" | |||
/// | /// | |||
inline std::ios_base & spellout(std::ios_base & ios) | inline std::ios_base & spellout(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::spellout, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::spellout); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Write an order of the number like 4th. | /// Write an order of the number like 4th. | |||
/// | /// | |||
inline std::ios_base & ordinal(std::ios_base & ios) | inline std::ios_base & ordinal(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::ordinal, flags::display_flags_mask); | ios_info::get(ios).display_flags(flags::ordinal); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Set default currency formatting style -- national, like "$" | /// Set default currency formatting style -- national, like "$" | |||
/// | /// | |||
inline std::ios_base & currency_default(std::ios_base & ios) | inline std::ios_base & currency_default(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::currency_default, flags::currency_flag s_mask); | ios_info::get(ios).currency_flags(flags::currency_default); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Set ISO currency formatting style, like "USD", (requires IC U >= 4.2) | /// Set ISO currency formatting style, like "USD", (requires IC U >= 4.2) | |||
/// | /// | |||
inline std::ios_base & currency_iso(std::ios_base & ios) | inline std::ios_base & currency_iso(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::currency_iso, flags::currency_flags_ma sk); | ios_info::get(ios).currency_flags(flags::currency_iso); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Set national currency formatting style, like "$" | /// Set national currency formatting style, like "$" | |||
/// | /// | |||
inline std::ios_base & currency_national(std::ios_base & ios) | inline std::ios_base & currency_national(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::currency_national, flags::currency_fla gs_mask); | ios_info::get(ios).currency_flags(flags::currency_national) ; | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set default (medium) time formatting style | /// set default (medium) time formatting style | |||
/// | /// | |||
inline std::ios_base & time_default(std::ios_base & ios) | inline std::ios_base & time_default(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time_default, flags::time_flags_mask); | ios_info::get(ios).time_flags(flags::time_default); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set short time formatting style | /// set short time formatting style | |||
/// | /// | |||
inline std::ios_base & time_short(std::ios_base & ios) | inline std::ios_base & time_short(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time_short, flags::time_flags_mask); | ios_info::get(ios).time_flags(flags::time_short); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set medium time formatting style | /// set medium time formatting style | |||
/// | /// | |||
inline std::ios_base & time_medium(std::ios_base & ios) | inline std::ios_base & time_medium(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time_medium, flags::time_flags_mask); | ios_info::get(ios).time_flags(flags::time_medium); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set long time formatting style | /// set long time formatting style | |||
/// | /// | |||
inline std::ios_base & time_long(std::ios_base & ios) | inline std::ios_base & time_long(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time_long, flags::time_flags_mask); | ios_info::get(ios).time_flags(flags::time_long); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set full time formatting style | /// set full time formatting style | |||
/// | /// | |||
inline std::ios_base & time_full(std::ios_base & ios) | inline std::ios_base & time_full(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::time_full, flags::time_flags_mask); | ios_info::get(ios).time_flags(flags::time_full); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set default (medium) date formatting style | /// set default (medium) date formatting style | |||
/// | /// | |||
inline std::ios_base & date_default(std::ios_base & ios) | inline std::ios_base & date_default(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date_default, flags::date_flags_mask); | ios_info::get(ios).date_flags(flags::date_default); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set short date formatting style | /// set short date formatting style | |||
/// | /// | |||
inline std::ios_base & date_short(std::ios_base & ios) | inline std::ios_base & date_short(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date_short, flags::date_flags_mask); | ios_info::get(ios).date_flags(flags::date_short); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set medium date formatting style | /// set medium date formatting style | |||
/// | /// | |||
inline std::ios_base & date_medium(std::ios_base & ios) | inline std::ios_base & date_medium(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date_medium, flags::date_flags_mask); | ios_info::get(ios).date_flags(flags::date_medium); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set long date formatting style | /// set long date formatting style | |||
/// | /// | |||
inline std::ios_base & date_long(std::ios_base & ios) | inline std::ios_base & date_long(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date_long, flags::date_flags_mask); | ios_info::get(ios).date_flags(flags::date_long); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// set full date formatting style | /// set full date formatting style | |||
/// | /// | |||
inline std::ios_base & date_full(std::ios_base & ios) | inline std::ios_base & date_full(std::ios_base & ios) | |||
{ | { | |||
ext_setf(ios, flags::date_full, flags::date_flags_mask); | ios_info::get(ios).date_flags(flags::date_full); | |||
return ios; | return ios; | |||
} | } | |||
/// \cond INTERNAL | /// \cond INTERNAL | |||
namespace details { | namespace details { | |||
template<typename CharType> | template<typename CharType> | |||
struct add_ftime { | struct add_ftime { | |||
std::basic_string<CharType> ftime; | std::basic_string<CharType> ftime; | |||
void apply(std::basic_ios<CharType> &ios) const | void apply(std::basic_ios<CharType> &ios) const | |||
{ | { | |||
ext_pattern(ios,flags::datetime_pattern,ftime); | ios_info::get(ios).date_time_pattern(ftime); | |||
as::strftime(ios); | as::strftime(ios); | |||
} | } | |||
}; | }; | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out,add_ftime<CharType> const &fmt) | std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out,add_ftime<CharType> const &fmt) | |||
{ | { | |||
fmt.apply(out); | fmt.apply(out); | |||
return out; | return out; | |||
skipping to change at line 440 | skipping to change at line 575 | |||
} | } | |||
/// \cond INTERNAL | /// \cond INTERNAL | |||
namespace details { | namespace details { | |||
struct set_timezone { | struct set_timezone { | |||
std::string id; | std::string id; | |||
}; | }; | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out,set_timezone const &fmt) | std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out,set_timezone const &fmt) | |||
{ | { | |||
ext_pattern(out,flags::time_zone_id,fmt.id); | ios_info::get(out).time_zone(fmt.id); | |||
return out; | return out; | |||
} | } | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_istream<CharType> &operator>>(std::basic_istream <CharType> &in,set_timezone const &fmt) | std::basic_istream<CharType> &operator>>(std::basic_istream <CharType> &in,set_timezone const &fmt) | |||
{ | { | |||
ext_pattern(in,flags::time_zone_id,fmt.id); | ios_info::get(in).time_zone(fmt.id); | |||
return in; | return in; | |||
} | } | |||
} | } | |||
/// \endcond | /// \endcond | |||
/// | /// | |||
/// Set GMT time zone to stream | /// Set GMT time zone to stream | |||
/// | /// | |||
inline std::ios_base &gmt(std::ios_base &ios) | inline std::ios_base &gmt(std::ios_base &ios) | |||
{ | { | |||
ext_pattern<char>(ios,flags::time_zone_id,"GMT"); | ios_info::get(ios).time_zone("GMT"); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Set local time zone to stream | /// Set local time zone to stream | |||
/// | /// | |||
inline std::ios_base &local_time(std::ios_base &ios) | inline std::ios_base &local_time(std::ios_base &ios) | |||
{ | { | |||
ext_pattern(ios,flags::time_zone_id,std::string()); | ios_info::get(ios).time_zone(time_zone::global()); | |||
return ios; | return ios; | |||
} | } | |||
/// | /// | |||
/// Set time zone using \a id | /// Set time zone using \a id | |||
/// | /// | |||
inline details::set_timezone time_zone(char const *id) | inline details::set_timezone time_zone(char const *id) | |||
{ | { | |||
details::set_timezone tz; | details::set_timezone tz; | |||
tz.id=id; | tz.id=id; | |||
skipping to change at line 491 | skipping to change at line 626 | |||
/// | /// | |||
/// Set time zone using \a id | /// Set time zone using \a id | |||
/// | /// | |||
inline details::set_timezone time_zone(std::string const &id) | inline details::set_timezone time_zone(std::string const &id) | |||
{ | { | |||
details::set_timezone tz; | details::set_timezone tz; | |||
tz.id=id; | tz.id=id; | |||
return tz; | return tz; | |||
} | } | |||
/// | ||||
/// Set time zone using time_zone class \a id | ||||
/// | ||||
inline details::set_timezone time_zone(booster::locale::time_zo | ||||
ne const &id) | ||||
{ | ||||
details::set_timezone tz; | ||||
tz.id=id.id(); | ||||
return tz; | ||||
} | ||||
/// | /// | |||
/// @} | /// @} | |||
/// | /// | |||
} // as manipulators | } // as manipulators | |||
} // locale | } // locale | |||
} // boost | } // boost | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
End of changes. 55 change blocks. | ||||
90 lines changed or deleted | 208 lines changed or added | |||
fstream.h | fstream.h | |||
---|---|---|---|---|
skipping to change at line 56 | skipping to change at line 56 | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
catch(bad_utf const &e) { | catch(bad_utf const &e) { | |||
return 0; | return 0; | |||
} | } | |||
} | } | |||
}; | }; | |||
#else // not msvc | #else // not msvc | |||
/// \cont INTERNAL | ||||
namespace details { | namespace details { | |||
class stdio_iodev : public booster::io_device { | class stdio_iodev : public booster::io_device { | |||
stdio_iodev(stdio_iodev const &); | stdio_iodev(stdio_iodev const &); | |||
void operator=(stdio_iodev const &); | void operator=(stdio_iodev const &); | |||
public: | public: | |||
stdio_iodev(FILE *f) : | stdio_iodev(FILE *f) : | |||
file_(f) | file_(f) | |||
{ | { | |||
} | } | |||
skipping to change at line 103 | skipping to change at line 103 | |||
} | } | |||
~stdio_iodev() | ~stdio_iodev() | |||
{ | { | |||
fclose(file_); | fclose(file_); | |||
} | } | |||
private: | private: | |||
FILE *file_; | FILE *file_; | |||
}; | }; | |||
} // details | } // details | |||
/// \endcond | ||||
template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | |||
class basic_filebuf; | class basic_filebuf; | |||
/// | ||||
/// Same as std::basic_filebuf<char> but accepts UTF-8 strings under | ||||
Windows | ||||
/// | ||||
template<> | template<> | |||
class basic_filebuf<char> : public booster::streambuf { | class basic_filebuf<char> : public booster::streambuf { | |||
public: | public: | |||
basic_filebuf() : opened_(false) | basic_filebuf() : opened_(false) | |||
{ | { | |||
} | } | |||
~basic_filebuf() | ~basic_filebuf() | |||
{ | { | |||
} | } | |||
skipping to change at line 178 | skipping to change at line 184 | |||
if(mode==(std::ios_base::binary | std::ios_base::out | std::ios_base::app | std::ios_base::in)) | if(mode==(std::ios_base::binary | std::ios_base::out | std::ios_base::app | std::ios_base::in)) | |||
return "a+b"; | return "a+b"; | |||
return ""; | return ""; | |||
} | } | |||
bool opened_; | bool opened_; | |||
}; | }; | |||
#endif | #endif | |||
/// | ||||
/// Same as std::basic_ifstream<char> but accepts UTF-8 strings unde | ||||
r Windows | ||||
/// | ||||
template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | |||
class basic_ifstream : public std::basic_istream<CharType,Traits> | class basic_ifstream : public std::basic_istream<CharType,Traits> | |||
{ | { | |||
public: | public: | |||
typedef basic_filebuf<CharType,Traits> internal_buffer_type; | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |||
typedef std::basic_istream<CharType,Traits> internal_stream_ type; | typedef std::basic_istream<CharType,Traits> internal_stream_ type; | |||
basic_ifstream() : | basic_ifstream() : | |||
internal_stream_type(new internal_buffer_type()) | internal_stream_type(new internal_buffer_type()) | |||
{ | { | |||
skipping to change at line 234 | skipping to change at line 243 | |||
} | } | |||
~basic_ifstream() | ~basic_ifstream() | |||
{ | { | |||
buf_->close(); | buf_->close(); | |||
} | } | |||
private: | private: | |||
std::auto_ptr<internal_buffer_type> buf_; | std::auto_ptr<internal_buffer_type> buf_; | |||
}; | }; | |||
/// | ||||
/// Same as std::basic_ofstream<char> but accepts UTF-8 strings unde | ||||
r Windows | ||||
/// | ||||
template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | |||
class basic_ofstream : public std::basic_ostream<CharType,Traits> | class basic_ofstream : public std::basic_ostream<CharType,Traits> | |||
{ | { | |||
public: | public: | |||
typedef basic_filebuf<CharType,Traits> internal_buffer_type; | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |||
typedef std::basic_ostream<CharType,Traits> internal_stream_ type; | typedef std::basic_ostream<CharType,Traits> internal_stream_ type; | |||
basic_ofstream() : | basic_ofstream() : | |||
internal_stream_type(new internal_buffer_type()) | internal_stream_type(new internal_buffer_type()) | |||
{ | { | |||
skipping to change at line 290 | skipping to change at line 303 | |||
} | } | |||
~basic_ofstream() | ~basic_ofstream() | |||
{ | { | |||
buf_->close(); | buf_->close(); | |||
} | } | |||
private: | private: | |||
std::auto_ptr<internal_buffer_type> buf_; | std::auto_ptr<internal_buffer_type> buf_; | |||
}; | }; | |||
/// | ||||
/// Same as std::basic_fstream<char> but accepts UTF-8 strings under | ||||
Windows | ||||
/// | ||||
template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | template<typename CharType,typename Traits = std::char_traits<CharTy pe> > | |||
class basic_fstream : public std::basic_iostream<CharType,Traits> | class basic_fstream : public std::basic_iostream<CharType,Traits> | |||
{ | { | |||
public: | public: | |||
typedef basic_filebuf<CharType,Traits> internal_buffer_type; | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |||
typedef std::basic_iostream<CharType,Traits> internal_stream _type; | typedef std::basic_iostream<CharType,Traits> internal_stream _type; | |||
basic_fstream() : | basic_fstream() : | |||
internal_stream_type(new internal_buffer_type()) | internal_stream_type(new internal_buffer_type()) | |||
{ | { | |||
skipping to change at line 346 | skipping to change at line 363 | |||
} | } | |||
~basic_fstream() | ~basic_fstream() | |||
{ | { | |||
buf_->close(); | buf_->close(); | |||
} | } | |||
private: | private: | |||
std::auto_ptr<internal_buffer_type> buf_; | std::auto_ptr<internal_buffer_type> buf_; | |||
}; | }; | |||
/// | ||||
/// Same as std::filebuf but accepts UTF-8 strings under Windows | ||||
/// | ||||
typedef basic_filebuf<char> filebuf; | typedef basic_filebuf<char> filebuf; | |||
/// | ||||
/// Same as std::ifstream but accepts UTF-8 strings under Windows | ||||
/// | ||||
typedef basic_ifstream<char> ifstream; | typedef basic_ifstream<char> ifstream; | |||
/// | ||||
/// Same as std::ofstream but accepts UTF-8 strings under Windows | ||||
/// | ||||
typedef basic_ofstream<char> ofstream; | typedef basic_ofstream<char> ofstream; | |||
/// | ||||
/// Same as std::fstream but accepts UTF-8 strings under Windows | ||||
/// | ||||
typedef basic_fstream<char> fstream; | typedef basic_fstream<char> fstream; | |||
#endif | #endif | |||
} // nowide | } // nowide | |||
} // booster | } // booster | |||
#endif | #endif | |||
End of changes. 10 change blocks. | ||||
1 lines changed or deleted | 34 lines changed or added | |||
function.h | function.h | |||
---|---|---|---|---|
// | // | |||
// Copyright (c) 2010 Artyom Beilis (Tonkikh) | // Copyright (c) 2010 Artyom Beilis (Tonkikh) | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_FUNCTION_H | #ifndef BOOSTER_FUNCTION_H | |||
#define BOOSTER_FUNCTION_H | #define BOOSTER_FUNCTION_H | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
#include <booster/clone_ptr.h> | #include <booster/clone_ptr.h> | |||
namespace booster { | namespace booster { | |||
template<typename Type> | template<typename Type> | |||
class function; | class function; | |||
class bad_function_call : public std::runtime_error { | class bad_function_call : public booster::runtime_error { | |||
public: | public: | |||
bad_function_call() : | bad_function_call() : | |||
std::runtime_error("bad_function_call") | booster::runtime_error("bad_function_call") | |||
{ | { | |||
} | } | |||
}; | }; | |||
#ifdef BOOSTER_DOXYGEN_DOCS | #ifdef BOOSTER_DOXYGEN_DOCS | |||
/// | /// | |||
/// \brief This is Booster's implementation of std::tr1::function/bo oster::function. | /// \brief This is Booster's implementation of std::tr1::function/bo oster::function. | |||
/// | /// | |||
/// This function is created from generic object that can be "called " i.e. | /// This function is created from generic object that can be "called " i.e. | |||
/// a class with operator() or function pointer that has same signat ure as | /// a class with operator() or function pointer that has same signat ure as | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added | |||
generator.h | generator.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
# pragma warning(push) | # pragma warning(push) | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <string> | #include <string> | |||
#include <locale> | #include <locale> | |||
#include <memory> | #include <memory> | |||
namespace booster { | namespace booster { | |||
template<typename Type> | ||||
class shared_ptr; | ||||
/// | /// | |||
/// \brief This is the main namespace that encloses all localization cl asses | /// \brief This is the main namespace that encloses all localization cl asses | |||
/// | /// | |||
namespace locale { | namespace locale { | |||
/// | class localization_backend; | |||
/// a enum type that specifies the character type that locales can | class localization_backend_manager; | |||
be generated for | ||||
/// | ||||
typedef enum { | ||||
char_facet = 1 << 0, ///< 8-bit character facets | ||||
wchar_t_facet = 1 << 1, ///< wide character facets | ||||
char16_t_facet = 1 << 2, ///< C++0x char16_t facets | ||||
char32_t_facet = 1 << 3, ///< C++0x char32_t facets | ||||
all_characters = 0xFFFF ///< Special mask -- generate all | static const unsigned nochar_facet = 0; ///< Unspecified | |||
} character_facet_type; | character category for character independed facets | |||
static const unsigned char_facet = 1 << 0; ///< 8-bit charac | ||||
ter facets | ||||
static const unsigned wchar_t_facet = 1 << 1; ///< wide charact | ||||
er facets | ||||
static const unsigned char16_t_facet = 1 << 2; ///< C++0x char16 | ||||
_t facets | ||||
static const unsigned char32_t_facet = 1 << 3; ///< C++0x char32 | ||||
_t facets | ||||
/// | static const unsigned character_first_facet = char_facet; ///< Fir | |||
/// a special enum used for more fine grained generation of facets | st facet specific for character type | |||
/// | static const unsigned character_last_facet = char32_t_facet; ///< L | |||
typedef enum { | ast facet specific for character typr | |||
collation_facet = 1 << 0, ///< Generate collation facets | static const unsigned all_characters = 0xFFFF; ///< Special mas | |||
formatting_facet= 1 << 1, ///< Generate numbers, currency, da | k -- generate all | |||
te-time formatting facets | ||||
message_facet = 1 << 2, ///< Generate message facets | ||||
codepage_facet= 1 << 3, ///< Generate codepage conversion f | ||||
acets (derived from std::codecvt) | ||||
all_categories = 0xFFFFFFFFu ///< Generate all of them | typedef unsigned character_facet_type; ///<type that specifies the | |||
} locale_category_type; | character type that locales can be generated for | |||
static const unsigned convert_facet = 1 << 0; ///< Generate | ||||
convertsion facets | ||||
static const unsigned collation_facet = 1 << 1; ///< Generate | ||||
collation facets | ||||
static const unsigned formatting_facet= 1 << 2; ///< Generate | ||||
numbers, currency, date-time formatting facets | ||||
static const unsigned parsing_facet = 1 << 3; ///< Generate | ||||
numbers, currency, date-time formatting facets | ||||
static const unsigned message_facet = 1 << 4; ///< Generate | ||||
message facets | ||||
static const unsigned codepage_facet = 1 << 5; ///< Generate | ||||
codepage conversion facets (derived from std::codecvt) | ||||
static const unsigned boundary_facet = 1 << 6; ///< Generate | ||||
boundary analysis facet | ||||
static const unsigned per_character_facet_first = convert_facet | ||||
; ///< First facet specific for character | ||||
static const unsigned per_character_facet_last = boundary_facet | ||||
; ///< Last facet specific for character | ||||
static const unsigned calendar_facet = 1 << 16; ///< Generat | ||||
e boundary analysis facet | ||||
static const unsigned information_facet = 1 << 17; ///< Gener | ||||
ate general locale information facet | ||||
static const unsigned non_character_facet_first = calendar_facet | ||||
; ///< First character independed facet | ||||
static const unsigned non_character_facet_last = information_fac | ||||
et;///< Last character independed facet | ||||
static const unsigned all_categories = 0xFFFFFFFFu; ///< Gene | ||||
rate all of them | ||||
typedef unsigned locale_category_type; ///< a type used for more fi | ||||
ne grained generation of facets | ||||
/// | /// | |||
/// \brief the major class used for locale generation | /// \brief the major class used for locale generation | |||
/// | /// | |||
/// This class is used for specification of all parameters required for locale generation and | /// This class is used for specification of all parameters required for locale generation and | |||
/// caching. This class const member functions are thread safe if l ocale class implementation is thread safe. | /// caching. This class const member functions are thread safe if l ocale class implementation is thread safe. | |||
/// | /// | |||
class BOOSTER_API generator { | class BOOSTER_API generator { | |||
public: | public: | |||
/// | ||||
/// Create new generator using global localization_backend_mana | ||||
ger | ||||
/// | ||||
generator(); | generator(); | |||
/// | ||||
/// Create new generator using specific localization_backend_ma | ||||
nager | ||||
/// | ||||
generator(localization_backend_manager const &); | ||||
~generator(); | ~generator(); | |||
/// | /// | |||
/// Set types of facets that should be generated, default all | /// Set types of facets that should be generated, default all | |||
/// | /// | |||
void categories(unsigned cats); | void categories(unsigned cats); | |||
/// | /// | |||
/// Get types of facets that should be generated, default all | /// Get types of facets that should be generated, default all | |||
/// | /// | |||
unsigned categories() const; | unsigned categories() const; | |||
skipping to change at line 81 | skipping to change at line 105 | |||
/// | /// | |||
/// Set the characters type for which the facets should be gene rated, default all supported | /// Set the characters type for which the facets should be gene rated, default all supported | |||
/// | /// | |||
void characters(unsigned chars); | void characters(unsigned chars); | |||
/// | /// | |||
/// Get the characters type for which the facets should be gene rated, default all supported | /// Get the characters type for which the facets should be gene rated, default all supported | |||
/// | /// | |||
unsigned characters() const; | unsigned characters() const; | |||
/// | /// | |||
/// Set encoding used for 8-bit character encoding. Default is | ||||
system default encoding | ||||
/// | ||||
void octet_encoding(std::string const &encoding); | ||||
/// | ||||
/// Get encoding used for 8-bit character encoding. Default is | ||||
system default encoding | ||||
/// | ||||
std::string octet_encoding() const; | ||||
/// | ||||
/// Add a new domain of messages that would be generated. It sh ould be set in order to enable | /// Add a new domain of messages that would be generated. It sh ould be set in order to enable | |||
/// messages support. | /// messages support. | |||
/// | /// | |||
void add_messages_domain(std::string const &domain); | void add_messages_domain(std::string const &domain); | |||
/// | /// | |||
/// Set default message domain. If this member was not called, the first added messages domain is used. | /// Set default message domain. If this member was not called, the first added messages domain is used. | |||
/// If the domain \a domain is not added yet it is added. | /// If the domain \a domain is not added yet it is added. | |||
/// | /// | |||
void set_default_messages_domain(std::string const &domain); | void set_default_messages_domain(std::string const &domain); | |||
skipping to change at line 130 | skipping to change at line 145 | |||
/// Remove all added paths | /// Remove all added paths | |||
/// | /// | |||
void clear_paths(); | void clear_paths(); | |||
/// | /// | |||
/// Remove all cached locales | /// Remove all cached locales | |||
/// | /// | |||
void clear_cache(); | void clear_cache(); | |||
/// | /// | |||
/// Generate a locale with id \a id and put it in cache | /// Turn locale caching ON | |||
/// | ||||
void preload(std::string const &id); | ||||
/// | ||||
/// Generate a locale with id \a id, encoding \a encoding and p | ||||
ut it in cache | ||||
/// | /// | |||
void preload(std::string const &id,std::string const &encoding) ; | void locale_cache_enabled(bool on); | |||
/// | /// | |||
/// Generate a locale with id \a id and put it in cache, use \a | /// Get locale cache option | |||
base as a locale for which all facets are added, | ||||
/// instead of global one | ||||
/// | ||||
void preload(std::locale const &base,std::string const &id); | ||||
/// | ||||
/// Generate a locale with id \a id, encoding \a encoding and p | ||||
ut it in cache, use \a base as a locale for which all facets are added, | ||||
/// instead of global one | ||||
/// | /// | |||
void preload(std::locale const &base,std::string const &id,std: :string const &encoding); | bool locale_cache_enabled() const; | |||
/// | /// | |||
/// Generate a locale with id \a id | /// Generate a locale with id \a id | |||
/// | /// | |||
std::locale generate(std::string const &id) const; | std::locale generate(std::string const &id) const; | |||
/// | /// | |||
/// Generate a locale with id \a id, encoding \a encoding | ||||
/// | ||||
std::locale generate(std::string const &id,std::string const &e | ||||
ncoding) const; | ||||
/// | ||||
/// Generate a locale with id \a id, use \a base as a locale fo r which all facets are added, | /// Generate a locale with id \a id, use \a base as a locale fo r which all facets are added, | |||
/// instead of global one | /// instead of std::locale::classic() one | |||
/// | /// | |||
std::locale generate(std::locale const &base,std::string const &id) const; | std::locale generate(std::locale const &base,std::string const &id) const; | |||
/// | /// | |||
/// Generate a locale with id \a id, encoding \a encoding, use | /// Shortcut to generate(id) | |||
\a base as a locale for which all facets are added, | ||||
/// instead of global one | ||||
/// | /// | |||
std::locale generate(std::locale const &base,std::string const | std::locale operator()(std::string const &id) const | |||
&id,std::string const &encoding) const; | { | |||
return generate(id); | ||||
} | ||||
/// | /// | |||
/// Get a locale with id \a id from cache, if not found, genera | /// Set backend specific option | |||
te one | ||||
/// | ||||
std::locale get(std::string const &id) const; | ||||
/// | ||||
/// Get a locale with id \a id and encoding \a encoding from ca | ||||
che, if not found, generate one | ||||
/// | /// | |||
std::locale get(std::string const &id,std::string const &encodi ng) const; | void set_option(std::string const &name,std::string const &valu e); | |||
/// | /// | |||
/// Shortcut to get(id) | /// Clear backend specific options | |||
/// | ||||
std::locale operator()(std::string const &id) const | ||||
{ | ||||
return get(id); | ||||
} | ||||
/// | ||||
/// Shortcut to get(id,encoding) | ||||
/// | /// | |||
std::locale operator()(std::string const &id,std::string const | void clear_options(); | |||
&encoding) const | ||||
{ | ||||
return get(id,encoding); | ||||
} | ||||
private: | private: | |||
template<typename CharType> | void set_all_options(shared_ptr<localization_backend> backend,s | |||
std::locale generate_for(std::locale const &source) const; | td::string const &id) const; | |||
std::locale complete_generation(std::locale const &source) cons | ||||
t; | ||||
generator(generator const &); | generator(generator const &); | |||
void operator=(generator const &); | void operator=(generator const &); | |||
struct data; | struct data; | |||
std::auto_ptr<data> d; | std::auto_ptr<data> d; | |||
}; | }; | |||
} | } | |||
} | } | |||
End of changes. 21 change blocks. | ||||
88 lines changed or deleted | 86 lines changed or added | |||
http_request.h | http_request.h | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#ifndef CPPCMS_HTTP_REQUEST_H | #ifndef CPPCMS_HTTP_REQUEST_H | |||
#define CPPCMS_HTTP_REQUEST_H | #define CPPCMS_HTTP_REQUEST_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
#include <booster/hold_ptr.h> | #include <booster/hold_ptr.h> | |||
#include <booster/shared_ptr.h> | #include <booster/shared_ptr.h> | |||
#include <cppcms/http_content_type.h> | ||||
#include <string> | #include <string> | |||
#include <map> | #include <map> | |||
#include <vector> | #include <vector> | |||
namespace cppcms { | namespace cppcms { | |||
namespace impl { namespace cgi { class connection; } } | namespace impl { namespace cgi { class connection; } } | |||
namespace http { | namespace http { | |||
skipping to change at line 62 | skipping to change at line 63 | |||
std::string auth_type(); | std::string auth_type(); | |||
/// | /// | |||
/// CGI CONTENT_LENGTH environment variable | /// CGI CONTENT_LENGTH environment variable | |||
/// | /// | |||
unsigned long long content_length(); | unsigned long long content_length(); | |||
/// | /// | |||
/// CGI CONTENT_TYPE environment variable | /// CGI CONTENT_TYPE environment variable | |||
/// | /// | |||
std::string content_type(); | std::string content_type(); | |||
/// | /// | |||
/// Parsed CGI CONTENT_TYPE environment variable | ||||
/// | ||||
cppcms::http::content_type content_type_parsed(); | ||||
/// | ||||
/// CGI GATEWAY_INTERFACE environment variable | /// CGI GATEWAY_INTERFACE environment variable | |||
/// | /// | |||
std::string gateway_interface(); | std::string gateway_interface(); | |||
/// | /// | |||
/// CGI PATH_INFO environment variable | /// CGI PATH_INFO environment variable | |||
/// | /// | |||
std::string path_info(); | std::string path_info(); | |||
/// | /// | |||
/// CGI PATH_TRANSLATED environment variable | /// CGI PATH_TRANSLATED environment variable | |||
/// | /// | |||
skipping to change at line 304 | skipping to change at line 309 | |||
std::string::const_iterator &p, | std::string::const_iterator &p, | |||
std::string::const_iterator e, | std::string::const_iterator e, | |||
std::string &key, | std::string &key, | |||
std::string &value); | std::string &value); | |||
struct _data; | struct _data; | |||
form_type get_; | form_type get_; | |||
form_type post_; | form_type post_; | |||
files_type files_; | files_type files_; | |||
cookies_type cookies_; | cookies_type cookies_; | |||
cppcms::http::content_type content_type_; | ||||
booster::hold_ptr<_data> d; | booster::hold_ptr<_data> d; | |||
impl::cgi::connection *conn_; | impl::cgi::connection *conn_; | |||
}; | }; | |||
} // namespace http | } // namespace http | |||
} // namespace cppcms | } // namespace cppcms | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 6 lines changed or added | |||
info.h | info.h | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
# pragma warning(disable : 4275 4251 4231 4660) | # pragma warning(disable : 4275 4251 4231 4660) | |||
#endif | #endif | |||
#include <locale> | #include <locale> | |||
#include <string> | #include <string> | |||
#include <map> | #include <map> | |||
#include <memory> | #include <memory> | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
struct info_impl; | ||||
/// | /// | |||
/// \brief a facet that holds general information about locale | /// \brief a facet that holds general information about locale | |||
/// | /// | |||
/// This facet should be always created in order to make all Boost. Locale functions work | /// This facet should be always created in order to make all Boost. Locale functions work | |||
/// | /// | |||
class BOOSTER_API info : public std::locale::facet | class BOOSTER_API info : public std::locale::facet | |||
{ | { | |||
public: | public: | |||
static std::locale::id id; ///< This member defines uniquely th is facet, required by STL | static std::locale::id id; ///< This member defines uniquely th is facet, required by STL | |||
/// | /// | |||
/// Creates locale using general locale id that includes encodi | /// String information about the locale | |||
ng | ||||
/// If encoding is not found, default system encoding is taken, | ||||
if the string is empty | ||||
/// default system locale is used. | ||||
/// | /// | |||
info(std::string posix_id,size_t refs = 0); | typedef enum { | |||
language_property, ///< ISO 639 language id | ||||
country_property, ///< ISO 3166 country id | ||||
variant_property, ///< Variant for locale | ||||
encoding_property, ///< encoding name | ||||
name_property ///< locale name | ||||
} string_propery; | ||||
/// | /// | |||
/// Creates locale using general locale id and cherset encoding | /// Integer information about locale | |||
/// if posix_id is empty default system locale is used. | ||||
/// | /// | |||
info(std::string posix_id,std::string encoding,size_t refs = 0) | typedef enum { | |||
; | utf8_property ///< Non zero value if uses UTF-8 encod | |||
ing | ||||
} integer_property; | ||||
/// | /// | |||
/// Standard facet's constructor | ||||
/// | ||||
info(size_t refs = 0) : std::locale::facet(refs) | ||||
{ | ||||
} | ||||
/// | ||||
/// Get language name | /// Get language name | |||
/// | /// | |||
std::string language() const; | std::string language() const | |||
{ | ||||
return get_string_property(language_property); | ||||
} | ||||
/// | /// | |||
/// Get country name | /// Get country name | |||
/// | /// | |||
std::string country() const; | std::string country() const | |||
{ | ||||
return get_string_property(country_property); | ||||
} | ||||
/// | /// | |||
/// Get locale variant | /// Get locale variant | |||
/// | /// | |||
std::string variant() const; | std::string variant() const | |||
{ | ||||
return get_string_property(variant_property); | ||||
} | ||||
/// | /// | |||
/// Get encoding | /// Get encoding | |||
/// | /// | |||
std::string encoding() const; | std::string encoding() const | |||
{ | ||||
return get_string_property(encoding_property); | ||||
} | ||||
/// | /// | |||
/// Is underlying encoding is UTF-8 (for char streams and strin gs) | /// Get the name of the locale, like en_US.UTF-8 | |||
/// | /// | |||
bool utf8() const | std::string name() const | |||
{ | { | |||
return utf8_; | return get_string_property(name_property); | |||
} | } | |||
/// \cond INTERNAL | /// | |||
/// Is underlying encoding is UTF-8 (for char streams and strin | ||||
// | gs) | |||
// Internal function, do not use it | /// | |||
// | bool utf8() const | |||
info_impl const *impl() const | ||||
{ | { | |||
return impl_.get(); | return get_ineger_property(utf8_property) != 0; | |||
} | } | |||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |||
std::locale::id& __get_id (void) const { return id; } | std::locale::id& __get_id (void) const { return id; } | |||
#endif | #endif | |||
/// \endcond | protected: | |||
protected: | /// | |||
/// Get string property by its id \a v | ||||
virtual ~info(); | /// | |||
virtual std::string get_string_property(string_propery v) const | ||||
private: | = 0; | |||
std::auto_ptr<info_impl> impl_; | /// | |||
bool utf8_; | /// Get integer property by its id \a v | |||
/// | ||||
virtual int get_ineger_property(integer_property v) const = 0; | ||||
}; | }; | |||
} | } | |||
} | } | |||
#ifdef BOOSTER_MSVC | #ifdef BOOSTER_MSVC | |||
#pragma warning(pop) | #pragma warning(pop) | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 16 change blocks. | ||||
34 lines changed or deleted | 54 lines changed or added | |||
io_service.h | io_service.h | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
#include <booster/aio/aio_category.h> | #include <booster/aio/aio_category.h> | |||
#include <booster/callback.h> | #include <booster/callback.h> | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
#include <string> | #include <string> | |||
#include <memory> | #include <memory> | |||
namespace booster { | namespace booster { | |||
class ptime; | class ptime; | |||
namespace aio { | namespace aio { | |||
typedef callback<void(system::error_code const &e,int fd)> accept_ha ndler; | ||||
class event_loop_impl; | class event_loop_impl; | |||
/// | ||||
/// \brief this is the central event loop that dispatches all reques | ||||
ts. | ||||
/// | ||||
/// This all this class member functions are thread safe unless spec | ||||
ified otherwise. | ||||
/// | ||||
/// Sinlge or multiple threads may execute run() member function and | ||||
dispatch its handlers, this class | ||||
/// also can be safely created before fork and used after it | ||||
/// | ||||
class BOOSTER_API io_service : public noncopyable { | class BOOSTER_API io_service : public noncopyable { | |||
public: | public: | |||
static const int in = 1 << 0; | static const int in = 1 << 0; | |||
static const int out = 1 << 1; | static const int out = 1 << 1; | |||
/// | ||||
/// Create io service using specific reactor type and not de | ||||
fault one (see reactor's class use_* constants) | ||||
/// | ||||
io_service(int reactor_type); | io_service(int reactor_type); | |||
/// | ||||
/// Create io service using default reactor | ||||
/// | ||||
io_service(); | io_service(); | |||
/// | ||||
/// Destroy io_service. It should be stopped before!. | ||||
/// | ||||
~io_service(); | ~io_service(); | |||
/// | ||||
/// Set event handler \a h for file descriptor \fd. \a event | ||||
can be in, out or in. | ||||
/// | ||||
/// Error handling: | ||||
/// | ||||
/// - If invalid \a event type is given, std::invalid_argume | ||||
nt is throw. | ||||
/// - All other applicative errors are always reported using | ||||
event handler \a h and never thrown directly. | ||||
/// | ||||
void set_io_event(native_type fd,int event,event_handler con st &h); | void set_io_event(native_type fd,int event,event_handler con st &h); | |||
/// | ||||
/// Cancel all io-events for file descriptor \a fd. Event ha | ||||
ndlers associated with this descriptor are | ||||
/// dispatched asynchronously with aio_error::canceled error | ||||
code. | ||||
/// | ||||
void cancel_io_events(native_type fd); | void cancel_io_events(native_type fd); | |||
/// | ||||
/// Create a timer that expires in \a point time, that is ha | ||||
ndled with \a h handler. | ||||
/// the handler will be called only in two cases: | ||||
/// | ||||
/// - When the current time >= \a point. | ||||
/// - Timer was canceled. \a h will be dispatched with aio_e | ||||
rror::canceled error code. | ||||
/// | ||||
/// The return value is special identification for the speci | ||||
fic timer, it can be used for timer cancellation. | ||||
/// Once cancel_timer_event is called with this unique ident | ||||
ification, it should never be called again with | ||||
/// this id as other timer may receive this identification. | ||||
/// | ||||
int set_timer_event(ptime const &point,event_handler const & h); | int set_timer_event(ptime const &point,event_handler const & h); | |||
/// | ||||
/// Cancel timer created with set_timer_event() asynchronous | ||||
ly, | ||||
/// | ||||
void cancel_timer_event(int event_id); | void cancel_timer_event(int event_id); | |||
/// | ||||
/// Run main event loop. This function starts actual event l | ||||
oop. It does not return until stop | ||||
/// is called or error occurs. | ||||
/// | ||||
/// If error occurs (exception is thrown) you may try to res | ||||
tart the event loop by calling run once again. | ||||
/// | ||||
/// However if run() is exited normally (i.e. by calling sto | ||||
p()) then you need to call reset() member function | ||||
/// before next call of run(). | ||||
/// | ||||
void run(); | void run(); | |||
/// | ||||
/// Same as run(), but, event-loop specific errors are repor | ||||
ted via \a e error code rather then by throwing. | ||||
/// Note, event handlers still may throw. | ||||
/// | ||||
void run(system::error_code &e); | void run(system::error_code &e); | |||
/// | ||||
/// Prepare the service after it was stopped. This function | ||||
is not thread safe. | ||||
/// | ||||
void reset(); | void reset(); | |||
/// | ||||
/// Stop the service. All threads executing run() function w | ||||
ill exit from it. You can't use this service | ||||
/// till you call reset() function. | ||||
/// | ||||
void stop(); | void stop(); | |||
/// | ||||
/// Post a single handler \a h for immediate execution in th | ||||
e event loop queue. Useful for execution of some | ||||
/// job in the thread that runs the event loop of the io_ser | ||||
vice. | ||||
/// | ||||
void post(handler const &h); | void post(handler const &h); | |||
/// | ||||
/// Get the real name of the reactor that io_service uses (c | ||||
alls reactor::name()) | ||||
/// | ||||
std::string reactor_name(); | std::string reactor_name(); | |||
private: | private: | |||
struct data; | struct data; | |||
hold_ptr<data> d; | hold_ptr<data> d; | |||
std::auto_ptr<event_loop_impl> impl_; | std::auto_ptr<event_loop_impl> impl_; | |||
}; | }; | |||
} // aio | } // aio | |||
} // booster | } // booster | |||
End of changes. 15 change blocks. | ||||
1 lines changed or deleted | 99 lines changed or added | |||
json.h | json.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// You should have received a copy of the GNU Lesser General Public Licens e | // You should have received a copy of the GNU Lesser General Public Licens e | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#ifndef CPPCMS_JSON_H | #ifndef CPPCMS_JSON_H | |||
#define CPPCMS_JSON_H | #define CPPCMS_JSON_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <booster/copy_ptr.h> | #include <booster/copy_ptr.h> | |||
#include <booster/backtrace.h> | ||||
#include <vector> | #include <vector> | |||
#include <map> | #include <map> | |||
#include <string> | #include <string> | |||
#include <iostream> | #include <iostream> | |||
#include <typeinfo> | ||||
#include <limits> | #include <limits> | |||
namespace cppcms { | namespace cppcms { | |||
/// | /// | |||
/// \brief This namespace includes all JSON parsing and formatting related classes and functions | /// \brief This namespace includes all JSON parsing and formatting related classes and functions | |||
/// | /// | |||
namespace json { | namespace json { | |||
class value; | class value; | |||
skipping to change at line 112 | skipping to change at line 111 | |||
compact = 0, ///< Print JSON values in most compact format | compact = 0, ///< Print JSON values in most compact format | |||
readable = 1 ///< Print JSON values in human readable format (with identention) | readable = 1 ///< Print JSON values in human readable format (with identention) | |||
}; | }; | |||
/// | /// | |||
/// \brief The error that is thrown in case of bad conversion of jso n::value to ordinary value | /// \brief The error that is thrown in case of bad conversion of jso n::value to ordinary value | |||
/// | /// | |||
/// When implementing json::traits for complex classes you are expec ted to throw this exception | /// When implementing json::traits for complex classes you are expec ted to throw this exception | |||
/// in case of invalid formatting | /// in case of invalid formatting | |||
/// | /// | |||
class CPPCMS_API bad_value_cast : public std::bad_cast { | class CPPCMS_API bad_value_cast : public booster::bad_cast { | |||
public: | public: | |||
bad_value_cast(); | bad_value_cast(); | |||
bad_value_cast(std::string const &s); | bad_value_cast(std::string const &s); | |||
bad_value_cast(std::string const &s,json_type actual); | bad_value_cast(std::string const &s,json_type actual); | |||
bad_value_cast(std::string const &s,json_type expected, json _type actual); | bad_value_cast(std::string const &s,json_type expected, json _type actual); | |||
virtual ~bad_value_cast() throw(); | virtual ~bad_value_cast() throw(); | |||
virtual const char* what() const throw(); | virtual const char* what() const throw(); | |||
private: | private: | |||
std::string msg_; | std::string msg_; | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 2 lines changed or added | |||
locale.h | locale.h | |||
---|---|---|---|---|
// | // | |||
// Copyright (c) 2009-2010 Artyom Beilis (Tonkikh) | // Copyright (c) 2009-2010 Artyom Beilis (Tonkikh) | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_LOCALE_H_INCLUDED | #ifndef BOOSTER_LOCALE_H_INCLUDED | |||
#define BOOSTER_LOCALE_H_INCLUDED | #define BOOSTER_LOCALE_H_INCLUDED | |||
#include <booster/locale/collator.h> | ||||
#include <booster/locale/boundary.h> | #include <booster/locale/boundary.h> | |||
#include <booster/locale/codepage.h> | #include <booster/locale/collator.h> | |||
#include <booster/locale/conversion.h> | #include <booster/locale/conversion.h> | |||
#include <booster/locale/date_time.h> | ||||
#include <booster/locale/date_time_facet.h> | ||||
#include <booster/locale/encoding.h> | ||||
#include <booster/locale/format.h> | #include <booster/locale/format.h> | |||
#include <booster/locale/formatting.h> | #include <booster/locale/formatting.h> | |||
#include <booster/locale/generator.h> | #include <booster/locale/generator.h> | |||
#include <booster/locale/gnu_gettext.h> | ||||
#include <booster/locale/info.h> | #include <booster/locale/info.h> | |||
#include <booster/locale/localization_backend.h> | ||||
#include <booster/locale/message.h> | #include <booster/locale/message.h> | |||
#include <booster/locale/time_zone.h> | #include <booster/locale/util.h> | |||
#include <booster/locale/date_time.h> | ||||
#endif | #endif | |||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 7 lines changed or added | |||
locale_fwd.h | locale_fwd.h | |||
---|---|---|---|---|
#ifndef CPPCMS_LOCALE_FWD_H | #ifndef CPPCMS_LOCALE_FWD_H | |||
#define CPPCMS_LOCALE_FWD_H | #define CPPCMS_LOCALE_FWD_H | |||
#include <cppcms/config.h> | #include <cppcms/config.h> | |||
#ifdef CPPCMS_HAVE_ICU | namespace booster { | |||
namespace booster { | namespace locale { | |||
namespace locale { | class generator; | |||
class generator; | class info; | |||
class info; | ||||
} | ||||
} | ||||
namespace cppcms { | ||||
namespace locale = ::booster::locale; | ||||
} | ||||
#else | ||||
namespace cppcms { | ||||
namespace locale { | ||||
class generator; | ||||
class info; | ||||
} | ||||
} | } | |||
#endif | } | |||
namespace cppcms { | ||||
namespace locale = ::booster::locale; | ||||
} | ||||
#endif | #endif | |||
End of changes. 2 change blocks. | ||||
18 lines changed or deleted | 8 lines changed or added | |||
localization.h | localization.h | |||
---|---|---|---|---|
#ifndef CPPCMS_LOCALIZATION_H | #ifndef CPPCMS_LOCALIZATION_H | |||
#define CPPCMS_LOCALIZATION_H | #define CPPCMS_LOCALIZATION_H | |||
#include <cppcms/config.h> | #include <cppcms/config.h> | |||
#include <booster/locale.h> | ||||
#ifdef CPPCMS_HAVE_ICU | namespace cppcms { | |||
# include <booster/locale.h> | namespace locale = ::booster::locale; | |||
} | ||||
namespace cppcms { | ||||
namespace locale = ::booster::locale; | ||||
} | ||||
#else | ||||
# include <cppcms/noicu_localization.h> | ||||
#endif | ||||
#endif | #endif | |||
End of changes. 1 change blocks. | ||||
10 lines changed or deleted | 4 lines changed or added | |||
log.h | log.h | |||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
#define BOOSTER_LOGGER_H | #define BOOSTER_LOGGER_H | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <iosfwd> | #include <iosfwd> | |||
#include <memory> | #include <memory> | |||
#include <string> | #include <string> | |||
#include <booster/copy_ptr.h> | #include <booster/copy_ptr.h> | |||
#include <booster/hold_ptr.h> | #include <booster/hold_ptr.h> | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
/*! \file */ | ||||
namespace booster { | namespace booster { | |||
template<typename T> | template<typename T> | |||
class shared_ptr; | class shared_ptr; | |||
template<typename T> | template<typename T> | |||
class weak_ptr; | class weak_ptr; | |||
/// | /// | |||
/// \brief This namespace includes Booster.Log related classes | /// \brief This namespace includes Booster.Log related classes | |||
/// | /// | |||
namespace log { | namespace log { | |||
/// | ||||
/// This enum defined severity level of logged messages | ||||
/// | ||||
typedef enum { | typedef enum { | |||
emergency = 0, | emergency = 0, | |||
alert = 10, | alert = 10, | |||
critical = 20, | critical = 20, | |||
error = 30, | error = 30, | |||
warning = 40, | warning = 40, | |||
notice = 50, | notice = 50, | |||
info = 60, | info = 60, | |||
debug = 70, | debug = 70, | |||
all = 100 | all = 100 | |||
} level_type; | } level_type; | |||
/// | ||||
/// \brief This class represents a single message that should be wri | ||||
tten to log | ||||
/// | ||||
/// Note, it is some generalization of data that allows you to forma | ||||
t any generic | ||||
/// data, it generally used by logging sinks rather then by end user | ||||
s | ||||
/// | ||||
class BOOSTER_API message { | class BOOSTER_API message { | |||
public: | public: | |||
/// | ||||
/// Create message with severity level \a l, sent from modul | ||||
e \a m in file | ||||
/// \a name in line \a line | ||||
/// | ||||
message(level_type l,char const *m,char const *name,int line ); | message(level_type l,char const *m,char const *name,int line ); | |||
/// | ||||
/// Default constructable | ||||
/// | ||||
message(); | message(); | |||
~message(); | ~message(); | |||
/// Copy message | ||||
message(message &); | message(message &); | |||
/// Assign the message | ||||
message &operator=(message &); | message &operator=(message &); | |||
/// | ||||
/// Get the severity level for the message | ||||
/// | ||||
level_type level() const; | level_type level() const; | |||
/// | ||||
/// Get the module name | ||||
/// | ||||
char const *module() const; | char const *module() const; | |||
/// | ||||
/// Get the file name | ||||
/// | ||||
char const *file_name() const; | char const *file_name() const; | |||
/// | ||||
/// Get the number of line in the file | ||||
/// | ||||
int file_line() const; | int file_line() const; | |||
/// | ||||
/// Get the actual message that should be written | ||||
/// | ||||
std::string log_message() const; | std::string log_message() const; | |||
/// | ||||
/// Get the output stream that consumes the message | ||||
/// | ||||
std::ostream &out(); | std::ostream &out(); | |||
private: | private: | |||
level_type level_; | level_type level_; | |||
char const *module_; | char const *module_; | |||
char const *file_name_; | char const *file_name_; | |||
int file_line_; | int file_line_; | |||
std::auto_ptr<std::ostringstream> message_; | std::auto_ptr<std::ostringstream> message_; | |||
struct data; | struct data; | |||
copy_ptr<data> d; | copy_ptr<data> d; | |||
}; | }; | |||
/// | ||||
/// \brief This is the abstract interface to general sink - the cons | ||||
umer | ||||
/// of the logged messages | ||||
/// | ||||
class BOOSTER_API sink : public noncopyable { | class BOOSTER_API sink : public noncopyable { | |||
public: | public: | |||
virtual void log(message const &) = 0; | /// | |||
/// Send the message \a m to log | ||||
/// | ||||
/// Note: it does not have to be thread safe - in terms that | ||||
only | ||||
/// one message is sent each time and it is promised that ar | ||||
e | ||||
/// not sent in parallel | ||||
/// | ||||
virtual void log(message const &m) = 0; | ||||
virtual ~sink() {} | virtual ~sink() {} | |||
}; | }; | |||
/// | ||||
/// \brief This is the central class that manages all logging operat | ||||
ions. | ||||
/// | ||||
/// This is singleton, you access it only via instance() static memb | ||||
er function. | ||||
/// | ||||
/// This class is thread safe | ||||
/// | ||||
class BOOSTER_API logger : public noncopyable { | class BOOSTER_API logger : public noncopyable { | |||
public: | public: | |||
/// | ||||
/// Get the instance of the logger | ||||
/// | ||||
static logger &instance(); | static logger &instance(); | |||
/// | ||||
/// Test if the message with severity level \a level of modu | ||||
le \a module should | ||||
/// be logged. This is generally called before preparing a m | ||||
essage in order | ||||
/// to prevent logging messages that shouldn't be logged | ||||
/// | ||||
bool should_be_logged(level_type level,char const *module); | bool should_be_logged(level_type level,char const *module); | |||
/// | ||||
/// Set specific severity level \a level for a module \a mod | ||||
ule. It would | ||||
/// be logged with different logging level then others. | ||||
/// | ||||
/// Note: \a module string should remain valid all the time | ||||
this log level | ||||
/// is used. It is better to use static strings for these pu | ||||
rposes | ||||
/// | ||||
void set_log_level(level_type level,char const *module); | void set_log_level(level_type level,char const *module); | |||
/// | ||||
/// Reset \a module's logging severity to default | ||||
/// | ||||
void reset_log_level(char const *module); | void reset_log_level(char const *module); | |||
/// | ||||
/// Set default logging level severity | ||||
/// | ||||
void set_default_level(level_type level); | void set_default_level(level_type level); | |||
/// | ||||
/// Add new logging sink - the target that receives messages | ||||
. | ||||
/// It is defined by it's pointer. | ||||
/// | ||||
/// If you plan to remove it, keep the pointer on such logge | ||||
r. | ||||
/// | ||||
void add_sink(shared_ptr<sink> const &s); | void add_sink(shared_ptr<sink> const &s); | |||
/// | ||||
/// Remove a logging sink using its pointer. Note it is enou | ||||
gh to keep | ||||
/// weak pointer on it allowing the logger to destroy the si | ||||
nk. | ||||
/// | ||||
void remove_sink(weak_ptr<sink> const &s); | void remove_sink(weak_ptr<sink> const &s); | |||
/// | ||||
/// Remove all logging sinks from the logger | ||||
/// | ||||
void remove_all_sinks(); | void remove_all_sinks(); | |||
/// | ||||
/// Send a message to the log, note, the message is sent reg | ||||
ardless of its | ||||
/// severity, use should_be_logged before you create the mes | ||||
sage | ||||
/// | ||||
void log(message const &); | void log(message const &); | |||
/// | ||||
/// Get convert the severity level to string | ||||
/// | ||||
static char const *level_to_string(level_type level); | static char const *level_to_string(level_type level); | |||
/// | ||||
/// Convert string to severity level, if the string is inval | ||||
id, std::invalid_argument is thrown | ||||
/// | ||||
static level_type string_to_level(std::string const &); | static level_type string_to_level(std::string const &); | |||
private: | private: | |||
struct entry { | struct entry { | |||
char const *module; | char const *module; | |||
level_type level; | level_type level; | |||
}; | }; | |||
static const int max_entries_size_ = 1024; | static const int max_entries_size_ = 1024; | |||
skipping to change at line 123 | skipping to change at line 227 | |||
~logger(); | ~logger(); | |||
}; | }; | |||
/// | /// | |||
/// \brief This namespace includes various output devices (sinks) fo r logger. | /// \brief This namespace includes various output devices (sinks) fo r logger. | |||
/// | /// | |||
/// It includes several standard devices that can be used in most ap plications | /// It includes several standard devices that can be used in most ap plications | |||
/// | /// | |||
namespace sinks { | namespace sinks { | |||
/// | ||||
/// Convert a logging message to a string with all the data | ||||
that can be | ||||
/// written to file. | ||||
/// | ||||
BOOSTER_API std::string format_plain_text_message(message co nst &msg); | BOOSTER_API std::string format_plain_text_message(message co nst &msg); | |||
/// | ||||
/// stderr based sink - sends messages to standard error out | ||||
put | ||||
/// | ||||
class BOOSTER_API standard_error : public sink { | class BOOSTER_API standard_error : public sink { | |||
public: | public: | |||
standard_error(); | standard_error(); | |||
virtual void log(message const &); | virtual void log(message const &); | |||
virtual ~standard_error(); | virtual ~standard_error(); | |||
private: | private: | |||
struct data; | struct data; | |||
hold_ptr<data> d; | hold_ptr<data> d; | |||
}; | }; | |||
/// | ||||
/// stderr based sink - sends messages to log file | ||||
/// | ||||
class BOOSTER_API file : public sink { | class BOOSTER_API file : public sink { | |||
public: | public: | |||
/// | ||||
/// Creates new object but does not open a file | ||||
/// | ||||
file(); | file(); | |||
virtual ~file(); | virtual ~file(); | |||
/// | ||||
/// Open log file | ||||
/// | ||||
void open(std::string file_name); | void open(std::string file_name); | |||
/// | ||||
/// Enable file rotation and set the maximal number | ||||
of files that should be kept. | ||||
/// | ||||
/// Each time the log opened, the old files are rena | ||||
med, if there are more files | ||||
/// then \a limit, the oldest is removed | ||||
/// | ||||
void max_files(unsigned limit); | void max_files(unsigned limit); | |||
/// | ||||
/// Append to output file rather then create new one | ||||
. | ||||
/// | ||||
void append(); | void append(); | |||
/// Send message to the log | ||||
virtual void log(message const &); | virtual void log(message const &); | |||
private: | private: | |||
void shift(std::string const &base); | void shift(std::string const &base); | |||
std::string format_file(std::string const &,int); | std::string format_file(std::string const &,int); | |||
unsigned max_files_; | unsigned max_files_; | |||
size_t max_size_; | size_t max_size_; | |||
size_t current_size_; | size_t current_size_; | |||
bool opened_; | bool opened_; | |||
bool append_; | bool append_; | |||
struct data; | struct data; | |||
hold_ptr<data> d; | hold_ptr<data> d; | |||
}; | }; | |||
#ifdef BOOSTER_POSIX | #ifdef BOOSTER_POSIX | |||
/// | ||||
/// POSIX syslog sink. | ||||
/// | ||||
class BOOSTER_API syslog : public sink { | class BOOSTER_API syslog : public sink { | |||
public: | public: | |||
/// | ||||
/// Create a new logger. Note: it does not call open | ||||
log, if you want | ||||
/// to provide non-default parameters, you need to c | ||||
all it on your own | ||||
/// | ||||
syslog(); | syslog(); | |||
/// | ||||
/// Send the message to the log | ||||
/// | ||||
virtual void log(message const &); | virtual void log(message const &); | |||
virtual ~syslog(); | virtual ~syslog(); | |||
private: | private: | |||
struct data; | struct data; | |||
hold_ptr<data> d; | hold_ptr<data> d; | |||
}; | }; | |||
#endif | #endif | |||
} // sinks | } // sinks | |||
#define BOOSTER_LOG(_l,_m) | /// | |||
\ | /// \def BOOSTER_LOG(level,module) | |||
::booster::log::logger::instance().should_be_logged(::booste | /// | |||
r::log::_l,_m) \ | /// \brief Log a message with severity \a level of the \a module to | |||
&& ::booster::log::message(::booster::log::_l,_m,__FILE__,__ | the log device if applicable. | |||
LINE__).out() | /// | |||
/// Notes: | ||||
/// | ||||
/// - it first checks of the message should be logged at all, and if | ||||
not, all the rest is not called | ||||
/// - the message is logged in the destruction of the output stream | ||||
object | ||||
/// - the parameter \a level should be given as is "warning" or "deb | ||||
ug" the namespace flags would | ||||
/// be added withing macro | ||||
/// - It may be more convenient to use BOOSTER_WARNING or BOOSTER_DE | ||||
BUG macros | ||||
/// | ||||
/// Example: | ||||
/// | ||||
/// \code | ||||
/// BOOSTER_LOG(warning,"file_system") << "Failed to open file nam | ||||
e " << name; | ||||
/// BOOSTER_CRITICAL("core") << "Failed to allocate memory"; | ||||
/// \endcode | ||||
/// | ||||
#define BOOSTER_LOG(level,module) | ||||
\ | ||||
::booster::log::logger::instance().should_be_logged(::booste | ||||
r::log::level,module) \ | ||||
&& ::booster::log::message(::booster::log::level,module,__FI | ||||
LE__,__LINE__).out() | ||||
#define BOOSTER_EMERG(_m) BOOSTER_LOG(emergency,_m) | /// Same as BOOSTER_LOG(emergency,m) | |||
#define BOOSTER_ALERT(_m) BOOSTER_LOG(alert,_m) | #define BOOSTER_EMERG(m) BOOSTER_LOG(emergency,m) | |||
#define BOOSTER_CRITICAL(_m) BOOSTER_LOG(critical,_m) | /// Same as BOOSTER_LOG(alert,m) | |||
#define BOOSTER_ERROR(_m) BOOSTER_LOG(error,_m) | #define BOOSTER_ALERT(m) BOOSTER_LOG(alert,m) | |||
#define BOOSTER_WARNING(_m) BOOSTER_LOG(warning,_m) | /// Same as BOOSTER_LOG(critical,m) | |||
#define BOOSTER_NOTICE(_m) BOOSTER_LOG(notice,_m) | #define BOOSTER_CRITICAL(m) BOOSTER_LOG(critical,m) | |||
#define BOOSTER_INFO(_m) BOOSTER_LOG(info,_m) | /// Same as BOOSTER_LOG(error,m) | |||
#define BOOSTER_DEBUG(_m) BOOSTER_LOG(debug,_m) | #define BOOSTER_ERROR(m) BOOSTER_LOG(error,m) | |||
/// Same as BOOSTER_LOG(warning,m) | ||||
#define BOOSTER_WARNING(m) BOOSTER_LOG(warning,m) | ||||
/// Same as BOOSTER_LOG(notice,m) | ||||
#define BOOSTER_NOTICE(m) BOOSTER_LOG(notice,m) | ||||
/// Same as BOOSTER_LOG(info,m) | ||||
#define BOOSTER_INFO(m) BOOSTER_LOG(info,m) | ||||
/// Same as BOOSTER_LOG(debug,m) | ||||
#define BOOSTER_DEBUG(m) BOOSTER_LOG(debug,m) | ||||
} // log | } // log | |||
} // booster | } // booster | |||
#endif | #endif | |||
End of changes. 41 change blocks. | ||||
15 lines changed or deleted | 218 lines changed or added | |||
message.h | message.h | |||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
namespace booster { | namespace booster { | |||
namespace locale { | namespace locale { | |||
/// | /// | |||
/// \defgroup message Message Formatting (translation) | /// \defgroup message Message Formatting (translation) | |||
/// | /// | |||
///This module provides message translation functionality, i.e. all ow your application to speak native language | ///This module provides message translation functionality, i.e. all ow your application to speak native language | |||
/// | /// | |||
/// @{ | /// @{ | |||
/// | /// | |||
class info; | ||||
/// | ||||
/// \cond INTERNAL | /// \cond INTERNAL | |||
/// | ||||
template<typename CharType> | template<typename CharType> | |||
struct base_message_format: public std::locale::facet | struct base_message_format: public std::locale::facet | |||
{ | { | |||
}; | }; | |||
/// \endcond | ||||
/// | ||||
/// \brief This facet provides message formatting abilities | ||||
/// | ||||
template<typename CharType> | template<typename CharType> | |||
class message_format : public base_message_format<CharType> | class message_format : public base_message_format<CharType> | |||
{ | { | |||
public: | public: | |||
/// | ||||
/// Character type | ||||
/// | ||||
typedef CharType char_type; | typedef CharType char_type; | |||
/// | ||||
/// String type | ||||
/// | ||||
typedef std::basic_string<CharType> string_type; | typedef std::basic_string<CharType> string_type; | |||
/// | ||||
/// Default constructor | ||||
/// | ||||
message_format(size_t refs = 0) : | message_format(size_t refs = 0) : | |||
base_message_format<CharType>(refs) | base_message_format<CharType>(refs) | |||
{ | { | |||
} | } | |||
/// | ||||
/// This function returns a pointer to string for a message def | ||||
ined by a \a context | ||||
/// and identification string \a id, both create a single key f | ||||
or message lookup in | ||||
/// a domain defined by \a domain_id. | ||||
/// | ||||
/// If translated string is found, it is returned, otherwise NU | ||||
LL is returned | ||||
/// | ||||
/// | ||||
virtual char_type const *get(int domain_id,char const *context, char const *id) const = 0; | virtual char_type const *get(int domain_id,char const *context, char const *id) const = 0; | |||
/// | ||||
/// This function returns a pointer to string for a plural mess | ||||
age defined by a \a context | ||||
/// and identification string \a single_id, both create a singl | ||||
e key for message lookup in | ||||
/// a domain defined \a domain_id. \a n used to pick a correct | ||||
translation string for specific | ||||
/// number. | ||||
/// | ||||
/// If translated string is found, it is returned, otherwise NU | ||||
LL is returned | ||||
/// | ||||
/// | ||||
virtual char_type const *get(int domain_id,char const *context, char const *single_id,int n) const = 0; | virtual char_type const *get(int domain_id,char const *context, char const *single_id,int n) const = 0; | |||
/// | ||||
/// Convert a string that defines \a domain to the integer id u | ||||
sed by \a get functions | ||||
/// | ||||
virtual int domain(std::string const &domain) const = 0; | virtual int domain(std::string const &domain) const = 0; | |||
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |||
std::locale::id& __get_id (void) const { return id; } | std::locale::id& __get_id (void) const { return id; } | |||
#endif | #endif | |||
static message_format<CharType> *create(info const &,std::vecto | ||||
r<std::string> const &paths,std::vector<std::string> const &domains); | ||||
protected: | protected: | |||
virtual ~message_format() | virtual ~message_format() | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// \endcond | ||||
/// | /// | |||
/// \brief This class represents a message that can be converted to specific locale message | /// \brief This class represents a message that can be converted to specific locale message | |||
/// | /// | |||
/// It holds original ASCII string that is queried in the dictionar y when converting to output string. | /// It holds original ASCII string that is queried in the dictionar y when converting to output string. | |||
/// The created string may be UTF-8, UTF-16, UTF-32 or other 8-bit encoded string according to target | /// The created string may be UTF-8, UTF-16, UTF-32 or other 8-bit encoded string according to target | |||
/// character type and locale encoding. | /// character type and locale encoding. | |||
/// | /// | |||
struct message { | struct message { | |||
public: | public: | |||
skipping to change at line 281 | skipping to change at line 309 | |||
} | } | |||
/// | /// | |||
/// Translate message and write to stream \a out, using imbued locale and domain set to the | /// Translate message and write to stream \a out, using imbued locale and domain set to the | |||
/// stream | /// stream | |||
/// | /// | |||
template<typename CharType> | template<typename CharType> | |||
void write(std::basic_ostream<CharType> &out) const | void write(std::basic_ostream<CharType> &out) const | |||
{ | { | |||
std::locale const &loc = out.getloc(); | std::locale const &loc = out.getloc(); | |||
int id = ext_value(out,flags::domain_id); | int id = ios_info::get(out).domain_id(); | |||
std::basic_string<CharType> buffer; | std::basic_string<CharType> buffer; | |||
out << write(loc,id,buffer); | out << write(loc,id,buffer); | |||
} | } | |||
private: | private: | |||
template<typename CharType> | template<typename CharType> | |||
CharType const *write(std::locale const &loc,int domain_id,std: :basic_string<CharType> &buffer) const | CharType const *write(std::locale const &loc,int domain_id,std: :basic_string<CharType> &buffer) const | |||
{ | { | |||
CharType const *translated = 0; | CharType const *translated = 0; | |||
skipping to change at line 467 | skipping to change at line 495 | |||
return message(context,id).str<char>(loc,domain); | return message(context,id).str<char>(loc,domain); | |||
} | } | |||
/// | /// | |||
/// Translate plural form according to locale \a loc in domain \a d omain in context \a context | /// Translate plural form according to locale \a loc in domain \a d omain in context \a context | |||
/// | /// | |||
inline std::string dnpgettext(char const *domain,char const *contex t,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | inline std::string dnpgettext(char const *domain,char const *contex t,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | |||
{ | { | |||
return message(context,s,p,n).str<char>(loc,domain); | return message(context,s,p,n).str<char>(loc,domain); | |||
} | } | |||
#ifndef BOOSTER_NO_STD_WSTRING | ||||
/// | /// | |||
/// Translate message \a id according to locale \a loc | /// Translate message \a id according to locale \a loc | |||
/// | /// | |||
inline std::wstring wgettext(char const *id,std::locale const &loc= std::locale()) | inline std::wstring wgettext(char const *id,std::locale const &loc= std::locale()) | |||
{ | { | |||
return message(id).str<wchar_t>(loc); | return message(id).str<wchar_t>(loc); | |||
} | } | |||
/// | /// | |||
/// Translate plural form according to locale \a loc | /// Translate plural form according to locale \a loc | |||
/// | /// | |||
skipping to change at line 527 | skipping to change at line 553 | |||
return message(context,id).str<wchar_t>(loc,domain); | return message(context,id).str<wchar_t>(loc,domain); | |||
} | } | |||
/// | /// | |||
/// Translate plural form according to locale \a loc in domain \a d omain in context \a context | /// Translate plural form according to locale \a loc in domain \a d omain in context \a context | |||
/// | /// | |||
inline std::wstring wdnpgettext(char const *domain,char const *cont ext,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | inline std::wstring wdnpgettext(char const *domain,char const *cont ext,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | |||
{ | { | |||
return message(context,s,p,n).str<wchar_t>(loc,domain); | return message(context,s,p,n).str<wchar_t>(loc,domain); | |||
} | } | |||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR16_T | #ifdef BOOSTER_HAS_CHAR16_T | |||
/// | /// | |||
/// Translate message \a id according to locale \a loc | /// Translate message \a id according to locale \a loc | |||
/// | /// | |||
inline std::u16string u16gettext(char const *id,std::locale const & loc=std::locale()) | inline std::u16string u16gettext(char const *id,std::locale const & loc=std::locale()) | |||
{ | { | |||
return message(id).str<char16_t>(loc); | return message(id).str<char16_t>(loc); | |||
} | } | |||
/// | /// | |||
/// Translate plural form according to locale \a loc | /// Translate plural form according to locale \a loc | |||
skipping to change at line 665 | skipping to change at line 689 | |||
template<> | template<> | |||
struct BOOSTER_API base_message_format<char> : public std::locale:: facet | struct BOOSTER_API base_message_format<char> : public std::locale:: facet | |||
{ | { | |||
base_message_format(size_t refs = 0) : std::locale::facet(refs) | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |||
{ | { | |||
} | } | |||
static std::locale::id id; | static std::locale::id id; | |||
}; | }; | |||
template<> | template<> | |||
BOOSTER_API message_format<char> *message_format<char>::create( i | ||||
nfo const &, | ||||
std::vector<std::string> const &domains, | ||||
std::vector<std::string> const &paths); | ||||
#ifndef BOOSTER_NO_STD_WSTRING | ||||
template<> | ||||
struct BOOSTER_API base_message_format<wchar_t> : public std::local e::facet | struct BOOSTER_API base_message_format<wchar_t> : public std::local e::facet | |||
{ | { | |||
base_message_format(size_t refs = 0) : std::locale::facet(refs) | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |||
{ | { | |||
} | } | |||
static std::locale::id id; | static std::locale::id id; | |||
}; | }; | |||
template<> | ||||
BOOSTER_API message_format<wchar_t> *message_format<wchar_t>::creat | ||||
e( info const &, | ||||
std::vector<std::string> const &domains, | ||||
std::vector<std::string> const &paths); | ||||
#endif | ||||
#ifdef BOOSTER_HAS_CHAR16_T | #ifdef BOOSTER_HAS_CHAR16_T | |||
template<> | template<> | |||
struct BOOSTER_API base_message_format<char16_t> : public std::loca le::facet | struct BOOSTER_API base_message_format<char16_t> : public std::loca le::facet | |||
{ | { | |||
base_message_format(size_t refs = 0) : std::locale::facet(refs) | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |||
{ | { | |||
} | } | |||
static std::locale::id id; | static std::locale::id id; | |||
}; | }; | |||
template<> | ||||
BOOSTER_API message_format<char16_t> *message_format<char16_t>::cre | ||||
ate( info const &, | ||||
std::vector<std::string> const &domains, | ||||
std::vector<std::string> const &paths); | ||||
#endif | #endif | |||
#ifdef BOOSTER_HAS_CHAR32_T | #ifdef BOOSTER_HAS_CHAR32_T | |||
template<> | template<> | |||
struct BOOSTER_API base_message_format<char32_t> : public std::loca le::facet | struct BOOSTER_API base_message_format<char32_t> : public std::loca le::facet | |||
{ | { | |||
base_message_format(size_t refs = 0) : std::locale::facet(refs) | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |||
{ | { | |||
} | } | |||
static std::locale::id id; | static std::locale::id id; | |||
}; | }; | |||
template<> | ||||
BOOSTER_API message_format<char32_t> *message_format<char32_t>::cre | ||||
ate( info const &, | ||||
std::vector<std::string> const &domains, | ||||
std::vector<std::string> const &paths); | ||||
#endif | #endif | |||
/// \endcond | /// \endcond | |||
/// | /// | |||
/// @} | /// @} | |||
/// | /// | |||
namespace as { | namespace as { | |||
/// \cond INTERNAL | /// \cond INTERNAL | |||
namespace details { | namespace details { | |||
struct set_domain { | struct set_domain { | |||
std::string domain_id; | std::string domain_id; | |||
}; | }; | |||
template<typename CharType> | template<typename CharType> | |||
std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out, set_domain const &dom) | std::basic_ostream<CharType> &operator<<(std::basic_ostream <CharType> &out, set_domain const &dom) | |||
{ | { | |||
int id = std::use_facet<message_format<CharType> >(out. getloc()).domain(dom.domain_id); | int id = std::use_facet<message_format<CharType> >(out. getloc()).domain(dom.domain_id); | |||
ext_value(out,flags::domain_id,id); | ios_info::get(out).domain_id(id); | |||
return out; | return out; | |||
} | } | |||
} // details | } // details | |||
/// \endcond | /// \endcond | |||
/// | /// | |||
/// \addtogroup manipulators | /// \addtogroup manipulators | |||
/// | /// | |||
/// @{ | /// @{ | |||
End of changes. 19 change blocks. | ||||
48 lines changed or deleted | 46 lines changed or added | |||
perl_regex.h | perl_regex.h | |||
---|---|---|---|---|
skipping to change at line 15 | skipping to change at line 15 | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_PERL_REGEX_H | #ifndef BOOSTER_PERL_REGEX_H | |||
#define BOOSTER_PERL_REGEX_H | #define BOOSTER_PERL_REGEX_H | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <booster/copy_ptr.h> | #include <booster/copy_ptr.h> | |||
#include <string> | #include <string> | |||
#include <vector> | #include <vector> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
namespace booster { | namespace booster { | |||
/// | /// | |||
/// \brief Exception that is thrown in case of creation of invalid r egex | /// \brief Exception that is thrown in case of creation of invalid r egex | |||
/// | /// | |||
class regex_error : public std::runtime_error { | class regex_error : public booster::runtime_error { | |||
public: | public: | |||
regex_error(std::string const &s) : std::runtime_error(s) | regex_error(std::string const &s) : booster::runtime_error(s ) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | /// | |||
/// \brief This is a simple wrapper of PCRE library. | /// \brief This is a simple wrapper of PCRE library. | |||
/// | /// | |||
/// It is designed to be used with sub_match, match_results, regex_m atch and regex_search template functions. | /// It is designed to be used with sub_match, match_results, regex_m atch and regex_search template functions. | |||
/// | /// | |||
/// It provides API similar to ones of Boost.Regex but it is also mu ch simplified. | /// It provides API similar to ones of Boost.Regex but it is also mu ch simplified. | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added | |||
refcounted.h | refcounted.h | |||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
#define BOOSTER_REFCOUNTED_H | #define BOOSTER_REFCOUNTED_H | |||
#include <booster/atomic_counter.h> | #include <booster/atomic_counter.h> | |||
namespace booster { | namespace booster { | |||
class refcounted; | class refcounted; | |||
void intrusive_ptr_add_ref(refcounted *ptr); | void intrusive_ptr_add_ref(refcounted *ptr); | |||
void intrusive_ptr_release(refcounted *ptr); | void intrusive_ptr_release(refcounted *ptr); | |||
/// | ||||
/// \brief This class is used as base class for reference counted | ||||
/// objects that use intrusive_ptr. Deriving from this class | ||||
/// allows simple way to manage reference counting for single object | ||||
/// | ||||
class refcounted { | class refcounted { | |||
public: | public: | |||
refcounted() : | refcounted() : | |||
refs_(0) | refs_(0) | |||
{ | { | |||
} | } | |||
virtual ~refcounted() | virtual ~refcounted() | |||
{ | { | |||
} | } | |||
private: | private: | |||
friend void intrusive_ptr_add_ref(refcounted *); | friend void intrusive_ptr_add_ref(refcounted *); | |||
friend void intrusive_ptr_release(refcounted *); | friend void intrusive_ptr_release(refcounted *); | |||
refcounted(refcounted const &other); | refcounted(refcounted const &other); | |||
refcounted const &operator=(refcounted const &other); | refcounted const &operator=(refcounted const &other); | |||
atomic_counter refs_; | atomic_counter refs_; | |||
}; | }; | |||
/// | ||||
/// Increase reference count | ||||
/// | ||||
inline void intrusive_ptr_add_ref(refcounted *p) | inline void intrusive_ptr_add_ref(refcounted *p) | |||
{ | { | |||
++p->refs_; | ++p->refs_; | |||
} | } | |||
/// | ||||
/// Decrease reference count, if it goes to 0, destroy the object | ||||
/// | ||||
inline void intrusive_ptr_release(refcounted *p) | inline void intrusive_ptr_release(refcounted *p) | |||
{ | { | |||
if(p && --p->refs_ == 0) | if(p && --p->refs_ == 0) | |||
delete p; | delete p; | |||
} | } | |||
} | } | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 11 lines changed or added | |||
serialization_classes.h | serialization_classes.h | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// You should have received a copy of the GNU Lesser General Public Licens e | // You should have received a copy of the GNU Lesser General Public Licens e | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#ifndef CPPCMS_SERIALIZATION_CLASSES_H | #ifndef CPPCMS_SERIALIZATION_CLASSES_H | |||
#define CPPCMS_SERIALIZATION_CLASSES_H | #define CPPCMS_SERIALIZATION_CLASSES_H | |||
#include <cppcms/defs.h> | #include <cppcms/defs.h> | |||
#include <booster/copy_ptr.h> | #include <booster/copy_ptr.h> | |||
#include <string> | #include <string> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
#include <booster/traits/enable_if.h> | #include <booster/traits/enable_if.h> | |||
#include <booster/traits/is_base_of.h> | #include <booster/traits/is_base_of.h> | |||
namespace cppcms { | namespace cppcms { | |||
#ifdef CPPCMS_DOXYGEN_DOCS | #ifdef CPPCMS_DOXYGEN_DOCS | |||
/// | /// | |||
/// Special traits class that describes how to serialize various | /// Special traits class that describes how to serialize various | |||
/// objects that are not defived from serializable_base. | /// objects that are not defived from serializable_base. | |||
skipping to change at line 59 | skipping to change at line 59 | |||
#else | #else | |||
template<typename Object,typename Enable = void> | template<typename Object,typename Enable = void> | |||
struct archive_traits; | struct archive_traits; | |||
#endif | #endif | |||
/// | /// | |||
/// Error thrown in case of serialization error | /// Error thrown in case of serialization error | |||
/// | /// | |||
class archive_error : public std::runtime_error { | class archive_error : public booster::runtime_error { | |||
public: | public: | |||
archive_error(std::string const &e) : std::runtime_error("cp pcms::archive_error: " + e) | archive_error(std::string const &e) : booster::runtime_error ("cppcms::archive_error: " + e) | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | /// | |||
/// Class that represents a binary archive that can be stored in per sistent storage or | /// Class that represents a binary archive that can be stored in per sistent storage or | |||
/// transfered. | /// transfered. | |||
/// | /// | |||
class CPPCMS_API archive { | class CPPCMS_API archive { | |||
public: | public: | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added | |||
session_api.h | session_api.h | |||
---|---|---|---|---|
skipping to change at line 72 | skipping to change at line 72 | |||
/// \return true of session was loaded, false otherwise | /// \return true of session was loaded, false otherwise | |||
virtual bool load(session_interface &iface,std::string &data,time_t &timeout) = 0; | virtual bool load(session_interface &iface,std::string &data,time_t &timeout) = 0; | |||
/// | /// | |||
/// Remove the session object | /// Remove the session object | |||
/// | /// | |||
/// \param iface - the session_interface object that allows read and set session cookie | /// \param iface - the session_interface object that allows read and set session cookie | |||
/// | /// | |||
virtual void clear(session_interface &iface) = 0; | virtual void clear(session_interface &iface) = 0; | |||
/// | /// | |||
/// Return true if the session store or save operations are blocking | ||||
or very cpu intensive | ||||
/// | ||||
virtual bool is_blocking() = 0; | ||||
/// | ||||
/// Destructor | /// Destructor | |||
/// | /// | |||
virtual ~session_api() {} | virtual ~session_api() {} | |||
}; | }; | |||
/// | /// | |||
/// \brief the factory object that generates custom implemented session_api objects | /// \brief the factory object that generates custom implemented session_api objects | |||
/// | /// | |||
class session_api_factory { | class session_api_factory { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 6 lines changed or added | |||
session_cookies.h | session_cookies.h | |||
---|---|---|---|---|
skipping to change at line 100 | skipping to change at line 100 | |||
session_cookies(std::auto_ptr<encryptor> encryptor); | session_cookies(std::auto_ptr<encryptor> encryptor); | |||
/// | /// | |||
/// Destroy it and destroy an encryptor it was created with | /// Destroy it and destroy an encryptor it was created with | |||
/// | /// | |||
~session_cookies(); | ~session_cookies(); | |||
/// | /// | |||
/// Save session to cookies, see session_api::save | /// Save session to cookies, see session_api::save | |||
/// | /// | |||
virtual void save(session_interface &,std::string const &dat a,time_t timeout,bool newone ,bool on_server); | virtual void save(session_interface &,std::string const &dat a,time_t timeout,bool newone ,bool on_server); | |||
/// | /// | |||
/// Load session from cookies, see session_api::load | /// Load session from cookies, see session_api::load | |||
/// | /// | |||
virtual bool load(session_interface &,std::string &data,time _t &timeout); | virtual bool load(session_interface &,std::string &data,time _t &timeout); | |||
/// | ||||
/// See session_api::is_blocking | ||||
/// | ||||
virtual bool is_blocking(); | ||||
/// | /// | |||
/// Delete session, see session_api::clear | /// Delete session, see session_api::clear | |||
/// | /// | |||
virtual void clear(session_interface &); | virtual void clear(session_interface &); | |||
private: | private: | |||
struct _data; | struct _data; | |||
booster::hold_ptr<_data> d; | booster::hold_ptr<_data> d; | |||
std::auto_ptr<encryptor> encryptor_; | std::auto_ptr<encryptor> encryptor_; | |||
}; | }; | |||
} // sessions | } // sessions | |||
End of changes. 2 change blocks. | ||||
0 lines changed or deleted | 7 lines changed or added | |||
session_dual.h | session_dual.h | |||
---|---|---|---|---|
skipping to change at line 65 | skipping to change at line 65 | |||
/// | /// | |||
virtual void save(session_interface &,std::string const &data,time_t timeout,bool new_session,bool on_server); | virtual void save(session_interface &,std::string const &data,time_t timeout,bool new_session,bool on_server); | |||
/// | /// | |||
/// See session_api::load | /// See session_api::load | |||
/// | /// | |||
virtual bool load(session_interface &,std::string &data,time_t &time out); | virtual bool load(session_interface &,std::string &data,time_t &time out); | |||
/// | /// | |||
/// See session_api::clear | /// See session_api::clear | |||
/// | /// | |||
virtual void clear(session_interface &); | virtual void clear(session_interface &); | |||
/// | ||||
/// see session_api::is_blocking | ||||
/// | ||||
virtual bool is_blocking(); | ||||
private: | private: | |||
struct _data; | struct _data; | |||
booster::hold_ptr<_data> d; | booster::hold_ptr<_data> d; | |||
booster::shared_ptr<session_cookies> client_; | booster::shared_ptr<session_cookies> client_; | |||
booster::shared_ptr<session_sid> server_; | booster::shared_ptr<session_sid> server_; | |||
size_t data_size_limit_; | size_t data_size_limit_; | |||
}; | }; | |||
} // sessions | } // sessions | |||
} // cppcms | } // cppcms | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 5 lines changed or added | |||
session_interface.h | session_interface.h | |||
---|---|---|---|---|
skipping to change at line 269 | skipping to change at line 269 | |||
/// | /// | |||
bool load(); | bool load(); | |||
/// | /// | |||
/// Save the session data, generally should not be called as it is s aved automatically. However when | /// Save the session data, generally should not be called as it is s aved automatically. However when | |||
/// writing asynchronous application and using custom slow storage d evices like SQL it may be useful to control | /// writing asynchronous application and using custom slow storage d evices like SQL it may be useful to control | |||
/// when and how save() is called. | /// when and how save() is called. | |||
/// | /// | |||
void save(); | void save(); | |||
/// | ||||
/// Returns true if the underlying session back-end uses blocking AP | ||||
I so it is unsuitable to be called | ||||
/// from asynchronous event loop. This can be used to decide how to | ||||
load session for specific connection. | ||||
/// | ||||
/// If the API is blocking you probably should load and save session | ||||
from thread pool rather then | ||||
/// from event loop when using asynchronous applications. | ||||
/// | ||||
bool is_blocking(); | ||||
/// | ||||
/// When using session id based session - force generation of new se | ||||
ssion id to prevent session | ||||
/// fixation attacks | ||||
/// | ||||
void reset_session(); | ||||
private: | private: | |||
friend class http::response; | friend class http::response; | |||
friend class http::request; | friend class http::request; | |||
struct entry; | struct entry; | |||
typedef std::map<std::string,entry> data_type; | typedef std::map<std::string,entry> data_type; | |||
data_type data_,data_copy_; | data_type data_,data_copy_; | |||
http::context *context_; | http::context *context_; | |||
skipping to change at line 294 | skipping to change at line 309 | |||
int timeout_val_; | int timeout_val_; | |||
int how_; | int how_; | |||
// Information from session data | // Information from session data | |||
time_t timeout_in_; | time_t timeout_in_; | |||
uint32_t new_session_ : 1; | uint32_t new_session_ : 1; | |||
uint32_t saved_ : 1; | uint32_t saved_ : 1; | |||
uint32_t on_server_ : 1; | uint32_t on_server_ : 1; | |||
uint32_t loaded_ : 1; | uint32_t loaded_ : 1; | |||
uint32_t reserved_ : 28; | uint32_t reset_ : 1; | |||
uint32_t reserved_ : 27; | ||||
std::string temp_cookie_; | std::string temp_cookie_; | |||
// storage itself | // storage itself | |||
booster::shared_ptr<session_api> storage_; | booster::shared_ptr<session_api> storage_; | |||
struct _data; | struct _data; | |||
booster::hold_ptr<_data> d; // for future use | booster::hold_ptr<_data> d; // for future use | |||
int cookie_age(); | int cookie_age(); | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 21 lines changed or added | |||
session_pool.h | session_pool.h | |||
---|---|---|---|---|
skipping to change at line 78 | skipping to change at line 78 | |||
private: | private: | |||
void after_fork(); | void after_fork(); | |||
struct cookies_factory; | struct cookies_factory; | |||
struct dual_factory; | struct dual_factory; | |||
struct sid_factory; | struct sid_factory; | |||
class gc_job; | class gc_job; | |||
template<typename Encryptor> | template<typename Encryptor> | |||
struct enc_factory; | struct enc_factory; | |||
template<typename Encryptor> | ||||
struct enc_factory_param; | ||||
struct _data; | struct _data; | |||
friend struct cookies_factory; | friend struct cookies_factory; | |||
friend struct dual_factory; | friend struct dual_factory; | |||
friend struct sid_factory; | friend struct sid_factory; | |||
friend class gc_job; | friend class gc_job; | |||
booster::hold_ptr<_data> d; | booster::hold_ptr<_data> d; | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 2 lines changed or added | |||
session_sid.h | session_sid.h | |||
---|---|---|---|---|
skipping to change at line 55 | skipping to change at line 55 | |||
~session_sid(); | ~session_sid(); | |||
/// | /// | |||
/// See session_api::save | /// See session_api::save | |||
/// | /// | |||
virtual void save(session_interface &,std::string const &dat a,time_t timeout,bool,bool); | virtual void save(session_interface &,std::string const &dat a,time_t timeout,bool,bool); | |||
/// | /// | |||
/// See session_api::load | /// See session_api::load | |||
/// | /// | |||
virtual bool load(session_interface &,std::string &data,time _t &timeout); | virtual bool load(session_interface &,std::string &data,time _t &timeout); | |||
/// | /// | |||
/// See session_api::is_blocking | ||||
/// | ||||
virtual bool is_blocking(); | ||||
/// | ||||
/// See session_api::clear | /// See session_api::clear | |||
/// | /// | |||
virtual void clear(session_interface &); | virtual void clear(session_interface &); | |||
private: | private: | |||
std::string get_new_sid(); | ||||
bool valid_sid(std::string const &cookie,std::string &id); | bool valid_sid(std::string const &cookie,std::string &id); | |||
std::string key(std::string sid); | ||||
struct _data; | struct _data; | |||
booster::hold_ptr<_data> d; | booster::hold_ptr<_data> d; | |||
booster::shared_ptr<session_storage> storage_; | booster::shared_ptr<session_storage> storage_; | |||
}; | }; | |||
} // sessions | } // sessions | |||
} // cppcms | } // cppcms | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 6 lines changed or added | |||
session_storage.h | session_storage.h | |||
---|---|---|---|---|
skipping to change at line 61 | skipping to change at line 61 | |||
/// | /// | |||
virtual bool load(std::string const &sid,time_t &timeout,std ::string &out) = 0; | virtual bool load(std::string const &sid,time_t &timeout,std ::string &out) = 0; | |||
/// | /// | |||
/// Remove a session with id \a sid from the storage | /// Remove a session with id \a sid from the storage | |||
/// | /// | |||
virtual void remove(std::string const &sid) = 0; | virtual void remove(std::string const &sid) = 0; | |||
/// | /// | |||
/// Return true of the save or load operations can be blocki | ||||
ng | ||||
/// | ||||
virtual bool is_blocking() = 0; | ||||
/// | ||||
/// Destroy an object | /// Destroy an object | |||
/// | /// | |||
virtual ~session_storage() | virtual ~session_storage() | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | /// | |||
/// \brief The factory is an interface to a factory that creates ses sion_storage objects, it should be thread safe. | /// \brief The factory is an interface to a factory that creates ses sion_storage objects, it should be thread safe. | |||
/// | /// | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 6 lines changed or added | |||
shared_ptr.h | shared_ptr.h | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
// See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentatio n. | // See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentatio n. | |||
// | // | |||
#include <booster/config.h> // for broken compiler workarounds | #include <booster/config.h> // for broken compiler workarounds | |||
#include <memory> | #include <memory> | |||
#include <cassert> | #include <cassert> | |||
#include <booster/backtrace.h> | ||||
#include <booster/checked_delete.h> | #include <booster/checked_delete.h> | |||
#include <booster/smart_ptr/shared_count.h> | #include <booster/smart_ptr/shared_count.h> | |||
#include <booster/smart_ptr/sp_convertible.h> | #include <booster/smart_ptr/sp_convertible.h> | |||
#include <algorithm> // for std::swap | #include <algorithm> // for std::swap | |||
#include <functional> // for std::less | #include <functional> // for std::less | |||
#include <typeinfo> // for std::bad_cast | #include <typeinfo> // for std::bad_cast | |||
#include <iosfwd> // for std::basic_ostream | #include <iosfwd> // for std::basic_ostream | |||
skipping to change at line 216 | skipping to change at line 217 | |||
{ | { | |||
pn = booster::detail::shared_count(); | pn = booster::detail::shared_count(); | |||
} | } | |||
} | } | |||
template<class Y> | template<class Y> | |||
shared_ptr(shared_ptr<Y> const & r, booster::detail::polymorphic_cast_t ag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn) | shared_ptr(shared_ptr<Y> const & r, booster::detail::polymorphic_cast_t ag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn) | |||
{ | { | |||
if(px == 0) | if(px == 0) | |||
{ | { | |||
throw std::bad_cast(); | throw booster::bad_cast(); | |||
} | } | |||
} | } | |||
template<class Y> | template<class Y> | |||
explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn() | explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn() | |||
{ | { | |||
Y * tmp = r.get(); | Y * tmp = r.get(); | |||
pn = booster::detail::shared_count(r); | pn = booster::detail::shared_count(r); | |||
booster::detail::sp_enable_shared_from_this( this, tmp, tmp ); | booster::detail::sp_enable_shared_from_this( this, tmp, tmp ); | |||
} | } | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 2 lines changed or added | |||
streambuf.h | streambuf.h | |||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <streambuf> | #include <streambuf> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <booster/hold_ptr.h> | #include <booster/hold_ptr.h> | |||
#include <memory> | #include <memory> | |||
#include <vector> | #include <vector> | |||
namespace booster { | namespace booster { | |||
/// | ||||
/// \brief This class is a base class of generic I/O device that can | ||||
be | ||||
/// used in very simple manner with booster::streambuf allowing to c | ||||
reate | ||||
/// iostreams easily | ||||
/// | ||||
class io_device { | class io_device { | |||
public: | public: | |||
/// | ||||
/// Seek reference | ||||
/// | ||||
typedef enum { | typedef enum { | |||
set, | set, //!< Set actual position (i.e. SEEK_CUR) | |||
cur, | cur, //!< Set relatively to current position (i.e. S | |||
end | EEK_CUR) | |||
end //!< Set relatively to end of file (i.e. SEEK_E | ||||
ND) | ||||
} pos_type; | } pos_type; | |||
/// | ||||
/// Read \a length bytes from the stream to buffer \a pos, r | ||||
eturn number of bytes | ||||
/// actually read. If return value is less then length, it i | ||||
s considered end of file | ||||
/// | ||||
/// If the stream is write only, do not implement (returns E | ||||
OF by default) | ||||
/// | ||||
virtual size_t read(char *pos,size_t length) | virtual size_t read(char *pos,size_t length) | |||
{ | { | |||
return 0; | return 0; | |||
} | } | |||
/// | ||||
/// Write \a length bytes to the devise from buffer \a pos, | ||||
return number of bytes | ||||
/// actually written, if the result is less then \a length, | ||||
considered as EOF. | ||||
/// | ||||
/// If the stream is read only, do not implement (returns EO | ||||
F by default) | ||||
/// | ||||
virtual size_t write(char const *pos,size_t length) | virtual size_t write(char const *pos,size_t length) | |||
{ | { | |||
return 0; | return 0; | |||
} | } | |||
/// | ||||
/// Seek the device to \a position relatively to \a pos. Ret | ||||
urn current position | ||||
/// in file. | ||||
/// | ||||
/// If error occurs return -1. | ||||
/// | ||||
/// If the stream is not seekable do not reimplement, return | ||||
s -1 by default. | ||||
/// | ||||
virtual long long seek(long long position,pos_type pos = set ) | virtual long long seek(long long position,pos_type pos = set ) | |||
{ | { | |||
return -1; | return -1; | |||
} | } | |||
virtual ~io_device() | virtual ~io_device() | |||
{ | { | |||
} | } | |||
}; | }; | |||
/// | ||||
/// \brief this is an implementation of generic streambuffer | ||||
/// | ||||
class BOOSTER_API streambuf : public std::streambuf { | class BOOSTER_API streambuf : public std::streambuf { | |||
public: | public: | |||
/// | ||||
/// Create a new stream buffer - without a stream | ||||
/// | ||||
streambuf(); | streambuf(); | |||
~streambuf(); | ~streambuf(); | |||
/// | ||||
/// Assign an io_device to the streambuf transferring an own | ||||
ership on it | ||||
/// | ||||
void device(std::auto_ptr<io_device> d); | void device(std::auto_ptr<io_device> d); | |||
/// | ||||
/// Assign an existing io_device to the streambuf. | ||||
/// | ||||
void device(io_device &d); | void device(io_device &d); | |||
/// | ||||
/// Detach currently attached io_device from the streambuf. | ||||
If it is owned, it is destroyed. | ||||
/// | ||||
void reset_device(); | void reset_device(); | |||
/// | ||||
/// Get the io_device that is in use | ||||
/// | ||||
io_device &device(); | io_device &device(); | |||
/// | ||||
/// Set the size of the internal buffer that is used for rea | ||||
d and write operations. Default | ||||
/// is 1024 bytes for each direction | ||||
/// | ||||
void set_buffer_size(size_t n); | void set_buffer_size(size_t n); | |||
protected: | protected: | |||
// Seek | // Seek | |||
virtual std::streampos seekoff( std::streamoff off, | virtual std::streampos seekoff( std::streamoff off, | |||
std::ios_base::seekdir way, | std::ios_base::seekdir way, | |||
std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); | std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); | |||
virtual std::streampos seekpos( std::streampos pos, | virtual std::streampos seekpos( std::streampos pos, | |||
std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); | std::ios_base::openmode m = std::ios_base::in | std::ios_base::out); | |||
// Get | // Get | |||
virtual int underflow(); | virtual int underflow(); | |||
virtual int pbackfail(int c = EOF); | ||||
// Put | // Put | |||
virtual int overflow(int c = EOF); | virtual int overflow(int c = EOF); | |||
virtual int sync(); | virtual int sync(); | |||
private: | private: | |||
std::vector<char> buffer_out_; | std::vector<char> buffer_out_; | |||
std::vector<char> buffer_in_; | std::vector<char> buffer_in_; | |||
End of changes. 14 change blocks. | ||||
3 lines changed or deleted | 71 lines changed or added | |||
system_error.h | system_error.h | |||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
// Copyright (c) 2010 Artyom Beilis (Tonkikh) | // Copyright (c) 2010 Artyom Beilis (Tonkikh) | |||
// | // | |||
// Distributed under the Boost Software License, Version 1.0. (See | // Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | // accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
#ifndef BOOSTER_SYSTEM_ERROR_H | #ifndef BOOSTER_SYSTEM_ERROR_H | |||
#define BOOSTER_SYSTEM_ERROR_H | #define BOOSTER_SYSTEM_ERROR_H | |||
#include <string> | #include <string> | |||
#include <stdexcept> | #include <booster/backtrace.h> | |||
#include <functional> | #include <functional> | |||
#include <booster/config.h> | #include <booster/config.h> | |||
namespace booster { | namespace booster { | |||
/// | /// | |||
/// \brief this namespace includes partial implementation of std::tr1's/boo st's system_error, error_code | /// \brief this namespace includes partial implementation of std::tr1's/boo st's system_error, error_code | |||
/// classes | /// classes | |||
/// | /// | |||
skipping to change at line 101 | skipping to change at line 101 | |||
inline bool operator==(error_code const &left,error_code const &righ t) | inline bool operator==(error_code const &left,error_code const &righ t) | |||
{ | { | |||
return left.value() == right.value() && left.category() == r ight.category(); | return left.value() == right.value() && left.category() == r ight.category(); | |||
} | } | |||
inline bool operator!=(error_code const &left,error_code const &righ t) | inline bool operator!=(error_code const &left,error_code const &righ t) | |||
{ | { | |||
return !(left==right); | return !(left==right); | |||
} | } | |||
class system_error : public std::runtime_error { | class system_error : public booster::runtime_error { | |||
public: | public: | |||
system_error(error_code const &e) : | system_error(error_code const &e) : | |||
std::runtime_error(e.message()), | booster::runtime_error(e.message()), | |||
error_(e) | error_(e) | |||
{ | { | |||
} | } | |||
system_error(error_code const &e,std::string const &message) : | system_error(error_code const &e,std::string const &message) : | |||
std::runtime_error(e.message()+": " + message), | booster::runtime_error(e.message()+": " + message), | |||
error_(e) | error_(e) | |||
{ | { | |||
} | } | |||
error_code const &code() const | error_code const &code() const | |||
{ | { | |||
return error_; | return error_; | |||
} | } | |||
private: | private: | |||
error_code error_; | error_code error_; | |||
}; | }; | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added | |||
thread.h | thread.h | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
#include <booster/noncopyable.h> | #include <booster/noncopyable.h> | |||
#include <booster/function.h> | #include <booster/function.h> | |||
#include <booster/config.h> | #include <booster/config.h> | |||
#include <memory> | #include <memory> | |||
namespace booster { | namespace booster { | |||
extern "C" void *booster_thread_func(void *); | extern "C" void *booster_thread_func(void *); | |||
/// | ||||
/// \brief the class that allows to start an execution thread | ||||
/// | ||||
class BOOSTER_API thread : public noncopyable { | class BOOSTER_API thread : public noncopyable { | |||
public: | public: | |||
/// | ||||
/// Run a function \a cb in separate thread | ||||
/// | ||||
thread(function<void()> const &cb); | thread(function<void()> const &cb); | |||
~thread(); | ~thread(); | |||
/// | ||||
/// Join existing thread | ||||
/// | ||||
void join(); | void join(); | |||
private: | private: | |||
friend void *booster_thread_func(void *); | friend void *booster_thread_func(void *); | |||
struct data; | struct data; | |||
hold_ptr<data> d; | hold_ptr<data> d; | |||
}; | }; | |||
class condition_variable; | class condition_variable; | |||
class BOOSTER_API mutex : public noncopyable { | class BOOSTER_API mutex : public noncopyable { | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 9 lines changed or added | |||
util.h | util.h | |||
---|---|---|---|---|
/////////////////////////////////////////////////////////////////////////// | ||||
//// | ||||
// | ||||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | ||||
// | ||||
// This program is free software: you can redistribute it and/or modify | ||||
// it under the terms of the GNU Lesser General Public License as publishe | ||||
d by | ||||
// the Free Software Foundation, either version 3 of the License, or | ||||
// (at your option) any later version. | ||||
// | // | |||
// This program is distributed in the hope that it will be useful, | // Copyright (c) 2009-2010 Artyom Beilis (Tonkikh) | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
// GNU Lesser General Public License for more details. | ||||
// | // | |||
// You should have received a copy of the GNU Lesser General Public Licens | // Distributed under the Boost Software License, Version 1.0. (See | |||
e | // accompanying file LICENSE_1_0.txt or copy at | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | // http://www.boost.org/LICENSE_1_0.txt) | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// | #ifndef BOOSTER_LOCALE_UTIL_HPP | |||
//// | #define BOOSTER_LOCALE_UTIL_HPP | |||
#ifndef CPPCMS_UTIL_H | #include <locale> | |||
#define CPPCMS_UTIL_H | #include <booster/cstdint.h> | |||
#include <booster/locale/generator.h> | ||||
#include <cppcms/defs.h> | #include <vector> | |||
#include <string> | namespace booster { | |||
namespace locale { | ||||
/// | ||||
/// \brief This namespace provides various utility function useful for Boos | ||||
t.Locale backends | ||||
/// implementations | ||||
/// | ||||
namespace util { | ||||
namespace cppcms { | /// | |||
/// \brief Return default system locale name in POSIX format. | ||||
/// | ||||
/// This function tries to detect the locale using, LC_CTYPE, LC_ALL an | ||||
d LANG environment | ||||
/// variables in this order and if all of them unset, in POSIX platform | ||||
s it returns "C" | ||||
/// | ||||
/// On Windows additionally to check the above environment variables, t | ||||
his function | ||||
/// tries to creates locale name from ISO-339 and ISO-3199 country code | ||||
s defined | ||||
/// for user default locale. | ||||
/// If \a use_utf8_on_windows is true it sets the encoding to UTF-8, ot | ||||
herwise, if system | ||||
/// locale supports ANSI code-page it defines the ANSI encoding like wi | ||||
ndows-1252, otherwise it fall-backs | ||||
/// to UTF-8 encoding if ANSI code-page is not available. | ||||
/// | ||||
BOOSTER_API | ||||
std::string get_system_locale(bool use_utf8_on_windows = false); | ||||
/// | /// | |||
/// \brief This namespace holds various useful helper functions for | /// \brief Installs information facet to locale in based on locale name | |||
we developer | \a name | |||
/// | /// | |||
/// This function installs boost::locale::info facet into the locale \a | ||||
in and returns | ||||
/// newly created locale. | ||||
/// | ||||
/// Note: all information is based only on parsing of string \a name; | ||||
/// | ||||
BOOSTER_API | ||||
std::locale create_info(std::locale const &in,std::string const &name); | ||||
namespace util { | /// | |||
/// | /// \brief This class represent a simple stateless converter from UCS-4 | |||
/// Escape string for inclusion in HTML page, i.e. | and to UCS-4 for | |||
/// | /// each single code point | |||
/// - < - \< | /// | |||
/// - > - \> | /// This class is used for creation of std::codecvt facet for convertin | |||
/// - \& - \& | g utf-16/utf-32 encoding | |||
/// - " - \" | /// to encoding supported by this converter | |||
/// | /// | |||
/// Note, this function does not deal with encodings, so it' | /// Please not, this converter should be fully stateless. By meaning fu | |||
s up to you to | lly stateless it should | |||
/// provide valid text encoding | /// never assume that it is called in any specific order on the text. E | |||
/// | ven if the | |||
std::string CPPCMS_API escape(std::string const &s); | /// encoding itself seems to be stateless like windows-1255 or shift-ji | |||
/// | s, some | |||
/// Encode string for URL (percent encoding) | /// encoders (most notably iconv) can actually compose several code-poi | |||
/// | nt into one or | |||
std::string CPPCMS_API urlencode(std::string const &s); | /// decompose then in case composite characters are found. So be very c | |||
/// | areful when implementing | |||
/// Decode string from URL-encoding (percent-encoding) | /// these converters for certain character set. | |||
/// | /// | |||
std::string CPPCMS_API urldecode(std::string const &s); | class base_converter { | |||
/// | public: | |||
/// Decode text in range [begin,end) from URL-encoding (perc | ||||
ent-encoding) | ||||
/// | ||||
std::string CPPCMS_API urldecode(char const *begin,char cons | ||||
t *end); | ||||
/// | ||||
/// Make MD5 hash of string \a input converting into binary | ||||
string of 16 bytes | ||||
/// | ||||
std::string CPPCMS_API md5(std::string const &input); | ||||
/// | ||||
/// Make MD5 hash of string \a input converting it into hexa | ||||
decimal string representing this hash | ||||
/// | ||||
std::string CPPCMS_API md5hex(std::string const &input); | ||||
} | /// | |||
} | /// This value should be returned in illegal input sequence or code | |||
-point is observed: | ||||
/// For example if UCS-32 code-point in rage reserved for UTF-16 su | ||||
rrogates ais met | ||||
/// or invalid UTF-8 sequence is found | ||||
/// | ||||
static const uint32_t illegal=0xFFFFFFFF; | ||||
/// | ||||
/// This value is returned in case of incomplete input sequence or | ||||
for to_unicode or | ||||
/// too small buffer for from_unicode functions | ||||
/// | ||||
static const uint32_t incomplete=0xFFFFFFFE; | ||||
virtual ~base_converter() | ||||
{ | ||||
} | ||||
/// | ||||
/// Return the maximal length that one Unicode code-point can be co | ||||
nverted, for example | ||||
/// for UTF-8 it is 4, for Shift-JIS it is 2 and ISO-8859-1 is 1 | ||||
/// | ||||
virtual int max_len() const | ||||
{ | ||||
return 1; | ||||
} | ||||
/// | ||||
/// Returns true if calling functions from_unicode, to_unicode, max | ||||
_len is thread safe. | ||||
/// | ||||
/// Rule of thumb: if this class implementation uses simple tables | ||||
that are unchanged | ||||
/// or is pure algorithmic like UTF-8 - so it does not share any mu | ||||
table bit for | ||||
/// independent to_unicode, from_unicode calls, you may set it to t | ||||
rue, otherwise, | ||||
/// for example if you use iconv_t descriptor or UConverter as conv | ||||
ersion object return false, | ||||
/// and this object would be cloned for each use. | ||||
/// | ||||
virtual bool is_thread_safe() const | ||||
{ | ||||
return false; | ||||
} | ||||
/// | ||||
/// Create a polymorphic copy of this object, usually called only i | ||||
f is_thread_safe() return false | ||||
/// | ||||
virtual base_converter *clone() const | ||||
{ | ||||
return new base_converter(); | ||||
} | ||||
/// | ||||
/// Convert a single character starting at begin and ending at most | ||||
at end to Unicode code-point. | ||||
/// | ||||
/// if valid input sequence found in [\a begin,\a code_point_end) s | ||||
uch as \a begin < \a code_point_end && \a code_point_end <= \a end | ||||
/// it is converted to its Unicode code point equivalent, \a begin | ||||
is set to \a code_point_end | ||||
/// | ||||
/// if incomplete input sequence found in [\a begin,\a end), i.e. t | ||||
here my be such \a code_point_end that \a code_point_end > \a end | ||||
/// and [\a begin, \a code_point_end) would be valid input sequence | ||||
, then \a incomplete is returned begin stays unchanged, for example | ||||
/// for UTF-8 conversion a *begin = 0xc2, \a begin +1 = \a end is s | ||||
uch situation. | ||||
/// | ||||
/// if invalid input sequence found, i.e. there there is a sequence | ||||
[\a begin, \a code_point_end) such as \a code_point_end <= \a end | ||||
/// that is illegal for this encoding, \a illegal is returned and b | ||||
egin stays unchanged. For example if *begin = 0xFF and begin < end | ||||
/// for UTF-8, then \a illegal is returned. | ||||
/// | ||||
/// | ||||
virtual uint32_t to_unicode(char const *&begin,char const *end) | ||||
{ | ||||
if(begin == end) | ||||
return incomplete; | ||||
unsigned char cp = *begin; | ||||
if(cp <= 0x7F) { | ||||
begin++; | ||||
return cp; | ||||
} | ||||
return illegal; | ||||
} | ||||
/// | ||||
/// Convert a single code-point \a u into encoding and store it in | ||||
[begin,end) range. | ||||
/// | ||||
/// If u is invalid Unicode code-point, or it can not be mapped cor | ||||
rectly to represented character set, | ||||
/// \a illegal should be returned | ||||
/// | ||||
/// If u can be converted to a sequence of bytes c1, ... , cN (1<= | ||||
N <= max_len() ) then | ||||
/// | ||||
/// -# If end - begin >= N, c1, ... cN are written starting at begi | ||||
n and N is returned | ||||
/// -# If end - begin < N, incomplete is returned, it is unspecifie | ||||
d what would be | ||||
/// stored in bytes in range [begin,end) | ||||
virtual uint32_t from_unicode(uint32_t u,char *begin,char const *en | ||||
d) | ||||
{ | ||||
if(begin==end) | ||||
return incomplete; | ||||
if(u >= 0x80) | ||||
return illegal; | ||||
*begin = static_cast<char>(u); | ||||
return 1; | ||||
} | ||||
}; | ||||
/// | ||||
/// This function creates a \a base_converter that can can be used for | ||||
conversion between UTF-8 and | ||||
/// unicode code points | ||||
/// | ||||
BOOSTER_API std::auto_ptr<base_converter> create_utf8_converter(); | ||||
/// | ||||
/// This function creates a \a base_converter that can can be used for | ||||
conversion between single byte | ||||
/// character encodings like ISO-8859-1, koi8-r, windows-1255 and Unico | ||||
de code points, | ||||
/// | ||||
/// If \a encoding is not supported, empty pointer is returned. You sho | ||||
uld check if | ||||
/// std::auto_ptr<base_converter>::get() != 0 | ||||
/// | ||||
BOOSTER_API std::auto_ptr<base_converter> create_simple_converter(std:: | ||||
string const &encoding); | ||||
/// | ||||
/// Install codecvt facet into locale \a in and return new locale that | ||||
is based on \a in and uses new | ||||
/// facet. | ||||
/// | ||||
/// codecvt facet would convert between narrow and wide/char16_t/char32 | ||||
_t encodings using \a cvt converter. | ||||
/// If \a cvt is null pointer, always failure conversion would be used | ||||
that fails on every first input or output. | ||||
/// | ||||
/// Note: the codecvt faced handles both UTF-16 and UTF-32 wide encodin | ||||
gs, it know to break and join | ||||
/// Unicode code-points above 0xFFFF to and from surrogate pairs correc | ||||
tly. \a cvt should be unaware | ||||
/// of wide encoding type | ||||
/// | ||||
BOOSTER_API | ||||
std::locale create_codecvt(std::locale const &in,std::auto_ptr<base_con | ||||
verter> cvt,character_facet_type type); | ||||
} // util | ||||
} // locale | ||||
} // boost | ||||
#endif | #endif | |||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||||
End of changes. 10 change blocks. | ||||
68 lines changed or deleted | 234 lines changed or added | |||