#include #include #include #include #include "preXmlLength.hh" #include "DWUnits.hh" #include "ExpatInterface/Element.h" namespace preXml { void Length::readFrom(const xml::Element & elt) { // Check we are reading the right kind of entity. assert(elt.getTagName() == string("length")); // These will be our allowed units: typedef std::map UnitMap; UnitMap uM; uM[string("mm")] = DWmm; uM[string("cm")] = DWcm; uM[string("m" )] = DWm; // Check we know this particular unit. string unit(elt[string("unit")]); assert(uM.find(unit) != uM.end()); // OK, we know the unit. We can go on. istrstream is(elt[string("value")].c_str()); double faceValue; is >> faceValue; this->_value = faceValue*uM[unit]; }; void Length::printMeNicelyTo(ostream & os) const { os << this->_value / DWmm << " mm"; }; } // end of namespace