1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//
//
// Copyright (C) 2019 Greg Landrum and T5 Informatics GmbH
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#ifndef RD_NULLQUERYALGEBRA_H
#define RD_NULLQUERYALGEBRA_H
#include <GraphMol/QueryOps.h>
namespace RDKit {
namespace {
template <class T>
void mergeBothNullQ(T *&returnQuery, T *&otherNullQ,
Queries::CompositeQueryType how) {
bool negatedQ = returnQuery->getNegation();
bool negatedOtherQ = otherNullQ->getNegation();
if (how == Queries::COMPOSITE_AND) {
// This is the only case in which we need to do anything
if (!negatedQ && negatedOtherQ) {
returnQuery->setNegation(true);
}
} else if (how == Queries::COMPOSITE_OR) {
// This is the only case in which we need to do anything
if (negatedQ && !negatedOtherQ) {
returnQuery->setNegation(false);
}
} else if (how == Queries::COMPOSITE_XOR) {
if (!negatedQ && !negatedOtherQ) {
returnQuery->setNegation(true);
} else if (negatedQ + negatedOtherQ == 1) {
returnQuery->setNegation(false);
}
}
}
template <class T>
void mergeNullQFirst(T *&returnQuery, T *&otherQ,
Queries::CompositeQueryType how) {
bool negatedQ = returnQuery->getNegation();
if (how == Queries::COMPOSITE_AND) {
if (!negatedQ) {
std::swap(returnQuery, otherQ);
}
} else if (how == Queries::COMPOSITE_OR) {
if (negatedQ) {
std::swap(returnQuery, otherQ);
}
} else if (how == Queries::COMPOSITE_XOR) {
std::swap(returnQuery, otherQ);
if (!negatedQ) {
returnQuery->setNegation(!returnQuery->getNegation());
}
}
}
} // namespace
template <class T>
void mergeNullQueries(T *&returnQuery, bool isQueryNull, T *&otherQuery,
bool isOtherQNull, Queries::CompositeQueryType how) {
PRECONDITION(returnQuery, "bad query");
PRECONDITION(otherQuery, "bad query");
PRECONDITION(how == Queries::COMPOSITE_AND || how == Queries::COMPOSITE_OR ||
how == Queries::COMPOSITE_XOR,
"bad combination op");
if (isQueryNull && isOtherQNull) {
mergeBothNullQ(returnQuery, otherQuery, how);
} else if (isQueryNull) {
mergeNullQFirst(returnQuery, otherQuery, how);
} else if (isOtherQNull) {
std::swap(returnQuery, otherQuery);
mergeNullQFirst(returnQuery, otherQuery, how);
}
}
} // namespace RDKit
#endif
|