Ignore:
Timestamp:
04/12/11 16:54:20 (13 years ago)
Author:
hozdoba
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/xmlio/group_template_impl.hpp

    r168 r172  
    2525      CGroupTemplate<U, V, W>::~CGroupTemplate(void) 
    2626   { /* Ne rien faire de plus */ } 
     27    
     28   ///-------------------------------------------------------------- 
     29    
     30   template <class U, class V, class W> 
     31      void CGroupTemplate<U, V, W>::toBinary(StdOStream & os) const 
     32   { 
     33      SuperClass::toBinary(os); 
     34       
     35      const StdSize grpnb = this->groupList.size(); 
     36      const StdSize chdnb = this->childList.size(); 
     37      tree::ENodeType cenum = U::GetType(); 
     38      tree::ENodeType genum = V::GetType(); 
     39       
     40      os.write (reinterpret_cast<const char*>(&grpnb) , sizeof(StdSize)); 
     41      os.write (reinterpret_cast<const char*>(&chdnb) , sizeof(StdSize));       
     42       
     43      typename std::vector<boost::shared_ptr<V> >::const_iterator  
     44         itg = this->groupList.begin(), endg = this->groupList.end(); 
     45      typename std::vector<boost::shared_ptr<U> >::const_iterator  
     46         itc = this->childList.begin(), endc = this->childList.end(); 
     47             
     48      for (; itg != endg; itg++) 
     49      {  
     50         boost::shared_ptr<V> group = *itg; 
     51         bool hid = group->hasId(); 
     52          
     53         os.write (reinterpret_cast<const char*>(&genum), sizeof(tree::ENodeType));       
     54         os.write (reinterpret_cast<const char*>(&hid), sizeof(bool)); 
     55          
     56         if (hid) 
     57         { 
     58            const StdString & id = group->getId(); 
     59            const StdSize size   = id.size(); 
     60                
     61            os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); 
     62            os.write (id.data(), size * sizeof(char));          
     63         }               
     64         group->toBinary(os); 
     65      } 
     66             
     67      for (; itc != endc; itc++) 
     68      {  
     69         boost::shared_ptr<U> child = *itc; 
     70         bool hid = child->hasId(); 
     71          
     72         os.write (reinterpret_cast<const char*>(&cenum), sizeof(tree::ENodeType)); 
     73         os.write (reinterpret_cast<const char*>(&hid), sizeof(bool)); 
     74          
     75         if (hid) 
     76         { 
     77            const StdString & id = child->getId(); 
     78            const StdSize size   = id.size(); 
     79                
     80            os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); 
     81            os.write (id.data(), size * sizeof(char));          
     82         }          
     83         child->toBinary(os); 
     84      } 
     85       
     86   } 
     87    
     88   template <class U, class V, class W> 
     89      void CGroupTemplate<U, V, W>::fromBinary(StdIStream & is) 
     90   { 
     91      SuperClass::fromBinary(is); 
     92       
     93      boost::shared_ptr<V> group_ptr = (this->hasId()) 
     94         ? CObjectFactory::GetObject<V>(this->getId()) 
     95         : CObjectFactory::GetObject(boost::polymorphic_downcast<V*>(this)); 
     96       
     97      StdSize grpnb = 0; 
     98      StdSize chdnb = 0; 
     99      tree::ENodeType renum = Unknown; 
     100       
     101      is.read (reinterpret_cast<char*>(&grpnb), sizeof(StdSize)); 
     102      is.read (reinterpret_cast<char*>(&chdnb), sizeof(StdSize)); 
     103       
     104      for (StdSize i = 0; i < grpnb; i++) 
     105      { 
     106         bool hid = false; 
     107         is.read (reinterpret_cast<char*>(&renum), sizeof(tree::ENodeType)); 
     108         is.read (reinterpret_cast<char*>(&hid), sizeof(bool)); 
     109          
     110         if (renum != V::GetType()) 
     111            ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)", 
     112                  << "[ renum = " << renum << "] Bad type !"); 
     113                         
     114         if (hid) 
     115         { 
     116            StdSize size  = 0; 
     117            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); 
     118            StdString id(size, ' '); 
     119            is.read (const_cast<char *>(id.data()), size * sizeof(char)); 
     120            CGroupFactory::CreateGroup(group_ptr, id)->fromBinary(is); 
     121         } 
     122         else 
     123         { 
     124            CGroupFactory::CreateGroup(group_ptr)->fromBinary(is); 
     125         } 
     126      } 
     127       
     128      for (StdSize j = 0; j < chdnb; j++) 
     129      { 
     130         bool hid = false; 
     131         is.read (reinterpret_cast<char*>(&renum), sizeof(tree::ENodeType)); 
     132         is.read (reinterpret_cast<char*>(&hid), sizeof(bool)); 
     133          
     134         if (renum != U::GetType()) 
     135            ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)", 
     136                  << "[ renum = " << renum << "] Bad type !"); 
     137                   
     138         if (hid) 
     139         { 
     140            StdSize size  = 0; 
     141            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); 
     142            StdString id(size, ' '); 
     143            is.read (const_cast<char *>(id.data()), size * sizeof(char)); 
     144            CGroupFactory::CreateChild(group_ptr, id)->fromBinary(is);             
     145         } 
     146         else 
     147         { 
     148            CGroupFactory::CreateChild(group_ptr)->fromBinary(is); 
     149         }    
     150      } 
     151   } 
     152 
     153   //-------------------------------------------------------------- 
    27154 
    28155   template <class U, class V, class W> 
     
    31158      StdOStringStream oss; 
    32159      StdString name = (this->getId().compare(V::GetDefName()) != 0) 
    33                      ? V::GetName() 
    34                      : V::GetDefName(); 
     160                     ? V::GetName() : V::GetDefName(); 
    35161 
    36162      oss << "< " << name << " "; 
     
    75201   } 
    76202 
     203   //--------------------------------------------------------------- 
     204 
    77205   template <class U, class V, class W> 
    78206      StdString CGroupTemplate<U, V, W>::GetName(void) 
     
    86214      return (U::GetName().append("_definition"));  
    87215   } 
     216    
     217   //---------------------------------------------------------------    
    88218 
    89219   template <class U, class V, class W> 
     
    94224   } 
    95225 
     226   //--------------------------------------------------------------- 
     227 
    96228   template <class U, class V, class W> 
    97229      const xios_map<StdString, boost::shared_ptr<V> >& 
     
    101233   } 
    102234 
     235   //--------------------------------------------------------------- 
     236 
    103237   template <class U, class V, class W> 
    104238      bool CGroupTemplate<U, V, W>::hasChild(void) const 
     
    107241   } 
    108242 
     243   //--------------------------------------------------------------- 
     244 
    109245   template <class U, class V, class W> 
    110246      void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node) 
     
    112248      this->parse(node, true);  
    113249   } 
     250    
     251   //--------------------------------------------------------------- 
    114252    
    115253   template <class U, class V, class W> 
     
    138276   } 
    139277 
     278   //--------------------------------------------------------------- 
     279 
    140280   template <class U, class V, class W> 
    141281      void CGroupTemplate<U, V, W>::getAllChildren(std::vector<boost::shared_ptr<U> > & allc) const 
     
    152292   } 
    153293 
     294   //--------------------------------------------------------------- 
     295 
    154296   template <class U, class V, class W> 
    155297      std::vector<boost::shared_ptr<U> > CGroupTemplate<U, V, W>::getAllChildren(void) const 
     
    160302   } 
    161303 
     304   //--------------------------------------------------------------- 
     305 
    162306   template <class U, class V, class W> 
    163307      void CGroupTemplate<U, V, W>::solveRefInheritance(void) 
    164308   { /* Ne rien faire de plus */ } 
    165309 
     310   ///-------------------------------------------------------------- 
     311 
    166312} // namespace xmlioserver 
    167313 
Note: See TracChangeset for help on using the changeset viewer.