From: Mikko Rasa Date: Wed, 18 Jul 2012 14:43:19 +0000 (+0300) Subject: Add facility for classes to specify what type they should be loaded as X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=818ead7b6ccef1e4d2435cc959bc07f910fcde46;p=libs%2Fdatafile.git Add facility for classes to specify what type they should be loaded as --- diff --git a/source/type.h b/source/type.h index a7c57c4..72d148a 100644 --- a/source/type.h +++ b/source/type.h @@ -31,18 +31,21 @@ struct FloatType { static const char signature = 'f'; typedef double Store; + typedef Store Load; }; struct BoolType { static const char signature = 'b'; typedef bool Store; + typedef Store Load; }; struct StringType { static const char signature = 's'; typedef std::string Store; + typedef Store Load; }; struct SymbolType @@ -53,57 +56,79 @@ struct SymbolType }; template -struct TypeInfo: SymbolType { }; +struct HasLoadType +{ + struct Yes { char c[2]; }; + struct No { char c; }; + + template + static Yes f(typename U::LoadType *); + template + static No f(...); + + enum { value = (sizeof(f(0))==sizeof(Yes)) }; +}; + +template::value> +struct TypeInfo; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; #ifdef MSVC template<> -struct TypeInfo<__int64>: IntType { }; +struct TypeInfo<__int64, false>: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; #else template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; template<> -struct TypeInfo: IntType { }; +struct TypeInfo: IntType { }; #endif template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: FloatType { }; +struct TypeInfo: FloatType { }; template<> -struct TypeInfo: BoolType { }; +struct TypeInfo: BoolType { }; template<> -struct TypeInfo: StringType { }; +struct TypeInfo: StringType { }; + +template +struct TypeInfo: TypeInfo { }; + +template +struct TypeInfo: TypeInfo { }; template -struct TypeInfo: TypeInfo { }; +struct TypeInfo: TypeInfo +{ typedef typename T::LoadType Load; }; template -struct TypeInfo: TypeInfo { }; +struct TypeInfo: SymbolType +{ typedef T Load; }; } // namespace DataFile } // namespace Msp diff --git a/source/value.h b/source/value.h index 78ec54a..e2b9fb1 100644 --- a/source/value.h +++ b/source/value.h @@ -25,7 +25,7 @@ public: Value(Symbol d): sig(TypeInfo::signature), data(d) { } template - typename RemoveReference::Type get() const + typename TypeInfo::Load get() const { return get_::Store>(); } char get_signature() const { return sig; }