mapcodexmlreader.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by root                                            *
00003  *   root@aquiles                                                          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020  
00021 #ifndef MAPCODEXMLREADER_H
00022 #define MAPCODEXMLREADER_H
00023 
00024 #include "xmlsomreader.h"
00025 #include "Mapcode.h"
00026 
00027 
00028 
00032 class MapcodeXMLReader : public xmlsom::XMLSOMReader {
00033 
00034   public:
00035   
00036     MapcodeXMLReader(std::string filename);
00037     
00038     virtual Mapcode* load() throw(std::exception);
00039     
00040     virtual ~MapcodeXMLReader() {};
00041     
00042   protected:
00043   
00044     virtual void processElement( const std::string& name,
00045                                  const std::string& value,
00046                                  const std::map<std::string,std::string>& attrs ) 
00047       throw(exception);
00048 
00049   private:
00050     
00051     int actualNode;
00052     
00053     int actualWeight;
00054     
00055     Mapcode* map;
00056     
00057     TMatrix     codebook;
00058     
00059     int height;
00060     
00061     int width;
00062     
00063     int depth;
00064     
00065     int dimension;
00066     
00067     int neigh;
00068     
00069     int size;
00070     
00071     std::string topology;    
00072 };
00073 
00074 
00075 
00076 //default constructor
00077 MapcodeXMLReader::MapcodeXMLReader(std::string filename) 
00078      : xmlsom::XMLSOMReader(filename) {  
00079 
00080   height = 1;
00081   width = 1;
00082   depth = 1;
00083   dimension = 1;
00084   neigh = 1;
00085   actualNode = 0;    
00086   actualWeight = 0;
00087 
00088 };
00089 
00090 
00091 
00092 //main method
00093 Mapcode* MapcodeXMLReader::load() throw(std::exception) {
00094   
00095   map = new Mapcode();
00096   
00097   doParse();
00098   
00099   map->setCodebook(codebook);
00100   map->setTopolParamsText(topology);
00101   map->setDimension(dimension);
00102   map->setNeighborType(neigh);
00103   map->setDimensions(0, height);
00104   map->setDimensions(1, width);
00105   map->setDimensions(2, depth);
00106 
00107   return map;
00108 };
00109 
00110 
00111 
00112 void MapcodeXMLReader::processElement( const std::string& name,
00113                                        const std::string& value,
00114                                        const std::map<std::string,std::string>& attrs )
00115   throw(std::exception) {
00116   
00117   if(name == "height")
00118     height = atoi(value.c_str());
00119   
00120   else if(name == "width")
00121     width = atoi(value.c_str());
00122 
00123   else if(name == "depth") {
00124     depth = atoi(value.c_str());
00125     size = height * width * depth;
00126     
00127   } else if(name == "dimension")
00128     dimension = atoi(value.c_str());
00129 
00130   else if(name == "neighbourhood")
00131     neigh = atoi(value.c_str());
00132 
00133   else if(name == "topology")
00134     topology = value;
00135 
00136   else if(name == "mapcode")
00137     codebook = create_matrix( 1, size, 1, dimension );  
00138   
00139   else if(name == "node") {
00140     ++actualNode;
00141     actualWeight = 0;
00142     
00143   } else if(name == "weight")
00144     codebook[actualNode][actualWeight] = atof(value.c_str());
00145 };
00146 
00147 
00148 
00149 #endif

Generated on Tue Aug 7 16:03:33 2007 for SOMCode by  doxygen 1.5.3