DescriptionScheme.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _DescriptionScheme_hxx_
00023 #define _DescriptionScheme_hxx_
00024
00025
00026 #include "DescriptionScope.hxx"
00027
00028
00029
00030
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