root/OpenSceneGraph/trunk/include/osgDB/DotOsgWrapper @ 13041

Revision 13041, 5.7 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
26namespace osgDB {
27
28
29/** deprecated. */
30class OSGDB_EXPORT DotOsgWrapper : public osg::Referenced
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
38        enum ReadWriteMode
39        {
40            READ_AND_WRITE,
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
61        /// protected to prevent inappropriate creation of wrappers.
62        DotOsgWrapper() {}
63
64        /// protected to prevent inappropriate creation of wrappers.
65        DotOsgWrapper(DotOsgWrapper&):osg::Referenced() {}
66
67        /// protected to prevent wrapper being created on stack.
68        virtual ~DotOsgWrapper() {}
69
70        osg::ref_ptr<osg::Object>   _prototype;
71
72        std::string                 _name;
73        Associates                  _associates;
74
75        ReadFunc                    _readFunc;
76        WriteFunc                   _writeFunc;
77
78        ReadWriteMode               _readWriteMode;
79};
80
81
82/** deprecated. */
83class OSGDB_EXPORT DeprecatedDotOsgWrapperManager : public osg::Referenced
84{
85    public:
86
87        DeprecatedDotOsgWrapperManager() {}
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);
96        osg::Image*          readImage(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
130/** deprecated. */
131class OSGDB_EXPORT RegisterDotOsgWrapperProxy
132{
133    public:
134
135        RegisterDotOsgWrapperProxy(osg::Object* proto,
136                                   const std::string& name,
137                                   const std::string& associates,
138                                   DotOsgWrapper::ReadFunc readFunc,
139                                   DotOsgWrapper::WriteFunc writeFunc,
140                                   DotOsgWrapper::ReadWriteMode readWriteMode=DotOsgWrapper::READ_AND_WRITE);
141
142        ~RegisterDotOsgWrapperProxy();
143
144    protected:
145        osg::ref_ptr<DotOsgWrapper> _wrapper;
146};
147
148/** deprecated. */
149template<class T>
150class TemplateRegisterDotOsgWrapperProxy : public RegisterDotOsgWrapperProxy, public T
151{
152    public:
153
154        TemplateRegisterDotOsgWrapperProxy(osg::Object* proto,
155                                   const std::string& name,
156                                   const std::string& associates,
157                                   DotOsgWrapper::ReadFunc readFunc,
158                                   DotOsgWrapper::WriteFunc writeFunc,
159                                   DotOsgWrapper::ReadWriteMode readWriteMode=DotOsgWrapper::READ_AND_WRITE):
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
Note: See TracBrowser for help on using the browser.