iSpike
2.1
Spike conversion library for robotics
|
00001 //iSpike includes 00002 #include "iSpike/ISpikeException.hpp" 00003 #include "iSpike/PropertyHolder.hpp" 00004 using namespace ispike; 00005 00006 00007 /*--------------------------------------------------------------------*/ 00008 /*--------- PROTECTED METHODS -------*/ 00009 /*--------------------------------------------------------------------*/ 00010 00012 void PropertyHolder::addProperty(Property property){ 00013 if(propertyMap.count(property.getName()) != 0){ 00014 LOG(LOG_CRITICAL) << "Property cannot be added because it already exists: "<< property.getName() <<endl; 00015 throw ISpikeException("Property cannot be added because it already exists."); 00016 } 00017 propertyMap[property.getName()] = property; 00018 } 00019 00020 00022 int PropertyHolder::updateIntegerProperty(Property& property){ 00023 checkProperty(property); 00024 propertyMap[property.getName()].setInt(property.getInt()); 00025 ++updatePropertyCount; 00026 return property.getInt(); 00027 } 00028 00030 double PropertyHolder::updateDoubleProperty(Property& property){ 00031 checkProperty(property); 00032 propertyMap[property.getName()].setDouble(property.getDouble()); 00033 ++updatePropertyCount; 00034 return property.getDouble(); 00035 } 00036 00038 string PropertyHolder::updateStringProperty(Property& property){ 00039 checkProperty(property); 00040 propertyMap[property.getName()].setString(property.getString()); 00041 ++updatePropertyCount; 00042 return property.getString(); 00043 } 00044 00046 string PropertyHolder::updateComboProperty(Property& property){ 00047 checkProperty(property); 00048 propertyMap[property.getName()].setString(property.getString()); 00049 propertyMap[property.getName()].setOptions(property.getOptions()); 00050 ++updatePropertyCount; 00051 return property.getString(); 00052 } 00053 00054 00055 /*--------------------------------------------------------------------*/ 00056 /*--------- PROTECTED METHODS -------*/ 00057 /*--------------------------------------------------------------------*/ 00058 00060 void PropertyHolder::checkProperty(Property& property){ 00061 if(propertyMap.count(property.getName()) == 0){ 00062 LOG(LOG_CRITICAL) << "Property does not exist in property map: " << property.getName() <<endl; 00063 throw ISpikeException("Property not recognized"); 00064 } 00065 } 00066 00067 00069 void PropertyHolder::printProperties(){ 00070 for(map<string, Property>::iterator iter = propertyMap.begin(); iter !=propertyMap.end(); ++iter ){ 00071 Property& tmpProp = iter->second; 00072 cout<<"Name: "<<tmpProp.getName()<<", "; 00073 if(tmpProp.getType() == Property::Integer) { 00074 cout<<"Type: Integer; value="<<tmpProp.getInt()<<endl; 00075 } else if(tmpProp.getType() == Property::Double) { 00076 cout<<"Type: Double; value="<<tmpProp.getDouble()<<endl; 00077 } else if(tmpProp.getType() == Property::String) { 00078 cout<<"Type: String; value="<<tmpProp.getString()<<endl; 00079 } else if(tmpProp.getType() == Property::Combo){ 00080 cout<<"Type: Combo; value="<<tmpProp.getString()<<"; Options="; 00081 vector<string> tmpOptions = tmpProp.getOptions(); 00082 for(unsigned i=0; i<tmpOptions.size(); ++i) 00083 cout<<tmpOptions[i]<<", "; 00084 cout<<endl; 00085 } 00086 } 00087 }