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 _Pool_hxx_ 00023 #define _Pool_hxx_ 00024 00025 #include "ScopePool.hxx" 00026 #include "DescriptionScheme.hxx" 00027 00028 namespace CLAM 00029 { 00040 class DescriptionDataPool : public Component 00041 { 00042 public: 00048 DescriptionDataPool(const DescriptionScheme & scheme) 00049 : _scheme(scheme), _scopePools(_scheme.GetNScopes(),(ScopePool*)0) 00050 { 00051 } 00052 ~DescriptionDataPool(); 00053 00060 void SetNumberOfContexts(const std::string & scopeName, unsigned size) 00061 { 00062 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00063 const DescriptionScope & scope = _scheme.GetScope(scopeIndex); 00064 _scopePools[scopeIndex] = new ScopePool(scope, size); 00065 } 00066 00067 unsigned GetNumberOfContexts(const std::string & scopeName) const 00068 { 00069 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00070 CLAM_ASSERT(_scopePools[scopeIndex], 00071 ("Getting the size of scope '"+scopeName+"' but it is not populated").c_str()); 00072 return _scopePools[scopeIndex]->GetSize(); 00073 } 00074 00075 void Insert(const std::string & scopeName, unsigned pos) 00076 { 00077 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00078 CLAM_ASSERT(_scopePools[scopeIndex], "booooo"); 00079 _scopePools[scopeIndex]->Insert(pos); 00080 } 00081 void Remove(const std::string & scopeName, unsigned pos) 00082 { 00083 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00084 CLAM_ASSERT(_scopePools[scopeIndex], "booooo"); 00085 _scopePools[scopeIndex]->Remove(pos); 00086 } 00087 00089 void InstantiateAttribute(const std::string & scopeName, const std::string & attributeName) 00090 { 00091 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00092 const DescriptionScope & scope = _scheme.GetScope(scopeIndex); 00093 scope.GetIndex(attributeName); 00094 CLAM_ASSERT(_scopePools[scopeIndex], 00095 ("Instantianting '"+scopeName+":"+attributeName+"' but the scope is not yet populated").c_str()); 00096 } 00104 template <typename AttributeType> 00105 AttributeType * GetWritePool(const std::string & scopeName, const std::string & attributeName) 00106 { 00107 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00108 00109 CLAM_ASSERT(_scopePools[scopeIndex], 00110 ("Writting data on '"+scopeName+":"+attributeName+"' but the scope is not yet populated").c_str()); 00111 00112 return _scopePools[scopeIndex]->template GetWritePool<AttributeType>(attributeName); 00113 } 00122 template <typename AttributeType> 00123 const AttributeType * GetReadPool(const std::string & scopeName, const std::string & attributeName) const 00124 { 00125 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00126 00127 CLAM_ASSERT(_scopePools[scopeIndex], 00128 ("Reading data from '"+scopeName+":"+attributeName+"' but the scope is not yet populated").c_str()); 00129 00130 return _scopePools[scopeIndex]->template GetReadPool<AttributeType>(attributeName); 00131 } 00132 bool IsInstantiated(const std::string & scopeName, const std::string & attributeName) const 00133 { 00134 unsigned scopeIndex = _scheme.GetScopeIndex(scopeName); 00135 if (!_scopePools[scopeIndex]) return false; 00136 return _scopePools[scopeIndex]->IsInstantiated(attributeName); 00137 } 00138 // Component Interface 00139 00140 const char * GetClassName() const { return "DescriptionDataPool"; } 00141 void StoreOn(Storage & storage) const 00142 { 00143 for (unsigned i = 0; i<_scopePools.size(); i++) 00144 { 00145 XMLComponentAdapter adapter(*(_scopePools[i]), "ScopePool", true); 00146 storage.Store(adapter); 00147 } 00148 } 00149 void LoadFrom(Storage & storage) 00150 { 00151 for (unsigned i = 0; i<_scopePools.size(); i++) 00152 { 00153 const DescriptionScope & scope = _scheme.GetScope(i); 00154 _scopePools[i] = new ScopePool(scope,0); 00155 XMLComponentAdapter adapter(*(_scopePools[i]), "ScopePool", true); 00156 storage.Load(adapter); 00157 } 00158 } 00159 00160 private: 00161 const DescriptionScheme & _scheme; 00162 typedef std::vector<ScopePool*> ScopePools; 00163 ScopePools _scopePools; 00164 }; 00165 00166 } 00167 00168 00169 #endif// _Pool_hxx_ 00170