BaseObjectDescription.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #include "BaseObjectDescription.h"
00028 #include "BaseContext.h"
00029 #include "BaseObject.h"
00030 #include <iostream>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace core
00036 {
00037 
00038 namespace objectmodel
00039 {
00040 
00041 BaseObjectDescription::BaseObjectDescription(const char* name, const char* type)
00042 {
00043     if (name)
00044         attributes["name"] = name;
00045     if (type)
00046         attributes["type"] = type;
00047 }
00048 
00049 BaseObjectDescription::~BaseObjectDescription()
00050 {
00051 //     for (std::map<std::string,std::string*>::iterator it = attributes.begin();
00052 //         it != attributes.end(); ++it)
00053 //     {
00054 //         delete it->second;
00055 //     }
00056     attributes.clear();
00057 }
00058 
00060 Base* BaseObjectDescription::getObject()
00061 {
00062     return NULL;
00063 }
00064 
00066 std::string BaseObjectDescription::getName()
00067 {
00068     return std::string(getAttribute("name",""));
00069 }
00070 
00072 BaseObjectDescription* BaseObjectDescription::getParent() const
00073 {
00074     return NULL;
00075 }
00076 
00078 std::string BaseObjectDescription::getBaseFile()
00079 {
00080     return "";
00081 }
00082 
00084 //const BaseObjectDescription::AttributeMap& BaseObjectDescription::getAttributeMap() const
00085 //{
00086 //    return attributes;
00087 //}
00088 
00090 BaseObjectDescription* BaseObjectDescription::find(const char* /*nodeName*/, bool /*absolute*/)
00091 {
00092     return NULL;
00093 }
00094 
00096 bool BaseObjectDescription::removeAttribute(const std::string&)
00097 {
00098     return false;
00099 }
00100 
00102 const char* BaseObjectDescription::getAttribute(const std::string& attr, const char* defaultVal)
00103 {
00104     AttributeMap::iterator it = attributes.find(attr);
00105     if (it == attributes.end())
00106         return defaultVal;
00107     else
00108         return it->second.c_str();
00109 }
00110 
00111 std::string BaseObjectDescription::getFullName()
00112 {
00113     BaseObjectDescription* parent = getParent();
00114     if (parent==NULL) return "/";
00115     std::string pname = parent->getFullName();
00116     pname += "/";
00117     pname += getName();
00118     return pname;
00119 }
00120 
00122 Base* BaseObjectDescription::findObject(const char* nodeName)
00123 {
00124     BaseObjectDescription* node = find(nodeName);
00125     if (node!=NULL)
00126     {
00127         //std::cout << "Found node "<<nodeName<<": "<<node->getName()<<std::endl;
00128         Base* obj = node->getObject();
00129         BaseContext* ctx = dynamic_cast<BaseContext*>(obj);
00130         if (ctx != NULL)
00131         {
00132             //std::cout << "Node "<<nodeName<<" is a context, returning MechanicalState."<<std::endl;
00133             obj = ctx->getMechanicalState();
00134         }
00135         return obj;
00136     }
00137     else
00138     {
00139         std::cout << "Node "<<nodeName<<" NOT FOUND."<<std::endl;
00140         return NULL;
00141     }
00142 }
00143 
00144 } // namespace objectmodel
00145 
00146 } // namespace core
00147 
00148 } // namespace sofa

Generated on Sun Nov 23 02:29:25 2008 for Sofa by  doxygen 1.5.7.1