00001
00002
00003
00004 #include <sstream>
00005
00006 #include "Specimen.h"
00007 #include "EmptyValue.h"
00008
00009 using namespace Yosokumo;
00010
00011
00012
00013 Specimen::Specimen()
00014 {
00015 setSpecimenKey(0);
00016 setStatus (Specimen::ACTIVE);
00017 setWeight (1);
00018 setPredictand (EmptyValue());
00019 }
00020
00021 Specimen::Specimen(uint64_t key)
00022 {
00023 setSpecimenKey(key);
00024 setStatus (Specimen::ACTIVE);
00025 setWeight (1);
00026 setPredictand (EmptyValue());
00027 }
00028
00029 Specimen::Specimen
00030 (
00031 uint64_t key,
00032 std::vector<Cell>::iterator begin,
00033 std::vector<Cell>::iterator end
00034 )
00035 {
00036 addCells(begin, end);
00037 setSpecimenKey(key);
00038 setStatus (Specimen::ACTIVE);
00039 setWeight (1);
00040 setPredictand (EmptyValue());
00041 }
00042
00043 Specimen::Specimen
00044 (
00045 uint64_t key,
00046 std::list<Cell>::iterator begin,
00047 std::list<Cell>::iterator end
00048 )
00049 {
00050 addCells(begin, end);
00051 setSpecimenKey(key);
00052 setStatus (Specimen::ACTIVE);
00053 setWeight (1);
00054 setPredictand (EmptyValue());
00055 }
00056
00057 Specimen::Specimen
00058 (
00059 uint64_t key,
00060 Value predictand,
00061 std::vector<Cell>::iterator begin,
00062 std::vector<Cell>::iterator end
00063 )
00064 {
00065 addCells(begin, end);
00066 setSpecimenKey(key);
00067 setStatus (Specimen::ACTIVE);
00068 setWeight (1);
00069 setPredictand (predictand);
00070 }
00071
00072 Specimen::Specimen
00073 (
00074 uint64_t key,
00075 Value predictand,
00076 std::list<Cell>::iterator begin,
00077 std::list<Cell>::iterator end
00078 )
00079 {
00080 addCells(begin, end);
00081 setSpecimenKey(key);
00082 setStatus (Specimen::ACTIVE);
00083 setWeight (1);
00084 setPredictand (predictand);
00085 }
00086
00087 Specimen::Specimen
00088 (
00089 uint64_t key,
00090 Status status,
00091 uint64_t weight,
00092 Value predictand,
00093 std::vector<Cell>::iterator begin,
00094 std::vector<Cell>::iterator end
00095 )
00096 {
00097 addCells(begin, end);
00098 setSpecimenKey(key);
00099 setStatus (status);
00100 setWeight (weight);
00101 setPredictand (predictand);
00102 }
00103
00104 Specimen::Specimen
00105 (
00106 uint64_t key,
00107 Status status,
00108 uint64_t weight,
00109 Value predictand,
00110 std::list<Cell>::iterator begin,
00111 std::list<Cell>::iterator end
00112 )
00113 {
00114 addCells(begin, end);
00115 setSpecimenKey(key);
00116 setStatus (status);
00117 setWeight (weight);
00118 setPredictand (predictand);
00119 }
00120
00121 Specimen::Specimen(const Specimen &rhs)
00122 {
00123 operator=(rhs);
00124 }
00125
00126 Specimen::~Specimen()
00127 {}
00128
00129 Specimen &Specimen::operator=(const Specimen &rhs)
00130 {
00131 if (this == &rhs)
00132 return *this;
00133
00134 key = rhs.key ;
00135 status = rhs.status ;
00136 weight = rhs.weight ;
00137 predictand = rhs.predictand;
00138
00139 Specimen &r = const_cast<Specimen &>(rhs);
00140
00141 addCells(r.cellSequence.begin(), r.cellSequence.end());
00142
00143 return *this;
00144 }
00145
00146
00147
00148
00149 void Specimen::setSpecimenKey(uint64_t key)
00150 {
00151 this->key = key;
00152 }
00153
00154 uint64_t Specimen::getSpecimenKey() const
00155 {
00156 return key;
00157 }
00158
00159
00160 void Specimen::setStatus(Status s)
00161 {
00162 status = s;
00163 }
00164
00165 Specimen::Status Specimen::getStatus() const
00166 {
00167 return status;
00168 }
00169
00170
00171 void Specimen::setWeight(uint64_t w)
00172 {
00173 weight = w;
00174 }
00175
00176 uint64_t Specimen::getWeight() const
00177 {
00178 return weight;
00179 }
00180
00181
00182 void Specimen::setPredictand(Value v)
00183 {
00184 predictand = v;
00185 }
00186
00187 Value Specimen::getPredictand() const
00188 {
00189 return predictand;
00190 }
00191
00192
00193
00194
00195 void Specimen::addCell(const Cell &cell)
00196 {
00197 cellSequence.push_back(cell);
00198 }
00199
00200
00201 bool Specimen::addCells
00202 (
00203 std::vector<Cell>::iterator begin,
00204 std::vector<Cell>::iterator end
00205 )
00206 {
00207 unsigned old_size = cellSequence.size();
00208 cellSequence.insert(cellSequence.end(), begin, end);
00209 return cellSequence.size() != old_size;
00210 }
00211
00212 bool Specimen::addCells
00213 (
00214 std::list<Cell>::iterator begin,
00215 std::list<Cell>::iterator end
00216 )
00217 {
00218 unsigned old_size = cellSequence.size();
00219 cellSequence.insert(cellSequence.end(), begin, end);
00220 return cellSequence.size() != old_size;
00221 }
00222
00223 bool Specimen::removeCells(uint64_t numCellsToRemove)
00224 {
00225 if (numCellsToRemove == 0 || isEmpty())
00226 return false;
00227
00228 if (numCellsToRemove >= size())
00229 clearCells();
00230 else
00231 cellSequence.erase(
00232 cellSequence.end()-numCellsToRemove,
00233 cellSequence.end());
00234
00235 return true;
00236 }
00237
00238
00239 Cell Specimen::getCell(int index) const
00240 {
00241 return cellSequence.at(index);
00242 }
00243
00244 void Specimen::clearCells()
00245 {
00246 cellSequence.clear();
00247 }
00248
00249 uint64_t Specimen::size() const
00250 {
00251 return cellSequence.size();
00252 }
00253
00254 bool Specimen::isEmpty() const
00255 {
00256 return cellSequence.empty();
00257 }
00258
00259
00260
00261
00262 std::string Specimen::toString() const
00263 {
00264 std::stringstream s;
00265 s <<
00266 "Specimen:" << "\n" <<
00267 " key = " << getSpecimenKey() << "\n" <<
00268 "\n" <<
00269 " status = " << getStatus() << "\n" <<
00270 " weight = " << getWeight() << "\n" <<
00271 " predictand = " << predictand.toString() << "\n";
00272
00273 for (uint64_t i = 0; i < size(); ++i)
00274 {
00275 Cell c = getCell(i);
00276
00277 s << " " << c.toString();
00278 }
00279
00280 return s.str();
00281 }
00282
00283