From 8286ac511144e4f17d34eac9affb97e50646344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:25:44 +0200 Subject: Imported Upstream version 4.0.0 --- libxsd-frontend/xsd-frontend/types.hxx | 242 ++++++++++++++++++++++++++++++++- 1 file changed, 237 insertions(+), 5 deletions(-) (limited to 'libxsd-frontend/xsd-frontend/types.hxx') diff --git a/libxsd-frontend/xsd-frontend/types.hxx b/libxsd-frontend/xsd-frontend/types.hxx index b3059fd..0cd1ad1 100644 --- a/libxsd-frontend/xsd-frontend/types.hxx +++ b/libxsd-frontend/xsd-frontend/types.hxx @@ -1,18 +1,250 @@ // file : xsd-frontend/types.hxx -// author : Boris Kolpackov -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_FRONTEND_TYPES_HXX #define XSD_FRONTEND_TYPES_HXX -#include +#include +#include // std::size_t namespace XSDFrontend { - using namespace Cult::Types; + using std::size_t; - typedef Cult::WideString String; + 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 WideString String; } #endif // XSD_FRONTEND_TYPES_HXX -- cgit v1.2.3