Changeset 108
- Timestamp:
- 06/18/10 14:33:19 (14 years ago)
- Location:
- XMLIO_V2/dev/dev_rv/src/XMLIO
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
r104 r108 12 12 class IStringStream_alt 13 13 { 14 public : 14 public : 15 15 IStringStream_alt(const std::string& str) : iss(str) 16 16 { /* Ne rien faire de plus */} 17 17 18 18 istream& operator>> (std::string& s) {s.assign(this->iss.str()); return (this->iss);} 19 19 istream& operator>> (int& s) { return (iss>>s); } … … 24 24 return (this->iss); 25 25 } 26 27 private : 26 27 private : 28 28 istringstream iss; 29 29 30 30 }; // class IStringStream_alt 31 31 … … 35 35 { 36 36 public : 37 37 38 38 bool hasValue ; 39 39 Ctype value ; 40 41 virtual bool _hasValue() {return hasValue;}42 40 43 virtual const char * getName(void) const = 0 ;44 41 virtual bool _hasValue() const { return hasValue; } 42 45 43 Attribut(void) : hasValue(false) {} ; 46 44 Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ; 47 48 Attribut(const Attribut& attr) : hasValue(attr.hasValue) 45 46 Attribut(const Attribut& attr) : hasValue(attr.hasValue) 49 47 { if (hasValue) value=attr.value ; } 50 48 51 49 Attribut& operator = (const Attribut & attr) 52 { 50 { 53 51 hasValue=attr.hasValue ; 54 52 if (hasValue) value=attr.value ; 55 return *this ; 53 return *this ; 56 54 } 57 55 58 56 virtual const char * getType(void) const = 0; 59 60 virtual void setFromString(const std::string str) 61 { 57 58 virtual void setFromString(const std::string str) 59 { 62 60 IStringStream_alt iss(str); Ctype val; 63 61 iss >> val; 64 62 this->setValue(val); 65 } 63 } 66 64 67 operator Ctype() 65 operator Ctype() const 68 66 { 69 if (!hasValue) 70 { 71 ostringstream oss; 72 oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>"; 73 74 throw XMLIOUndefinedValueException(oss.str()); 75 } 67 if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 76 68 return value ; 77 69 } 78 70 79 71 virtual void assignValue(const BaseAttribut* _ba) 80 72 { value = ((Attribut*)_ba) -> value; hasValue = true; } … … 85 77 virtual void setValue(const Ctype & value_) 86 78 { hasValue=true ; value=value_ ; } 87 79 88 80 virtual void getValue(Ctype & value_) const 89 81 { 90 if (!hasValue) 91 { 92 ostringstream oss; 93 oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>"; 94 95 throw XMLIOUndefinedValueException(oss.str()); 96 } 82 if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 97 83 value_=value ; 98 84 } 99 85 100 }; // class Attribut 86 }; // class Attribut 101 87 }; // namespace XMLIOSERVER 102 88 103 89 #endif //__ATTRIBUT__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut_registrar.hpp
r107 r108 52 52 void setSAttribut(const string& att_name, const std::string& value) 53 53 { 54 //std::cout << "Attribut :" << att_name<< ", " << value<< std::endl; 55 56 if (hasAttribut(att_name)) 57 { getAttribut(att_name)->setFromString(value) ; } 58 else 59 { 60 ostringstream oss; 61 oss << "CAttributRegistrar::setAttribut<ValueType>, could not find <<" << att_name <<">> attribut in registred list" <<">>"; 62 throw XMLIOUndefinedValueException(oss.str()); 63 } 54 if (hasAttribut(att_name)) getAttribut(att_name)->setFromString(value); 55 else throw XMLIOUndefinedValueException("Impossible de trouver l'attribut nommé \"" + att_name +"\" dans la liste des attributs enregistrés !"); 64 56 } 65 57 -
XMLIO_V2/dev/dev_rv/src/XMLIO/base_attribut.hpp
r104 r108 13 13 { 14 14 public: 15 16 virtual const char * getName(void) const = 0 ;15 16 virtual string getName(void) const = 0 ; 17 17 virtual ostream & print(ostream& o) const = 0 ; 18 18 19 19 friend ostream& operator <<(ostream& o,const BaseAttribut& Attr) 20 20 {return Attr.print(o) ; } 21 21 22 22 virtual void assignValue(const BaseAttribut*) = 0; 23 24 virtual const char * getId(void){return getName();} ;23 24 virtual string getId(void) const {return getName();} ; 25 25 bool hasId(void){return (true);} 26 26 27 27 virtual void setFromString(const std::string str) = 0; 28 28 29 29 #define SETTER_AND_GETTER(TYPE) \ 30 30 virtual void setValue(const TYPE & value) { error_set() ; }\ … … 36 36 virtual void getValue(Array<TYPE,2>& value) const { error_get() ; }\ 37 37 virtual void getValue(Array<TYPE,3>& value) const { error_get() ; } 38 38 39 39 SETTER_AND_GETTER(int) 40 40 SETTER_AND_GETTER(bool) … … 42 42 SETTER_AND_GETTER(char) 43 43 SETTER_AND_GETTER(string) 44 44 45 45 #undef SETTER_AND_GETTER 46 46 47 48 virtual bool _hasValue() = 0;47 48 virtual bool _hasValue() const = 0; 49 49 50 50 static void error_set(void) … … 53 53 static void error_get(void) 54 54 { throw XMLIOIncompatibleTypeException("BaseAttribut::set<type> >Getting value type is incompatible with attribut type"); } 55 55 56 56 }; //class BaseAttribut 57 57 } // namespace XMLIOSERVER 58 58 59 59 #endif //__BASE_ATTRIBUT__ 60 60 -
XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp
r107 r108 16 16 static void ShowTree(ostream& os = std::clog) 17 17 { 18 clog << "<?xml version=\"1.0\"?>" << std::endl;19 clog << "<simulation>" << std::endl;18 clog << NIndent << "<?xml version=\"1.0\"?>" << std::endl; 19 clog << NIndent << "<"<< Context::GetRootName() << ">" << std::endl; 20 20 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 21 21 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 22 22 // On sort chacun des contextes successivement. 23 clog << *((*it).second)[(*it).first] << std::endl;24 clog << "</simulation>" << std::endl ;23 { Context::SetCurrentContext((*it).first); clog << *((*it).second)[(*it).first] << std::endl; } 24 clog << NIndent << "</" << Context::GetRootName() << ">" << std::endl ; 25 25 } 26 26 … … 36 36 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 37 37 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 38 // Résolution des héritages des descendands (cà d des héritages de groupes) pour chacun des contextes. 38 { 39 // Résolution des héritages descendants (cà d des héritages de groupes) pour chacun des contextes. 40 Context::SetCurrentContext((*it).first); 39 41 ((*it).second)[(*it).first]->resolveDescInheritance(); 42 43 // Résolution des héritages par référence au niveau des fichiers 44 const std::vector<CFile*>& allFiles = CFile::GetCurrentListObject().getVector(); 45 for (unsigned int i = 0; i < allFiles.size(); i++) allFiles[i]->resolveFieldRefInheritance(); 46 } 40 47 } 41 48 … … 113 120 114 121 static string GetName(void) {return ("context"); } 122 static string GetRootName(void) {return ("simulation"); } 115 123 116 124 virtual bool hasChild(void) const -
XMLIO_V2/dev/dev_rv/src/XMLIO/declare_attribut.hpp
r98 r108 8 8 { \ 9 9 public: \ 10 const char * getName(void) const { return #att_name ;}\10 virtual string getName(void) const { return #att_name ;} \ 11 11 virtual const char * getType(void) const { return #att_type ;} \ 12 12 attr_##att_name(void) : Attribut<att_type>() {} \ -
XMLIO_V2/dev/dev_rv/src/XMLIO/field.hpp
r107 r108 17 17 18 18 static string GetName(void) {return ("field"); } 19 20 virtual CField* getReference(void) const 21 { 22 if(!field_ref._hasValue()) return (NULL); 23 string refname = field_ref; 24 if (!CField::HasObject(refname)) 25 { WARNING("Référence invalide sur l'objet "+GetName()+" nommé \""+refname+"\""); return (NULL);} 26 27 return (&CField::GetObject(field_ref)); 28 } 19 29 20 30 void parse (XMLNode& _node) -
XMLIO_V2/dev/dev_rv/src/XMLIO/file.hpp
r107 r108 36 36 } 37 37 38 void getAllFields(std::vector<CField*>& _allF) const { if (vfieldGroup!=NULL) vfieldGroup->getAllChildren(_allF); } 38 39 virtual bool hasChild(void) const { return (vfieldGroup != NULL); } 39 40 virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; } 41 /*{ // Sortie sans affichage des groupes. 42 std::vector<CField*> allF; getAllFields(allF); 43 for (unsigned int i = 0; i < allF.size(); i++) 44 out << *(allF[i]) << std::endl; 45 }*/ 40 46 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 41 47 { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); } 48 49 void resolveFieldRefInheritance(void) 50 { 51 std::vector<CField*> allF; getAllFields(allF); 52 for (unsigned int i = 0; i < allF.size(); i++) allF[i]->resolveRefInheritance(); 53 } 42 54 43 55 FieldGroup* getVirtualFieldGroup(void) { return (vfieldGroup); } -
XMLIO_V2/dev/dev_rv/src/XMLIO/main_cpp.cpp
r107 r108 12 12 { 13 13 string file("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_test.xml"); 14 //string file("/local/XMLIOSERVER_DEV/dev_rv/iodef_test.xml"); 14 15 15 //string file("/local/XMLIOSERVER_DEV/dev_rv/iodef_test.xml");16 16 ifstream istr( file.c_str() , ifstream::in ); 17 17 18 18 // On commence la lecture du flux de donnée xml qui doit posséder pour racine un unique noeud nommé "simulation". 19 XMLNode node = XMLNode::CreateNode(istr, "simulation");19 XMLNode node = XMLNode::CreateNode(istr, Context::GetRootName()); 20 20 // On parse le fichier xml noeud par noeud (ie on construit dynamiquement notre arbre d'objets). 21 21 XMLParser::Parse(node); … … 26 26 // On poursuit le traitement ... 27 27 28 // On écrit l'arborescence r esultante du traitement sur la sortie.28 // On écrit l'arborescence résultante du traitement sur la sortie. 29 29 Context::ShowTree(std::clog); 30 30 -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_group_template.hpp
r107 r108 51 51 groupList.addObject(&obj); 52 52 53 return ( GroupTemplate<T, U>::GetObject(_id));53 return (obj); 54 54 } 55 55 … … 89 89 90 90 const StrHashMap<T*>& getCurrentListChild(void) { return (childList); } 91 const vector<T*>& getCurrentVectorChild(void) { return (childList.getVector()); } 91 92 92 93 size_t getNbChild() const {return (childList.getVectorSize()); } 94 95 void getAllChildren(std::vector<T*>& _allc ) 96 { 97 const vector<GroupTemplate<T, U>*>& groupvect = groupList.getVector(); 98 _allc.insert (_allc.end(), getCurrentVectorChild().begin(), getCurrentVectorChild().end()); 99 100 for(unsigned int i = 0; i < groupvect.size() ; i++) 101 groupvect[i] -> getAllChildren(_allc); 102 } 93 103 94 104 virtual ~GroupTemplate() … … 108 118 {// Si l'identifiant est défini. 109 119 if (V::HasObject(attributes["id"])) 110 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO120 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée \""+attributes["id"]+"\" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 111 121 instance_ptr = (V*)(&createGroup(attributes["id"])); 112 122 instance_ptr->parse(_node); … … 126 136 {// Si l'identifiant est défini. 127 137 if (V::HasObject(attributes["id"])) 128 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO138 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée \""+attributes["id"]+"\" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 129 139 instance_ptr = (V*)(&createChild(attributes["id"])); 130 140 instance_ptr->parse(_node); -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_logger.hpp
r106 r108 1 1 #ifndef __XMLIO_LOGGER__ 2 #define __XMLIO_LOGGER__ 2 #define __XMLIO_LOGGER__ 3 3 4 4 // Entête Poco logging … … 12 12 #include <Poco/AutoPtr.h> 13 13 14 #include <csignal> 15 16 #ifdef __GNUC__ 17 #include <execinfo.h> 18 #include <cxxabi.h> 19 #endif // __GNUC__ 14 20 15 21 // Classes utilisées issues de Poco … … 28 34 { 29 35 public : 30 36 31 37 ILogger(const string& _fileLogName, bool _withConsole = true) 32 38 { 33 39 // Perte mémoire faible ici (/ still reachable: 84 bytes in 2 blocks /) 34 40 35 41 // TODO Créer une sortie fichier. 36 42 AutoPtr<PatternFormatter> pf = new PatternFormatter("[%Y-%m-%d %H:%M:%S] %t"); … … 38 44 AutoPtr<FormattingChannel> pFCConsole = new FormattingChannel(pf); 39 45 pFCConsole->setChannel(cc); 40 pFCConsole->open(); 46 pFCConsole->open(); 41 47 Logger::create("ConsoleLogger", pFCConsole, Message::PRIO_INFORMATION); 48 49 signal(SIGSEGV, SigHandler); 42 50 } 43 51 44 static Logger & GetConsoleLogger(void) {return (Logger::get("ConsoleLogger"));} 45 46 ~ILogger(void) 47 { /* Ne rien faire de plus */ } 48 52 53 static void ShowBTrace(std::ostream& out = std::clog) 54 { 55 #ifdef __GNUC__ 56 int status = 0; 57 string value; 58 void *stack_addrs[20] = {NULL}; 59 size_t stack_depth = backtrace(stack_addrs, 20); 60 char **stack_strings = backtrace_symbols(stack_addrs, stack_depth); 61 62 out << "Trace : " << std::endl; 63 for (size_t i = 2, j = 0; i < stack_depth; i++) 64 { 65 value.assign(stack_strings[i]); 66 size_t bpos = value.find ('('), epos = value.find ('+'); 67 if ((bpos != string::npos) and (epos != string::npos)) 68 { 69 char* demangled_name = abi::__cxa_demangle(value.substr(bpos+1, epos-bpos-1).c_str(), 0, 0, &status); 70 if (status == 0) out << " " << ++j << " -> " << (demangled_name) << std::endl; 71 else out << " " << ++j << " -> " << value.substr(bpos+1, epos-bpos-1) << std::endl; 72 free(demangled_name); 73 } 74 } 75 76 free(stack_strings); 77 #endif // __GNUC__ 78 } 79 80 static void SigHandler(int _sigValue) 81 { 82 std::cerr << "============= Erreur =============" << std::endl; 83 std::cerr << "Signal " << _sigValue << " reçu !" << std::endl; 84 ShowBTrace(std::cerr); 85 std::cerr << "==================================" << std::endl; 86 exit(EXIT_FAILURE); 87 } 88 89 90 static Logger & GetConsoleLogger(void) {return (Logger::get("ConsoleLogger"));} 91 92 ~ILogger(void) 93 { /* Ne rien faire de plus */ } 94 49 95 }; // class XMLIOLogger 50 96 51 97 // Initialisation de la classe de Logging 52 98 static ILogger LOGGER("xmlio.log"); 53 99 54 ///////////////////////////////////////////////////////////////////// 55 static unsigned int Indent; 100 ///////////////////////////////////////////////////////////////////// 101 static unsigned int Indent = 0; 102 static const char* Increm = " "; 56 103 57 std::ostream& NIndent(std::ostream& out) 58 { for(unsigned int i = 0; i < Indent; i++) out << " "; return(out); } 104 std::ostream& NIndent(std::ostream& out) 105 { 106 static unsigned int LineNB = 1; 107 out<< LineNB++ << ". "; 108 for(unsigned int i = 0;i < Indent; i++) out << Increm; 109 return(out); 110 } 59 111 60 std::ostream& IncIndent(std::ostream& out) { Indent++; return (NIndent(out)); }61 std::ostream& DecEndl(std::ostream& out) { Indent--; return (NIndent(out)); }62 /////////////////////////////////////////////////////////////////////112 std::ostream& IncIndent(std::ostream& out) { Indent++; return (NIndent(out)); } 113 std::ostream& DecEndl(std::ostream& out) { Indent--; return (out); } 114 ///////////////////////////////////////////////////////////////////// 63 115 64 /************* POUR MEMOIRE **********************65 #include <stdio.h>66 #include <execinfo.h>67 #include <signal.h>68 #include <stdlib.h>69 70 void handler(int sig) {71 void *array[10];72 size_t size;73 // get void*'s for all entries on the stack74 size = backtrace(array, 10);75 // print out all the frames to stderr76 fprintf(stderr, "Error: signal %d:\n", sig);77 backtrace_symbols_fd(array, size, 2);78 exit(1);79 }80 void baz() {81 int *foo = (int*)-1; // make a bad pointer82 printf("%d\n", *foo); // causes segfault83 }84 void bar() { baz(); }85 void foo() { bar(); }86 87 int main(int argc, char **argv) {88 signal(SIGSEGV, handler); // install our handler89 foo(); // this will call foo, bar, and baz. baz segfaults.90 }91 92 ***************************************************************/93 94 116 }; // namespace XMLIOSERVER 95 117 … … 99 121 // A compléter. 100 122 101 #endif // __XMLIO_LOGGER__ 123 #endif // __XMLIO_LOGGER__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp
r107 r108 22 22 public : 23 23 24 25 24 friend ostream& operator<< (ostream& out, const T& c) 26 25 { 27 26 const AttributRegistrar &ar = c; 27 28 if (c.baseObject != NULL) 29 out << IncIndent << "<-- Reference resolved for the following "+ T::GetName() +" : \"" << c.baseObject->getId() << "\" -->" << DecEndl << std::endl; 30 28 31 if (c.hasChild()) 29 32 { … … 39 42 string getName(void) const {return (T::GetName()); } 40 43 44 virtual T* getReference(void) const { return (NULL); } 45 41 46 virtual bool hasChild(void) const { return (false); } 42 47 virtual void printChild(ostream& out) const { /* Ne rien faire de plus */ } 48 43 49 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) { addAttributes(*_parent); } 50 virtual void resolveRefInheritance(void) 51 { 52 std::vector<T*> allRef; 53 T* refer = (T*)this; 54 // On remonte le fil des héritages par référence (Boucle infinie). 55 while((refer = refer->getReference()) != NULL) 56 allRef.insert(allRef.begin(), baseObject = refer); 57 58 // Gestion des attributs ici. 59 } 44 60 45 61 static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) … … 83 99 protected : 84 100 85 ObjectTemplate(void) : AbstractObject() 101 ObjectTemplate(void) : AbstractObject(), baseObject(NULL) 86 102 {/* Ne rien faire de plus */} 87 ObjectTemplate(const string& _id) : AbstractObject(_id) 103 ObjectTemplate(const string& _id) : AbstractObject(_id), baseObject(NULL) 88 104 {/* Ne rien faire de plus */} 89 105 … … 100 116 { 101 117 if (V::HasObject(did)) 102 WARNING("Le noeud nommé "+ did +" existe déjà pour les instances de type "+V::GetName()+", le dernier défini complétera le premier dans le context actuel!");118 WARNING("Le noeud nommé \""+ did +"\" existe déjà pour les instances de type "+V::GetName()+", le dernier défini complétera le premier dans le context actuel!"); 103 119 instance_ptr = (V*)&V::CreateObject(did); 104 120 instance_ptr->parse(_node, parseAttr); … … 108 124 109 125 private : 126 T* baseObject; 110 127 111 128 static string CurrContext; -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_node.hpp
r107 r108 54 54 { /* Ne rien faire de plus */} 55 55 56 static XMLNode CreateNode(istream& _istr, const string& _rootName = string("simulation"))56 static XMLNode CreateNode(istream& _istr, const string& _rootName) 57 57 { 58 58 XMLNode node(_rootName); -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_parser.hpp
r107 r108 31 31 { WARNING("Le context ne sera pas traité car il n'est pas identifié !"); continue; } 32 32 33 if( Context:: HasObject(attributes["id"]))33 if( Context::GetAllListObject().find(attributes["id"]) != Context::GetAllListObject().end()) 34 34 { WARNING("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); continue; } 35 35
Note: See TracChangeset
for help on using the changeset viewer.