00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "class.h"
00023 #include "node.h"
00024 #include <iostream>
00025
00026 using namespace boost;
00027 using namespace std;
00028 using namespace zeitgeist;
00029
00030 Leaf::Leaf(const std::string &name) : mName(name), mCachedFullPath(NULL)
00031 {
00032 }
00033
00034 Leaf::~Leaf()
00035 {
00036 }
00037
00038 boost::weak_ptr<Node>& Leaf::GetParent()
00039 {
00040 return mParent;
00041 }
00042
00043 const boost::weak_ptr<Node>& Leaf::GetParent() const
00044 {
00045 return mParent;
00046 }
00047
00048 boost::shared_ptr<Leaf> Leaf::GetChild(const std::string &name, bool )
00049 {
00050 if (name.compare("..") == 0)
00051 {
00052 return make_shared(GetParent());
00053 }
00054
00055 if (name.compare(".") == 0)
00056 {
00057
00058 return shared_static_cast<Leaf>(make_shared(GetSelf()));
00059 }
00060
00061 return boost::shared_ptr<Leaf>();
00062 }
00063
00064 boost::shared_ptr<Leaf> Leaf::GetChildOfClass(const std::string &, bool )
00065 {
00066 return boost::shared_ptr<Leaf>();
00067 }
00068
00069 boost::shared_ptr<Leaf> Leaf::GetChildSupportingClass(const std::string &, bool )
00070 {
00071 return boost::shared_ptr<Leaf>();
00072 }
00073
00074 void Leaf::GetChildren(const std::string &name, TLeafList &baseList, bool )
00075 {
00076 if (name.compare("..") == 0)
00077 {
00078 baseList.push_back(make_shared(GetParent()));
00079 }
00080
00081 if (name.compare(".") == 0)
00082 {
00083 baseList.push_back(shared_static_cast<Leaf>(make_shared(GetSelf())));
00084 }
00085 }
00086
00087 void Leaf::GetChildrenOfClass(const std::string &, TLeafList &, bool )
00088 {
00089 }
00090
00091 void Leaf::GetChildrenSupportingClass(const std::string &, TLeafList &, bool )
00092 {
00093 }
00094
00095 boost::weak_ptr<Node>
00096 Leaf::GetParentSupportingClass(const std::string &name) const
00097 {
00098 shared_ptr<Node> node
00099 = shared_static_cast<Node>(make_shared(GetParent()));
00100
00101 while
00102 (
00103 (node.get() != 0) &&
00104 (node->GetClass()) &&
00105 (! node->GetClass()->SupportsClass(name))
00106 )
00107 {
00108 node = make_shared(node->GetParent());
00109 }
00110
00111 return weak_ptr<Node>(node);
00112 }
00113
00114 bool Leaf::IsLeaf() const
00115 {
00116 return true;
00117 }
00118
00119 void Leaf::RemoveChildReference(const boost::shared_ptr<Leaf> &)
00120 {
00121 }
00122
00123 bool Leaf::AddChildReference(const boost::shared_ptr<Leaf> &)
00124 {
00125 return false;
00126 }
00127
00128 void Leaf::Unlink()
00129 {
00130
00131 SetParent(boost::shared_ptr<Node>());
00132 }
00133
00134 void Leaf::UnlinkChildren()
00135 {
00136 }
00137
00138 void Leaf::Dump() const
00139 {
00140 Object::Dump();
00141 cout << "Leaf: '" << GetName() << "'" << endl;
00142 }
00143
00144 const std::string& Leaf::GetFullPath() const
00145 {
00146
00147 if (mCachedFullPath == NULL)
00148 {
00149 std::string parentPath;
00150
00151 if (shared_ptr<Leaf> p = GetParent().lock())
00152 {
00153 if (p)
00154 {
00155 shared_ptr<Leaf> blah = make_shared(GetParent());
00156 parentPath = blah->GetFullPath();
00157 }
00158 }
00159
00160
00161 if (IsLeaf())
00162 mCachedFullPath = new std::string(parentPath + mName);
00163 else
00164 mCachedFullPath = new std::string(parentPath + mName + "/");
00165 }
00166
00167 return *mCachedFullPath;
00168 }
00169
00170 void Leaf::ClearCachedData() const
00171 {
00172 delete mCachedFullPath;
00173 mCachedFullPath = NULL;
00174 }
00175
00176 Leaf::TLeafList gFakeChildren;
00177
00178 Leaf::TLeafList::iterator Leaf::begin()
00179 {
00180 return gFakeChildren.begin();
00181 }
00182
00183 Leaf::TLeafList::const_iterator Leaf::begin() const
00184 {
00185 return gFakeChildren.begin();
00186 }
00187
00188 Leaf::TLeafList::iterator Leaf::end()
00189 {
00190 return gFakeChildren.end();
00191 }
00192
00193 Leaf::TLeafList::const_iterator Leaf::end() const
00194 {
00195 return gFakeChildren.end();
00196 }
00197
00198 void Leaf::SetParent(const boost::shared_ptr<Node> &newParent)
00199 {
00200 shared_ptr<Node> oldParent = make_shared(GetParent());
00201 if (oldParent.get() != 0)
00202 {
00203
00204 shared_ptr<Leaf> self
00205 = shared_static_cast<Leaf>(make_shared(GetSelf()));
00206
00207
00208
00209 assert(self.use_count() > 1);
00210
00211 if (newParent.get() == 0)
00212 {
00213
00214 OnUnlink();
00215 ClearCachedData();
00216 oldParent->RemoveChildReference(self);
00217 }
00218
00219
00220 oldParent->RemoveChildReference(self);
00221
00222
00223 if (newParent.get() != 0)
00224 {
00225 newParent->AddChildReference(self);
00226 }
00227 }
00228
00229 mParent = newParent;
00230 if (! mParent.expired())
00231 {
00232
00233 OnLink();
00234 }
00235 }
00236
00237 void Leaf::OnLink()
00238 {
00239 }
00240
00241 void Leaf::OnUnlink()
00242 {
00243 }