Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:50

0001 #ifndef GENERS_ARRAYIO_HH_
0002 #define GENERS_ARRAYIO_HH_
0003 
0004 #include "Alignment/Geners/interface/CPP11_array.hh"
0005 #include "Alignment/Geners/interface/GenericIO.hh"
0006 
0007 namespace gs {
0008     template<class T, std::size_t N>
0009     struct ClassIdSpecialization<CPP11_array<T,N> >
0010     {inline static ClassId classId(const bool isPtr=false)
0011     {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};
0012 
0013     template<class T, std::size_t N>
0014     struct ClassIdSpecialization<const CPP11_array<T,N> >
0015     {inline static ClassId classId(const bool isPtr=false)
0016     {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};
0017 
0018     template<class T, std::size_t N>
0019     struct ClassIdSpecialization<volatile CPP11_array<T,N> >
0020     {inline static ClassId classId(const bool isPtr=false)
0021     {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};
0022 
0023     template<class T, std::size_t N>
0024     struct ClassIdSpecialization<const volatile CPP11_array<T,N> >
0025     {inline static ClassId classId(const bool isPtr=false)
0026     {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};
0027 
0028     template <class T, std::size_t N>
0029     struct IOIsContiguous<CPP11_array<T,N> >
0030     {enum {value = 1};};
0031 
0032     template <class T, std::size_t N>
0033     struct IOIsContiguous<const CPP11_array<T,N> >
0034     {enum {value = 1};};
0035 
0036     template <class T, std::size_t N>
0037     struct IOIsContiguous<volatile CPP11_array<T,N> >
0038     {enum {value = 1};};
0039 
0040     template <class T, std::size_t N>
0041     struct IOIsContiguous<const volatile CPP11_array<T,N> >
0042     {enum {value = 1};};
0043 
0044     // Need to specialize behavior in the header because
0045     // there is no "clear" method in std::array
0046     template <class Stream, class State, class T, std::size_t N>
0047     struct GenericReader<Stream, State, CPP11_array<T,N>, InContainerHeader>
0048     {
0049         typedef CPP11_array<T,N> Container;
0050         inline static bool process(Container& a, Stream& is, State* state,
0051                                    const bool processClassId)
0052         {
0053             if (processClassId)
0054             {
0055                 static const ClassId current(ClassId::makeId<Container>());
0056                 ClassId id(is, 1);
0057                 current.ensureSameName(id);
0058             }
0059             if (!IOTraits<T>::IsPOD)
0060             {
0061                 ClassId id(is, 1);
0062                 state->push_back(id);
0063             }
0064             return true;
0065         }
0066     };
0067 
0068     // Ignore array size I/O. The size is built into
0069     // the type definition anyway
0070     template <class Stream, class State, class T, std::size_t N>
0071     struct GenericWriter<Stream, State, CPP11_array<T,N>, InContainerSize>
0072     {
0073         inline static bool process(std::size_t, Stream& os, State*,
0074                                    const bool processClassId)
0075             {return true;}
0076     };
0077 
0078     template <class Stream, class State, class T, std::size_t N>
0079     struct GenericReader<Stream, State, CPP11_array<T,N>, InContainerSize>
0080     {
0081         inline static bool process(std::size_t, Stream& os, State*,
0082                                    const bool processClassId)
0083             {return true;}
0084     };
0085 
0086     template <class Stream, class State, class T, std::size_t N>
0087     struct GenericWriter<Stream, State, CPP11_array<T,N>, InPODArray>
0088     {
0089         typedef CPP11_array<T,N> Array;
0090         inline static bool process(const Array& a, Stream& os, State*, bool)
0091         {
0092             write_pod_array(os, &a[0], N);
0093             return !os.fail();
0094         }
0095     };
0096 
0097     template <class Stream, class State, class T, std::size_t N>
0098     struct GenericReader<Stream, State, CPP11_array<T,N>, InPODArray>
0099     {
0100         typedef CPP11_array<T,N> Array;
0101         inline static bool process(Array& a, Stream& is, State*, bool)
0102         {
0103             read_pod_array(is, &a[0], N);
0104             return !is.fail();
0105         }
0106     };
0107 
0108     template <class T, std::size_t N>
0109     struct InsertContainerItem<CPP11_array<T,N> >
0110     {
0111         typedef CPP11_array<T,N> A;
0112         static inline void insert(A& obj, const typename A::value_type& item,
0113                                   const std::size_t itemNumber)
0114             {obj.at(itemNumber) = item;}
0115     };
0116 
0117     template <class T, std::size_t N>
0118     struct InsertContainerItem<volatile CPP11_array<T,N> >
0119     {
0120         typedef CPP11_array<T,N> A;
0121         static inline void insert(A& obj, const typename A::value_type& item,
0122                                   const std::size_t itemNumber)
0123             {obj.at(itemNumber) = item;}
0124     };
0125 }
0126 
0127 #endif // GENERS_ARRAYIO_HH_
0128