OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Registry.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgFX - Copyright (C) 2003 Marco Jez
14 
15 #ifndef OSGFX_REGISTRY_
16 #define OSGFX_REGISTRY_
17 
18 #include <osgFX/Export>
19 #include <osgFX/Effect>
20 
21 #include <osg/ref_ptr>
22 
23 #include <map>
24 #include <string>
25 
26 namespace osgFX
27 {
28 
30  {
31  public:
32 
33  struct Proxy {
34  Proxy(const Effect* effect): _effect(effect)
35  {
37  }
38 
40  {
41  Registry::instance()->removeEffect(_effect.get());
42  }
43  private:
45  };
46 
47  typedef std::map<std::string, osg::ref_ptr<const Effect> > EffectMap;
48 
49  static Registry* instance();
50 
51  inline void registerEffect(const Effect* effect);
52 
53  inline void removeEffect(const Effect* effect);
54 
55  inline const EffectMap& getEffectMap() const;
56 
57  protected:
58 
59  // Registry is a singleton; constructor and destructor must be protected
60  Registry();
61  ~Registry() {}
62 
63  private:
64  EffectMap _effects;
65  };
66 
67  // INLINE METHODS
68 
69 
70 
72  {
73  return _effects;
74  }
75 
76  inline void Registry::registerEffect(const Effect* effect)
77  {
78  _effects[effect->effectName()] = effect;
79  }
80 
81  inline void Registry::removeEffect(const Effect* effect)
82  {
83  EffectMap::iterator itr = _effects.find(effect->effectName());
84  if (itr != _effects.end())
85  {
86  _effects.erase(itr);
87  }
88  }
89 
90 }
91 
92 #endif
void registerEffect(const Effect *effect)
Definition: Registry.h:76
Proxy(const Effect *effect)
Definition: Registry.h:34
void removeEffect(const Effect *effect)
Definition: Registry.h:81
static Registry * instance()
#define OSGFX_EXPORT
Definition: Export.h:27
const EffectMap & getEffectMap() const
Definition: Registry.h:71
virtual const char * effectName() const =0
std::map< std::string, osg::ref_ptr< const Effect > > EffectMap
Definition: Registry.h:47