Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:51:49

0001 #ifndef BASE_OBJECT_H
0002 #define BASE_OBJECT_H
0003 
0004 /**
0005  * @file BaseObject.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date September 09, 2014
0008  * @version 1.0
0009  */
0010 
0011 #include <string>
0012 
0013 namespace ElemUtils {
0014 class Packet;
0015 } /* namespace ElemUtils */
0016 
0017 namespace PARTONS {
0018 
0019 /** @class BaseObject
0020  *
0021  * @brief BaseObject is the ”zeroth-level-object” of the architecture.
0022  * Each module in PARTONS is referred to with a unique class name and a unique int used as ID.
0023  *
0024  * Any C++ object in PARTONS can inherit of it. It fulfills several needs:
0025  * 1. It contains a clone function to be used to the factory to provide the user an object identified by a simple key (a string).
0026  * 2. It carries information on the identity of a specific object among others to transmit an explicit message to the logger (i.e. understandable by a human being, not an address in memory).
0027  * 3. It handles Packets to allow systematic computations over lists of inputs e.g. with threads.
0028  * 4. It allows the registry to store pointers to all modules in a generic way.
0029  */
0030 class BaseObject {
0031 public:
0032 
0033     /**
0034      * Constructor.
0035      * Takes a string parameter that represents the class's name of the child instance class.
0036      *
0037      * @param className class's name of child class.
0038      */
0039     BaseObject(const std::string &className);
0040 
0041     /**
0042      * Default destructor.
0043      */
0044     virtual ~BaseObject();
0045 
0046     /**
0047      * Virtual clone function to allow the factory to clone all derived members object stored in the BaseObjectRegistry.
0048      * @return
0049      */
0050     virtual BaseObject* clone() const;
0051 
0052     /**
0053      * Because of the initialization step order of the program, objects are registered in a total random order and some objects depend on others.
0054      * To avoid the problem of pointer resolution order, this method is called by the BaseObjectRegistery after all objects are well registered in it.
0055      * See BaseObjectRegistry class documentation for more details.
0056      */
0057     virtual void resolveObjectDependencies();
0058 
0059     /**
0060      * Return a pre-formatted characters string for output visualization of class member's values.
0061      *
0062      * @return a pre-formatted characters string.
0063      */
0064     virtual std::string toString() const;
0065 
0066     /**
0067      * Used to split a complex C++ object into a concatenation of simple types.
0068      *
0069      * @param packet
0070      */
0071     void serialize(ElemUtils::Packet &packet) const;
0072 
0073     /**
0074      * Used to rebuild a complex C++ object from a concatenation of simple type.
0075      *
0076      * @param packet
0077      */
0078     void unserialize(ElemUtils::Packet &packet);
0079 
0080     /**
0081      * Overload of < operator to sort BaseObject object by its indexId value.
0082      *
0083      * @param other
0084      * @return
0085      */
0086     bool operator <(const BaseObject& other) const;
0087 
0088     // ##### GETTERS & SETTERS #####
0089 
0090     /**
0091      *
0092      * @return Name of last child class.
0093      */
0094     const std::string& getClassName() const;
0095 
0096     /**
0097      *
0098      * @return Unique id identifying each object.
0099      */
0100     unsigned int getObjectId() const;
0101 
0102     /**
0103      *
0104      * @return Integer used when object is created from database. It is related to the id column value in the right database table.
0105      */
0106     int getIndexId() const;
0107     /**
0108      *
0109      * @param indexId Integer used when object is created from database. It is related to the id column value in the right database table.
0110      */
0111     void setIndexId(int indexId);
0112 
0113 protected:
0114 
0115     /**
0116      * Copy constructor.
0117      *
0118      * @param other
0119      */
0120     BaseObject(const BaseObject& other);
0121 
0122     /**
0123      * Print info message into logger.
0124      *
0125      * @param functionName Name of the function throwing an information. Use \_\_func\_\_ to set it automatically.
0126      * @param message Message to the logger.
0127      */
0128     void info(const std::string &functionName,
0129             const std::string &message) const;
0130 
0131     /**
0132      * Print debug message into logger.
0133      *
0134      * @param functionName ame of the function throwing an information. Use \_\_func\_\_ to set it automatically.
0135      * @param message Message to the logger.
0136      */
0137     void debug(const std::string &functionName,
0138             const std::string &message) const;
0139 
0140     /**
0141      * Print warning message into logger.
0142      *
0143      * @param functionName ame of the function throwing an information. Use \_\_func\_\_ to set it automatically.
0144      * @param message Message to the logger.
0145      */
0146     void warn(const std::string &functionName,
0147             const std::string &message) const;
0148 
0149     /**
0150      * Use in automation process to throw exception when a parameter is missing from the XML scenario file.
0151      *
0152      * @param parameterName
0153      */
0154     void errorMissingParameter(const std::string &parameterName) const;
0155 
0156 private:
0157     unsigned int m_objectId; ///< Unique id identifying each object.
0158     std::string m_className; ///< String that represents class's name used by the LoggerManager's class to know the source of the output trace.
0159 
0160     int m_indexId; ///< Integer used when object is created from database. It is related to the id column value in the right database table.
0161 
0162     static unsigned int m_uniqueObjectIdCounter;
0163 
0164     /**
0165      * On call, returns an incremented by one uniqueID member value.
0166      *
0167      * @return incremented unsigned int ID.
0168      */
0169     unsigned int getUniqueObjectId();
0170 };
0171 
0172 ElemUtils::Packet& operator <<(ElemUtils::Packet& packet, BaseObject& object);
0173 ElemUtils::Packet& operator >>(ElemUtils::Packet& packet, BaseObject& object);
0174 
0175 } /* namespace PARTONS */
0176 
0177 #endif /* BASE_OBJECT_H */