XMLComponentAdapter.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 XMLComponentAdapter
00024 // 
00025 
00026 #ifndef _XMLComponentAdapter_h
00027 #define _XMLComponentAdapter_h
00028 #include "BasicXMLable.hxx"
00029 #include "Component.hxx"
00030 #include "Assert.hxx"
00031 
00032 namespace CLAM {
00033 
00062 class XMLComponentAdapter : public BasicXMLable , public Component {
00063 // Internal Types
00064 public:
00065         typedef BasicXMLable super;
00066 // Attributes
00067 private:
00068         Component &myAdaptee;
00069 // Construction/Destruction
00070 public:
00092         template <class T> XMLComponentAdapter (const T & adaptee, const char * name=NULL, bool isXMLElement=false)
00093                 : BasicXMLable(name, isXMLElement), myAdaptee(const_cast<T&>(adaptee))
00094         {
00095                 CLAM_ASSERT(!name||isXMLElement,"Adapting a component as attribute is useless");
00096         }
00097         virtual ~XMLComponentAdapter() {};
00098 
00099 // Accessors (for XMLable interface)
00100 public:
00101         //* @return The XML content: an empty string.
00102         virtual std::string XMLContent() const
00103         {
00104                 return "";
00105         }
00106 
00107         //* Extracts the content from the stream.
00108         virtual bool XMLContent(std::istream & str) 
00109         {
00110                 return true;
00111         }
00112 
00113         //* Returns the class name
00114         const char * GetClassName() const {return "XMLComponentAdapter";}
00115 
00116 // Operators (for Component interface)
00117 public:
00123         virtual void StoreOn (Storage & store) const {
00124                 myAdaptee.StoreOn(store);
00125         };
00131         virtual void LoadFrom (Storage & store) {
00132                 myAdaptee.LoadFrom(store);
00133         };
00134 // Testing
00135 public:
00136         //* Check the internal status for a class instance is valid
00137         bool FulfilsInvariant();
00138 };
00139 
00140 }
00141 
00142 #endif//_XMLComponentAdapter_h
00143 
Generated by  doxygen 1.6.3