BaseObject.h

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 #ifndef SOFA_CORE_OBJECTMODEL_BASEOBJECT_H
00028 #define SOFA_CORE_OBJECTMODEL_BASEOBJECT_H
00029 
00030 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00031 #pragma once
00032 #endif
00033 
00034 #include <sofa/core/objectmodel/Base.h>
00035 #include <sofa/core/objectmodel/BaseContext.h>
00036 #include <sofa/core/objectmodel/BaseObjectDescription.h>
00037 #include <sofa/helper/vector.h>
00038 
00039 namespace sofa
00040 {
00041 
00042 namespace core
00043 {
00044 
00045 namespace objectmodel
00046 {
00047 
00048 class Event;
00049 
00059 class BaseObject : public virtual Base
00060 {
00061 public:
00062     BaseObject();
00063 
00064     virtual ~BaseObject();
00065 
00068     void setContext(BaseContext* n);
00069 
00070     const BaseContext* getContext() const;
00071 
00072     BaseContext* getContext();
00074 
00078 
00080     template<class T>
00081     static bool canCreate(T*& /*obj*/, BaseContext* /*context*/, BaseObjectDescription* /*arg*/)
00082     {
00083         return true;
00084     }
00085 
00087     template<class T>
00088     static void create(T*& obj, BaseContext* context, BaseObjectDescription* arg)
00089     {
00090         obj = new T;
00091         if (context) context->addObject(obj);
00092         if (arg) obj->parse(arg);
00093     }
00094     
00096     virtual void init();
00097     
00099     virtual void bwdInit();
00100     
00102     virtual void reinit();
00103 
00105     virtual void storeResetState();
00106 
00108     virtual void reset();
00109     
00111     virtual void writeState( std::ostream& out );
00112     
00116     virtual void cleanup();
00117     
00119 
00123     
00124     Data<bool> f_listening;
00125     
00127     virtual void handleEvent( Event* );
00128 
00130     virtual void handleTopologyChange(){}
00131 
00133     virtual void handleStateChange(){}
00134     
00136     
00140     Data<bool> f_printLog;
00141 
00145     virtual void draw() {}
00146 
00147     const sofa::helper::vector<std::string> & getLogWarning(){return logWarnings;}
00148      
00149     void logWarning(std::string l){logWarnings.push_back(l); std::cerr<<"WARNING: " << l << "\n";}
00150     
00152     
00156     
00158     double getTime() const;
00159     
00161 
00162 protected:
00163     BaseContext* context_;
00164     sofa::helper::vector< std::string > logWarnings;
00165 };
00166 
00167 } // namespace objectmodel
00168 
00169 } // namespace core
00170 
00171 } // namespace sofa
00172 
00173 #endif

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