openscenegraph
osgFX/Registry
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
26namespace osgFX
27{
28
30 {
31 public:
32
33 struct Proxy {
34 Proxy(const Effect* effect): _effect(effect)
35 {
36 Registry::instance()->registerEffect(effect);
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
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
Definition Effect:66
virtual const char * effectName() const =0
Definition osgFX/Registry:30
static Registry * instance()
void removeEffect(const Effect *effect)
Definition osgFX/Registry:81
std::map< std::string, osg::ref_ptr< const Effect > > EffectMap
Definition osgFX/Registry:47
const EffectMap & getEffectMap() const
Definition osgFX/Registry:71
void registerEffect(const Effect *effect)
Definition osgFX/Registry:76
~Registry()
Definition osgFX/Registry:61
Definition Referenced:44
Definition ref_ptr:32
Definition AnisotropicLighting:25
#define OSGFX_EXPORT
Definition osgFX/Export:27
Definition osgFX/Registry:33
~Proxy()
Definition osgFX/Registry:39
Proxy(const Effect *effect)
Definition osgFX/Registry:34