CLAM-Development  1.4.0
XMLComponentAdapter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
23 // Class XMLComponentAdapter
24 //
25 
26 #ifndef _XMLComponentAdapter_h
27 #define _XMLComponentAdapter_h
28 #include "BasicXMLable.hxx"
29 #include "Component.hxx"
30 #include "Assert.hxx"
31 
32 namespace CLAM {
33 
62 class XMLComponentAdapter : public BasicXMLable , public Component {
63 // Internal Types
64 public:
66 // Attributes
67 private:
68  Component &myAdaptee;
69 // Construction/Destruction
70 public:
92  template <class T> XMLComponentAdapter (const T & adaptee, const char * name=NULL, bool isXMLElement=false)
93  : BasicXMLable(name, isXMLElement), myAdaptee(const_cast<T&>(adaptee))
94  {
95  CLAM_ASSERT(!name||isXMLElement,"Adapting a component as attribute is useless");
96  }
97  virtual ~XMLComponentAdapter() {};
98 
99 // Accessors (for XMLable interface)
100 public:
101  //* @return The XML content: an empty string.
102  virtual std::string XMLContent() const
103  {
104  return "";
105  }
106 
107  //* Extracts the content from the stream.
108  virtual bool XMLContent(std::istream & str)
109  {
110  return true;
111  }
112 
113  //* Returns the class name
114  const char * GetClassName() const {return "XMLComponentAdapter";}
115 
116 // Operators (for Component interface)
117 public:
123  virtual void StoreOn (Storage & store) const {
124  myAdaptee.StoreOn(store);
125  };
131  virtual void LoadFrom (Storage & store) {
132  myAdaptee.LoadFrom(store);
133  };
134 // Testing
135 public:
136  //* Check the internal status for a class instance is valid
137  bool FulfilsInvariant();
138 };
139 
140 }
141 
142 #endif//_XMLComponentAdapter_h
143