Technology parser parses simple

Physical Rules
This commit is contained in:
The Coriolis Project 2008-05-06 16:23:45 +00:00
parent 60e4882d0c
commit 0b6f74bda6
7 changed files with 138 additions and 47 deletions

View File

@ -2,6 +2,7 @@
#include "Technology.h"
using namespace Hurricane;
#include "ATechnology.h"
#include "ATechnologyXmlParser.h"
#include "AEnv.h"
@ -9,7 +10,22 @@ using namespace Hurricane;
void AEnv::create(const char* technoFilePath) {
DataBase* db = getDataBase();
if (db) {
throw Error("");
}
db = DataBase::create();
Technology* techno = Technology::create(db, Name("AnalogicTechnology"));
ATechnologyXmlParser::parse(technoFilePath, techno);
}
ATechnology* AEnv::getATechnology() {
DataBase* db = getDataBase();
if (!db) {
throw Error("");
}
Technology* technology = db->getTechnology();
if (!technology) {
throw Error("");
}
ATechnology* atechnology = ATechnology::getATechnology(technology);
return atechnology;
}

View File

@ -1,9 +1,12 @@
#ifndef AENV_H_
#define AENV_H_
class ATechnology;
class AEnv {
public:
static void create(const char* technoFilePath);
static ATechnology* getATechnology();
};
#endif /* AENV_H_ */

View File

