00001
00002
00003 #include "SpecimenBlock.h"
00004
00005 using namespace Yosokumo;
00006
00007
00008
00009 SpecimenBlock::SpecimenBlock() : Block()
00010 {
00011 setType(SPECIMEN);
00012 }
00013
00014 SpecimenBlock::SpecimenBlock(std::string id) : Block(id)
00015 {
00016 setType(SPECIMEN);
00017 }
00018
00019 SpecimenBlock::SpecimenBlock(
00020 std::vector<Specimen>::iterator begin,
00021 std::vector<Specimen>::iterator end) : Block()
00022 {
00023 setType(SPECIMEN);
00024 addSpecimens(begin, end);
00025 }
00026
00027 SpecimenBlock::SpecimenBlock(
00028 std::list<Specimen>::iterator begin,
00029 std::list<Specimen>::iterator end) : Block()
00030 {
00031 setType(SPECIMEN);
00032 addSpecimens(begin, end);
00033 }
00034
00035 SpecimenBlock::SpecimenBlock(
00036 std::string id,
00037 std::vector<Specimen>::iterator begin,
00038 std::vector<Specimen>::iterator end) : Block(id)
00039 {
00040 setType(SPECIMEN);
00041 addSpecimens(begin, end);
00042 }
00043
00044 SpecimenBlock::SpecimenBlock(
00045 std::string id,
00046 std::list<Specimen>::iterator begin,
00047 std::list<Specimen>::iterator end) : Block(id)
00048 {
00049 setType(SPECIMEN);
00050 addSpecimens(begin, end);
00051 }
00052
00053 SpecimenBlock::~SpecimenBlock()
00054 {}
00055
00056
00057
00058
00059 void SpecimenBlock::addSpecimen(Specimen* specimen)
00060 {
00061 specimenSequence.push_back(specimen);
00062 }
00063
00064 bool SpecimenBlock::addSpecimens(
00065 std::vector<Specimen>::iterator begin,
00066 std::vector<Specimen>::iterator end)
00067 {
00068 bool changed = false;
00069
00070 for (std::vector<Specimen>::iterator i = begin; i != end; ++i)
00071 {
00072 addSpecimen(&(*i));
00073 changed = true;
00074 }
00075
00076 return changed;
00077 }
00078
00079 bool SpecimenBlock::addSpecimens(
00080 std::list<Specimen>::iterator begin,
00081 std::list<Specimen>::iterator end)
00082 {
00083 bool changed = false;
00084
00085 for (std::list<Specimen>::iterator i = begin; i != end; ++i)
00086 {
00087 addSpecimen(&(*i));
00088 changed = true;
00089 }
00090
00091 return changed;
00092 }
00093
00094 bool SpecimenBlock::removeSpecimens(uint64_t numSpecimensToRemove)
00095 {
00096 if (numSpecimensToRemove == 0 || isEmpty())
00097 return false;
00098
00099 if (numSpecimensToRemove >= size())
00100 clearSpecimens();
00101 else
00102 specimenSequence.erase(
00103 specimenSequence.end()-numSpecimensToRemove,
00104 specimenSequence.end());
00105
00106 return true;
00107 }
00108
00109 Specimen *SpecimenBlock::getSpecimen(uint64_t index) const
00110 {
00111 return specimenSequence[index];
00112 }
00113
00114
00115 void SpecimenBlock::clearSpecimens()
00116 {
00117 specimenSequence.clear();
00118 }
00119
00120 uint64_t SpecimenBlock::size() const
00121 {
00122 return specimenSequence.size();
00123 }
00124
00125 bool SpecimenBlock::isEmpty() const
00126 {
00127 return specimenSequence.empty();
00128 }
00129
00130
00131
00132
00133 std::string SpecimenBlock::toString()
00134 {
00135 std::stringstream s;
00136
00137 s <<
00138 "SpecimenBlock:" << '\n' <<
00139 " type = " << getType() << '\n' <<
00140 " studyIdentifier = " << getStudyIdentifier() << '\n';
00141
00142 for (uint64_t i = 0; i < size(); ++i)
00143 {
00144 Specimen* sp = getSpecimen(i);
00145
00146 s << "\n" << " " << sp->toString();
00147 }
00148
00149 return s.str();
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 std::ostream &operator<<(std::ostream &os, SpecimenBlock &sb)
00161 {
00162 os << sb.toString();
00163 return os;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173 std::stringstream &operator<<(std::stringstream &s, SpecimenBlock &sb)
00174 {
00175 s << sb.toString();
00176 return s;
00177 }
00178
00179