Commit 188fa4e5 by maarten

fixed crash definitively

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@525 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent d053492a
...@@ -437,13 +437,18 @@ class Row ...@@ -437,13 +437,18 @@ class Row
: mData(data) {} : mData(data) {}
Row(const ItemRow* data) Row(const ItemRow* data)
: mData(const_cast<ItemRow*>(data)), mConst(true) {} : mData(const_cast<ItemRow*>(data)), mCascade(false) {}
Row(const Row& rhs); Row(const Row& rhs);
Row& operator=(const Row& rhs); Row& operator=(const Row& rhs);
~Row(); ~Row();
void setCascading(bool cascade)
{
mCascade = cascade;
}
void next(); ///< make this row point to the next ItemRow void next(); ///< make this row point to the next ItemRow
struct const_iterator : public std::iterator<std::forward_iterator_tag, const Item> struct const_iterator : public std::iterator<std::forward_iterator_tag, const Item>
...@@ -556,7 +561,7 @@ class Row ...@@ -556,7 +561,7 @@ class Row
ItemRow* mData; ItemRow* mData;
uint32_t mLineNr = 0; uint32_t mLineNr = 0;
bool mConst = false; bool mCascade = true;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -1179,16 +1184,19 @@ class RowSet ...@@ -1179,16 +1184,19 @@ class RowSet
iterator() {} iterator() {}
iterator(const iterator& i) iterator(const iterator& i)
: mCurrentIter(i.mCurrentIter) : mPos(i.mPos)
, mEnd(i.mEnd)
, mCurrentRow(i.mCurrentRow) {} , mCurrentRow(i.mCurrentRow) {}
iterator(const std::vector<ItemRow*>::iterator& i) iterator(const std::vector<ItemRow*>::iterator& p, const std::vector<ItemRow*>::iterator& e)
: mCurrentIter(i) : mPos(p)
, mCurrentRow(*i) {} , mEnd(e)
, mCurrentRow(p == e ? nullptr : *p) {}
iterator& operator=(const iterator& i) iterator& operator=(const iterator& i)
{ {
mCurrentIter = i.mCurrentIter; mPos = i.mPos;
mEnd = i.mEnd;
mCurrentRow = i.mCurrentRow; mCurrentRow = i.mCurrentRow;
return *this; return *this;
} }
...@@ -1198,8 +1206,11 @@ class RowSet ...@@ -1198,8 +1206,11 @@ class RowSet
iterator& operator++() iterator& operator++()
{ {
++mCurrentIter; ++mPos;
mCurrentRow = Row(*mCurrentIter); if (mPos != mEnd)
mCurrentRow = Row(*mPos);
else
mCurrentRow = Row();
return *this; return *this;
} }
...@@ -1232,24 +1243,24 @@ class RowSet ...@@ -1232,24 +1243,24 @@ class RowSet
friend difference_type operator-(const iterator& a, const iterator& b) friend difference_type operator-(const iterator& a, const iterator& b)
{ {
return std::distance(a.mCurrentIter, b.mCurrentIter); return std::distance(a.mPos, b.mPos);
} }
bool operator==(const iterator& i) const { return mCurrentIter == i.mCurrentIter; } bool operator==(const iterator& i) const { return mPos == i.mPos; }
bool operator!=(const iterator& i) const { return mCurrentIter != i.mCurrentIter; } bool operator!=(const iterator& i) const { return mPos != i.mPos; }
private: private:
friend class RowSet; friend class RowSet;
std::vector<ItemRow*>::iterator current() const { return mCurrentIter; } std::vector<ItemRow*>::iterator current() const { return mPos; }
std::vector<ItemRow*>::iterator mCurrentIter; std::vector<ItemRow*>::iterator mPos, mEnd;
Row mCurrentRow; Row mCurrentRow;
}; };
iterator begin() { return iterator(mItems.begin()); } iterator begin() { return iterator(mItems.begin(), mItems.end()); }
iterator end() { return iterator(mItems.end()); } iterator end() { return iterator(mItems.end(), mItems.end()); }
Row front() const { return Row(mItems.front()); } Row front() const { return Row(mItems.front()); }
size_t size() const { return mItems.size(); } size_t size() const { return mItems.size(); }
...@@ -1271,7 +1282,7 @@ class RowSet ...@@ -1271,7 +1282,7 @@ class RowSet
iterator insert(iterator pos, ItemRow* item) iterator insert(iterator pos, ItemRow* item)
{ {
return iterator(mItems.insert(pos.current(), item)); return iterator(mItems.insert(pos.current(), item), mItems.end());
} }
private: private:
......
...@@ -2245,6 +2245,7 @@ void Category::write(ostream& os, const vector<string>& columns) ...@@ -2245,6 +2245,7 @@ void Category::write(ostream& os, const vector<string>& columns)
Row::Row(const Row& rhs) Row::Row(const Row& rhs)
: mData(rhs.mData) : mData(rhs.mData)
, mCascade(rhs.mCascade)
{ {
} }
...@@ -2262,14 +2263,12 @@ void Row::next() ...@@ -2262,14 +2263,12 @@ void Row::next()
Row& Row::operator=(const Row& rhs) Row& Row::operator=(const Row& rhs)
{ {
mData = rhs.mData; mData = rhs.mData;
mCascade = rhs.mCascade;
return *this; return *this;
} }
void Row::assign(const std::vector<Item>& values) void Row::assign(const std::vector<Item>& values)
{ {
if (mConst)
throw logic_error("Row is const, cannot assign values");
auto cat = mData->mCategory; auto cat = mData->mCategory;
map<string,tuple<int,string,string>> changed; map<string,tuple<int,string,string>> changed;
...@@ -2287,7 +2286,8 @@ void Row::assign(const std::vector<Item>& values) ...@@ -2287,7 +2286,8 @@ void Row::assign(const std::vector<Item>& values)
// see if we need to update any child categories that depend on these values // see if we need to update any child categories that depend on these values
// auto iv = col.mValidator; // auto iv = col.mValidator;
if (mCascade)
{
auto& validator = cat->getValidator(); auto& validator = cat->getValidator();
auto& db = cat->db(); auto& db = cat->db();
...@@ -2327,6 +2327,7 @@ void Row::assign(const std::vector<Item>& values) ...@@ -2327,6 +2327,7 @@ void Row::assign(const std::vector<Item>& values)
for (auto& cr: rows) for (auto& cr: rows)
cr.assign(newValues); cr.assign(newValues);
} }
}
} }
void Row::assign(const Item& value, bool skipUpdateLinked) void Row::assign(const Item& value, bool skipUpdateLinked)
...@@ -2353,9 +2354,6 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked) ...@@ -2353,9 +2354,6 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
if (mData == nullptr) if (mData == nullptr)
throw logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + to_string(column)); throw logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + to_string(column));
if (mConst)
throw logic_error("Row is const, cannot assign value '" + value + "' to column with index " + to_string(column));
auto cat = mData->mCategory; auto cat = mData->mCategory;
auto& col = cat->mColumns[column]; auto& col = cat->mColumns[column];
...@@ -2440,7 +2438,7 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked) ...@@ -2440,7 +2438,7 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
// see if we need to update any child categories that depend on this value // see if we need to update any child categories that depend on this value
auto iv = col.mValidator; auto iv = col.mValidator;
if (not skipUpdateLinked and iv != nullptr) if (not skipUpdateLinked and iv != nullptr and mCascade)
{ {
auto& validator = cat->getValidator(); auto& validator = cat->getValidator();
auto& db = cat->db(); auto& db = cat->db();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment