Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#ifndef GENERS_ARRAYIO_HH_
#define GENERS_ARRAYIO_HH_

#include "Alignment/Geners/interface/CPP11_array.hh"
#include "Alignment/Geners/interface/GenericIO.hh"

namespace gs {
    template<class T, std::size_t N>
    struct ClassIdSpecialization<CPP11_array<T,N> >
    {inline static ClassId classId(const bool isPtr=false)
    {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};

    template<class T, std::size_t N>
    struct ClassIdSpecialization<const CPP11_array<T,N> >
    {inline static ClassId classId(const bool isPtr=false)
    {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};

    template<class T, std::size_t N>
    struct ClassIdSpecialization<volatile CPP11_array<T,N> >
    {inline static ClassId classId(const bool isPtr=false)
    {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};

    template<class T, std::size_t N>
    struct ClassIdSpecialization<const volatile CPP11_array<T,N> >
    {inline static ClassId classId(const bool isPtr=false)
    {return ClassId(stack_container_name<T,N>("std::array"), 0, isPtr);}};

    template <class T, std::size_t N>
    struct IOIsContiguous<CPP11_array<T,N> >
    {enum {value = 1};};

    template <class T, std::size_t N>
    struct IOIsContiguous<const CPP11_array<T,N> >
    {enum {value = 1};};

    template <class T, std::size_t N>
    struct IOIsContiguous<volatile CPP11_array<T,N> >
    {enum {value = 1};};

    template <class T, std::size_t N>
    struct IOIsContiguous<const volatile CPP11_array<T,N> >
    {enum {value = 1};};

    // Need to specialize behavior in the header because
    // there is no "clear" method in std::array
    template <class Stream, class State, class T, std::size_t N>
    struct GenericReader<Stream, State, CPP11_array<T,N>, InContainerHeader>
    {
        typedef CPP11_array<T,N> Container;
        inline static bool process(Container& a, Stream& is, State* state,
                                   const bool processClassId)
        {
            if (processClassId)
            {
                static const ClassId current(ClassId::makeId<Container>());
                ClassId id(is, 1);
                current.ensureSameName(id);
            }
            if (!IOTraits<T>::IsPOD)
            {
                ClassId id(is, 1);
                state->push_back(id);
            }
            return true;
        }
    };

    // Ignore array size I/O. The size is built into
    // the type definition anyway
    template <class Stream, class State, class T, std::size_t N>
    struct GenericWriter<Stream, State, CPP11_array<T,N>, InContainerSize>
    {
        inline static bool process(std::size_t, Stream& os, State*,
                                   const bool processClassId)
            {return true;}
    };

    template <class Stream, class State, class T, std::size_t N>
    struct GenericReader<Stream, State, CPP11_array<T,N>, InContainerSize>
    {
        inline static bool process(std::size_t, Stream& os, State*,
                                   const bool processClassId)
            {return true;}
    };

    template <class Stream, class State, class T, std::size_t N>
    struct GenericWriter<Stream, State, CPP11_array<T,N>, InPODArray>
    {
        typedef CPP11_array<T,N> Array;
        inline static bool process(const Array& a, Stream& os, State*, bool)
        {
            write_pod_array(os, &a[0], N);
            return !os.fail();
        }
    };

    template <class Stream, class State, class T, std::size_t N>
    struct GenericReader<Stream, State, CPP11_array<T,N>, InPODArray>
    {
        typedef CPP11_array<T,N> Array;
        inline static bool process(Array& a, Stream& is, State*, bool)
        {
            read_pod_array(is, &a[0], N);
            return !is.fail();
        }
    };

    template <class T, std::size_t N>
    struct InsertContainerItem<CPP11_array<T,N> >
    {
        typedef CPP11_array<T,N> A;
        static inline void insert(A& obj, const typename A::value_type& item,
                                  const std::size_t itemNumber)
            {obj.at(itemNumber) = item;}
    };

    template <class T, std::size_t N>
    struct InsertContainerItem<volatile CPP11_array<T,N> >
    {
        typedef CPP11_array<T,N> A;
        static inline void insert(A& obj, const typename A::value_type& item,
                                  const std::size_t itemNumber)
            {obj.at(itemNumber) = item;}
    };
}

#endif // GENERS_ARRAYIO_HH_