OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DotOsgWrapper.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 
14 #ifndef OSGDB_DOTOSGWRAPPER
15 #define OSGDB_DOTOSGWRAPPER 1
16 
17 #include <osg/ref_ptr>
18 #include <osg/Object>
19 
20 #include <osgDB/Input>
21 #include <osgDB/Output>
22 
23 #include <string>
24 #include <vector>
25 
26 namespace osgDB {
27 
28 
31 {
32  public:
33 
34  typedef std::vector<std::string> Associates;
35  typedef bool (*ReadFunc)(osg::Object&,osgDB::Input&);
36  typedef bool (*WriteFunc)(const osg::Object&,osgDB::Output&);
37 
39  {
41  READ_ONLY
42  };
43 
44  DotOsgWrapper(osg::Object* proto,
45  const std::string& name,
46  const std::string& associates,
47  ReadFunc readFunc,
48  WriteFunc writeFunc,
49  ReadWriteMode readWriteMode=READ_AND_WRITE);
50 
51 
52  inline const osg::Object* getPrototype() const { return _prototype.get(); }
53  inline const std::string& getName() const { return _name; }
54  inline const Associates& getAssociates() const { return _associates; }
55  inline ReadFunc getReadFunc() const { return _readFunc; }
56  inline WriteFunc getWriteFunc() const { return _writeFunc; }
57  inline ReadWriteMode getReadWriteMode() const { return _readWriteMode; }
58 
59  protected:
60 
63 
65  DotOsgWrapper(DotOsgWrapper&):osg::Referenced() {}
66 
68  virtual ~DotOsgWrapper() {}
69 
71 
72  std::string _name;
73  Associates _associates;
74 
75  ReadFunc _readFunc;
76  WriteFunc _writeFunc;
77 
79 };
80 
81 
84 {
85  public:
86 
88 
89  void addDotOsgWrapper(DotOsgWrapper* wrapper);
90  void removeDotOsgWrapper(DotOsgWrapper* wrapper);
91 
92  osg::Object* readObjectOfType(const osg::Object& compObj,Input& fr);
93  osg::Object* readObjectOfType(const basic_type_wrapper &btw, Input& fr);
94 
95  osg::Object* readObject(Input& fr);
97  osg::Drawable* readDrawable(Input& fr);
98  osg::Uniform* readUniform(Input& fr);
99  osg::StateAttribute* readStateAttribute(Input& fr);
100  osg::Node* readNode(Input& fr);
101  osg::Shader* readShader(Input& fr);
102 
103  bool writeObject(const osg::Object& obj,Output& fw);
104 
105  typedef std::list<std::string> FileNames;
106  bool getLibraryFileNamesToTry(const std::string& name, FileNames& fileNames);
107 
108  private:
109 
110  virtual ~DeprecatedDotOsgWrapperManager() {}
111 
112  typedef std::map< std::string, osg::ref_ptr<DotOsgWrapper> > DotOsgWrapperMap;
113 
114  osg::Object* readObject(DotOsgWrapperMap& dowMap,Input& fr);
115  void eraseWrapper(DotOsgWrapperMap& wrappermap,DotOsgWrapper* wrapper);
116 
117  DotOsgWrapperMap _objectWrapperMap;
118  DotOsgWrapperMap _imageWrapperMap;
119  DotOsgWrapperMap _drawableWrapperMap;
120  DotOsgWrapperMap _stateAttrWrapperMap;
121  DotOsgWrapperMap _uniformWrapperMap;
122  DotOsgWrapperMap _nodeWrapperMap;
123  DotOsgWrapperMap _shaderWrapperMap;
124 
125  DotOsgWrapperMap _classNameWrapperMap;
126 
127 };
128 
129 
132 {
133  public:
134 
136  const std::string& name,
137  const std::string& associates,
138  DotOsgWrapper::ReadFunc readFunc,
139  DotOsgWrapper::WriteFunc writeFunc,
141 
143 
144  protected:
146 };
147 
149 template<class T>
151 {
152  public:
153 
155  const std::string& name,
156  const std::string& associates,
157  DotOsgWrapper::ReadFunc readFunc,
158  DotOsgWrapper::WriteFunc writeFunc,
160  RegisterDotOsgWrapperProxy(proto, name, associates, readFunc, writeFunc, readWriteMode) {}
161 
162 };
163 
164 
165 #define REGISTER_DOTOSGWRAPPER(classname) \
166  extern "C" void dotosgwrapper_##classname(void) {} \
167  static osgDB::RegisterDotOsgWrapperProxy dotosgwrapper_proxy_##classname
168 
169 }
170 
171 #endif
bool(* WriteFunc)(const osg::Object &, osgDB::Output &)
Definition: DotOsgWrapper.h:36
std::vector< std::string > Associates
Definition: DotOsgWrapper.h:34
osg::ref_ptr< osg::Object > _prototype
Definition: DotOsgWrapper.h:70
const std::string & getName() const
Definition: DotOsgWrapper.h:53
ReadWriteMode getReadWriteMode() const
Definition: DotOsgWrapper.h:57
const osg::Object * getPrototype() const
Definition: DotOsgWrapper.h:52
ReadWriteMode _readWriteMode
Definition: DotOsgWrapper.h:78
Associates _associates
Definition: DotOsgWrapper.h:73
DotOsgWrapper()
protected to prevent inappropriate creation of wrappers.
Definition: DotOsgWrapper.h:62
Definition: Archive.h:24
DotOsgWrapper(DotOsgWrapper &)
protected to prevent inappropriate creation of wrappers.
Definition: DotOsgWrapper.h:65
std::list< std::string > FileNames
bool(* ReadFunc)(osg::Object &, osgDB::Input &)
Definition: DotOsgWrapper.h:35
#define OSGDB_EXPORT
Definition: Export.h:39
Definition: Node.h:71
Definition: AlphaFunc.h:19
WriteFunc getWriteFunc() const
Definition: DotOsgWrapper.h:56
ReadFunc getReadFunc() const
Definition: DotOsgWrapper.h:55
TemplateRegisterDotOsgWrapperProxy(osg::Object *proto, const std::string &name, const std::string &associates, DotOsgWrapper::ReadFunc readFunc, DotOsgWrapper::WriteFunc writeFunc, DotOsgWrapper::ReadWriteMode readWriteMode=DotOsgWrapper::READ_AND_WRITE)
virtual ~DotOsgWrapper()
protected to prevent wrapper being created on stack.
Definition: DotOsgWrapper.h:68
const Associates & getAssociates() const
Definition: DotOsgWrapper.h:54
osg::ref_ptr< DotOsgWrapper > _wrapper
void readImage(const osg::Image *image, O &operation)
Definition: ImageUtils.h:59