00001 #include "DcsData.h"
00002 #include "Sct/LogicErrors.h"
00003 #include <algorithm>
00004
00005 namespace SctData{
00006 DcsData::DataPoint::DataPoint(float value, OWLTime time)
00007 : value(value), time(time) {
00008 }
00009 DcsData::DataPoint::DataPoint() : value (0.), time(long(0)){
00010 }
00011 DcsData::DataPoint::~DataPoint(){
00012 }
00013
00014 std::string DcsData::getClassName() const{
00015 return "SctData::DcsData";
00016 }
00017
00018 DcsData::DcsData() {}
00019
00020 DcsData::~DcsData() {}
00021
00022 void DcsData::setParameter(const std::string& name, float value, OWLTime time){
00023 m_data[name]=DataPoint(value, time);
00024 }
00025
00026 bool DcsData::hasParameter(const std::string& name) const {
00027 return ( m_data.find(name) != m_data.end() );
00028 }
00029
00030 float DcsData::getParameter(const std::string& name) const {
00031 return getDataPoint(name).value;
00032 }
00033
00034 OWLTime DcsData::getTime(const std::string& name) const {
00035 return getDataPoint(name).time;
00036 }
00037
00038 std::list <std::string> DcsData::getAllParameterNames() const{
00039 std::list<std::string> names;
00040 for (std::map<std::string, DataPoint>::const_iterator i=m_data.begin();
00041 i!=m_data.end(); ++i){
00042 names.push_back((*i).first);
00043 }
00044 return names;
00045 }
00046
00047 DcsData::DataPoint DcsData::getDataPoint(const std::string& name) const {
00048 if (!hasParameter(name)){
00049 std::cerr << "No such parameter " << name << std::endl;
00050 for ( std::map<std::string, DataPoint>::const_iterator i = m_data.begin();
00051 i != m_data.end(); ++i ){
00052 std::cerr << "\t" << (*i).first << " = " << (*i).second.value << std::endl;
00053 }
00054 throw Sct::LogicError(string("No such parameter ")+name, __FILE__, __LINE__);
00055 }
00056 return (*m_data.find(name)).second;
00057 }
00058
00059 }