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 <iostream>
#include <iomanip>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <limits>
using namespace std; using namespace std;
#include <libxml/parser.h> #include <libxml/parser.h>
@ -23,10 +25,12 @@ using namespace std;
namespace { namespace {
template<class T> T getValue(xmlChar* str) { template<class T> T getValue(xmlChar* str) {
std::istringstream iss; if (string((const char*)str).empty())
iss.str((const char*) str); return numeric_limits<T>::quiet_NaN();
T res; std::istringstream iss;
iss >> res; iss.str((const char*) str);
T res;
iss >> res;
return res; return res;
} }
} }
@ -199,28 +203,39 @@ bool Techno::writeToFile(string filePath) {
if (_rules.size() == 0) { if (_rules.size() == 0) {
throw DTRException("[ERROR] Cannot writeToFile since no rule is defined!"); throw DTRException("[ERROR] Cannot writeToFile since no rule is defined!");
} }
file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\">" << endl file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\">" << endl
<< " <physical_rules>" << endl; << " <physical_rules>" << endl;
file.setf(ios::left, ios::adjustfield);
for (size_t i = 0 ; i < _rules.size() ; i++) { for (size_t i = 0 ; i < _rules.size() ; i++) {
Rule* rule = _rules[i]; Rule* rule = _rules[i];
string name = "\""+rule->getName().getString()+"\"";
if (dynamic_cast<ARule*>(rule)) { if (dynamic_cast<ARule*>(rule)) {
file << " <arule name=\"" << rule->getName().getString() << "\" "; file << " <arule name=" << setw(20) << name << " ";
} else { } else {
file << " <rule name=\"" << rule->getName().getString() << "\" "; file << " <rule name=" << setw(20) << name << " ";
} }
int spacing = 18;
if (rule->getType() != Name("")) { 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("")) { if (rule->getLayer1() != Name("")) {
string l1 = "\""+rule->getLayer1().getString()+"\"";
if (rule->getLayer2() != Name("")) { 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 { } 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 file << " </physical_rules>" << endl
<< "</technology>" << endl; << "</technology>" << endl;

View File

@ -39,6 +39,8 @@ class Rule {
// modifiers // modifiers
inline void setType(Name); inline void setType(Name);
inline void setValue(double);
inline void setRef(Name);
// members // members
private: private:
@ -65,7 +67,9 @@ inline Name Rule::getLayer1() { return _layer1; };
inline Name Rule::getLayer2() { return _layer2; }; inline Name Rule::getLayer2() { return _layer2; };
inline const std::string& Rule::getValueAsString() { return _valueStr.getString(); }; 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 } // namespace DTR
#endif #endif