freXMLStreamObject.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freXMLStreamObject.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freXMLStreamObject_h
00023 #define __freXMLStreamObject_h
00024 
00025 //This is to avoid the warnings produced by itk/stl and ease the search for errors
00026 //in the creation report
00027 #pragma warning( disable : 4786)
00028 
00029 #include "expat.h"
00030 #include <fstream>
00031 #include <map>
00032 #include <vector>
00033 #include <string>
00034 
00035 #include "freElementals.h"
00036 #include "freConstXMLTags.h"
00037 
00038 #include "itkMacro.h"
00039 
00040 namespace FREE
00041 {
00042 
00043 //Macro for generation of a controller ID
00044 #define freXMLTagMacro( Name, Value )\
00045   namespace XMLTags {\
00046                 static const char* const Name = Value;\
00047         }
00048 
00062 class XMLStreamObject
00063 {
00064 public:
00065   virtual const char *GetNameOfClass() const
00066         {return "XMLStreamObject";};
00067 
00069   static const std::string cXML_Text;
00070 
00071   typedef std::pair<std::string,std::string> AttributeType;
00072   typedef std::map<std::string,std::string> AttributesType;
00073         //uses vector for saving, to avoid automatic sort feature of stl::map
00074   typedef std::vector<AttributeType> AttributesSaveListType;
00075 
00082   void LoadFromString(const std::string& rsData);
00083 
00087   std::string SaveToString() const;
00088 
00094   void SaveToFile(const std::string& sFileName, const std::string& sXSLT = "", const std::string& sEncoding = "ISO-8859-1") const;
00095 
00098   void LoadFromFile(const std::string& sFileName);
00099 
00101   virtual void Reset();
00102 
00104   virtual const std::string GetXMLTag() const;
00105 
00107   void SetXMLTag(const std::string& sTag) { m_sXMLTag = sTag; };
00108 
00110   virtual XMLStreamObject& operator = (const XMLStreamObject& rXMLStreamObject);
00111 
00113   XMLStreamObject(const std::string& sXMLTag);
00114 
00116   XMLStreamObject(const XMLStreamObject& rXMLStreamObject);
00117 
00119   virtual ~XMLStreamObject();
00120 
00121 protected:
00142   virtual void SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData);
00143 
00148   virtual void AttributesLoadProcessing(const AttributesType& rAttributes);
00149 
00156   virtual void SaveAttributes(AttributesSaveListType& rAttributes) const;
00157 
00164   std::string SaveToString(const unsigned int& iDepth) const;
00165 
00177   virtual std::string SaveData(const unsigned int& iDepth, bool& bHasSubElements) const;
00178 
00182   virtual void FinalizeLoading() const {/*reimplement in derived classes if needed.*/};
00183 
00188   virtual bool CheckValidLoading() const;
00189 
00194   virtual void SetNeededSubElements();
00195 
00199   void AddNeededSubElement(const std::string& sSubElementTag);
00200 
00205         static std::string CreateSimpleElement(const std::string& sTag, const std::string& sValue);
00206 
00215         static void AddSubElement(std::string& sData, const std::string& sTag, const std::string& sValue, const unsigned int& iParentalDepth);
00216 
00218         static void AddSubElement(std::string& sData, const std::string& sTag, const std::string& sValue, const AttributesType& rAttributes, const unsigned int& iParentalDepth);
00219 
00227         static void AddSubElement(std::string& sData, const XMLStreamObject* pSubElement, const unsigned int& iParentalDepth);
00234         static void AddSubElement(std::string& sData, const std::string& sSubElement, const unsigned int& iParentalDepth);
00235 
00240         static void AddIndentation(std::string& sData, const unsigned int& iDepth);
00241 
00242 private:
00243   static void CB_Static_StartElement(void* parser, const char *name,
00244                                      const char **pAttributes);
00245 
00246   static void CB_Static_EndElement(void* parser, const char *name);
00247 
00248   static void CB_Static_CharacterDataHandler(void* parser, const char* data,
00249                                              int length);
00250 
00254   void CB_StartElement(const char * name,const char **pAttributes);
00255 
00259   void CB_EndElement(const char *name);
00260 
00264   void CB_CharacterDataHandler(const char *inData, int inLength);
00265 
00267   void ResetRequirements();
00268 
00270   void ResetLoadingHelpers();
00271 
00273   static AttributesType ConvertExpatAttrToMap(const char** pAttributes);
00274 
00276   static std::string ConvertAttributesToString(const AttributesSaveListType& rAttributes);
00277 
00281   std::string ExtractSubElementXmlString();
00282 
00286   std::string ExtractSubElementContentString();
00287 
00291   void NotifyFoundSubElement(const std::string& sSubElementTag);
00292 
00295   void CommitSubElement();
00296 
00299   STLStringVector m_NeededSubElements;
00300 
00302   std::string m_sActSubElementTag;
00303 
00306   AttributesType m_ActSubElementAttributes;
00307 
00309   const std::string* m_psLoadData;
00310 
00313   unsigned int m_iActSubElementLevel; 
00314 
00317   long m_lElementStartPos;
00320   long m_lElementStopPos;
00323   long m_lContentStartPos;
00326   long m_lContentStopPos;
00327 
00329   std::string m_sXMLTag;
00330 
00332   XML_Parser m_Parser;
00333 };
00334 
00335 }//end of namespace FREE
00336 
00337 #endif

Generated at Sat Oct 13 18:14:02 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000