S11n.h

Go to the documentation of this file.
00001 #ifndef __S11N_H__
00002 #define __S11N_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include "String.h"
00011 #include "XmlElement.h"
00012 #include "Error.h"
00013 
00014 // Declaration.
00015 
00016 template<class T>
00017 class S11n
00018 {
00019 
00020 public:
00021 
00022   static int toString(const T &value, String &str);
00023   static int fromString(const String &str, T &value);
00024 
00025   static int toXml(const T &value, XmlElement *element);
00026   static int fromXml(const XmlElement *element, T &value);
00027 
00028 private:
00029 
00030   static int toXmlAttrValue(const T &value, XmlElement *element);
00031   static int fromXmlAttrValue(const XmlElement *element, T &value);
00032 
00033 };
00034 
00035 // Implementation.
00036 
00037 // Private methods.
00038 
00039 template<class T>
00040 int S11n<T>::toXmlAttrValue(const T &value, XmlElement *element)
00041 {
00042   CHECK_POINTER(element);
00043 
00044   String str;
00045   int res;
00046 
00047   if (FAILED(res = element->removeChildren()))
00048     return ERROR_BACKTRACE(res);
00049 
00050   if (FAILED(res = toString(value, str)))
00051     return ERROR_BACKTRACE(res);
00052 
00053   if (FAILED(res = element->setAttribute(XML_ATTR_VALUE, str)))
00054     return ERROR_BACKTRACE(res);
00055 
00056   return OK;
00057 }
00058 
00059 template<class T>
00060 int S11n<T>::fromXmlAttrValue(const XmlElement *element, T &value)
00061 {
00062   CHECK_POINTER(element);
00063 
00064   String str;
00065   int res;
00066 
00067   if (FAILED(res = element->attribute(XML_ATTR_VALUE, str)))
00068     return ERROR_BACKTRACE(res);
00069 
00070   if (FAILED(res = fromString(str, value)))
00071     return ERROR_BACKTRACE(res);
00072 
00073   return OK;
00074 }
00075 
00076 #include "S11nBool.h"
00077 #include "S11nChar.h"
00078 #include "S11nDouble.h"
00079 #include "S11nInt.h"
00080 #include "S11nObject.h"
00081 #include "S11nPointer.h"
00082 #include "S11nString.h"
00083 #include "S11nUint.h"
00084 #include "S11nVector.h"
00085 
00086 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1