00001 /* 00002 * Copyright (C) 2008, Daniel Kollar and Kevin Kroeninger. 00003 * All rights reserved. 00004 * 00005 * For the licensing terms see doc/COPYING. 00006 */ 00007 00008 // --------------------------------------------------------- 00009 00010 #include "BCDataPoint.h" 00011 #include "BCLog.h" 00012 00013 // --------------------------------------------------------- 00014 00015 BCDataPoint::BCDataPoint(int nvariables) 00016 { 00017 00018 // assign the specified number of variables to the data 00019 // point and fill with zero 00020 00021 fData.assign(nvariables, 0.0); 00022 00023 } 00024 00025 // --------------------------------------------------------- 00026 00027 BCDataPoint::BCDataPoint(std::vector<double> x) 00028 { 00029 00030 // copy all values of x to the data point 00031 for (std::vector<double>::const_iterator it = x.begin(); it != x.end(); ++it) 00032 fData.push_back(*it); 00033 00034 } 00035 00036 // --------------------------------------------------------- 00037 00038 BCDataPoint::~BCDataPoint() 00039 { 00040 00041 } 00042 00043 // --------------------------------------------------------- 00044 00045 double BCDataPoint::GetValue(int index) 00046 { 00047 00048 double value = -1.0; 00049 00050 // check if index is in range. return value if true ... 00051 if (index >= 0 && index < int(fData.size())) 00052 value = fData[index]; 00053 00054 // ... or give warning if not. 00055 else 00056 BCLog::Out(BCLog::warning, BCLog::warning,"BCDataPoint::GetValue. Index out of range."); 00057 00058 return value; 00059 00060 } 00061 00062 // --------------------------------------------------------- 00063 00064 void BCDataPoint::SetValue(int index, double value) 00065 { 00066 00067 // check if index is in range. set value if true ... 00068 00069 if (index >= 0 && index < int(fData.size())) 00070 fData[index] = value; 00071 00072 // ... or give warning if not. 00073 00074 else 00075 BCLog::Out(BCLog::warning, BCLog::warning,"BCDataPoint::SetValue. Index out of range."); 00076 00077 } 00078 00079 // --------------------------------------------------------- 00080 00081 void BCDataPoint::SetValues(std::vector <double> values) 00082 { 00083 00084 // check if sizes are the same. if true, clear the data point and copy from 00085 // the vector passed to the method ... 00086 00087 if (values.size() == fData.size()) 00088 { 00089 fData.clear(); 00090 00091 for (std::vector<double>::const_iterator it = values.begin(); it != values.end(); ++it) 00092 fData.push_back(*it); 00093 } 00094 00095 // ... or give warning if the size if not the same. 00096 00097 else 00098 BCLog::Out(BCLog::warning, BCLog::warning,"BCDataPoint::SetValues. vectors have different ranges."); 00099 00100 } 00101 00102 // --------------------------------------------------------- 00103 00104