Changeset 173
- Timestamp:
- 04/13/11 15:15:12 (14 years ago)
- Location:
- XMLIO_V2/dev/dev_rv/src/xmlio
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/xmlio/array_impl.hpp
r171 r173 1 1 #ifndef __XMLIO_CArray_impl__ 2 2 #define __XMLIO_CArray_impl__ 3 4 #include "array_mac.hpp" 3 5 4 6 namespace xmlioserver … … 41 43 42 44 template <typename ValueType, StdSize NumDims, typename Allocator> 43 StdOStream & operator << (StdOStream & os, 44 const boost::shared_ptr<CArray<ValueType, NumDims, Allocator> > & array) 45 { os << *array; return (os); } 45 StdOStream & operator << 46 (StdOStream & os, const boost::shared_ptr<CArray<ValueType, NumDims, Allocator> > & array) 47 { 48 os << *array; 49 return (os); 50 } 51 52 //---------------------------------------------------------------- 53 54 template <typename ValueType> void FromBinary 55 (StdIStream & is, ARRAY(ValueType, 1) & array) 56 { 57 ARRAY_ASSIGN(array, ValueType, 1, [1]); 58 array->fromBinary(is); 59 } 60 61 template <typename ValueType> void FromBinary 62 (StdIStream & is, ARRAY(ValueType, 2) & array) 63 { 64 ARRAY_ASSIGN(array, ValueType, 2, [1][1]); 65 array->fromBinary(is); 66 } 46 67 68 template <typename ValueType> void FromBinary 69 (StdIStream & is, ARRAY(ValueType, 3) & array) 70 { 71 ARRAY_ASSIGN(array, ValueType, 3, [1][1][1]); 72 array->fromBinary(is); 73 } 47 74 //---------------------------------------------------------------- 48 75 -
XMLIO_V2/dev/dev_rv/src/xmlio/attribute_map.cpp
r171 r173 161 161 if (!this->hasAttribute(key)) 162 162 ERROR("CAttributeMap::fromBinary(StdIStream & is)", 163 << "[ key = " << key << "] key not found !"); 164 163 << "[ key = " << key << "] key not found !"); 164 165 165 is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool)); 166 166 -
XMLIO_V2/dev/dev_rv/src/xmlio/attribute_template.hpp
r152 r173 53 53 54 54 virtual void toBinary (StdOStream & os) const; 55 virtual void fromBinary(StdIStream & is); 55 virtual void fromBinary(StdIStream & is); 56 56 57 57 protected : … … 60 60 CAttributeTemplate(void); // Not implemented. 61 61 62 }; // class CAttribute 63 62 }; // class CAttribute 63 64 64 } // namespace tree 65 66 template <class T> void FromBinary(StdIStream & is, T & obj); 67 65 68 } // namespace xmlioserver 66 69 -
XMLIO_V2/dev/dev_rv/src/xmlio/attribute_template_impl.hpp
r152 r173 1 1 #ifndef __XMLIO_CAttributeTemplate_impl__ 2 2 #define __XMLIO_CAttributeTemplate_impl__ 3 4 #include "array.hpp" 3 5 4 6 namespace xmlioserver … … 102 104 void CAttributeTemplate<T>::fromBinary(StdIStream & is) 103 105 { 104 this->getValue()->fromBinary(is); 106 T value; 107 FromBinary(is, value); 108 this->setValue(value); 105 109 } 106 110 -
XMLIO_V2/dev/dev_rv/src/xmlio/group_template_impl.hpp
r172 r173 160 160 ? V::GetName() : V::GetDefName(); 161 161 162 oss << "< 162 oss << "<" << name << " "; 163 163 if (this->hasId() && (this->getId().compare(V::GetDefName()) != 0)) 164 164 oss << " id=\"" << this->getId() << "\" "; … … 185 185 } 186 186 187 oss << "</ 187 oss << "</" << name << " >"; 188 188 } 189 189 else -
XMLIO_V2/dev/dev_rv/src/xmlio/indent.cpp
r152 r173 10 10 unsigned int CIndent::Indent = 0; 11 11 StdString CIndent::Increm = StdString(" "); 12 bool CIndent::WithLine = true;12 bool CIndent::WithLine = false; 13 13 14 14 StdOStream & CIndent::NIndent(StdOStream& out) … … 42 42 line.find(xml::CXMLNode::GetRootName()) != StdString::npos) 43 43 retvalue << CIndent::NIndent << line << std::endl; 44 else if (line.find("</ 44 else if (line.find("</") != StdString::npos) 45 45 retvalue << CIndent::NIndent << line << CIndent::DecEndl << std::endl; 46 46 else if (line.find(" />") != StdString::npos) -
XMLIO_V2/dev/dev_rv/src/xmlio/main_server.cpp
r171 r173 13 13 { 14 14 comm::CMPIManager::Initialise(&argc, &argv); // < seulement en mode connecté 15 16 //CTreeManager::ParseFile ("test/iodef_simple_test.xml"); 17 18 /*StdOFStream ofs("data/data.bin"); 19 CTreeManager::ToBinary(ofs); 20 ofs.close();*/ 15 21 16 // Création d'un contexte 17 boost::shared_ptr<CContext> contxt = CTreeManager::CreateContext("mon_context"); 22 StdIFStream ifs("data/data.bin"); 23 CTreeManager::FromBinary(ifs); 24 ifs.close(); 18 25 19 20 boost::shared_ptr<CGridGroup> grid_def = 21 CObjectFactory::GetObject<CGridGroup>(StdString("grid_definition")); 22 boost::shared_ptr<CAxisGroup> axis_def = 23 CObjectFactory::GetObject<CAxisGroup>(StdString("axis_definition")); 24 boost::shared_ptr<CDomainGroup> domain_def = 25 CObjectFactory::GetObject<CDomainGroup>(StdString("domain_definition")); 26 27 // Ajout d'une grille, d'un axe et d'un domaine. 28 boost::shared_ptr<CGrid> grid = 29 CGroupFactory::CreateChild(grid_def , StdString("ma_grille")); 30 boost::shared_ptr<CAxis> axis = 31 CGroupFactory::CreateChild(axis_def , StdString("mon_axe")); 32 boost::shared_ptr<CDomain> domain = 33 CGroupFactory::CreateChild(domain_def, StdString("mon_domaine")); 34 35 boost::shared_ptr<CDomain> sdomain = 36 CGroupFactory::CreateChild(domain_def, StdString("mon_super_domaine")); 37 38 // Définition des attributs de la grille. 39 grid->domain_ref.setValue(StdString("mon_domaine")); 40 grid->axis_ref.setValue(StdString("mon_axe")); 41 42 // Définition des attributs de l'axe. 43 ARRAY_CREATE(zvalue, double, 1, [10]); 44 45 axis->size.setValue(zvalue->num_elements()); 46 axis->zvalue.setValue(zvalue); 47 48 // Définition des attributs du domaine l'axe. 49 ARRAY_CREATE(latvalue, double, 1, [200]); 50 ARRAY_CREATE(lonvalue, double, 1, [200]); 51 52 ARRAY_CREATE(mask, bool, 2, [20][10]); 53 54 for (StdSize i = 0; i<mask->num_elements(); i++) 55 (mask->data())[i] = i%2; 56 57 domain->ni_glo.setValue(40); 58 domain->nj_glo.setValue(40); 59 60 domain->ibegin.setValue(1); 61 domain->ni.setValue(20); 62 domain->jbegin.setValue(1); 63 domain->nj.setValue(10); 64 65 domain->data_dim.setValue(2); 66 67 domain->mask.setValue(mask); 68 domain->lonvalue.setValue(lonvalue); 69 domain->latvalue.setValue(latvalue); 70 71 // Résolution 72 grid->solveReference(); 73 74 std::cout << grid->storeIndex << std::endl; 75 std::cout << grid->out_i_index << std::endl; 76 std::cout << grid->out_j_index << std::endl; 77 std::cout << grid->out_l_index << std::endl; 26 StdIFStream ifss("data/data.bin"); 27 CTreeManager::FromBinary(ifss); 28 ifss.close(); 78 29 79 30 // Sortie de l'arborescence xml sous forme de fichier. 80 31 CTreeManager::PrintTreeToFile("data/def/test.xml"); 81 82 83 ARRAY_CREATE(sarray, double, 1, [1]);84 StdIFStream ifs("data/monfichierbinaire");85 sarray->fromBinary(ifs);86 ifs.close();87 88 89 90 91 92 93 94 95 32 96 33 -
XMLIO_V2/dev/dev_rv/src/xmlio/manager/tree_manager.cpp
r168 r173 21 21 boost::shared_ptr<CContextGroup> group_context = CContext::GetContextGroup(); 22 22 CTreeManager::SetCurrentContextId(id); 23 bool hasctxt = CObjectFactory::HasObject<CContext>(id); 23 24 24 25 boost::shared_ptr<tree::CContext> context = 25 26 CObjectFactory::CreateObject<tree::CContext>(id); 26 CGroupFactory::AddChild(group_context, context);27 if (!hasctxt) CGroupFactory::AddChild(group_context, context); 27 28 28 29 #define DECLARE_NODE(Name_, name_) \ … … 59 60 60 61 void CTreeManager::ParseFile(const StdString & filename) 61 { xml::CXMLParser::ParseFile(filename); } 62 { 63 xml::CXMLParser::ParseFile(filename); 64 } 62 65 63 66 void CTreeManager::ParseString(const StdString & xmlContent) 64 { xml::CXMLParser::ParseString(xmlContent); } 67 { 68 xml::CXMLParser::ParseString(xmlContent); 69 } 65 70 66 71 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 } 68 159 69 160 ///------------------------------------------------------------- -
XMLIO_V2/dev/dev_rv/src/xmlio/manager/tree_manager.hpp
r157 r173 33 33 static void ParseString(const StdString & xmlContent); 34 34 static void ParseStream(StdIStream & stream); 35 36 /// Binaire /// 37 static void ToBinary (StdOStream & os); 38 static void FromBinary(StdIStream & is); 35 39 36 40 }; // class CTreeManager -
XMLIO_V2/dev/dev_rv/src/xmlio/node/context.cpp
r168 r173 1 1 #include "context.hpp" 2 3 #include "tree_manager.hpp" 2 4 3 5 #include "attribute_template_impl.hpp" … … 64 66 << " ce dernier ne sera pas pris en compte lors du traitement !"); } 65 67 66 67 68 68 #define DECLARE_NODE(Name_, name_) \ 69 if (name.compare(C##Name_##Definition::GetDefName()) == 0) \ 70 { CObjectFactory::CreateObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) -> parse(node); \ 69 71 continue; } 70 71 72 #define DECLARE_NODE_PAR(Name_, name_) 73 #include "node_type.conf" 72 74 73 75 DEBUG(<< "L'élément nommé \'" << name … … 93 95 94 96 out << "<? xml version=\"1.0\" ?>" << std::endl; 95 out << "< 97 out << "<" << xml::CXMLNode::GetRootName() << " >" << std::endl; 96 98 97 99 for (; it != end; it++) 98 100 { 99 boost::shared_ptr<CContext> context = *it; 100 CObjectFactory::SetCurrentContextId(context->getId()); 101 CGroupFactory::SetCurrentContextId(context->getId()); 101 boost::shared_ptr<CContext> context = *it; 102 CTreeManager::SetCurrentContextId(context->getId()); 102 103 out << *context << std::endl; 103 104 } 104 105 105 out << "</ " << xml::CXMLNode::GetRootName() << " >" << std::endl; 106 107 CObjectFactory::SetCurrentContextId(currentContextId); 108 CGroupFactory::SetCurrentContextId(currentContextId); 109 } 110 106 out << "</" << xml::CXMLNode::GetRootName() << " >" << std::endl; 107 CTreeManager::SetCurrentContextId(currentContextId); 108 } 109 110 //---------------------------------------------------------------- 111 112 void CContext::toBinary(StdOStream & os) const 113 { 114 SuperClass::toBinary(os); 115 116 #define DECLARE_NODE(Name_, name_) \ 117 { \ 118 ENodeType renum = C##Name_##Definition::GetType(); \ 119 bool val = CObjectFactory::HasObject<C##Name_##Definition> \ 120 (C##Name_##Definition::GetDefName()); \ 121 os.write (reinterpret_cast<const char*>(&renum), sizeof(ENodeType)); \ 122 os.write (reinterpret_cast<const char*>(&val), sizeof(bool)); \ 123 if (val) CObjectFactory::GetObject<C##Name_##Definition> \ 124 (C##Name_##Definition::GetDefName())->toBinary(os); \ 125 } 126 #define DECLARE_NODE_PAR(Name_, name_) 127 #include "node_type.conf" 128 } 129 130 //---------------------------------------------------------------- 131 132 void CContext::fromBinary(StdIStream & is) 133 { 134 SuperClass::fromBinary(is); 135 #define DECLARE_NODE(Name_, name_) \ 136 { \ 137 bool val = false; \ 138 ENodeType renum = Unknown; \ 139 is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType)); \ 140 is.read (reinterpret_cast<char*>(&val), sizeof(bool)); \ 141 if (renum != C##Name_##Definition::GetType()) \ 142 ERROR("CContext::fromBinary(StdIStream & is)", \ 143 << "[ renum = " << renum << "] Bad type !"); \ 144 if (val) CObjectFactory::CreateObject<C##Name_##Definition> \ 145 (C##Name_##Definition::GetDefName()) -> fromBinary(is); \ 146 } 147 #define DECLARE_NODE_PAR(Name_, name_) 148 #include "node_type.conf" 149 150 } 151 152 111 153 //---------------------------------------------------------------- 112 154 … … 114 156 { 115 157 StdOStringStream oss; 116 oss << "< 158 oss << "<" << CContext::GetName() 117 159 << " id=\"" << this->getId() << "\" " 118 160 << SuperClassAttribute::toString() << ">" << std::endl; … … 124 166 { 125 167 126 127 168 #define DECLARE_NODE(Name_, name_) \ 169 if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ 128 170 oss << *CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) << std::endl; 129 130 131 132 } 133 134 oss << "</ 171 #define DECLARE_NODE_PAR(Name_, name_) 172 #include "node_type.conf" 173 174 } 175 176 oss << "</" << CContext::GetName() << " >"; 135 177 136 178 return (oss.str()); … … 141 183 void CContext::solveDescInheritance(const CAttributeMap * const UNUSED(parent)) 142 184 { 143 144 185 #define DECLARE_NODE(Name_, name_) \ 186 if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ 145 187 CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())->solveDescInheritance(); 146 147 188 #define DECLARE_NODE_PAR(Name_, name_) 189 #include "node_type.conf" 148 190 } 149 191 … … 152 194 bool CContext::hasChild(void) const 153 195 { 154 return ( false ||155 156 157 158 196 return ( 197 #define DECLARE_NODE(Name_, name_) \ 198 CObjectFactory::HasObject<C##Name_##Definition> (C##Name_##Definition::GetDefName()) || 199 #define DECLARE_NODE_PAR(Name_, name_) 200 #include "node_type.conf" 159 201 false); 160 202 } 161 203 162 204 //---------------------------------------------------------------- -
XMLIO_V2/dev/dev_rv/src/xmlio/node/context.hpp
r168 r173 20 20 // Declare/Define CFileAttribute 21 21 BEGIN_DECLARE_ATTRIBUTE_MAP(CContext) 22 #include "context_attribute.conf"22 # include "context_attribute.conf" 23 23 END_DECLARE_ATTRIBUTE_MAP(CContext) 24 24 … … 73 73 74 74 virtual StdString toString(void) const; 75 virtual void toBinary (StdOStream & os) const; 76 virtual void fromBinary(StdIStream & is); 75 77 76 78 }; // class CContext -
XMLIO_V2/dev/dev_rv/src/xmlio/node/domain.hpp
r168 r173 22 22 // Declare/Define CDomainAttribute 23 23 BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain) 24 #include "domain_attribute.conf"24 # include "domain_attribute.conf" 25 25 END_DECLARE_ATTRIBUTE_MAP(CDomain) 26 26 -
XMLIO_V2/dev/dev_rv/src/xmlio/node/field.hpp
r168 r173 27 27 // Declare/Define CFieldAttribute 28 28 BEGIN_DECLARE_ATTRIBUTE_MAP(CField) 29 #include "field_attribute.conf"29 # include "field_attribute.conf" 30 30 END_DECLARE_ATTRIBUTE_MAP(CField) 31 31 -
XMLIO_V2/dev/dev_rv/src/xmlio/node/file.cpp
r168 r173 138 138 StdOStringStream oss; 139 139 140 oss << "< 140 oss << "<" << CFile::GetName() << " "; 141 141 if (this->hasId()) 142 142 oss << " id=\"" << this->getId() << "\" "; … … 144 144 if (this->getVirtualFieldGroup().get() != NULL) 145 145 oss << *this->getVirtualFieldGroup() << std::endl; 146 oss << "</ 146 oss << "</" << CFile::GetName() << " >"; 147 147 return (oss.str()); 148 148 } -
XMLIO_V2/dev/dev_rv/src/xmlio/node/file.hpp
r168 r173 22 22 // Declare/Define CFileAttribute 23 23 BEGIN_DECLARE_ATTRIBUTE_MAP(CFile) 24 #include "file_attribute.conf"24 # include "file_attribute.conf" 25 25 END_DECLARE_ATTRIBUTE_MAP(CFile) 26 26 -
XMLIO_V2/dev/dev_rv/src/xmlio/node/grid.hpp
r169 r173 23 23 // Declare/Define CGridAttribute 24 24 BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid) 25 #include "grid_attribute.conf"25 # include "grid_attribute.conf" 26 26 END_DECLARE_ATTRIBUTE_MAP(CGrid) 27 27 -
XMLIO_V2/dev/dev_rv/src/xmlio/object_factory_impl.hpp
r152 r173 85 85 } 86 86 else if (CObjectFactory::HasObject<U>(id)) 87 { 87 88 return (CObjectFactory::GetObject<U>(id)); 89 } 88 90 else 89 91 { -
XMLIO_V2/dev/dev_rv/src/xmlio/object_template_impl.hpp
r172 r173 56 56 { 57 57 StdOStringStream oss; 58 oss << "< 58 oss << "<" << T::GetName(); 59 59 if (this->hasId()) 60 60 oss << " id=\"" << this->getId() << "\""; -
XMLIO_V2/dev/dev_rv/src/xmlio/xml_parser.cpp
r152 r173 53 53 54 54 if (attributes.end() == attributes.find("id")) 55 { DEBUG("Le context ne sera pas traité car il n'est pas identifié !"); 56 continue; } 55 { 56 DEBUG("Le context ne sera pas traité car il n'est pas identifié !"); 57 continue; 58 } 57 59 58 60 CObjectFactory::SetCurrentContextId(attributes["id"]); 59 61 CGroupFactory::SetCurrentContextId(attributes["id"]); 60 62 61 if(CObjectFactory::HasObject<tree::CContext>(attributes["id"])) 62 { DEBUG("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); 63 continue; } 63 bool hasctxt = CObjectFactory::HasObject<tree::CContext>(attributes["id"]); 64 65 if(hasctxt) 66 { 67 DEBUG("Le context ne sera pas traité car " 68 << "il existe déjà un autre context possédant le même nom !"); 69 continue; 70 } 64 71 65 72 boost::shared_ptr<tree::CContext> context = 66 73 CObjectFactory::CreateObject<tree::CContext>(attributes["id"]); 67 CGroupFactory::AddChild(group_context, context);74 if (!hasctxt) CGroupFactory::AddChild(group_context, context); 68 75 context->parse(node); 69 76
Note: See TracChangeset
for help on using the changeset viewer.