Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GENERS_VARPACK_HH_
0002 #define GENERS_VARPACK_HH_
0003 
0004 #include "Alignment/Geners/interface/CPP11_config.hh"
0005 #ifdef CPP11_STD_AVAILABLE
0006 
0007 #include <string>
0008 #include <cassert>
0009 
0010 #include "Alignment/Geners/interface/tupleIO.hh"
0011 #include "Alignment/Geners/interface/VPackIOCycler.hh"
0012 
0013 namespace gs {
0014     //
0015     // The VarPack template does not process the class ids of the
0016     // tuple items every time the reading is performed. This can
0017     // speed up reading of these items. Apply "checkTypeEveryTime(true)"
0018     // to enable type check for every read if I/O versions for some
0019     // of the items can change from one read to another.
0020     //
0021     template<typename... Args>
0022     class VarPack : public std::tuple<Args...>
0023     {
0024         template<typename Pack, int N> friend struct Private::VPackIOCycler;
0025 
0026     public:
0027         typedef std::tuple<Args...> Base;
0028 
0029         inline VarPack() : firstRead_(true), checkTypeEveryTime_(false) {}
0030 
0031         inline explicit VarPack(const Args&... args) :
0032             std::tuple<Args...>(args...),
0033             firstRead_(true), checkTypeEveryTime_(false) {}
0034 
0035         inline bool checkTypeEveryTime() const {return checkTypeEveryTime_;}
0036 
0037         inline VarPack& checkTypeEveryTime(const bool newValue)
0038         {
0039             checkTypeEveryTime_ = newValue;
0040             return *this;
0041         }
0042 
0043         inline ClassId classId() const {return ClassId(*this);}
0044 
0045         // For I/O purposes, this class is identical to std::tuple
0046         static const char* classname()
0047         {
0048             static const std::string name(tuple_class_name<Base>("std::tuple"));
0049             return name.c_str();
0050         }
0051         static inline unsigned version() {return 0;}
0052 
0053         inline bool write(std::ostream& of) const
0054         {
0055             return write_item(of, *(static_cast<const Base*>(this)), false);
0056         }
0057 
0058         static inline void restore(const ClassId& id, std::istream& is,
0059                                    VarPack* pack)
0060         {
0061             assert(pack);
0062             if (pack->firstRead_ || pack->checkTypeEveryTime_)
0063             {
0064                 static const ClassId packId(ClassId::makeId<VarPack>());
0065                 packId.ensureSameName(id);
0066                 id.templateParameters(&pack->iostack_);
0067                 assert(pack->iostack_.size() == std::tuple_size<Base>::value);
0068                 pack->firstRead_ = false;
0069             }
0070             Private::VPackIOCycler<
0071                 VarPack,std::tuple_size<Base>::value>::read(pack, is);
0072         }
0073 
0074     private:
0075         std::vector<std::vector<ClassId> > iostack_;
0076         bool firstRead_;
0077         bool checkTypeEveryTime_;
0078     };
0079 
0080 
0081     // Function to simplify creation of variable packs
0082     template<typename... Args>
0083     inline VarPack<Args...> make_VarPack(Args... args)
0084     {
0085         return VarPack<Args...>(args...);
0086     }
0087 }
0088 
0089 #endif // CPP11_STD_AVAILABLE
0090 #endif // GENERS_VARPACK_HH_
0091