00001
00009 #include "SimObjectAttributes.h"
00010 #include <string.h>
00011
00012 SimObjectAttributes::SimObjectAttributes( shared_ptr<SimObjectAttributesDefinition> attrDef ) {
00013 this->attrDef = attrDef;
00014 attrDef->lock();
00015 this->mem = (char*)calloc( attrDef->mem_size(), 1 );
00016 }
00017
00018 SimObjectAttributes::SimObjectAttributes( SimObjectAttributes const& attr) {
00019 this->attrDef = attr.attrDef;
00020 this->mem = (char*)calloc( attrDef->mem_size(), 1 );
00021 memcpy( this->mem, attr.mem, attrDef->mem_size() );
00022 }
00023
00024 SimObjectAttributes::~SimObjectAttributes() {
00025 free( this->mem );
00026 }
00027
00028 template< typename T >
00029 T SimObjectAttributes::get( string name ) const
00030 {
00031 return *( (T*)( mem + attrDef->offset(name) ) );
00032 }
00033
00034 template< typename T >
00035 void SimObjectAttributes::set( string name, T value )
00036 {
00037 *( (T*)( mem + attrDef->offset(name) ) ) = value;
00038 }
00039
00040 template int SimObjectAttributes::get<int>( string name ) const;
00041 template float SimObjectAttributes::get<float>( string name ) const;
00042 template double SimObjectAttributes::get<double>( string name ) const;
00043 template long SimObjectAttributes::get<long>( string name ) const;
00044 template long long SimObjectAttributes::get<long long>( string name ) const;
00045
00046 template void SimObjectAttributes::set<int>( string name, int value );
00047 template void SimObjectAttributes::set<float>( string name, float value );
00048 template void SimObjectAttributes::set<double>( string name, double value );
00049 template void SimObjectAttributes::set<long>( string name, long value );
00050 template void SimObjectAttributes::set<long long>( string name, long long value );
00051