Add optional Criteria && || operator support (#1797)

This commit is contained in:
OrbitZore 2023-09-26 13:58:02 +08:00 committed by GitHub
parent 63b7f5eb13
commit fd7af8110f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 4 deletions

View File

@ -21,8 +21,16 @@ namespace orm
{
const Criteria operator&&(Criteria cond1, Criteria cond2)
{
assert(cond1);
assert(cond2);
bool cond1valid = (bool)cond1, cond2valid = (bool)cond2;
assert(cond1valid || cond2valid);
if (cond1valid && !cond2valid)
{
return cond1;
}
if (!cond1valid && cond2valid)
{
return cond2;
}
Criteria cond;
cond.conditionString_ = "( ";
cond.conditionString_ += cond1.conditionString_;
@ -47,8 +55,16 @@ const Criteria operator&&(Criteria cond1, Criteria cond2)
const Criteria operator||(Criteria cond1, Criteria cond2)
{
assert(cond1);
assert(cond2);
bool cond1valid = (bool)cond1, cond2valid = (bool)cond2;
assert(cond1valid || cond2valid);
if (cond1valid && !cond2valid)
{
return cond1;
}
if (!cond1valid && cond2valid)
{
return cond2;
}
Criteria cond;
cond.conditionString_ = "( ";
cond.conditionString_ += cond1.conditionString_;