root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/Object.cpp @ 13041

Revision 13041, 2.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#include "osg/Object"
2#include "osg/Notify"
3
4#include "osgDB/Registry"
5#include "osgDB/Input"
6#include "osgDB/Output"
7
8using namespace osg;
9using namespace osgDB;
10
11// forward declare functions to use later.
12bool Object_readLocalData(Object& obj, Input& fr);
13bool Object_writeLocalData(const Object& obj, Output& fw);
14
15// register the read and write functions with the osgDB::Registry.
16// note, Object doesn't currently require any read and write.
17REGISTER_DOTOSGWRAPPER(Object)
18(
19    /*new osg::Object*/NULL,
20    "Object",
21    "Object",
22    &Object_readLocalData,
23    &Object_writeLocalData
24);
25
26bool Object_readLocalData(Object& obj, Input& fr)
27{
28    bool iteratorAdvanced = false;
29
30    if (fr[0].matchWord("DataVariance"))
31    {
32        if (fr[1].matchWord("DYNAMIC"))
33        {
34            obj.setDataVariance(osg::Object::DYNAMIC);
35            fr +=2 ;
36            iteratorAdvanced = true;
37        }
38        else if (fr[1].matchWord("STATIC"))
39        {
40            obj.setDataVariance(osg::Object::STATIC);
41            fr +=2 ;
42            iteratorAdvanced = true;
43        }
44        else if (fr[1].matchWord("UNSPECIFIED"))
45        {
46            obj.setDataVariance(osg::Object::UNSPECIFIED);
47            fr +=2 ;
48            iteratorAdvanced = true;
49        }
50    }
51
52    if (fr.matchSequence("name %s"))
53    {
54        obj.setName(fr[1].getStr());
55        fr+=2;
56        iteratorAdvanced = true;
57    }
58
59    if (fr.matchSequence("UserData {"))
60    {
61        osg::notify(osg::DEBUG_INFO) << "Matched UserData {"<< std::endl;
62        int entry = fr[0].getNoNestedBrackets();
63        fr += 2;
64
65        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
66        {
67            Object* object = fr.readObject();
68            if (object) obj.setUserData(object);
69            osg::notify(osg::DEBUG_INFO) << "read "<<object<< std::endl;
70            ++fr;
71        }
72        iteratorAdvanced = true;
73    }
74
75    return iteratorAdvanced;
76}
77
78
79bool Object_writeLocalData(const Object& obj, Output& fw)
80{
81    switch(obj.getDataVariance())
82    {
83        case(osg::Object::STATIC):      fw.indent() << "DataVariance STATIC" << std::endl;break;
84        case(osg::Object::DYNAMIC):     fw.indent() << "DataVariance DYNAMIC" << std::endl;break;
85        case(osg::Object::UNSPECIFIED): break; // fw.indent() << "DataVariance UNSPECIFIED" << std::endl;break;
86    }
87
88    if (!obj.getName().empty()) fw.indent() << "name "<<fw.wrapString(obj.getName())<< std::endl;
89
90    if (obj.getUserData())
91    {
92        const Object* object = dynamic_cast<const Object*>(obj.getUserData());
93        if (object)
94        {
95            fw.indent() << "UserData {"<< std::endl;
96            fw.moveIn();
97            fw.writeObject(*object);
98            fw.moveOut();
99            fw.indent() << "}"<< std::endl;
100        }
101    }
102
103    return true;
104}
Note: See TracBrowser for help on using the browser.