1 /*
2 * CCondition.cc
3 *
4 * Copyright 2014-2018 D. Mitch Bailey cvc at shuharisystem dot com
5 *
6 * This file is part of cvc.
7 *
8 * cvc is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * cvc is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with cvc. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * You can download cvc from https://github.com/d-m-bailey/cvc.git
22 */
23
24 #include "CCondition.hh"
25
CCondition(string theParameter,string theRelation,string theValue)26 CCondition::CCondition(string theParameter, string theRelation, string theValue) {
27 parameter = theParameter;
28 relation = gRelationStringMap[theRelation];
29 stringValue = theValue;
30 CNormalValue myNumericValue(theValue);
31 numericValue = myNumericValue;
32 }
33
CheckCondition(CNormalValue & theCheckValue)34 bool CCondition::CheckCondition(CNormalValue & theCheckValue) {
35 switch (relation) {
36 case equals: return (( theCheckValue == numericValue ) ? true : false);
37 case lessThan: return (( theCheckValue < numericValue ) ? true : false);
38 case greaterThan: return (( theCheckValue > numericValue ) ? true : false);
39 case notLessThan: return (( ! ( theCheckValue < numericValue )) ? true : false);
40 case notGreaterThan: return (( ! ( theCheckValue > numericValue )) ? true : false);
41 default: return false;
42 }
43 }
44
PrintRelation()45 string CCondition::PrintRelation() {
46 try {
47 return gRelationMap.at(relation);
48 }
49 catch (const out_of_range& oor_exception) {
50 return "??";
51 }
52 }
53
PrintValue()54 string CCondition::PrintValue() {
55 return to_string<long int>(numericValue.value) + "@" + to_string<int>(numericValue.scale);
56 }
57
Print(ostream & theLogFile,string theIndentation)58 void CCondition::Print(ostream & theLogFile, string theIndentation) {
59 if ( theIndentation == "same-line" ) {
60 theLogFile << " " << parameter << PrintRelation() << numericValue.Format();
61 } else {
62 theLogFile << theIndentation << "Condition: " << parameter << PrintRelation() << numericValue.Format() << endl;
63 }
64 }
65
66