Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:19

0001 #ifndef GENERS_IOTRAITS_HH_
0002 #define GENERS_IOTRAITS_HH_
0003 
0004 #include <iostream>
0005 
0006 #include "Alignment/Geners/interface/IOIsClassType.hh"
0007 #include "Alignment/Geners/interface/IOIsContainer.hh"
0008 #include "Alignment/Geners/interface/IOIsContiguous.hh"
0009 #include "Alignment/Geners/interface/IOIsExternal.hh"
0010 #include "Alignment/Geners/interface/IOIsIOPtr.hh"
0011 #include "Alignment/Geners/interface/IOIsPOD.hh"
0012 #include "Alignment/Geners/interface/IOIsPair.hh"
0013 #include "Alignment/Geners/interface/IOIsReadable.hh"
0014 #include "Alignment/Geners/interface/IOIsSharedPtr.hh"
0015 #include "Alignment/Geners/interface/IOIsString.hh"
0016 #include "Alignment/Geners/interface/IOIsTuple.hh"
0017 #include "Alignment/Geners/interface/IOIsWritable.hh"
0018 
0019 namespace gs {
0020   template <class T>
0021   struct IOTraits {
0022     static const bool IsClass = IOIsClassType<T>::value;
0023     static constexpr int ISCLASS = 1;
0024 
0025     // Pointers are not PODs for I/O purposes.
0026     //
0027     // It looks like std::array of PODs is itself considered
0028     // a POD by the "CPP11_is_pod" template, at least by some
0029     // g++ versions (in particular, 4.4.5). This is a bug/feature
0030     // that we need to avoid.
0031     static const bool IsPOD =
0032         (IOIsPOD<T>::value && !IOIsContainer<T>::value && !CPP11_is_pointer<T>::value && !IOIsExternal<T>::value);
0033     static constexpr int ISPOD = 2;
0034 
0035     static const bool IsWritable = (IOIsWritable<T>::value && !IOIsExternal<T>::value);
0036     static constexpr int ISWRITABLE = 4;
0037 
0038     static const bool IsStdContainer = (IOIsContainer<T>::value && !IOIsWritable<T>::value && !IOIsExternal<T>::value);
0039     static constexpr int ISSTDCONTAINER = 8;
0040 
0041     // Readable objects are required to be writable
0042     static const bool IsPlaceReadable = (IOIsPlaceReadable<T>::value && IOIsWritable<T>::value);
0043     static constexpr int ISPLACEREADABLE = 16;
0044 
0045     // Prefer place readability to heap readability
0046     static const bool IsHeapReadable =
0047         (IOIsHeapReadable<T>::value && !IOIsPlaceReadable<T>::value && IOIsWritable<T>::value);
0048     static constexpr int ISHEAPREADABLE = 32;
0049 
0050     static const bool IsPointer = (CPP11_is_pointer<T>::value && !IOIsExternal<T>::value);
0051     static constexpr int ISPOINTER = 64;
0052 
0053     static const bool IsSharedPtr = (IOIsSharedPtr<T>::value && !IOIsExternal<T>::value);
0054     static constexpr int ISSHAREDPTR = 128;
0055 
0056     static const bool IsPair = IOIsPair<T>::value;
0057     static constexpr int ISPAIR = 256;
0058 
0059     static const bool IsString = IOIsString<T>::value;
0060     static constexpr int ISSTRING = 512;
0061 
0062     // The following trait is relevant for containers only
0063     static const bool IsContiguous = IOIsContiguous<T>::value;
0064     static constexpr int ISCONTIGUOUS = 1024;
0065 
0066     static const bool IsTuple = IOIsTuple<T>::value;
0067     static constexpr int ISTUPLE = 2048;
0068 
0069     static const bool IsIOPtr = IOIsIOPtr<T>::value;
0070     static constexpr int ISIOPTR = 4096;
0071 
0072     // A catch-all definition for externally defined types which
0073     // want to use the template-based I/O within this system but
0074     // do not want to implement the standard "read/write" mechanism.
0075     // The user has to declare the external type by modifying the
0076     // "IOIsExternal" template.
0077     static const bool IsExternal = IOIsExternal<T>::value;
0078     static constexpr int ISEXTERNAL = 8192;
0079 
0080     // Special enums for heap-readable objects known
0081     // to be called with zero pointer as an argument.
0082     // In this case we will avoid compiling an assignment
0083     // operator for the object.
0084     static constexpr int ISNULLPOINTER = 16384;
0085     static constexpr int ISPUREHEAPREADABLE = 32768;
0086 
0087     static const int Signature = IsClass * ISCLASS + IsPOD * ISPOD + IsWritable * ISWRITABLE +
0088                                  IsStdContainer * ISSTDCONTAINER + IsPlaceReadable * ISPLACEREADABLE +
0089                                  IsHeapReadable * ISHEAPREADABLE + IsPointer * ISPOINTER + IsSharedPtr * ISSHAREDPTR +
0090                                  IsPair * ISPAIR + IsString * ISSTRING + IsContiguous * ISCONTIGUOUS +
0091                                  IsTuple * ISTUPLE + IsIOPtr * ISIOPTR + IsExternal * ISEXTERNAL +
0092                                  IsPointer * ISNULLPOINTER + IsHeapReadable * ISPUREHEAPREADABLE;
0093   };
0094 
0095   template <class T>
0096   inline IOTraits<T> IOItemTraits(const T &) {
0097     return IOTraits<T>();
0098   }
0099 }  // namespace gs
0100 
0101 template <class T>
0102 std::ostream &operator<<(std::ostream &os, const gs::IOTraits<T> &) {
0103   typedef gs::IOTraits<T> Tr;
0104   os << "IsClass = " << Tr::IsClass << ", IsPOD = " << Tr::IsPOD << ", IsWritable = " << Tr::IsWritable
0105      << ", IsStdContainer = " << Tr::IsStdContainer << ", IsPlaceReadable = " << Tr::IsPlaceReadable
0106      << ", IsHeapReadable = " << Tr::IsHeapReadable << ", IsPointer = " << Tr::IsPointer
0107      << ", IsSharedPtr = " << Tr::IsSharedPtr << ", IsPair = " << Tr::IsPair << ", IsString = " << Tr::IsString
0108      << ", IsContiguous = " << Tr::IsContiguous << ", IsTuple = " << Tr::IsTuple << ", IsIOPtr = " << Tr::IsIOPtr
0109      << ", IsExternal = " << Tr::IsExternal;
0110   return os;
0111 }
0112 
0113 #endif  // GENERS_IOTRAITS_HH_