Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:54:30

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_CONTAINEDOBJECT_H
0012 #define GAUDIKERNEL_CONTAINEDOBJECT_H
0013 
0014 // Include files
0015 #include <GaudiKernel/Kernel.h>
0016 #include <GaudiKernel/ObjectContainerBase.h>
0017 #include <GaudiKernel/StreamBuffer.h>
0018 #include <iostream>
0019 
0020 // Forward declarations
0021 template <class TYPE>
0022 class ObjectVector;
0023 template <class TYPE>
0024 class ObjectList;
0025 
0026 // Typedefs
0027 typedef ObjectVector<ContainedObject> ContainedObjectVector;
0028 typedef ObjectList<ContainedObject>   ContainedObjectList;
0029 
0030 // Definition of the CLID for this class
0031 static const CLID CLID_ContainedObject = 190;
0032 
0033 /** @class ContainedObject ContainedObject.h GaudiKernel/ContainedObject.h
0034 
0035     All classes that their objects may be contained in an LHCb
0036     ObjectContainer (e.g. ObjectVector, or ObjectList),
0037     have to inherit from the class ContainedObject. It guarantees
0038     the navigability from the contained object back to its container.
0039     @author Pavel Binko
0040 */
0041 class GAUDI_API ContainedObject {
0042 
0043   /// Allow the container classes access to protected members
0044   friend class ObjectVector<ContainedObject>;
0045   friend class ObjectList<ContainedObject>;
0046 
0047 protected:
0048   /// Constructors
0049   ContainedObject() = default;
0050   /// Copy constructor and assignement: do NOT copy the parent reference...
0051   ContainedObject( const ContainedObject& ) : ContainedObject() {}
0052   // cppcheck-suppress operatorEqVarError; see comment above
0053   ContainedObject& operator=( const ContainedObject& ) { return *this; }
0054   /// Destructor
0055   virtual ~ContainedObject();
0056 
0057 public:
0058   /// Retrieve pointer to class identifier
0059   virtual const CLID& clID() const { return classID(); }
0060   static const CLID&  classID() { return CLID_ContainedObject; }
0061 
0062   /// Access to parent object
0063   const ObjectContainerBase* parent() const { return m_parent; }
0064   /// Update parent member
0065   void setParent( ObjectContainerBase* value ) { m_parent = value; }
0066 
0067   /// Distance in the parent container
0068   virtual long index() const { return m_parent ? m_parent->index( this ) : -1; }
0069   /// Serialize the object for writing
0070   virtual StreamBuffer& serialize( StreamBuffer& s ) const { return s; }
0071   /// Serialize the object for reading
0072   virtual StreamBuffer& serialize( StreamBuffer& s ) { return s; }
0073   /// Fill the output stream (ASCII)
0074   virtual std::ostream& fillStream( std::ostream& s ) const { return s; }
0075   /// Output operator (ASCII)
0076   friend std::ostream& operator<<( std::ostream& s, const ContainedObject& obj ) { return obj.fillStream( s ); }
0077 
0078 private:
0079   /// Pointer to the parent
0080   ObjectContainerBase* m_parent = nullptr;
0081 };
0082 
0083 #endif // GAUDIKERNEL_CONTAINEDOBJECT_H