Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
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;
}