Ignore:
Timestamp:
06/17/10 16:44:31 (14 years ago)
Author:
hozdoba
Message:

Commit intermédiaire ...
Remontée de plusieurs fonctionnalités dans l'arbre des héritages.
Amélioration de la lisibilité du code.
etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp

    r104 r107  
    11#ifndef __XMLIO_OBJECT_TEMPLATE__ 
    2 #define __XMLIO_OBJECT_TEMPLATE__  
     2#define __XMLIO_OBJECT_TEMPLATE__ 
     3 
     4#include "declare_attribut.hpp" 
     5#include "attribut_registrar.hpp" 
    36 
    47// Classes utilisées issues de la STL 
     
    811 
    912using XMLIOSERVER::StrHashMap; 
    10     
     13 
     14using XMLIOSERVER::XML::XMLNode; 
     15using XMLIOSERVER::XML::THashAttributes; 
     16 
    1117namespace XMLIOSERVER 
    1218{ 
    1319   template <class T> 
    14       class ObjectTemplate : public AbstractObject 
     20      class ObjectTemplate : public AbstractObject, public virtual AttributRegistrar 
    1521   { 
    1622      public : 
    17           
    18          static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException)  
     23 
     24 
     25         friend ostream& operator<< (ostream& out, const T& c) 
     26         { 
     27            const AttributRegistrar &ar = c; 
     28            if (c.hasChild()) 
     29            { 
     30               out << IncIndent  << "<" << c.getName()   << c.printId() << ar << ">" << std::endl; 
     31               c.printChild(out); // << Ecriture des objets enfants ici. 
     32               out << NIndent    << "</" << c.getName()  << ">" << DecEndl; 
     33            } 
     34            else out << IncIndent << "<" << c.getName()  << c.printId() << ar << "/>" << DecEndl; 
     35 
     36            return (out); 
     37         } 
     38 
     39         string getName(void) const {return (T::GetName()); } 
     40 
     41         virtual bool hasChild(void) const { return (false); } 
     42         virtual void printChild(ostream& out) const { /* Ne rien faire de plus */ } 
     43         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) { addAttributes(*_parent); } 
     44 
     45         static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) 
    1946         { 
    2047            // Si l'identifiant est répertorié, on retourne l'élément existant. 
    2148            if(ObjectTemplate<T>::HasObject(_id)) 
    2249               return (ObjectTemplate<T>::GetObject(_id)); 
    23                                
    24             // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié.            
     50 
     51            // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié. 
    2552            ObjectTemplate<T>::AllListObj[CurrContext].addObject(new T(_id)); 
    26              
     53 
    2754            return (ObjectTemplate<T>::GetObject(_id)); 
    2855         } 
    29           
     56 
    3057         static T& CreateObject(void) 
    3158         { 
     
    3461            return (*value); 
    3562         } 
    36           
     63 
    3764         static T& GetObject(const string _id) throw (XMLIOUndefinedValueException) 
    3865         { return (*ObjectTemplate<T>::AllListObj[CurrContext][_id]); } 
    39           
     66 
    4067         static bool HasObject(const string _id) 
    4168         { 
     
    4370            return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); 
    4471         } 
    45           
     72 
    4673         static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } 
    4774         static HashMap<string, StrHashMap<T> >& GetAllListObject(void) { return (AllListObj); } 
    48                  
    49          static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; }  
    50           
    51          static string& GetCurrentContextId(void) { return (CurrContext); }  
    52           
     75 
     76         static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } 
     77 
     78         static string& GetCurrentContextId(void) { return (CurrContext); } 
     79 
    5380         virtual ~ObjectTemplate(void) 
    5481         {/* Ne rien faire de plus */} 
    55           
     82 
    5683      protected : 
    57        
     84 
    5885         ObjectTemplate(void) : AbstractObject() 
    59          {/* Ne rien faire de plus */}          
    60          ObjectTemplate(const string& _id) : AbstractObject(_id)  
    6186         {/* Ne rien faire de plus */} 
    62           
     87         ObjectTemplate(const string& _id) : AbstractObject(_id) 
     88         {/* Ne rien faire de plus */} 
     89 
     90         XML::XMLNode getNodeIncludedFile(const string& path, const string& _rootName) 
     91         { 
     92            ifstream istr( path.c_str() , ifstream::in ); 
     93            return XML::XMLNode::CreateNode(istr, _rootName); 
     94         } 
     95 
     96         template <class V> static V* CreateInstanceAndParse( THashAttributes& attributes, XMLNode& _node, const char* defaultId, bool parseAttr = true ) 
     97         { 
     98            V* instance_ptr = NULL; string did(defaultId); 
     99            if (defaultId != NULL) 
     100            { 
     101               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!"); 
     103               instance_ptr = (V*)&V::CreateObject(did); 
     104               instance_ptr->parse(_node, parseAttr); 
     105            } 
     106            return (instance_ptr); 
     107         } 
     108 
    63109      private : 
    64           
     110 
    65111         static string CurrContext; 
    66112         static HashMap<string, StrHashMap<T> > AllListObj; 
    67        
     113 
    68114   };// class ObjectTemplate 
    69     
     115 
    70116   template <class T> string ObjectTemplate<T>::CurrContext ; 
    71117   template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj; 
    72     
     118 
    73119}// namespace XMLIOSERVER 
    74     
    75 #endif // __XMLIO_OBJECT_TEMPLATE__  
     120 
     121#endif // __XMLIO_OBJECT_TEMPLATE__ 
Note: See TracChangeset for help on using the changeset viewer.