CLAM-Development  1.4.0
DescriptionScheme.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 
22 #include "DescriptionScheme.hxx"
23 #include "XMLAdapter.hxx"
24 
25 namespace CLAM
26 {
28  {
29  Scopes::iterator it = _scopes.begin();
30  Scopes::iterator end = _scopes.end();
31  for (; it!=end; it++)
32  delete *it;
33  }
34  namespace Hidden
35  {
36  class AttributeInserter : public Component
37  {
38  public:
39  AttributeInserter(DescriptionScheme & scheme) : _scheme(scheme) {}
40  const char * GetClassName() const {return "AttributeInserter"; }
41  void StoreOn(Storage & storage) const
42  {
43  }
44  void LoadFrom(Storage & storage)
45  {
46  std::string _name;
47  XMLAdapter<std::string> nameAdapter(_name, "name", false);
48  storage.Load(nameAdapter);
49 
50  std::string _scope;
51  XMLAdapter<std::string> scopeAdapter(_scope, "scope", false);
52  storage.Load(scopeAdapter);
53 
54  std::string _type;
55  XMLAdapter<std::string> typeAdapter(_type, "type", false);
56  storage.Load(typeAdapter);
57 
58  if (_type == "Float")
59  _scheme.AddAttribute<float>(_scope, _name);
60  else if (_type == "String")
61  _scheme.AddAttribute<std::string>(_scope, _name);
62  }
63  private:
64  DescriptionScheme & _scheme;
65  };
66  }
67 
68  void DescriptionScheme::StoreOn(Storage & storage) const
69  {
70  for (unsigned int i = 0; i < GetNScopes(); i++)
71  {
72  const DescriptionScope & scope = GetScope(i);
73  for (unsigned int j = 0; j < scope.GetNAttributes(); j++)
74  {
75  XMLComponentAdapter adapter(scope.GetAttribute(j), "Attribute", true);
76  storage.Store(adapter);
77  }
78  }
79  }
80 
82  {
83  for (; true; )
84  {
85  Hidden::AttributeInserter inserter(*this);
86  XMLComponentAdapter adapter(inserter, "Attribute", true);
87  if (!storage.Load(adapter)) break;
88  }
89  }
90 }
91 
92