Adding support for unspecified values (saving NaN)

Adding setValue && setRef methods on Rules

    writeToFile method now produce an easy to read file thanks to iomanip.stw() method
This commit is contained in:
Damien Dupuis 2010-11-16 11:24:26 +00:00
parent b90b40f656
commit 7506bae16e
2 changed files with 31 additions and 12 deletions

View File

@ -8,10 +8,12 @@
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>
#include <limits>
using namespace std;
#include <libxml/parser.h>
@ -23,10 +25,12 @@ using namespace std;
namespace {
template<class T> T getValue(xmlChar* str) {
std::istringstream iss;
iss.str((const char*) str);
T res;
iss >> res;
if (string((const char*)str).empty())
return numeric_limits<T>::quiet_NaN();
std::istringstream iss;
iss.str((const char*) str);
T res;
iss >> res;
return res;
}
}
@ -203,24 +207,35 @@ bool Techno::writeToFile(string filePath) {
file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\">" << endl
<< " <physical_rules>" << endl;
file.setf(ios::left, ios::adjustfield);
for (size_t i = 0 ; i < _rules.size() ; i++) {
Rule* rule = _rules[i];
string name = "\""+rule->getName().getString()+"\"";
if (dynamic_cast<ARule*>(rule)) {
file << " <arule name=\"" << rule->getName().getString() << "\" ";
file << " <arule name=" << setw(20) << name << " ";
} else {
file << " <rule name=\"" << rule->getName().getString() << "\" ";
file << " <rule name=" << setw(20) << name << " ";
}
int spacing = 18;
if (rule->getType() != Name("")) {
file << "type=\"" << rule->getType().getString() << "\" ";
string type = "\""+rule->getType().getString()+"\"";
file << "type=" << setw(12) << type << " ";
spacing = 0;
}
if (rule->getLayer1() != Name("")) {
string l1 = "\""+rule->getLayer1().getString()+"\"";
if (rule->getLayer2() != Name("")) {
file << "layer1=\"" << rule->getLayer1().getString() << "\" layer2=\"" << rule->getLayer2().getString() << "\" ";
string l2 = "\""+rule->getLayer2().getString()+"\"";
file << "layer1=" << setw(10) << l1 << " layer2=" << setw(10) << l2 << " ";
} else {
file << "layer=\"" << rule->getLayer1().getString() << "\" ";
file << "layer=" << setw(11+spacing) << l1 << " ";
}
} else {
file << setw(36) << " ";
}
file << "value=\"" << rule->getValue() << "\" ref=\"" << rule->getRef().getString() << "\"/>" << endl;
ostringstream oss;
oss << "\"" << rule->getValue() <<"\"";
file << "value=" << setw(7) << oss.str() << " ref=\"" << rule->getRef().getString() << "\"/>" << endl;
}
file << " </physical_rules>" << endl
<< "</technology>" << endl;

View File

@ -39,6 +39,8 @@ class Rule {
// modifiers
inline void setType(Name);
inline void setValue(double);
inline void setRef(Name);
// members
private:
@ -65,7 +67,9 @@ inline Name Rule::getLayer1() { return _layer1; };
inline Name Rule::getLayer2() { return _layer2; };
inline const std::string& Rule::getValueAsString() { return _valueStr.getString(); };
inline void Rule::setType(Name type) { _type = type; };
inline void Rule::setType(Name type) { _type = type; };
inline void Rule::setValue(double value) { _value = value; _valueStr = to_string(value); };
inline void Rule::setRef(Name ref) { _ref = ref; };
} // namespace DTR
#endif