DescriptionScheme.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 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 
00022 #include "DescriptionScheme.hxx"
00023 #include "XMLAdapter.hxx"
00024 
00025 namespace CLAM
00026 {
00027         DescriptionScheme::~DescriptionScheme()
00028         {
00029                         Scopes::iterator it = _scopes.begin();
00030                         Scopes::iterator end = _scopes.end();
00031                         for (; it!=end; it++)
00032                                 delete *it;
00033         }
00034         namespace Hidden
00035         {
00036                 class AttributeInserter : public Component
00037                 {
00038                 public:
00039                         AttributeInserter(DescriptionScheme & scheme) : _scheme(scheme) {}
00040                         const char * GetClassName() const {return "AttributeInserter"; }
00041                         void StoreOn(Storage & storage) const
00042                         {
00043                         }
00044                         void LoadFrom(Storage & storage)
00045                         {
00046                                 std::string _name;
00047                                 XMLAdapter<std::string> nameAdapter(_name, "name", false);
00048                                 storage.Load(nameAdapter);
00049 
00050                                 std::string _scope;
00051                                 XMLAdapter<std::string> scopeAdapter(_scope, "scope", false);
00052                                 storage.Load(scopeAdapter);
00053 
00054                                 std::string _type;
00055                                 XMLAdapter<std::string> typeAdapter(_type, "type", false);
00056                                 storage.Load(typeAdapter);
00057 
00058                                 if (_type == "Float")
00059                                         _scheme.AddAttribute<float>(_scope, _name);
00060                                 else if (_type == "String")
00061                                         _scheme.AddAttribute<std::string>(_scope, _name);
00062                         }
00063                 private:
00064                         DescriptionScheme & _scheme;
00065                 };
00066         }
00067         
00068         void DescriptionScheme::StoreOn(Storage & storage) const
00069         {
00070                 for (unsigned int i = 0; i < GetNScopes(); i++)
00071                 {
00072                         const DescriptionScope & scope = GetScope(i);
00073                         for (unsigned int j = 0; j < scope.GetNAttributes(); j++)
00074                         {
00075                                 XMLComponentAdapter adapter(scope.GetAttribute(j), "Attribute", true);
00076                                 storage.Store(adapter);
00077                         }
00078                 }
00079         }
00080 
00081         void DescriptionScheme::LoadFrom(Storage & storage)
00082         {
00083                 for (; true; )
00084                 {
00085                         Hidden::AttributeInserter inserter(*this);
00086                         XMLComponentAdapter adapter(inserter, "Attribute", true);
00087                         if (!storage.Load(adapter)) break;
00088                 }
00089         }
00090 }
00091 
00092 
Generated by  doxygen 1.6.3