Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GENERS_VALARRAYIO_HH_
0002 #define GENERS_VALARRAYIO_HH_
0003 
0004 #include <valarray>
0005 #include "Alignment/Geners/interface/GenericIO.hh"
0006 
0007 namespace gs {
0008     template <class T>
0009     struct IOIsContiguous<std::valarray<T> >
0010     {enum {value = 1};};
0011 
0012     template <class T>
0013     struct IOIsContiguous<const std::valarray<T> >
0014     {enum {value = 1};};
0015 
0016     template <class T>
0017     struct IOIsContiguous<volatile std::valarray<T> >
0018     {enum {value = 1};};
0019 
0020     template <class T>
0021     struct IOIsContiguous<const volatile std::valarray<T> >
0022     {enum {value = 1};};
0023 
0024     template <class T>
0025     struct InsertContainerItem<std::valarray<T> >
0026     {
0027         typedef std::valarray<T> A;
0028         static inline void insert(A& obj, const typename A::value_type& item,
0029                                   const std::size_t itemNumber)
0030             {obj[itemNumber] = item;}
0031     };
0032 
0033     template <class T>
0034     struct InsertContainerItem<volatile std::valarray<T> >
0035     {
0036         typedef std::valarray<T> A;
0037         static inline void insert(A& obj, const typename A::value_type& item,
0038                                   const std::size_t itemNumber)
0039             {obj[itemNumber] = item;}
0040     };
0041 
0042     // Need to specialize behavior in the header because
0043     // there is no "clear" method in std::valarray
0044     template <class Stream, class State, class T>
0045     struct GenericReader<Stream, State, std::valarray<T>, InContainerHeader>
0046     {
0047         typedef std::valarray<T> Container;
0048         inline static bool process(Container& a, Stream& is, State* state,
0049                                    const bool processClassId)
0050         {
0051             if (processClassId)
0052             {
0053                 static const ClassId current(ClassId::makeId<Container>());
0054                 ClassId id(is, 1);
0055                 current.ensureSameName(id);
0056             }
0057             if (!IOTraits<T>::IsPOD)
0058             {
0059                 ClassId id(is, 1);
0060                 state->push_back(id);
0061             }
0062             return true;
0063         }
0064     };
0065 
0066     namespace Private {
0067         template
0068         <
0069             template <typename, typename, typename, typename> class Visitor,
0070             typename T,
0071             typename Arg1,
0072             typename Arg2
0073         >
0074         struct iterate_const_container<Visitor,std::valarray<T>,Arg1,Arg2>
0075         {
0076             static bool process(const std::valarray<T>& v, Arg1& a1,
0077                                 Arg2* p2, const std::size_t len)
0078             {
0079                 bool itemStatus = true;
0080                 for (std::size_t i=0; i<len && itemStatus; ++i)
0081                     itemStatus = process_const_item<Visitor>(v[i],a1,p2,false);
0082                 return itemStatus;
0083             }
0084         };
0085 
0086         template
0087         <
0088             template <typename, typename, typename, typename> class Visitor,
0089             typename T,
0090             typename Arg1,
0091             typename Arg2
0092         >
0093         struct iterate_container<Visitor,std::valarray<T>,Arg1,Arg2>
0094         {
0095             static bool process(std::valarray<T>& obj, Arg1& a1,
0096                                 Arg2* p2, const std::size_t newSize)
0097             {
0098                 obj.resize(newSize);
0099                 bool itemStatus = true;
0100                 for (std::size_t i=0; i<newSize && itemStatus; ++i)
0101                     itemStatus = Visitor<
0102                         Arg1,Arg2,std::valarray<T>,InContainerCycle>::process(
0103                             obj, a1, p2, i);
0104                 return itemStatus;
0105             }
0106         };
0107     }
0108 }
0109 
0110 gs_specialize_template_id_T(std::valarray, 0, 1)
0111 
0112 #endif // GENERS_VALARRAYIO_HH_
0113