SimObjectAttributesDefinition.cpp

Go to the documentation of this file.
00001 
00009 #include "SimObjectAttributesDefinition.h"
00010 #include "PCSIMException.h"
00011 
00012 #include "boost/format.hpp"
00013 
00014 SimObjectAttributesDefinition::SimObjectAttributesDefinition()
00015         : m_memsize(0), m_locked(false) {}
00016 
00017 template< typename T >
00018 void SimObjectAttributesDefinition::add
00019     (string name) {
00020     if( m_locked ) {
00021         throw( PCSIM::Exception( "SimObjectAttributesDefinition::add", boost::str( boost::format("SimObjectAttributesDefinition already locked. Can not any new attributes.") ) ) );
00022     }
00023     if( m_offset_hash.find(name) != m_offset_hash.end() ) {
00024         throw( PCSIM::Exception( "SimObjectAttributesDefinition::add", boost::str( boost::format("Attribute with name %1% already exists.") % name ) ) );
00025     }
00026     m_offset_hash[name] = m_memsize;
00027     m_memsize += sizeof(T);
00028 }
00029 
00030 
00031 void SimObjectAttributesDefinition::addDouble(string const& name) {
00032     SimObjectAttributesDefinition::add<double>(name);
00033 }
00034 
00035 
00036 void SimObjectAttributesDefinition::addInt(string const& name) {
00037     SimObjectAttributesDefinition::add<int>(name);
00038 }
00039 
00040 
00041 void SimObjectAttributesDefinition::addString(string const& name, string const& value)
00042 {
00043     throw( PCSIM::Exception( "SimObjectAttributesDefinition::addString", "not implemented" ) );
00044 }
00045 
00046 
00047 size_t SimObjectAttributesDefinition::offset(string const& name) const
00048 {
00049     if( m_offset_hash.find(name) == m_offset_hash.end() ) {
00050         throw( PCSIM::Exception( "SimObjectAttributesDefinition::offset", boost::str( boost::format("Attribute with name %1% does not exists.") % name ) ) );
00051     }
00052 
00053     return m_offset_hash[name];
00054 }
00055 
00056 vector< string > SimObjectAttributesDefinition::names() const
00057 {
00058     vector< string > names(0);
00059     offsethash_t::const_iterator i;
00060     for( i = m_offset_hash.begin(); i != m_offset_hash.end(); i++ ) {
00061         names.push_back( i->first );
00062     }
00063     return names;
00064 }
00065 
00066 
00067 void SimObjectAttributesDefinition::lock() {
00068     m_locked = true;
00069 }
00070 
00071 SimObjectAttributesDefinition::~SimObjectAttributesDefinition() {}
00072 
00073 template void SimObjectAttributesDefinition::add<char>
00074 ( string name );
00075 template void SimObjectAttributesDefinition::add<short>
00076 ( string name );
00077 template void SimObjectAttributesDefinition::add<int>
00078 ( string name );
00079 template void SimObjectAttributesDefinition::add<float>
00080 ( string name );
00081 template void SimObjectAttributesDefinition::add<double>
00082 ( string name );
00083 template void SimObjectAttributesDefinition::add<long>
00084 ( string name );
00085 template void SimObjectAttributesDefinition::add<long long>
00086 ( string name );
00087 

Generated on Wed Jul 9 16:34:37 2008 for PCSIM by  doxygen 1.5.5