iSpike  2.1
Spike conversion library for robotics
D:/Home/Programs/iSpike/src/Property.cpp
Go to the documentation of this file.
00001 #include "iSpike/Property.hpp"
00002 #include "iSpike/ISpikeException.hpp"
00003 using namespace ispike;
00004 
00005 //Other includes
00006 #include <iostream>
00007 using namespace std;
00008 
00010 Property::Property(){
00011         type = Property::Undefined;
00012         name = "Unnamed";
00013         description = "Undescribed";
00014         readOnly = false;
00015 
00016         intVal = 0;
00017         doubleVal = 0.0;
00018         stringVal = "Undefined";
00019 }
00020 
00021 
00023 Property::Property(ValueType type, int value, string name, string description, bool readOnly){
00024         if(type == Property::Integer){
00025                 this->type = Property::Integer;
00026                 this->intVal = value;
00027                 this->doubleVal = 0;
00028         }
00029         else if(type == Property::Double){
00030                 this->type = Property::Double;
00031                 this->doubleVal = value;
00032                 this->intVal = 0;
00033         }
00034         this->name = name;
00035         this->description = description;
00036         this->readOnly = readOnly;
00037 
00038         stringVal = "Undefined";
00039 }
00040 
00041 
00043 Property::Property(ValueType type, double value, string name, string description, bool readOnly){
00044         if(type == Property::Integer){
00045                 this->type = Property::Integer;
00046                 this->intVal = (int)value;
00047                 this->doubleVal = 0;
00048         }
00049         else if(type == Property::Double){
00050                 this->type = Property::Double;
00051                 this->doubleVal = value;
00052                 this->intVal = 0;
00053         }
00054         this->name = name;
00055         this->description = description;
00056         this->readOnly = readOnly;
00057 
00058         this->stringVal = "Undefined";
00059 }
00060 
00061 
00063 Property::Property(string value, string name, string description, bool readOnly){
00064         this->type = Property::String;
00065         this->stringVal = value;
00066         this->name = name;
00067         this->description = description;
00068         this->readOnly = readOnly;
00069 
00070         this->intVal = 0;
00071         this->doubleVal = 0.0;
00072 }
00073 
00074 
00076 Property::Property(string value, vector<string> options, string name, string description, bool readOnly){
00077         this->type = Property::Combo;
00078         this->options = options;
00079         this->stringVal = value;
00080         this->name = name;
00081         this->description = description;
00082         this->readOnly = readOnly;
00083 
00084         this->intVal = 0;
00085         this->doubleVal = 0.0;
00086 }
00087 
00088 
00090 Property::Property(const Property& prop){
00091         this->type = prop.type;
00092         this->name = prop.name;
00093         this->description = prop.description;
00094         this->readOnly = prop.readOnly;
00095         this->intVal = prop.intVal;
00096         this->doubleVal = prop.doubleVal;
00097         this->stringVal = prop.stringVal;
00098         this->options = prop.options;
00099 }
00100 
00101 
00103 Property::~Property(){
00104 }
00105 
00106 
00107 /*----------------------------------------------------------*/
00108 /*------                PUBLIC METHODS                ------*/
00109 /*----------------------------------------------------------*/
00110 
00112 Property& Property::operator=(const Property& rhs){
00113         //Check for self assignment
00114         if(this == &rhs)
00115                 return *this;
00116 
00117         this->type = rhs.type;
00118         this->name = rhs.name;
00119         this->description = rhs.description;
00120         this->readOnly = rhs.readOnly;
00121         this->intVal = rhs.intVal;
00122         this->doubleVal = rhs.doubleVal;
00123         this->stringVal = rhs.stringVal;
00124         this->options = rhs.options;
00125 
00126         return *this;
00127 }
00128 
00129 
00130 int Property::getInt(){
00131         if(this->type == Property::Integer)
00132                 return intVal;
00133         throw ISpikeException("getInt() should not be called on a non-integer property: " + getName());
00134 }
00135 
00136 void Property::setInt(int newInt){
00137         if(this->type != Property::Integer)
00138                 throw ISpikeException("setInt() should not be called on a non-integer property: " + getName());
00139         this->intVal = newInt;
00140 }
00141 
00142 double Property::getDouble(){
00143         if(this->type == Property::Double)
00144                 return doubleVal;
00145         throw ISpikeException("getDouble() should not be called on a non-double property: " + getName());
00146 }
00147 
00148 void Property::setDouble(double newDouble){
00149         if(this->type != Property::Double)
00150                 throw ISpikeException("setDouble() should not be called on a non-double property: " + getName());
00151         this->doubleVal = newDouble;
00152 }
00153 
00154 string Property::getString(){
00155         if(this->type == Property::String || this->type == Property::Combo)
00156                 return stringVal;
00157         throw ISpikeException("getString() should not be called on a non-string or non-combo property: " + getName());
00158 }
00159 
00160 void Property::setString(string newString){
00161         if(this->type != Property::String && this->type != Property::Combo)
00162                 throw ISpikeException("setString() should not be called on a non-string or non-combo property: " + getName());
00163         this->stringVal = newString;
00164 }
00165 
00166 vector<string> Property::getOptions(){
00167         if(this->type == Property::Combo)
00168                 return options;
00169         throw ISpikeException("getOptions() should not be called on a non-combo property: " + getName());
00170 }
00171 
00172 void Property::setOptions(vector<string> options){
00173         if(this->type != Property::Combo)
00174                 throw ISpikeException("setOptions() should not be called on a non-combo property: " + getName());
00175         this->options = options;
00176 }
00177 
00178 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines