// -*- mode: C++; tab-width: 4; indent-tabs-mode: t; -*- vim:ts=4:sw=4 // // Copyright (C) 2004 David Lau (skunix) // Chong Kai Xiong (descender) // // This file is part of The Plains of Usata. // // The Plains of Usata is licensed under the GNU General Public // License (GPL) version 2. For details, please see the COPYING file // included in the software distribution, or visit // http://www.fsf.org/licenses/gpl.html. // // $Id: scene-manager.cpp,v 1.1 2004/12/31 06:34:14 skunix Exp $ #include "scene-manager.hpp" #include namespace usata { namespace SM_internal { struct Impl { enum AddStatus { OK, DUPLICATE_NAME, BAD_NAME }; //! \todo make this optionaly a hash_map instead typedef std::map ChildrenMap; ChildrenMap children; Object* get_ptr(const std::string&); AddStatus add(const Object_sp& obj) { ChildrenMap::iterator it( children.find(obj->name())); if (it != children.end()) { return DUPLICATE_NAME; } //! \todo verify valid name children.insert(std::make_pair(obj->name(), obj)); return OK; } Object* lookup_ptr(const std::string& name) { Object* retval=0; ChildrenMap::iterator it(children.find(name)); if (it != children.end()) { retval=it->second.get(); } return retval; } Object_sp lookup(const std::string& name) { Object_sp retval; ChildrenMap::iterator it(children.find(name)); if (it != children.end()) { retval = it->second; } return retval; } bool remove(const std::string&, Object*) { return false; } }; } using namespace SM_internal; SceneManager::SceneManager() : impl(new Impl) { } SceneManager::~SceneManager() { } void SceneManager::add_child(const Object_sp& pObj, std::string& path) { std::string cpy(path); std::string name=NodeInterface::NodePathPop(cpy); if (cpy.empty()) // if cpy is empty, this is the end of the path { int result = impl->add(pObj); //! \todo check result, throw if invalid name, warn if dup return; } Object *child = impl->lookup_ptr(name); if (child == 0) { //! \todo throw! return; } NodeInterface *child_interface = dynamic_cast(child); if (child_interface == 0) { //! \todo throw! return; } return child_interface->add_child(pObj, cpy); } Object_sp SceneManager::get_child(const std::string& name) { return impl->lookup(name); } }