#ifndef ME_PROXYPACK_HH_ #define ME_PROXYPACK_HH_ #include "geners/tupleIO.hh" namespace gs { // // The class ClassIdComparator must provide a static function // "bool compatible(const ClassId& idOnFile, const ClassId& idProxyPack);" // template class ProxyPack : public std::tuple { public: typedef std::tuple Base; ProxyPack() : firstRead_(true) {} inline explicit ProxyPack(const Args&... args) : std::tuple(args...), firstRead_(true) {} inline ClassId classId() const {return ClassId(*this);} static inline const char* classname() { static std::string name; if (name.size() == 0) { std::ostringstream os; os << "gs::ProxyPack<"; Private::TupleClassIdCycler< Base, std::tuple_size::value>::collectClassIds(os); os << '>'; name = os.str(); } return name.c_str(); } static inline unsigned version() {return 1;} inline bool write(std::ostream& of) const { return write_item(of, *(static_cast(this)), false); } static inline bool restore(const ClassId& id, std::istream& is, ProxyPack* pack) { // Checking ClassId every time would take too long... assert(pack); if (pack->firstRead_) { assert(ClassIdComparator::compatible(id, pack->classId())); pack->firstRead_ = false; pack->iostack_.reserve(1); pack->iostack_.push_back(id); } return GenericReader, Base, Int2Type::ISTUPLE> >::process( *(static_cast(pack)), is, &pack->iostack_, false); } private: bool firstRead_; std::vector iostack_; }; // Functions to simplify creation of proxy packs template inline ProxyPack make_proxy_pack(Args&&... args) { return ProxyPack(args...); } } #endif // ME_PROXYPACK_HH_