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

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/xmlio/manager/tree_manager.cpp

    r168 r173  
    2121         boost::shared_ptr<CContextGroup> group_context = CContext::GetContextGroup(); 
    2222         CTreeManager::SetCurrentContextId(id); 
     23         bool hasctxt = CObjectFactory::HasObject<CContext>(id); 
    2324          
    2425         boost::shared_ptr<tree::CContext> context = 
    2526               CObjectFactory::CreateObject<tree::CContext>(id); 
    26          CGroupFactory::AddChild(group_context, context); 
     27         if (!hasctxt) CGroupFactory::AddChild(group_context, context); 
    2728 
    2829#define DECLARE_NODE(Name_, name_) \ 
     
    5960 
    6061      void CTreeManager::ParseFile(const StdString & filename) 
    61       { xml::CXMLParser::ParseFile(filename); } 
     62      {  
     63         xml::CXMLParser::ParseFile(filename);  
     64      } 
    6265 
    6366      void CTreeManager::ParseString(const StdString & xmlContent) 
    64       { xml::CXMLParser::ParseString(xmlContent); } 
     67      {  
     68         xml::CXMLParser::ParseString(xmlContent);  
     69      } 
    6570 
    6671      void CTreeManager::ParseStream(StdIStream & stream) 
    67       { xml::CXMLParser::ParseStream(stream); } 
     72      {  
     73         xml::CXMLParser::ParseStream(stream);  
     74      } 
     75       
     76      //-------------------------------------------------------------- 
     77       
     78      void CTreeManager::ToBinary(StdOStream & os) 
     79      { 
     80         StdString currentContextId = 
     81            CObjectFactory::GetCurrentContextId(); 
     82         std::vector<boost::shared_ptr<CContext> > def_vector = 
     83            CContext::GetContextGroup()->getChildList(); 
     84             
     85         const StdSize size = def_vector.size();          
     86         const ENodeType cenum = CContext::GetType(); 
     87         const ENodeType genum = CContextGroup::GetType(); 
     88          
     89         os.write (reinterpret_cast<const char*>(&genum) , sizeof(ENodeType));  
     90         os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize)); 
     91          
     92         for (StdSize i = 0; i < size; i++) 
     93         { 
     94            boost::shared_ptr<CContext> context = def_vector[i];          
     95            CTreeManager::SetCurrentContextId(context->getId());                 
     96            const bool hid = context->hasId(); // Toujours vrai 
     97             
     98            os.write (reinterpret_cast<const char*>(&cenum), sizeof(ENodeType));       
     99            os.write (reinterpret_cast<const char*>(&hid), sizeof(bool)); 
     100             
     101            if (hid) 
     102            { 
     103               const StdString & id = context->getId(); 
     104               const StdSize size   = id.size(); 
     105                   
     106               os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); 
     107               os.write (id.data(), size * sizeof(char));          
     108            }  
     109             
     110            context->toBinary(os); 
     111         } 
     112         CTreeManager::SetCurrentContextId(currentContextId);           
     113      } 
     114       
     115      void CTreeManager::FromBinary(StdIStream & is) 
     116      { 
     117         StdSize ctxtnb = 0; 
     118         ENodeType renum = Unknown; 
     119          
     120         boost::shared_ptr<CContextGroup> group_context = 
     121                           CContext::GetContextGroup(); 
     122                            
     123         is.read (reinterpret_cast<char*>(&renum), sizeof(StdSize));    
     124         is.read (reinterpret_cast<char*>(&ctxtnb), sizeof(ENodeType)); 
     125 
     126         if (renum != CContextGroup::GetType()) 
     127            ERROR("CTreeManager::FromBinary(StdIStream & is)", 
     128                  << "[ renum = " << renum << "] Bad type !"); 
     129 
     130         for (StdSize i = 0; i < ctxtnb; i++) 
     131         { 
     132            bool hid = false; 
     133            is.read (reinterpret_cast<char*>(&renum), sizeof(tree::ENodeType)); 
     134            is.read (reinterpret_cast<char*>(&hid), sizeof(bool)); 
     135             
     136            if (renum != CContext::GetType()) 
     137               ERROR("CTreeManager::FromBinary(StdIStream & is)", 
     138                     << "[ renum = " << renum << "] Bad type !"); 
     139                            
     140            if (hid) 
     141            { 
     142               StdSize size  = 0; 
     143               is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); 
     144               StdString id(size, ' '); 
     145               is.read (const_cast<char *>(id.data()), size * sizeof(char)); 
     146                
     147               CTreeManager::SetCurrentContextId(id);                
     148               bool hasctxt = CObjectFactory::HasObject<CContext>(id); 
     149                
     150               boost::shared_ptr<CContext> context = 
     151                  CObjectFactory::CreateObject<CContext>(id); 
     152                   
     153               if (!hasctxt) 
     154                  CGroupFactory::AddChild(group_context, context); 
     155               context->fromBinary(is); 
     156            } 
     157         } 
     158      } 
    68159 
    69160      ///------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.