CLAM-Development
1.1
|
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 #ifndef _DescriptionScheme_hxx_ 00023 #define _DescriptionScheme_hxx_ 00024 00025 00026 #include "DescriptionScope.hxx" 00027 00028 /* 00029 You can find the doxygen of the SemanticalAnalysis group 00030 at the end of this file. 00031 */ 00032 00033 namespace CLAM 00034 { 00035 00036 00061 class DescriptionScheme : public Component 00062 { 00063 private: 00064 typedef std::map<std::string, unsigned> ScopeMap; 00065 typedef std::vector<DescriptionScope *> Scopes; 00066 private: 00067 Scopes _scopes; 00068 ScopeMap _scopeNameMap; 00069 public: 00070 DescriptionScheme() 00071 { 00072 } 00073 00074 ~DescriptionScheme(); 00075 00085 template < typename DataType > 00086 void AddAttribute(const std::string &scope, const std::string & name) 00087 { 00088 DescriptionScope & theScope = SearchScopeOrAdd(scope); 00089 theScope.template Add<DataType>(name); 00090 } 00091 00092 DescriptionScope & SearchScopeOrAdd(const std::string scopeName) 00093 { 00094 const unsigned nScopes = _scopes.size(); 00095 std::pair<ScopeMap::iterator,bool> result = 00096 _scopeNameMap.insert(std::make_pair(scopeName,nScopes)); 00097 00098 if (!result.second) return *_scopes[result.first->second]; 00099 00100 DescriptionScope * theScope = new DescriptionScope(scopeName); 00101 _scopes.push_back(theScope); 00102 return *theScope; 00103 } 00104 00105 unsigned GetScopeIndex(const std::string & name) const 00106 { 00107 ScopeMap::const_iterator it = _scopeNameMap.find(name); 00108 CLAM_ASSERT(it!=_scopeNameMap.end(), ("Attribute scope '" + name + "' not found").c_str()); 00109 return it->second; 00110 } 00111 00112 const DescriptionScope & GetScope(unsigned scopeIndex) const 00113 { 00114 CLAM_ASSERT(scopeIndex < _scopes.size(), "Accessing an illegal scope index for the description scheme"); 00115 return *_scopes[scopeIndex]; 00116 } 00117 00118 const DescriptionScope & GetScope(const std::string & name) const 00119 { 00120 unsigned scopeIndex = GetScopeIndex(name); 00121 return GetScope(scopeIndex); 00122 } 00123 unsigned GetNScopes() const 00124 { 00125 return _scopes.size(); 00126 } 00127 00128 const std::string & GetScopeName(unsigned scopeIndex) const 00129 { 00130 const DescriptionScope & scope = GetScope(scopeIndex); 00131 return scope.GetName(); 00132 } 00133 void StoreOn(Storage & storage) const; 00134 void LoadFrom(Storage & storage); 00135 const char * GetClassName() const { return "DescriptionScheme"; } 00136 }; 00137 } 00138 00305 #endif// _DescriptionScheme_hxx_ 00306