RepositoryMapcodeXML.h

00001 // RepositoryMapcodeXML.h: interface for the RepositoryMapcodeXML class.
00002 //
00004 
00005 
00006 #ifndef RepositoryMapcodeXML_H
00007 #define RepositoryMapcodeXML_H
00008 
00009 
00010 #include "IMapcodeRepository.h"
00011 #include "somdataxmlreader.h"
00012 #include "mapcodexmlreader.h"
00013 #include "xmlsomwriter.h"
00014 #include "util.h"
00015 #include <iostream>
00016 
00017 using std::cout;
00018 
00019 
00020 class RepositoryMapcodeXML : public IMapcodeRepository {
00021 
00022   public:
00023    
00024           RepositoryMapcodeXML();
00025 
00026           virtual ~RepositoryMapcodeXML();
00027 
00028           virtual void save(const Mapcode* mapcode, const std::string fileName);
00029 
00030           virtual Mapcode* load(std::string filename);
00031 };
00032 
00033 
00034 
00035 RepositoryMapcodeXML::RepositoryMapcodeXML() {};
00036 
00037 
00038 
00039 RepositoryMapcodeXML::~RepositoryMapcodeXML() {};
00040 
00041 
00042 
00043 void RepositoryMapcodeXML::save(const Mapcode* mapcode, const std::string fileName) {
00044 
00045   
00046 
00047   TMatrix codebook = mapcode->getCodebook();
00048   int dimension = mapcode->getDimension();
00049 
00050   int height = mapcode->getDimensions(0); height = (height > 0) ? height : 1;
00051   int width = mapcode->getDimensions(1);  width  = (width > 0)  ? width  : 1;
00052   int depth = mapcode->getDimensions(2);  depth  = (depth > 0)  ? depth  : 1;
00053 
00054   int size = mapcode->getMapSize();
00055   TopolParams top = mapcode->getTopolParams();  
00056   
00057 
00058   xmlsom::XMLSOMWriter writer(fileName);
00059   
00060   
00061   writer.startDocument();
00062   
00063   writer.startElement("som");
00064   
00065   writer.writeElement("height", inttostr(height));  
00066   
00067   writer.writeElement("width", inttostr(width));
00068   
00069   writer.writeElement("depth", inttostr(depth));
00070   
00071   writer.writeElement("dimension", inttostr(dimension));
00072   
00073   writer.writeElement("neighbourhood", inttostr(mapcode->getNeighborType()));
00074   
00075   writer.writeElement("topology", top.dimension);
00076   
00077   writer.endElement();
00078   
00079   writer.startElement("mapcode");
00080   
00081   char fltString[25]; // float to char conversions
00082   
00083   for(register int i = 0 ; i < size ; i++) {
00084     writer.startElement("node");
00085    
00086     for(register int j = 0 ; j < dimension ; j++) {
00087       sprintf(fltString, "%G", codebook[i][j]);
00088       writer.writeElement( "weight", fltString );
00089       }
00090     
00091     writer.endElement();  // node
00092   }
00093   writer.endElement();  // mapcode
00094   writer.endElement();  // som
00095   writer.endDocument();
00096   
00097 
00098   /*writer.writeElement("height", reinterpret_cast<char*>(height));
00099 
00100   writer.writeElement("width", reinterpret_cast<char*>(width));
00101   
00102   writer.writeElement("depth", reinterpret_cast<char*>(depth));
00103   
00104   writer.writeElement("dimension", reinterpret_cast<char*>(dimension));
00105   
00106   writer.writeElement("neighbourhood", reinterpret_cast<char*>(mapcode->getNeighborType()));
00107   
00108   writer.writeElement("topology", top.dimension);
00109   
00110   writer.startElement("mapcode");
00111   
00112   char fltString[25]; // float to char conversions
00113   
00114   for(register int i = 0 ; i < size ; i++) {
00115     writer.startElement("node");
00116    
00117     for(register int j = 0 ; j < dimension ; j++) {
00118       sprintf(fltString, "%G", codebook[i][j]);
00119       writer.writeElement( "weight", fltString );
00120     }
00121     
00122     writer.endElement();  // node
00123   }
00124   
00125   writer.endElement();  // mapcode
00126   writer.endElement();  // som
00127   writer.endDocument(); */
00128 };
00129 
00130 
00131 
00132 Mapcode* RepositoryMapcodeXML::load(std::string fileName) {
00133 
00134   MapcodeXMLReader reader(fileName);
00135 
00136   return reader.load();
00137 };
00138 
00139 
00140 
00141 #endif 
00142 

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