XMLArrayAdapter.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00023 // Class XMLArrayAdapter
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 // Internal Types
00061 public:
00062         typedef BasicXMLable super;
00063         typedef T t_adaptee;
00064 // Attributes
00065 private:
00066         t_adaptee * mAdaptee;
00067         unsigned int size;
00068 // Construction/Destruction
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 // Accessors
00100 public:
00101         //* @return A string with the extracted XML content
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         //* Extracts the content from the stream.
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 // Testing
00125 public:
00126         //* Check the internal status for a class instance is valid
00127         bool FulfilsInvariant() {
00128                 return super::FulfilsInvariant();
00129         }
00130 };
00131 }
00132 
00133 
00134 #endif//_XMLArrayAdapter_h
00135 
Generated by  doxygen 1.6.3