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
29 class OSGFX_EXPORT Registry : public osg::Referenced
30 {
31 public:
32
33 struct Proxy {
34 Proxy(const Effect* effect): _effect(effect)
35 {
36 Registry::instance()->registerEffect(effect);
37 }
38
39 ~Proxy()
40 {
41 Registry::instance()->removeEffect(_effect.get());
42 }
43 private:
44 osg::ref_ptr<const Effect> _effect;
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
71 inline const Registry::EffectMap& Registry::getEffectMap() const
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