00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef ZEITGEIST_LEAF_H
00038 #define ZEITGEIST_LEAF_H
00039
00040 #include <list>
00041 #include <string>
00042 #include "object.h"
00043
00044 namespace zeitgeist
00045 {
00046
00050 class Leaf : public Object
00051 {
00052 friend class Node;
00053
00054
00055
00056 public:
00057 typedef std::list< boost::shared_ptr<Leaf> > TLeafList;
00058
00059
00060
00061
00062 public:
00064 Leaf(const std::string &name = "<unnamed>");
00065 virtual ~Leaf();
00066
00068 std::string& GetName()
00069 { return mName; }
00070
00072 const std::string& GetName() const
00073 { return mName; }
00074
00075
00076
00078 boost::weak_ptr<Node>& GetParent();
00079
00081 const boost::weak_ptr<Node>& GetParent() const;
00082
00087 virtual boost::shared_ptr<Leaf>
00088 GetChild(const std::string &name, bool recursive = false);
00089
00093 virtual boost::shared_ptr<Leaf>
00094 GetChildOfClass(const std::string &name, bool recursive = false);
00095
00100 virtual boost::shared_ptr<Leaf>
00101 GetChildSupportingClass(const std::string &name, bool recursive = false);
00102
00110 template<class CLASS>
00111 boost::shared_ptr<CLASS>
00112 FindChildSupportingClass(bool recursive = false)
00113 {
00114 TLeafList::iterator lstEnd = end();
00115 for (TLeafList::iterator i = begin(); i != lstEnd; ++i)
00116 {
00117
00118 boost::shared_ptr<CLASS> child = boost::shared_dynamic_cast<CLASS>(*i);
00119 if (child.get() != 0)
00120 {
00121 return child;
00122 }
00123
00124 if (recursive)
00125 {
00126 return (*i)->FindChildSupportingClass<CLASS>(recursive);
00127 }
00128 }
00129
00130 return boost::shared_ptr<CLASS>();
00131 }
00132
00135 virtual void
00136 GetChildren(const std::string &name, TLeafList &baseList, bool recursive = false);
00137
00140 virtual void GetChildrenOfClass(const std::string &name, TLeafList &baseList, bool recursive = false);
00141
00146 virtual void GetChildrenSupportingClass(const std::string &name, TLeafList &baseList, bool recursive = false);
00147
00154 template<class CLASS>
00155 void ListChildrenSupportingClass(TLeafList& list, bool recursive = false)
00156 {
00157 TLeafList::iterator lstEnd = end();
00158 for (TLeafList::iterator i = begin(); i != lstEnd; ++i)
00159 {
00160
00161 boost::shared_ptr<CLASS> child = boost::shared_dynamic_cast<CLASS>(*i);
00162 if (child.get() != 0)
00163 {
00164 list.push_back(child);
00165 }
00166
00167 if (recursive)
00168 {
00169 (*i)->ListChildrenSupportingClass<CLASS>(list,recursive);
00170 }
00171 }
00172 }
00173
00178 virtual boost::weak_ptr<Node>
00179 GetParentSupportingClass(const std::string &name) const;
00180
00188 template<class CLASS>
00189 boost::weak_ptr<CLASS>
00190 FindParentSupportingClass() const;
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00214 virtual bool IsLeaf() const;
00215
00217 virtual void RemoveChildReference(const boost::shared_ptr<Leaf> &base);
00218
00220 virtual bool AddChildReference(const boost::shared_ptr<Leaf> &base);
00221
00223 void Unlink();
00224
00226 virtual void UnlinkChildren();
00227
00229 virtual void Dump() const;
00230
00232 virtual void UpdateCached() {}
00233
00237 const std::string& GetFullPath() const;
00238
00241 void ClearCachedData() const;
00242
00244 void SetName(const std::string &name)
00245 { mName = name; ClearCachedData(); }
00246
00247
00248 virtual TLeafList::iterator begin();
00249 virtual TLeafList::const_iterator begin() const;
00250 virtual TLeafList::iterator end();
00251 virtual TLeafList::const_iterator end() const;
00252 protected:
00256 virtual void UpdateCachedInternal() {}
00257
00265 void SetParent(const boost::shared_ptr<Node> &parent);
00266
00272 virtual void OnLink();
00273
00278 virtual void OnUnlink();
00279
00280 private:
00281 Leaf(const Leaf &obj);
00282 Leaf& operator=(const Leaf &obj);
00283
00284
00285
00286
00287 protected:
00292 boost::weak_ptr<Node> mParent;
00293
00294 private:
00296 std::string mName;
00297
00299 mutable std::string *mCachedFullPath;
00300 };
00301
00306 }
00307
00308 #endif //ZEITGEIST_LEAF_H