#include <Arith.h>
Public Types | |
| enum | eTagType { ETAG_const = 0, ETAG_refer, ETAG_add, ETAG_minus, ETAG_mul, ETAG_quo, ETAG_uminus, ETAG_max, ETAG_n } |
| The different element types handled (evaluated) by this class. More... | |
Public Methods | |
| Arith::Arith (const DOM_Element elt) | |
| double | evaluate () |
| Return a double, the result of performing all the operations indicated by the element and its children. More... | |
| void | saveValue () |
| add "value" attribute into DOM. More... | |
| ~Arith () | |
Static Public Methods | |
| double | getUnitsScale (const DOM_Element &elt) |
| Return scale factor due to units specification. More... | |
Private Types | |
| typedef DOMString * | ptrDOMString |
Private Methods | |
| double | add () |
| double | minus () |
| double | mul () |
| double | quo () |
| double | myMax () |
Static Private Methods | |
| void | init () |
Private Attributes | |
| DOM_Element | m_elt |
| int | m_tag |
| double | m_number |
| bool | m_evaluated |
Static Private Attributes | |
| ptrDOMString * | typeNames |
| ptrDOMString | valString |
| ptrDOMString | refToString |
| ptrDOMString | constString |
| ptrDOMString | referString |
| ptrDOMString | addString |
| ptrDOMString | minusString |
| ptrDOMString | uminusString |
| ptrDOMString | mulString |
| ptrDOMString | quoString |
| ptrDOMString | maxString |
| ptrDOMString | notesString |
| ptrDOMString | lengthString |
| ptrDOMString | cmString |
| ptrDOMString | mString |
Definition at line 12 of file Arith.h.
|
|
Definition at line 56 of file Arith.h. Referenced by init(). |
|
|
The different element types handled (evaluated) by this class.
Definition at line 15 of file Arith.h.
00015 {
00016 ETAG_const = 0,
00017 ETAG_refer,
00018 ETAG_add,
00019 ETAG_minus,
00020 ETAG_mul,
00021 ETAG_quo,
00022 ETAG_uminus,
00023 ETAG_max,
00024 ETAG_n
00025 } ;
|
|
|
Definition at line 41 of file Arith.h.
00041 {};
|
|
|
Definition at line 146 of file Arith.cxx. References xmlUtil::firstEltChild(), m_elt, and xmlUtil::nextEltSibling(). Referenced by evaluate().
00146 {
00147 double ans = 0.0;
00148 DOM_Element elt = firstEltChild(m_elt);
00149 ans += Arith(elt).evaluate();
00150 elt = nextEltSibling(elt);
00151 while (elt != DOM_Element()) {
00152 ans += Arith(elt).evaluate();
00153 elt = nextEltSibling(elt);
00154 }
00155 return ans;
00156 }
|
|
|
|
|
|
Return a double, the result of performing all the operations indicated by the element and its children.
Definition at line 70 of file Arith.cxx. References add(), ETAG_add, ETAG_const, ETAG_max, ETAG_minus, ETAG_mul, ETAG_quo, ETAG_refer, ETAG_uminus, xmlUtil::firstEltChild(), getUnitsScale(), m_elt, m_evaluated, m_number, minus(), mul(), myMax(), notesString, quo(), refToString, and valString. Referenced by saveValue().
00070 {
00071 if (!m_evaluated) { // evaluate
00072 DOM_Element curElt;
00073 switch(m_tag) {
00074 case ETAG_const: {
00075 DOMString val = m_elt.getAttribute(*valString);
00076 if (!(val.equals(DOMString()) ) ) { //got something
00077 // Had better convert properly to a double
00078 m_number = atof(xml::Dom::transToChar(val));
00079 m_number *= getUnitsScale(m_elt);
00080 }
00081 else { // must have a single operator child or refer child
00082 // either of which can be evaluated, optionally preceded
00083 // by a <notes> child, which we ignore
00084 curElt = firstEltChild(m_elt);
00085 if (curElt.getTagName().equals(*notesString)) { // move on
00086 DOM_Node next = curElt.getNextSibling();
00087 curElt = static_cast <DOM_Element &>(next);
00088 }
00089 m_number = Arith(curElt).evaluate();
00090 }
00091 break;
00092 }
00093 case ETAG_refer: {
00094 // Find the element pointed to and evaluate it
00095 DOMString ref = m_elt.getAttribute(*refToString);
00096 curElt = (m_elt.getOwnerDocument()).getElementById(ref);
00097 if (curElt.getTagName().equals("prim")) {
00098 m_number =
00099 atof(xml::Dom::transToChar(curElt.getAttribute(*valString)));
00100 m_number *= getUnitsScale(curElt);
00101 }
00102 else {
00103 m_number = Arith(curElt).evaluate();
00104 }
00105 break;
00106 }
00107 case ETAG_uminus: {
00108 // Have a single child
00109 curElt = firstEltChild(m_elt);
00110 m_number = -(Arith(curElt).evaluate());
00111 break;
00112 }
00113 // Do the work elsewhere for the remaining operators
00114 case ETAG_add: {
00115 m_number = add();
00116 break;
00117 }
00118
00119 case ETAG_mul: {
00120 m_number = mul();
00121 break;
00122 }
00123
00124 case ETAG_minus: {
00125 m_number = minus();
00126 break;
00127 }
00128 case ETAG_quo: {
00129 m_number = quo();
00130 break;
00131 }
00132
00133 case ETAG_max: {
00134 m_number = myMax();
00135 break;
00136 }
00137 default: {
00138 return 0;
00139 }
00140 }
00141 m_evaluated = true;
00142 }
00143 return m_number;
00144 }
|
|
|
Return scale factor due to units specification. For now only applies to lengths, which should be converted to mm (always returns 1.0 for other kinds of constants) Definition at line 233 of file Arith.cxx. References cmString, lengthString, and mString. Referenced by evaluate().
00233 {
00234 if (!(elt.getAttribute("uType")).equals(*lengthString) ) {
00235 return 1.0;
00236 }
00237
00238 DOMString unitLength = elt.getAttribute("unitLength");
00239 if (unitLength.equals(*cmString)) return 10.0;
00240 else if (unitLength.equals(*mString)) return 1000.0;
00241 else return 1.0;
00242 }
|
|
|
Definition at line 244 of file Arith.cxx. References addString, cmString, constString, ETAG_add, ETAG_const, ETAG_max, ETAG_minus, ETAG_mul, ETAG_n, ETAG_quo, ETAG_refer, ETAG_uminus, lengthString, maxString, minusString, mString, mulString, notesString, ptrDOMString, quoString, referString, refToString, typeNames, uminusString, and valString.
00244 {
00245 constString = new DOMString("const");
00246 referString = new DOMString("refer");
00247 addString = new DOMString("add");
00248 minusString = new DOMString("minus");
00249 mulString = new DOMString("mul");
00250 quoString = new DOMString("quo");
00251 uminusString = new DOMString("uminus");
00252 maxString = new DOMString("max");
00253 notesString = new DOMString("notes");
00254 lengthString = new DOMString("length");
00255 cmString = new DOMString("cm");
00256 mString = new DOMString("m");
00257
00258 valString = new DOMString("value");
00259 refToString = new DOMString("refTo");
00260
00261
00262 typeNames = new ptrDOMString[ETAG_n];
00263 typeNames[ETAG_const] = constString;
00264 typeNames[ETAG_refer] = referString;
00265 typeNames[ETAG_add] = addString;
00266 typeNames[ETAG_minus] = minusString;
00267 typeNames[ETAG_mul] = mulString;
00268 typeNames[ETAG_quo] = quoString;
00269 typeNames[ETAG_uminus] = uminusString;
00270 typeNames[ETAG_max] = maxString;
00271 }
|
|
|
Definition at line 181 of file Arith.cxx. References xmlUtil::firstEltChild(), m_elt, and xmlUtil::nextEltSibling(). Referenced by evaluate().
00181 {
00182 double ans;
00183 DOM_Element elt = firstEltChild(m_elt);
00184 ans = Arith(elt).evaluate();
00185 elt = nextEltSibling(elt);
00186 ans -= Arith(elt).evaluate();
00187 return ans;
00188 }
|
|
|
Definition at line 158 of file Arith.cxx. References xmlUtil::firstEltChild(), m_elt, and xmlUtil::nextEltSibling(). Referenced by evaluate().
00158 {
00159 double ans = 1.0;
00160 DOM_Element elt = firstEltChild(m_elt);
00161 ans *= Arith(elt).evaluate();
00162 elt = nextEltSibling(elt);
00163 while (elt != DOM_Element()) {
00164 ans *= Arith(elt).evaluate();
00165 elt = nextEltSibling(elt);
00166 }
00167 return ans;
00168 }
|
|
|
Definition at line 170 of file Arith.cxx. References xmlUtil::firstEltChild(), m_elt, and xmlUtil::nextEltSibling(). Referenced by evaluate().
00170 {
00171 DOM_Element elt = firstEltChild(m_elt);
00172 double ans = Arith(elt).evaluate();
00173 elt = nextEltSibling(elt);
00174 while (elt != DOM_Element()) {
00175 double newAns = Arith(elt).evaluate();
00176 if (newAns > ans) ans = newAns;
00177 elt = nextEltSibling(elt);
00178 }
00179 return ans;
00180 }
|
|
|
Definition at line 190 of file Arith.cxx. References xmlUtil::firstEltChild(), m_elt, and xmlUtil::nextEltSibling(). Referenced by evaluate().
00190 {
00191 double ans;
00192 double divisor;
00193 DOM_Element elt = firstEltChild(m_elt);
00194 ans = Arith(elt).evaluate();
00195 elt = nextEltSibling(elt);
00196 divisor = Arith(elt).evaluate(); // check for 0?
00197 ans /= divisor;
00198 return ans;
00199 }
|
|
|
add "value" attribute into DOM. This is a no-op for all but const elements. Definition at line 202 of file Arith.cxx. References ETAG_const, evaluate(), m_elt, m_evaluated, m_number, m_tag, and valString.
00202 {
00203 // Only makes sense for a const
00204 if (m_tag != ETAG_const) return;
00205
00206 if (!m_evaluated) evaluate();
00207
00208 // Check if we're supposed to be an int. If so, coerce
00209 // m_number to be nearby int in case of round-off error
00210 if (DOMString("int").equals(m_elt.getAttribute("type"))) {
00211 // If we're not already a perfect int, attempt to fix
00212 // so that we round the right way.
00213 // Otherwise, leave well enough alone
00214 long int intValue = m_number;
00215 double intified = intValue;
00216 if (intified != m_number) {
00217 double fixup = 0.5;
00218 if (m_number < 0.0) fixup = -fixup;
00219 long int intValue = (m_number + fixup);
00220 m_number = intValue;
00221 }
00222 }
00223 // Answer will always be returned in mm for length-type
00224 // constants, so, just in case, this attribute should be
00225 // set to "mm". If we're not a length-type constant,
00226 // setting this attribute is harmless.
00227
00228 xml::Dom::addAttribute(m_elt, *valString, m_number);
00229 xml::Dom::addAttribute(m_elt, std::string("unitLength"),
00230 std::string("mm"));
00231 }
|
|
|
Definition at line 39 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 47 of file Arith.cxx. Referenced by getUnitsScale(), and init(). |
|
|
Definition at line 37 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 46 of file Arith.cxx. Referenced by getUnitsScale(), and init(). |
|
|
Definition at line 51 of file Arith.h. Referenced by add(), evaluate(), minus(), mul(), myMax(), quo(), and saveValue(). |
|
|
|
|
|
|
|
|
Definition at line 52 of file Arith.h. Referenced by saveValue(). |
|
|
Definition at line 44 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 40 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 48 of file Arith.cxx. Referenced by getUnitsScale(), and init(). |
|
|
Definition at line 42 of file Arith.cxx. Referenced by init(). |
|
|
|
|
|
Definition at line 43 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 38 of file Arith.cxx. Referenced by init(). |
|
|
|
|
|
Definition at line 34 of file Arith.cxx. Referenced by init(). |
|
|
Definition at line 41 of file Arith.cxx. Referenced by init(). |
|
|
|
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001