// $Id: IDataSymLink.hxx,v 1.6 2007/11/28 20:08:05 mcgrew Exp $ // // The base class for Event Data. // #ifndef T_DATA_SYM_LINK_HXX #define T_DATA_SYM_LINK_HXX #include class TBrowser; #include "IDatum.hxx" namespace COMET { OA_EXCEPTION(EBadSymLink,EDatum); class IDataSymLink; } #define TDATA_SYM_LINK_TITLE "Link To" /// The IDataSymLink class provides a way to reference a IDatum object in a /// IData tree without having the IData object become the parent. This is /// conceptually similar to a symbolic link in a unix file system. class COMET::IDataSymLink : public IDatum { private: /// The datum which this is a link too. TString fLink; public: /// A virtual function that can be used to have "special" Get<> /// behavior. This is mostly used by the TDatumLink class so that /// it can have a weak reference to IDatum elsewhere in the /// hierarchy, and have a Get<> method that refers transparently to /// the linked object. The GetThis() method should be used /// wherever the link indirection might be desired. Notice that /// this will follow the link all the way to the real object (even /// if there are several links along the way. virtual const IDatum *GetThis(void) const { IHandle parent = GetParent(); if (!parent) return NULL; // The name in fLink relative to the parent. IHandle link = parent->Get(fLink); if (!link) return NULL; return link->GetThis(); }; virtual IDatum *GetThis(void) { IHandle parent = GetParent(); if (!parent) return NULL; // The name in fLink relative to the parent. IHandle link = parent->Get(fLink); if (!link) return NULL; return link->GetThis(); }; public: IDataSymLink() : IDatum("",TDATA_SYM_LINK_TITLE) { }; /// Create a new IDataSymLink. A IDataSymLink inherits two fields from /// IDatum, "Name" and "Title". The name is the handle that is /// used to find "this" in IData objects. It can only contain /// alphanumeric characters (no "/" or spaces) and///should* be /// unique with in any level of the IData hierarchy. For instance, /// to get a particular datum out of a IData object you use /// data->Get("thename"). The title is a discription /// of a particular type of datum. As an example, the MC /// interaction data might be named "interaction" and titled "MC /// Interaction Data". The default title is "Event Datum". explicit IDataSymLink(const char* name, const char *link = NULL) : IDatum(name,TDATA_SYM_LINK_TITLE) { SetLink(link); }; virtual ~IDataSymLink(); /// Set the IDatum that is being linked. virtual void SetLink(const char* link) { if (link) fLink = link; else fLink = ""; }; /// Print the datum information. virtual void ls(Option_t* opt = "") const; /// Check if this link is to a browsable class. virtual Bool_t IsFolder(void) const; /// Call the browser for the linked class. virtual void Browse(TBrowser* b); private: IDatum* RemoveDatum(IDatum*){ MayNotUse("RemoveDatum"); return NULL; } void InsertDatum(IDatum*){ MayNotUse("InsertDatum"); } IDatum* FindDatum(const char *){ MayNotUse("FindDatum"); return NULL; } protected: ClassDef(IDataSymLink,2); }; #endif