@ -5,42 +5,28 @@ using namespace Hurricane;
#include "ATechnology.h"
namespace {
static Name ATechnologyPropertyName("ATechnologyProperty");
}
class ATechnologyProperty : public PrivateProperty {
public:
typedef PrivateProperty Inherit;
typedef map<string, ATechnology::PhysicalRule*> PhysicalRules;
static ATechnologyProperty* create(Technology* technology);
ATechnologyProperty();
virtual Name getName() const {
Name ATechnology::getName() const {
return ATechnologyPropertyName;
}
virtual string _getTypeName() const {
string ATechnology::_getTypeName() const {
return _TName("ATechnologyProperty");
}
void addPhysicalRule(ATechnology::PhysicalRule& physicalRule) {
PhysicalRules::iterator prit = physicalRules_.find(physicalRule.name_);
void ATechnology::addPhysicalRule(const string& name, double value, const string& reference) {
PhysicalRules::iterator prit = physicalRules_.find(name);
if (prit != physicalRules_.end()) {
throw Error("");
}
ATechnology::PhysicalRule* newPhysicalRule = new ATechnology::PhysicalRule(physicalRule);
PhysicalRule* newPhysicalRule = new PhysicalRule(name, value, reference);
physicalRules_[newPhysicalRule->name_] = newPhysicalRule;
}
private:
PhysicalRules physicalRules_;
};
ATechnologyProperty::ATechnologyProperty():
Inherit(),
physicalRules_()
{}
ATechnologyProperty* ATechnologyProperty::create(Technology* technology) {
ATechnologyProperty* prop = new ATechnologyProperty();
ATechnology* ATechnology::create(Technology* technology) {
ATechnology* prop = new ATechnology();
prop->_postCreate();
@ -49,9 +35,24 @@ ATechnologyProperty* ATechnologyProperty::create(Technology* technology) {
return prop;
}
ATechnology* ATechnology::getATechnology(Technology* technology) {
Property* property = technology->getProperty(ATechnologyPropertyName);
if (property) {
ATechnology* aTechnology = static_cast<ATechnology*>(property);
return aTechnology;
}
return NULL;
}
void ATechnology::print() {
cout << "Printing ATechnology" << endl;
cout << " o Physical Rules" << endl;
for (PhysicalRules::iterator prit = physicalRules_.begin();
prit != physicalRules_.end();
prit++) {
PhysicalRule* physicalRule = prit->second;
cout << " - name = " << physicalRule->name_ <<
", value = " << physicalRule->value_ <<
", ref = " << physicalRule->reference_ << endl;
}
}

View File

@ -1,13 +1,22 @@
#ifndef ATECHNOLOGY_H_
#define ATECHNOLOGY_H_
class ATechnology {
#include "Property.h"
using namespace Hurricane;
namespace Hurricane {
class Technology;
}
class ATechnology : public PrivateProperty {
public:
typedef PrivateProperty Inherit;
class PhysicalRule {
public:
PhysicalRule(string& name,
PhysicalRule(const string& name,
double value,
string& reference):
const string& reference):
name_(name),
value_(value),
reference_(reference) {}
@ -19,7 +28,21 @@ class ATechnology {
const double value_;
const string reference_;
};
static const PhysicalRule& getPhysicalRule(string name);
typedef map<string, ATechnology::PhysicalRule*> PhysicalRules;
static ATechnology* create(Hurricane::Technology* technology);
static ATechnology* getATechnology(Hurricane::Technology* technology);
const PhysicalRule* getPhysicalRule(string name);
void addPhysicalRule(const string& name, double value, const string& reference);
void print();
virtual Name getName() const;
virtual string _getTypeName() const;
ATechnology():
Inherit(),
physicalRules_() {}
private:
PhysicalRules physicalRules_;
};
#endif /* ATECHNOLOGY_H_*/

View File

@ -1,14 +1,42 @@
#include "ATechnologyXmlParser.h"
#include "ATechnology.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "Technology.h"
using namespace Hurricane;
#include "ATechnologyXmlParser.h"
namespace {
void readPhysicalRules(xmlNode* node, ATechnology* aTechnology) {
if (node->type == XML_ELEMENT_NODE && node->children) {
for (xmlNode* ruleNode = node->children;
ruleNode;
ruleNode = ruleNode->next) {
if (ruleNode->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(ruleNode->name, (xmlChar*)"rule")) {
xmlChar* ruleNameC = xmlGetProp(ruleNode, (xmlChar*)"name");
xmlChar* valueC = xmlGetProp(ruleNode, (xmlChar*)"value");
xmlChar* refC = xmlGetProp(ruleNode, (xmlChar*)"ref");
if (ruleNameC && valueC && refC) {
string ruleName((const char*)ruleNameC);
double value = atof((const char*)valueC);
string reference((const char*)refC);
aTechnology->addPhysicalRule(ruleName, value, reference);
}
}
}
}
}
}
ATechnology* parseFileAsTechnology(const char* filePath, Technology* technology) {
ATechnology* aTechnology = ATechnology::create(technology);
xmlDocPtr doc; /* the resulting document tree */
doc = xmlReadFile(filePath, NULL, 0);
@ -19,13 +47,22 @@ ATechnology* parseFileAsTechnology(const char* filePath, Technology* technology)
/*Get the design element node */
xmlNode* rootElement = xmlDocGetRootElement(doc);
if (rootElement->type == XML_ELEMENT_NODE && xmlStrEqual(rootElement->name, (xmlChar*)"technology")) {
if (rootElement->type == XML_ELEMENT_NODE &&
xmlStrEqual(rootElement->name, (xmlChar*)"technology")) {
xmlNode* child = rootElement->children;
for (xmlNode* node = child; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(node->name, (xmlChar*)"physical_rules")) {
readPhysicalRules(node, aTechnology);
}
}
}
}
}
}
ATechnology* parseTechnologyFromXml(const char* filePath, Technology* technology) {
ATechnology* ATechnologyXmlParser::parse(const char* filePath, Technology* technology) {
LIBXML_TEST_VERSION

View File

@ -9,7 +9,7 @@ class ATechnology;
class ATechnologyXmlParser {
public:
static ATechnology* parseTechnologyFromXml(const char* filePath, Hurricane::Technology* technology);
static ATechnology* parse(const char* filePath, Hurricane::Technology* technology);
};
#endif /*ATECHNOLOGYXMLPARSER_H_*/

View File

@ -1,16 +1,27 @@
#include <iostream>
#include "DBo.h"
#include "Warning.h"
#include "Error.h"
using namespace Hurricane;
#include "AEnv.h"
#include "ATechnology.h"
int main() {
int main(int argc, char* argv[]) {
try {
cout << "simple analogic test" << endl;
AEnv::create("toto");
if (argc != 2) {
cerr << "atest techno.xml";
exit(56);
}
AEnv::create(argv[1]);
ATechnology* aTechnology = AEnv::getATechnology();
if (!aTechnology) {
exit(56);
}
aTechnology->print();
exit(0);
} catch (Hurricane::Warning& w) {
cerr << w.what() << endl;