XMLAdapter.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 XMLAdapter
00024 // 
00025 
00026 #ifndef _XMLAdapter_
00027 #define _XMLAdapter_
00028 
00029 #include "BasicXMLable.hxx"
00030 #include <sstream>
00031 #include <string>
00032 
00033 namespace CLAM {
00034 
00057 template <class T> class XMLAdapter : public BasicXMLable {
00058 // Internal Types
00059 public:
00060         typedef BasicXMLable super;
00061         typedef T t_adaptee;
00062 // Attributes
00063 private:
00064         t_adaptee & mAdaptee;
00065 // Construction/Destruction
00066 public:
00082         XMLAdapter (t_adaptee & anAdaptee, const char * name=NULL, bool isXMLElement=false)
00083                 : BasicXMLable(name, isXMLElement), mAdaptee(anAdaptee)
00084         {
00085         }
00086         XMLAdapter (const t_adaptee & anAdaptee, const char * name=NULL, bool isXMLElement=false)
00087                 : BasicXMLable(name, isXMLElement), mAdaptee(const_cast<T&>(anAdaptee))
00088         {
00089         }
00090         virtual ~XMLAdapter() 
00091         {
00092         };
00093 
00094 // Accessors
00095 public:
00096         //* @return A string with the extracted XML content
00097         std::string XMLContent() const
00098         {
00099 
00100                 std::stringstream str;
00101                 str << mAdaptee << std::ends;
00102                 return str.str();
00103         }
00104 
00105         //* Extracts the content from the stream.
00106         bool XMLContent(std::istream & str) 
00107         {
00108                 str >> mAdaptee;
00109                 return str!=NULL;
00110         }
00111 // Testing
00112 public:
00113         //* Check the internal status for a class instance is valid
00114         bool FulfilsInvariant()
00115         {
00116                 return super::FulfilsInvariant();
00117         }
00118 };
00119 
00120 }
00121 #endif//_XMLAdapter_
00122 
Generated by  doxygen 1.6.3