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
: mData(data) {}
Row(const ItemRow* data)
: mData(const_cast<ItemRow*>(data)), mConst(true) {}
: mData(const_cast<ItemRow*>(data)), mCascade(false) {}
Row(const Row& rhs);
Row& operator=(const Row& rhs);
~Row();
void setCascading(bool cascade)
{
mCascade = cascade;
}
void next(); ///< make this row point to the next ItemRow
struct const_iterator : public std::iterator<std::forward_iterator_tag, const Item>
......@@ -556,7 +561,7 @@ class Row
ItemRow* mData;
uint32_t mLineNr = 0;
bool mConst = false;
bool mCascade = true;
};
// --------------------------------------------------------------------
......@@ -1179,16 +1184,19 @@ class RowSet
iterator() {}
iterator(const iterator& i)
: mCurrentIter(i.mCurrentIter)
: mPos(i.mPos)
, mEnd(i.mEnd)
, mCurrentRow(i.mCurrentRow) {}
iterator(const std::vector<ItemRow*>::iterator& i)
: mCurrentIter(i)
, mCurrentRow(*i) {}
iterator(const std::vector<ItemRow*>::iterator& p, const std::vector<ItemRow*>::iterator& e)
: mPos(p)
, mEnd(e)
, mCurrentRow(p == e ? nullptr : *p) {}
iterator& operator=(const iterator& i)
{
mCurrentIter = i.mCurrentIter;
mPos = i.mPos;
mEnd = i.mEnd;
mCurrentRow = i.mCurrentRow;
return *this;
}
......@@ -1198,8 +1206,11 @@ class RowSet
iterator& operator++()
{
++mCurrentIter;
mCurrentRow = Row(*mCurrentIter);
++mPos;
if (mPos != mEnd)
mCurrentRow = Row(*mPos);
else
mCurrentRow = Row();
return *this;
}
......@@ -1232,24 +1243,24 @@ class RowSet
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 mCurrentIter != i.mCurrentIter; }
bool operator==(const iterator& i) const { return mPos == i.mPos; }
bool operator!=(const iterator& i) const { return mPos != i.mPos; }
private:
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;
};
iterator begin() { return iterator(mItems.begin()); }
iterator end() { return iterator(mItems.end()); }
iterator begin() { return iterator(mItems.begin(), mItems.end()); }
iterator end() { return iterator(mItems.end(), mItems.end()); }
Row front() const { return Row(mItems.front()); }
size_t size() const { return mItems.size(); }
......@@ -1271,7 +1282,7 @@ class RowSet
iterator insert(iterator pos, ItemRow* item)
{
return iterator(mItems.insert(pos.current(), item));
return iterator(mItems.insert(pos.current(), item), mItems.end());
}
private:
......
......@@ -2245,12 +2245,13 @@ void Category::write(ostream& os, const vector<string>& columns)
Row::Row(const Row& rhs)
: mData(rhs.mData)
, mCascade(rhs.mCascade)
{
}
Row::~Row()
{
}
void Row::next()
......@@ -2262,14 +2263,12 @@ void Row::next()
Row& Row::operator=(const Row& rhs)
{
mData = rhs.mData;
mCascade = rhs.mCascade;
return *this;
}
void Row::assign(const std::vector<Item>& values)
{
if (mConst)
throw logic_error("Row is const, cannot assign values");
auto cat = mData->mCategory;
map<string,tuple<int,string,string>> changed;
......@@ -2287,45 +2286,47 @@ void Row::assign(const std::vector<Item>& values)
// see if we need to update any child categories that depend on these values
// auto iv = col.mValidator;
auto& validator = cat->getValidator();
auto& db = cat->db();
for (auto linked: validator.getLinksForParent(cat->mName))
if (mCascade)
{
auto childCat = db.get(linked->mChildCategory);
if (childCat == nullptr)
continue;
auto& validator = cat->getValidator();
auto& db = cat->db();
// if (find(linked->mParentKeys.begin(), linked->mParentKeys.end(), iv->mTag) == linked->mParentKeys.end())
// continue;
for (auto linked: validator.getLinksForParent(cat->mName))
{
auto childCat = db.get(linked->mChildCategory);
if (childCat == nullptr)
continue;
Condition cond;
string childTag;
// if (find(linked->mParentKeys.begin(), linked->mParentKeys.end(), iv->mTag) == linked->mParentKeys.end())
// continue;
vector<Item> newValues;
for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
{
string pk = linked->mParentKeys[ix];
string ck = linked->mChildKeys[ix];
Condition cond;
string childTag;
if (changed.count(pk) > 0)
{
childTag = ck;
cond = move(cond) && (Key(ck) == std::get<1>(changed[pk]));
newValues.emplace_back(ck, std::get<2>(changed[pk]));
}
else
vector<Item> newValues;
for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
{
const char* value = (*this)[pk].c_str();
cond = move(cond) && (Key(ck) == value);
string pk = linked->mParentKeys[ix];
string ck = linked->mChildKeys[ix];
if (changed.count(pk) > 0)
{
childTag = ck;
cond = move(cond) && (Key(ck) == std::get<1>(changed[pk]));
newValues.emplace_back(ck, std::get<2>(changed[pk]));
}
else
{
const char* value = (*this)[pk].c_str();
cond = move(cond) && (Key(ck) == value);
}
}
}
auto rows = childCat->find(move(cond));
for (auto& cr: rows)
cr.assign(newValues);
auto rows = childCat->find(move(cond));
for (auto& cr: rows)
cr.assign(newValues);
}
}
}
......@@ -2353,9 +2354,6 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
if (mData == nullptr)
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& col = cat->mColumns[column];
......@@ -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
auto iv = col.mValidator;
if (not skipUpdateLinked and iv != nullptr)
if (not skipUpdateLinked and iv != nullptr and mCascade)
{
auto& validator = cat->getValidator();
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