Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ImageProcessorsDescription.cpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00019 #include<ImLib3D/ImageProcessorsDescription.hpp>
00020 
00022 void 
00023 ImageProcessorsDescription::CreateTree()
00024 {
00025     // get all nodes
00026     vector<string> names;
00027     vector<string> parents;
00028     for(uint i=0;i<imageProcessors.size();i++)
00029     {
00030         if(imageProcessors[i].parent=="NONE"){continue;}
00031         names.push_back(imageProcessors[i].name);
00032         parents.push_back(imageProcessors[i].parent);
00033     }
00034     for(uint i=0;i<imageProcessorNodes.size();i++)
00035     {
00036         if(imageProcessorNodes[i].parent=="NONE"){continue;}
00037         names.push_back(imageProcessorNodes[i].name);
00038         parents.push_back(imageProcessorNodes[i].parent);
00039     }
00040 
00041     // insert them into tree
00042     uint lastSize=names.size();
00043     while(names.size())
00044     {
00045         for(uint i=0;i<names.size();i++)
00046         {
00047             ImProcNode *parentNode=imProcTree.FindNode(parents[i]);
00048             ImProcNode *childNode=imProcTree.FindNode(names[i]);
00049             if(parentNode)
00050             {
00051                 if(!childNode){parentNode->subnodes.push_back(new ImProcNode(names[i]));}
00052                 names.erase(names.begin()+i);
00053                 parents.erase(parents.begin()+i);
00054                 break;
00055             }
00056         }
00057         if(lastSize==names.size()){ThrowError("ImageProcessorsDescription::CreateTree failed");}
00058         lastSize=names.size();
00059     }
00060     imProcTree.SetParents();
00061 }
00062 
00063 
00064 template<class T>
00065 void
00066 Concatenate(vector<T> &a,const vector<T> &b)
00067 {
00068     a.insert(a.begin(),b.begin(),b.end());
00069 }
00070 
00071 void 
00072 ImageProcessorsDescription::Merge(XIPD::ImageProcessorsDescription &other)
00073 {
00074     Concatenate(imageProcessorNodes,other.imageProcessorNodes);
00075     Concatenate(imageProcessors    ,other.imageProcessors    );
00076     Concatenate(templateGroups     ,other.templateGroups     );
00077     Concatenate(argumentTypes      ,other.argumentTypes      );
00078 
00079 //      xmlpp::Element *dup=DuplicateXMLNode(other.root());
00080 
00081 //      // merge image processors and nodes (just add new ones)
00082 //      xmlpp::Element::NodeList nodeList=dup->get_children();
00083 //      for(xmlpp::Element::NodeList::iterator p=nodeList.begin();p!=nodeList.end();++p)
00084 //      {
00085 //          string name=(*p)->get_name();
00086 //          if(name=="ImageProcessorNode" || name=="ImageProcessor")
00087 //          {
00088 //  //          printf("merging1:\"%s\"\n",name.c_str());
00089 //              tree.root()->add_child(*p);
00090 //          }
00091 //      }
00092 
00093 //      // really merge other nodes 
00094 //      nodeList=dup->get_children();
00095 //      for(xmlpp::Element::NodeList::iterator p=nodeList.begin();p!=nodeList.end();++p)
00096 //      {
00097 //          string name=(*p)->get_name();
00098 //  //      printf("merging2:\"%s\"\n",name.c_str());
00099 //          if(name=="ImageProcessorNode" || name=="ImageProcessor"){continue;}
00100 //          // check if orig tree has top nodes with this name
00101 //          xmlpp::Element::NodeList nlist=tree.root()->get_children(name);
00102 
00103 //          if(nlist.size()==0){tree.root()->add_child(*p);}
00104 //          else
00105 //          if(nlist.size()>1)
00106 //          {ThrowError("ImageProcessorsDescription::merge: two toplevel nodes with same name:\"%s\"",name);}
00107 //          else
00108 //          {
00109 //              printf("merging subnodes for:%s\n",name.c_str());
00110 //              xmlpp::Element::NodeList nodeList=(*p)->get_children();
00111 //              for(xmlpp::Element::NodeList::iterator p1=nodeList.begin();p1!=nodeList.end();++p1)
00112 //              {
00113 //                  (*(nlist.begin()))->add_child(*p1);
00114 //              }           
00115 //          }
00116 //      }
00117 
00118 }
00119 //  vector<xmlpp::Element *> 
00120 //  ImageProcessorsDescription::Args(xmlpp::Element *node,const string &type)
00121 //  {
00122 //      vector<xmlpp::Element *> res;
00123 //      xmlpp::Element::NodeList nodeList=node->get_children();
00124 //      for(xmlpp::Element::NodeList::iterator p=nodeList.begin();p!=nodeList.end();++p)
00125 //      {
00126 //              if(type=="cmdline" && 
00127 //                 ( (*p)->get_name()=="arg" ||
00128 //                   (*p)->get_name()=="cmdlinearg" ||
00129 //                   (*p)->get_name()=="optarg" )){res.push_back(*p);}
00130 //              if(type=="cpp" && 
00131 //                 ( (*p)->get_name()=="arg" ||
00132 //                   (*p)->get_name()=="cpparg" ||
00133 //                   (*p)->get_name()=="optarg" )){res.push_back(*p);}
00134 //      }
00135 //      return res;
00136 //  }
00137 //  void 
00138 //  ImageProcessorsDescription::PrintDoxyDoc(const string& name,const string& type)
00139 //  {
00140 //      if(type=="class head")
00141 //      {
00142 //          xmlpp::Element *node=Get(name);
00143 //          if(!node){printf("Unkown image processor \"%s\"\n",name.c_str());return;}
00144 //  //              printf("%s (%s)\n",node->get_attribute("name")->get_value().c_str(),node->get_attribute("parent")->get_value().c_str());
00145 //          Print(GetContent(name,"ShortDescription"),4,80);
00146 //          Print(GetContent(name,"LongDescription"),8,76);         
00147 //          vector<xmlpp::Element *> args=Args(node,"cpp");
00148 //          vector<string> argnames;
00149 //          for(uint i=0;i<args.size();i++){argnames.push_back(args[i]->get_attribute("name")->get_value().c_str());}
00150 //          Pad(argnames);
00151 //          printf("     <UL>Args:\n");
00152 //          for(uint i=0;i<args.size();i++)
00153 //          {
00154 //              printf("      <LI>%s  type:%s\n",
00155 //                     argnames[i].c_str(),
00156 //                     args[i]->get_attribute("type")->get_value().c_str() );
00157                 
00158 //          }
00159 //          printf("     </UL>\n");
00160 //      }
00161 //  }
00163 //  void 
00164 //  ImageProcessorsDescription::PrintHelp(const string &name)
00165 //  {
00166 //      xmlpp::Element *node=Get(name);
00167 //      if(!node){printf("unkown image processor:%s\n",name.c_str());return;}
00168 //      printf("%s (%s)\n",node->get_attribute("name")->get_value().c_str(),node->get_attribute("parent")->get_value().c_str());
00169 //      Print(GetContent(name,"ShortDescription"),4,80);
00170 //      Print(GetContent(name,"LongDescription"),8,76);
00171 //  //          printf("%s\n\n",GetContent(name,"ShortDescription").c_str());
00172 //  //          printf("%s\n",GetContent(name,"LongDescription").c_str());
00173 //      vector<xmlpp::Element *> args=Args(node,"cmdline");
00174 //      vector<string> argnames;
00175 //      for(uint i=0;i<args.size();i++)
00176 //      {
00177 //          string name=args[i]->get_attribute("name")->get_value().c_str();
00178 //          if(args[i]->get_name()=="optarg"){name="[opt] "+name;}
00179 //          argnames.push_back(name);
00180 //      }
00181 //      Pad(argnames);
00182 //      printf("    Args:\n");
00183 //      for(uint i=0;i<args.size();i++)
00184 //      {
00185 //          printf("      %s  type:%s\n",
00186 //                 argnames[i].c_str(),
00187 //                 args[i]->get_attribute("type")->get_value().c_str() );
00188                    
00189 //      }
00190 //  }

Generated on Fri Jun 17 13:36:04 2005 for ImLib3D by  doxygen 1.4.2