Debian Codegraph @

Kernel/DataTypeComparator.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef DATATYPECOMPARATOR_H
21 #define DATATYPECOMPARATOR_Hcxx . . $ `Kernel/DataTypeComparator.h:21:9`!
22
23 #include <ctime>
24 #include <string>
25 #include <ostream>
26
27 #include "fpp_assert.h"cxx . . $ `<file>/Kernel/fpp_assert.h`/
28 #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/
29
30 /// allows one to compare DataType values wrt appropriate type
31 class ComparableDTcxx . . $ ComparableDT#
32 {
33 private: // members
34 /// value as a string
35 stdcxx . . $ std/::stringcxx . . $ std/string# strValuecxx . . $ ComparableDT#strValue.;
36 /// value as a number
37 long longIntValuecxx . . $ ComparableDT#longIntValue. = 0;
38 /// value as a float
39 float floatValuecxx . . $ ComparableDT#floatValue. = 0.0;
40 /// value as a date
41 long timeValuecxx . . $ ComparableDT#timeValue. = 0; // FIXME!! FORNOW
42 /// tag of a value
43 enum ValueTypecxx . . $ ComparableDT#ValueType# { UNUSEDcxx . . $ ComparableDT#UNUSED. = 0, INTcxx . . $ ComparableDT#INT., STRcxx . . $ ComparableDT#STR., FLOATcxx . . $ ComparableDT#FLOAT., TIMEcxx . . $ ComparableDT#TIME. } vTypecxx . . $ ComparableDT#vType. = UNUSEDcxx . . $ ComparableDT#UNUSED.;
44
45 public: // interface
46 /// create empty dt
47 ComparableDTcxx . . $ ComparableDT#ComparableDT(49f6e7a06ebc5aa8).() = default;
48 /// create NUMBER's dt
49 explicit ComparableDTcxx . . $ ComparableDT#ComparableDT(1624ee8275b10bda). ( long int value )
50 : longIntValuecxx . . $ ComparableDT#longIntValue.(value)
51 , vTypecxx . . $ ComparableDT#vType.(INTcxx . . $ ComparableDT#INT.)
52 {}
53 /// create STRING's dt
54 explicit ComparableDTcxx . . $ ComparableDT#ComparableDT(85c52e162fed56f9). ( const char* value )
55 : strValuecxx . . $ ComparableDT#strValue.(value)
56 , vTypecxx . . $ ComparableDT#vType.(STRcxx . . $ ComparableDT#STR.)
57 {}
58 /// create FLOAT's dt
59 explicit ComparableDTcxx . . $ ComparableDT#ComparableDT(9364e6e7bff7660). ( float value )
60 : floatValuecxx . . $ ComparableDT#floatValue.(value)
61 , vTypecxx . . $ ComparableDT#vType.(FLOATcxx . . $ ComparableDT#FLOAT.)
62 {}
63 /// create dateTime's dt; use dummy parameter to distinguish it from INT one
64 explicit ComparableDTcxx . . $ ComparableDT#ComparableDT(3b75d2d14f60ac6a). ( long value, int )
65 : timeValuecxx . . $ ComparableDT#timeValue.(value)
66 , vTypecxx . . $ ComparableDT#vType.(TIMEcxx . . $ ComparableDT#TIME.)
67 {}
68 /// copy c'tor
69 ComparableDTcxx . . $ ComparableDT#ComparableDT(f06be5ec4c0c4bf9). ( const ComparableDTcxx . . $ ComparableDT#& copy ) = default;
70 /// assignment
71 ComparableDTcxx . . $ ComparableDT#& operatorcxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd).= ( const ComparableDTcxx . . $ ComparableDT#& copy ) = default;
72
73 /// get NUMBER
74 long int getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84). ( void ) const { return longIntValuecxx . . $ ComparableDT#longIntValue.; }
75 /// get STRING
76 const stdcxx . . $ std/::stringcxx . . $ std/string#& getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f). ( void ) const { return strValuecxx . . $ ComparableDT#strValue.; }
77 /// get FLOAT
78 float getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2). ( void ) const { return floatValuecxx . . $ ComparableDT#floatValue.; }
79 /// get TIME
80 long getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84). ( void ) const { return timeValuecxx . . $ ComparableDT#timeValue.; }
81 /// check if the datatype is discrete
82 bool hasDiscreteTypecxx . . $ ComparableDT#hasDiscreteType(50ce9a9e25b4a850). ( void ) const { return vTypecxx . . $ ComparableDT#vType. == INTcxx . . $ ComparableDT#INT. || vTypecxx . . $ ComparableDT#vType. == TIMEcxx . . $ ComparableDT#TIME.; }
83 /// check whether the comparator is inited
84 bool initedcxx . . $ ComparableDT#inited(50ce9a9e25b4a850). ( void ) const { return vTypecxx . . $ ComparableDT#vType. != UNUSEDcxx . . $ ComparableDT#UNUSED.; }
85 /// check whether the comparator is compatible with another one
86 bool compatiblecxx . . $ ComparableDT#compatible(91deb93419938144). ( const ComparableDTcxx . . $ ComparableDT#& other ) const { return !initedcxx . . $ ComparableDT#inited(50ce9a9e25b4a850).() || !other.initedcxx . . $ ComparableDT#inited(50ce9a9e25b4a850).() || vTypecxx . . $ ComparableDT#vType. == other.vTypecxx . . $ ComparableDT#vType.; }
87 /// correct min value if the DT is discrete and EXCL is true; @return new EXCL value
88 bool correctMincxx . . $ ComparableDT#correctMin(efaadfb7dc14930a). ( bool excl )
89 {
90 if ( vTypecxx . . $ ComparableDT#vType. == INTcxx . . $ ComparableDT#INT. && excl )
91 { // transform (n,} into [n+1,}
92 longIntValuecxx . . $ ComparableDT#longIntValue.++;
93 return false;
94 }
95 if ( vTypecxx . . $ ComparableDT#vType. == TIMEcxx . . $ ComparableDT#TIME. && excl )
96 { // transform (n,} into [n+1,}
97 timeValuecxx . . $ ComparableDT#timeValue.++;
98 return false;
99 }
100 return excl;
101 }
102 /// correct max value if the DT is discrete and EXCL is true; @return new EXCL value
103 bool correctMaxcxx . . $ ComparableDT#correctMax(efaadfb7dc14930a). ( bool excl )
104 {
105 if ( vTypecxx . . $ ComparableDT#vType. == INTcxx . . $ ComparableDT#INT. && excl )
106 { // transform (n,} into [n+1,}
107 longIntValuecxx . . $ ComparableDT#longIntValue.--;
108 return false;
109 }
110 if ( vTypecxx . . $ ComparableDT#vType. == TIMEcxx . . $ ComparableDT#TIME. && excl )
111 { // transform (n,} into [n+1,}
112 timeValuecxx . . $ ComparableDT#timeValue.--;
113 return false;
114 }
115 return excl;
116 }
117
118 // compare 2 values
119
120 /// check whether 2 DT entries with the same TYPE are equal
121 bool operatorcxx . . $ ComparableDT#`operator==`(91deb93419938144). == ( const ComparableDTcxx . . $ ComparableDT#& other ) const
122 {
123 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( vType == other.vType ); // sanity check
124 switch ( vTypecxx . . $ ComparableDT#vType. )
125 {
126 case INTcxx . . $ ComparableDT#INT.: return getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).() == other.getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).();
127 case STRcxx . . $ ComparableDT#STR.: return getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).() ==cxx . . $ std/`operator==`(2965e344aacb545b). other.getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).();
128 case FLOATcxx . . $ ComparableDT#FLOAT.: return getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).() == other.getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).();
129 case TIMEcxx . . $ ComparableDT#TIME.: return getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).() == other.getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).();
130 default: fpp_unreachablecxx . . $ EFPPAssertion#();
131 }
132 }
133 /// check whether 2 DT entries with the same TYPE are NOT equal
134 bool operatorcxx . . $ ComparableDT#`operator!=`(91deb93419938144). != ( const ComparableDTcxx . . $ ComparableDT#& other ) const
135 { return !(*this ==cxx . . $ ComparableDT#`operator==`(91deb93419938144). other); }
136 /// check whether 2 DT entries with the same TYPE are in '<' relation
137 bool operatorcxx . . $ ComparableDT#`operator<`(91deb93419938144). < ( const ComparableDTcxx . . $ ComparableDT#& other ) const
138 {
139 fpp_assertcxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9). ( vType == other.vType ); // sanity check
140 switch ( vTypecxx . . $ ComparableDT#vType. )
141 {
142 case INTcxx . . $ ComparableDT#INT.: return getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).() < other.getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).();
143 case STRcxx . . $ ComparableDT#STR.: return getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).() <cxx . . $ std/`operator<`(2965e344aacb545b). other.getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).();
144 case FLOATcxx . . $ ComparableDT#FLOAT.: return getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).() < other.getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).();
145 case TIMEcxx . . $ ComparableDT#TIME.: return getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).() < other.getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).();
146 default: fpp_unreachablecxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9).();
147 }
148 }
149 /// check whether 2 DT entries with the same TYPE are in '>' relation
150 bool operatorcxx . . $ ComparableDT#`operator>`(91deb93419938144). > ( const ComparableDTcxx . . $ ComparableDT#& other ) const { return other <cxx . . $ ComparableDT#`operator<`(91deb93419938144). *this; }
151
152 /// print the LISP value of a DTC; FIXME!! hack
153 stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& printValuecxx . . $ ComparableDT#printValue(be3b0a5ae87fb0b4). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
154 {
155 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ';
156 switch ( vTypecxx . . $ ComparableDT#vType. )
157 {
158 case INTcxx . . $ ComparableDT#INT.: o <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).(); break;
159 case FLOATcxx . . $ ComparableDT#FLOAT.: o <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).(); break;
160 case STRcxx . . $ ComparableDT#STR.: o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '"' <<cxx . . $ std/`operator<<`(88df5bef833f7f83). getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '"'; break;
161 case TIMEcxx . . $ ComparableDT#TIME.: o <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).(); break;
162 default: fpp_unreachablecxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9).();
163 }
164 return o;
165 }
166 friend stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& operatorcxx . . $ `operator<<`(e3894dd2e2b77146). << ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const ComparableDTcxx . . $ ComparableDT#& cdt );
167 }; // ComparableDT
168
169 inline
170 stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& operatorcxx . . $ `operator<<`(e3894dd2e2b77146). << ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const ComparableDTcxx . . $ ComparableDT#& cdt )
171 {
172 switch ( cdt.vTypecxx . . $ ComparableDT#vType. )
173 {
174 case ComparableDTcxx . . $ ComparableDT#::INTcxx . . $ ComparableDT#INT.: o <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). cdt.getLongIntValuecxx . . $ ComparableDT#getLongIntValue(57a65ae535d7db84).(); break;
175 case ComparableDTcxx . . $ ComparableDT#::STRcxx . . $ ComparableDT#STR.: o <<cxx . . $ std/`operator<<`(88df5bef833f7f83). cdt.getStringValuecxx . . $ ComparableDT#getStringValue(f4fff0029955a25f).(); break;
176 case ComparableDTcxx . . $ ComparableDT#::FLOATcxx . . $ ComparableDT#FLOAT.: o <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). cdt.getFloatValuecxx . . $ ComparableDT#getFloatValue(5036dfe8d4170af2).(); break;
177 case ComparableDTcxx . . $ ComparableDT#::TIMEcxx . . $ ComparableDT#TIME.: o <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). cdt.getTimeValuecxx . . $ ComparableDT#getTimeValue(57a65ae535d7db84).(); break;
178 default: fpp_unreachablecxx . . $ EFPPAssertion#();
179 }
180 return o;
181 }
182
183 #endif