00001
00002
00003
00004
00005 #include "GaudiKernel/PropertyMgr.h"
00006
00007
00008 #ifdef WIN32
00009 # include <string.h>
00010 # define strcasecmp _stricmp
00011 #else
00012 # include <strings.h>
00013 #endif
00014 #include <iostream>
00015 #include <strstream>
00016 #include <stdexcept>
00017
00018 PropertyMgr::PropertyMgr() { }
00019
00020 PropertyMgr::~PropertyMgr() {
00021
00022
00023
00024
00025
00026
00027
00028
00029 PropertyCollectionType::iterator it;
00030 std::vector<bool>::const_iterator itb = m_isOwned.begin( );
00031 for(it = m_properties.begin(); it != m_properties.end(); it++) {
00032 if ( (*itb) ) {
00033 delete (*it);
00034 }
00035 itb++;
00036 }
00037 }
00038
00039
00040 StatusCode PropertyMgr::setProperty(const Property& p) {
00041 PropertyCollectionType::iterator it;
00042
00043 for(it = m_properties.begin(); it != m_properties.end(); it++) {
00044 if( strcasecmp(((*it)->name()).c_str(), (p.name()).c_str()) == 0 ) {
00045
00046
00047
00048 try {
00049 (*it)->assign(p);
00050 } catch(...) {
00051 return StatusCode::FAILURE;
00052 }
00053 return StatusCode::SUCCESS;
00054 }
00055 }
00056 return StatusCode::FAILURE;
00057 }
00058
00059
00060 StatusCode
00061 PropertyMgr::setProperty( std::istream& i )
00062 {
00063 SimpleProperty< int > modelProperty;
00064 modelProperty.nameFromStream( i );
00065
00066 try {
00067 Property& actualProperty = const_cast<Property&>(getProperty( modelProperty.name( ) ));
00068 actualProperty.valueFromStream( i );
00069 } catch ( std::out_of_range ) {
00070 return StatusCode::FAILURE;
00071 }
00072
00073 return StatusCode::SUCCESS;
00074 }
00075
00076
00077 StatusCode
00078 PropertyMgr::setProperty( const std::string& n, const std::string& v )
00079 {
00080 try {
00081 Property& property = const_cast<Property&>(getProperty( n ));
00082 std::strstream s;
00083 s << v ;
00084 property.valueFromStream( s );
00085 s.freeze(false);
00086 } catch ( std::out_of_range ) {
00087 return StatusCode::FAILURE;
00088 }
00089 return StatusCode::SUCCESS;
00090 }
00091
00092
00093
00094 StatusCode PropertyMgr::getProperty(Property* p) const {
00095 try {
00096 const Property& source = getProperty( p->name() );
00097 source.load( *p );
00098 return StatusCode::SUCCESS;
00099 }
00100 catch ( ... ) {
00101 return StatusCode::FAILURE;
00102 }
00103 }
00104
00105
00106 const Property& PropertyMgr::getProperty( const std::string& name) const {
00107 PropertyCollectionType::const_iterator it;
00108
00109 for(it = m_properties.begin(); it != m_properties.end(); it++) {
00110 if( strcasecmp(((*it)->name()).c_str(), name.c_str()) == 0 ) {
00111
00112 return **it;
00113 }
00114 }
00115 throw std::out_of_range( "Property "+name+" not found." );
00116 }
00117
00118
00119 StatusCode PropertyMgr::getProperty( const std::string& n, std::string& v ) const {
00120
00121 std::strstream s;
00122 v = "";
00123 try {
00124 const Property& property = getProperty( n );
00125 property.nameAndValueAsStream(s);
00126 while( s.get() != ':' && !s.fail() ) { }
00127 while( !s.fail() ) v += s.get();
00128 return StatusCode::SUCCESS;
00129 }
00130 catch ( ... ) {
00131 return StatusCode::FAILURE;
00132 }
00133 }
00134
00135 const std::vector<Property*>& PropertyMgr::getProperties( ) const {
00136 return m_properties;
00137 }
00138
00139
00140
00141 StatusCode PropertyMgr::queryInterface(const IID&, void**) { return StatusCode::FAILURE; }
00142 unsigned long PropertyMgr::addRef() { return 0; }
00143 unsigned long PropertyMgr::release() { return 0; }