00001
00002
00003 #include "CellBlock.h"
00004
00005 using namespace Yosokumo;
00006
00007
00008
00009 CellBlock::CellBlock() : Block()
00010 {
00011 setType(CELL);
00012 }
00013
00014 CellBlock::CellBlock(std::string id) : Block(id)
00015 {
00016 setType(CELL);
00017 }
00018
00019 CellBlock::CellBlock(
00020 std::vector<Cell>::iterator begin,
00021 std::vector<Cell>::iterator end) : Block()
00022 {
00023 setType(CELL);
00024 addCells(begin, end);
00025 }
00026
00027 CellBlock::CellBlock(
00028 std::list<Cell>::iterator begin,
00029 std::list<Cell>::iterator end) : Block()
00030 {
00031 setType(CELL);
00032 addCells(begin, end);
00033 }
00034
00035 CellBlock::CellBlock(
00036 std::string id,
00037 std::vector<Cell>::iterator begin,
00038 std::vector<Cell>::iterator end) : Block(id)
00039 {
00040 setType(CELL);
00041 addCells(begin, end);
00042 }
00043
00044 CellBlock::CellBlock(
00045 std::string id,
00046 std::list<Cell>::iterator begin,
00047 std::list<Cell>::iterator end) : Block(id)
00048 {
00049 setType(CELL);
00050 addCells(begin, end);
00051 }
00052
00053 CellBlock::~CellBlock()
00054 {}
00055
00056
00057
00058
00059 void CellBlock::addCell(const Cell &cell)
00060 {
00061 cellSequence.push_back(cell);
00062 }
00063
00064 bool CellBlock::addCells(
00065 std::vector<Cell>::iterator begin,
00066 std::vector<Cell>::iterator end)
00067 {
00068 unsigned old_size = cellSequence.size();
00069 cellSequence.insert(cellSequence.end(), begin, end);
00070 return cellSequence.size() != old_size;
00071 }
00072
00073 bool CellBlock::addCells(
00074 std::list<Cell>::iterator begin,
00075 std::list<Cell>::iterator end)
00076 {
00077 unsigned old_size = cellSequence.size();
00078 cellSequence.insert(cellSequence.end(), begin, end);
00079 return cellSequence.size() != old_size;
00080 }
00081
00082 bool CellBlock::removeCells(uint64_t numCellsToRemove)
00083 {
00084 if (numCellsToRemove == 0 || isEmpty())
00085 return false;
00086
00087 if (numCellsToRemove >= size())
00088 clearCells();
00089 else
00090 cellSequence.erase(
00091 cellSequence.end()-numCellsToRemove,
00092 cellSequence.end());
00093
00094 return true;
00095 }
00096
00097
00098 Cell CellBlock::getCell(uint64_t index) const
00099 {
00100 return cellSequence.at(index);
00101 }
00102
00103
00104 void CellBlock::clearCells()
00105 {
00106 cellSequence.clear();
00107 }
00108
00109 uint64_t CellBlock::size() const
00110 {
00111 return cellSequence.size();
00112 }
00113
00114 bool CellBlock::isEmpty() const
00115 {
00116 return cellSequence.empty();
00117 }
00118
00119
00120 std::string CellBlock::toString()
00121 {
00122 std::stringstream s;
00123
00124 s <<
00125 "CellBlock:" << '\n' <<
00126 " type = " << getType() << '\n' <<
00127 " studyIdentifier = " << getStudyIdentifier() << '\n';
00128
00129 for (uint64_t i = 0; i < size(); ++i)
00130 {
00131 Cell c = getCell(i);
00132
00133 s << "\n" << " " << c.toString();
00134 }
00135
00136 return s.str();
00137 }
00138
00139 std::ostream &operator<<(std::ostream &os, CellBlock &p)
00140 {
00141 os << p.toString();
00142 return os;
00143 }
00144
00145 std::stringstream &operator<<(std::stringstream &s, CellBlock &p)
00146 {
00147 s << p.toString();
00148 return s;
00149 }
00150
00151