Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:07:11

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 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   ContainedObject& operator=( const ContainedObject& ) { return *this; }
0053   /// Destructor
0054   virtual ~ContainedObject();
0055 
0056 public:
0057   /// Retrieve pointer to class identifier
0058   virtual const CLID& clID() const { return classID(); }
0059   static const CLID&  classID() { return CLID_ContainedObject; }
0060 
0061   /// Access to parent object
0062   const ObjectContainerBase* parent() const { return m_parent; }
0063   /// Update parent member
0064   void setParent( ObjectContainerBase* value ) { m_parent = value; }
0065 
0066   /// Distance in the parent container
0067   virtual long index() const { return m_parent ? m_parent->index( this ) : -1; }
0068   /// Serialize the object for writing
0069   virtual StreamBuffer& serialize( StreamBuffer& s ) const { return s; }
0070   /// Serialize the object for reading
0071   virtual StreamBuffer& serialize( StreamBuffer& s ) { return s; }
0072   /// Fill the output stream (ASCII)
0073   virtual std::ostream& fillStream( std::ostream& s ) const { return s; }
0074   /// Output operator (ASCII)
0075   friend std::ostream& operator<<( std::ostream& s, const ContainedObject& obj ) { return obj.fillStream( s ); }
0076 
0077 private:
0078   /// Pointer to the parent
0079   ObjectContainerBase* m_parent = nullptr;
0080 };
0081 
0082 #endif // GAUDIKERNEL_CONTAINEDOBJECT_H