#ifndef __PXXObject__H__ #define __PXXObject__H__ ///////////////////////////////////////////////////////////////////////////////// /// // /// PXXObject // /// // /// This is a wrapper class of base object. // /// Every class in payloads or unpacker directory which will be compiled with // /// ROOT and IceTray must inherit the class. // /// Some of functions are defined for only ROOT compile to keep compatibility // /// with the IceTray. // /// The PXXObject has a PXXObjectPtr field named fMyOwnerPtr_ in order to // /// store the pointer to its owner. The default value of fMyOwnerPtr_is 0 and // /// it isn't copied by neither copy-constructor nor operator= function. // /// To set owner, you have to call SetOwnerPtr(PXXObjectPtr) manually. // // /// It also equip Delete(PXXObjectPtr) function which delete the argument // /// pointer after owner check. See comments in Delete to get more informations.// /// // /// @author Kotoyo Hoshina // ///////////////////////////////////////////////////////////////////////////////// #include #include "payloads-unpacker/base/PXXTypes.h" #include "TObject.h" class PXXObject; #ifdef __USEROOT__ // compile with ROOT #include "TError.h" #include "TROOT.h" typedef PXXObject* PXXObjectPtr; #define SET_LOGGER(X) // It do nothing but arrow compile with ROOT... #else // compile woth IceTray #include "dataclasses/StoragePolicy.h" typedef shared_ptr PXXObjectPtr; #endif using namespace std; class PXXObject : public TObject { public: SET_LOGGER("PXXObject"); /** * Constructor */ PXXObject(); //------------------------------------------------------------------------------ /** * Copy constructor. DO NOT COPY fMyOwnerPtr_. */ PXXObject(const PXXObject &org):TObject(org), fMyOwnerPtr_(0){} //------------------------------------------------------------------------------ /** * operator=. DO NOT COPY fMyOwnerPtr_. */ PXXObject &operator=(const PXXObject &orig) { return *this; } const PXXObject &operator=(const PXXObject &orig) const { return *this; } //------------------------------------------------------------------------------ /** * Destructor. */ virtual ~PXXObject() {} //------------------------------------------------------------------------------ /** * Set pointer to owner. Only the owner can execute delete for its datamembers. * You should call it only when you create an object with "new" operator. */ virtual void SetOwnerPtr(void *ownerptr); //------------------------------------------------------------------------------ /** * Return its owner which is used to check owner. */ virtual const void *GetOwnerPtr() const { return fMyOwnerPtr_; } //------------------------------------------------------------------------------ /** * Initialize a pointer to 0. * Currently, only ROOT pointer is required initialize. */ virtual void InitializePointer(PXXObjectPtr objptr); //------------------------------------------------------------------------------ /** * Delete is a wrapper function for delete operator. It deletes ROOT pointer, * but not delete shared_pointer. * It checks whether the object is owner of objptr or not: * if (this == objptr->GetOwnerPtr()) { * then delete objptr only when the if test is true. */ virtual void Delete(PXXObjectPtr objptr); //------------------------------------------------------------------------------ /** * Get type name. Type name doesn't have to be same as class name. */ virtual string GetTypeName() const { return fTypeName_; } //------------------------------------------------------------------------------ /** * Set type name. Type name doesn't have to same as class name. */ virtual void SetTypeName(const string &s) { fTypeName_ = s; } //------------------------------------------------------------------------------ #ifdef __USEROOT__ /** * Log info to unify the logging system. * Don't use ROOT native logging TObject::Info directly to keep compativility * with IceTray. */ virtual void log_info(const char *va_(fmt), ...) const; //------------------------------------------------------------------------------ /** * Log warn to unify the logging system. * Don't use ROOT native logging TObject::Warning directly to keep compativility * with IceTray */ virtual void log_warn(const char *va_(fmt), ...) const; //------------------------------------------------------------------------------ /** * Log error to unify the logging system. * Don't use ROOT native logging TObject::Error directly to keep compativility * with IceTray */ virtual void log_error(const char *va_(fmt), ...) const; //------------------------------------------------------------------------------ /** * Log fatal to unify the logging system. * Don't use ROOT native logging TObject::Fatal directly to keep compativility * with IceTray */ virtual void log_fatal(const char *va_(fmt), ...) const; //------------------------------------------------------------------------------ #endif // __USEROOT__ private: void *fMyOwnerPtr_; // pointer to its owner object string fTypeName_; // type name which can include version tag ClassDef(PXXObject, 0) // Base of every unpacker classes }; #include "payloads-unpacker/base/PXXPointerCasts.h" #endif // __PXXObject_H__