XMLArrayAdapter.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024
00025
00026 #ifndef _XMLArrayAdapter_h
00027 #define _XMLArrayAdapter_h
00028
00029 #include "BasicXMLable.hxx"
00030 #include <sstream>
00031
00032 namespace CLAM {
00033
00059 template <class T> class XMLArrayAdapter : public BasicXMLable {
00060
00061 public:
00062 typedef BasicXMLable super;
00063 typedef T t_adaptee;
00064
00065 private:
00066 t_adaptee * mAdaptee;
00067 unsigned int size;
00068
00069 public:
00086 XMLArrayAdapter (t_adaptee * anAdaptee, unsigned int nElements, const char * name=NULL, bool isXMLElement=false)
00087 : BasicXMLable(name, isXMLElement), mAdaptee(anAdaptee)
00088 {
00089 size = nElements;
00090 }
00091 XMLArrayAdapter (const t_adaptee * anAdaptee, unsigned int nElements,
00092 const char * name=NULL, bool isXMLElement=false)
00093 : BasicXMLable(name, isXMLElement), mAdaptee(const_cast<T*>(anAdaptee))
00094 {
00095 size = nElements;
00096 }
00097 virtual ~XMLArrayAdapter() {};
00098
00099
00100 public:
00101
00102 std::string XMLContent() const
00103 {
00104 std::string s;
00105 s.resize(size*15);
00106 std::stringstream str(s);
00107 for (unsigned int i=0; i<size; i++) {
00108 str << mAdaptee[i];
00109 if (i < size-1) str << " ";
00110 }
00111 str << std::ends;
00112 return str.str();
00113 }
00114
00115
00116 bool XMLContent(std::istream & str)
00117 {
00118 for (unsigned int i=0; i<size; i++) {
00119 str >> mAdaptee[i];
00120 }
00121 return bool(str.good());
00122 }
00123
00124
00125 public:
00126
00127 bool FulfilsInvariant() {
00128 return super::FulfilsInvariant();
00129 }
00130 };
00131 }
00132
00133
00134 #endif//_XMLArrayAdapter_h
00135