00001
00002 #ifndef GAUDIKERNEL_DATAOBJECT_H
00003 #define GAUDIKERNEL_DATAOBJECT_H
00004
00005
00006 #include "GaudiKernel/ClassID.h"
00007 #include "GaudiKernel/IDataDirectory.h"
00008 #include "GaudiKernel/IInspectable.h"
00009 #include "GaudiKernel/ISerialize.h"
00010
00011 #include <vector>
00012
00013
00014 class IDataDirectory;
00015 class IOpaqueAddress;
00016 class StreamBuffer;
00017 class DataObject;
00018
00019
00020 static const CLID CLID_DataObject = 1;
00021
00030 class DataObject : virtual public IInspectable {
00031 public:
00033 enum DirLinkType {INVALID, VALID};
00038 class Link {
00040 friend class DataObject;
00042 std::string m_path;
00044 DataObject* m_pObject;
00046 long m_id;
00048 Link(long id, const std::string& path, const DataObject* pObject=0)
00049 : m_path(path), m_id(id) {
00050 set(pObject);
00051 }
00053 Link() : m_path(""), m_pObject(0), m_id(INVALID) {
00054 }
00056 Link& operator=(const Link& link) {
00057 set(link.m_pObject);
00058 m_path = link.m_path;
00059 m_id = link.m_id;
00060 return *this;
00061 }
00063 void set(const DataObject* pObject) {
00064 m_pObject = const_cast<DataObject*>(pObject);
00065 }
00067 void set(long id, const std::string& path, const DataObject* pObject) {
00068 set(pObject);
00069 m_path = path;
00070 m_id = id;
00071 }
00072 public:
00074 bool operator==(const Link& link) const {
00075 return link.m_path == m_path;
00076 }
00078 DataObject* object() {
00079 return m_pObject;
00080 }
00082 const DataObject* object() const {
00083 return m_pObject;
00084 }
00086 const std::string& path() const {
00087 return m_path;
00088 }
00089 long ID() const {
00090 return m_id;
00091 }
00093 IOpaqueAddress* address();
00094 };
00095 typedef std::vector<Link*> LinkVector;
00097 typedef IDataDirectory::DirIterator DirIterator;
00099 typedef IDataDirectory::DirIterator ConstDirIterator;
00101 typedef LinkVector::iterator LinkIterator;
00103 typedef LinkVector::const_iterator ConstLinkIterator;
00104 private:
00106 IDataDirectory* m_pDirectory;
00108 unsigned long m_refCount;
00110 mutable LinkVector m_linkVector;
00112 unsigned char m_version;
00114 bool m_isLocked;
00115 public:
00117 DataObject(const std::string& name = "");
00119 virtual ~DataObject();
00121 virtual unsigned long addRef();
00123 virtual unsigned long release();
00125 virtual unsigned long refCount() const;
00127 virtual const CLID& clID() const;
00129 static const CLID& classID();
00131 virtual const unsigned char version() const;
00133 virtual void setVersion(unsigned char vsn);
00135 const std::string& localPath() const;
00137 const std::string& location() const;
00139 const std::string& fullpath() const;
00141 DataObject* parent();
00143 const DataObject* parent() const;
00145 DataObject* find(const std::string& path);
00147 const DataObject* find(const std::string& path) const;
00149 IDataDirectory* leaf(const std::string& path);
00151 const IDataDirectory* leaf(const std::string& path) const;
00153 void setDirectory(IDataDirectory* dir);
00155 IDataDirectory* directory();
00157 const IDataDirectory* directory() const;
00159 virtual TransientStore* store();
00161 virtual const TransientStore* store() const;
00163 IOpaqueAddress* address();
00165 const IOpaqueAddress* address() const;
00167 DirIterator dirBegin();
00169 ConstDirIterator dirBegin() const;
00171 DirIterator dirEnd();
00173 ConstDirIterator dirEnd() const;
00175 LinkIterator linkBegin();
00177 ConstLinkIterator linkBegin() const;
00179 LinkIterator linkEnd();
00181 ConstLinkIterator linkEnd() const;
00183 size_t linkSize() const;
00185 Link* symLink(long id);
00187 Link* symLink(DataObject* pObject);
00189 Link* symLink(const std::string& path);
00191 long addLink(const std::string& path, const DataObject* pObject) const;
00193 long removeLink(const DataObject* pObject) const;
00195 long removeLink(const std::string& fullPath) const;
00197 long removeLink(long id) const;
00199 void clearLinks();
00201 virtual StreamBuffer& serialize(StreamBuffer& s);
00203 virtual StreamBuffer& serialize(StreamBuffer& s) const;
00205 virtual bool acceptInspector(IInspector* pI);
00207 virtual bool acceptInspector(IInspector* pI) const;
00209 bool isLocked( ) const;
00211 StatusCode setLocked( );
00212
00213 private:
00215 StatusCode setUnlocked( );
00216
00217 };
00218
00219 #endif // GAUDIKERNEL_DATAOBJECT_H