本文整理汇总了C++中boost::shared_ptr::AddChildReference方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::AddChildReference方法的具体用法?C++ shared_ptr::AddChildReference怎么用?C++ shared_ptr::AddChildReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::AddChildReference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetParent
void Leaf::SetParent(const boost::shared_ptr<Node> &newParent)
{
boost::shared_ptr<Node> oldParent = GetParent().lock();
boost::shared_ptr<Leaf> self = static_pointer_cast<Leaf>(GetSelf().lock());
if (oldParent.get() != 0)
{
// we have a parent, so update our state
// here reference count should be > 1 (at least one in the
// parent, and one in this routine)
assert(self.use_count() > 1);
if (newParent.get() == 0)
{
// time to clean up
OnUnlink();
ClearCachedData();
oldParent->RemoveChildReference(self);
}
// we remove ourself from the old parent's list of children
oldParent->RemoveChildReference(self);
// we add ourself to the new parent's list of children
if (newParent.get() != 0)
{
newParent->AddChildReference(self);
}
}
mParent = newParent;
if (newParent.get() == 0)
{
return;
}
// assure a unique name among our siblings
boost::shared_ptr<Leaf> sibling = newParent->GetChild(mName);
if (sibling != self)
{
stringstream ss;
ss << mName << "_" << newParent->GetNumberOfChildren() << ">";
mName = ss.str().c_str();
}
// we have been linked, so now we can do something :)
OnLink();
}
示例2: if
bool
RubySceneImporter::ReadGraph(sexp_t* sexp, boost::shared_ptr<BaseNode> root)
{
while (sexp != 0)
{
switch (sexp->ty)
{
case SEXP_VALUE:
{
string name = Lookup(string(sexp->val));
if (name == S_NODE)
{
sexp = sexp->next;
boost::shared_ptr<BaseNode> node = CreateNode(sexp);
if (node.get() == 0)
{
return false;
}
root->AddChildReference(node);
root = node;
}
else if (name == S_SELECT)
{
sexp = sexp->next;
string name(sexp->val); //todo: use abbrevTable here?
boost::shared_ptr<BaseNode> node =
dynamic_pointer_cast<BaseNode>(root->GetChild(name));
if (node.get() == 0)
{
GetLog()->Error() << "ERROR: Select: " << name << " not found\n";
return false;
}
root = node;
}
else if (name == S_PWD)
{
GetLog()->Debug() << "DEBUG: pwd: " << root->GetFullPath() << "\n";
}
else if (name == S_TEMPLATE)
{
sexp = sexp->next;
return ParseTemplate(sexp);
}
else if (name == S_DEFINE)
{
sexp = sexp->next;
return ParseDefine(sexp);
}
else if (name == S_SWITCH)
{
sexp = sexp->next;
return ParseSwitch(sexp, root);
} else {
return ReadMethodCall(sexp, root);
}
}
break;
case SEXP_LIST:
if (! ReadGraph(sexp->list,root))
{
return false;
}
break;
default:
return false;
}
sexp = sexp->next;
}
return true;
}