Commit 2dec584f by Maarten L. Hekkelman

clean up code

parent 5ab2ccae
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
#include <numeric> #include <numeric>
#include <regex> #include <regex>
#include <set> #include <set>
#include <shared_mutex>
#include <stack> #include <stack>
#include <tuple> #include <tuple>
#include <unordered_map> #include <unordered_map>
#include <shared_mutex>
#include <filesystem> #include <filesystem>
...@@ -570,36 +570,6 @@ void Datablock::write(std::ostream &os, const std::vector<std::string> &order) ...@@ -570,36 +570,6 @@ void Datablock::write(std::ostream &os, const std::vector<std::string> &order)
cat.write(os); cat.write(os);
} }
// // mmcif support, sort of. First write the 'entry' Category
// // and if it exists, _AND_ we have a Validator, write out the
// // auditConform record.
//
// for (auto& cat: mCategories)
// {
// if (cat.name() == "entry")
// {
// cat.write(os);
//
// if (mValidator != nullptr)
// {
// Category auditConform(*this, "audit_conform", nullptr);
// auditConform.emplace({
// { "dict_name", mValidator->dictName() },
// { "dict_version", mValidator->dictVersion() }
// });
// auditConform.write(os);
// }
//
// break;
// }
// }
//
// for (auto& cat: mCategories)
// {
// if (cat.name() != "entry" and cat.name() != "audit_conform")
// cat.write(os);
// }
} }
bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
...@@ -669,7 +639,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -669,7 +639,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
while (catB_i != catB.end()) while (catB_i != catB.end())
missingA.push_back(*catB_i++); missingA.push_back(*catB_i++);
if (not (missingA.empty() and missingB.empty())) if (not(missingA.empty() and missingB.empty()))
{ {
if (cif::VERBOSE > 1) if (cif::VERBOSE > 1)
{ {
...@@ -706,7 +676,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -706,7 +676,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
++catA_i; ++catA_i;
else else
{ {
if (not (*dbA.get(*catA_i) == *dbB.get(*catB_i))) if (not(*dbA.get(*catA_i) == *dbB.get(*catB_i)))
{ {
if (cif::VERBOSE > 1) if (cif::VERBOSE > 1)
{ {
...@@ -724,10 +694,10 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -724,10 +694,10 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
return result; return result;
} }
std::ostream& operator<<(std::ostream &os, const Datablock &data) std::ostream &operator<<(std::ostream &os, const Datablock &data)
{ {
// whoohoo... this sucks! // whoohoo... this sucks!
const_cast<Datablock&>(data).write(os); const_cast<Datablock &>(data).write(os);
return os; return os;
} }
...@@ -1162,7 +1132,7 @@ void CatIndex::reconstruct() ...@@ -1162,7 +1132,7 @@ void CatIndex::reconstruct()
insert(r.mData); insert(r.mData);
// maybe reconstruction can be done quicker by using the following commented code. // maybe reconstruction can be done quicker by using the following commented code.
// however, I've not had the time to think of a way to std::set the red/black flag correctly in that case. // however, I've not had the time to think of a way to set the red/black flag correctly in that case.
// std::vector<ItemRow*> rows; // std::vector<ItemRow*> rows;
// transform(mCat.begin(), mCat.end(), backInserter(rows), // transform(mCat.begin(), mCat.end(), backInserter(rows),
...@@ -1254,82 +1224,15 @@ size_t CatIndex::size() const ...@@ -1254,82 +1224,15 @@ size_t CatIndex::size() const
return result; return result;
} }
//bool CatIndex::isValid() const
//{
// bool result = true;
//
// if (mRoot != nullptr)
// {
// uint32_t minBlack = numeric_limits<uint32_t>::max();
// uint32_t maxBlack = 0;
//
// assert(not mRoot->mRed);
//
// result = isValid(mRoot, false, 0, minBlack, maxBlack);
// assert(minBlack == maxBlack);
// }
//
// return result;
//}
//
//bool CatIndex::validate(entry* h, bool isParentRed, uint32_t blackDepth, uint32_t& minBlack, uint32_t& maxBlack) const
//{
// bool result = true;
//
// if (h->mRed)
// assert(not isParentRed);
// else
// ++blackDepth;
//
// if (isParentRed)
// assert(not h->mRed);
//
// if (h->mLeft != nullptr and h->mRight != nullptr)
// {
// if (isRed(h->mLeft))
// assert(not isRed(h->mRight));
// if (isRed(h->mRight))
// assert(not isRed(h->mLeft));
// }
//
// if (h->mLeft != nullptr)
// {
// assert(mComp(h->mLeft->mRow, h->mRow) < 0);
// validate(h->mLeft, h->mRed, blackDepth, minBlack, maxBlack);
// }
// else
// {
// if (minBlack > blackDepth)
// minBlack = blackDepth;
// if (maxBlack < blackDepth)
// maxBlack = blackDepth;
// }
//
// if (h->mRight != nullptr)
// {
// assert(mComp(h->mRight->mRow, h->mRow) > 0);
// validate(h->mRight, h->mRight, blackDepth, minBlack, maxBlack);
// }
// else
// {
// if (minBlack > blackDepth)
// minBlack = blackDepth;
// if (maxBlack < blackDepth)
// maxBlack = blackDepth;
// }
//}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
RowSet::RowSet(Category &cat) RowSet::RowSet(Category &cat)
: mCat(&cat) : mCat(&cat)
// , mCond(nullptr)
{ {
} }
RowSet::RowSet(Category &cat, Condition &&cond) RowSet::RowSet(Category &cat, Condition &&cond)
: mCat(&cat) : mCat(&cat)
// , mCond(new Condition(std::forward<Condition>(cond)))
{ {
cond.prepare(cat); cond.prepare(cat);
...@@ -1343,21 +1246,17 @@ RowSet::RowSet(Category &cat, Condition &&cond) ...@@ -1343,21 +1246,17 @@ RowSet::RowSet(Category &cat, Condition &&cond)
RowSet::RowSet(const RowSet &rhs) RowSet::RowSet(const RowSet &rhs)
: mCat(rhs.mCat) : mCat(rhs.mCat)
, mItems(rhs.mItems) , mItems(rhs.mItems)
// , mCond(nullptr)
{ {
} }
RowSet::RowSet(RowSet &&rhs) RowSet::RowSet(RowSet &&rhs)
: mCat(rhs.mCat) : mCat(rhs.mCat)
, mItems(std::move(rhs.mItems)) , mItems(std::move(rhs.mItems))
// , mCond(rhs.mCond)
{ {
// rhs.mCond = nullptr;
} }
RowSet::~RowSet() RowSet::~RowSet()
{ {
// delete mCond;
} }
RowSet &RowSet::operator=(const RowSet &rhs) RowSet &RowSet::operator=(const RowSet &rhs)
...@@ -1469,7 +1368,7 @@ void Category::updateLinks() ...@@ -1469,7 +1368,7 @@ void Category::updateLinks()
auto childCat = mDb.get(link->mChildCategory); auto childCat = mDb.get(link->mChildCategory);
if (childCat == nullptr) if (childCat == nullptr)
continue; continue;
mChildLinks.push_back({ childCat, link }); mChildLinks.push_back({childCat, link});
} }
for (auto link : mValidator->getLinksForChild(mName)) for (auto link : mValidator->getLinksForChild(mName))
...@@ -1477,7 +1376,7 @@ void Category::updateLinks() ...@@ -1477,7 +1376,7 @@ void Category::updateLinks()
auto parentCat = mDb.get(link->mParentCategory); auto parentCat = mDb.get(link->mParentCategory);
if (parentCat == nullptr) if (parentCat == nullptr)
continue; continue;
mParentLinks.push_back({ parentCat, link }); mParentLinks.push_back({parentCat, link});
} }
} }
} }
...@@ -1543,21 +1442,6 @@ size_t Category::addColumn(std::string_view name) ...@@ -1543,21 +1442,6 @@ size_t Category::addColumn(std::string_view name)
return result; return result;
} }
// RowSet Category::find(Condition&& cond)
// {
// RowSet result(*this);
// cond.prepare(*this);
// for (auto r: *this)
// {
// if (cond(*this, r))
// result.push_back(r);
// }
// return result;
// }
void Category::reorderByIndex() void Category::reorderByIndex()
{ {
if (mIndex != nullptr) if (mIndex != nullptr)
...@@ -1667,21 +1551,6 @@ Row Category::operator[](Condition &&cond) ...@@ -1667,21 +1551,6 @@ Row Category::operator[](Condition &&cond)
return result; return result;
} }
// RowSet Category::find(Condition&& cond)
// {
// // return RowSet(*this, std::forward<Condition>(cond));
// RowSet result(*this);
// cond.prepare(*this);
// for (auto r: *this)
// {
// if (cond(*this, r))
// result.insert(result.end(), r);
// }
// return result;
// }
bool Category::exists(Condition &&cond) const bool Category::exists(Condition &&cond) const
{ {
bool result = false; bool result = false;
...@@ -2414,22 +2283,22 @@ bool operator==(const Category &a, const Category &b) ...@@ -2414,22 +2283,22 @@ bool operator==(const Category &a, const Category &b)
bool result = true; bool result = true;
// set<std::string> tagsA(a.fields()), tagsB(b.fields()); // set<std::string> tagsA(a.fields()), tagsB(b.fields());
// //
// if (tagsA != tagsB) // if (tagsA != tagsB)
// std::cout << "Unequal number of fields" << std::endl; // std::cout << "Unequal number of fields" << std::endl;
auto& validator = a.getValidator(); auto &validator = a.getValidator();
auto catValidator = validator.getValidatorForCategory(a.name()); auto catValidator = validator.getValidatorForCategory(a.name());
if (catValidator == nullptr) if (catValidator == nullptr)
throw std::runtime_error("missing cat validator"); throw std::runtime_error("missing cat validator");
typedef std::function<int(const char*,const char*)> compType; typedef std::function<int(const char *, const char *)> compType;
std::vector<std::tuple<std::string,compType>> tags; std::vector<std::tuple<std::string, compType>> tags;
auto keys = catValidator->mKeys; auto keys = catValidator->mKeys;
std::vector<size_t> keyIx; std::vector<size_t> keyIx;
for (auto& tag: a.fields()) for (auto &tag : a.fields())
{ {
auto iv = catValidator->getValidatorForItem(tag); auto iv = catValidator->getValidatorForItem(tag);
if (iv == nullptr) if (iv == nullptr)
...@@ -2439,7 +2308,8 @@ bool operator==(const Category &a, const Category &b) ...@@ -2439,7 +2308,8 @@ bool operator==(const Category &a, const Category &b)
throw std::runtime_error("missing type validator"); throw std::runtime_error("missing type validator");
tags.push_back(std::make_tuple(tag, std::bind(&cif::ValidateType::compare, tv, std::placeholders::_1, std::placeholders::_2))); tags.push_back(std::make_tuple(tag, std::bind(&cif::ValidateType::compare, tv, std::placeholders::_1, std::placeholders::_2)));
auto pred = [tag](const std::string& s) -> bool { return cif::iequals(tag, s) == 0; }; auto pred = [tag](const std::string &s) -> bool
{ return cif::iequals(tag, s) == 0; };
if (find_if(keys.begin(), keys.end(), pred) == keys.end()) if (find_if(keys.begin(), keys.end(), pred) == keys.end())
keyIx.push_back(tags.size() - 1); keyIx.push_back(tags.size() - 1);
} }
...@@ -2447,11 +2317,11 @@ bool operator==(const Category &a, const Category &b) ...@@ -2447,11 +2317,11 @@ bool operator==(const Category &a, const Category &b)
// a.reorderByIndex(); // a.reorderByIndex();
// b.reorderByIndex(); // b.reorderByIndex();
auto rowEqual = [&](const cif::Row& ra, const cif::Row& rb) auto rowEqual = [&](const cif::Row &ra, const cif::Row &rb)
{ {
int d = 0; int d = 0;
for (auto kix: keyIx) for (auto kix : keyIx)
{ {
std::string tag; std::string tag;
compType compare; compType compare;
...@@ -2498,7 +2368,7 @@ bool operator==(const Category &a, const Category &b) ...@@ -2498,7 +2368,7 @@ bool operator==(const Category &a, const Category &b)
std::vector<std::string> missingA, missingB, different; std::vector<std::string> missingA, missingB, different;
for (auto& tt: tags) for (auto &tt : tags)
{ {
std::string tag; std::string tag;
compType compare; compType compare;
...@@ -2507,8 +2377,12 @@ bool operator==(const Category &a, const Category &b) ...@@ -2507,8 +2377,12 @@ bool operator==(const Category &a, const Category &b)
// make it an option to compare unapplicable to empty or something // make it an option to compare unapplicable to empty or something
const char* ta = ra[tag].c_str(); if (strcmp(ta, ".") == 0 or strcmp(ta, "?") == 0) ta = ""; const char *ta = ra[tag].c_str();
const char* tb = rb[tag].c_str(); if (strcmp(tb, ".") == 0 or strcmp(tb, "?") == 0) tb = ""; if (strcmp(ta, ".") == 0 or strcmp(ta, "?") == 0)
ta = "";
const char *tb = rb[tag].c_str();
if (strcmp(tb, ".") == 0 or strcmp(tb, "?") == 0)
tb = "";
if (compare(ta, tb) != 0) if (compare(ta, tb) != 0)
{ {
...@@ -2529,18 +2403,6 @@ bool operator==(const Category &a, const Category &b) ...@@ -2529,18 +2403,6 @@ bool operator==(const Category &a, const Category &b)
return result; return result;
} }
// auto Category::iterator::operator++() -> iterator&
// {
// mCurrent = Row(mCurrent.data()->mNext);
// return *this;
// }
// auto Category::const_iterator::operator++() -> const_iterator&
// {
// mCurrent = Row(mCurrent.data()->mNext);
// return *this;
// }
namespace detail namespace detail
{ {
......
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