OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
PluginContext.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 #ifndef PLUGINCONTEXT_H
34 #define PLUGINCONTEXT_H
35 
36 #if defined(OPENIG_SDK)
37  #include <OpenIG-PluginBase/Export.h>
38  #include <OpenIG-Base/ImageGenerator.h>
39  #include <OpenIG-Base/IGCore.h>
40 #else
41  #include <Core-PluginBase/Export.h>
42  #include <Core-Base/ImageGenerator.h>
43  #include <Core-Base/IGCore.h>
44 #endif
45 
46 
47 #include <map>
48 
49 namespace OpenIG {
50  namespace PluginBase {
51 
59  class IGPLUGINCORE_EXPORT PluginContext
60  {
61  public:
69  : _ig(0) {}
70 
79  : _ig(ig) {}\
80 
89  {
90  _ig = ig;
91  }
92 
101  {
102  return _ig;
103  }
104 
105 
117  template<typename T>
118  struct Attribute : public osg::Referenced
119  {
127  Attribute(T value)
128  : _value(value) {}
129 
137  void setValue(const T& value)
138  {
139  _value = value;
140  }\
141 
149  T& getValue()
150  {
151  return _value;
152  }
153 
154  T _value;
155  };
156 
157  typedef std::multimap< std::string, osg::ref_ptr<osg::Referenced> > AttributeMap;
158  typedef std::multimap< std::string, osg::ref_ptr<osg::Referenced> >::iterator AttributeMapIterator;
159  typedef std::multimap< std::string, osg::ref_ptr<osg::Referenced> >::const_iterator AttributeMapConstIterator;
160 
169  AttributeMap& getAttributes()
170  {
171  return _attributes;
172  }
173 
182  void addAttribute(const std::string& name, osg::Referenced* attr)
183  {
184  if (attr == 0) return;
185 
186  _attributes.insert(AttributeMap::value_type(name, attr));
187  }
188 
197  osg::Referenced* getAttribute(const std::string& name)
198  {
199  AttributeMapIterator itr = _attributes.find(name);
200  if (itr != _attributes.end())
201  return itr->second.get();
202  else
203  return 0;
204  }
205 
213  osg::ValueObject* getOrCreateValueObject()
214  {
215  if (!_valueObject.valid())
216  {
217  _valueObject = new osg::ValueObject;
218  }
219  return _valueObject.get();
220  }
221 
229  void setValueObject(osg::ValueObject* valueObject)
230  {
231  _valueObject = valueObject;
232  }
233 
234  protected:
236  AttributeMap _attributes;
237  osg::ref_ptr<osg::ValueObject> _valueObject;
238  };
239  }
240 } // namespace
241 
242 #endif // PLUGINCONTEXT_H
Definition: ImageGenerator.h:62
PluginContext(OpenIG::Base::ImageGenerator *ig)
Constructor with reference to OpenIG::Base::ImageGenerator.
Definition: PluginContext.h:78
void setValue(const T &value)
Set some value.
Definition: PluginContext.h:137
osg::ValueObject * getOrCreateValueObject()
Gets a value object to pass data to plugins.
Definition: PluginContext.h:213
osg::ref_ptr< osg::ValueObject > _valueObject
attrinute name based map
Definition: PluginContext.h:237
AttributeMap & getAttributes()
Gets a handle of all the igplugincore::PluginContext::Attribute present in the context.
Definition: PluginContext.h:169
Attribute struct.
Definition: PluginContext.h:118
The Image Generator abstract interface. This is base class for openig::OpenIG.
Definition: ImageGenerator.h:74
void setValueObject(osg::ValueObject *valueObject)
Sets a value object to pass data to plugins.
Definition: PluginContext.h:229
OpenIG::Base::ImageGenerator * getImageGenerator() const
Returns the OpenIG::Base::ImageGenerator reference.
Definition: PluginContext.h:100
void addAttribute(const std::string &name, osg::Referenced *attr)
Adds an igplugincore::PluginContext::Attribute with a given name.
Definition: PluginContext.h:182
osg::Referenced * getAttribute(const std::string &name)
Gets an igplugincore::PluginContext::Attribute by its name.
Definition: PluginContext.h:197
The PluginContext class.
Definition: PluginContext.h:59
Attribute(T value)
Attribute.
Definition: PluginContext.h:127
AttributeMap _attributes
a reference to ImageGenerator
Definition: PluginContext.h:236
PluginContext()
Constructor.
Definition: PluginContext.h:68
void setImageGenerator(OpenIG::Base::ImageGenerator *ig)
Sets the OpenIG::Base::ImageGenerator reference.
Definition: PluginContext.h:88
T & getValue()
Gets the value.
Definition: PluginContext.h:149