]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/type.h
Cosmetic changes
[libs/datafile.git] / source / type.h
index 242a9e11d1bed7c30cf8bbc978ff1b001133d74b..0e371e632a9bb4b66aee10520e5aab300726675e 100644 (file)
@@ -1,13 +1,8 @@
-/* $Id$
-
-This file is part of libmspdatafile
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_DATAFILE_TYPE_H_
 #define MSP_DATAFILE_TYPE_H_
 
+#include <cstdint>
+#include <msp/core/meta.h>
 #include <msp/strings/lexicalcast.h>
 
 namespace Msp {
@@ -17,8 +12,10 @@ struct Symbol
 {
        std::string name;
 
+       Symbol() = default;
+
        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); }
 };
@@ -26,25 +23,29 @@ struct Symbol
 struct IntType
 {
        static const char signature = 'i';
-       typedef long long int Store;
+       typedef std::int64_t Store;
+       typedef Store Load;
 };
 
 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
@@ -54,50 +55,84 @@ struct SymbolType
        typedef Symbol Store;
 };
 
+const char valid_signatures[] =
+{
+       IntType::signature,
+       FloatType::signature,
+       BoolType::signature,
+       StringType::signature,
+       SymbolType::signature,
+       0
+};
+
+struct CheckLoadType: Sfinae
+{
+       template<typename T>
+       static Yes f(typename T::LoadType *);
+       using Sfinae::f;
+};
+
 template<typename T>
-struct TypeInfo: SymbolType { };
+struct HasLoadType: Sfinae::Evaluate<CheckLoadType, T> { };
+
+template<typename T, bool lt = HasLoadType<T>::value>
+struct TypeInfo;
+
+template<>
+struct TypeInfo<short int, false>: IntType { };
+
+template<>
+struct TypeInfo<unsigned short int, false>: IntType { };
 
 template<>
-struct TypeInfo<short int>: IntType { };
+struct TypeInfo<int, false>: IntType { };
 
 template<>
-struct TypeInfo<unsigned short int>: IntType { };
+struct TypeInfo<unsigned int, false>: IntType { };
 
 template<>
-struct TypeInfo<int>: IntType { };
+struct TypeInfo<long int, false>: IntType { };
 
 template<>
-struct TypeInfo<unsigned int>: IntType { };
+struct TypeInfo<unsigned long int, false>: IntType { };
 
 template<>
-struct TypeInfo<long int>: IntType { };
+struct TypeInfo<long long int, false>: IntType { };
 
 template<>
-struct TypeInfo<unsigned long int>: IntType { };
+struct TypeInfo<unsigned long long int, false>: IntType { };
 
 template<>
-struct TypeInfo<long long int>: IntType { };
+struct TypeInfo<float, false>: FloatType { };
 
 template<>
-struct TypeInfo<unsigned long long int>: IntType { };
+struct TypeInfo<double, false>: FloatType { };
 
 template<>
-struct TypeInfo<float>: FloatType { };
+struct TypeInfo<bool, false>: BoolType { };
 
 template<>
-struct TypeInfo<double>: FloatType { };
+struct TypeInfo<std::string, false>: StringType { };
 
 template<>
-struct TypeInfo<bool>: BoolType { };
+struct TypeInfo<char *, false>: StringType { };
 
 template<>
-struct TypeInfo<std::string>: StringType { };
+struct TypeInfo<const char *, false>: StringType { };
+
+template<typename T>
+struct TypeInfo<const T, false>: TypeInfo<T> { };
+
+template<typename T>
+struct TypeInfo<T &, false>: TypeInfo<T> { };
 
 template<typename T>
-struct TypeInfo<const T>: TypeInfo<T> { };
+struct TypeInfo<T, true>: TypeInfo<typename T::LoadType>
+{ typedef typename T::LoadType Load; };
 
 template<typename T>
-struct TypeInfo<T &>: TypeInfo<T> { };
+struct TypeInfo<T, false>: SymbolType
+{ typedef T Load; };
 
 } // namespace DataFile
 } // namespace Msp