00001
00002 #ifndef GAUDIKERNEL_CONTAINEDOBJECT_H
00003 #define GAUDIKERNEL_CONTAINEDOBJECT_H
00004
00005
00006 #include "GaudiKernel/Kernel.h"
00007 #include "GaudiKernel/StreamBuffer.h"
00008 #include "GaudiKernel/ObjectContainerBase.h"
00009 #include <iostream>
00010
00011
00012 template <class TYPE> class ObjectVector;
00013 template <class TYPE> class ObjectList;
00014
00015
00016 typedef ObjectVector<ContainedObject> ContainedObjectVector;
00017 typedef ObjectList<ContainedObject> ContainedObjectList;
00018
00019
00020 static const CLID CLID_ContainedObject = 190;
00021
00031 class ContainedObject {
00032
00034 friend class ObjectVector<ContainedObject>;
00035 friend class ObjectList<ContainedObject>;
00036
00037 protected:
00039 ContainedObject()
00040 : m_parent(0) { }
00042 ContainedObject(const ContainedObject&) { m_parent = 0; }
00044 virtual ~ContainedObject();
00045
00047 ContainedObject& operator = (const ContainedObject&) {
00048 m_parent = 0;
00049 return *this;
00050 }
00051
00052 public:
00054 virtual const CLID& clID() const { return ContainedObject::classID(); }
00055 static const CLID& classID() { return CLID_ContainedObject; }
00056
00058 const ObjectContainerBase* parent () const { return m_parent; }
00060 void setParent (ObjectContainerBase* value) { m_parent = value; }
00061
00063 long distance() const { return m_parent->distance(this); }
00064
00066 virtual StreamBuffer& serialize( StreamBuffer& s ) const {
00067 return s;
00068 }
00070 virtual StreamBuffer& serialize( StreamBuffer& s ) {
00071 return s;
00072 }
00073
00075 friend std::ostream& operator<< ( std::ostream& s, const ContainedObject& obj ) {
00076 return obj.fillStream(s);
00077 }
00079 virtual std::ostream& fillStream( std::ostream& s ) const {
00080 if( 0 != m_parent ) {
00081 s << "class ContainedObject : Pointer to parent container exists ("
00082 << m_parent << ")";
00083 }
00084 return s;
00085 }
00086
00087 private:
00089 ObjectContainerBase* m_parent;
00090 };
00091
00092
00093 inline ContainedObject::~ContainedObject() {
00094
00095 if( 0 != m_parent ) {
00096 if( m_parent->release(this).isFailure() ) {
00097
00098
00099 }
00100 }
00101 }
00102 #endif // GAUDIKERNEL_CONTAINEDOBJECT_H