CLAM-Development  1.4.0
DescriptionScheme.hxx
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 #ifndef _DescriptionScheme_hxx_
23 #define _DescriptionScheme_hxx_
24 
25 
26 #include "DescriptionScope.hxx"
27 
28 /*
29  You can find the doxygen of the SemanticalAnalysis group
30  at the end of this file.
31  */
32 
33 namespace CLAM
34 {
35 
36 
62  {
63  private:
64  typedef std::map<std::string, unsigned> ScopeMap;
65  typedef std::vector<DescriptionScope *> Scopes;
66  private:
67  Scopes _scopes;
68  ScopeMap _scopeNameMap;
69  public:
71  {
72  }
73 
75 
85  template < typename DataType >
86  void AddAttribute(const std::string &scope, const std::string & name)
87  {
88  DescriptionScope & theScope = SearchScopeOrAdd(scope);
89  theScope.template Add<DataType>(name);
90  }
91 
92  DescriptionScope & SearchScopeOrAdd(const std::string scopeName)
93  {
94  const unsigned nScopes = _scopes.size();
95  std::pair<ScopeMap::iterator,bool> result =
96  _scopeNameMap.insert(std::make_pair(scopeName,nScopes));
97 
98  if (!result.second) return *_scopes[result.first->second];
99 
100  DescriptionScope * theScope = new DescriptionScope(scopeName);
101  _scopes.push_back(theScope);
102  return *theScope;
103  }
104 
105  unsigned GetScopeIndex(const std::string & name) const
106  {
107  ScopeMap::const_iterator it = _scopeNameMap.find(name);
108  CLAM_ASSERT(it!=_scopeNameMap.end(), ("Attribute scope '" + name + "' not found").c_str());
109  return it->second;
110  }
111 
112  const DescriptionScope & GetScope(unsigned scopeIndex) const
113  {
114  CLAM_ASSERT(scopeIndex < _scopes.size(), "Accessing an illegal scope index for the description scheme");
115  return *_scopes[scopeIndex];
116  }
117 
118  const DescriptionScope & GetScope(const std::string & name) const
119  {
120  unsigned scopeIndex = GetScopeIndex(name);
121  return GetScope(scopeIndex);
122  }
123  unsigned GetNScopes() const
124  {
125  return _scopes.size();
126  }
127 
128  const std::string & GetScopeName(unsigned scopeIndex) const
129  {
130  const DescriptionScope & scope = GetScope(scopeIndex);
131  return scope.GetName();
132  }
133  void StoreOn(Storage & storage) const;
134  void LoadFrom(Storage & storage);
135  const char * GetClassName() const { return "DescriptionScheme"; }
136  };
137 }
138 
305 #endif// _DescriptionScheme_hxx_
306