BaseObjectDescription.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_CORE_OBJECTMODEL_BASEOBJECTDESCRIPTION_H
00028 #define SOFA_CORE_OBJECTMODEL_BASEOBJECTDESCRIPTION_H
00029
00030 #include <string>
00031 #include <list>
00032 #include <map>
00033
00034 namespace sofa
00035 {
00036
00037 namespace core
00038 {
00039
00040 namespace objectmodel
00041 {
00042
00043 class Base;
00044
00052 class BaseObjectDescription
00053 {
00054 public:
00055 class Attribute
00056 {
00057 protected:
00058 std::string value;
00059 bool accessed;
00060 public:
00061 Attribute() : accessed(false) {}
00062 Attribute(const std::string& v) : value(v), accessed(false) {}
00063 void operator=(const std::string& v) { value = v; }
00064 void operator=(const char* v) { value = v; }
00065 operator std::string() { accessed = true; return value; }
00066 const char* c_str() { accessed = true; return value.c_str(); }
00067 bool isAccessed() { return accessed; }
00068 void setAccessed(bool v) { accessed = v; }
00069 };
00070
00071 typedef std::map<std::string,Attribute> AttributeMap;
00072
00073 BaseObjectDescription(const char* name=NULL, const char* type=NULL);
00074
00075 virtual ~BaseObjectDescription();
00076
00078 virtual Base* getObject();
00079
00081 virtual std::string getName();
00082
00084 virtual BaseObjectDescription* getParent() const;
00085
00087 virtual std::string getBaseFile();
00088
00090
00091
00093 template<class T> void getAttributeList(T& container)
00094 {
00095 for (AttributeMap::iterator it = attributes.begin();
00096 it != attributes.end(); ++it)
00097 container.push_back(it->first);
00098 }
00099
00101 virtual BaseObjectDescription* find(const char* nodeName, bool absolute=false);
00102
00104 virtual Base* findObject(const char* nodeName);
00105
00107 virtual const char* getAttribute(const std::string& attr, const char* defaultVal=NULL);
00108
00110 virtual bool removeAttribute(const std::string& attr);
00111
00113 virtual std::string getFullName();
00114
00115 protected:
00116 AttributeMap attributes;
00117 };
00118
00119 }
00120
00121 }
00122
00123 }
00124
00125 #endif