RepositorySOMDataXML.h

00001 // RepositorySOMDataXML.h: interface for the RepositorySOMDataXML class.
00002 //
00004 
00005 #ifndef ISOMDataRepository_h
00006 #define ISOMDataRepository_h
00007 
00008 
00009 #include "ISOMDataRepository.h"
00010 #include "somdataxmlreader.h"
00011 #include "xmlsomwriter.h"
00012 #include <string>
00013 
00014 
00015 
00016 class RepositorySOMDataXML : public ISOMDataRepository  {
00017 
00018   public:
00019 
00020           RepositorySOMDataXML(const char* filename);    
00021     
00022           virtual ~RepositorySOMDataXML();
00023     
00024     virtual void save(SOMData data);
00025     
00026     virtual SOMData* load(std::vector<std::string> params, int flag = 0);
00027     
00028   private:
00029     
00030     std::string filename;
00031     
00032 };
00033 
00034 
00035 
00036 RepositorySOMDataXML::RepositorySOMDataXML(const char* xmlfile) 
00037     : filename(xmlfile) {  
00038   
00039 };
00040 
00041 
00042 
00043 RepositorySOMDataXML::~RepositorySOMDataXML() {};
00044 
00045 
00046 
00047 
00048 void RepositorySOMDataXML::save( SOMData data ) {
00049   
00050   TMatrix entries = data.getEntries();
00051   TvecLabel labels = data.getLabel();
00052   int size = data.getDataSize();  
00053   int dimension = data.getDimension();
00054   char fltString[25]; // float to char conversions
00055 
00056   xmlsom::XMLSOMWriter writer(filename);
00057   
00058   writer.startDocument();
00059   writer.startElement("somdata");
00060   writer.writeElement("size", reinterpret_cast<char*>(size));
00061   writer.writeElement("dimension", reinterpret_cast<char*>(dimension));
00062   writer.startElement("data");
00063   
00064   for(register int i = 0 ; i < size ; i++) {
00065     writer.startElement("row");
00066     writer.writeElement("label", labels[i]);
00067     
00068     for(register int j = 0 ; j < dimension ; j++) {
00069       sprintf(fltString, "%G", entries[i][j]);
00070       writer.writeElement("weight", fltString);
00071     }
00072     
00073     writer.endElement();  // row
00074   }
00075   
00076   writer.endElement();  // data
00077   writer.endElement();  // somdata
00078   writer.endDocument();
00079 };
00080 
00081 
00082 
00083 SOMData* RepositorySOMDataXML::load( std::vector<std::string> params, int flag ) {
00084 
00085   SOMDataXMLReader reader(filename);
00086   
00087   return reader.load();
00088 };
00089 
00090 
00091 #endif 
00092 

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