]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/type.h
Update a SFINAE construct
[libs/datafile.git] / source / type.h
index 701a5dc9786533f930e6c49778988f6816f83189..fdd040d81adccd82b53b9e9509b48b4348b70ed8 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_DATAFILE_TYPE_H_
 
 #include <msp/core/inttypes.h>
+#include <msp/core/meta.h>
 #include <msp/strings/lexicalcast.h>
 
 namespace Msp {
@@ -11,8 +12,10 @@ struct Symbol
 {
        std::string name;
 
+       Symbol() { }
+
        template<typename T>
-       Symbol(const T &n): name(lexical_cast(n)) { }
+       Symbol(const T &n): name(lexical_cast<std::string>(n)) { }
 
        template<typename T> operator T() const { return lexical_cast<T>(name); }
 };
@@ -52,20 +55,26 @@ struct SymbolType
        typedef Symbol Store;
 };
 
-template<typename T>
-struct HasLoadType
+const char valid_signatures[] =
 {
-       struct Yes { char c[2]; };
-       struct No { char c; };
-
-       template<typename U>
-       static Yes f(typename U::LoadType *);
-       template<typename U>
-       static No f(...);
+       IntType::signature,
+       FloatType::signature,
+       BoolType::signature,
+       StringType::signature,
+       SymbolType::signature,
+       0
+};
 
-       enum { value = (sizeof(f<T>(0))==sizeof(Yes)) };
+struct CheckLoadType: Sfinae
+{
+       template<typename T>
+       static Yes f(typename T::LoadType *);
+       using Sfinae::f;
 };
 
+template<typename T>
+struct HasLoadType: Sfinae::Evaluate<CheckLoadType, T> { };
+
 template<typename T, bool lt = HasLoadType<T>::value>
 struct TypeInfo;
 
@@ -113,6 +122,12 @@ struct TypeInfo<bool, false>: BoolType { };
 template<>
 struct TypeInfo<std::string, false>: StringType { };
 
+template<>
+struct TypeInfo<char *, false>: StringType { };
+
+template<>
+struct TypeInfo<const char *, false>: StringType { };
+
 template<typename T>
 struct TypeInfo<const T, false>: TypeInfo<T> { };