
Five Considerations for Software Architects Kevlin Henney [email protected] Economy There's nothing long-winded about "Liberté, égalité, fraternité". Maurice Saatchi Continuing existence or cessation of existence: those are the scenarios. Is it more empowering mentally to work towards an accommodation of the downsizings and negative outcomes of adversarial circumstance, or would it be a greater enhancement of the bottom line to move forwards to a challenge to our current difficulties, and, by making a commitment to opposition, to effect their demise? Tom Burton, Long Words Bother Me To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? William Shakespeare, Hamlet #ifndef BOOST_LEXICAL_CAST_INCLUDED typename stringstream<CharType>::type interpreter(arg); &>::do_cast(arg); // mpl::apply_if doesn't work well for MSVC 6 here, and neither does #define BOOST_LEXICAL_CAST_INCLUDED #endif } // inheriting from a metafunction // Boost lexical_cast.hpp header -------------------------------------------// setup_interpreter<Target, Source>(interpreter); template<typename CharType, typename CharTraits, typename Allocator, typename Source> template<class Target, class Source> // inline std::basic_string<CharType, CharTraits, Allocator> struct select_base // See http://www.boost.org for most recent version including documentation. Target result; lexical_cast_impl(std::basic_string<CharType, CharTraits, Allocator> *, Source arg) { // { typedef typename mpl::if_<is_same<Target, char>, // Target==char? // what: lexical_cast custom keyword cast if(!(interpreter >> result) || !(interpreter >> std::ws).eof()) return any_to_string_base<std::basic_string<CharType, CharTraits, Allocator>, Source, typename mpl::if_<is_same<Source, char>, // Source==char? // who: contributed by Kevlin Henney and enhanced by Terje Slettebø throw detail::no_lexical_conversion<Target, Source>(); CharType>::do_cast(arg); direct_cast_base<Target, Source>, // when: November 2000, March 2003 } typename mpl::if_<is_same<Source, char *>, // Source==char *? return result; pointer_to_char_to_char_base<Target, Source>, #include <typeinfo> } template<typename CharType, typename CharTraits, typename Allocator> typename mpl::if_<is_same<Source, const char *>, // Source==const char *? #include <string> }; inline std::basic_string<CharType, CharTraits, Allocator> pointer_to_char_to_char_base<Target, Source>, #include <boost/config.hpp> lexical_cast_impl(std::basic_string<CharType, CharTraits, Allocator> *, CharType arg) typename mpl::if_<is_same<Source, std::string>, // Source==std::string? #include <boost/limits.hpp> ////////////////////////////////////////////////////////////////////////// { string_to_char_base<Target, const Source &>, #include <boost/static_assert.hpp> // any_to_string_base return char_to_string_base<std::basic_string<CharType, CharTraits, Allocator>, CharType>::do_cast(arg); lexical_cast_base<Target, Source, char> ////////////////////////////////////////////////////////////////////////// } >::type #ifdef BOOST_NO_STRINGSTREAM >::type #include <strstream> template<typename Target, typename Source, typename CharType> template<typename CharType, typename CharTraits, typename Allocator> >::type #else struct any_to_string_base inline std::basic_string<CharType, CharTraits, Allocator> >::type, #include <sstream> { lexical_cast_impl(std::basic_string<CharType, CharTraits, Allocator> *, CharType *arg) typename mpl::if_<is_same<Target, std::string>, // Target==std::string? #endif static Target do_cast(Source arg) { typename mpl::if_<is_same<Source, char>, // Source==char? { return direct_cast_base<std::basic_string<CharType, CharTraits, Allocator>, CharType *>::do_cast(arg); char_to_string_base<Target, Source>, #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || \ typename stringstream<CharType>::type interpreter; } typename mpl::if_<is_same<Source, char *>, // Source==char *? defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) setup_interpreter<Target, Source>(interpreter); direct_cast_base<Target, Source>, #include <boost/mpl/if.hpp> if(!(interpreter << arg)) template<typename CharType, typename CharTraits, typename Allocator> typename mpl::if_<is_same<Source, const char *>, // Source==const char *? #include <boost/type_traits/same_traits.hpp> throw detail::no_lexical_conversion<Target, Source>(); inline std::basic_string<CharType, CharTraits, Allocator> direct_cast_base<Target, Source>, #endif return interpreter.str(); lexical_cast_impl(std::basic_string<CharType, CharTraits, Allocator> *, const CharType *arg) typename mpl::if_<is_same<Source, std::string>, // Source==std::string? } { direct_cast_base<Target, const Source &>, namespace boost }; return direct_cast_base<std::basic_string<CharType, CharTraits, Allocator>, const CharType any_to_string_base<Target, Source, char> { *>::do_cast(arg); >::type // exception used to indicate runtime lexical_cast failure template<typename Target, typename Source> } >::type class bad_lexical_cast : public std::bad_cast struct string_to_char_base >::type { { template<typename Target> >::type, public: static Target do_cast(Source arg) inline Target lexical_cast_impl(Target *, char *arg) typename mpl::if_<is_same<Target, wchar_t>, // Target==wchar_t? virtual ~bad_lexical_cast() throw() { { typename mpl::if_<is_same<Source, wchar_t>, // Source==wchar_t? { if(arg.length()!=1) return string_to_any_base<Target, char *, char>::do_cast(arg); direct_cast_base<Target, Source>, } throw detail::no_lexical_conversion<Target, Source>(); } typename mpl::if_<is_same<Source, wchar_t *>, // Source==wchar_t *? }; return arg[0]; pointer_to_char_to_char_base<Target, Source>, } template<typename Target> typename mpl::if_<is_same<Source, const wchar_t *>, // Source==const wchar_t *? namespace detail }; inline Target lexical_cast_impl(Target *, const char *arg) pointer_to_char_to_char_base<Target, Source>, { { typename mpl::if_<is_same<Source, std::wstring>, // Source==std::wstring? template<typename Target, typename Source> template<typename Target, typename Source> return string_to_any_base<Target, const char *, char>::do_cast(arg); string_to_char_base<Target, const Source &>, class no_lexical_conversion : public bad_lexical_cast struct pointer_to_char_to_char_base } lexical_cast_base<Target, Source, wchar_t> { { >::type public: static Target do_cast(Source arg) template<typename Target> >::type no_lexical_conversion() { inline Target lexical_cast_impl(Target *, wchar_t arg) >::type : description( if(arg[0] == Target() || arg[1] != Target()) { >::type, std::string() + "bad lexical cast: " + throw detail::no_lexical_conversion<Target, Source>(); return lexical_cast_base<Target, wchar_t, wchar_t>::do_cast(arg); typename mpl::if_<is_same<Target, std::wstring>, // Target==std::wstring? "source type value could not be interpreted as target, Target=" + return arg[0]; } typename mpl::if_<is_same<Source, wchar_t>, // Source==wchar_t? typeid(Target).name() + ", Source=" + typeid(Source).name()) } char_to_string_base<Target, Source>, { }; template<typename Target> typename mpl::if_<is_same<Source, wchar_t *>, // Source==wchar_t *? } inline Target lexical_cast_impl(Target *, wchar_t *arg) direct_cast_base<Target, Source>, virtual ~no_lexical_conversion() throw() template<typename Target, typename Source> { typename mpl::if_<is_same<Source, const wchar_t *>, // Source==const wchar_t *? { struct char_to_string_base return string_to_any_base<Target, wchar_t *, wchar_t>::do_cast(arg); direct_cast_base<Target, Source>, } { } typename mpl::if_<is_same<Source, std::wstring>, // Source==std::wstring? virtual const char *what() const throw() static Target do_cast(Source arg) direct_cast_base<Target, const Source &>, { { template<typename Target> any_to_string_base<Target, Source, wchar_t> return description.c_str(); return Target(1, arg); inline Target lexical_cast_impl(Target *, const wchar_t *arg) >::type } } { >::type private: }; return string_to_any_base<Target, const wchar_t *, wchar_t>::do_cast(arg); >::type const std::string description; // static initialization fails on MSVC6 } >::type, }; template<typename Target, typename Source> typename mpl::if_<is_same<Target, Source>, // Target==Source? } struct direct_cast_base template<typename Target, typename CharType, typename CharTraits, typename Allocator> direct_cast_base<Target, const Source &>, { inline Target lexical_cast_impl(Target *, const std::basic_string<CharType, CharTraits, Allocator> &arg) typename mpl::if_<is_same<Source, char *>, // Source==char *? namespace detail static Target do_cast(Source arg) { string_to_any_base<Target, Source, char>, { { return string_to_any_base<Target, typename mpl::if_<is_same<Source, const char *>, // Source==const template<typename CharType> return arg; const std::basic_string<CharType, CharTraits, Allocator> &, CharType>::do_cast(arg); char *? struct stringstream } } string_to_any_base<Target, Source, char>, { }; typename mpl::if_<is_same<Source, std::string>, // #if defined(BOOST_NO_STRINGSTREAM) template<typename Type> Source==std::string? typedef std::strstream type; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && \ inline Type lexical_cast_impl(Type *, const Type &arg) string_to_any_base<Target, const Source &, char>, #else !defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) { typename mpl::if_<is_same<Source, wchar_t>, // Source==wchar_t? typedef std::basic_stringstream<CharType> type; return direct_cast_base<Type,
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages39 Page
-
File Size-