source: XMLIO_V2/dev/dev_rv/xmlio_xml_parser.hpp @ 96

Last change on this file since 96 was 96, checked in by hozdoba, 14 years ago

Suppression de nombreuses fuites mémoires (200kbytes)

File size: 3.1 KB
Line 
1#ifndef __XMLIO_XML_PARSER__
2#define __XMLIO_XML_PARSER__
3
4// Utilisation de la STL
5using std::string;
6
7namespace XMLIOSERVER
8{
9   namespace XML
10   {         
11      using XMLIOSERVER::Context;
12     
13      class XMLParser
14      {
15         public : 
16         
17            static void Parse(XMLNode& _node)
18            {
19               THashAttributes attributes;
20                             
21               do {               
22                 // Traitement de l'identifiant
23                  _node.getAttributes(attributes);
24                           
25                  if (attributes.end() == attributes.find("id"))
26                  { WARNING("Le context ne sera pas traité car il n'est pas identifié !"); continue; }
27                 
28                  if( Context::HasObject(attributes["id"]))
29                  { WARNING("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); continue; }
30                 
31                  Context::SetCurrentContext(attributes["id"]);
32                  Context& context = Context::CreateObject(attributes["id"]);
33                 
34                  context.parse(_node);
35                  attributes.clear();
36                 
37               } while (_node.goToNextElement());               
38            } 
39           
40            static void FreeMemory(void)
41            {
42               HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject();
43               
44               for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++)
45               {
46                  string& id = (*it).first;
47                  StrHashMap<Context>& sc = (*it).second;
48                  // BUG AllListContext contient une StrHashMap<Context> liée à l'identifiant "" d'où la vérification ci-dessous.
49                  if (id.size()>0) delete sc[id];
50               }
51            }
52           
53            static bool CLASS_TEST(const string& file = string("/local/testsuite/iodef_test.xml"), ostream& log = std::clog)
54            {
55               ifstream istr( file.c_str() , ifstream::in );
56               XMLNode node("simulation");
57               XMLNode::CreateNode(node, istr);
58               XMLParser::Parse(node);
59               log << "Nombre de Contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 1 attendus."<< std::endl;
60               log << "Nombre de FieldGroups listés : " << FieldGroup::GetCurrentListObject().getSize() << " contre 5 attendus."<< std::endl;
61               log << "Description du champs votkeavt : " << Field::GetObject("votkeavt").description << " contre \"Vertical Eddy Diffusivity\" attendus."<< std::endl;
62               
63               log << "Test  XMLParser ... ok !" << std::endl;
64               
65               FreeMemory(); // Pour supprimer la mémoire liée à l'allocation dynamique.
66               
67               return (true);
68            }
69                 
70      }; // class XMLParser     
71   }; // namespace XML
72
73};// namespace XMLIOSERVER
74
75
76#endif // __XMLIO_XML_PARSER__
Note: See TracBrowser for help on using the repository browser.