17 #ifndef AGX_PROPERTY_H 18 #define AGX_PROPERTY_H 32 #define PROPERTY_THROW_IF_TRUE(X, MESSAGE) if (X) { agxThrow std::runtime_error(MESSAGE); } 39 #define PROPERTY_TYPE(type, Type) \ 42 typedef agx::HashTable<std::string,type > Type ## Map;\ 46 Type ## Map m_ ## Type ## _map;\ 54 Type ## Map& getPropertyMap ## Type() { return m_ ## Type ## _map; };\ 61 size_t getNumberOfProperties ## Type() const{ return m_ ## Type ## _map.size(); };\ 63 void registerPropertyType ## Type()\ 65 m_types.insert( #Type );\ 73 type& addProperty ## Type( const std::string& name,\ 74 type value = type() )\ 76 m_ ## Type ## _map[name] = value;\ 77 return m_ ## Type ## _map[name];\ 84 bool removeProperty ## Type( const std::string& name)\ 86 Type ## Map::iterator p = m_ ## Type ## _map.find( name );\ 87 if(p == m_ ## Type ## _map.end()) return false; else { m_ ## Type ## _map.erase(p); return true; } \ 95 type& setProperty ## Type( const std::string& name, type value)\ 97 Type ## Map::iterator p = m_ ## Type ## _map.find( name );\ 98 PROPERTY_THROW_IF_TRUE( p == m_ ## Type ## _map.end(), "Property named "+name+" is missing" );\ 107 bool hasProperty ## Type( const std::string& name) const \ 108 {return m_ ## Type ## _map.find(name)!=m_ ## Type ## _map.end();};\ 115 type getProperty ## Type( const std::string& name ) const \ 117 Type ## Map::const_iterator p = m_ ## Type ## _map.find( name );\ 118 PROPERTY_THROW_IF_TRUE( p == m_ ## Type ## _map.end(), "Property " + name + " of type " + #Type + " is missing!" );\ 121 type& getProperty ## Type( const std::string& name ) \ 123 Type ## Map::iterator p = m_ ## Type ## _map.find( name );\ 124 PROPERTY_THROW_IF_TRUE( p == m_ ## Type ## _map.end(), "Property " + name + " of type " + #Type + " is missing!" );\ 132 bool getProperty ## Type( const std::string& name, type & value) const \ 134 if (hasProperty ## Type( name )) { \ 135 value = getProperty ## Type( name ); \ 142 void copyProperties ## Type( const PropertyContainer* pc ) {\ 143 if ( pc->m_ ## Type ## _map.size() == 0 ) return;\ 144 for ( Type ## Map::const_iterator i = pc->m_ ## Type ## _map.begin();\ 145 i != pc->m_ ## Type ## _map.end(); i++ ) {\ 146 m_ ## Type ## _map[i->first] = i->second;\ 163 registerPropertyTypeInt();
164 registerPropertyTypeFloat();
165 registerPropertyTypeDouble();
166 registerPropertyTypeReal();
167 registerPropertyTypeBool();
168 registerPropertyTypeString();
169 registerPropertyTypeLong();
170 registerPropertyTypeVec2();
171 registerPropertyTypeVec3();
178 copyPropertiesInt( pc );
179 copyPropertiesFloat( pc );
180 copyPropertiesDouble( pc );
181 copyPropertiesReal( pc );
182 copyPropertiesBool( pc );
183 copyPropertiesString( pc );
184 copyPropertiesLong( pc );
185 copyPropertiesVec2( pc );
186 copyPropertiesVec3( pc );
191 return m_types.find( name ) != m_types.end();
196 return m_types.size();
225 m_Double_map.clear();
228 m_String_map.clear();
243 #define SAVE_PROPERTY_CONTAINER( Out, TypeName, Type ) \ 245 TypeName ## Map::const_iterator it = m_ ## TypeName ## _map.begin(); \ 246 Out.beginSection("PropertyContainer");\ 247 Out.addAttribute("size", m_ ## TypeName ## _map.size() );\ 248 for(; it != m_ ## TypeName ## _map.end(); ++it) {\ 249 Type TypeName ## value; \ 250 std::string name = it->first; \ 251 TypeName ## value = it->second; \ 252 Out << agxStream::out( "name", name );\ 253 Out << agxStream::out( "value", TypeName ## value );\ 255 Out.endSection("PropertyContainer");\ 273 #define RESTORE_PROPERTY_CONTAINER( In, TypeName, Type ) \ 275 size_t size; std::string name;\ 278 m_ ## TypeName ## _map.clear(); \ 279 In.beginSection("PropertyContainer");\ 280 In.getAttribute("size", size); \ 281 for(size_t i=0; i < size ; ++i) {\ 282 In >> agxStream::in( "name", name );\ 283 In >> agxStream::in( "value", value );\ 284 addProperty ## TypeName (name, value);\ 286 In.endSection("PropertyContainer");\ 308 #endif // AGX_PROPERTY_H bool hasPropertyType(const std::string &name) const
Return true if a property of type name is present in the container.
AGXTERRAIN_EXPORT void clear()
void copyProperties(const PropertyContainer *pc)
agx::HashSet< std::string > TypeSet
size_t size() const
Return the number of types that are registered.
#define AGXPHYSICS_EXPORT
Base class providing referencing counted objects.
Class that is a container of named properties.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
virtual ~PropertyContainer()
agx::ref_ptr< PropertyContainer > PropertyContainerRef
#define PROPERTY_TYPE(type, Type)
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...