From 0b6f74bda681daba28dd93b38533944f34343f4d Mon Sep 17 00:00:00 2001 From: The Coriolis Project Date: Tue, 6 May 2008 16:23:45 +0000 Subject: [PATCH] Technology parser parses simple Physical Rules --- chamsin/src/technology/AEnv.cpp | 16 +++++ chamsin/src/technology/AEnv.h | 3 + chamsin/src/technology/ATechnology.cpp | 71 ++++++++++--------- chamsin/src/technology/ATechnology.h | 31 ++++++-- .../src/technology/ATechnologyXmlParser.cpp | 43 ++++++++++- chamsin/src/technology/ATechnologyXmlParser.h | 2 +- chamsin/src/tests/AnalogicTest.cpp | 19 +++-- 7 files changed, 138 insertions(+), 47 deletions(-) diff --git a/chamsin/src/technology/AEnv.cpp b/chamsin/src/technology/AEnv.cpp index ac441170..8018e14f 100644 --- a/chamsin/src/technology/AEnv.cpp +++ b/chamsin/src/technology/AEnv.cpp @@ -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; } diff --git a/chamsin/src/technology/AEnv.h b/chamsin/src/technology/AEnv.h index 9e5bedd6..6a09a434 100644 --- a/chamsin/src/technology/AEnv.h +++ b/chamsin/src/technology/AEnv.h @@ -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_ */ diff --git a/chamsin/src/technology/ATechnology.cpp b/chamsin/src/technology/ATechnology.cpp index fb9f04d5..4a8a767e 100644 --- a/chamsin/src/technology/ATechnology.cpp +++ b/chamsin/src/technology/ATechnology.cpp @@ -5,42 +5,28 @@ using namespace Hurricane; #include "ATechnology.h" namespace { - static Name ATechnologyPropertyName("ATechnologyProperty"); +} +Name ATechnology::getName() const { + return ATechnologyPropertyName; +} -class ATechnologyProperty : public PrivateProperty { - public: - typedef PrivateProperty Inherit; - typedef map PhysicalRules; - static ATechnologyProperty* create(Technology* technology); - ATechnologyProperty(); - virtual Name getName() const { - return ATechnologyPropertyName; - } - virtual string _getTypeName() const { - return _TName("ATechnologyProperty"); - } - void addPhysicalRule(ATechnology::PhysicalRule& physicalRule) { - PhysicalRules::iterator prit = physicalRules_.find(physicalRule.name_); - if (prit != physicalRules_.end()) { - throw Error(""); - } - ATechnology::PhysicalRule* newPhysicalRule = new ATechnology::PhysicalRule(physicalRule); - physicalRules_[newPhysicalRule->name_] = newPhysicalRule; - } - private: - PhysicalRules physicalRules_; -}; +string ATechnology::_getTypeName() const { + return _TName("ATechnologyProperty"); +} +void ATechnology::addPhysicalRule(const string& name, double value, const string& reference) { + PhysicalRules::iterator prit = physicalRules_.find(name); + if (prit != physicalRules_.end()) { + throw Error(""); + } + PhysicalRule* newPhysicalRule = new PhysicalRule(name, value, reference); + physicalRules_[newPhysicalRule->name_] = newPhysicalRule; +} -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(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; + } +} diff --git a/chamsin/src/technology/ATechnology.h b/chamsin/src/technology/ATechnology.h index a085fca7..e035faf7 100644 --- a/chamsin/src/technology/ATechnology.h +++ b/chamsin/src/technology/ATechnology.h @@ -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 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_*/ diff --git a/chamsin/src/technology/ATechnologyXmlParser.cpp b/chamsin/src/technology/ATechnologyXmlParser.cpp index cfe1bc49..23c50155 100644 --- a/chamsin/src/technology/ATechnologyXmlParser.cpp +++ b/chamsin/src/technology/ATechnologyXmlParser.cpp @@ -1,14 +1,42 @@ +#include "ATechnologyXmlParser.h" + +#include "ATechnology.h" + #include #include #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 diff --git a/chamsin/src/technology/ATechnologyXmlParser.h b/chamsin/src/technology/ATechnologyXmlParser.h index 0561f441..ca8df01a 100644 --- a/chamsin/src/technology/ATechnologyXmlParser.h +++ b/chamsin/src/technology/ATechnologyXmlParser.h @@ -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_*/ diff --git a/chamsin/src/tests/AnalogicTest.cpp b/chamsin/src/tests/AnalogicTest.cpp index 2af546fa..d651bac8 100644 --- a/chamsin/src/tests/AnalogicTest.cpp +++ b/chamsin/src/tests/AnalogicTest.cpp @@ -1,17 +1,28 @@ #include +#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"); - exit(0); + cout << "simple analogic test" << endl; + 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; } catch (Hurricane::Error& e) {