Back to index

nordugrid-arc-nox  1.1.0~rc6
simpletype.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include <arc/XMLNode.h>
00009 #include <arc/StringConv.h>
00010 
00011 #include "schemaconv.h"
00012 
00013 using namespace Arc;
00014 
00015 // -------- Simple type ------------
00016 
00017 // 1 - class/parent name (C++,XML)
00018 static const char* simple_type_pattern_h = "\
00019 class %1$s: public Arc::XMLNode {\n\
00020  public:\n\
00021   static %1$s New(Arc::XMLNode parent);\n\
00022   %1$s(Arc::XMLNode node);\n\
00023 };\n\
00024 \n\
00025 ";
00026 
00027 // 1 - class/parent name (C++,XML)
00028 // 2 - class namespace (XML)
00029 static const char* simple_type_pattern_cpp = "\
00030 %1$s %1$s::New(Arc::XMLNode parent) {\n\
00031   Arc::NS ns;\n\
00032   ns[\"ns\"]=\"%2$s\";\n\
00033   %1$s el(parent.NewChild(\"ns:%1$s\",ns));\n\
00034   return el;\n\
00035 }\n\
00036 \n\
00037 %1$s::%1$s(Arc::XMLNode node):Arc::XMLNode(node){\n\
00038   Arc::NS ns;\n\
00039   ns[\"ns\"]=\"%2$s\";\n\
00040   Namespaces(ns);\n\
00041 }\n\
00042 \n\
00043 ";
00044 
00045 void simpletypeprintnamed(const std::string& cppspace,const std::string& ntype,XMLNode stype,const std::string& ns,std::ostream& h_file,std::ostream& cpp_file) {
00046   strprintf(h_file,simple_type_pattern_h,ntype);
00047   strprintf(cpp_file,simple_type_pattern_cpp,ntype,ns);
00048 }
00049 
00050 void simpletypeprint(XMLNode stype,const std::string& ns,std::ostream& h_file,std::ostream& cpp_file) {
00051   std::string ntype;
00052   if(stype.Name() == "simpleType") {
00053     ntype = (std::string)(stype.Attribute("name"));
00054     h_file<<"//simple type: "<<ntype<<std::endl;
00055   } else if(stype.Name() == "complexType") {
00056     XMLNode extension = stype["xsd:simpleContent"]["xsd:extension"];
00057     if(!extension) return;
00058     ntype = (std::string)(stype.Attribute("name"));
00059     h_file<<"//complex type: "<<ntype<<" (simple content)"<<std::endl;
00060   } else {
00061     return;
00062   }
00063   simpletypeprintnamed("",ntype,stype,ns,h_file,cpp_file);
00064 }
00065