From 26899a31d9a85e6ec6cfb782b0977af05e3330c1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Jun 2012 11:51:14 +0200 Subject: Get rid of dependency on libcult --- xsd-frontend/types.hxx | 237 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 4 deletions(-) (limited to 'xsd-frontend/types.hxx') diff --git a/xsd-frontend/types.hxx b/xsd-frontend/types.hxx index f3512e1..5e7793e 100644 --- a/xsd-frontend/types.hxx +++ b/xsd-frontend/types.hxx @@ -6,17 +6,246 @@ #ifndef XSD_FRONTEND_TYPES_HXX #define XSD_FRONTEND_TYPES_HXX +#include #include // std::size_t -#include - namespace XSDFrontend { using std::size_t; - using namespace Cult::Types; + namespace Bits + { + struct None {}; + + template + struct NarrowerChar + { + typedef None Type; + }; + + template <> + struct NarrowerChar + { + typedef char Type; + }; + } + + struct NonRepresentable: std::exception + { + virtual char const* + what () const throw (); + }; + + template ::Type> + class StringTemplate; + + template <> + class StringTemplate + { + }; + + template + class StringTemplate : public std::basic_string + { + typedef std::basic_string Base; + typedef std::basic_string NarrowerBase; + + Base& + base () + { + return *this; + } + + Base const& + base () const + { + return *this; + } + + public: + typedef typename Base::size_type size_type; + + using Base::npos; + + public: + StringTemplate () + { + } + + StringTemplate (StringTemplate const& str, + size_type pos, + size_type n = npos) + : Base (str, pos, n) + { + } + + StringTemplate (C const* s, size_type n) + : Base (s, n) + { + } + + StringTemplate (C const* s) + : Base (s) + { + } + + StringTemplate (size_type n, C c) + : Base (n, c) + { + } + + template + StringTemplate(I begin, I end) + : Base (begin, end) + { + } + + StringTemplate (StringTemplate const& other) + : Base (other) + { + } + + // Conversion from Base. + // + StringTemplate (Base const& str) + : Base (str) + { + } + + // Conversion from the Narrower type. Experimental. + // + StringTemplate (NC const* s) + { + from_narrow (s); + } + + StringTemplate (StringTemplate const& other) + { + from_narrow (other.c_str ()); + } + + StringTemplate (NarrowerBase const& other) + { + from_narrow (other.c_str ()); + } + + // Assignment. + // + StringTemplate& + operator= (StringTemplate const& str) + { + base () = str; + return *this; + } + + StringTemplate& + operator= (C const* s) + { + base () = s; + return *this; + } + + StringTemplate& + operator= (C c) + { + base () = c; + return *this; + } + + // Assignment from Base. + // + StringTemplate& + operator= (Base const& str) + { + base () = str; + return *this; + } + + public: + StringTemplate& + operator+= (StringTemplate const& str) + { + base () += str; + return *this; + } + + StringTemplate& + operator+= (C const* s) + { + base () += s; + return *this; + } + + StringTemplate& + operator+= (C c) + { + base () += c; + return *this; + } + + // Conversion to the Narrower type. + // + public: + StringTemplate + to_narrow () const; + + // Conversion to bool. + // + private: + typedef void (StringTemplate::*BooleanConvertible)(); + void true_ () {} + + public: + operator BooleanConvertible () const + { + return this->empty () ? 0 : &StringTemplate::true_; + } + + private: + void + from_narrow (NC const* s); + }; + + + template + StringTemplate + operator+ (StringTemplate const& lhs, StringTemplate const& rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (C const* lhs, StringTemplate const& rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (StringTemplate const& lhs, C const* rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (C lhs, StringTemplate const& rhs) + { + return StringTemplate (1, lhs) += rhs; + } + + template + StringTemplate + operator+ (StringTemplate const& lhs, C rhs) + { + return StringTemplate (lhs) += rhs; + } + + typedef StringTemplate NarrowString; + typedef StringTemplate WideString; - typedef Cult::WideString String; + typedef WideString String; } #endif // XSD_FRONTEND_TYPES_HXX -- cgit v1.1