From 7614b0524221e8473c87a70f0e3f37b9b207bb2a Mon Sep 17 00:00:00 2001 From: Cms Build Date: Wed, 8 May 2019 14:16:36 +0200 Subject: [PATCH] Clang-Format --- .../interface/CocoaMaterialElementary.h | 4 +- .../interface/CocoaSolidShape.h | 1 - .../interface/CocoaSolidShapeBox.h | 4 +- .../interface/CocoaSolidShapeTubs.h | 8 +- .../src/CocoaMaterialElementary.cc | 12 +- .../CocoaDDLObjects/src/CocoaSolidShapeBox.cc | 4 +- .../src/CocoaSolidShapeTubs.cc | 6 +- Alignment/Geners/interface/AbsArchive.hh | 285 ++- Alignment/Geners/interface/AbsCatalog.hh | 119 +- Alignment/Geners/interface/AbsReader.hh | 159 +- Alignment/Geners/interface/AbsRecord.hh | 73 +- Alignment/Geners/interface/AbsReference.hh | 174 +- Alignment/Geners/interface/ArrayAdaptor.hh | 313 ++- Alignment/Geners/interface/BZ2Handle.hh | 56 +- .../Geners/interface/BinaryArchiveBase.hh | 425 ++-- .../Geners/interface/BinaryFileArchive.hh | 109 +- Alignment/Geners/interface/CPP11_auto_ptr.hh | 2 +- Alignment/Geners/interface/CPP11_config.hh | 2 +- .../Geners/interface/CPP11_shared_ptr.hh | 2 +- .../Geners/interface/CPP11_type_traits.hh | 2 +- Alignment/Geners/interface/CStringBuf.hh | 24 +- Alignment/Geners/interface/CStringStream.hh | 121 +- Alignment/Geners/interface/CatalogEntry.hh | 106 +- Alignment/Geners/interface/CatalogIO.hh | 207 +- Alignment/Geners/interface/CharBuffer.hh | 32 +- Alignment/Geners/interface/ClassId.hh | 1317 +++++----- Alignment/Geners/interface/ClearIfPointer.hh | 27 +- Alignment/Geners/interface/ColumnBuffer.hh | 97 +- Alignment/Geners/interface/CompressedIO.hh | 148 +- .../Geners/interface/ContiguousCatalog.hh | 140 +- Alignment/Geners/interface/GeneralCatalog.hh | 167 +- Alignment/Geners/interface/GenericIO.hh | 1313 +++++----- Alignment/Geners/interface/IOException.hh | 142 +- Alignment/Geners/interface/IOIsAnyPtr.hh | 16 +- Alignment/Geners/interface/IOIsClassType.hh | 27 +- Alignment/Geners/interface/IOIsContainer.hh | 83 +- Alignment/Geners/interface/IOIsContiguous.hh | 116 +- Alignment/Geners/interface/IOIsExternal.hh | 107 +- Alignment/Geners/interface/IOIsIOPtr.hh | 85 +- Alignment/Geners/interface/IOIsNumber.hh | 60 +- Alignment/Geners/interface/IOIsPOD.hh | 47 +- Alignment/Geners/interface/IOIsPair.hh | 18 +- Alignment/Geners/interface/IOIsReadable.hh | 100 +- Alignment/Geners/interface/IOIsSharedPtr.hh | 39 +- Alignment/Geners/interface/IOIsString.hh | 39 +- Alignment/Geners/interface/IOIsTuple.hh | 11 +- Alignment/Geners/interface/IOIsUnsigned.hh | 51 +- Alignment/Geners/interface/IOIsWritable.hh | 47 +- Alignment/Geners/interface/IOPointeeType.hh | 29 +- Alignment/Geners/interface/IOPtr.hh | 363 +-- Alignment/Geners/interface/IOTraits.hh | 186 +- .../Geners/interface/InsertContainerItem.hh | 16 +- Alignment/Geners/interface/Int2Type.hh | 33 +- Alignment/Geners/interface/ItemDescriptor.hh | 79 +- Alignment/Geners/interface/ItemLocation.hh | 72 +- .../Geners/interface/MultiFileArchive.hh | 115 +- Alignment/Geners/interface/ProcessItem.hh | 784 +++--- Alignment/Geners/interface/Reference.hh | 124 +- Alignment/Geners/interface/Regex.hh | 91 +- Alignment/Geners/interface/SearchSpecifier.hh | 75 +- Alignment/Geners/interface/StringArchive.hh | 155 +- Alignment/Geners/interface/StrippedType.hh | 77 +- .../Geners/interface/WriteOnlyCatalog.hh | 124 +- Alignment/Geners/interface/ZlibHandle.hh | 50 +- Alignment/Geners/interface/binaryIO.hh | 490 ++-- Alignment/Geners/interface/complexIO.hh | 104 +- Alignment/Geners/interface/streamposIO.hh | 65 +- Alignment/Geners/interface/stringArchiveIO.hh | 77 +- Alignment/Geners/interface/uriUtils.hh | 12 +- Alignment/Geners/src/AbsArchive.cc | 204 +- Alignment/Geners/src/AbsReference.cc | 250 +- Alignment/Geners/src/BZ2Handle.cc | 42 +- Alignment/Geners/src/BinaryArchiveBase.cc | 606 ++--- Alignment/Geners/src/BinaryFileArchive.cc | 318 ++- Alignment/Geners/src/CStringBuf.cc | 30 +- Alignment/Geners/src/CStringStream.cc | 249 +- Alignment/Geners/src/CatalogEntry.cc | 196 +- Alignment/Geners/src/CatalogIO.cc | 34 +- Alignment/Geners/src/CharBuffer.cc | 98 +- Alignment/Geners/src/ClassId.cc | 532 ++-- Alignment/Geners/src/ColumnBuffer.cc | 89 +- Alignment/Geners/src/ContiguousCatalog.cc | 371 ++- Alignment/Geners/src/GeneralCatalog.cc | 515 ++-- Alignment/Geners/src/ItemDescriptor.cc | 34 +- Alignment/Geners/src/ItemLocation.cc | 90 +- Alignment/Geners/src/MultiFileArchive.cc | 531 ++-- Alignment/Geners/src/SearchSpecifier.cc | 16 +- Alignment/Geners/src/StringArchive.cc | 115 +- Alignment/Geners/src/WriteOnlyCatalog.cc | 193 +- Alignment/Geners/src/ZlibHandle.cc | 54 +- Alignment/Geners/src/stringArchiveIO.cc | 141 +- Alignment/Geners/src/uriUtils.cc | 68 +- Alignment/Geners/test/CmdLine.hh | 52 +- Alignment/Geners/test/cdump.cc | 20 +- Alignment/Geners/test/cmerge.cc | 33 +- Alignment/Geners/test/crecover.cc | 167 +- Alignment/Geners/test/gssa_dump.cc | 10 +- Alignment/Geners/test/print_items.cc | 44 +- Alignment/LaserDQM/plugins/LaserDQM.cc | 61 +- Alignment/LaserDQM/plugins/LaserDQM.h | 13 +- .../LaserDQM/plugins/LaserDQMInitMonitors.cc | 2074 +++++++--------- .../LaserDQM/plugins/LaserDQMStatistics.cc | 2140 ++++++----------- .../TwoBodyDecay/interface/TwoBodyDecay.h | 34 +- .../interface/TwoBodyDecayDerivatives.h | 54 +- .../interface/TwoBodyDecayEstimator.h | 26 +- .../interface/TwoBodyDecayFitter.h | 34 +- .../TwoBodyDecayLinearizationPointFinder.h | 10 +- .../interface/TwoBodyDecayModel.h | 18 +- .../interface/TwoBodyDecayParameters.h | 37 +- .../TwoBodyDecayVirtualMeasurement.h | 15 +- .../src/TwoBodyDecayDerivatives.cc | 101 +- .../TwoBodyDecay/src/TwoBodyDecayEstimator.cc | 121 +- .../TwoBodyDecay/src/TwoBodyDecayFitter.cc | 44 +- .../TwoBodyDecayLinearizationPointFinder.cc | 27 +- .../TwoBodyDecay/src/TwoBodyDecayModel.cc | 30 +- ...erContainmentCorrectionsVsEtaESProducer.cc | 38 +- ...lShowerContainmentCorrectionsESProducer.cc | 64 +- .../EcalContainmentCorrectionAnalyzer.cc | 11 +- .../interface/EcnaAnalyzer.h | 18 +- .../src/EcnaAnalyzer.cc | 732 +++--- .../interface/NumberOfDevices.h | 21 +- .../SiStripObjects/interface/SiStripCcu.h | 7 +- .../SiStripObjects/interface/SiStripDelay.h | 28 +- .../interface/SiStripDetCabling.h | 104 +- .../SiStripObjects/interface/SiStripFec.h | 3 +- .../interface/SiStripFecCabling.h | 12 +- .../interface/SiStripFecCrate.h | 3 +- .../SiStripObjects/interface/SiStripGain.h | 53 +- .../interface/SiStripHashedDetId.h | 11 +- .../SiStripObjects/interface/SiStripModule.h | 10 +- .../SiStripObjects/interface/SiStripQuality.h | 45 +- .../interface/SiStripRegionCabling.h | 81 +- .../SiStripObjects/interface/SiStripRing.h | 3 +- .../SiStripObjects/src/NumberOfDevices.cc | 5 +- CalibFormats/SiStripObjects/src/SiStripCcu.cc | 3 +- .../SiStripObjects/src/SiStripDelay.cc | 27 +- .../SiStripObjects/src/SiStripDetCabling.cc | 339 +-- CalibFormats/SiStripObjects/src/SiStripFec.cc | 3 +- .../SiStripObjects/src/SiStripFecCabling.cc | 301 +-- .../SiStripObjects/src/SiStripFecCrate.cc | 3 +- .../SiStripObjects/src/SiStripGain.cc | 46 +- .../SiStripObjects/src/SiStripHashedDetId.cc | 33 +- .../SiStripObjects/src/SiStripModule.cc | 162 +- .../SiStripObjects/src/SiStripQuality.cc | 365 ++- .../src/SiStripRegionCabling.cc | 49 +- .../SiStripObjects/src/SiStripRing.cc | 3 +- .../test/UnitTests/TestSiStripDelay.cc | 23 +- .../test/UnitTests/TestSiStripGain.cc | 35 +- .../test/plugins/testSiStripHashedDetId.cc | 78 +- .../test/plugins/testSiStripHashedDetId.h | 3 +- .../interface/RPCFakeCalibration.h | 3 +- .../interface/RPCPerformanceESSource.h | 6 +- CalibMuon/RPCCalibration/src/RPCCalibSetUp.cc | 69 +- .../RPCCalibration/src/RPCFakeCalibration.cc | 21 +- .../src/RPCPerformanceESSource.cc | 11 +- .../src/SiPixelIsAliveCalibration.cc | 54 +- .../SiPixelSCurveCalibrationAnalysis.h | 64 +- .../src/SiPixelSCurveCalibrationAnalysis.cc | 285 +-- Calibration/EcalTBTools/interface/TB06Reco.h | 2 +- .../EcalTBTools/interface/TB06RecoH2.h | 2 +- Calibration/EcalTBTools/interface/TB06Tree.h | 22 +- .../EcalTBTools/interface/TB06TreeH2.h | 73 +- Calibration/EcalTBTools/src/TB06Tree.cc | 50 +- Calibration/EcalTBTools/src/TB06TreeH2.cc | 103 +- Calibration/EcalTBTools/src/classes.h | 4 +- .../HcalConnectivity/src/HcalCableMapper.cc | 100 +- .../interface/PixelSLinkDataInputSource.h | 10 +- .../src/PixelSLinkDataInputSource.cc | 65 +- 168 files changed, 10497 insertions(+), 12678 deletions(-) diff --git a/Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h b/Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h index e3b8dcf891885..4d60f99c228b5 100644 --- a/Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h +++ b/Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h @@ -14,11 +14,9 @@ #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h" class CocoaMaterialElementary { - public: //---------- Constructors / Destructor - CocoaMaterialElementary(ALIstring name, float density, ALIstring symbol, - float A, ALIint Z); + CocoaMaterialElementary(ALIstring name, float density, ALIstring symbol, float A, ALIint Z); ~CocoaMaterialElementary(){}; ALIstring getName() const { return theName; } diff --git a/Alignment/CocoaDDLObjects/interface/CocoaSolidShape.h b/Alignment/CocoaDDLObjects/interface/CocoaSolidShape.h index 553b1b512eb46..942bde75b3bbb 100644 --- a/Alignment/CocoaDDLObjects/interface/CocoaSolidShape.h +++ b/Alignment/CocoaDDLObjects/interface/CocoaSolidShape.h @@ -14,7 +14,6 @@ #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h" class CocoaSolidShape { - public: //---------- Constructors / Destructor CocoaSolidShape(ALIstring type); diff --git a/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h b/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h index 1bf54dcffdf2c..25182e7d7f15d 100644 --- a/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h +++ b/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h @@ -11,11 +11,9 @@ #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h" class CocoaSolidShapeBox : public CocoaSolidShape { - public: //---------- Constructors / Destructor - CocoaSolidShapeBox(ALIstring type, ALIfloat xdim, ALIfloat ydim, - ALIfloat zdim); + CocoaSolidShapeBox(ALIstring type, ALIfloat xdim, ALIfloat ydim, ALIfloat zdim); ~CocoaSolidShapeBox() override{}; ALIfloat getXHalfLength() const { return theXHalfLength; } diff --git a/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h b/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h index 2a8c80b719348..a58750af2345e 100644 --- a/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h +++ b/Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h @@ -12,11 +12,13 @@ #include "CLHEP/Units/GlobalSystemOfUnits.h" class CocoaSolidShapeTubs : public CocoaSolidShape { - public: //---------- Constructors / Destructor - CocoaSolidShapeTubs(const ALIstring pType, ALIfloat pRMin, ALIfloat pRMax, - ALIfloat pDz, ALIfloat pSPhi = 0. * deg, + CocoaSolidShapeTubs(const ALIstring pType, + ALIfloat pRMin, + ALIfloat pRMax, + ALIfloat pDz, + ALIfloat pSPhi = 0. * deg, ALIfloat pDPhi = 360. * deg); ~CocoaSolidShapeTubs() override{}; ALIfloat getInnerRadius() const { return theInnerRadius; } diff --git a/Alignment/CocoaDDLObjects/src/CocoaMaterialElementary.cc b/Alignment/CocoaDDLObjects/src/CocoaMaterialElementary.cc index 4fb4ac6df7797..b843f34cf9932 100644 --- a/Alignment/CocoaDDLObjects/src/CocoaMaterialElementary.cc +++ b/Alignment/CocoaDDLObjects/src/CocoaMaterialElementary.cc @@ -4,24 +4,20 @@ // // History: v1.0 // Pedro Arce -#include // include floating-point std::abs functions +#include // include floating-point std::abs functions #include #include #include "Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h" -CocoaMaterialElementary::CocoaMaterialElementary(ALIstring name, float density, - ALIstring symbol, float A, - ALIint Z) +CocoaMaterialElementary::CocoaMaterialElementary(ALIstring name, float density, ALIstring symbol, float A, ALIint Z) : theName(name), theDensity(density), theSymbol(symbol), theA(A), theZ(Z) {} -ALIbool CocoaMaterialElementary:: -operator==(const CocoaMaterialElementary &mate) const { +ALIbool CocoaMaterialElementary::operator==(const CocoaMaterialElementary &mate) const { // GM: Using numeric_limits::epsilon() might be better instead of a // magic number 'kTolerance'. Not changing this to not break code // potentially relying on this number. const float kTolerance = 1.E-9; - return (std::abs(mate.getDensity() - theDensity) < kTolerance && - mate.getSymbol() == theSymbol && + return (std::abs(mate.getDensity() - theDensity) < kTolerance && mate.getSymbol() == theSymbol && std::abs(mate.getA() - theA) < kTolerance && mate.getZ() == theZ); } diff --git a/Alignment/CocoaDDLObjects/src/CocoaSolidShapeBox.cc b/Alignment/CocoaDDLObjects/src/CocoaSolidShapeBox.cc index 373753a06b7c9..c48c992d44d44 100644 --- a/Alignment/CocoaDDLObjects/src/CocoaSolidShapeBox.cc +++ b/Alignment/CocoaDDLObjects/src/CocoaSolidShapeBox.cc @@ -9,10 +9,8 @@ #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h" -CocoaSolidShapeBox::CocoaSolidShapeBox(ALIstring type, ALIfloat xdim, - ALIfloat ydim, ALIfloat zdim) +CocoaSolidShapeBox::CocoaSolidShapeBox(ALIstring type, ALIfloat xdim, ALIfloat ydim, ALIfloat zdim) : CocoaSolidShape(type) { - theXHalfLength = xdim; theYHalfLength = ydim; theZHalfLength = zdim; diff --git a/Alignment/CocoaDDLObjects/src/CocoaSolidShapeTubs.cc b/Alignment/CocoaDDLObjects/src/CocoaSolidShapeTubs.cc index 2fd5671d91d59..c2e282268c211 100644 --- a/Alignment/CocoaDDLObjects/src/CocoaSolidShapeTubs.cc +++ b/Alignment/CocoaDDLObjects/src/CocoaSolidShapeTubs.cc @@ -9,11 +9,9 @@ #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h" -CocoaSolidShapeTubs::CocoaSolidShapeTubs(const ALIstring type, ALIfloat pRMin, - ALIfloat pRMax, ALIfloat pDz, - ALIfloat pSPhi, ALIfloat pDPhi) +CocoaSolidShapeTubs::CocoaSolidShapeTubs( + const ALIstring type, ALIfloat pRMin, ALIfloat pRMax, ALIfloat pDz, ALIfloat pSPhi, ALIfloat pDPhi) : CocoaSolidShape(type) { - theInnerRadius = pRMin; theOuterRadius = pRMax; theZHalfLength = pDz; diff --git a/Alignment/Geners/interface/AbsArchive.hh b/Alignment/Geners/interface/AbsArchive.hh index cc85c5f2f4b76..a228fb15bd8de 100644 --- a/Alignment/Geners/interface/AbsArchive.hh +++ b/Alignment/Geners/interface/AbsArchive.hh @@ -10,156 +10,149 @@ #include "Alignment/Geners/interface/SearchSpecifier.hh" namespace gs { -class AbsArchive; + class AbsArchive; } gs::AbsArchive &operator<<(gs::AbsArchive &ar, const gs::AbsRecord &record); namespace gs { -// -// If you need to retrieve the items, use the interface provided -// by the "Reference" class. Public interface of this class only -// allows to examine the item metadata and to copy items as BLOBs. -// -class AbsArchive { -public: - AbsArchive(const char *name); - inline virtual ~AbsArchive() {} - - // Archive name - const std::string &name() const { return name_; } - - // Is it correctly open? - virtual bool isOpen() const = 0; - - // If an attempt to open the archive failed, call the following - // method to find out why - virtual std::string error() const = 0; - - // Is the archive readable? - virtual bool isReadable() const = 0; - - // Is the archive writable? - virtual bool isWritable() const = 0; - - // Number of items in the archive. Note that id value - // of 0 refers to an invalid item. - virtual unsigned long long size() const = 0; - - // Smallest and largest ids of any item in the archive - virtual unsigned long long smallestId() const = 0; - virtual unsigned long long largestId() const = 0; - - // Are the item ids contiguous between the smallest and - // the largest? - virtual bool idsAreContiguous() const = 0; - - // Check if the item with given id is actually present - // in the archive - virtual bool itemExists(unsigned long long id) const = 0; - - // Search for matching items based on item name and - // category (no type match required) - virtual void itemSearch(const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern, - std::vector *found) const = 0; - - // Fetch metadata for the item with given id. NULL pointer is - // returned if there is no item in the archive with the given id - // (and there is an automatic cast from CPP11_shared_ptr to bool). - virtual CPP11_shared_ptr - catalogEntry(unsigned long long id) = 0; - - // Dump everything to storage (if the archive is open for writing - // and if this makes sense for the archive) - virtual void flush() = 0; - - // Copy an item from this archive to a destination archive. - // This archive and destination archive must be distinct. - // Note that, while it is always possible to copy an item - // with correct id, a standalone operation like this is - // not necessarily going to make sense because the item - // could be just a part of some distributed object. // - // If "newName" and/or "newCategory" arguments are left at their - // default value of 0, the existing name and/or category are used. + // If you need to retrieve the items, use the interface provided + // by the "Reference" class. Public interface of this class only + // allows to examine the item metadata and to copy items as BLOBs. // - // This method returns the id of the copy in the destination - // archive. - unsigned long long copyItem(unsigned long long id, AbsArchive *destination, - const char *newName = nullptr, - const char *newCategory = nullptr); - - // The id and the length of the last item written - // (the results make sense only for the archives - // that have been open for writing) - inline unsigned long long lastItemId() const { return lastItemId_; } - inline unsigned long long lastItemLength() const { return lastItemLength_; } - - inline bool operator==(const AbsArchive &r) const { - return (typeid(*this) == typeid(r)) && this->isEqual(r); - } - inline bool operator!=(const AbsArchive &r) const { return !(*this == r); } - -protected: - void addItemToReference(AbsReference &r, unsigned long long id) const; - - // Archives which want to implement reasonable comparisons - // should override the function below - virtual bool isEqual(const AbsArchive &) const { return false; } - -private: - friend class AbsReference; - friend gs::AbsArchive & ::operator<<(gs::AbsArchive &ar, - const gs::AbsRecord &record); - - // Search for items which correspond to the given reference. - // The "reference" works both as the input and as the output in - // this query. The concrete implementations should utilize the - // "addItemToReference" method in order to produce results. - virtual void search(AbsReference &reference) = 0; - - // Position the input stream for reading the item with given id. - // The reading must follow immediately, any other operaction on - // the archive can invalidate the result. - // - // The "sz" argument could be NULL in which case it should be - // ignored. If it is not NULL, the *sz value on completion - // should be set as follows: - // - // *sz = -1 -- if the uncompressed object size in the stream - // is the same as in the catalog - // *sz >= 0 -- *sz is the object size after decompression - // (usually not the same as in the catalog) - // - virtual std::istream &inputStream(unsigned long long id, long long *sz) = 0; - - // Get the stream for writing the next object - virtual std::ostream &outputStream() = 0; - - // The following function should return 0 on failure and - // the item id in the archive on success. The id must be positive. - virtual unsigned long long addToCatalog(const AbsRecord &record, - unsigned compressCode, - unsigned long long itemLength) = 0; - - // The archives which want to support compression should - // override the following two methods - virtual std::ostream &compressedStream(std::ostream &uncompressed) { - return uncompressed; - } - - // The following function returns some kind of a code which - // tells us how the item was compressed. Default value of 0 - // means no compression. - virtual unsigned flushCompressedRecord(std::ostream & /* compressed */) { - return 0U; - } - - std::string name_; - unsigned long long lastItemId_; - unsigned long long lastItemLength_; -}; -} // namespace gs - -#endif // GENERS_ABSARCHIVE_HH_ + class AbsArchive { + public: + AbsArchive(const char *name); + inline virtual ~AbsArchive() {} + + // Archive name + const std::string &name() const { return name_; } + + // Is it correctly open? + virtual bool isOpen() const = 0; + + // If an attempt to open the archive failed, call the following + // method to find out why + virtual std::string error() const = 0; + + // Is the archive readable? + virtual bool isReadable() const = 0; + + // Is the archive writable? + virtual bool isWritable() const = 0; + + // Number of items in the archive. Note that id value + // of 0 refers to an invalid item. + virtual unsigned long long size() const = 0; + + // Smallest and largest ids of any item in the archive + virtual unsigned long long smallestId() const = 0; + virtual unsigned long long largestId() const = 0; + + // Are the item ids contiguous between the smallest and + // the largest? + virtual bool idsAreContiguous() const = 0; + + // Check if the item with given id is actually present + // in the archive + virtual bool itemExists(unsigned long long id) const = 0; + + // Search for matching items based on item name and + // category (no type match required) + virtual void itemSearch(const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern, + std::vector *found) const = 0; + + // Fetch metadata for the item with given id. NULL pointer is + // returned if there is no item in the archive with the given id + // (and there is an automatic cast from CPP11_shared_ptr to bool). + virtual CPP11_shared_ptr catalogEntry(unsigned long long id) = 0; + + // Dump everything to storage (if the archive is open for writing + // and if this makes sense for the archive) + virtual void flush() = 0; + + // Copy an item from this archive to a destination archive. + // This archive and destination archive must be distinct. + // Note that, while it is always possible to copy an item + // with correct id, a standalone operation like this is + // not necessarily going to make sense because the item + // could be just a part of some distributed object. + // + // If "newName" and/or "newCategory" arguments are left at their + // default value of 0, the existing name and/or category are used. + // + // This method returns the id of the copy in the destination + // archive. + unsigned long long copyItem(unsigned long long id, + AbsArchive *destination, + const char *newName = nullptr, + const char *newCategory = nullptr); + + // The id and the length of the last item written + // (the results make sense only for the archives + // that have been open for writing) + inline unsigned long long lastItemId() const { return lastItemId_; } + inline unsigned long long lastItemLength() const { return lastItemLength_; } + + inline bool operator==(const AbsArchive &r) const { return (typeid(*this) == typeid(r)) && this->isEqual(r); } + inline bool operator!=(const AbsArchive &r) const { return !(*this == r); } + + protected: + void addItemToReference(AbsReference &r, unsigned long long id) const; + + // Archives which want to implement reasonable comparisons + // should override the function below + virtual bool isEqual(const AbsArchive &) const { return false; } + + private: + friend class AbsReference; + friend gs::AbsArchive & ::operator<<(gs::AbsArchive &ar, const gs::AbsRecord &record); + + // Search for items which correspond to the given reference. + // The "reference" works both as the input and as the output in + // this query. The concrete implementations should utilize the + // "addItemToReference" method in order to produce results. + virtual void search(AbsReference &reference) = 0; + + // Position the input stream for reading the item with given id. + // The reading must follow immediately, any other operaction on + // the archive can invalidate the result. + // + // The "sz" argument could be NULL in which case it should be + // ignored. If it is not NULL, the *sz value on completion + // should be set as follows: + // + // *sz = -1 -- if the uncompressed object size in the stream + // is the same as in the catalog + // *sz >= 0 -- *sz is the object size after decompression + // (usually not the same as in the catalog) + // + virtual std::istream &inputStream(unsigned long long id, long long *sz) = 0; + + // Get the stream for writing the next object + virtual std::ostream &outputStream() = 0; + + // The following function should return 0 on failure and + // the item id in the archive on success. The id must be positive. + virtual unsigned long long addToCatalog(const AbsRecord &record, + unsigned compressCode, + unsigned long long itemLength) = 0; + + // The archives which want to support compression should + // override the following two methods + virtual std::ostream &compressedStream(std::ostream &uncompressed) { return uncompressed; } + + // The following function returns some kind of a code which + // tells us how the item was compressed. Default value of 0 + // means no compression. + virtual unsigned flushCompressedRecord(std::ostream & /* compressed */) { return 0U; } + + std::string name_; + unsigned long long lastItemId_; + unsigned long long lastItemLength_; + }; +} // namespace gs + +#endif // GENERS_ABSARCHIVE_HH_ diff --git a/Alignment/Geners/interface/AbsCatalog.hh b/Alignment/Geners/interface/AbsCatalog.hh index 01014a0fb510d..22f343e13fedb 100644 --- a/Alignment/Geners/interface/AbsCatalog.hh +++ b/Alignment/Geners/interface/AbsCatalog.hh @@ -10,76 +10,73 @@ #include "Alignment/Geners/interface/SearchSpecifier.hh" namespace gs { -// -// This abstract class defines interfaces for adding entries to -// a catalog but not for removing them. Of course, derived classes -// can also implement catalog entry removal if necessary. -// -struct AbsCatalog { - virtual ~AbsCatalog() {} + // + // This abstract class defines interfaces for adding entries to + // a catalog but not for removing them. Of course, derived classes + // can also implement catalog entry removal if necessary. + // + struct AbsCatalog { + virtual ~AbsCatalog() {} - // The number of entries in the catalog - virtual unsigned long long size() const = 0; + // The number of entries in the catalog + virtual unsigned long long size() const = 0; - // Smallest and largest ids of any item in the catalog - virtual unsigned long long smallestId() const = 0; - virtual unsigned long long largestId() const = 0; - virtual bool isContiguous() const = 0; + // Smallest and largest ids of any item in the catalog + virtual unsigned long long smallestId() const = 0; + virtual unsigned long long largestId() const = 0; + virtual bool isContiguous() const = 0; - // Check if an item with the given id is actually present in - // the catalog. Catalogs which support non-contiguous item ids - // (for example, if items can be removed) MUST override this. - virtual bool itemExists(const unsigned long long id) const { - if (id == 0ULL) - return false; - assert(isContiguous()); - return id >= smallestId() && id <= largestId(); - } + // Check if an item with the given id is actually present in + // the catalog. Catalogs which support non-contiguous item ids + // (for example, if items can be removed) MUST override this. + virtual bool itemExists(const unsigned long long id) const { + if (id == 0ULL) + return false; + assert(isContiguous()); + return id >= smallestId() && id <= largestId(); + } - // The following function should return the id of the new entry - virtual unsigned long long makeEntry(const ItemDescriptor &descriptor, - unsigned compressionCode, - unsigned long long itemLength, - const ItemLocation &loc, - unsigned long long offset = 0ULL) = 0; + // The following function should return the id of the new entry + virtual unsigned long long makeEntry(const ItemDescriptor &descriptor, + unsigned compressionCode, + unsigned long long itemLength, + const ItemLocation &loc, + unsigned long long offset = 0ULL) = 0; - // It must be possible to retrieve the entry made by the last - // "makeEntry" call. If no "makeEntry" calls were made in this - // program (e.g., the catalog was only read and not written), - // null pointer should be returned. The entry should be owned - // by the catalog itself. - virtual const CatalogEntry *lastEntryMade() const = 0; + // It must be possible to retrieve the entry made by the last + // "makeEntry" call. If no "makeEntry" calls were made in this + // program (e.g., the catalog was only read and not written), + // null pointer should be returned. The entry should be owned + // by the catalog itself. + virtual const CatalogEntry *lastEntryMade() const = 0; - // The following function returns a shared pointer to the entry. - // The pointer will contain NULL in case the item is not found. - virtual CPP11_shared_ptr - retrieveEntry(unsigned long long id) const = 0; + // The following function returns a shared pointer to the entry. + // The pointer will contain NULL in case the item is not found. + virtual CPP11_shared_ptr retrieveEntry(unsigned long long id) const = 0; - // The following function fetches just the stream position - // associated with the entry. "true" is returned on success. - // Useful for catalogs which serve a single stream. - virtual bool retrieveStreampos(unsigned long long id, - unsigned *compressionCode, - unsigned long long *length, - std::streampos *pos) const = 0; + // The following function fetches just the stream position + // associated with the entry. "true" is returned on success. + // Useful for catalogs which serve a single stream. + virtual bool retrieveStreampos(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length, + std::streampos *pos) const = 0; - // Search for matching entries based on item name and category - virtual void search(const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern, - std::vector *idsFound) const = 0; + // Search for matching entries based on item name and category + virtual void search(const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern, + std::vector *idsFound) const = 0; - inline bool operator==(const AbsCatalog &r) const { - return (typeid(*this) == typeid(r)) && this->isEqual(r); - } - inline bool operator!=(const AbsCatalog &r) const { return !(*this == r); } + inline bool operator==(const AbsCatalog &r) const { return (typeid(*this) == typeid(r)) && this->isEqual(r); } + inline bool operator!=(const AbsCatalog &r) const { return !(*this == r); } - // Prototypes needed for I/O - virtual ClassId classId() const = 0; - virtual bool write(std::ostream &) const = 0; + // Prototypes needed for I/O + virtual ClassId classId() const = 0; + virtual bool write(std::ostream &) const = 0; -protected: - virtual bool isEqual(const AbsCatalog &) const = 0; -}; -} // namespace gs + protected: + virtual bool isEqual(const AbsCatalog &) const = 0; + }; +} // namespace gs -#endif // GENERS_ABSCATALOG_HH_ +#endif // GENERS_ABSCATALOG_HH_ diff --git a/Alignment/Geners/interface/AbsReader.hh b/Alignment/Geners/interface/AbsReader.hh index 46bffab64d880..d0b8ef0e4763b 100644 --- a/Alignment/Geners/interface/AbsReader.hh +++ b/Alignment/Geners/interface/AbsReader.hh @@ -33,84 +33,83 @@ #include "Alignment/Geners/interface/ClassId.hh" namespace gs { -template struct AbsReader { - virtual ~AbsReader() {} - - virtual Base *read(const ClassId &id, std::istream &in) const = 0; -}; - -template -struct ConcreteReader : public AbsReader { - virtual ~ConcreteReader() {} - - inline Derived *read(const ClassId &id, std::istream &in) const { - // Assume that Derived::read(id, in) returns a new object - // of type "Derived" allocated on the heap - return Derived::read(id, in); - } -}; - -template -class DefaultReader : public std::map *> { -public: - typedef Base value_type; - - inline DefaultReader() : std::map *>() {} - - virtual ~DefaultReader() { - for (typename std::map *>::iterator it = - this->begin(); - it != this->end(); ++it) - delete it->second; - } - - inline Base *read(const ClassId &id, std::istream &in) const { - typename std::map *>::const_iterator it = - this->find(id.name()); - if (it == this->end()) { - std::ostringstream os; - os << "In gs::DefaultReader::read: class \"" << id.name() - << "\" is not mapped to a concrete reader"; - throw gs::IOInvalidArgument(os.str()); + template + struct AbsReader { + virtual ~AbsReader() {} + + virtual Base *read(const ClassId &id, std::istream &in) const = 0; + }; + + template + struct ConcreteReader : public AbsReader { + virtual ~ConcreteReader() {} + + inline Derived *read(const ClassId &id, std::istream &in) const { + // Assume that Derived::read(id, in) returns a new object + // of type "Derived" allocated on the heap + return Derived::read(id, in); } - return it->second->read(id, in); - } - -private: - DefaultReader(const DefaultReader &); - DefaultReader &operator=(const DefaultReader &); -}; - -// A trivial implementation of the Meyers singleton for use with reader -// factories. Naturally, this assumes that all factories are independent -// from each other (otherwise we are getting into trouble with undefined -// singleton destruction order). Also, this particular code is not -// thread-safe (but should become thread-safe in C++11 if I understand -// static local initialization guarantees correctly). -// -// Assume that "Reader" is derived from "DefaultReader" and that it -// publishes its base class as "Base". -// -template class StaticReader { -public: - typedef typename Reader::Base::value_type InheritanceBase; - - static const Reader &instance() { - static Reader obj; - return obj; - } - - template static void registerClass() { - Reader &rd = const_cast(instance()); - const ClassId &id(ClassId::makeId()); - delete rd[id.name()]; - rd[id.name()] = new ConcreteReader(); - } - -private: - // Disable the constructor - StaticReader(); -}; -} // namespace gs - -#endif // GENERS_ABSREADER_HH_ + }; + + template + class DefaultReader : public std::map *> { + public: + typedef Base value_type; + + inline DefaultReader() : std::map *>() {} + + virtual ~DefaultReader() { + for (typename std::map *>::iterator it = this->begin(); it != this->end(); ++it) + delete it->second; + } + + inline Base *read(const ClassId &id, std::istream &in) const { + typename std::map *>::const_iterator it = this->find(id.name()); + if (it == this->end()) { + std::ostringstream os; + os << "In gs::DefaultReader::read: class \"" << id.name() << "\" is not mapped to a concrete reader"; + throw gs::IOInvalidArgument(os.str()); + } + return it->second->read(id, in); + } + + private: + DefaultReader(const DefaultReader &); + DefaultReader &operator=(const DefaultReader &); + }; + + // A trivial implementation of the Meyers singleton for use with reader + // factories. Naturally, this assumes that all factories are independent + // from each other (otherwise we are getting into trouble with undefined + // singleton destruction order). Also, this particular code is not + // thread-safe (but should become thread-safe in C++11 if I understand + // static local initialization guarantees correctly). + // + // Assume that "Reader" is derived from "DefaultReader" and that it + // publishes its base class as "Base". + // + template + class StaticReader { + public: + typedef typename Reader::Base::value_type InheritanceBase; + + static const Reader &instance() { + static Reader obj; + return obj; + } + + template + static void registerClass() { + Reader &rd = const_cast(instance()); + const ClassId &id(ClassId::makeId()); + delete rd[id.name()]; + rd[id.name()] = new ConcreteReader(); + } + + private: + // Disable the constructor + StaticReader(); + }; +} // namespace gs + +#endif // GENERS_ABSREADER_HH_ diff --git a/Alignment/Geners/interface/AbsRecord.hh b/Alignment/Geners/interface/AbsRecord.hh index ad3f10ae8a599..05ecdfeff4f87 100644 --- a/Alignment/Geners/interface/AbsRecord.hh +++ b/Alignment/Geners/interface/AbsRecord.hh @@ -4,45 +4,42 @@ #include "Alignment/Geners/interface/ItemDescriptor.hh" namespace gs { -class AbsArchive; -class AbsRecord; -} // namespace gs + class AbsArchive; + class AbsRecord; +} // namespace gs gs::AbsArchive &operator<<(gs::AbsArchive &ar, const gs::AbsRecord &record); namespace gs { -class AbsRecord : public ItemDescriptor { -public: - inline ~AbsRecord() override {} - - // Item id will be set to non-0 value upon writing the item - // into the archive. When the id is not 0, the record can no - // longer be written out (if you really want to write out the - // same item again, make another record). - inline unsigned long long id() const { return itemId_; } - - // Item length will be set to non-0 value upon writing the item - // into the archive. - inline unsigned long long itemLength() const { return itemLength_; } - -protected: - inline AbsRecord() : ItemDescriptor(), itemId_(0), itemLength_(0) {} - inline AbsRecord(const ClassId &classId, const char *ioPrototype, - const char *name, const char *category) - : ItemDescriptor(classId, ioPrototype, name, category), itemId_(0), - itemLength_(0) {} - -private: - friend gs::AbsArchive & ::operator<<(gs::AbsArchive &ar, - const gs::AbsRecord &record); - - // The following functions must be overriden by derived classes. - // "writeData" should return "true" upon success. - virtual bool writeData(std::ostream &os) const = 0; - - mutable unsigned long long itemId_; - mutable unsigned long long itemLength_; -}; -} // namespace gs - -#endif // GENERS_ABSRECORD_HH_ + class AbsRecord : public ItemDescriptor { + public: + inline ~AbsRecord() override {} + + // Item id will be set to non-0 value upon writing the item + // into the archive. When the id is not 0, the record can no + // longer be written out (if you really want to write out the + // same item again, make another record). + inline unsigned long long id() const { return itemId_; } + + // Item length will be set to non-0 value upon writing the item + // into the archive. + inline unsigned long long itemLength() const { return itemLength_; } + + protected: + inline AbsRecord() : ItemDescriptor(), itemId_(0), itemLength_(0) {} + inline AbsRecord(const ClassId &classId, const char *ioPrototype, const char *name, const char *category) + : ItemDescriptor(classId, ioPrototype, name, category), itemId_(0), itemLength_(0) {} + + private: + friend gs::AbsArchive & ::operator<<(gs::AbsArchive &ar, const gs::AbsRecord &record); + + // The following functions must be overriden by derived classes. + // "writeData" should return "true" upon success. + virtual bool writeData(std::ostream &os) const = 0; + + mutable unsigned long long itemId_; + mutable unsigned long long itemLength_; + }; +} // namespace gs + +#endif // GENERS_ABSRECORD_HH_ diff --git a/Alignment/Geners/interface/AbsReference.hh b/Alignment/Geners/interface/AbsReference.hh index 9bbf990b8526a..3fe1ae59696cf 100644 --- a/Alignment/Geners/interface/AbsReference.hh +++ b/Alignment/Geners/interface/AbsReference.hh @@ -9,91 +9,89 @@ #include "Alignment/Geners/interface/SearchSpecifier.hh" namespace gs { -class AbsArchive; -class CatalogEntry; - -class AbsReference { -public: - inline virtual ~AbsReference() {} - - inline AbsArchive &archive() const { return archive_; } - inline const ClassId &type() const { return classId_; } - inline const std::string &ioPrototype() const { return ioProto_; } - inline const SearchSpecifier &namePattern() const { return namePattern_; } - inline const SearchSpecifier &categoryPattern() const { - return categoryPattern_; - } - - // Determine if the item in the catalog is compatible for I/O - // purposes with the one referenced here - virtual bool isIOCompatible(const CatalogEntry &r) const; - - // Check I/O prototype only allowing for class id mismatch - bool isSameIOPrototype(const CatalogEntry &r) const; - - // Are there any items referenced? - bool empty() const; - - // Exactly one item referenced? - bool unique() const; - - // How many items are referenced? - unsigned long size() const; - - // The following function throws gs::IOOutOfRange exception - // if the index is out of range - unsigned long long id(unsigned long index) const; - - // Catalog entry retrieval by index in the list of referenced items. - // Throws gs::IOOutOfRange exception if the index is out of range. - CPP11_shared_ptr - indexedCatalogEntry(unsigned long index) const; - -protected: - // Use the following constructor to retrieve an item with - // a known id - AbsReference(AbsArchive &ar, const ClassId &classId, const char *ioProto, - unsigned long long itemId); - - // Use the following constructor to search for items which - // match name and category patterns - AbsReference(AbsArchive &ar, const ClassId &classId, const char *ioProto, - const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern); - - std::istream &positionInputStream(unsigned long long id) const; - -private: - friend class AbsArchive; - - AbsReference() = delete; - - void initialize() const; - void addItemId(unsigned long long id); - - AbsArchive &archive_; - ClassId classId_; - std::string ioProto_; - - // The following items will be filled or not, - // depending on which constructor was called - unsigned long long searchId_; - SearchSpecifier namePattern_; - SearchSpecifier categoryPattern_; - - // Id for a unique verified item - unsigned long long itemId_; - - // The item list in case ids are not unique - std::vector idList_; - - // We can't talk to the archive from the constructor - // because we need correct "isIOCompatible" which - // can be overriden by derived classes. Therefore, - // we will delay archive searching until the first - // function call. - bool initialized_; -}; -} // namespace gs - -#endif // GENERS_ABSREFERENCE_HH_ + class AbsArchive; + class CatalogEntry; + + class AbsReference { + public: + inline virtual ~AbsReference() {} + + inline AbsArchive &archive() const { return archive_; } + inline const ClassId &type() const { return classId_; } + inline const std::string &ioPrototype() const { return ioProto_; } + inline const SearchSpecifier &namePattern() const { return namePattern_; } + inline const SearchSpecifier &categoryPattern() const { return categoryPattern_; } + + // Determine if the item in the catalog is compatible for I/O + // purposes with the one referenced here + virtual bool isIOCompatible(const CatalogEntry &r) const; + + // Check I/O prototype only allowing for class id mismatch + bool isSameIOPrototype(const CatalogEntry &r) const; + + // Are there any items referenced? + bool empty() const; + + // Exactly one item referenced? + bool unique() const; + + // How many items are referenced? + unsigned long size() const; + + // The following function throws gs::IOOutOfRange exception + // if the index is out of range + unsigned long long id(unsigned long index) const; + + // Catalog entry retrieval by index in the list of referenced items. + // Throws gs::IOOutOfRange exception if the index is out of range. + CPP11_shared_ptr indexedCatalogEntry(unsigned long index) const; + + protected: + // Use the following constructor to retrieve an item with + // a known id + AbsReference(AbsArchive &ar, const ClassId &classId, const char *ioProto, unsigned long long itemId); + + // Use the following constructor to search for items which + // match name and category patterns + AbsReference(AbsArchive &ar, + const ClassId &classId, + const char *ioProto, + const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern); + + std::istream &positionInputStream(unsigned long long id) const; + + private: + friend class AbsArchive; + + AbsReference() = delete; + + void initialize() const; + void addItemId(unsigned long long id); + + AbsArchive &archive_; + ClassId classId_; + std::string ioProto_; + + // The following items will be filled or not, + // depending on which constructor was called + unsigned long long searchId_; + SearchSpecifier namePattern_; + SearchSpecifier categoryPattern_; + + // Id for a unique verified item + unsigned long long itemId_; + + // The item list in case ids are not unique + std::vector idList_; + + // We can't talk to the archive from the constructor + // because we need correct "isIOCompatible" which + // can be overriden by derived classes. Therefore, + // we will delay archive searching until the first + // function call. + bool initialized_; + }; +} // namespace gs + +#endif // GENERS_ABSREFERENCE_HH_ diff --git a/Alignment/Geners/interface/ArrayAdaptor.hh b/Alignment/Geners/interface/ArrayAdaptor.hh index 78a3c1268bd3c..7f5c626a82095 100644 --- a/Alignment/Geners/interface/ArrayAdaptor.hh +++ b/Alignment/Geners/interface/ArrayAdaptor.hh @@ -11,171 +11,160 @@ #include "Alignment/Geners/interface/binaryIO.hh" namespace gs { -template -struct GenericWriter; - -template -struct GenericReader; - -template class ArrayAdaptor { -public: - typedef T value_type; - typedef const T *const_iterator; - - inline ArrayAdaptor(const T *indata, const std::size_t sz, - const bool writeItemClassId = true) - : data_(indata), size_(sz), writetemCl_(writeItemClassId) { - if (sz) - assert(data_); - } - - inline std::size_t size() const { return size_; } - inline const_iterator begin() const { return data_; } - inline const_iterator end() const { return data_ + size_; } - inline bool writeItemClassId() const { return writetemCl_; } - inline const T &operator[](const std::size_t index) const { - return data_[index]; - } - inline T &operator[](const std::size_t index) { - return (const_cast(data_))[index]; - } - inline T &at(const std::size_t index) { - if (index >= size_) - throw gs::IOOutOfRange("gs::ArrayAdaptor::at: index out of range"); - return (const_cast(data_))[index]; - } - -private: - ArrayAdaptor() = delete; - - const T *data_; - std::size_t size_; - bool writetemCl_; -}; - -template struct IOIsContiguous> { - enum { value = 1 }; -}; - -template struct IOIsContiguous> { - enum { value = 1 }; -}; - -template struct IOIsContiguous> { - enum { value = 1 }; -}; - -template struct IOIsContiguous> { - enum { value = 1 }; -}; - -template struct InsertContainerItem> { - typedef ArrayAdaptor A; - static inline void insert(A &obj, const typename A::value_type &item, - const std::size_t itemNumber) { - obj.at(itemNumber) = item; - } -}; - -template struct InsertContainerItem> { - typedef ArrayAdaptor A; - static inline void insert(A &obj, const typename A::value_type &item, - const std::size_t itemNumber) { - obj.at(itemNumber) = item; - } -}; - -// Ignore array size I/O. The size is provided in the constructor. -// Of course, it still has to be written somewhere, but that code -// is external w.r.t. the array adaptor. -template -struct GenericWriter, InContainerSize> { - inline static bool process(std::size_t, Stream &os, State *, - const bool processClassId) { - return true; - } -}; - -template -struct GenericReader, InContainerSize> { - inline static bool process(std::size_t, Stream &os, State *, - const bool processClassId) { - return true; - } -}; - -template -struct GenericWriter, InPODArray> { - inline static bool process(const ArrayAdaptor &a, Stream &os, State *, - bool) { - const std::size_t len = a.size(); - if (len) - write_pod_array(os, &a[0], len); - return !os.fail(); - } -}; - -template -struct GenericReader, InPODArray> { - inline static bool process(ArrayAdaptor &a, Stream &s, State *, bool) { - const std::size_t len = a.size(); - if (len) - read_pod_array(s, &a[0], len); - return !s.fail(); - } -}; - -template -struct GenericWriter, InContainerHeader> { - typedef ArrayAdaptor Container; - - inline static bool process(const Container &c, Stream &os, State *, - const bool processClassId) { - bool status = - processClassId ? ClassId::makeId().write(os) : true; - if (status && !(IOTraits::IsPOD && IOTraits::IsContiguous) && - c.writeItemClassId()) - status = ClassId::makeId().write(os); - return status; - } -}; - -template -struct GenericReader, InContainerHeader> { - typedef ArrayAdaptor Container; - - inline static bool process(Container &a, Stream &is, State *state, - const bool processClassId) { - bool status = true; - if (processClassId) { - ClassId id(is, 1); - const ClassId ¤t = ClassId::makeId(); - status = (id.name() == current.name()); + template + struct GenericWriter; + + template + struct GenericReader; + + template + class ArrayAdaptor { + public: + typedef T value_type; + typedef const T *const_iterator; + + inline ArrayAdaptor(const T *indata, const std::size_t sz, const bool writeItemClassId = true) + : data_(indata), size_(sz), writetemCl_(writeItemClassId) { + if (sz) + assert(data_); } - if (status) { + + inline std::size_t size() const { return size_; } + inline const_iterator begin() const { return data_; } + inline const_iterator end() const { return data_ + size_; } + inline bool writeItemClassId() const { return writetemCl_; } + inline const T &operator[](const std::size_t index) const { return data_[index]; } + inline T &operator[](const std::size_t index) { return (const_cast(data_))[index]; } + inline T &at(const std::size_t index) { + if (index >= size_) + throw gs::IOOutOfRange("gs::ArrayAdaptor::at: index out of range"); + return (const_cast(data_))[index]; + } + + private: + ArrayAdaptor() = delete; + + const T *data_; + std::size_t size_; + bool writetemCl_; + }; + + template + struct IOIsContiguous> { + enum { value = 1 }; + }; + + template + struct IOIsContiguous> { + enum { value = 1 }; + }; + + template + struct IOIsContiguous> { + enum { value = 1 }; + }; + + template + struct IOIsContiguous> { + enum { value = 1 }; + }; + + template + struct InsertContainerItem> { + typedef ArrayAdaptor A; + static inline void insert(A &obj, const typename A::value_type &item, const std::size_t itemNumber) { + obj.at(itemNumber) = item; + } + }; + + template + struct InsertContainerItem> { + typedef ArrayAdaptor A; + static inline void insert(A &obj, const typename A::value_type &item, const std::size_t itemNumber) { + obj.at(itemNumber) = item; + } + }; + + // Ignore array size I/O. The size is provided in the constructor. + // Of course, it still has to be written somewhere, but that code + // is external w.r.t. the array adaptor. + template + struct GenericWriter, InContainerSize> { + inline static bool process(std::size_t, Stream &os, State *, const bool processClassId) { return true; } + }; + + template + struct GenericReader, InContainerSize> { + inline static bool process(std::size_t, Stream &os, State *, const bool processClassId) { return true; } + }; + + template + struct GenericWriter, InPODArray> { + inline static bool process(const ArrayAdaptor &a, Stream &os, State *, bool) { + const std::size_t len = a.size(); + if (len) + write_pod_array(os, &a[0], len); + return !os.fail(); + } + }; + + template + struct GenericReader, InPODArray> { + inline static bool process(ArrayAdaptor &a, Stream &s, State *, bool) { + const std::size_t len = a.size(); + if (len) + read_pod_array(s, &a[0], len); + return !s.fail(); + } + }; + + template + struct GenericWriter, InContainerHeader> { + typedef ArrayAdaptor Container; + + inline static bool process(const Container &c, Stream &os, State *, const bool processClassId) { + bool status = processClassId ? ClassId::makeId().write(os) : true; + if (status && !(IOTraits::IsPOD && IOTraits::IsContiguous) && c.writeItemClassId()) + status = ClassId::makeId().write(os); + return status; + } + }; + + template + struct GenericReader, InContainerHeader> { + typedef ArrayAdaptor Container; + + inline static bool process(Container &a, Stream &is, State *state, const bool processClassId) { + bool status = true; + if (processClassId) { + ClassId id(is, 1); + const ClassId ¤t = ClassId::makeId(); + status = (id.name() == current.name()); + } + if (status) { + if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) + if (a.writeItemClassId()) { + ClassId id(is, 1); + state->push_back(id); + } + } + return status; + } + }; + + template + struct GenericReader, InContainerFooter> { + typedef ArrayAdaptor Container; + + inline static bool process(Container &a, Stream &, State *state, bool) { if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) - if (a.writeItemClassId()) { - ClassId id(is, 1); - state->push_back(id); - } + if (a.writeItemClassId()) + state->pop_back(); + return true; } - return status; - } -}; - -template -struct GenericReader, InContainerFooter> { - typedef ArrayAdaptor Container; - - inline static bool process(Container &a, Stream &, State *state, bool) { - if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) - if (a.writeItemClassId()) - state->pop_back(); - return true; - } -}; -} // namespace gs + }; +} // namespace gs gs_specialize_template_id_T(gs::ArrayAdaptor, 0, 1) -#endif // GENERS_ARRAYADAPTOR_HH_ +#endif // GENERS_ARRAYADAPTOR_HH_ diff --git a/Alignment/Geners/interface/BZ2Handle.hh b/Alignment/Geners/interface/BZ2Handle.hh index 75ec6622e76d6..9b5333bf54d4d 100644 --- a/Alignment/Geners/interface/BZ2Handle.hh +++ b/Alignment/Geners/interface/BZ2Handle.hh @@ -12,31 +12,31 @@ // is performed, and having it on the stack saves a bit of time. namespace gs { -class BZ2InflateHandle { -public: - explicit BZ2InflateHandle(bz_stream &strm); - ~BZ2InflateHandle(); - -private: - BZ2InflateHandle() = delete; - BZ2InflateHandle(const BZ2InflateHandle &) = delete; - BZ2InflateHandle &operator=(const BZ2InflateHandle &) = delete; - - bz_stream *strm_; -}; - -class BZ2DeflateHandle { -public: - explicit BZ2DeflateHandle(bz_stream &strm); - ~BZ2DeflateHandle(); - -private: - BZ2DeflateHandle() = delete; - BZ2DeflateHandle(const BZ2DeflateHandle &) = delete; - BZ2DeflateHandle &operator=(const BZ2DeflateHandle &) = delete; - - bz_stream *strm_; -}; -} // namespace gs - -#endif // GENERS_BZ2HANDLE_HH_ + class BZ2InflateHandle { + public: + explicit BZ2InflateHandle(bz_stream &strm); + ~BZ2InflateHandle(); + + private: + BZ2InflateHandle() = delete; + BZ2InflateHandle(const BZ2InflateHandle &) = delete; + BZ2InflateHandle &operator=(const BZ2InflateHandle &) = delete; + + bz_stream *strm_; + }; + + class BZ2DeflateHandle { + public: + explicit BZ2DeflateHandle(bz_stream &strm); + ~BZ2DeflateHandle(); + + private: + BZ2DeflateHandle() = delete; + BZ2DeflateHandle(const BZ2DeflateHandle &) = delete; + BZ2DeflateHandle &operator=(const BZ2DeflateHandle &) = delete; + + bz_stream *strm_; + }; +} // namespace gs + +#endif // GENERS_BZ2HANDLE_HH_ diff --git a/Alignment/Geners/interface/BinaryArchiveBase.hh b/Alignment/Geners/interface/BinaryArchiveBase.hh index 0e36513c4a120..b4169af649980 100644 --- a/Alignment/Geners/interface/BinaryArchiveBase.hh +++ b/Alignment/Geners/interface/BinaryArchiveBase.hh @@ -9,226 +9,205 @@ #include "Alignment/Geners/interface/CStringStream.hh" namespace gs { -class BinaryArchiveBase : public AbsArchive { -public: - // The "mode" argument is a string which can have one or more - // sections, separated by ":". The first section has the same - // meaning as in the "fopen" call (see "man 3 fopen"). Additional - // sections can specify other aspects of the archive behavior - // using the format "option=value" if the default settings are - // not suitable. The available options are: - // - // "z" -- compression type. Possible option values are - // "n" -- no compression (default) - // "z" -- compress with zlib - // "b" -- compress with bzlib2 - // - // "cl" -- compression level (an integer between -1 and 9, - // -1 is default. Meanigful for zlib compression - // only. See zlib documentation for details. - // - // "cb" -- compression buffer size in bytes (unsigned integer). - // Default is 1 MB. - // - // "cm" -- minimum object size in bytes to compress (unsigned - // integer). Objects whose serialized size is below - // this limit are not compressed. Default is 1 KB. - // - // "cat" -- if the value is set to "i" (which means "internal" - // or "injected"), the catalog data will be injected - // into the data stream in addition to having it in - // a separate catalog file. This allows for catalog - // recovery from the data stream in cases of program - // failure but also increases the data file size. - // The default value of this option is "s" which means - // that the catalog data will be stored separately. - // This option is meaningful for new archives only, - // for existing archives the value of this option is - // taken from the archive header record. - // - // Example: "w+:z=z:cl=9:cm=2048:cat=s". This will compress - // objects with 2 KB or larger size using level 9 zlib compression - // (the best compression ratio possible in zlib which is also - // the slowest). The archive will be open for reading and writing. - // If an archive with the same name already exists, it will be - // overwritten. The catalog will be stored in a separate file - // created when the archive is closed, catalog recovery from the - // data file(s) in case of a catastrophic program failure will not - // be possible. - // - BinaryArchiveBase(const char *name, const char *mode); - - ~BinaryArchiveBase() override; - - inline bool isOpen() const override { return modeIsValid_ && catalog_; } - - inline bool isReadable() const override { - return modeIsValid_ && catalog_ && (mode_ & std::ios_base::in); - } - - inline bool isWritable() const override { - return modeIsValid_ && catalog_ && (mode_ & std::ios_base::out); - } - - // Error message produced in case the archive could not be opened - inline std::string error() const override { - return errorStream_ ? errorStream_->str() : std::string(""); - } - - // Check whether the constructor "mode" argument was valid. - // If it was not, derived classes should behave as if the - // archive could not be opened. - inline bool modeValid() const { return modeIsValid_; } - - inline unsigned long long size() const override { - return catalog_ ? catalog_->size() : 0ULL; - } - - inline unsigned long long smallestId() const override { - return catalog_ ? catalog_->smallestId() : 0ULL; - } - - inline unsigned long long largestId() const override { - return catalog_ ? catalog_->largestId() : 0ULL; - } - - inline bool idsAreContiguous() const override { - return catalog_ ? catalog_->isContiguous() : false; - } - - inline bool itemExists(const unsigned long long id) const override { - return catalog_ ? catalog_->itemExists(id) : false; - } - - void itemSearch(const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern, - std::vector *idsFound) const override; - - inline CPP11_shared_ptr - catalogEntry(const unsigned long long id) override { - return catalog_ ? catalog_->retrieveEntry(id) - : CPP11_shared_ptr( - (const CatalogEntry *)nullptr); - } - - // Inspection methods for compression options - inline CStringStream::CompressionMode compressionMode() const { - return cStream_->compressionMode(); - } - - inline std::size_t compressionBufferSize() const { - return cStream_->bufferSize(); - } - - inline int compressionLevel() const { return cStream_->compressionLevel(); } - - inline unsigned minSizeToCompress() const { - return cStream_->minSizeToCompress(); - } - - // Inject metadata into the data stream when writing? If this - // method returns "true", we either had "cat=i" in the opening - // mode for a new archive or a corresponding flag was set in - // the header of an existing archive data file. - inline bool injectMetadata() const { return addCatalogToData_; } - - // The following method moves the "get pointer" of the stream - // to the end of file as a side effect - static bool isEmptyFile(std::fstream &s); - - // The following method converts the first section of the "mode" - // argument into std::ios_base::openmode - static std::ios_base::openmode parseMode(const char *mode); - -protected: - inline AbsCatalog *catalog() const { return catalog_; } - - // Non-null catalog must be set exactly once. This object will - // assume the catalog ownership. Null catalog can be set after - // non-null in case some essential operation on the catalog has - // failed (such as writing it to file) in order to indicate - // failure to open the archive. - void setCatalog(AbsCatalog *c); - - // Set compression mode (can be used when the catalog is read). - // The argment must be consistent with one of the modes defined - // in the CStringStream.hh header. - inline void setCompressionMode(const unsigned cMode) { - cStream_->setCompressionMode( - static_cast(cMode)); - } - - // Stream for error messages. To be used from constructors - // of derived classes in case of problems, to indicate the - // reason why the archive could not be opened. - inline std::ostringstream &errorStream() { - if (!errorStream_) - errorStream_ = new std::ostringstream(); - return *errorStream_; - } - - // The following method opens a binary archive. It makes sure - // that a proper header is written out in case an empty file - // is open or in case the file is truncated, and that the header - // is there when a non-empty file is open without truncation. - // If the argument fstream is open when this method is invoked, - // it is closed first. After invocation of this method, the - // "injectMetadata()" flag will be properly set up for the - // data file open last. If the method is not successful, it - // closes the stream and throws an exception inherited from - // "IOException". - // - void openDataFile(std::fstream &stream, const char *filename); - - // Stream mode used to open the archive data file(s) - inline std::ios_base::openmode openmode() const { return mode_; } - - // Info needed for catalog recovery. These methods will return - // null pointers if item metadata is not in the data stream. - const ClassId *catalogEntryClassId() const { return storedEntryId_; } - const ClassId *itemLocationClassId() const { return storedLocationId_; } - -private: - BinaryArchiveBase() = delete; - BinaryArchiveBase(const BinaryArchiveBase &) = delete; - BinaryArchiveBase &operator=(const BinaryArchiveBase &) = delete; - - static bool parseArchiveOptions(std::ostringstream &errmes, const char *mode, - CStringStream::CompressionMode *m, - int *compressionLevel, - unsigned *minSizeToCompress, - unsigned *bufSize, bool *multiplexCatalog); - - void writeHeader(std::ostream &os); - - // The following method returns "true" if a correctly - // formatted header was found - bool readHeader(std::istream &is); - - void search(AbsReference &reference) override; - - // The derived classes must override the following two methods - virtual std::ostream &plainOutputStream() = 0; - virtual std::istream &plainInputStream(unsigned long long id, - unsigned *compressionCode, - unsigned long long *length) = 0; - - std::istream &inputStream(unsigned long long id, long long *sz) override; - std::ostream &outputStream() override; - std::ostream &compressedStream(std::ostream &uncompressed) override; - unsigned flushCompressedRecord(std::ostream &compressed) override; - void releaseClassIds(); - - const std::ios_base::openmode mode_; - std::ostringstream *errorStream_; - CStringStream *cStream_; - AbsCatalog *catalog_; - ClassId *storedEntryId_; - ClassId *storedLocationId_; - bool catalogIsSet_; - bool modeIsValid_; - bool addCatalogToData_; -}; -} // namespace gs - -#endif // GENERS_BINARYARCHIVEBASE_HH_ + class BinaryArchiveBase : public AbsArchive { + public: + // The "mode" argument is a string which can have one or more + // sections, separated by ":". The first section has the same + // meaning as in the "fopen" call (see "man 3 fopen"). Additional + // sections can specify other aspects of the archive behavior + // using the format "option=value" if the default settings are + // not suitable. The available options are: + // + // "z" -- compression type. Possible option values are + // "n" -- no compression (default) + // "z" -- compress with zlib + // "b" -- compress with bzlib2 + // + // "cl" -- compression level (an integer between -1 and 9, + // -1 is default. Meanigful for zlib compression + // only. See zlib documentation for details. + // + // "cb" -- compression buffer size in bytes (unsigned integer). + // Default is 1 MB. + // + // "cm" -- minimum object size in bytes to compress (unsigned + // integer). Objects whose serialized size is below + // this limit are not compressed. Default is 1 KB. + // + // "cat" -- if the value is set to "i" (which means "internal" + // or "injected"), the catalog data will be injected + // into the data stream in addition to having it in + // a separate catalog file. This allows for catalog + // recovery from the data stream in cases of program + // failure but also increases the data file size. + // The default value of this option is "s" which means + // that the catalog data will be stored separately. + // This option is meaningful for new archives only, + // for existing archives the value of this option is + // taken from the archive header record. + // + // Example: "w+:z=z:cl=9:cm=2048:cat=s". This will compress + // objects with 2 KB or larger size using level 9 zlib compression + // (the best compression ratio possible in zlib which is also + // the slowest). The archive will be open for reading and writing. + // If an archive with the same name already exists, it will be + // overwritten. The catalog will be stored in a separate file + // created when the archive is closed, catalog recovery from the + // data file(s) in case of a catastrophic program failure will not + // be possible. + // + BinaryArchiveBase(const char *name, const char *mode); + + ~BinaryArchiveBase() override; + + inline bool isOpen() const override { return modeIsValid_ && catalog_; } + + inline bool isReadable() const override { return modeIsValid_ && catalog_ && (mode_ & std::ios_base::in); } + + inline bool isWritable() const override { return modeIsValid_ && catalog_ && (mode_ & std::ios_base::out); } + + // Error message produced in case the archive could not be opened + inline std::string error() const override { return errorStream_ ? errorStream_->str() : std::string(""); } + + // Check whether the constructor "mode" argument was valid. + // If it was not, derived classes should behave as if the + // archive could not be opened. + inline bool modeValid() const { return modeIsValid_; } + + inline unsigned long long size() const override { return catalog_ ? catalog_->size() : 0ULL; } + + inline unsigned long long smallestId() const override { return catalog_ ? catalog_->smallestId() : 0ULL; } + + inline unsigned long long largestId() const override { return catalog_ ? catalog_->largestId() : 0ULL; } + + inline bool idsAreContiguous() const override { return catalog_ ? catalog_->isContiguous() : false; } + + inline bool itemExists(const unsigned long long id) const override { + return catalog_ ? catalog_->itemExists(id) : false; + } + + void itemSearch(const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern, + std::vector *idsFound) const override; + + inline CPP11_shared_ptr catalogEntry(const unsigned long long id) override { + return catalog_ ? catalog_->retrieveEntry(id) + : CPP11_shared_ptr((const CatalogEntry *)nullptr); + } + + // Inspection methods for compression options + inline CStringStream::CompressionMode compressionMode() const { return cStream_->compressionMode(); } + + inline std::size_t compressionBufferSize() const { return cStream_->bufferSize(); } + + inline int compressionLevel() const { return cStream_->compressionLevel(); } + + inline unsigned minSizeToCompress() const { return cStream_->minSizeToCompress(); } + + // Inject metadata into the data stream when writing? If this + // method returns "true", we either had "cat=i" in the opening + // mode for a new archive or a corresponding flag was set in + // the header of an existing archive data file. + inline bool injectMetadata() const { return addCatalogToData_; } + + // The following method moves the "get pointer" of the stream + // to the end of file as a side effect + static bool isEmptyFile(std::fstream &s); + + // The following method converts the first section of the "mode" + // argument into std::ios_base::openmode + static std::ios_base::openmode parseMode(const char *mode); + + protected: + inline AbsCatalog *catalog() const { return catalog_; } + + // Non-null catalog must be set exactly once. This object will + // assume the catalog ownership. Null catalog can be set after + // non-null in case some essential operation on the catalog has + // failed (such as writing it to file) in order to indicate + // failure to open the archive. + void setCatalog(AbsCatalog *c); + + // Set compression mode (can be used when the catalog is read). + // The argment must be consistent with one of the modes defined + // in the CStringStream.hh header. + inline void setCompressionMode(const unsigned cMode) { + cStream_->setCompressionMode(static_cast(cMode)); + } + + // Stream for error messages. To be used from constructors + // of derived classes in case of problems, to indicate the + // reason why the archive could not be opened. + inline std::ostringstream &errorStream() { + if (!errorStream_) + errorStream_ = new std::ostringstream(); + return *errorStream_; + } + + // The following method opens a binary archive. It makes sure + // that a proper header is written out in case an empty file + // is open or in case the file is truncated, and that the header + // is there when a non-empty file is open without truncation. + // If the argument fstream is open when this method is invoked, + // it is closed first. After invocation of this method, the + // "injectMetadata()" flag will be properly set up for the + // data file open last. If the method is not successful, it + // closes the stream and throws an exception inherited from + // "IOException". + // + void openDataFile(std::fstream &stream, const char *filename); + + // Stream mode used to open the archive data file(s) + inline std::ios_base::openmode openmode() const { return mode_; } + + // Info needed for catalog recovery. These methods will return + // null pointers if item metadata is not in the data stream. + const ClassId *catalogEntryClassId() const { return storedEntryId_; } + const ClassId *itemLocationClassId() const { return storedLocationId_; } + + private: + BinaryArchiveBase() = delete; + BinaryArchiveBase(const BinaryArchiveBase &) = delete; + BinaryArchiveBase &operator=(const BinaryArchiveBase &) = delete; + + static bool parseArchiveOptions(std::ostringstream &errmes, + const char *mode, + CStringStream::CompressionMode *m, + int *compressionLevel, + unsigned *minSizeToCompress, + unsigned *bufSize, + bool *multiplexCatalog); + + void writeHeader(std::ostream &os); + + // The following method returns "true" if a correctly + // formatted header was found + bool readHeader(std::istream &is); + + void search(AbsReference &reference) override; + + // The derived classes must override the following two methods + virtual std::ostream &plainOutputStream() = 0; + virtual std::istream &plainInputStream(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length) = 0; + + std::istream &inputStream(unsigned long long id, long long *sz) override; + std::ostream &outputStream() override; + std::ostream &compressedStream(std::ostream &uncompressed) override; + unsigned flushCompressedRecord(std::ostream &compressed) override; + void releaseClassIds(); + + const std::ios_base::openmode mode_; + std::ostringstream *errorStream_; + CStringStream *cStream_; + AbsCatalog *catalog_; + ClassId *storedEntryId_; + ClassId *storedLocationId_; + bool catalogIsSet_; + bool modeIsValid_; + bool addCatalogToData_; + }; +} // namespace gs + +#endif // GENERS_BINARYARCHIVEBASE_HH_ diff --git a/Alignment/Geners/interface/BinaryFileArchive.hh b/Alignment/Geners/interface/BinaryFileArchive.hh index fb0987078258d..9fa10b0558981 100644 --- a/Alignment/Geners/interface/BinaryFileArchive.hh +++ b/Alignment/Geners/interface/BinaryFileArchive.hh @@ -7,57 +7,58 @@ #include "Alignment/Geners/interface/CatalogIO.hh" namespace gs { -class BinaryFileArchive : public BinaryArchiveBase { -public: - // See the note inside the "BinaryArchiveBase.hh" header - // for the meaning of the "mode" argument - BinaryFileArchive(const char *basename, const char *mode, - const char *annotation = nullptr, - unsigned dataFileBufferSize = 1048576U, - unsigned catalogFileBufferSize = 131072U); - ~BinaryFileArchive() override; - - void flush() override; - -private: - void writeCatalog(); - void releaseBuffers(); - - template void readCatalog() { - assert(!catalog()); - unsigned compressionMode; - setCatalog(readBinaryCatalog(catStream_, &compressionMode, - &catalogMergeLevel_, - &catalogAnnotations_, true)); - assert(catalog()); - setCompressionMode(compressionMode); - } - - // The following methods have to be overriden from the base - std::ostream &plainOutputStream() override; - std::istream &plainInputStream(unsigned long long id, - unsigned *compressionCode, - unsigned long long *length) override; - - unsigned long long addToCatalog(const AbsRecord &record, - unsigned compressionCode, - unsigned long long itemLength) override; - - char *filebuf_; - char *catabuf_; - std::string annotation_; - std::string dataFileName_; - std::string catalogFileName_; - std::string dataFileURI_; - std::fstream dataStream_; - std::fstream catStream_; - std::streampos lastpos_; - std::streampos jumppos_; - std::vector catalogAnnotations_; - unsigned catalogMergeLevel_; - bool annotationsMerged_; - bool streamFlushed_; -}; -} // namespace gs - -#endif // GENERS_BINARYFILEARCHIVE_HH_ + class BinaryFileArchive : public BinaryArchiveBase { + public: + // See the note inside the "BinaryArchiveBase.hh" header + // for the meaning of the "mode" argument + BinaryFileArchive(const char *basename, + const char *mode, + const char *annotation = nullptr, + unsigned dataFileBufferSize = 1048576U, + unsigned catalogFileBufferSize = 131072U); + ~BinaryFileArchive() override; + + void flush() override; + + private: + void writeCatalog(); + void releaseBuffers(); + + template + void readCatalog() { + assert(!catalog()); + unsigned compressionMode; + setCatalog( + readBinaryCatalog(catStream_, &compressionMode, &catalogMergeLevel_, &catalogAnnotations_, true)); + assert(catalog()); + setCompressionMode(compressionMode); + } + + // The following methods have to be overriden from the base + std::ostream &plainOutputStream() override; + std::istream &plainInputStream(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length) override; + + unsigned long long addToCatalog(const AbsRecord &record, + unsigned compressionCode, + unsigned long long itemLength) override; + + char *filebuf_; + char *catabuf_; + std::string annotation_; + std::string dataFileName_; + std::string catalogFileName_; + std::string dataFileURI_; + std::fstream dataStream_; + std::fstream catStream_; + std::streampos lastpos_; + std::streampos jumppos_; + std::vector catalogAnnotations_; + unsigned catalogMergeLevel_; + bool annotationsMerged_; + bool streamFlushed_; + }; +} // namespace gs + +#endif // GENERS_BINARYFILEARCHIVE_HH_ diff --git a/Alignment/Geners/interface/CPP11_auto_ptr.hh b/Alignment/Geners/interface/CPP11_auto_ptr.hh index 358990f989343..1de84b424a6b1 100644 --- a/Alignment/Geners/interface/CPP11_auto_ptr.hh +++ b/Alignment/Geners/interface/CPP11_auto_ptr.hh @@ -11,4 +11,4 @@ #define CPP11_auto_ptr std::auto_ptr #endif -#endif // GENERS_CPP11_AUTO_PTR_HH_ +#endif // GENERS_CPP11_AUTO_PTR_HH_ diff --git a/Alignment/Geners/interface/CPP11_config.hh b/Alignment/Geners/interface/CPP11_config.hh index 9133f91351699..f3e0ae462b695 100644 --- a/Alignment/Geners/interface/CPP11_config.hh +++ b/Alignment/Geners/interface/CPP11_config.hh @@ -5,4 +5,4 @@ #define CPP11_STD_AVAILABLE #endif -#endif // GENERS_CPP11_CONFIG_HH_ +#endif // GENERS_CPP11_CONFIG_HH_ diff --git a/Alignment/Geners/interface/CPP11_shared_ptr.hh b/Alignment/Geners/interface/CPP11_shared_ptr.hh index c37c51de27b2a..cc80ba4422ab0 100644 --- a/Alignment/Geners/interface/CPP11_shared_ptr.hh +++ b/Alignment/Geners/interface/CPP11_shared_ptr.hh @@ -11,4 +11,4 @@ #define CPP11_shared_ptr std::tr1::shared_ptr #endif -#endif // GENERS_CPP11_SHARED_PTR_HH_ +#endif // GENERS_CPP11_SHARED_PTR_HH_ diff --git a/Alignment/Geners/interface/CPP11_type_traits.hh b/Alignment/Geners/interface/CPP11_type_traits.hh index 982a6342f1edd..259b6d994fc86 100644 --- a/Alignment/Geners/interface/CPP11_type_traits.hh +++ b/Alignment/Geners/interface/CPP11_type_traits.hh @@ -13,4 +13,4 @@ #define CPP11_is_pointer std::tr1::is_pointer #endif -#endif // GENERS_CPP11_TYPE_TRAITS_HH_ +#endif // GENERS_CPP11_TYPE_TRAITS_HH_ diff --git a/Alignment/Geners/interface/CStringBuf.hh b/Alignment/Geners/interface/CStringBuf.hh index 61cfb54f64561..793bd1b9a5bb5 100644 --- a/Alignment/Geners/interface/CStringBuf.hh +++ b/Alignment/Geners/interface/CStringBuf.hh @@ -4,19 +4,17 @@ #include namespace gs { -class CStringBuf : public std::stringbuf { -public: - explicit CStringBuf(std::ios_base::openmode mode = std::ios_base::in | - std::ios_base::out) - : std::stringbuf(mode) {} + class CStringBuf : public std::stringbuf { + public: + explicit CStringBuf(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::stringbuf(mode) {} - const char *getGetBuffer(unsigned long long *len) const; - const char *getPutBuffer(unsigned long long *len) const; + const char *getGetBuffer(unsigned long long *len) const; + const char *getPutBuffer(unsigned long long *len) const; -private: - CStringBuf(const CStringBuf &) = delete; - CStringBuf &operator=(const CStringBuf &) = delete; -}; -} // namespace gs + private: + CStringBuf(const CStringBuf &) = delete; + CStringBuf &operator=(const CStringBuf &) = delete; + }; +} // namespace gs -#endif // GENERS_CSTRINGBUF_HH_ +#endif // GENERS_CSTRINGBUF_HH_ diff --git a/Alignment/Geners/interface/CStringStream.hh b/Alignment/Geners/interface/CStringStream.hh index d73e53c3d4121..f43826f439c8d 100644 --- a/Alignment/Geners/interface/CStringStream.hh +++ b/Alignment/Geners/interface/CStringStream.hh @@ -23,65 +23,62 @@ #include "Alignment/Geners/interface/ZlibHandle.hh" namespace gs { -class CStringStream : public std::basic_iostream { -public: - enum CompressionMode { NOT_COMPRESSED = 0, ZLIB, BZIP2 }; - - CStringStream(CompressionMode m, int compressionLevel, - unsigned minSizeToCompress, unsigned bufSize); - - // Basic inspectors - inline CompressionMode compressionMode() const { return mode_; } - inline int compressionLevel() const { return compressionLevel_; } - inline unsigned minSizeToCompress() const { return minSizeToCompress_; } - inline std::size_t bufferSize() const { return comprBuf_.size(); } - - // "setCompressionMode" calls "reset" internally. - // All unprocessed data will be lost. - void setCompressionMode(CompressionMode m); - - // The sink must be set before calling "writeCompressed". - // This is where the compressed data will be dumped. - inline void setSink(std::ostream &os) { sink_ = &os; } - - // "writeCompressed" compresses the content of this stream - // and dumps them to sink. The write pointer is repositioned - // at the beginning of the stream. The compression mode is - // returned (always NOT_COMPRESSED if the amount of data - // was below "minSizeToCompress"). - CompressionMode writeCompressed(); - - // Fill this stream from compressed data. Could be called - // repetitively. Uncompressed data is appended at the end - // (internal pointers are not reset). - void readCompressed(std::istream &in, unsigned compressionCode, - unsigned long long len); - - // Reposition both read and write pointers of the stream - // at the beginning of the stream - void reset(); - - // Parse the compression mode. Returns "true" on success. - static bool getCompressionModeByName(const char *name, CompressionMode *m); - - // String representation of the compression mode - static std::string compressionModeName(CompressionMode m, - bool useShortName = true); - -private: - CStringStream(const CStringStream &) = delete; - CStringStream &operator=(const CStringStream &) = delete; - - CStringBuf buf_; - CompressionMode mode_; - int compressionLevel_; - unsigned minSizeToCompress_; - std::vector comprBuf_; - std::vector readBuf_; - std::ostream *sink_; - CPP11_auto_ptr inflator_; - CPP11_auto_ptr deflator_; -}; -} // namespace gs - -#endif // GENERS_CSTRINGSTREAM_HH_ + class CStringStream : public std::basic_iostream { + public: + enum CompressionMode { NOT_COMPRESSED = 0, ZLIB, BZIP2 }; + + CStringStream(CompressionMode m, int compressionLevel, unsigned minSizeToCompress, unsigned bufSize); + + // Basic inspectors + inline CompressionMode compressionMode() const { return mode_; } + inline int compressionLevel() const { return compressionLevel_; } + inline unsigned minSizeToCompress() const { return minSizeToCompress_; } + inline std::size_t bufferSize() const { return comprBuf_.size(); } + + // "setCompressionMode" calls "reset" internally. + // All unprocessed data will be lost. + void setCompressionMode(CompressionMode m); + + // The sink must be set before calling "writeCompressed". + // This is where the compressed data will be dumped. + inline void setSink(std::ostream &os) { sink_ = &os; } + + // "writeCompressed" compresses the content of this stream + // and dumps them to sink. The write pointer is repositioned + // at the beginning of the stream. The compression mode is + // returned (always NOT_COMPRESSED if the amount of data + // was below "minSizeToCompress"). + CompressionMode writeCompressed(); + + // Fill this stream from compressed data. Could be called + // repetitively. Uncompressed data is appended at the end + // (internal pointers are not reset). + void readCompressed(std::istream &in, unsigned compressionCode, unsigned long long len); + + // Reposition both read and write pointers of the stream + // at the beginning of the stream + void reset(); + + // Parse the compression mode. Returns "true" on success. + static bool getCompressionModeByName(const char *name, CompressionMode *m); + + // String representation of the compression mode + static std::string compressionModeName(CompressionMode m, bool useShortName = true); + + private: + CStringStream(const CStringStream &) = delete; + CStringStream &operator=(const CStringStream &) = delete; + + CStringBuf buf_; + CompressionMode mode_; + int compressionLevel_; + unsigned minSizeToCompress_; + std::vector comprBuf_; + std::vector readBuf_; + std::ostream *sink_; + CPP11_auto_ptr inflator_; + CPP11_auto_ptr deflator_; + }; +} // namespace gs + +#endif // GENERS_CSTRINGSTREAM_HH_ diff --git a/Alignment/Geners/interface/CatalogEntry.hh b/Alignment/Geners/interface/CatalogEntry.hh index 79d173698fb82..a9548dfd5cf07 100644 --- a/Alignment/Geners/interface/CatalogEntry.hh +++ b/Alignment/Geners/interface/CatalogEntry.hh @@ -5,66 +5,68 @@ #include "Alignment/Geners/interface/ItemLocation.hh" namespace gs { -class CatalogEntry : public ItemDescriptor { -public: - // Default constructor returns an invalid entry - CatalogEntry(); + class CatalogEntry : public ItemDescriptor { + public: + // Default constructor returns an invalid entry + CatalogEntry(); - // Use this constructor to build valid entries - CatalogEntry(const ItemDescriptor &descr, unsigned long long id, - unsigned compressionCode, unsigned long long itemLength, - const ItemLocation &location, unsigned long long offset = 0ULL); + // Use this constructor to build valid entries + CatalogEntry(const ItemDescriptor &descr, + unsigned long long id, + unsigned compressionCode, + unsigned long long itemLength, + const ItemLocation &location, + unsigned long long offset = 0ULL); - inline ~CatalogEntry() override {} + inline ~CatalogEntry() override {} - inline unsigned long long id() const { return id_; } - inline unsigned long long offset() const { return offset_; } - inline const ItemLocation &location() const { return location_; } - inline unsigned long long itemLength() const { return len_; } - inline unsigned compressionCode() const { return compressionCode_; } + inline unsigned long long id() const { return id_; } + inline unsigned long long offset() const { return offset_; } + inline const ItemLocation &location() const { return location_; } + inline unsigned long long itemLength() const { return len_; } + inline unsigned compressionCode() const { return compressionCode_; } - inline CatalogEntry &setStreamPosition(std::streampos pos) { - location_.setStreamPosition(pos); - return *this; - } - inline CatalogEntry &setURI(const char *newURI) { - location_.setURI(newURI); - return *this; - } - inline CatalogEntry &setCachedItemURI(const char *newURI) { - location_.setCachedItemURI(newURI); - return *this; - } - inline CatalogEntry &setOffset(const unsigned long long off) { - offset_ = off; - return *this; - } + inline CatalogEntry &setStreamPosition(std::streampos pos) { + location_.setStreamPosition(pos); + return *this; + } + inline CatalogEntry &setURI(const char *newURI) { + location_.setURI(newURI); + return *this; + } + inline CatalogEntry &setCachedItemURI(const char *newURI) { + location_.setCachedItemURI(newURI); + return *this; + } + inline CatalogEntry &setOffset(const unsigned long long off) { + offset_ = off; + return *this; + } - // Dump a simple human-readable representation - bool humanReadable(std::ostream &os) const; + // Dump a simple human-readable representation + bool humanReadable(std::ostream &os) const; - // Methods related to I/O for this record itself - inline virtual ClassId classId() const { return ClassId(*this); } - virtual bool write(std::ostream &of) const; + // Methods related to I/O for this record itself + inline virtual ClassId classId() const { return ClassId(*this); } + virtual bool write(std::ostream &of) const; - static inline const char *classname() { return "gs::CatalogEntry"; } - static inline unsigned version() { return 1; } + static inline const char *classname() { return "gs::CatalogEntry"; } + static inline unsigned version() { return 1; } - // "locId" is the class id for ItemLocation. Should be written - // out by the catalog together with the CatalogEntry class id. - static CatalogEntry *read(const ClassId &id, const ClassId &locId, - std::istream &in); + // "locId" is the class id for ItemLocation. Should be written + // out by the catalog together with the CatalogEntry class id. + static CatalogEntry *read(const ClassId &id, const ClassId &locId, std::istream &in); -protected: - bool isEqual(const ItemDescriptor &) const override; + protected: + bool isEqual(const ItemDescriptor &) const override; -private: - unsigned long long id_; - unsigned long long len_; - unsigned long long offset_; - unsigned compressionCode_; - ItemLocation location_; -}; -} // namespace gs + private: + unsigned long long id_; + unsigned long long len_; + unsigned long long offset_; + unsigned compressionCode_; + ItemLocation location_; + }; +} // namespace gs -#endif // GENERS_CATALOGENTRY_HH_ +#endif // GENERS_CATALOGENTRY_HH_ diff --git a/Alignment/Geners/interface/CatalogIO.hh b/Alignment/Geners/interface/CatalogIO.hh index abc3a805a4371..41ed25a553d5f 100644 --- a/Alignment/Geners/interface/CatalogIO.hh +++ b/Alignment/Geners/interface/CatalogIO.hh @@ -16,40 +16,42 @@ #include "Alignment/Geners/interface/AbsCatalog.hh" namespace gs { -struct CatalogFormat1 { - enum { ID = 713265489 }; -}; - -// In the following, it is assumed that the catalog is stored -// in memory and that it has a stream dedicated to it. The -// function returns "true" on success. -// -// Programs which make new catalogs should set "mergeLevel" to 1. -// Programs which combine existing catalogs should add up the -// merge levels of those catalogs to come up with the "mergeLevel". -// -// "annotations" are arbitrary strings (which should be just combined -// when catalogs are merged). -bool writeBinaryCatalog(std::ostream &os, unsigned compressionCode, - unsigned mergeLevel, - const std::vector &annotations, - const AbsCatalog &catalog, - unsigned formatId = CatalogFormat1::ID); - -// In the following, it is assumed that the Catalog class -// has a "read" function which builds the catalog on the heap. -// The "allowReadingByDifferentClass" parameter specifies -// whether the catalog class is allowed to read something -// written by another catalog class. This function returns NULL -// pointer on failure. Note that the user must call "delete" -// on the returned pointer at some point in the future. -template -Catalog *readBinaryCatalog(std::istream &is, unsigned *compressionCode, - unsigned *mergeLevel, - std::vector *annotations, - bool allowReadingByDifferentClass, - unsigned formatId = CatalogFormat1::ID); -} // namespace gs + struct CatalogFormat1 { + enum { ID = 713265489 }; + }; + + // In the following, it is assumed that the catalog is stored + // in memory and that it has a stream dedicated to it. The + // function returns "true" on success. + // + // Programs which make new catalogs should set "mergeLevel" to 1. + // Programs which combine existing catalogs should add up the + // merge levels of those catalogs to come up with the "mergeLevel". + // + // "annotations" are arbitrary strings (which should be just combined + // when catalogs are merged). + bool writeBinaryCatalog(std::ostream &os, + unsigned compressionCode, + unsigned mergeLevel, + const std::vector &annotations, + const AbsCatalog &catalog, + unsigned formatId = CatalogFormat1::ID); + + // In the following, it is assumed that the Catalog class + // has a "read" function which builds the catalog on the heap. + // The "allowReadingByDifferentClass" parameter specifies + // whether the catalog class is allowed to read something + // written by another catalog class. This function returns NULL + // pointer on failure. Note that the user must call "delete" + // on the returned pointer at some point in the future. + template + Catalog *readBinaryCatalog(std::istream &is, + unsigned *compressionCode, + unsigned *mergeLevel, + std::vector *annotations, + bool allowReadingByDifferentClass, + unsigned formatId = CatalogFormat1::ID); +} // namespace gs #include #include @@ -58,76 +60,77 @@ Catalog *readBinaryCatalog(std::istream &is, unsigned *compressionCode, #include "Alignment/Geners/interface/binaryIO.hh" namespace gs { -template -Catalog *readBinaryCatalog(std::istream &is, unsigned *compressionCode, - unsigned *mergeLevel, - std::vector *annotations, - const bool allowReadingByDifferentClass, - const unsigned expectedformatId) { - assert(compressionCode); - assert(mergeLevel); - assert(annotations); - - is.seekg(0, std::ios_base::beg); - - unsigned formatId = 0, endianness = 0; - unsigned char sizelong = 0; - read_pod(is, &formatId); - read_pod(is, &endianness); - read_pod(is, &sizelong); - - if (is.fail()) - throw IOReadFailure("In gs::readBinaryCatalog: input stream failure"); - - if (endianness != 0x01020304 || formatId != expectedformatId || - sizelong != sizeof(long)) - throw IOInvalidData("In gs::readBinaryCatalog: not \"geners\" " - "binary metafile or incompatible system " - "architecture"); - - read_pod(is, compressionCode); - read_pod(is, mergeLevel); - read_pod_vector(is, annotations); - ClassId id(is, 1); - Catalog *readback = nullptr; - - ClassId catId(ClassId::makeId()); - if (id.name() == catId.name()) - // The reading is done by the same class as the writing. - // Make sure the "read" function gets the correct class version. - readback = Catalog::read(id, is); - else { - if (!allowReadingByDifferentClass) { - std::ostringstream os; - os << "In gs::readBinarCatalog: incompatible " - << "catalog class: written by \"" << id.name() - << "\", but reading is attempted by \"" << catId.name() << '"'; - throw IOInvalidData(os.str()); + template + Catalog *readBinaryCatalog(std::istream &is, + unsigned *compressionCode, + unsigned *mergeLevel, + std::vector *annotations, + const bool allowReadingByDifferentClass, + const unsigned expectedformatId) { + assert(compressionCode); + assert(mergeLevel); + assert(annotations); + + is.seekg(0, std::ios_base::beg); + + unsigned formatId = 0, endianness = 0; + unsigned char sizelong = 0; + read_pod(is, &formatId); + read_pod(is, &endianness); + read_pod(is, &sizelong); + + if (is.fail()) + throw IOReadFailure("In gs::readBinaryCatalog: input stream failure"); + + if (endianness != 0x01020304 || formatId != expectedformatId || sizelong != sizeof(long)) + throw IOInvalidData( + "In gs::readBinaryCatalog: not \"geners\" " + "binary metafile or incompatible system " + "architecture"); + + read_pod(is, compressionCode); + read_pod(is, mergeLevel); + read_pod_vector(is, annotations); + ClassId id(is, 1); + Catalog *readback = nullptr; + + ClassId catId(ClassId::makeId()); + if (id.name() == catId.name()) + // The reading is done by the same class as the writing. + // Make sure the "read" function gets the correct class version. + readback = Catalog::read(id, is); + else { + if (!allowReadingByDifferentClass) { + std::ostringstream os; + os << "In gs::readBinarCatalog: incompatible " + << "catalog class: written by \"" << id.name() << "\", but reading is attempted by \"" << catId.name() + << '"'; + throw IOInvalidData(os.str()); + } + + // The reading is not done by the same class as the writing. + // All bets are off, and it is up to the user to decide whether + // this makes sense. However, to maintain compatibility with + // version 1 archives, we need to pass this version to the + // catalog read function. + if (id.version() == 1) + catId.setVersion(1); + + readback = Catalog::read(catId, is); } - // The reading is not done by the same class as the writing. - // All bets are off, and it is up to the user to decide whether - // this makes sense. However, to maintain compatibility with - // version 1 archives, we need to pass this version to the - // catalog read function. - if (id.version() == 1) - catId.setVersion(1); - - readback = Catalog::read(catId, is); - } + // Catalogs do not necessarily know their size in advance, + // so that they might read until the end of file is encountered. + // However, the eof flag on the stream can result in various + // problems later (for example, in writing to the stream). + // Remove this flag. + if (is.eof() && !is.fail() && !is.bad()) { + is.clear(); + is.seekg(0, std::ios_base::end); + } - // Catalogs do not necessarily know their size in advance, - // so that they might read until the end of file is encountered. - // However, the eof flag on the stream can result in various - // problems later (for example, in writing to the stream). - // Remove this flag. - if (is.eof() && !is.fail() && !is.bad()) { - is.clear(); - is.seekg(0, std::ios_base::end); + return readback; } +} // namespace gs - return readback; -} -} // namespace gs - -#endif // GENERS_CATALOGIO_HH_ +#endif // GENERS_CATALOGIO_HH_ diff --git a/Alignment/Geners/interface/CharBuffer.hh b/Alignment/Geners/interface/CharBuffer.hh index 39041acb3f2e7..84da1a2b9d5c9 100644 --- a/Alignment/Geners/interface/CharBuffer.hh +++ b/Alignment/Geners/interface/CharBuffer.hh @@ -7,25 +7,25 @@ #include "Alignment/Geners/interface/ClassId.hh" namespace gs { -class CharBuffer : public std::basic_iostream { -public: - inline CharBuffer() { this->init(&buf_); } + class CharBuffer : public std::basic_iostream { + public: + inline CharBuffer() { this->init(&buf_); } - unsigned long size() const; + unsigned long size() const; - inline ClassId classId() const { return ClassId(*this); } - bool write(std::ostream &of) const; + inline ClassId classId() const { return ClassId(*this); } + bool write(std::ostream &of) const; - static inline const char *classname() { return "gs::CharBuffer"; } - static inline unsigned version() { return 1; } - static void restore(const ClassId &id, std::istream &in, CharBuffer *buf); + static inline const char *classname() { return "gs::CharBuffer"; } + static inline unsigned version() { return 1; } + static void restore(const ClassId &id, std::istream &in, CharBuffer *buf); - bool operator==(const CharBuffer &r) const; - inline bool operator!=(const CharBuffer &r) const { return !(*this == r); } + bool operator==(const CharBuffer &r) const; + inline bool operator!=(const CharBuffer &r) const { return !(*this == r); } -private: - CStringBuf buf_; -}; -} // namespace gs + private: + CStringBuf buf_; + }; +} // namespace gs -#endif // GENERS_CHARBUFFER_HH_ +#endif // GENERS_CHARBUFFER_HH_ diff --git a/Alignment/Geners/interface/ClassId.hh b/Alignment/Geners/interface/ClassId.hh index 25f744777440a..9ceb182923606 100644 --- a/Alignment/Geners/interface/ClassId.hh +++ b/Alignment/Geners/interface/ClassId.hh @@ -17,218 +17,202 @@ #include namespace gs { -class ClassId { -public: - // Generic constructor using a prefix (which is usually - // a class name) and a version number - inline ClassId(const char *prefix, const unsigned version, - const bool isPtr = false) { - initialize(prefix, version, isPtr); - } + class ClassId { + public: + // Generic constructor using a prefix (which is usually + // a class name) and a version number + inline ClassId(const char *prefix, const unsigned version, const bool isPtr = false) { + initialize(prefix, version, isPtr); + } - // Generic constructor using a prefix (which is usually - // a class name) and a version number - inline ClassId(const std::string &prefix, const unsigned version, - const bool isPtr = false) { - initialize(prefix.c_str(), version, isPtr); - } + // Generic constructor using a prefix (which is usually + // a class name) and a version number + inline ClassId(const std::string &prefix, const unsigned version, const bool isPtr = false) { + initialize(prefix.c_str(), version, isPtr); + } - // Use the following constructor in the "classId()" methods - // of user-developed classes. - // - // Implementation note: it is possible to "specialize" - // this constructor by delegating the actual job to the - // "ClassIdSpecialization". Then we would be able to create - // class ids for built-in and user types in a unified - // way. This, however, would incur a performance hit - // due to the necessity of making another ClassId and - // copying the result into the internals of the new object. - // This performance hit was deemed significant. If you - // need a universal way to create class ids at some - // point in your code, use the "itemId" method instead - // (this may or may not incur a performance hit, depending - // on what exactly the compiler does). - template inline ClassId(const T &) { - initialize(T::classname(), T::version(), false); - } + // Use the following constructor in the "classId()" methods + // of user-developed classes. + // + // Implementation note: it is possible to "specialize" + // this constructor by delegating the actual job to the + // "ClassIdSpecialization". Then we would be able to create + // class ids for built-in and user types in a unified + // way. This, however, would incur a performance hit + // due to the necessity of making another ClassId and + // copying the result into the internals of the new object. + // This performance hit was deemed significant. If you + // need a universal way to create class ids at some + // point in your code, use the "itemId" method instead + // (this may or may not incur a performance hit, depending + // on what exactly the compiler does). + template + inline ClassId(const T &) { + initialize(T::classname(), T::version(), false); + } - // Constructor from the class id represented by a string - explicit ClassId(const std::string &id); - - // Use the following constructor in "read" functions. - // Dummy argument "reading" is needed in order to generate - // a distinct function signature (otherwise the templated - // constructor can win). - ClassId(std::istream &in, int reading); - - // Use the following pseudo-constructor in static "read" - // methods in case a type check is desired. It has to be - // made static because constructor without any arguments - // can not be a template. Also, this is the way to construct - // class ids for built-in types (there is no way to specialize - // member methods). - template static ClassId makeId(); - - // "Universal" item id which also works for built-in types - template static ClassId itemId(const T &); - - // Inspectors for the class name and version number - inline const std::string &name() const { return name_; } - inline unsigned version() const { return version_; } - - // Is this class a pointer for I/O purposes? - inline bool isPointer() const { return isPtr_; } - - // The following function should return a unique class id string - // which takes version number into account - inline const std::string &id() const { return id_; } - - // The following checks if the class name corresponds to - // a template (using the standard manner of class name forming) - bool isTemplate() const; - - // The following function fills the vector with class template - // parameters (if the class is not a template, the vector is - // cleared). Due to the manner in which things are used in this - // package, the result is actually a vector of (vectors of size 1). - void templateParameters(std::vector> *p) const; - - // Function to write this object out. Returns "true" on success. - bool write(std::ostream &of) const; - - // Comparison operators - inline bool operator==(const ClassId &r) const { return id_ == r.id_; } - inline bool operator!=(const ClassId &r) const { return !(*this == r); } - inline bool operator<(const ClassId &r) const { return id_ < r.id_; } - inline bool operator>(const ClassId &r) const { return id_ > r.id_; } - - // Modify the version number - void setVersion(unsigned newVersion); - - // The following methods verify that the id/classname/version - // of this object are equal to those of the argument and throw - // "gs::IOInvalidArgument" exception if this is not so - void ensureSameId(const ClassId &id) const; - void ensureSameName(const ClassId &id) const; - void ensureSameVersion(const ClassId &id) const; - - // The following method ensures that the version number of this - // class id is within certain range [min, max], with both limits - // allowed. "gs::IOInvalidArgument" exception is thrown if this - // is not so. - void ensureVersionInRange(unsigned min, unsigned max) const; - - // Sometimes one really needs to make a placeholder class id... - // This is a dangerous function: the code using ClassId class - // will normally assume that a ClassId object is always in a valid - // state. Invalid class ids can be distinguished by their empty - // class names (i.e., name().empty() returns "true"). - static ClassId invalidId(); - -private: - ClassId(); - - void initialize(const char *prefix, unsigned version, bool isPtr); - bool makeName(); - bool makeVersion(); - - std::string name_; - std::string id_; - unsigned version_; - bool isPtr_; - - // Return "true" if the prefix is valid - static bool validatePrefix(const char *prefix); -}; - -// Simple class id compatibility checkers for use as policy classes -// in templated code -struct SameClassId { - inline static bool compatible(const ClassId &id1, const ClassId &id2) { - return id1.name() == id2.name(); - } -}; + // Constructor from the class id represented by a string + explicit ClassId(const std::string &id); + + // Use the following constructor in "read" functions. + // Dummy argument "reading" is needed in order to generate + // a distinct function signature (otherwise the templated + // constructor can win). + ClassId(std::istream &in, int reading); + + // Use the following pseudo-constructor in static "read" + // methods in case a type check is desired. It has to be + // made static because constructor without any arguments + // can not be a template. Also, this is the way to construct + // class ids for built-in types (there is no way to specialize + // member methods). + template + static ClassId makeId(); + + // "Universal" item id which also works for built-in types + template + static ClassId itemId(const T &); + + // Inspectors for the class name and version number + inline const std::string &name() const { return name_; } + inline unsigned version() const { return version_; } + + // Is this class a pointer for I/O purposes? + inline bool isPointer() const { return isPtr_; } + + // The following function should return a unique class id string + // which takes version number into account + inline const std::string &id() const { return id_; } + + // The following checks if the class name corresponds to + // a template (using the standard manner of class name forming) + bool isTemplate() const; + + // The following function fills the vector with class template + // parameters (if the class is not a template, the vector is + // cleared). Due to the manner in which things are used in this + // package, the result is actually a vector of (vectors of size 1). + void templateParameters(std::vector> *p) const; + + // Function to write this object out. Returns "true" on success. + bool write(std::ostream &of) const; + + // Comparison operators + inline bool operator==(const ClassId &r) const { return id_ == r.id_; } + inline bool operator!=(const ClassId &r) const { return !(*this == r); } + inline bool operator<(const ClassId &r) const { return id_ < r.id_; } + inline bool operator>(const ClassId &r) const { return id_ > r.id_; } + + // Modify the version number + void setVersion(unsigned newVersion); + + // The following methods verify that the id/classname/version + // of this object are equal to those of the argument and throw + // "gs::IOInvalidArgument" exception if this is not so + void ensureSameId(const ClassId &id) const; + void ensureSameName(const ClassId &id) const; + void ensureSameVersion(const ClassId &id) const; + + // The following method ensures that the version number of this + // class id is within certain range [min, max], with both limits + // allowed. "gs::IOInvalidArgument" exception is thrown if this + // is not so. + void ensureVersionInRange(unsigned min, unsigned max) const; + + // Sometimes one really needs to make a placeholder class id... + // This is a dangerous function: the code using ClassId class + // will normally assume that a ClassId object is always in a valid + // state. Invalid class ids can be distinguished by their empty + // class names (i.e., name().empty() returns "true"). + static ClassId invalidId(); + + private: + ClassId(); + + void initialize(const char *prefix, unsigned version, bool isPtr); + bool makeName(); + bool makeVersion(); + + std::string name_; + std::string id_; + unsigned version_; + bool isPtr_; + + // Return "true" if the prefix is valid + static bool validatePrefix(const char *prefix); + }; -struct SameClassName { - inline static bool compatible(const ClassId &id1, const ClassId &id2) { - return id1 == id2; - } -}; - -// Specialize the following template in order to be able to construct -// ClassId for classes which do not implement static functions -// "classname()" and "version()". -template struct ClassIdSpecialization { - inline static ClassId classId(const bool isPtr = false) { - return ClassId(T::classname(), T::version(), isPtr); - } -}; + // Simple class id compatibility checkers for use as policy classes + // in templated code + struct SameClassId { + inline static bool compatible(const ClassId &id1, const ClassId &id2) { return id1.name() == id2.name(); } + }; -// Utility functions for naming template classes. The "nInclude" -// argument tells us how many template parameters to include into -// the generated template name. For example, use of -// -// template_class_name("myTemplate",1) -// -// will generate a class name which looks like myTemplate, with -// second template parameter omitted. While the result is equivalent -// to invoking "template_class_name("myTemplate")", having an -// explicit limit is convenient for use from certain higher-level -// functions. Note, however, that in the call with two template -// parameters the class id specialization for Y must be available, -// even though it is not used. -// -// This feature is sometimes helpful when certain template parameters -// specify aspects of template behavior which have nothing to do -// with object data contents and I/O. Typical example of such -// a parameter is std::allocator of STL -- changing this to a custom -// allocator will not affect serialized representation of an STL -// container. -// -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 1); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 1); -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 2); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 2); -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 3); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 3); -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 4); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 4); -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 5); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 5); -template -std::string template_class_name(const char *templateName, - unsigned nInclude = 6); -template -std::string template_class_name(const std::string &templateName, - unsigned nInclude = 6); - -// Utility functions for naming stack-based containers such as std::array -template -std::string stack_container_name(const char *templateName); - -template -std::string stack_container_name(const std::string &templateName); -} // namespace gs + struct SameClassName { + inline static bool compatible(const ClassId &id1, const ClassId &id2) { return id1 == id2; } + }; + + // Specialize the following template in order to be able to construct + // ClassId for classes which do not implement static functions + // "classname()" and "version()". + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool isPtr = false) { return ClassId(T::classname(), T::version(), isPtr); } + }; + + // Utility functions for naming template classes. The "nInclude" + // argument tells us how many template parameters to include into + // the generated template name. For example, use of + // + // template_class_name("myTemplate",1) + // + // will generate a class name which looks like myTemplate, with + // second template parameter omitted. While the result is equivalent + // to invoking "template_class_name("myTemplate")", having an + // explicit limit is convenient for use from certain higher-level + // functions. Note, however, that in the call with two template + // parameters the class id specialization for Y must be available, + // even though it is not used. + // + // This feature is sometimes helpful when certain template parameters + // specify aspects of template behavior which have nothing to do + // with object data contents and I/O. Typical example of such + // a parameter is std::allocator of STL -- changing this to a custom + // allocator will not affect serialized representation of an STL + // container. + // + template + std::string template_class_name(const char *templateName, unsigned nInclude = 1); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 1); + template + std::string template_class_name(const char *templateName, unsigned nInclude = 2); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 2); + template + std::string template_class_name(const char *templateName, unsigned nInclude = 3); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 3); + template + std::string template_class_name(const char *templateName, unsigned nInclude = 4); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 4); + template + std::string template_class_name(const char *templateName, unsigned nInclude = 5); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 5); + template + std::string template_class_name(const char *templateName, unsigned nInclude = 6); + template + std::string template_class_name(const std::string &templateName, unsigned nInclude = 6); + + // Utility functions for naming stack-based containers such as std::array + template + std::string stack_container_name(const char *templateName); + + template + std::string stack_container_name(const std::string &templateName); +} // namespace gs #include #include @@ -246,566 +230,517 @@ std::string stack_container_name(const std::string &templateName); // Specializations of "ClassIdSpecialization" for built-in classes. // They all look the same, so we want to use a macro -#define gs_specialize_class_helper(qualifyer, name, version) /**/ \ - template <> struct ClassIdSpecialization { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(#name, version, isPtr); \ - } \ +#define gs_specialize_class_helper(qualifyer, name, version) /**/ \ + template <> \ + struct ClassIdSpecialization { \ + inline static ClassId classId(const bool isPtr = false) { return ClassId(#name, version, isPtr); } \ }; -#define gs_specialize_class_id(name, version) /**/ \ - namespace gs { \ - gs_specialize_class_helper(GENERS_EMPTY_TYPE_QUALIFYER_, name, version) \ - gs_specialize_class_helper(const, name, version) \ - gs_specialize_class_helper(volatile, name, version) \ - gs_specialize_class_helper(const volatile, name, version) \ +#define gs_specialize_class_id(name, version) /**/ \ + namespace gs { \ + gs_specialize_class_helper(GENERS_EMPTY_TYPE_QUALIFYER_, name, version) \ + gs_specialize_class_helper(const, name, version) gs_specialize_class_helper(volatile, name, version) \ + gs_specialize_class_helper(const volatile, name, version) \ } // Specializations of "ClassIdSpecialization" for single-argument templates -#define gs_specialize_template_help_T(qualifyer, name, version, MAX) /**/ \ - template struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), version, isPtr); \ - } \ +#define gs_specialize_template_help_T(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_T(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_help_T(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, \ - MAX) \ - gs_specialize_template_help_T(const, name, version, MAX) \ - gs_specialize_template_help_T(volatile, name, version, MAX) \ - gs_specialize_template_help_T(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_T(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_help_T(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_help_T(const, name, version, MAX) \ + gs_specialize_template_help_T(volatile, name, version, MAX) \ + gs_specialize_template_help_T(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for two-argument templates -#define gs_specialize_template_help_TT(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), version, isPtr); \ - } \ +#define gs_specialize_template_help_TT(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TT(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_help_TT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, \ - MAX) \ - gs_specialize_template_help_TT(const, name, version, MAX) \ - gs_specialize_template_help_TT(volatile, name, version, MAX) \ - gs_specialize_template_help_TT(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TT(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_help_TT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_help_TT(const, name, version, MAX) \ + gs_specialize_template_help_TT(volatile, name, version, MAX) \ + gs_specialize_template_help_TT(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for three-argument templates -#define gs_specialize_template_help_TTT(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), version, \ - isPtr); \ - } \ +#define gs_specialize_template_help_TTT(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TTT(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_help_TTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, \ - MAX) \ - gs_specialize_template_help_TTT(const, name, version, MAX) \ - gs_specialize_template_help_TTT(volatile, name, version, MAX) \ - gs_specialize_template_help_TTT(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TTT(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_help_TTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_help_TTT(const, name, version, MAX) \ + gs_specialize_template_help_TTT(volatile, name, version, MAX) \ + gs_specialize_template_help_TTT(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for four-argument templates -#define gs_specialize_template_help_TTTT(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), version, \ - isPtr); \ - } \ +#define gs_specialize_template_help_TTTT(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TTTT(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_help_TTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, \ - version, MAX) \ - gs_specialize_template_help_TTTT(const, name, version, MAX) \ - gs_specialize_template_help_TTTT(volatile, name, version, MAX) \ - gs_specialize_template_help_TTTT(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TTTT(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_help_TTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_help_TTTT(const, name, version, MAX) \ + gs_specialize_template_help_TTTT(volatile, name, version, MAX) \ + gs_specialize_template_help_TTTT(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for five-argument templates -#define gs_specialize_template_hlp_TTTTT(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), version, \ - isPtr); \ - } \ +#define gs_specialize_template_hlp_TTTTT(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TTTTT(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_hlp_TTTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, \ - version, MAX) \ - gs_specialize_template_hlp_TTTTT(const, name, version, MAX) \ - gs_specialize_template_hlp_TTTTT(volatile, name, version, MAX) \ - gs_specialize_template_hlp_TTTTT(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TTTTT(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_hlp_TTTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_hlp_TTTTT(const, name, version, MAX) \ + gs_specialize_template_hlp_TTTTT(volatile, name, version, MAX) \ + gs_specialize_template_hlp_TTTTT(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for six-argument templates -#define gs_specialize_template_h_TTTTTT(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(template_class_name(#name, MAX), \ - version, isPtr); \ - } \ +#define gs_specialize_template_h_TTTTTT(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(template_class_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TTTTTT(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_h_TTTTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, \ - MAX) \ - gs_specialize_template_h_TTTTTT(const, name, version, MAX) \ - gs_specialize_template_h_TTTTTT(volatile, name, version, MAX) \ - gs_specialize_template_h_TTTTTT(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TTTTTT(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_h_TTTTTT(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_h_TTTTTT(const, name, version, MAX) \ + gs_specialize_template_h_TTTTTT(volatile, name, version, MAX) \ + gs_specialize_template_h_TTTTTT(const volatile, name, version, MAX) \ } // Specializations of "ClassIdSpecialization" for two-argument templates // which include an integer as a second argument (like std::array) -#define gs_specialize_template_help_TN(qualifyer, name, version, MAX) /**/ \ - template \ - struct ClassIdSpecialization> { \ - inline static ClassId classId(const bool isPtr = false) { \ - return ClassId(stack_container_name(#name, MAX), version, isPtr); \ - } \ +#define gs_specialize_template_help_TN(qualifyer, name, version, MAX) /**/ \ + template \ + struct ClassIdSpecialization> { \ + inline static ClassId classId(const bool isPtr = false) { \ + return ClassId(stack_container_name(#name, MAX), version, isPtr); \ + } \ }; -#define gs_specialize_template_id_TN(name, version, MAX) /**/ \ - namespace gs { \ - gs_specialize_template_help_TN(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, \ - MAX) \ - gs_specialize_template_help_TN(const, name, version, MAX) \ - gs_specialize_template_help_TN(volatile, name, version, MAX) \ - gs_specialize_template_help_TN(const volatile, name, version, \ - MAX) \ +#define gs_specialize_template_id_TN(name, version, MAX) /**/ \ + namespace gs { \ + gs_specialize_template_help_TN(GENERS_EMPTY_TYPE_QUALIFYER_, name, version, MAX) \ + gs_specialize_template_help_TN(const, name, version, MAX) \ + gs_specialize_template_help_TN(volatile, name, version, MAX) \ + gs_specialize_template_help_TN(const volatile, name, version, MAX) \ } namespace gs { -// "template_class_name" implementations -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id(ClassIdSpecialization::classId()); - name += id.id(); - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned nInclude) { - return template_class_name(templateName.c_str(), nInclude); -} - -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id1(ClassIdSpecialization::classId()); - name += id1.id(); - if (nInclude > 1) { - name += ','; - const ClassId &id2(ClassIdSpecialization::classId()); - name += id2.id(); + // "template_class_name" implementations + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id(ClassIdSpecialization::classId()); + name += id.id(); + name += '>'; } - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned nInclude) { - return template_class_name(templateName.c_str(), nInclude); -} - -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id1(ClassIdSpecialization::classId()); - name += id1.id(); - if (nInclude > 1) { - name += ','; - const ClassId &id2(ClassIdSpecialization::classId()); - name += id2.id(); - } - if (nInclude > 2) { - name += ','; - const ClassId &id3(ClassIdSpecialization::classId()); - name += id3.id(); + return name; + } + + template + inline std::string template_class_name(const std::string &templateName, const unsigned nInclude) { + return template_class_name(templateName.c_str(), nInclude); + } + + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id1(ClassIdSpecialization::classId()); + name += id1.id(); + if (nInclude > 1) { + name += ','; + const ClassId &id2(ClassIdSpecialization::classId()); + name += id2.id(); + } + name += '>'; } - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned nInclude) { - return template_class_name(templateName.c_str(), nInclude); -} - -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id1(ClassIdSpecialization::classId()); - name += id1.id(); - if (nInclude > 1) { - name += ','; - const ClassId &id2(ClassIdSpecialization::classId()); - name += id2.id(); + return name; + } + + template + inline std::string template_class_name(const std::string &templateName, const unsigned nInclude) { + return template_class_name(templateName.c_str(), nInclude); + } + + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id1(ClassIdSpecialization::classId()); + name += id1.id(); + if (nInclude > 1) { + name += ','; + const ClassId &id2(ClassIdSpecialization::classId()); + name += id2.id(); + } + if (nInclude > 2) { + name += ','; + const ClassId &id3(ClassIdSpecialization::classId()); + name += id3.id(); + } + name += '>'; } - if (nInclude > 2) { - name += ','; - const ClassId &id3(ClassIdSpecialization::classId()); - name += id3.id(); + return name; + } + + template + inline std::string template_class_name(const std::string &templateName, const unsigned nInclude) { + return template_class_name(templateName.c_str(), nInclude); + } + + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id1(ClassIdSpecialization::classId()); + name += id1.id(); + if (nInclude > 1) { + name += ','; + const ClassId &id2(ClassIdSpecialization::classId()); + name += id2.id(); + } + if (nInclude > 2) { + name += ','; + const ClassId &id3(ClassIdSpecialization::classId()); + name += id3.id(); + } + if (nInclude > 3) { + name += ','; + const ClassId &id4(ClassIdSpecialization::classId()); + name += id4.id(); + } + name += '>'; } - if (nInclude > 3) { - name += ','; - const ClassId &id4(ClassIdSpecialization::classId()); - name += id4.id(); - } - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned n) { - return template_class_name(templateName.c_str(), n); -} - -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id1(ClassIdSpecialization::classId()); - name += id1.id(); - if (nInclude > 1) { - name += ','; - const ClassId &id2(ClassIdSpecialization::classId()); - name += id2.id(); + return name; + } + + template + inline std::string template_class_name(const std::string &templateName, const unsigned n) { + return template_class_name(templateName.c_str(), n); + } + + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id1(ClassIdSpecialization::classId()); + name += id1.id(); + if (nInclude > 1) { + name += ','; + const ClassId &id2(ClassIdSpecialization::classId()); + name += id2.id(); + } + if (nInclude > 2) { + name += ','; + const ClassId &id3(ClassIdSpecialization::classId()); + name += id3.id(); + } + if (nInclude > 3) { + name += ','; + const ClassId &id4(ClassIdSpecialization::classId()); + name += id4.id(); + } + if (nInclude > 4) { + name += ','; + const ClassId &id5(ClassIdSpecialization::classId()); + name += id5.id(); + } + name += '>'; } - if (nInclude > 2) { - name += ','; - const ClassId &id3(ClassIdSpecialization::classId()); - name += id3.id(); + return name; + } + + template + inline std::string template_class_name(const std::string &templateName, const unsigned n) { + return template_class_name(templateName.c_str(), n); + } + + template + std::string template_class_name(const char *templateName, const unsigned nInclude) { + assert(templateName); + std::string name(templateName); + if (nInclude) { + name += '<'; + const ClassId &id1(ClassIdSpecialization::classId()); + name += id1.id(); + if (nInclude > 1) { + name += ','; + const ClassId &id2(ClassIdSpecialization::classId()); + name += id2.id(); + } + if (nInclude > 2) { + name += ','; + const ClassId &id3(ClassIdSpecialization::classId()); + name += id3.id(); + } + if (nInclude > 3) { + name += ','; + const ClassId &id4(ClassIdSpecialization::classId()); + name += id4.id(); + } + if (nInclude > 4) { + name += ','; + const ClassId &id5(ClassIdSpecialization::classId()); + name += id5.id(); + } + if (nInclude > 5) { + name += ','; + const ClassId &id6(ClassIdSpecialization::classId()); + name += id6.id(); + } + name += '>'; } - if (nInclude > 3) { - name += ','; - const ClassId &id4(ClassIdSpecialization::classId()); - name += id4.id(); - } - if (nInclude > 4) { - name += ','; - const ClassId &id5(ClassIdSpecialization::classId()); - name += id5.id(); - } - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned n) { - return template_class_name(templateName.c_str(), n); -} - -template -std::string template_class_name(const char *templateName, - const unsigned nInclude) { - assert(templateName); - std::string name(templateName); - if (nInclude) { - name += '<'; - const ClassId &id1(ClassIdSpecialization::classId()); - name += id1.id(); - if (nInclude > 1) { - name += ','; - const ClassId &id2(ClassIdSpecialization::classId()); - name += id2.id(); - } - if (nInclude > 2) { - name += ','; - const ClassId &id3(ClassIdSpecialization::classId()); - name += id3.id(); - } - if (nInclude > 3) { - name += ','; - const ClassId &id4(ClassIdSpecialization::classId()); - name += id4.id(); - } - if (nInclude > 4) { - name += ','; - const ClassId &id5(ClassIdSpecialization::classId()); - name += id5.id(); - } - if (nInclude > 5) { - name += ','; - const ClassId &id6(ClassIdSpecialization::classId()); - name += id6.id(); - } - name += '>'; - } - return name; -} - -template -inline std::string template_class_name(const std::string &templateName, - const unsigned n) { - return template_class_name(templateName.c_str(), n); -} - -template -std::string stack_container_name(const char *templateName) { - assert(templateName); - const ClassId &id1(ClassIdSpecialization::classId()); - std::ostringstream os; - os << templateName << '<' << id1.id() << ',' << N << "(0)>"; - return os.str(); -} - -template -std::string stack_container_name(const std::string &templateName) { - return stack_container_name(templateName.c_str()); -} - -// Skip references in class ids -template struct ClassIdSpecialization { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); + return name; } -}; -// Skip pointers in class ids -template struct ClassIdSpecialization { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); + template + inline std::string template_class_name(const std::string &templateName, const unsigned n) { + return template_class_name(templateName.c_str(), n); } -}; -template struct ClassIdSpecialization { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); + template + std::string stack_container_name(const char *templateName) { + assert(templateName); + const ClassId &id1(ClassIdSpecialization::classId()); + std::ostringstream os; + os << templateName << '<' << id1.id() << ',' << N << "(0)>"; + return os.str(); } -}; -template struct ClassIdSpecialization { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); + template + std::string stack_container_name(const std::string &templateName) { + return stack_container_name(templateName.c_str()); } -}; -template struct ClassIdSpecialization { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); - } -}; - -// Skip shared pointers in class ids -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); - } -}; - -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); - } -}; - -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); - } -}; - -template -struct ClassIdSpecialization> { - inline static ClassId classId(const bool /* isPtr */ = false) { - return ClassIdSpecialization::classId(true); - } -}; + // Skip references in class ids + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -// Skip IOPtr in class ids and do not turn on the pointer flag -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + // Skip pointers in class ids + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -// Same thing for IOProxy -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + // Skip shared pointers in class ids + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -template struct ClassIdSpecialization> { - inline static ClassId classId(const bool isPtr = false) { - return ClassIdSpecialization::classId(isPtr); - } -}; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization::classId(true); } + }; -// The remaining ClassId static functions -template inline ClassId ClassId::makeId() { - return ClassIdSpecialization::classId(); -} + // Skip IOPtr in class ids and do not turn on the pointer flag + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -namespace Private { -template struct CallClassId { - static inline ClassId get(const T &) { - return ClassIdSpecialization::classId(); - } -}; - -template struct CallClassId { - static inline ClassId get(const T &obj) { return obj.classId(); } -}; - -// The following class will check for the existence of two -// possible signatures of the "classId" method: -// "const ClassId& classId() const" and "ClassId classId() const". -template class TypeHasClassIdHelper { - template struct TypeCheck; - template struct FcnType1 { typedef ClassId (T::*fptr)() const; }; - template struct FcnType2 { - typedef const ClassId &(T::*fptr)() const; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } }; - typedef char Yes; - typedef struct { - char a[2]; - } No; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; - template - static Yes Has1(TypeCheck::fptr, &T::classId> *); - template static No Has1(...); + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; - template - static Yes Has2(TypeCheck::fptr, &T::classId> *); - template static No Has2(...); + // Same thing for IOProxy + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -public: - static const bool value = ((sizeof(Has1(0)) == sizeof(Yes)) || - (sizeof(Has2(0)) == sizeof(Yes))); -}; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -template ::value> struct TypeHasClassId { - static const bool value = false; -}; + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -template struct TypeHasClassId { - static const bool value = TypeHasClassIdHelper::value; -}; -} // namespace Private + template + struct ClassIdSpecialization> { + inline static ClassId classId(const bool isPtr = false) { return ClassIdSpecialization::classId(isPtr); } + }; -template inline ClassId ClassId::itemId(const T &item) { - // Make sure that item is not a pointer. - static_assert((!IOIsAnyPtr::value), - "can not use pointers with this method"); + // The remaining ClassId static functions + template + inline ClassId ClassId::makeId() { + return ClassIdSpecialization::classId(); + } - // If the classId() function is avalable for this item, call it - // (it could be virtual). Otherwise, call the generic method. - return Private::CallClassId::value, T>::get(item); -} -} // namespace gs + namespace Private { + template + struct CallClassId { + static inline ClassId get(const T &) { return ClassIdSpecialization::classId(); } + }; + + template + struct CallClassId { + static inline ClassId get(const T &obj) { return obj.classId(); } + }; + + // The following class will check for the existence of two + // possible signatures of the "classId" method: + // "const ClassId& classId() const" and "ClassId classId() const". + template + class TypeHasClassIdHelper { + template + struct TypeCheck; + template + struct FcnType1 { + typedef ClassId (T::*fptr)() const; + }; + template + struct FcnType2 { + typedef const ClassId &(T::*fptr)() const; + }; + + typedef char Yes; + typedef struct { + char a[2]; + } No; + + template + static Yes Has1(TypeCheck::fptr, &T::classId> *); + template + static No Has1(...); + + template + static Yes Has2(TypeCheck::fptr, &T::classId> *); + template + static No Has2(...); + + public: + static const bool value = ((sizeof(Has1(0)) == sizeof(Yes)) || (sizeof(Has2(0)) == sizeof(Yes))); + }; + + template ::value> + struct TypeHasClassId { + static const bool value = false; + }; + + template + struct TypeHasClassId { + static const bool value = TypeHasClassIdHelper::value; + }; + } // namespace Private + + template + inline ClassId ClassId::itemId(const T &item) { + // Make sure that item is not a pointer. + static_assert((!IOIsAnyPtr::value), "can not use pointers with this method"); + + // If the classId() function is avalable for this item, call it + // (it could be virtual). Otherwise, call the generic method. + return Private::CallClassId::value, T>::get(item); + } +} // namespace gs // Class ids for standard types -gs_specialize_class_id(float, 0) gs_specialize_class_id(double, 0) - gs_specialize_class_id(long double, 0) gs_specialize_class_id(int, 0) - gs_specialize_class_id(unsigned, 0) gs_specialize_class_id(long, 0) - gs_specialize_class_id(long long, - 0) gs_specialize_class_id(unsigned long, 0) - gs_specialize_class_id(unsigned long long, - 0) gs_specialize_class_id(short, 0) - gs_specialize_class_id(unsigned short, - 0) gs_specialize_class_id(bool, 0) - gs_specialize_class_id(char, 0) - gs_specialize_class_id(unsigned char, 0) - gs_specialize_class_id(signed char, 0) - gs_specialize_class_id(void, 0) - gs_specialize_class_id(std::string, 0) +gs_specialize_class_id(float, 0) gs_specialize_class_id(double, 0) gs_specialize_class_id(long double, 0) + gs_specialize_class_id(int, 0) gs_specialize_class_id(unsigned, 0) gs_specialize_class_id(long, 0) + gs_specialize_class_id(long long, 0) gs_specialize_class_id(unsigned long, 0) + gs_specialize_class_id(unsigned long long, 0) gs_specialize_class_id(short, 0) + gs_specialize_class_id(unsigned short, 0) gs_specialize_class_id(bool, 0) + gs_specialize_class_id(char, 0) gs_specialize_class_id(unsigned char, 0) + gs_specialize_class_id(signed char, 0) gs_specialize_class_id(void, 0) + gs_specialize_class_id(std::string, 0) // Class ids for some standard library templates // used by this I/O package - gs_specialize_template_id_T(std::less, 0, 1) - gs_specialize_template_id_T(std::equal_to, 0, 1) - gs_specialize_template_id_T(std::allocator, 0, 1) - gs_specialize_template_id_T(std::char_traits, 0, 1) - gs_specialize_template_id_TT(std::vector, 0, 1) - gs_specialize_template_id_TT(std::pair, 0, 2) - gs_specialize_template_id_TTT(std::basic_string, 0, - 2) - -#endif // GENERS_CLASSID_HH_ + gs_specialize_template_id_T(std::less, 0, 1) gs_specialize_template_id_T(std::equal_to, 0, 1) + gs_specialize_template_id_T(std::allocator, 0, 1) gs_specialize_template_id_T(std::char_traits, 0, 1) + gs_specialize_template_id_TT(std::vector, 0, 1) gs_specialize_template_id_TT(std::pair, 0, 2) + gs_specialize_template_id_TTT(std::basic_string, 0, 2) + +#endif // GENERS_CLASSID_HH_ diff --git a/Alignment/Geners/interface/ClearIfPointer.hh b/Alignment/Geners/interface/ClearIfPointer.hh index 2a616b257ccdc..43c476e09eb7f 100644 --- a/Alignment/Geners/interface/ClearIfPointer.hh +++ b/Alignment/Geners/interface/ClearIfPointer.hh @@ -2,18 +2,21 @@ #define GENERS_CLEARIFPOINTER_HH_ namespace gs { -template struct ClearIfPointer { - static void clear(T &) {} -}; + template + struct ClearIfPointer { + static void clear(T &) {} + }; -template struct ClearIfPointer { - static void clear(T *&ptr) { ptr = 0; } -}; + template + struct ClearIfPointer { + static void clear(T *&ptr) { ptr = 0; } + }; -// The following will set object value to 0 if object is a pointer -template void clearIfPointer(T &obj) { - ClearIfPointer::clear(obj); -} -} // namespace gs + // The following will set object value to 0 if object is a pointer + template + void clearIfPointer(T &obj) { + ClearIfPointer::clear(obj); + } +} // namespace gs -#endif // GENERS_CLEARIFPOINTER_HH_ +#endif // GENERS_CLEARIFPOINTER_HH_ diff --git a/Alignment/Geners/interface/ColumnBuffer.hh b/Alignment/Geners/interface/ColumnBuffer.hh index b7af3a88bbad0..69dde408c347f 100644 --- a/Alignment/Geners/interface/ColumnBuffer.hh +++ b/Alignment/Geners/interface/ColumnBuffer.hh @@ -8,52 +8,51 @@ #include "Alignment/Geners/interface/ClassId.hh" namespace gs { -namespace Private { -struct ColumnBuffer { - inline ColumnBuffer() : firstrow(0), lastrowp1(0), podsize(0) {} - - // The actual buffer - CharBuffer buf; - - // The range of rows stored in the buffer is [firstrow, lastrowp1) - unsigned long firstrow; - unsigned long lastrowp1; - - // The following member will be non-0 if the column - // members are PODs for I/O purposes - unsigned long podsize; - - // If the above member is 0, objects in the buffer may have - // variable size. Because of this, we need to store an offset - // of each object separately. To conserve space, the vector - // of object offsets is not filled for PODs. - std::vector offsets; - - // Methods related to I/O - bool write(std::ostream &os) const; - inline const ClassId &classId() const { return static_classId(); } - - // The "restore" method is special and requires - // use of special references. The reason is the - // following: we will likely store a large number - // of these buffers at a time. Storing the class id - // of CharBuffer every time would be a waste of - // storage space. Because of this, we will assume - // that the code that manages these buffers will - // stash the CharBuffer class id somewhere. - static void restore(const ClassId &id, const ClassId &charBufId, - std::istream &in, ColumnBuffer *buf); - - static inline const char *classname() { return "gs::Private::ColumnBuffer"; } - static inline unsigned version() { return 1; } - - bool operator==(const ColumnBuffer &r) const; - inline bool operator!=(const ColumnBuffer &r) const { return !(*this == r); } - -private: - static const ClassId &static_classId(); -}; -} // namespace Private -} // namespace gs - -#endif // GENERS_COLUMNBUFFER_HH_ + namespace Private { + struct ColumnBuffer { + inline ColumnBuffer() : firstrow(0), lastrowp1(0), podsize(0) {} + + // The actual buffer + CharBuffer buf; + + // The range of rows stored in the buffer is [firstrow, lastrowp1) + unsigned long firstrow; + unsigned long lastrowp1; + + // The following member will be non-0 if the column + // members are PODs for I/O purposes + unsigned long podsize; + + // If the above member is 0, objects in the buffer may have + // variable size. Because of this, we need to store an offset + // of each object separately. To conserve space, the vector + // of object offsets is not filled for PODs. + std::vector offsets; + + // Methods related to I/O + bool write(std::ostream &os) const; + inline const ClassId &classId() const { return static_classId(); } + + // The "restore" method is special and requires + // use of special references. The reason is the + // following: we will likely store a large number + // of these buffers at a time. Storing the class id + // of CharBuffer every time would be a waste of + // storage space. Because of this, we will assume + // that the code that manages these buffers will + // stash the CharBuffer class id somewhere. + static void restore(const ClassId &id, const ClassId &charBufId, std::istream &in, ColumnBuffer *buf); + + static inline const char *classname() { return "gs::Private::ColumnBuffer"; } + static inline unsigned version() { return 1; } + + bool operator==(const ColumnBuffer &r) const; + inline bool operator!=(const ColumnBuffer &r) const { return !(*this == r); } + + private: + static const ClassId &static_classId(); + }; + } // namespace Private +} // namespace gs + +#endif // GENERS_COLUMNBUFFER_HH_ diff --git a/Alignment/Geners/interface/CompressedIO.hh b/Alignment/Geners/interface/CompressedIO.hh index d159e56adc52f..be107abd91fa2 100644 --- a/Alignment/Geners/interface/CompressedIO.hh +++ b/Alignment/Geners/interface/CompressedIO.hh @@ -12,83 +12,85 @@ #include "Alignment/Geners/interface/GenericIO.hh" namespace gs { -// The following function returns "true" on success, "false" on failure -template -bool write_compressed_item( - std::ostream &os, const Item &item, - CStringStream::CompressionMode m = CStringStream::ZLIB, - int compressionLevel = -1, unsigned minSizeToCompress = 1024U, - unsigned bufSize = 1048576U); + // The following function returns "true" on success, "false" on failure + template + bool write_compressed_item(std::ostream &os, + const Item &item, + CStringStream::CompressionMode m = CStringStream::ZLIB, + int compressionLevel = -1, + unsigned minSizeToCompress = 1024U, + unsigned bufSize = 1048576U); -template -void restore_compressed_item(std::istream &in, Item *item); + template + void restore_compressed_item(std::istream &in, Item *item); -template -CPP11_auto_ptr read_compressed_item(std::istream &in); -} // namespace gs + template + CPP11_auto_ptr read_compressed_item(std::istream &in); +} // namespace gs namespace gs { -template -inline bool write_compressed_item(std::ostream &os, const Item &item, - const CStringStream::CompressionMode m, - const int compressionLevel, - const unsigned minSizeToCompress, - const unsigned bufSize) { - CStringStream cs(m, compressionLevel, minSizeToCompress, bufSize); - unsigned compressionCode = 0; - long long len = 0; - const std::streampos base = os.tellp(); - write_pod(os, len); - write_pod(os, compressionCode); - if (os.fail() || os.bad()) - return false; - const std::streampos start = os.tellp(); - cs.setSink(os); - if (!write_item(cs, item)) - return false; - cs.flush(); - compressionCode = static_cast(cs.writeCompressed()); - const std::streampos now = os.tellp(); - const std::streamoff off = now - start; - len = off; - os.seekp(base); - write_pod(os, len); - write_pod(os, compressionCode); - os.seekp(now); - return !(cs.fail() || cs.bad() || os.fail() || os.bad()); -} + template + inline bool write_compressed_item(std::ostream &os, + const Item &item, + const CStringStream::CompressionMode m, + const int compressionLevel, + const unsigned minSizeToCompress, + const unsigned bufSize) { + CStringStream cs(m, compressionLevel, minSizeToCompress, bufSize); + unsigned compressionCode = 0; + long long len = 0; + const std::streampos base = os.tellp(); + write_pod(os, len); + write_pod(os, compressionCode); + if (os.fail() || os.bad()) + return false; + const std::streampos start = os.tellp(); + cs.setSink(os); + if (!write_item(cs, item)) + return false; + cs.flush(); + compressionCode = static_cast(cs.writeCompressed()); + const std::streampos now = os.tellp(); + const std::streamoff off = now - start; + len = off; + os.seekp(base); + write_pod(os, len); + write_pod(os, compressionCode); + os.seekp(now); + return !(cs.fail() || cs.bad() || os.fail() || os.bad()); + } -template -inline void restore_compressed_item(std::istream &is, Item *item) { - long long len; - read_pod(is, &len); - unsigned compressionCode; - read_pod(is, &compressionCode); - CStringStream::CompressionMode m = - static_cast(compressionCode); - CStringStream cs(m, -1, 1024U, 1048576U); - cs.readCompressed(is, compressionCode, len); - if (!is.good()) - throw IOReadFailure("In restore_compressed_item: " - "input stream failure"); - restore_item(cs, item); -} + template + inline void restore_compressed_item(std::istream &is, Item *item) { + long long len; + read_pod(is, &len); + unsigned compressionCode; + read_pod(is, &compressionCode); + CStringStream::CompressionMode m = static_cast(compressionCode); + CStringStream cs(m, -1, 1024U, 1048576U); + cs.readCompressed(is, compressionCode, len); + if (!is.good()) + throw IOReadFailure( + "In restore_compressed_item: " + "input stream failure"); + restore_item(cs, item); + } -template -inline CPP11_auto_ptr read_compressed_item(std::istream &is) { - long long len; - read_pod(is, &len); - unsigned compressionCode; - read_pod(is, &compressionCode); - CStringStream::CompressionMode m = - static_cast(compressionCode); - CStringStream cs(m, -1, 1024U, 1048576U); - cs.readCompressed(is, compressionCode, len); - if (!is.good()) - throw IOReadFailure("In read_compressed_item: " - "input stream failure"); - return read_item(cs); -} -} // namespace gs + template + inline CPP11_auto_ptr read_compressed_item(std::istream &is) { + long long len; + read_pod(is, &len); + unsigned compressionCode; + read_pod(is, &compressionCode); + CStringStream::CompressionMode m = static_cast(compressionCode); + CStringStream cs(m, -1, 1024U, 1048576U); + cs.readCompressed(is, compressionCode, len); + if (!is.good()) + throw IOReadFailure( + "In read_compressed_item: " + "input stream failure"); + return read_item(cs); + } +} // namespace gs -#endif // GENERS_COMPRESSEDIO_HH_ +#endif // GENERS_COMPRESSEDIO_HH_ diff --git a/Alignment/Geners/interface/ContiguousCatalog.hh b/Alignment/Geners/interface/ContiguousCatalog.hh index ced683be60604..778140b1a0f25 100644 --- a/Alignment/Geners/interface/ContiguousCatalog.hh +++ b/Alignment/Geners/interface/ContiguousCatalog.hh @@ -8,75 +8,71 @@ #include "Alignment/Geners/interface/CPP11_shared_ptr.hh" namespace gs { -class ContiguousCatalog : public AbsCatalog { -public: - // Default constructor creates an empty catalog - inline ContiguousCatalog(const unsigned long long firstId = 1) - : firstId_(firstId ? firstId : 1ULL) {} - inline ~ContiguousCatalog() override {} - - inline unsigned long long size() const override { return records_.size(); } - inline unsigned long long smallestId() const override { return firstId_; } - inline unsigned long long largestId() const override { - return firstId_ + records_.size() - 1; - } - inline bool isContiguous() const override { return true; } - - CPP11_shared_ptr - retrieveEntry(unsigned long long id) const override; - - bool retrieveStreampos(unsigned long long id, unsigned *compressionCode, - unsigned long long *length, - std::streampos *pos) const override; - - // Add a new entry without an id (id will be generated internally - // and returned) - unsigned long long makeEntry(const ItemDescriptor &descriptor, - unsigned compressionCode, - unsigned long long itemLength, - const ItemLocation &loc, - unsigned long long offset = 0ULL) override; - - inline const CatalogEntry *lastEntryMade() const override { - return lastEntry_.get(); - } - - // Search for matching entries based on item name and category - void search(const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern, - std::vector *idsFound) const override; - - // Methods needed for I/O - ClassId classId() const override { return ClassId(*this); } - bool write(std::ostream &os) const override; - - static inline const char *classname() { return "gs::ContiguousCatalog"; } - static inline unsigned version() { return 2; } - static ContiguousCatalog *read(const ClassId &id, std::istream &in); - -protected: - bool isEqual(const AbsCatalog &) const override; - -private: - typedef CPP11_shared_ptr SPtr; - - // In the following multimap, item name is the key and - // item id is the value - typedef std::multimap NameMap; - - // In the following map, item category is the key - typedef std::map RecordMap; - - void findByName(const NameMap &nmap, const SearchSpecifier &namePattern, - std::vector *found) const; - - std::vector records_; - unsigned long long firstId_; - RecordMap recordMap_; - SPtr lastEntry_; - - static ContiguousCatalog *read_v1(std::istream &in); -}; -} // namespace gs - -#endif // GENERS_CONTIGUOUSCATALOG_HH_ + class ContiguousCatalog : public AbsCatalog { + public: + // Default constructor creates an empty catalog + inline ContiguousCatalog(const unsigned long long firstId = 1) : firstId_(firstId ? firstId : 1ULL) {} + inline ~ContiguousCatalog() override {} + + inline unsigned long long size() const override { return records_.size(); } + inline unsigned long long smallestId() const override { return firstId_; } + inline unsigned long long largestId() const override { return firstId_ + records_.size() - 1; } + inline bool isContiguous() const override { return true; } + + CPP11_shared_ptr retrieveEntry(unsigned long long id) const override; + + bool retrieveStreampos(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length, + std::streampos *pos) const override; + + // Add a new entry without an id (id will be generated internally + // and returned) + unsigned long long makeEntry(const ItemDescriptor &descriptor, + unsigned compressionCode, + unsigned long long itemLength, + const ItemLocation &loc, + unsigned long long offset = 0ULL) override; + + inline const CatalogEntry *lastEntryMade() const override { return lastEntry_.get(); } + + // Search for matching entries based on item name and category + void search(const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern, + std::vector *idsFound) const override; + + // Methods needed for I/O + ClassId classId() const override { return ClassId(*this); } + bool write(std::ostream &os) const override; + + static inline const char *classname() { return "gs::ContiguousCatalog"; } + static inline unsigned version() { return 2; } + static ContiguousCatalog *read(const ClassId &id, std::istream &in); + + protected: + bool isEqual(const AbsCatalog &) const override; + + private: + typedef CPP11_shared_ptr SPtr; + + // In the following multimap, item name is the key and + // item id is the value + typedef std::multimap NameMap; + + // In the following map, item category is the key + typedef std::map RecordMap; + + void findByName(const NameMap &nmap, + const SearchSpecifier &namePattern, + std::vector *found) const; + + std::vector records_; + unsigned long long firstId_; + RecordMap recordMap_; + SPtr lastEntry_; + + static ContiguousCatalog *read_v1(std::istream &in); + }; +} // namespace gs + +#endif // GENERS_CONTIGUOUSCATALOG_HH_ diff --git a/Alignment/Geners/interface/GeneralCatalog.hh b/Alignment/Geners/interface/GeneralCatalog.hh index 1ce48ef134a71..4fa065ec9cf84 100644 --- a/Alignment/Geners/interface/GeneralCatalog.hh +++ b/Alignment/Geners/interface/GeneralCatalog.hh @@ -6,88 +6,85 @@ #include "Alignment/Geners/interface/AbsCatalog.hh" namespace gs { -class GeneralCatalog : public AbsCatalog { -public: - // Default constructor creates an empty catalog - GeneralCatalog(); - inline ~GeneralCatalog() override {} - - inline unsigned long long size() const override { return records_.size(); } - inline unsigned long long smallestId() const override { return smallestId_; } - inline unsigned long long largestId() const override { return largestId_; } - inline bool isContiguous() const override { return false; } - inline bool itemExists(const unsigned long long id) const override { - return records_.find(id) != records_.end(); - } - - CPP11_shared_ptr - retrieveEntry(const unsigned long long id) const override; - - bool retrieveStreampos(unsigned long long id, unsigned *compressionCode, - unsigned long long *length, - std::streampos *pos) const override; - - // Add a new entry without an id (id will be generated internally - // and returned) - unsigned long long makeEntry(const ItemDescriptor &descriptor, - unsigned compressionCode, - unsigned long long itemLength, - const ItemLocation &loc, - unsigned long long offset = 0ULL) override; - - inline const CatalogEntry *lastEntryMade() const override { - return lastEntry_.get(); - } - - // Add a new entry with id (presumably, from another catalog). - // Returns "true" on success. The entry is not included (and "false" - // is returned) in case the entry with the given id already exists. - bool addEntry(CPP11_shared_ptr ptr); - - // Remove an entry with the given id. "false" is returned in case - // an entry with the specified id does not exist. - bool removeEntry(unsigned long long id); - - // Search for matching entries based on item name and category - void search(const SearchSpecifier &namePattern, - const SearchSpecifier &categoryPattern, - std::vector *idsFound) const override; - - // Methods needed for I/O - ClassId classId() const override { return ClassId(*this); } - bool write(std::ostream &os) const override; - - static inline const char *classname() { return "gs::GeneralCatalog"; } - static inline unsigned version() { return 2; } - static GeneralCatalog *read(const ClassId &id, std::istream &in); - -protected: - bool isEqual(const AbsCatalog &) const override; - -private: - typedef CPP11_shared_ptr SPtr; - - // In the following multimap, item name is the key and - // catalog entry pointer is the value - typedef std::multimap NameMap; - - // In the following map, item category is the key - typedef std::map RecordMap; - - // In the following map, item id is the key - typedef std::map IdMap; - - void findByName(const NameMap &nmap, const SearchSpecifier &namePattern, - std::vector *found) const; - - IdMap records_; - RecordMap recordMap_; - unsigned long long smallestId_; - unsigned long long largestId_; - SPtr lastEntry_; - - static GeneralCatalog *read_v1(std::istream &in); -}; -} // namespace gs - -#endif // GENERS_GENERALCATALOG_HH_ + class GeneralCatalog : public AbsCatalog { + public: + // Default constructor creates an empty catalog + GeneralCatalog(); + inline ~GeneralCatalog() override {} + + inline unsigned long long size() const override { return records_.size(); } + inline unsigned long long smallestId() const override { return smallestId_; } + inline unsigned long long largestId() const override { return largestId_; } + inline bool isContiguous() const override { return false; } + inline bool itemExists(const unsigned long long id) const override { return records_.find(id) != records_.end(); } + + CPP11_shared_ptr retrieveEntry(const unsigned long long id) const override; + + bool retrieveStreampos(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length, + std::streampos *pos) const override; + + // Add a new entry without an id (id will be generated internally + // and returned) + unsigned long long makeEntry(const ItemDescriptor &descriptor, + unsigned compressionCode, + unsigned long long itemLength, + const ItemLocation &loc, + unsigned long long offset = 0ULL) override; + + inline const CatalogEntry *lastEntryMade() const override { return lastEntry_.get(); } + + // Add a new entry with id (presumably, from another catalog). + // Returns "true" on success. The entry is not included (and "false" + // is returned) in case the entry with the given id already exists. + bool addEntry(CPP11_shared_ptr ptr); + + // Remove an entry with the given id. "false" is returned in case + // an entry with the specified id does not exist. + bool removeEntry(unsigned long long id); + + // Search for matching entries based on item name and category + void search(const SearchSpecifier &namePattern, + const SearchSpecifier &categoryPattern, + std::vector *idsFound) const override; + + // Methods needed for I/O + ClassId classId() const override { return ClassId(*this); } + bool write(std::ostream &os) const override; + + static inline const char *classname() { return "gs::GeneralCatalog"; } + static inline unsigned version() { return 2; } + static GeneralCatalog *read(const ClassId &id, std::istream &in); + + protected: + bool isEqual(const AbsCatalog &) const override; + + private: + typedef CPP11_shared_ptr SPtr; + + // In the following multimap, item name is the key and + // catalog entry pointer is the value + typedef std::multimap NameMap; + + // In the following map, item category is the key + typedef std::map RecordMap; + + // In the following map, item id is the key + typedef std::map IdMap; + + void findByName(const NameMap &nmap, + const SearchSpecifier &namePattern, + std::vector *found) const; + + IdMap records_; + RecordMap recordMap_; + unsigned long long smallestId_; + unsigned long long largestId_; + SPtr lastEntry_; + + static GeneralCatalog *read_v1(std::istream &in); + }; +} // namespace gs + +#endif // GENERS_GENERALCATALOG_HH_ diff --git a/Alignment/Geners/interface/GenericIO.hh b/Alignment/Geners/interface/GenericIO.hh index fc993f717a686..95e0848f0d1e3 100644 --- a/Alignment/Geners/interface/GenericIO.hh +++ b/Alignment/Geners/interface/GenericIO.hh @@ -13,746 +13,681 @@ #include "Alignment/Geners/interface/StrippedType.hh" namespace gs { -/** + /** // Generic top-level function which can be used to write out // almost anything. Intended mainly for use inside "write" // methods of user-developed classes and templates. Returns // "true" if the argument item is successfully written out. */ -template -inline bool write_item(Stream &os, const Item &item, - const bool writeClassId = true) { - char *ps = nullptr; - return process_const_item(item, os, ps, writeClassId); -} - -/** + template + inline bool write_item(Stream &os, const Item &item, const bool writeClassId = true) { + char *ps = nullptr; + return process_const_item(item, os, ps, writeClassId); + } + + /** // A function for overwriting existing objects (which usually live // on the stack). This function actually skips couple levels of // indirection which would be generated by a call to "process_item". */ -template -inline void restore_item(Stream &is, Item *item, - const bool readClassId = true) { - typedef std::vector State; - assert(item); - State state; - const bool status = - GenericReader::ISPOINTER>>::process(item, is, - &state, - readClassId); - if (is.fail()) - throw IOReadFailure("In gs::restore_item: input stream failure"); - if (!status) - throw IOInvalidData("In gs::restore_item: invalid input stream data"); -} - -/** + template + inline void restore_item(Stream &is, Item *item, const bool readClassId = true) { + typedef std::vector State; + assert(item); + State state; + const bool status = GenericReader::ISPOINTER>>::process( + item, is, &state, readClassId); + if (is.fail()) + throw IOReadFailure("In gs::restore_item: input stream failure"); + if (!status) + throw IOInvalidData("In gs::restore_item: invalid input stream data"); + } + + /** // Function for returning objects on the heap. This function // requires explicit specification of its first template // parameter, the type of the item to read. This function // either succeeds or throws an exception which inherits // from std::exception. */ -template -inline CPP11_auto_ptr read_item(Stream &is, - const bool readClassId = true) { - typedef std::vector State; - Item *item = nullptr; - State state; - const bool status = GenericReader< - Stream, State, Item *, - Int2Type::ISNULLPOINTER>>::process(item, is, &state, - readClassId); - CPP11_auto_ptr ptr(item); - if (is.fail()) - throw IOReadFailure("In gs::read_item: input stream failure"); - if (!status || item == nullptr) - throw IOInvalidData("In gs::read_item: invalid input stream data"); - return ptr; -} - -/** + template + inline CPP11_auto_ptr read_item(Stream &is, const bool readClassId = true) { + typedef std::vector State; + Item *item = nullptr; + State state; + const bool status = GenericReader::ISNULLPOINTER>>::process( + item, is, &state, readClassId); + CPP11_auto_ptr ptr(item); + if (is.fail()) + throw IOReadFailure("In gs::read_item: input stream failure"); + if (!status || item == nullptr) + throw IOInvalidData("In gs::read_item: invalid input stream data"); + return ptr; + } + + /** // Generic top-level function for writing arrays. Note that // the length of the array is not written out and that the // length must be known in advance in the scope from which // the companion function, "read_array", is called. "true" // is returned upon success, "false" on failure. */ -template -inline bool write_array(Stream &os, Item *items, const std::size_t length) { - char *ps = nullptr; - return process_const_item(ArrayAdaptor(items, length), - os, ps, false); -} - -/** + template + inline bool write_array(Stream &os, Item *items, const std::size_t length) { + char *ps = nullptr; + return process_const_item(ArrayAdaptor(items, length), os, ps, false); + } + + /** // Function for deserializing arrays. The length of the array // must be known in the scope from which this function is invoked. */ -template -inline void read_array(Stream &is, Item *items, const std::size_t length) { - typedef std::vector State; - State state; - ArrayAdaptor adap(items, length); - const bool st = process_item(adap, is, &state, false); - if (is.fail()) - throw IOReadFailure("In gs::read_array: input stream failure"); - if (!st) - throw IOInvalidData("In gs::read_array: invalid input stream data"); -} -} // namespace gs + template + inline void read_array(Stream &is, Item *items, const std::size_t length) { + typedef std::vector State; + State state; + ArrayAdaptor adap(items, length); + const bool st = process_item(adap, is, &state, false); + if (is.fail()) + throw IOReadFailure("In gs::read_array: input stream failure"); + if (!st) + throw IOInvalidData("In gs::read_array: invalid input stream data"); + } +} // namespace gs namespace gs { -template -struct GenericWriter2 : public GenericWriter {}; - -template -struct GenericReader2 : public GenericReader {}; - -// The reader and writer templates should be specialized -// (that is, their "process" function should be defined) using -// the following processing stage types from "ProcessItem.hh": -// -// Int2Type::ISPOD> (+readIntoPtr) -// InContainerHeader -// InContainerFooter -// InContainerSize -// InPODArray -// Int2Type::ISWRITABLE> -// Int2Type::ISPOINTER> -// Int2Type::ISSHAREDPTR> -// Int2Type::ISPAIR> (+readIntoPtr) -// Int2Type::ISSTRING> (+readIntoPtr) -// -// In addition, the reader should be specialized for the following -// types: -// -// InContainerCycle (process only) -// Int2Type::ISSTDCONTAINER> (readIntoPtr only) -// Int2Type::ISHEAPREADABLE> (readIntoPtr only) -// Int2Type::ISPLACEREADABLE> (readIntoPtr only) -// -// The resulting code is essentially one big compile-time state -// machine with two main switching hubs: "process_item" function -// from "ProcessItem.hh" and "process" function in GenericReader -// template specialized for bare pointers. -// - -//=================================================================== -// -// Processing of a POD -// -//=================================================================== -template -struct GenericWriter::ISPOD>> { - inline static bool process(const T &s, Stream &os, State *, - const bool processClassId) { - static const ClassId current(ClassId::makeId()); - const bool status = processClassId ? current.write(os) : true; - if (status) - write_pod(os, s); - return status && !os.fail(); - } -}; - -template -struct GenericReader::ISPOD>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *, - const bool processClassId) { - CPP11_auto_ptr myptr; - if (ptr == 0) - myptr = CPP11_auto_ptr(new T()); - if (processClassId) { + template + struct GenericWriter2 : public GenericWriter {}; + + template + struct GenericReader2 : public GenericReader {}; + + // The reader and writer templates should be specialized + // (that is, their "process" function should be defined) using + // the following processing stage types from "ProcessItem.hh": + // + // Int2Type::ISPOD> (+readIntoPtr) + // InContainerHeader + // InContainerFooter + // InContainerSize + // InPODArray + // Int2Type::ISWRITABLE> + // Int2Type::ISPOINTER> + // Int2Type::ISSHAREDPTR> + // Int2Type::ISPAIR> (+readIntoPtr) + // Int2Type::ISSTRING> (+readIntoPtr) + // + // In addition, the reader should be specialized for the following + // types: + // + // InContainerCycle (process only) + // Int2Type::ISSTDCONTAINER> (readIntoPtr only) + // Int2Type::ISHEAPREADABLE> (readIntoPtr only) + // Int2Type::ISPLACEREADABLE> (readIntoPtr only) + // + // The resulting code is essentially one big compile-time state + // machine with two main switching hubs: "process_item" function + // from "ProcessItem.hh" and "process" function in GenericReader + // template specialized for bare pointers. + // + + //=================================================================== + // + // Processing of a POD + // + //=================================================================== + template + struct GenericWriter::ISPOD>> { + inline static bool process(const T &s, Stream &os, State *, const bool processClassId) { static const ClassId current(ClassId::makeId()); - ClassId id(str, 1); - current.ensureSameName(id); - } - read_pod(str, ptr ? ptr : myptr.get()); - if (str.fail()) - return false; - if (ptr == 0) - ptr = myptr.release(); - return true; - } - - inline static bool process(T &s, Stream &os, State *st, - const bool processClassId) { - T *ps = &s; - return readIntoPtr(ps, os, st, processClassId); - } -}; - -//=================================================================== -// -// Processing of a container header -// -//=================================================================== -template -struct GenericWriter { - inline static bool process(const Container &, Stream &os, State *, - const bool processClassId) { - typedef typename Container::value_type T; - - static const ClassId current(ClassId::makeId()); - bool status = processClassId ? current.write(os) : true; - - // Maybe we do not have to write out the container class id, - // but we do have to write out the item class id -- unless the - // container is just an array of pods. Otherwise we might not - // be able to read the container items back. - if (status && !(IOTraits::IsPOD && IOTraits::IsContiguous)) { - static const ClassId itemId(ClassId::makeId()); - status = itemId.write(os); - } - return status; - } -}; - -template -struct GenericReader { - inline static bool process(Container &a, Stream &is, State *state, - const bool processClassId) { - typedef typename Container::value_type T; - - if (processClassId) { - static const ClassId current(ClassId::makeId()); - ClassId id(is, 1); - current.ensureSameName(id); + const bool status = processClassId ? current.write(os) : true; + if (status) + write_pod(os, s); + return status && !os.fail(); + } + }; + + template + struct GenericReader::ISPOD>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *, const bool processClassId) { + CPP11_auto_ptr myptr; + if (ptr == 0) + myptr = CPP11_auto_ptr(new T()); + if (processClassId) { + static const ClassId current(ClassId::makeId()); + ClassId id(str, 1); + current.ensureSameName(id); + } + read_pod(str, ptr ? ptr : myptr.get()); + if (str.fail()) + return false; + if (ptr == 0) + ptr = myptr.release(); + return true; } - a.clear(); - if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) { - ClassId id(is, 1); - // Remember the class id of the contained items. - // We need to do this even if the id is invalid because - // the id will be popped back when the "InContainerFooter" - // stage is processed. - state->push_back(id); + inline static bool process(T &s, Stream &os, State *st, const bool processClassId) { + T *ps = &s; + return readIntoPtr(ps, os, st, processClassId); } - return true; - } -}; + }; + + //=================================================================== + // + // Processing of a container header + // + //=================================================================== + template + struct GenericWriter { + inline static bool process(const Container &, Stream &os, State *, const bool processClassId) { + typedef typename Container::value_type T; -//=================================================================== -// -// Processing of a container footer -// -//=================================================================== -template -struct GenericWriter { - inline static bool process(const Container &, Stream &, State *, bool) { - return true; - } -}; - -template -struct GenericReader { - inline static bool process(Container &, Stream &, State *state, bool) { - typedef typename Container::value_type T; - if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) - state->pop_back(); - return true; - } -}; + static const ClassId current(ClassId::makeId()); + bool status = processClassId ? current.write(os) : true; + + // Maybe we do not have to write out the container class id, + // but we do have to write out the item class id -- unless the + // container is just an array of pods. Otherwise we might not + // be able to read the container items back. + if (status && !(IOTraits::IsPOD && IOTraits::IsContiguous)) { + static const ClassId itemId(ClassId::makeId()); + status = itemId.write(os); + } + return status; + } + }; -//=================================================================== -// -// Processing of container size -// -//=================================================================== -template -struct GenericWriter { - inline static bool process(const std::size_t &sz, Stream &os, State *, - bool /* processClassId */) { - write_pod(os, sz); - return !os.fail(); - } -}; - -template -struct GenericReader { - inline static bool process(std::size_t &sz, Stream &is, State *, - bool /* processClassId */) { - read_pod(is, &sz); - return !is.fail(); - } -}; + template + struct GenericReader { + inline static bool process(Container &a, Stream &is, State *state, const bool processClassId) { + typedef typename Container::value_type T; -//=================================================================== -// -// Processing of data in contiguous POD containers -// -//=================================================================== -template -struct GenericWriter { - inline static bool process(const ArrayLike &a, Stream &os, State *, bool) { - const std::size_t len = a.size(); - write_pod(os, len); - if (len) - write_pod_array(os, &a[0], len); - return !os.fail(); - } -}; - -template -struct GenericReader { - inline static bool process(ArrayLike &a, Stream &s, State *, bool) { - std::size_t len = 0; - read_pod(s, &len); - if (s.fail()) - return false; - a.resize(len); - if (!len) + if (processClassId) { + static const ClassId current(ClassId::makeId()); + ClassId id(is, 1); + current.ensureSameName(id); + } + a.clear(); + if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) { + ClassId id(is, 1); + + // Remember the class id of the contained items. + // We need to do this even if the id is invalid because + // the id will be popped back when the "InContainerFooter" + // stage is processed. + state->push_back(id); + } return true; - read_pod_array(s, &a[0], len); - return !s.fail(); - } -}; - -//=================================================================== -// -// Processing of "writable" objects -// -//=================================================================== -template -struct GenericWriter::ISWRITABLE>> { - inline static bool process(const T &s, Stream &os, State *, - const bool processClassId) { - return (processClassId ? s.classId().write(os) : true) && s.write(os) && - !os.fail(); - } -}; - -template -struct GenericReader::ISWRITABLE>> { - inline static bool process(T &s, Stream &is, State *st, - const bool processClassId) { - typedef IOTraits M; - T *ps = &s; - return GenericReader< - Stream, State, T, - Int2Type>:: - readIntoPtr(ps, is, st, processClassId); - } -}; - -//=================================================================== -// -// Processing of bare pointers. -// -// The writer simply dereferences the pointer. -// -// In the reader, we want to read stuff into the pointee object, -// or want to create an item on the heap if the pointer value is 0. -// -//=================================================================== -template -struct GenericWriter::ISPOINTER>> { - inline static bool process(const Ptr &ptr, Stream &os, State *s, - const bool processClassId) { - // Can't have pointers to pointers. This is a design - // decision which simplifies things considerably. - typedef typename IOPointeeType::type Pointee; - typedef IOTraits M; - static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, - "can not write pointers to pointers"); - - // Can't have NULL pointers either. But this - // can be checked at run time only. - assert(ptr); - return process_const_item(*ptr, os, s, processClassId); - } -}; - -template -struct GenericReader::ISPOINTER>> { - inline static bool process(Ptr &ptr, Stream &str, State *s, - const bool processClassId) { - // We need to figure out the type of the pointee - // and make a swich depending on that type. - // Note that the pointee itself can not be a pointer. - typedef typename IOPointeeType::type Pointee; - typedef IOTraits M; - static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, - "can not read pointers to pointers"); - - return GenericReader< - Stream, State, Pointee, - Int2Type>::readIntoPtr(ptr, str, s, processClassId); - } -}; - -template -struct GenericReader::ISNULLPOINTER>> { - inline static bool process(Ptr &ptr, Stream &str, State *s, - const bool processClassId) { - // We need to figure out the type of the pointee - // and make a swich depending on that type. - // Note that the pointee itself can not be a pointer. - typedef typename IOPointeeType::type Pointee; - typedef IOTraits M; - static_assert((M::Signature & (M::ISNULLPOINTER | M::ISSHAREDPTR)) == 0, - "can not read pointers to pointers"); - - return GenericReader< - Stream, State, Pointee, - Int2Type>::readIntoPtr(ptr, str, s, processClassId); - } -}; - -//=================================================================== -// -// Processing of shared pointers -- similar logic to pointers. -// For the reader, handling of the shared pointer is reduced -// to handling of a normal pointer with 0 value. -// -//=================================================================== -template -struct GenericWriter::ISSHAREDPTR>> { - inline static bool process(const Ptr &ptr, Stream &os, State *s, - const bool processClassId) { - typedef typename Ptr::element_type Pointee; - typedef IOTraits M; - static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, - "can not write pointers to pointers"); - assert(ptr.get()); - return process_const_item(*ptr, os, s, processClassId); - } -}; - -template -struct GenericReader::ISSHAREDPTR>> { - inline static bool process(ShPtr &a, Stream &str, State *s, - const bool processClassId) { - typedef typename ShPtr::element_type Pointee; - typedef IOTraits M; - static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, - "can not read pointers to pointers"); - Pointee *ptr = 0; - const bool status = GenericReader< - Stream, State, Pointee *, - Int2Type::ISNULLPOINTER>>::process(ptr, str, s, - processClassId); - if (status) { - assert(ptr); - a = CPP11_shared_ptr(ptr); + } + }; + + //=================================================================== + // + // Processing of a container footer + // + //=================================================================== + template + struct GenericWriter { + inline static bool process(const Container &, Stream &, State *, bool) { return true; } + }; + + template + struct GenericReader { + inline static bool process(Container &, Stream &, State *state, bool) { + typedef typename Container::value_type T; + if (!(IOTraits::IsPOD && IOTraits::IsContiguous)) + state->pop_back(); return true; - } else { - delete ptr; - return false; } - } -}; + }; + + //=================================================================== + // + // Processing of container size + // + //=================================================================== + template + struct GenericWriter { + inline static bool process(const std::size_t &sz, Stream &os, State *, bool /* processClassId */) { + write_pod(os, sz); + return !os.fail(); + } + }; -//=================================================================== -// -// Processing of std::pair -// -//=================================================================== -template -struct GenericWriter::ISPAIR>> { - inline static bool process(const T &s, Stream &os, State *st, - const bool processClassId) { - // Here is a little problem: in this scope "GenericWriter" - // means GenericWriter::ISPAIR> > - // However, we want to use the whole template, unspecialized. - // This is why "GenericWriter2" is introduced: a copy of - // "GenericWriter" via public inheritance. - static const ClassId current(ClassId::makeId()); - return (processClassId ? current.write(os) : true) && - process_const_item(s.first, os, st, false) && - process_const_item(s.second, os, st, false); - } -}; - -template -struct GenericReader::ISPAIR>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, - const bool processClassId) { - CPP11_auto_ptr myptr; - if (ptr == 0) { - myptr = CPP11_auto_ptr(new T()); - clearIfPointer(myptr.get()->first); - clearIfPointer(myptr.get()->second); - } - std::vector> itemIds; - if (processClassId) { + template + struct GenericReader { + inline static bool process(std::size_t &sz, Stream &is, State *, bool /* processClassId */) { + read_pod(is, &sz); + return !is.fail(); + } + }; + + //=================================================================== + // + // Processing of data in contiguous POD containers + // + //=================================================================== + template + struct GenericWriter { + inline static bool process(const ArrayLike &a, Stream &os, State *, bool) { + const std::size_t len = a.size(); + write_pod(os, len); + if (len) + write_pod_array(os, &a[0], len); + return !os.fail(); + } + }; + + template + struct GenericReader { + inline static bool process(ArrayLike &a, Stream &s, State *, bool) { + std::size_t len = 0; + read_pod(s, &len); + if (s.fail()) + return false; + a.resize(len); + if (!len) + return true; + read_pod_array(s, &a[0], len); + return !s.fail(); + } + }; + + //=================================================================== + // + // Processing of "writable" objects + // + //=================================================================== + template + struct GenericWriter::ISWRITABLE>> { + inline static bool process(const T &s, Stream &os, State *, const bool processClassId) { + return (processClassId ? s.classId().write(os) : true) && s.write(os) && !os.fail(); + } + }; + + template + struct GenericReader::ISWRITABLE>> { + inline static bool process(T &s, Stream &is, State *st, const bool processClassId) { + typedef IOTraits M; + T *ps = &s; + return GenericReader>:: + readIntoPtr(ps, is, st, processClassId); + } + }; + + //=================================================================== + // + // Processing of bare pointers. + // + // The writer simply dereferences the pointer. + // + // In the reader, we want to read stuff into the pointee object, + // or want to create an item on the heap if the pointer value is 0. + // + //=================================================================== + template + struct GenericWriter::ISPOINTER>> { + inline static bool process(const Ptr &ptr, Stream &os, State *s, const bool processClassId) { + // Can't have pointers to pointers. This is a design + // decision which simplifies things considerably. + typedef typename IOPointeeType::type Pointee; + typedef IOTraits M; + static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, "can not write pointers to pointers"); + + // Can't have NULL pointers either. But this + // can be checked at run time only. + assert(ptr); + return process_const_item(*ptr, os, s, processClassId); + } + }; + + template + struct GenericReader::ISPOINTER>> { + inline static bool process(Ptr &ptr, Stream &str, State *s, const bool processClassId) { + // We need to figure out the type of the pointee + // and make a swich depending on that type. + // Note that the pointee itself can not be a pointer. + typedef typename IOPointeeType::type Pointee; + typedef IOTraits M; + static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, "can not read pointers to pointers"); + + return GenericReader< + Stream, + State, + Pointee, + Int2Type>::readIntoPtr(ptr, str, s, processClassId); + } + }; + + template + struct GenericReader::ISNULLPOINTER>> { + inline static bool process(Ptr &ptr, Stream &str, State *s, const bool processClassId) { + // We need to figure out the type of the pointee + // and make a swich depending on that type. + // Note that the pointee itself can not be a pointer. + typedef typename IOPointeeType::type Pointee; + typedef IOTraits M; + static_assert((M::Signature & (M::ISNULLPOINTER | M::ISSHAREDPTR)) == 0, "can not read pointers to pointers"); + + return GenericReader< + Stream, + State, + Pointee, + Int2Type>::readIntoPtr(ptr, str, s, processClassId); + } + }; + + //=================================================================== + // + // Processing of shared pointers -- similar logic to pointers. + // For the reader, handling of the shared pointer is reduced + // to handling of a normal pointer with 0 value. + // + //=================================================================== + template + struct GenericWriter::ISSHAREDPTR>> { + inline static bool process(const Ptr &ptr, Stream &os, State *s, const bool processClassId) { + typedef typename Ptr::element_type Pointee; + typedef IOTraits M; + static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, "can not write pointers to pointers"); + assert(ptr.get()); + return process_const_item(*ptr, os, s, processClassId); + } + }; + + template + struct GenericReader::ISSHAREDPTR>> { + inline static bool process(ShPtr &a, Stream &str, State *s, const bool processClassId) { + typedef typename ShPtr::element_type Pointee; + typedef IOTraits M; + static_assert((M::Signature & (M::ISPOINTER | M::ISSHAREDPTR)) == 0, "can not read pointers to pointers"); + Pointee *ptr = 0; + const bool status = GenericReader::ISNULLPOINTER>>::process( + ptr, str, s, processClassId); + if (status) { + assert(ptr); + a = CPP11_shared_ptr(ptr); + return true; + } else { + delete ptr; + return false; + } + } + }; + + //=================================================================== + // + // Processing of std::pair + // + //=================================================================== + template + struct GenericWriter::ISPAIR>> { + inline static bool process(const T &s, Stream &os, State *st, const bool processClassId) { + // Here is a little problem: in this scope "GenericWriter" + // means GenericWriter::ISPAIR> > + // However, we want to use the whole template, unspecialized. + // This is why "GenericWriter2" is introduced: a copy of + // "GenericWriter" via public inheritance. static const ClassId current(ClassId::makeId()); - ClassId pairId(str, 1); - current.ensureSameName(pairId); - pairId.templateParameters(&itemIds); - assert(itemIds.size() == 2U); - } else { - assert(!s->empty()); - s->back().templateParameters(&itemIds); - if (itemIds.size() != 2U) { - std::string err("In gs::GenericReader::readIntoPtr: " - "bad class id for std::pair on the " - "class id stack: "); - err += s->back().id(); - throw IOInvalidData(err); + return (processClassId ? current.write(os) : true) && + process_const_item(s.first, os, st, false) && + process_const_item(s.second, os, st, false); + } + }; + + template + struct GenericReader::ISPAIR>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, const bool processClassId) { + CPP11_auto_ptr myptr; + if (ptr == 0) { + myptr = CPP11_auto_ptr(new T()); + clearIfPointer(myptr.get()->first); + clearIfPointer(myptr.get()->second); + } + std::vector> itemIds; + if (processClassId) { + static const ClassId current(ClassId::makeId()); + ClassId pairId(str, 1); + current.ensureSameName(pairId); + pairId.templateParameters(&itemIds); + assert(itemIds.size() == 2U); + } else { + assert(!s->empty()); + s->back().templateParameters(&itemIds); + if (itemIds.size() != 2U) { + std::string err( + "In gs::GenericReader::readIntoPtr: " + "bad class id for std::pair on the " + "class id stack: "); + err += s->back().id(); + throw IOInvalidData(err); + } } + if (!(process_item((ptr ? ptr : myptr.get())->first, str, &itemIds[0], false) && + process_item((ptr ? ptr : myptr.get())->second, str, &itemIds[1], false))) + return false; + if (ptr == 0) + ptr = myptr.release(); + return true; } - if (!(process_item((ptr ? ptr : myptr.get())->first, str, - &itemIds[0], false) && - process_item((ptr ? ptr : myptr.get())->second, str, - &itemIds[1], false))) - return false; - if (ptr == 0) - ptr = myptr.release(); - return true; - } - - inline static bool process(T &s, Stream &os, State *st, - const bool processClassId) { - T *ps = &s; - return readIntoPtr(ps, os, st, processClassId); - } -}; -//=================================================================== -// -// Processing of std::string -// -//=================================================================== -template -struct GenericWriter::ISSTRING>> { - inline static bool process(const std::string &s, Stream &os, State *, - const bool processClassId) { - static const ClassId current(ClassId::makeId()); - const bool status = processClassId ? current.write(os) : true; - if (status) - write_string(os, s); - return status && !os.fail(); - } -}; - -template -struct GenericReader::ISSTRING>> { - inline static bool readIntoPtr(std::string *&ptr, Stream &is, State *, - const bool processClassId) { - CPP11_auto_ptr myptr; - if (ptr == nullptr) - myptr = CPP11_auto_ptr(new std::string()); - if (processClassId) { + inline static bool process(T &s, Stream &os, State *st, const bool processClassId) { + T *ps = &s; + return readIntoPtr(ps, os, st, processClassId); + } + }; + + //=================================================================== + // + // Processing of std::string + // + //=================================================================== + template + struct GenericWriter::ISSTRING>> { + inline static bool process(const std::string &s, Stream &os, State *, const bool processClassId) { static const ClassId current(ClassId::makeId()); - ClassId id(is, 1); - current.ensureSameName(id); + const bool status = processClassId ? current.write(os) : true; + if (status) + write_string(os, s); + return status && !os.fail(); + } + }; + + template + struct GenericReader::ISSTRING>> { + inline static bool readIntoPtr(std::string *&ptr, Stream &is, State *, const bool processClassId) { + CPP11_auto_ptr myptr; + if (ptr == nullptr) + myptr = CPP11_auto_ptr(new std::string()); + if (processClassId) { + static const ClassId current(ClassId::makeId()); + ClassId id(is, 1); + current.ensureSameName(id); + } + read_string(is, ptr ? ptr : myptr.get()); + if (is.fail()) + return false; + if (ptr == nullptr) + ptr = myptr.release(); + return true; } - read_string(is, ptr ? ptr : myptr.get()); - if (is.fail()) - return false; - if (ptr == nullptr) - ptr = myptr.release(); - return true; - } - - inline static bool process(std::string &s, Stream &is, State *st, - const bool processClassId) { - std::string *ptr = &s; - return readIntoPtr(ptr, is, st, processClassId); - } -}; - -//=================================================================== -// -// Processing of container readout -// -//=================================================================== -template -struct GenericReader { -private: - typedef typename Container::value_type item_type; - typedef IOTraits M; - - // Item is a simple pointer - inline static bool process2(Container &obj, Stream &is, State *st, - const std::size_t itemN, Int2Type<1>) { - item_type ptr = 0; - const bool status = - GenericReader::ISNULLPOINTER>>::process(ptr, is, - st, - true); - if (status) { - assert(ptr); - InsertContainerItem::insert(obj, ptr, itemN); - } else - delete ptr; - return status; - } - // Item is a shared pointer - inline static bool process2(Container &obj, Stream &is, State *st, - const std::size_t itemN, Int2Type<2>) { - typedef typename item_type::element_type Pointee; - Pointee *ptr = 0; - const bool status = - GenericReader::ISNULLPOINTER>>::process(ptr, is, - st, - true); - if (status) { - assert(ptr); - CPP11_shared_ptr sptr(ptr); - InsertContainerItem::insert(obj, sptr, itemN); - } else - delete ptr; - return status; - } + inline static bool process(std::string &s, Stream &is, State *st, const bool processClassId) { + std::string *ptr = &s; + return readIntoPtr(ptr, is, st, processClassId); + } + }; + + //=================================================================== + // + // Processing of container readout + // + //=================================================================== + template + struct GenericReader { + private: + typedef typename Container::value_type item_type; + typedef IOTraits M; + + // Item is a simple pointer + inline static bool process2(Container &obj, Stream &is, State *st, const std::size_t itemN, Int2Type<1>) { + item_type ptr = 0; + const bool status = + GenericReader::ISNULLPOINTER>>::process(ptr, is, st, true); + if (status) { + assert(ptr); + InsertContainerItem::insert(obj, ptr, itemN); + } else + delete ptr; + return status; + } - // Item is heap-readable - inline static bool process2(Container &obj, Stream &is, State *st, - const std::size_t itemN, Int2Type<3>) { - // No class id -- this is a member of a container - assert(!st->empty()); - item_type *ptr = item_type::read(st->back(), is); - if (ptr) { - InsertContainerItem::insert(obj, *ptr, itemN); - delete ptr; + // Item is a shared pointer + inline static bool process2(Container &obj, Stream &is, State *st, const std::size_t itemN, Int2Type<2>) { + typedef typename item_type::element_type Pointee; + Pointee *ptr = 0; + const bool status = + GenericReader::ISNULLPOINTER>>::process(ptr, is, st, true); + if (status) { + assert(ptr); + CPP11_shared_ptr sptr(ptr); + InsertContainerItem::insert(obj, sptr, itemN); + } else + delete ptr; + return status; } - return ptr; - } - // Item is not a pointer and not heap-readable. - // Assume that it has a default constructor. - inline static bool process2(Container &obj, Stream &is, State *st, - const std::size_t itemN, Int2Type<4>) { - typedef typename StrippedType::type NCType; - NCType item; - NCType *pitem = &item; - bool status = - GenericReader::ISPOINTER>>::process(pitem, is, - st, false); - if (status) - InsertContainerItem::insert(obj, item, itemN); - return status; - } + // Item is heap-readable + inline static bool process2(Container &obj, Stream &is, State *st, const std::size_t itemN, Int2Type<3>) { + // No class id -- this is a member of a container + assert(!st->empty()); + item_type *ptr = item_type::read(st->back(), is); + if (ptr) { + InsertContainerItem::insert(obj, *ptr, itemN); + delete ptr; + } + return ptr; + } -public: - inline static bool process(Container &obj, Stream &is, State *st, - const std::size_t itemN) { - // By default, we will assume that container starts empty. - // Here, we need to produce a new item. There are 3 options: - // 1) make it on the stack, insert a copy into the container - // 2) make it on the heap, insert a copy, delete original - // 3) the container contains pointers to begin with, so - // we make it on the stack and add a pointer to the container - return process2( - obj, is, st, itemN, - Int2Type()); - } -}; + // Item is not a pointer and not heap-readable. + // Assume that it has a default constructor. + inline static bool process2(Container &obj, Stream &is, State *st, const std::size_t itemN, Int2Type<4>) { + typedef typename StrippedType::type NCType; + NCType item; + NCType *pitem = &item; + bool status = + GenericReader::ISPOINTER>>::process(pitem, is, st, false); + if (status) + InsertContainerItem::insert(obj, item, itemN); + return status; + } -//=================================================================== -// -// Reading things when a pointer is given -// -//=================================================================== -template -struct GenericReader::ISSTDCONTAINER>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, - const bool processClassId) { - if (ptr) - return process_item(*ptr, str, s, processClassId); - else { - CPP11_auto_ptr myptr(new T()); - if (!process_item(*myptr, str, s, processClassId)) - return false; - ptr = myptr.release(); - return true; + public: + inline static bool process(Container &obj, Stream &is, State *st, const std::size_t itemN) { + // By default, we will assume that container starts empty. + // Here, we need to produce a new item. There are 3 options: + // 1) make it on the stack, insert a copy into the container + // 2) make it on the heap, insert a copy, delete original + // 3) the container contains pointers to begin with, so + // we make it on the stack and add a pointer to the container + return process2(obj, + is, + st, + itemN, + Int2Type()); } - } -}; - -template -struct GenericReader::ISHEAPREADABLE>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, - const bool processClassId) { - T *readback = 0; - if (processClassId) { - ClassId id(str, 1); - readback = T::read(id, str); - } else { - assert(!s->empty()); - readback = T::read(s->back(), str); - } - if (readback) { - if (ptr) { - try { - // We will assume here that the "read" - // operation takes precedence over constness - *const_cast::type *>(ptr) = *readback; - } catch (...) { + }; + + //=================================================================== + // + // Reading things when a pointer is given + // + //=================================================================== + template + struct GenericReader::ISSTDCONTAINER>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, const bool processClassId) { + if (ptr) + return process_item(*ptr, str, s, processClassId); + else { + CPP11_auto_ptr myptr(new T()); + if (!process_item(*myptr, str, s, processClassId)) + return false; + ptr = myptr.release(); + return true; + } + } + }; + + template + struct GenericReader::ISHEAPREADABLE>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, const bool processClassId) { + T *readback = 0; + if (processClassId) { + ClassId id(str, 1); + readback = T::read(id, str); + } else { + assert(!s->empty()); + readback = T::read(s->back(), str); + } + if (readback) { + if (ptr) { + try { + // We will assume here that the "read" + // operation takes precedence over constness + *const_cast::type *>(ptr) = *readback; + } catch (...) { + delete readback; + throw; + } delete readback; - throw; - } - delete readback; - } else + } else + ptr = readback; + } + return readback; + } + }; + + template + struct GenericReader::ISPUREHEAPREADABLE>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, const bool processClassId) { + T *readback = nullptr; + if (processClassId) { + ClassId id(str, 1); + readback = T::read(id, str); + } else { + assert(!s->empty()); + readback = T::read(s->back(), str); + } + if (readback) { + assert(!ptr); ptr = readback; + } + return readback; } - return readback; - } -}; - -template -struct GenericReader::ISPUREHEAPREADABLE>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, - const bool processClassId) { - T *readback = nullptr; - if (processClassId) { - ClassId id(str, 1); - readback = T::read(id, str); - } else { - assert(!s->empty()); - readback = T::read(s->back(), str); - } - if (readback) { - assert(!ptr); - ptr = readback; - } - return readback; - } -}; - -template -struct GenericReader::ISPLACEREADABLE>> { - inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, - const bool processClassId) { - CPP11_auto_ptr myptr; - if (ptr == 0) - myptr = CPP11_auto_ptr(new T()); - if (processClassId) { - ClassId id(str, 1); - T::restore(id, str, ptr ? ptr : myptr.get()); - } else { - assert(!s->empty()); - T::restore(s->back(), str, ptr ? ptr : myptr.get()); - } - if (ptr == 0) - ptr = myptr.release(); - return ptr; - } -}; -} // namespace gs + }; + + template + struct GenericReader::ISPLACEREADABLE>> { + inline static bool readIntoPtr(T *&ptr, Stream &str, State *s, const bool processClassId) { + CPP11_auto_ptr myptr; + if (ptr == 0) + myptr = CPP11_auto_ptr(new T()); + if (processClassId) { + ClassId id(str, 1); + T::restore(id, str, ptr ? ptr : myptr.get()); + } else { + assert(!s->empty()); + T::restore(s->back(), str, ptr ? ptr : myptr.get()); + } + if (ptr == 0) + ptr = myptr.release(); + return ptr; + } + }; +} // namespace gs -#endif // GENERS_GENERICIO_HH_ +#endif // GENERS_GENERICIO_HH_ diff --git a/Alignment/Geners/interface/IOException.hh b/Alignment/Geners/interface/IOException.hh index d69013f4743d5..a52c211073c26 100644 --- a/Alignment/Geners/interface/IOException.hh +++ b/Alignment/Geners/interface/IOException.hh @@ -6,118 +6,106 @@ #include "FWCore/Utilities/interface/Exception.h" namespace gs { -/** Base class for the exceptions specific to the Geners I/O library */ -struct IOException : public cms::Exception { - inline IOException() : cms::Exception("gs::IOException") {} + /** Base class for the exceptions specific to the Geners I/O library */ + struct IOException : public cms::Exception { + inline IOException() : cms::Exception("gs::IOException") {} - inline explicit IOException(const std::string &description) - : cms::Exception(description) {} + inline explicit IOException(const std::string &description) : cms::Exception(description) {} - inline explicit IOException(const char *description) - : cms::Exception(description) {} + inline explicit IOException(const char *description) : cms::Exception(description) {} - ~IOException() throw() override {} -}; + ~IOException() throw() override {} + }; -struct IOLengthError : public IOException { - inline IOLengthError() : IOException("gs::IOLengthError") {} + struct IOLengthError : public IOException { + inline IOLengthError() : IOException("gs::IOLengthError") {} - inline explicit IOLengthError(const std::string &description) - : IOException(description) {} + inline explicit IOLengthError(const std::string &description) : IOException(description) {} - ~IOLengthError() throw() override {} -}; + ~IOLengthError() throw() override {} + }; -struct IOOutOfRange : public IOException { - inline IOOutOfRange() : IOException("gs::IOOutOfRange") {} + struct IOOutOfRange : public IOException { + inline IOOutOfRange() : IOException("gs::IOOutOfRange") {} - inline explicit IOOutOfRange(const std::string &description) - : IOException(description) {} + inline explicit IOOutOfRange(const std::string &description) : IOException(description) {} - ~IOOutOfRange() throw() override {} -}; + ~IOOutOfRange() throw() override {} + }; -struct IOInvalidArgument : public IOException { - inline IOInvalidArgument() : IOException("gs::IOInvalidArgument") {} + struct IOInvalidArgument : public IOException { + inline IOInvalidArgument() : IOException("gs::IOInvalidArgument") {} - inline explicit IOInvalidArgument(const std::string &description) - : IOException(description) {} + inline explicit IOInvalidArgument(const std::string &description) : IOException(description) {} - ~IOInvalidArgument() throw() override {} -}; + ~IOInvalidArgument() throw() override {} + }; -/* Automatic replacement end} */ + /* Automatic replacement end} */ -/** + /** // Throw this exception to indicate failure of various stream // opening methods if it is difficult or impossible to clean up // after the failure in the normal flow of control */ -class IOOpeningFailure : public IOException { - inline static std::string - fileOpeningFailure(const std::string &whereInTheCode, - const std::string &filename) { - std::string msg("In "); - msg += whereInTheCode; - msg += ": failed to open file \""; - msg += filename; - msg += "\""; - return msg; - } - -public: - inline IOOpeningFailure() : IOException("gs::IOOpeningFailure") {} - - inline explicit IOOpeningFailure(const std::string &description) - : IOException(description) {} - - inline IOOpeningFailure(const std::string &whereInTheCode, - const std::string &filename) - : IOException(fileOpeningFailure(whereInTheCode, filename)) {} - - ~IOOpeningFailure() throw() override {} -}; - -/** + class IOOpeningFailure : public IOException { + inline static std::string fileOpeningFailure(const std::string &whereInTheCode, const std::string &filename) { + std::string msg("In "); + msg += whereInTheCode; + msg += ": failed to open file \""; + msg += filename; + msg += "\""; + return msg; + } + + public: + inline IOOpeningFailure() : IOException("gs::IOOpeningFailure") {} + + inline explicit IOOpeningFailure(const std::string &description) : IOException(description) {} + + inline IOOpeningFailure(const std::string &whereInTheCode, const std::string &filename) + : IOException(fileOpeningFailure(whereInTheCode, filename)) {} + + ~IOOpeningFailure() throw() override {} + }; + + /** // Throw this exception to indicate failure in the writing process. // For example, fail() method of the output stream returns "true", // and the function is unable to handle this situation locally. */ -struct IOWriteFailure : public IOException { - inline IOWriteFailure() : IOException("gs::IOWriteFailure") {} + struct IOWriteFailure : public IOException { + inline IOWriteFailure() : IOException("gs::IOWriteFailure") {} - inline explicit IOWriteFailure(const std::string &description) - : IOException(description) {} + inline explicit IOWriteFailure(const std::string &description) : IOException(description) {} - ~IOWriteFailure() throw() override {} -}; + ~IOWriteFailure() throw() override {} + }; -/** + /** // Throw this exception to indicate failure in the reading process. // For example, fail() method of the input stream returns "true", // and the function is unable to handle this situation locally. */ -struct IOReadFailure : public IOException { - inline IOReadFailure() : IOException("gs::IOReadFailure") {} + struct IOReadFailure : public IOException { + inline IOReadFailure() : IOException("gs::IOReadFailure") {} - inline explicit IOReadFailure(const std::string &description) - : IOException(description) {} + inline explicit IOReadFailure(const std::string &description) : IOException(description) {} - ~IOReadFailure() throw() override {} -}; + ~IOReadFailure() throw() override {} + }; -/** + /** // Throw this exception when improperly formatted or invalid data // is detected */ -struct IOInvalidData : public IOException { - inline IOInvalidData() : IOException("gs::IOInvalidData") {} + struct IOInvalidData : public IOException { + inline IOInvalidData() : IOException("gs::IOInvalidData") {} - inline explicit IOInvalidData(const std::string &description) - : IOException(description) {} + inline explicit IOInvalidData(const std::string &description) : IOException(description) {} - ~IOInvalidData() throw() override {} -}; -} // namespace gs + ~IOInvalidData() throw() override {} + }; +} // namespace gs -#endif // GENERS_IOEXCEPTION_HH_ +#endif // GENERS_IOEXCEPTION_HH_ diff --git a/Alignment/Geners/interface/IOIsAnyPtr.hh b/Alignment/Geners/interface/IOIsAnyPtr.hh index fb057bf3ac1b6..f23c0c4aa36a1 100644 --- a/Alignment/Geners/interface/IOIsAnyPtr.hh +++ b/Alignment/Geners/interface/IOIsAnyPtr.hh @@ -6,12 +6,12 @@ #include "Alignment/Geners/interface/IOIsSharedPtr.hh" namespace gs { -// Here we are taking into account only the types of pointers -// known to the I/O system -template struct IOIsAnyPtr { - static const bool value = (CPP11_is_pointer::value || - IOIsSharedPtr::value || IOIsIOPtr::value); -}; -} // namespace gs + // Here we are taking into account only the types of pointers + // known to the I/O system + template + struct IOIsAnyPtr { + static const bool value = (CPP11_is_pointer::value || IOIsSharedPtr::value || IOIsIOPtr::value); + }; +} // namespace gs -#endif // GENERS_IOISANYPTR_HH_ +#endif // GENERS_IOISANYPTR_HH_ diff --git a/Alignment/Geners/interface/IOIsClassType.hh b/Alignment/Geners/interface/IOIsClassType.hh index 4d274b525e264..a9d1968110c80 100644 --- a/Alignment/Geners/interface/IOIsClassType.hh +++ b/Alignment/Geners/interface/IOIsClassType.hh @@ -2,17 +2,20 @@ #define GENERS_IOISCLASSTYPE_HH_ namespace gs { -template class IOIsClassType { - typedef char One; - typedef struct { - char a[2]; - } Two; - template static One test(int C::*); - template static Two test(...); + template + class IOIsClassType { + typedef char One; + typedef struct { + char a[2]; + } Two; + template + static One test(int C::*); + template + static Two test(...); -public: - enum { value = sizeof(IOIsClassType::template test(nullptr)) == 1 }; -}; -} // namespace gs + public: + enum { value = sizeof(IOIsClassType::template test(nullptr)) == 1 }; + }; +} // namespace gs -#endif // GENERS_IOISCLASSTYPE_HH_ +#endif // GENERS_IOISCLASSTYPE_HH_ diff --git a/Alignment/Geners/interface/IOIsContainer.hh b/Alignment/Geners/interface/IOIsContainer.hh index 223bdcd24cf62..2986195dae50c 100644 --- a/Alignment/Geners/interface/IOIsContainer.hh +++ b/Alignment/Geners/interface/IOIsContainer.hh @@ -4,41 +4,48 @@ #include namespace gs { -// In the following template, enum "IsContainer" is evaluated to 1 -// at compile time if T has T::value_type typedef -template class IOIsContainer { -private: - typedef char One; - typedef struct { - char a[2]; - } Two; - template static One test(typename C::value_type const *); - template static Two test(...); - -public: - enum { value = sizeof(IOIsContainer::template test(0)) == 1 }; -}; - -// Char strings get a special treatment -template <> class IOIsContainer { -public: - enum { value = 0 }; -}; - -template <> class IOIsContainer { -public: - enum { value = 0 }; -}; - -template <> class IOIsContainer { -public: - enum { value = 0 }; -}; - -template <> class IOIsContainer { -public: - enum { value = 0 }; -}; -} // namespace gs - -#endif // GENERS_IOISCONTAINER_HH_ + // In the following template, enum "IsContainer" is evaluated to 1 + // at compile time if T has T::value_type typedef + template + class IOIsContainer { + private: + typedef char One; + typedef struct { + char a[2]; + } Two; + template + static One test(typename C::value_type const *); + template + static Two test(...); + + public: + enum { value = sizeof(IOIsContainer::template test(0)) == 1 }; + }; + + // Char strings get a special treatment + template <> + class IOIsContainer { + public: + enum { value = 0 }; + }; + + template <> + class IOIsContainer { + public: + enum { value = 0 }; + }; + + template <> + class IOIsContainer { + public: + enum { value = 0 }; + }; + + template <> + class IOIsContainer { + public: + enum { value = 0 }; + }; +} // namespace gs + +#endif // GENERS_IOISCONTAINER_HH_ diff --git a/Alignment/Geners/interface/IOIsContiguous.hh b/Alignment/Geners/interface/IOIsContiguous.hh index d3cfce7eab7a9..779ad3ad6df40 100644 --- a/Alignment/Geners/interface/IOIsContiguous.hh +++ b/Alignment/Geners/interface/IOIsContiguous.hh @@ -5,71 +5,77 @@ #include namespace gs { -template struct IOIsContiguous { - enum { value = 0 }; -}; + template + struct IOIsContiguous { + enum { value = 0 }; + }; -// String is treated as a pod vector. This will be guaranteed -// to work correctly in the C++11 standard. The current standard -// does not specify that the characters must be stored contuguously -// inside the string -- however, this is always true in practice. -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + // String is treated as a pod vector. This will be guaranteed + // to work correctly in the C++11 standard. The current standard + // does not specify that the characters must be stored contuguously + // inside the string -- however, this is always true in practice. + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -// std::vector is used by the package everywhere. No point in not -// having it here. -template struct IOIsContiguous> { - enum { value = 1 }; -}; + // std::vector is used by the package everywhere. No point in not + // having it here. + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -template -struct IOIsContiguous> { - enum { value = 1 }; -}; + template + struct IOIsContiguous> { + enum { value = 1 }; + }; -// Hovever, std::vector should be excluded -template <> struct IOIsContiguous> { - enum { value = 0 }; -}; + // Hovever, std::vector should be excluded + template <> + struct IOIsContiguous> { + enum { value = 0 }; + }; -template <> struct IOIsContiguous> { - enum { value = 0 }; -}; + template <> + struct IOIsContiguous> { + enum { value = 0 }; + }; -template <> struct IOIsContiguous> { - enum { value = 0 }; -}; + template <> + struct IOIsContiguous> { + enum { value = 0 }; + }; -template <> struct IOIsContiguous> { - enum { value = 0 }; -}; -} // namespace gs + template <> + struct IOIsContiguous> { + enum { value = 0 }; + }; +} // namespace gs -#endif // GENERS_IOISCONTIGUOUS_HH_ +#endif // GENERS_IOISCONTIGUOUS_HH_ diff --git a/Alignment/Geners/interface/IOIsExternal.hh b/Alignment/Geners/interface/IOIsExternal.hh index 6e130ce6b9683..c46a0c43b3d55 100644 --- a/Alignment/Geners/interface/IOIsExternal.hh +++ b/Alignment/Geners/interface/IOIsExternal.hh @@ -2,68 +2,81 @@ #define GENERS_IOISEXTERNAL_HH_ namespace gs { -template struct IOIsExternal { - enum { value = 0 }; -}; -} // namespace gs + template + struct IOIsExternal { + enum { value = 0 }; + }; +} // namespace gs // Use the following macro (outside of any namespace) // to declare some type as external for I/O purposes // -#define gs_declare_type_external(T) /**/ \ - namespace gs { \ - template <> struct IOIsExternal { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsExternal { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsExternal { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsExternal { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_type_external(T) /**/ \ + namespace gs { \ + template <> \ + struct IOIsExternal { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsExternal { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsExternal { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsExternal { \ + enum { value = 1 }; \ + }; \ } // Use the following macro (outside of any namespace) // to declare some template parameterized by one argument // as external for I/O purposes // -#define gs_declare_template_external_T(name) /**/ \ - namespace gs { \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_template_external_T(name) /**/ \ + namespace gs { \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ } // Use the following macro (outside of any namespace) // to declare some template parameterized by two arguments // as external for I/O purposes // -#define gs_declare_template_external_TT(name) /**/ \ - namespace gs { \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ - template struct IOIsExternal> { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_template_external_TT(name) /**/ \ + namespace gs { \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ + template \ + struct IOIsExternal> { \ + enum { value = 1 }; \ + }; \ } -#endif // GENERS_IOISEXTERNAL_HH_ +#endif // GENERS_IOISEXTERNAL_HH_ diff --git a/Alignment/Geners/interface/IOIsIOPtr.hh b/Alignment/Geners/interface/IOIsIOPtr.hh index d887bf4a5e2ca..7da2fd68b0edf 100644 --- a/Alignment/Geners/interface/IOIsIOPtr.hh +++ b/Alignment/Geners/interface/IOIsIOPtr.hh @@ -4,41 +4,50 @@ #include "Alignment/Geners/interface/IOPtr.hh" namespace gs { -template struct IOIsIOPtr { - enum { value = 0 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; - -template struct IOIsIOPtr> { - enum { value = 1 }; -}; -} // namespace gs - -#endif // GENERS_IOISIOPTR_HH_ + template + struct IOIsIOPtr { + enum { value = 0 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; + + template + struct IOIsIOPtr> { + enum { value = 1 }; + }; +} // namespace gs + +#endif // GENERS_IOISIOPTR_HH_ diff --git a/Alignment/Geners/interface/IOIsNumber.hh b/Alignment/Geners/interface/IOIsNumber.hh index 1b7ebe705cec9..7b8732665da77 100644 --- a/Alignment/Geners/interface/IOIsNumber.hh +++ b/Alignment/Geners/interface/IOIsNumber.hh @@ -2,37 +2,37 @@ #define GENERS_IOISNUMBER_HH_ namespace gs { -template struct IOIsNumber { - enum { value = 0 }; -}; -} // namespace gs + template + struct IOIsNumber { + enum { value = 0 }; + }; +} // namespace gs -#define gs_declare_type_as_number(T) /**/ \ - namespace gs { \ - template <> struct IOIsNumber { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsNumber { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsNumber { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsNumber { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_type_as_number(T) /**/ \ + namespace gs { \ + template <> \ + struct IOIsNumber { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsNumber { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsNumber { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsNumber { \ + enum { value = 1 }; \ + }; \ } -gs_declare_type_as_number(float) gs_declare_type_as_number(double) - gs_declare_type_as_number(long double) gs_declare_type_as_number(int) - gs_declare_type_as_number(unsigned) gs_declare_type_as_number(long) - gs_declare_type_as_number(long long) - gs_declare_type_as_number(unsigned long) - gs_declare_type_as_number(unsigned long long) - gs_declare_type_as_number(short) - gs_declare_type_as_number(unsigned short) - gs_declare_type_as_number(char) - gs_declare_type_as_number(unsigned char) - gs_declare_type_as_number(signed char) +gs_declare_type_as_number(float) gs_declare_type_as_number(double) gs_declare_type_as_number(long double) + gs_declare_type_as_number(int) gs_declare_type_as_number(unsigned) gs_declare_type_as_number(long) + gs_declare_type_as_number(long long) gs_declare_type_as_number(unsigned long) + gs_declare_type_as_number(unsigned long long) gs_declare_type_as_number(short) + gs_declare_type_as_number(unsigned short) gs_declare_type_as_number(char) + gs_declare_type_as_number(unsigned char) gs_declare_type_as_number(signed char) -#endif // GENERS_IOISNUMBER_HH_ +#endif // GENERS_IOISNUMBER_HH_ diff --git a/Alignment/Geners/interface/IOIsPOD.hh b/Alignment/Geners/interface/IOIsPOD.hh index c158d5bb9e9e9..84d9ebf624267 100644 --- a/Alignment/Geners/interface/IOIsPOD.hh +++ b/Alignment/Geners/interface/IOIsPOD.hh @@ -4,30 +4,35 @@ #include "Alignment/Geners/interface/CPP11_type_traits.hh" namespace gs { -// In the following template, enum "IsPOD" is evaluated to 1 -// at compile time if T belongs to one of the known POD types. -template struct IOIsPOD { - enum { value = CPP11_is_pod::value }; -}; -} // namespace gs + // In the following template, enum "IsPOD" is evaluated to 1 + // at compile time if T belongs to one of the known POD types. + template + struct IOIsPOD { + enum { value = CPP11_is_pod::value }; + }; +} // namespace gs // Use the following macro (outside of any namespace) // to declare some struct as POD for I/O purposes // -#define gs_declare_type_as_pod(T) /**/ \ - namespace gs { \ - template <> struct IOIsPOD { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsPOD { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsPOD { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsPOD { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_type_as_pod(T) /**/ \ + namespace gs { \ + template <> \ + struct IOIsPOD { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsPOD { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsPOD { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsPOD { \ + enum { value = 1 }; \ + }; \ } -#endif // GENERS_IOISPOD_HH_ +#endif // GENERS_IOISPOD_HH_ diff --git a/Alignment/Geners/interface/IOIsPair.hh b/Alignment/Geners/interface/IOIsPair.hh index 6fb8e1580e4f2..9b9e3b1f8ed44 100644 --- a/Alignment/Geners/interface/IOIsPair.hh +++ b/Alignment/Geners/interface/IOIsPair.hh @@ -4,13 +4,15 @@ #include namespace gs { -template struct IOIsPair { - enum { value = 0 }; -}; + template + struct IOIsPair { + enum { value = 0 }; + }; -template struct IOIsPair> { - enum { value = 1 }; -}; -} // namespace gs + template + struct IOIsPair> { + enum { value = 1 }; + }; +} // namespace gs -#endif // GENERS_IOISPAIR_HH_ +#endif // GENERS_IOISPAIR_HH_ diff --git a/Alignment/Geners/interface/IOIsReadable.hh b/Alignment/Geners/interface/IOIsReadable.hh index f63f5a116c24f..7dbabe2ffbb28 100644 --- a/Alignment/Geners/interface/IOIsReadable.hh +++ b/Alignment/Geners/interface/IOIsReadable.hh @@ -6,57 +6,61 @@ #include "Alignment/Geners/interface/StrippedType.hh" namespace gs { -template class IOIsHeapReadableHelper { -private: - template struct tester; - typedef char One; - typedef struct { - char a[2]; - } Two; - template static One test(tester<&C::read> *); - template static Two test(...); - -public: - enum { - value = sizeof(IOIsHeapReadableHelper::template test(nullptr)) == 1 + template + class IOIsHeapReadableHelper { + private: + template + struct tester; + typedef char One; + typedef struct { + char a[2]; + } Two; + template + static One test(tester<&C::read> *); + template + static Two test(...); + + public: + enum { value = sizeof(IOIsHeapReadableHelper::template test(nullptr)) == 1 }; + }; + + template ::value> + struct IOIsHeapReadable { + enum { value = 0 }; + }; + + template + struct IOIsHeapReadable { + enum { value = IOIsHeapReadableHelper::type>::value }; }; -}; -template ::value> -struct IOIsHeapReadable { - enum { value = 0 }; -}; + template + class IOIsPlaceReadableHelper { + private: + template + struct tester; + typedef char One; + typedef struct { + char a[2]; + } Two; + template + static One test(tester<&C::restore> *); + template + static Two test(...); + + public: + enum { value = sizeof(IOIsPlaceReadableHelper::template test(0)) == 1 }; + }; -template struct IOIsHeapReadable { - enum { - value = IOIsHeapReadableHelper::type>::value + template ::value> + struct IOIsPlaceReadable { + enum { value = 0 }; }; -}; - -template class IOIsPlaceReadableHelper { -private: - template struct tester; - typedef char One; - typedef struct { - char a[2]; - } Two; - template static One test(tester<&C::restore> *); - template static Two test(...); - -public: - enum { value = sizeof(IOIsPlaceReadableHelper::template test(0)) == 1 }; -}; - -template ::value> -struct IOIsPlaceReadable { - enum { value = 0 }; -}; - -template struct IOIsPlaceReadable { - enum { - value = IOIsPlaceReadableHelper::type>::value + + template + struct IOIsPlaceReadable { + enum { value = IOIsPlaceReadableHelper::type>::value }; }; -}; -} // namespace gs +} // namespace gs -#endif // GENERS_IOISREADABLE_HH_ +#endif // GENERS_IOISREADABLE_HH_ diff --git a/Alignment/Geners/interface/IOIsSharedPtr.hh b/Alignment/Geners/interface/IOIsSharedPtr.hh index b43bf25344247..93d419f940aa4 100644 --- a/Alignment/Geners/interface/IOIsSharedPtr.hh +++ b/Alignment/Geners/interface/IOIsSharedPtr.hh @@ -4,25 +4,30 @@ #include "Alignment/Geners/interface/CPP11_shared_ptr.hh" namespace gs { -template struct IOIsSharedPtr { - enum { value = 0 }; -}; + template + struct IOIsSharedPtr { + enum { value = 0 }; + }; -template struct IOIsSharedPtr> { - enum { value = 1 }; -}; + template + struct IOIsSharedPtr> { + enum { value = 1 }; + }; -template struct IOIsSharedPtr> { - enum { value = 1 }; -}; + template + struct IOIsSharedPtr> { + enum { value = 1 }; + }; -template struct IOIsSharedPtr> { - enum { value = 1 }; -}; + template + struct IOIsSharedPtr> { + enum { value = 1 }; + }; -template struct IOIsSharedPtr> { - enum { value = 1 }; -}; -} // namespace gs + template + struct IOIsSharedPtr> { + enum { value = 1 }; + }; +} // namespace gs -#endif // GENERS_IOISSHAREDPTR_HH_ +#endif // GENERS_IOISSHAREDPTR_HH_ diff --git a/Alignment/Geners/interface/IOIsString.hh b/Alignment/Geners/interface/IOIsString.hh index 89d30823b576e..415312219c2be 100644 --- a/Alignment/Geners/interface/IOIsString.hh +++ b/Alignment/Geners/interface/IOIsString.hh @@ -4,25 +4,30 @@ #include namespace gs { -template struct IOIsString { - enum { value = 0 }; -}; + template + struct IOIsString { + enum { value = 0 }; + }; -template <> struct IOIsString { - enum { value = 1 }; -}; + template <> + struct IOIsString { + enum { value = 1 }; + }; -template <> struct IOIsString { - enum { value = 1 }; -}; + template <> + struct IOIsString { + enum { value = 1 }; + }; -template <> struct IOIsString { - enum { value = 1 }; -}; + template <> + struct IOIsString { + enum { value = 1 }; + }; -template <> struct IOIsString { - enum { value = 1 }; -}; -} // namespace gs + template <> + struct IOIsString { + enum { value = 1 }; + }; +} // namespace gs -#endif // GENERS_IOISSTRING_HH_ +#endif // GENERS_IOISSTRING_HH_ diff --git a/Alignment/Geners/interface/IOIsTuple.hh b/Alignment/Geners/interface/IOIsTuple.hh index 9695fa318ae5f..e8b20aca7b9e6 100644 --- a/Alignment/Geners/interface/IOIsTuple.hh +++ b/Alignment/Geners/interface/IOIsTuple.hh @@ -2,9 +2,10 @@ #define GENERS_IOISTUPLE_HH_ namespace gs { -template struct IOIsTuple { - enum { value = 0 }; -}; -} // namespace gs + template + struct IOIsTuple { + enum { value = 0 }; + }; +} // namespace gs -#endif // GENERS_IOISTUPLE_HH_ +#endif // GENERS_IOISTUPLE_HH_ diff --git a/Alignment/Geners/interface/IOIsUnsigned.hh b/Alignment/Geners/interface/IOIsUnsigned.hh index 18d8fd616ca34..ded98d149c84c 100644 --- a/Alignment/Geners/interface/IOIsUnsigned.hh +++ b/Alignment/Geners/interface/IOIsUnsigned.hh @@ -2,31 +2,34 @@ #define GENERS_IOISUNSIGNED_HH_ namespace gs { -template struct IOIsUnsigned { - enum { value = 0 }; -}; -} // namespace gs + template + struct IOIsUnsigned { + enum { value = 0 }; + }; +} // namespace gs -#define gs_declare_type_as_unsigned(T) /**/ \ - namespace gs { \ - template <> struct IOIsUnsigned { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsUnsigned { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsUnsigned { \ - enum { value = 1 }; \ - }; \ - template <> struct IOIsUnsigned { \ - enum { value = 1 }; \ - }; \ +#define gs_declare_type_as_unsigned(T) /**/ \ + namespace gs { \ + template <> \ + struct IOIsUnsigned { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsUnsigned { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsUnsigned { \ + enum { value = 1 }; \ + }; \ + template <> \ + struct IOIsUnsigned { \ + enum { value = 1 }; \ + }; \ } -gs_declare_type_as_unsigned(unsigned char) - gs_declare_type_as_unsigned(unsigned short) - gs_declare_type_as_unsigned(unsigned int) - gs_declare_type_as_unsigned(unsigned long) - gs_declare_type_as_unsigned(unsigned long long) +gs_declare_type_as_unsigned(unsigned char) gs_declare_type_as_unsigned(unsigned short) + gs_declare_type_as_unsigned(unsigned int) gs_declare_type_as_unsigned(unsigned long) + gs_declare_type_as_unsigned(unsigned long long) -#endif // GENERS_IOISUNSIGNED_HH_ +#endif // GENERS_IOISUNSIGNED_HH_ diff --git a/Alignment/Geners/interface/IOIsWritable.hh b/Alignment/Geners/interface/IOIsWritable.hh index 6757cdf6c46cb..6a7b4d00620b1 100644 --- a/Alignment/Geners/interface/IOIsWritable.hh +++ b/Alignment/Geners/interface/IOIsWritable.hh @@ -6,30 +6,33 @@ #include namespace gs { -template class IOIsWritableHelper { -private: - template struct tester; - typedef char One; - typedef struct { - char a[2]; - } Two; - template static One test(tester<&C::write> *); - template static Two test(...); + template + class IOIsWritableHelper { + private: + template + struct tester; + typedef char One; + typedef struct { + char a[2]; + } Two; + template + static One test(tester<&C::write> *); + template + static Two test(...); -public: - enum { - value = sizeof(IOIsWritableHelper::template test(nullptr)) == 1 + public: + enum { value = sizeof(IOIsWritableHelper::template test(nullptr)) == 1 }; }; -}; -template ::value> -struct IOIsWritable { - enum { value = 0 }; -}; + template ::value> + struct IOIsWritable { + enum { value = 0 }; + }; -template struct IOIsWritable { - enum { value = IOIsWritableHelper::value }; -}; -} // namespace gs + template + struct IOIsWritable { + enum { value = IOIsWritableHelper::value }; + }; +} // namespace gs -#endif // GENERS_IOISWRITABLE_HH_ +#endif // GENERS_IOISWRITABLE_HH_ diff --git a/Alignment/Geners/interface/IOPointeeType.hh b/Alignment/Geners/interface/IOPointeeType.hh index 4479aa04bad49..70de6579a104e 100644 --- a/Alignment/Geners/interface/IOPointeeType.hh +++ b/Alignment/Geners/interface/IOPointeeType.hh @@ -2,17 +2,28 @@ #define GENERS_IOPOINTEETYPE_HH_ namespace gs { -template struct IOPointeeType; + template + struct IOPointeeType; -template struct IOPointeeType { typedef T type; }; + template + struct IOPointeeType { + typedef T type; + }; -template struct IOPointeeType { typedef T type; }; + template + struct IOPointeeType { + typedef T type; + }; -template struct IOPointeeType { typedef T type; }; + template + struct IOPointeeType { + typedef T type; + }; -template struct IOPointeeType { - typedef T type; -}; -} // namespace gs + template + struct IOPointeeType { + typedef T type; + }; +} // namespace gs -#endif // GENERS_IOPOINTEETYPE_HH_ +#endif // GENERS_IOPOINTEETYPE_HH_ diff --git a/Alignment/Geners/interface/IOPtr.hh b/Alignment/Geners/interface/IOPtr.hh index 64178135bc329..94b69a38dcaba 100644 --- a/Alignment/Geners/interface/IOPtr.hh +++ b/Alignment/Geners/interface/IOPtr.hh @@ -6,196 +6,197 @@ // "Silent" pointers for the I/O system namespace gs { -template class IOProxy; - -template class IOPtr { - template friend class IOProxy; - -public: - typedef T element_type; - - inline IOPtr() : ptr_(0) {} - inline IOPtr(T *ptr) : ptr_(ptr) {} - IOPtr(const IOProxy &p); - - IOPtr &operator=(const IOProxy &p); - inline IOPtr &operator=(const IOPtr &p) { - ptr_ = p.ptr_; - return *this; + template + class IOProxy; + + template + class IOPtr { + template + friend class IOProxy; + + public: + typedef T element_type; + + inline IOPtr() : ptr_(0) {} + inline IOPtr(T *ptr) : ptr_(ptr) {} + IOPtr(const IOProxy &p); + + IOPtr &operator=(const IOProxy &p); + inline IOPtr &operator=(const IOPtr &p) { + ptr_ = p.ptr_; + return *this; + } + + // Typical pointer operations + inline T *get() const { return ptr_; } + inline T *operator->() const { + if (!ptr_) + throw gs::IOInvalidArgument("In gs::IOPtr::operator->: attempt to dereference null pointer"); + return ptr_; + } + inline T &operator*() const { + if (!ptr_) + throw gs::IOInvalidArgument("In gs::IOPtr::operator*: attempt to dereference null pointer"); + return *ptr_; + } + inline IOPtr &operator++() { + ++ptr_; + return *this; + } + inline void operator++(int) { ++ptr_; } + inline IOPtr &operator--() { + --ptr_; + return *this; + } + inline void operator--(int) { --ptr_; } + + // Implicit conversion to "bool" + inline operator bool() const { return !(ptr_ == 0); } + + // Names are ignored during comparisons + inline bool operator==(const IOPtr &r) const { return ptr_ == r.ptr_; } + inline bool operator!=(const IOPtr &r) const { return ptr_ != r.ptr_; } + bool operator==(const IOProxy &r) const; + bool operator!=(const IOProxy &r) const; + + // Should be able to work as with bare pointer inside the I/O code + inline T *&getIOReference() { return ptr_; } + inline T *const &getIOReference() const { + if (!ptr_) + throw gs::IOInvalidArgument( + "In gs::IOPtr::getIOReference: unusable " + "const reference to null pointer"); + return ptr_; + } + + private: + T *ptr_; + }; + + template + class IOProxy { + template + friend class IOPtr; + + public: + typedef T element_type; + + inline IOProxy() : ptr_(0) {} + inline IOProxy(T *ptr) : ptr_(ptr) {} + inline IOProxy(T *ptr, const char *varname) : ptr_(ptr), name_(varname ? varname : "") {} + inline IOProxy(T *ptr, const std::string &varname) : ptr_(ptr), name_(varname) {} + inline IOProxy(const IOPtr &p) : ptr_(p.ptr_) {} + inline IOProxy(const IOPtr &p, const char *varname) : ptr_(p.ptr_), name_(varname ? varname : "") {} + inline IOProxy(const IOPtr &p, const std::string &varname) : ptr_(p.ptr_), name_(varname) {} + + inline IOProxy &operator=(const IOProxy &p) { + ptr_ = p.ptr_; + name_ = p.name_; + return *this; + } + inline IOProxy &operator=(const IOPtr &p) { + ptr_ = p.ptr_; + name_ = ""; + return *this; + } + + // Get name + inline const std::string &name() const { return name_; } + + // Set name + inline IOProxy &setName(const char *varname) { + name_ = varname ? varname : ""; + return *this; + } + inline IOProxy &setName(const std::string &varname) { + name_ = varname; + return *this; + } + + // Typical pointer operations + inline T *get() const { return ptr_; } + inline T *operator->() const { + if (!ptr_) + throw gs::IOInvalidArgument("In gs::IOProxy::operator->: attempt to dereference null pointer"); + return ptr_; + } + inline T &operator*() const { + if (!ptr_) + throw gs::IOInvalidArgument("In gs::IOProxy::operator*: attempt to dereference null pointer"); + return *ptr_; + } + inline IOProxy &operator++() { + ++ptr_; + return *this; + } + inline void operator++(int) { ++ptr_; } + inline IOProxy &operator--() { + --ptr_; + return *this; + } + inline void operator--(int) { --ptr_; } + + // Implicit conversion to "bool" + inline operator bool() const { return !(ptr_ == 0); } + + // Names are ignored during comparisons + inline bool operator==(const IOProxy &r) const { return ptr_ == r.ptr_; } + inline bool operator!=(const IOProxy &r) const { return ptr_ != r.ptr_; } + inline bool operator==(const IOPtr &r) const { return ptr_ == r.ptr_; } + inline bool operator!=(const IOPtr &r) const { return ptr_ != r.ptr_; } + + // Should be able to work as with bare pointer inside the I/O code + inline T *&getIOReference() { return ptr_; } + inline T *const &getIOReference() const { + if (!ptr_) + throw gs::IOInvalidArgument( + "In gs::IOProxy::getIOReference: unusable " + "const reference to null pointer"); + return ptr_; + } + + private: + T *ptr_; + std::string name_; + }; + + // Convenience function for making IOPtr objects + template + inline IOPtr make_IOPtr(T &obj) { + return IOPtr(&obj); } - // Typical pointer operations - inline T *get() const { return ptr_; } - inline T *operator->() const { - if (!ptr_) - throw gs::IOInvalidArgument( - "In gs::IOPtr::operator->: attempt to dereference null pointer"); - return ptr_; - } - inline T &operator*() const { - if (!ptr_) - throw gs::IOInvalidArgument( - "In gs::IOPtr::operator*: attempt to dereference null pointer"); - return *ptr_; - } - inline IOPtr &operator++() { - ++ptr_; - return *this; - } - inline void operator++(int) { ++ptr_; } - inline IOPtr &operator--() { - --ptr_; - return *this; - } - inline void operator--(int) { --ptr_; } - - // Implicit conversion to "bool" - inline operator bool() const { return !(ptr_ == 0); } - - // Names are ignored during comparisons - inline bool operator==(const IOPtr &r) const { return ptr_ == r.ptr_; } - inline bool operator!=(const IOPtr &r) const { return ptr_ != r.ptr_; } - bool operator==(const IOProxy &r) const; - bool operator!=(const IOProxy &r) const; - - // Should be able to work as with bare pointer inside the I/O code - inline T *&getIOReference() { return ptr_; } - inline T *const &getIOReference() const { - if (!ptr_) - throw gs::IOInvalidArgument("In gs::IOPtr::getIOReference: unusable " - "const reference to null pointer"); - return ptr_; + // In the user code, the following function can be usually wrapped + // as follows: + // + // #define io_proxy(obj) gs::make_IOProxy( obj , #obj ) + // + template + inline IOProxy make_IOProxy(T &obj, const char *name) { + return IOProxy(&obj, name); } +} // namespace gs -private: - T *ptr_; -}; - -template class IOProxy { - template friend class IOPtr; - -public: - typedef T element_type; - - inline IOProxy() : ptr_(0) {} - inline IOProxy(T *ptr) : ptr_(ptr) {} - inline IOProxy(T *ptr, const char *varname) - : ptr_(ptr), name_(varname ? varname : "") {} - inline IOProxy(T *ptr, const std::string &varname) - : ptr_(ptr), name_(varname) {} - inline IOProxy(const IOPtr &p) : ptr_(p.ptr_) {} - inline IOProxy(const IOPtr &p, const char *varname) - : ptr_(p.ptr_), name_(varname ? varname : "") {} - inline IOProxy(const IOPtr &p, const std::string &varname) - : ptr_(p.ptr_), name_(varname) {} - - inline IOProxy &operator=(const IOProxy &p) { - ptr_ = p.ptr_; - name_ = p.name_; - return *this; - } - inline IOProxy &operator=(const IOPtr &p) { +// IOPtr methods which could not be defined earlier +namespace gs { + template + inline IOPtr::IOPtr(const IOProxy &p) : ptr_(p.ptr_) {} + + template + inline IOPtr &IOPtr::operator=(const IOProxy &p) { ptr_ = p.ptr_; - name_ = ""; return *this; } - // Get name - inline const std::string &name() const { return name_; } - - // Set name - inline IOProxy &setName(const char *varname) { - name_ = varname ? varname : ""; - return *this; - } - inline IOProxy &setName(const std::string &varname) { - name_ = varname; - return *this; + template + inline bool IOPtr::operator==(const IOProxy &r) const { + return ptr_ == r.ptr_; } - // Typical pointer operations - inline T *get() const { return ptr_; } - inline T *operator->() const { - if (!ptr_) - throw gs::IOInvalidArgument( - "In gs::IOProxy::operator->: attempt to dereference null pointer"); - return ptr_; - } - inline T &operator*() const { - if (!ptr_) - throw gs::IOInvalidArgument( - "In gs::IOProxy::operator*: attempt to dereference null pointer"); - return *ptr_; - } - inline IOProxy &operator++() { - ++ptr_; - return *this; - } - inline void operator++(int) { ++ptr_; } - inline IOProxy &operator--() { - --ptr_; - return *this; - } - inline void operator--(int) { --ptr_; } - - // Implicit conversion to "bool" - inline operator bool() const { return !(ptr_ == 0); } - - // Names are ignored during comparisons - inline bool operator==(const IOProxy &r) const { return ptr_ == r.ptr_; } - inline bool operator!=(const IOProxy &r) const { return ptr_ != r.ptr_; } - inline bool operator==(const IOPtr &r) const { return ptr_ == r.ptr_; } - inline bool operator!=(const IOPtr &r) const { return ptr_ != r.ptr_; } - - // Should be able to work as with bare pointer inside the I/O code - inline T *&getIOReference() { return ptr_; } - inline T *const &getIOReference() const { - if (!ptr_) - throw gs::IOInvalidArgument("In gs::IOProxy::getIOReference: unusable " - "const reference to null pointer"); - return ptr_; + template + inline bool IOPtr::operator!=(const IOProxy &r) const { + return ptr_ != r.ptr_; } +} // namespace gs -private: - T *ptr_; - std::string name_; -}; - -// Convenience function for making IOPtr objects -template inline IOPtr make_IOPtr(T &obj) { - return IOPtr(&obj); -} - -// In the user code, the following function can be usually wrapped -// as follows: -// -// #define io_proxy(obj) gs::make_IOProxy( obj , #obj ) -// -template inline IOProxy make_IOProxy(T &obj, const char *name) { - return IOProxy(&obj, name); -} -} // namespace gs - -// IOPtr methods which could not be defined earlier -namespace gs { -template -inline IOPtr::IOPtr(const IOProxy &p) : ptr_(p.ptr_) {} - -template -inline IOPtr &IOPtr::operator=(const IOProxy &p) { - ptr_ = p.ptr_; - return *this; -} - -template -inline bool IOPtr::operator==(const IOProxy &r) const { - return ptr_ == r.ptr_; -} - -template -inline bool IOPtr::operator!=(const IOProxy &r) const { - return ptr_ != r.ptr_; -} -} // namespace gs - -#endif // GENERS_IOPTR_HH_ +#endif // GENERS_IOPTR_HH_ diff --git a/Alignment/Geners/interface/IOTraits.hh b/Alignment/Geners/interface/IOTraits.hh index f104d7ebcd2fa..7c64ee549b2f5 100644 --- a/Alignment/Geners/interface/IOTraits.hh +++ b/Alignment/Geners/interface/IOTraits.hh @@ -17,109 +17,97 @@ #include "Alignment/Geners/interface/IOIsWritable.hh" namespace gs { -template struct IOTraits { - static const bool IsClass = IOIsClassType::value; - enum { ISCLASS = 1 }; - - // Pointers are not PODs for I/O purposes. - // - // It looks like std::array of PODs is itself considered - // a POD by the "CPP11_is_pod" template, at least by some - // g++ versions (in particular, 4.4.5). This is a bug/feature - // that we need to avoid. - static const bool IsPOD = - (IOIsPOD::value && !IOIsContainer::value && - !CPP11_is_pointer::value && !IOIsExternal::value); - enum { ISPOD = 2 }; - - static const bool IsWritable = - (IOIsWritable::value && !IOIsExternal::value); - enum { ISWRITABLE = 4 }; - - static const bool IsStdContainer = - (IOIsContainer::value && !IOIsWritable::value && - !IOIsExternal::value); - enum { ISSTDCONTAINER = 8 }; - - // Readable objects are required to be writable - static const bool IsPlaceReadable = - (IOIsPlaceReadable::value && IOIsWritable::value); - enum { ISPLACEREADABLE = 16 }; - - // Prefer place readability to heap readability - static const bool IsHeapReadable = - (IOIsHeapReadable::value && !IOIsPlaceReadable::value && - IOIsWritable::value); - enum { ISHEAPREADABLE = 32 }; - - static const bool IsPointer = - (CPP11_is_pointer::value && !IOIsExternal::value); - enum { ISPOINTER = 64 }; - - static const bool IsSharedPtr = - (IOIsSharedPtr::value && !IOIsExternal::value); - enum { ISSHAREDPTR = 128 }; - - static const bool IsPair = IOIsPair::value; - enum { ISPAIR = 256 }; - - static const bool IsString = IOIsString::value; - enum { ISSTRING = 512 }; - - // The following trait is relevant for containers only - static const bool IsContiguous = IOIsContiguous::value; - enum { ISCONTIGUOUS = 1024 }; - - static const bool IsTuple = IOIsTuple::value; - enum { ISTUPLE = 2048 }; - - static const bool IsIOPtr = IOIsIOPtr::value; - enum { ISIOPTR = 4096 }; - - // A catch-all definition for externally defined types which - // want to use the template-based I/O within this system but - // do not want to implement the standard "read/write" mechanism. - // The user has to declare the external type by modifying the - // "IOIsExternal" template. - static const bool IsExternal = IOIsExternal::value; - enum { ISEXTERNAL = 8192 }; - - // Special enums for heap-readable objects known - // to be called with zero pointer as an argument. - // In this case we will avoid compiling an assignment - // operator for the object. - enum { ISNULLPOINTER = 16384 }; - enum { ISPUREHEAPREADABLE = 32768 }; - - static const int Signature = - IsClass * ISCLASS + IsPOD * ISPOD + IsWritable * ISWRITABLE + - IsStdContainer * ISSTDCONTAINER + IsPlaceReadable * ISPLACEREADABLE + - IsHeapReadable * ISHEAPREADABLE + IsPointer * ISPOINTER + - IsSharedPtr * ISSHAREDPTR + IsPair * ISPAIR + IsString * ISSTRING + - IsContiguous * ISCONTIGUOUS + IsTuple * ISTUPLE + IsIOPtr * ISIOPTR + - IsExternal * ISEXTERNAL + IsPointer * ISNULLPOINTER + - IsHeapReadable * ISPUREHEAPREADABLE; -}; - -template inline IOTraits IOItemTraits(const T &) { - return IOTraits(); -} -} // namespace gs + template + struct IOTraits { + static const bool IsClass = IOIsClassType::value; + enum { ISCLASS = 1 }; + + // Pointers are not PODs for I/O purposes. + // + // It looks like std::array of PODs is itself considered + // a POD by the "CPP11_is_pod" template, at least by some + // g++ versions (in particular, 4.4.5). This is a bug/feature + // that we need to avoid. + static const bool IsPOD = + (IOIsPOD::value && !IOIsContainer::value && !CPP11_is_pointer::value && !IOIsExternal::value); + enum { ISPOD = 2 }; + + static const bool IsWritable = (IOIsWritable::value && !IOIsExternal::value); + enum { ISWRITABLE = 4 }; + + static const bool IsStdContainer = (IOIsContainer::value && !IOIsWritable::value && !IOIsExternal::value); + enum { ISSTDCONTAINER = 8 }; + + // Readable objects are required to be writable + static const bool IsPlaceReadable = (IOIsPlaceReadable::value && IOIsWritable::value); + enum { ISPLACEREADABLE = 16 }; + + // Prefer place readability to heap readability + static const bool IsHeapReadable = + (IOIsHeapReadable::value && !IOIsPlaceReadable::value && IOIsWritable::value); + enum { ISHEAPREADABLE = 32 }; + + static const bool IsPointer = (CPP11_is_pointer::value && !IOIsExternal::value); + enum { ISPOINTER = 64 }; + + static const bool IsSharedPtr = (IOIsSharedPtr::value && !IOIsExternal::value); + enum { ISSHAREDPTR = 128 }; + + static const bool IsPair = IOIsPair::value; + enum { ISPAIR = 256 }; + + static const bool IsString = IOIsString::value; + enum { ISSTRING = 512 }; + + // The following trait is relevant for containers only + static const bool IsContiguous = IOIsContiguous::value; + enum { ISCONTIGUOUS = 1024 }; + + static const bool IsTuple = IOIsTuple::value; + enum { ISTUPLE = 2048 }; + + static const bool IsIOPtr = IOIsIOPtr::value; + enum { ISIOPTR = 4096 }; + + // A catch-all definition for externally defined types which + // want to use the template-based I/O within this system but + // do not want to implement the standard "read/write" mechanism. + // The user has to declare the external type by modifying the + // "IOIsExternal" template. + static const bool IsExternal = IOIsExternal::value; + enum { ISEXTERNAL = 8192 }; + + // Special enums for heap-readable objects known + // to be called with zero pointer as an argument. + // In this case we will avoid compiling an assignment + // operator for the object. + enum { ISNULLPOINTER = 16384 }; + enum { ISPUREHEAPREADABLE = 32768 }; + + static const int Signature = IsClass * ISCLASS + IsPOD * ISPOD + IsWritable * ISWRITABLE + + IsStdContainer * ISSTDCONTAINER + IsPlaceReadable * ISPLACEREADABLE + + IsHeapReadable * ISHEAPREADABLE + IsPointer * ISPOINTER + IsSharedPtr * ISSHAREDPTR + + IsPair * ISPAIR + IsString * ISSTRING + IsContiguous * ISCONTIGUOUS + + IsTuple * ISTUPLE + IsIOPtr * ISIOPTR + IsExternal * ISEXTERNAL + + IsPointer * ISNULLPOINTER + IsHeapReadable * ISPUREHEAPREADABLE; + }; + + template + inline IOTraits IOItemTraits(const T &) { + return IOTraits(); + } +} // namespace gs template std::ostream &operator<<(std::ostream &os, const gs::IOTraits &) { typedef gs::IOTraits Tr; - os << "IsClass = " << Tr::IsClass << ", IsPOD = " << Tr::IsPOD - << ", IsWritable = " << Tr::IsWritable - << ", IsStdContainer = " << Tr::IsStdContainer - << ", IsPlaceReadable = " << Tr::IsPlaceReadable - << ", IsHeapReadable = " << Tr::IsHeapReadable - << ", IsPointer = " << Tr::IsPointer - << ", IsSharedPtr = " << Tr::IsSharedPtr << ", IsPair = " << Tr::IsPair - << ", IsString = " << Tr::IsString - << ", IsContiguous = " << Tr::IsContiguous << ", IsTuple = " << Tr::IsTuple - << ", IsIOPtr = " << Tr::IsIOPtr << ", IsExternal = " << Tr::IsExternal; + os << "IsClass = " << Tr::IsClass << ", IsPOD = " << Tr::IsPOD << ", IsWritable = " << Tr::IsWritable + << ", IsStdContainer = " << Tr::IsStdContainer << ", IsPlaceReadable = " << Tr::IsPlaceReadable + << ", IsHeapReadable = " << Tr::IsHeapReadable << ", IsPointer = " << Tr::IsPointer + << ", IsSharedPtr = " << Tr::IsSharedPtr << ", IsPair = " << Tr::IsPair << ", IsString = " << Tr::IsString + << ", IsContiguous = " << Tr::IsContiguous << ", IsTuple = " << Tr::IsTuple << ", IsIOPtr = " << Tr::IsIOPtr + << ", IsExternal = " << Tr::IsExternal; return os; } -#endif // GENERS_IOTRAITS_HH_ +#endif // GENERS_IOTRAITS_HH_ diff --git a/Alignment/Geners/interface/InsertContainerItem.hh b/Alignment/Geners/interface/InsertContainerItem.hh index bfb134b2f96e7..dd1aa6c2845e5 100644 --- a/Alignment/Geners/interface/InsertContainerItem.hh +++ b/Alignment/Geners/interface/InsertContainerItem.hh @@ -4,12 +4,12 @@ #include namespace gs { -template struct InsertContainerItem { - static inline void insert(T &obj, const typename T::value_type &item, - const std::size_t /* itemNumber */) { - obj.push_back(item); - } -}; -} // namespace gs + template + struct InsertContainerItem { + static inline void insert(T &obj, const typename T::value_type &item, const std::size_t /* itemNumber */) { + obj.push_back(item); + } + }; +} // namespace gs -#endif // GENERS_INSERTCONTAINERITEM_HH_ +#endif // GENERS_INSERTCONTAINERITEM_HH_ diff --git a/Alignment/Geners/interface/Int2Type.hh b/Alignment/Geners/interface/Int2Type.hh index bab5dd6537bc7..9d749f2a84d3a 100644 --- a/Alignment/Geners/interface/Int2Type.hh +++ b/Alignment/Geners/interface/Int2Type.hh @@ -4,22 +4,23 @@ #include namespace gs { -namespace Private { -inline std::string makeInt2TypeStage(const int v) { - std::ostringstream os; - os << "Int2Type::" << v; - return os.str(); -} -} // namespace Private + namespace Private { + inline std::string makeInt2TypeStage(const int v) { + std::ostringstream os; + os << "Int2Type::" << v; + return os.str(); + } + } // namespace Private -template struct Int2Type { - enum { value = v }; + template + struct Int2Type { + enum { value = v }; - static const char *stage() { - static const std::string buf(Private::makeInt2TypeStage(v)); - return buf.c_str(); - } -}; -} // namespace gs + static const char *stage() { + static const std::string buf(Private::makeInt2TypeStage(v)); + return buf.c_str(); + } + }; +} // namespace gs -#endif // GENERS_INT2TYPE_HH_ +#endif // GENERS_INT2TYPE_HH_ diff --git a/Alignment/Geners/interface/ItemDescriptor.hh b/Alignment/Geners/interface/ItemDescriptor.hh index 9a48b2f90262e..a069c40a801b7 100644 --- a/Alignment/Geners/interface/ItemDescriptor.hh +++ b/Alignment/Geners/interface/ItemDescriptor.hh @@ -10,47 +10,38 @@ #include "Alignment/Geners/interface/ClassId.hh" namespace gs { -class ItemDescriptor { -public: - ItemDescriptor(); - ItemDescriptor(const ClassId &classId, const char *ioPrototype, - const char *name, const char *category); - inline virtual ~ItemDescriptor() {} - - inline const ClassId &type() const { return classId_; } - inline const std::string &ioPrototype() const { return ioProto_; } - inline const std::string &name() const { return nameCat_.first; } - inline const std::string &category() const { return nameCat_.second; } - inline const std::pair &nameAndCategory() const { - return nameCat_; - } - - inline bool operator==(const ItemDescriptor &r) const { - return (typeid(*this) == typeid(r)) && this->isEqual(r); - } - inline bool operator!=(const ItemDescriptor &r) const { - return !(*this == r); - } - - // The following returns "true" if the class id and - // I/O prototype of this item coincide with those of - // the argument - bool isSameClassIdandIO(const ItemDescriptor &r) const; - - // The following method checks I/O prototype only - // allowing for class id mismatch - inline bool isSameIOPrototype(const ItemDescriptor &r) const { - return ioProto_ == r.ioProto_; - } - -protected: - virtual bool isEqual(const ItemDescriptor &) const; - -private: - ClassId classId_; - std::string ioProto_; - std::pair nameCat_; -}; -} // namespace gs - -#endif // GENERS_ITEMDESCRIPTOR_HH_ + class ItemDescriptor { + public: + ItemDescriptor(); + ItemDescriptor(const ClassId &classId, const char *ioPrototype, const char *name, const char *category); + inline virtual ~ItemDescriptor() {} + + inline const ClassId &type() const { return classId_; } + inline const std::string &ioPrototype() const { return ioProto_; } + inline const std::string &name() const { return nameCat_.first; } + inline const std::string &category() const { return nameCat_.second; } + inline const std::pair &nameAndCategory() const { return nameCat_; } + + inline bool operator==(const ItemDescriptor &r) const { return (typeid(*this) == typeid(r)) && this->isEqual(r); } + inline bool operator!=(const ItemDescriptor &r) const { return !(*this == r); } + + // The following returns "true" if the class id and + // I/O prototype of this item coincide with those of + // the argument + bool isSameClassIdandIO(const ItemDescriptor &r) const; + + // The following method checks I/O prototype only + // allowing for class id mismatch + inline bool isSameIOPrototype(const ItemDescriptor &r) const { return ioProto_ == r.ioProto_; } + + protected: + virtual bool isEqual(const ItemDescriptor &) const; + + private: + ClassId classId_; + std::string ioProto_; + std::pair nameCat_; + }; +} // namespace gs + +#endif // GENERS_ITEMDESCRIPTOR_HH_ diff --git a/Alignment/Geners/interface/ItemLocation.hh b/Alignment/Geners/interface/ItemLocation.hh index e93c5fd38c826..10f2e9a059b2e 100644 --- a/Alignment/Geners/interface/ItemLocation.hh +++ b/Alignment/Geners/interface/ItemLocation.hh @@ -7,41 +7,37 @@ #include "Alignment/Geners/interface/ClassId.hh" namespace gs { -class ItemLocation { -public: - inline ItemLocation(std::streampos pos, const char *URI, - const char *cachedItemURI = nullptr) - : pos_(pos), URI_(URI ? URI : ""), - cachedItemURI_(cachedItemURI ? cachedItemURI : "") {} - - inline std::streampos streamPosition() const { return pos_; } - inline const std::string &URI() const { return URI_; } - inline const std::string &cachedItemURI() const { return cachedItemURI_; } - - inline void setStreamPosition(std::streampos pos) { pos_ = pos; } - inline void setURI(const char *newURI) { URI_ = newURI ? newURI : ""; } - inline void setCachedItemURI(const char *newURI) { - cachedItemURI_ = newURI ? newURI : ""; - } - - bool operator==(const ItemLocation &r) const; - inline bool operator!=(const ItemLocation &r) const { return !(*this == r); } - - // Methods related to I/O - inline ClassId classId() const { return ClassId(*this); } - bool write(std::ostream &of) const; - - static inline const char *classname() { return "gs::ItemLocation"; } - static inline unsigned version() { return 1; } - static ItemLocation *read(const ClassId &id, std::istream &in); - -private: - ItemLocation() = delete; - - std::streampos pos_; - std::string URI_; - std::string cachedItemURI_; -}; -} // namespace gs - -#endif // GENERS_ITEMLOCATION_HH_ + class ItemLocation { + public: + inline ItemLocation(std::streampos pos, const char *URI, const char *cachedItemURI = nullptr) + : pos_(pos), URI_(URI ? URI : ""), cachedItemURI_(cachedItemURI ? cachedItemURI : "") {} + + inline std::streampos streamPosition() const { return pos_; } + inline const std::string &URI() const { return URI_; } + inline const std::string &cachedItemURI() const { return cachedItemURI_; } + + inline void setStreamPosition(std::streampos pos) { pos_ = pos; } + inline void setURI(const char *newURI) { URI_ = newURI ? newURI : ""; } + inline void setCachedItemURI(const char *newURI) { cachedItemURI_ = newURI ? newURI : ""; } + + bool operator==(const ItemLocation &r) const; + inline bool operator!=(const ItemLocation &r) const { return !(*this == r); } + + // Methods related to I/O + inline ClassId classId() const { return ClassId(*this); } + bool write(std::ostream &of) const; + + static inline const char *classname() { return "gs::ItemLocation"; } + static inline unsigned version() { return 1; } + static ItemLocation *read(const ClassId &id, std::istream &in); + + private: + ItemLocation() = delete; + + std::streampos pos_; + std::string URI_; + std::string cachedItemURI_; + }; +} // namespace gs + +#endif // GENERS_ITEMLOCATION_HH_ diff --git a/Alignment/Geners/interface/MultiFileArchive.hh b/Alignment/Geners/interface/MultiFileArchive.hh index ee48abeb6b32e..a040ef4a6b935 100644 --- a/Alignment/Geners/interface/MultiFileArchive.hh +++ b/Alignment/Geners/interface/MultiFileArchive.hh @@ -7,67 +7,68 @@ #include "Alignment/Geners/interface/CatalogIO.hh" namespace gs { -class MultiFileArchive : public BinaryArchiveBase { -public: - // See the note inside the "BinaryArchiveBase.hh" header - // for the meaning of the "mode" argument - MultiFileArchive(const char *basename, const char *mode, - const char *annotation = nullptr, - unsigned typicalFileSizeInMB = 1000U, - unsigned dataFileBufferSize = 1048576U, - unsigned catalogFileBufferSize = 131072U); - ~MultiFileArchive() override; + class MultiFileArchive : public BinaryArchiveBase { + public: + // See the note inside the "BinaryArchiveBase.hh" header + // for the meaning of the "mode" argument + MultiFileArchive(const char *basename, + const char *mode, + const char *annotation = nullptr, + unsigned typicalFileSizeInMB = 1000U, + unsigned dataFileBufferSize = 1048576U, + unsigned catalogFileBufferSize = 131072U); + ~MultiFileArchive() override; - void flush() override; + void flush() override; -private: - void writeCatalog(); - void openWriteStream(); - void setupWriteStream(); - void updateReadStream(const std::string &uri); - void releaseBuffers(); + private: + void writeCatalog(); + void openWriteStream(); + void setupWriteStream(); + void updateReadStream(const std::string &uri); + void releaseBuffers(); - template void readCatalog() { - assert(!catalog()); - unsigned compressionMode; - setCatalog(readBinaryCatalog(catStream_, &compressionMode, - &catalogMergeLevel_, - &catalogAnnotations_, true)); - assert(catalog()); - setCompressionMode(compressionMode); - } + template + void readCatalog() { + assert(!catalog()); + unsigned compressionMode; + setCatalog( + readBinaryCatalog(catStream_, &compressionMode, &catalogMergeLevel_, &catalogAnnotations_, true)); + assert(catalog()); + setCompressionMode(compressionMode); + } - // The following methods have to be overriden from the base - std::ostream &plainOutputStream() override; - std::istream &plainInputStream(unsigned long long id, - unsigned *compressionCode, - unsigned long long *length) override; + // The following methods have to be overriden from the base + std::ostream &plainOutputStream() override; + std::istream &plainInputStream(unsigned long long id, + unsigned *compressionCode, + unsigned long long *length) override; - unsigned long long addToCatalog(const AbsRecord &record, - unsigned compressionCode, - unsigned long long itemLength) override; + unsigned long long addToCatalog(const AbsRecord &record, + unsigned compressionCode, + unsigned long long itemLength) override; - char *filebuf_; - char *readbuf_; - char *catabuf_; - std::string annotation_; - std::string catalogFileName_; - std::string writeFileName_; - std::string writeFileURI_; - std::string readFileName_; - std::string readFileURI_; - std::fstream writeStream_; - std::fstream catStream_; - std::fstream separateReadStream_; - std::streampos lastpos_; - std::streampos jumppos_; - std::streampos maxpos_; - std::vector catalogAnnotations_; - unsigned long writeFileNumber_; - unsigned catalogMergeLevel_; - bool annotationsMerged_; - bool streamFlushed_; -}; -} // namespace gs + char *filebuf_; + char *readbuf_; + char *catabuf_; + std::string annotation_; + std::string catalogFileName_; + std::string writeFileName_; + std::string writeFileURI_; + std::string readFileName_; + std::string readFileURI_; + std::fstream writeStream_; + std::fstream catStream_; + std::fstream separateReadStream_; + std::streampos lastpos_; + std::streampos jumppos_; + std::streampos maxpos_; + std::vector catalogAnnotations_; + unsigned long writeFileNumber_; + unsigned catalogMergeLevel_; + bool annotationsMerged_; + bool streamFlushed_; + }; +} // namespace gs -#endif // GENERS_MULTIFILEARCHIVE_HH_ +#endif // GENERS_MULTIFILEARCHIVE_HH_ diff --git a/Alignment/Geners/interface/ProcessItem.hh b/Alignment/Geners/interface/ProcessItem.hh index ff82e819466b8..26d2297427fc9 100644 --- a/Alignment/Geners/interface/ProcessItem.hh +++ b/Alignment/Geners/interface/ProcessItem.hh @@ -30,27 +30,27 @@ #include "Alignment/Geners/interface/Int2Type.hh" namespace gs { -// Special types to designate stages in container processing -struct InContainerHeader { - static const char *stage() { return "InContainerHeader"; } -}; + // Special types to designate stages in container processing + struct InContainerHeader { + static const char *stage() { return "InContainerHeader"; } + }; -struct InContainerSize { - static const char *stage() { return "InContainerSize"; } -}; + struct InContainerSize { + static const char *stage() { return "InContainerSize"; } + }; -struct InContainerFooter { - static const char *stage() { return "InContainerFooter"; } -}; + struct InContainerFooter { + static const char *stage() { return "InContainerFooter"; } + }; -struct InContainerCycle { - static const char *stage() { return "InContainerCycle"; } -}; + struct InContainerCycle { + static const char *stage() { return "InContainerCycle"; } + }; -struct InPODArray { - static const char *stage() { return "InPODArray"; } -}; -} // namespace gs + struct InPODArray { + static const char *stage() { return "InPODArray"; } + }; +} // namespace gs // I am not aware of an easy way to have both const and non-const // version of a template defined in the same code fragment. This is @@ -93,226 +93,180 @@ struct InPODArray { #endif namespace gs { -namespace Private { -template