ObjectElement.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 :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #include <sofa/simulation/tree/xml/ObjectElement.h>
00026 #include <sofa/simulation/tree/xml/Element.inl>
00027 #include <sofa/core/ObjectFactory.h>
00028 
00029 
00030 namespace sofa
00031 {
00032 
00033 namespace simulation
00034 {
00035 
00036 namespace tree
00037 {
00038 
00039 namespace xml
00040 {
00041 
00042 using namespace sofa::defaulttype;
00043 using helper::Creator;
00044 
00045 //template class Factory< std::string, objectmodel::BaseObject, Node<objectmodel::BaseObject*>* >;
00046 
00047 ObjectElement::ObjectElement(const std::string& name, const std::string& type, BaseElement* parent)
00048 : Element<core::objectmodel::BaseObject>(name, type, parent)
00049 {
00050 }
00051 
00052 ObjectElement::~ObjectElement()
00053 {
00054 }
00055 
00056 
00057 bool ObjectElement::init()
00058 {
00059   int i=0;
00060   for (child_iterator<> it = begin(); it != end(); ++it)
00061   {
00062     i++;
00063     it->init();
00064   }
00065   
00066   return initNode();  
00067 }
00068 
00069 bool ObjectElement::initNode()
00070 {
00071     //if (!Element<core::objectmodel::BaseObject>::initNode()) return false;
00072     core::objectmodel::BaseContext* ctx = dynamic_cast<core::objectmodel::BaseContext*>(getParent()->getObject());
00073 
00074 //     std::cout << "ObjectElement: creating "<<getAttribute( "type", "" )<<std::endl;
00075     
00076 
00077     core::objectmodel::BaseObject *obj = core::ObjectFactory::CreateObject(ctx, this);
00078     
00079     if (obj == NULL)
00080         obj = Factory::CreateObject(this->getType(), this);
00081     if (obj == NULL)
00082         return false;
00083     setObject(obj);
00084     obj->setName(getName());
00085     
00086     // display any unused attributes
00087     std::string unused;
00088     for (AttributeMap::iterator it = attributes.begin(), itend = attributes.end(); it != itend; ++it)
00089     {
00090         if (!it->second.isAccessed())
00091         {
00092             unused += ' ';
00093             unused += it->first;
00094      
00095             obj->logWarning(std::string("Unused Attribute: \"") + it->first + std::string("\" with value: \"" ) + it->second.c_str() + std::string("\"") );       
00096         }
00097     }
00098     if (!unused.empty())
00099     {
00100         std::cerr << "WARNING: Unused attribute(s) in "<<getFullName()<<" :"<<unused<<std::endl;
00101     }
00102     return true;
00103 }
00104 
00105 SOFA_DECL_CLASS(Object)
00106 
00107 Creator<BaseElement::NodeFactory, ObjectElement> ObjectNodeClass("Object");
00108 
00109 const char* ObjectElement::getClass() const
00110 {
00111     return ObjectNodeClass.c_str();
00112 }
00113 
00114 } // namespace xml
00115 
00116 } // namespace tree
00117 
00118 } // namespace simulation
00119 
00120 } // namespace sofa
00121 

Generated on Sun Nov 23 04:05:48 2008 for Sofa by  doxygen 1.5.7.1