OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

XML serialisation issues / examples


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Mon Jan 15, 2018 11:54 pm    Post subject:
XML serialisation issues / examples
Reply with quote

Hi,

as previously mentioned there are some issues when using serialisation with XML. Here is a small code snippet:
Code:

#define USE_BRACKETS 1
#define USE_USER_SERIALIZER 1

namespace TestOSG
{
   class TestStruct : public osg::Object
   {
   public:
      TestStruct(void)
      {
      }
      TestStruct(TestStruct const& test, osg::CopyOp const& copyOperator=osg::CopyOp::SHALLOW_COPY)
                     :osg::Object(test,copyOperator),
                      m_From(test.m_From), m_Till(test.m_Till)
      {
      }
      
      META_Object(TestOSG,TestStruct);
      
      osg::Vec3 m_From;
      osg::Vec3 m_Till;
      
      osg::Vec3 const& getFrom(void) const {return m_From;}
      osg::Vec3 const& getTill(void) const {return m_Till;}
      
      void setFrom(osg::Vec3 const& from) {m_From = from;}
      void setTill(osg::Vec3 const& till) {m_Till = till;}
   };
}

namespace
{
   bool checkTestSerialization(TestOSG::TestStruct const&)
   {
      return true;
   }

   bool readTestSerialization(osgDB::InputStream& inputStream, TestOSG::TestStruct& testData)
   {
      inputStream >> inputStream.BEGIN_BRACKET;
      inputStream >> inputStream.PROPERTY("From") >> testData.m_From;
      inputStream >> inputStream.PROPERTY("Till") >> testData.m_Till;
      inputStream >> inputStream.END_BRACKET;
      return true;
   }
   
   bool writeTestSerialization(osgDB::OutputStream& outputStream, TestOSG::TestStruct const& testData)
   {
#if (USE_BRACKETS)
      outputStream << outputStream.BEGIN_BRACKET << std::endl;
#endif
      outputStream << outputStream.PROPERTY("From") << testData.m_From << std::endl;
      outputStream << outputStream.PROPERTY("Till") << testData.m_Till << std::endl;
#if (USE_BRACKETS)
      outputStream << outputStream.END_BRACKET << std::endl;
#endif
      return true;
   }
}

#if (USE_USER_SERIALIZER)
REGISTER_OBJECT_WRAPPER(TestStruct,
                                    new TestOSG::TestStruct,
                                    TestOSG::TestStruct,
                                    "osg::Object TestOSG::TestStruct")
{
   ADD_USER_SERIALIZER(TestSerialization);
}
#else
REGISTER_OBJECT_WRAPPER(TestStruct,
                                    new TestOSG::TestStruct,
                                    TestOSG::TestStruct,
                                    "osg::Object TestOSG::TestStruct")
{
   ADD_VEC3_SERIALIZER(From,osg::Vec3(1,0,0));
   ADD_VEC3_SERIALIZER(Till,osg::Vec3(1,0,0));
}
#endif

extern "C" void wrapper_serializer_library_TestOSG(void)
{
}

USE_SERIALIZER_WRAPPER(TestStruct)


The output depends on the flags.

USE_BRACKETS == 1
USE_USER_SERIALIZER == 0 (OK):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< From attribute="0 0 0" />
< Till attribute="0 0 0&nl;&nl;" />
< /UniqueID>
< /TestOSG::TestStruct>

USE_BRACKETS == 1
USE_USER_SERIALIZER == 1 (wrong):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< TestSerialization attribute="&nl;">
< From attribute="0 0 0&nl;">
< Till attribute="0 0 0&nl;&nl;&nl;" />
< /From>
< /TestSerialization>
< /UniqueID>
< /TestOSG::TestStruct>


USE_BRACKETS == 0
USE_USER_SERIALIZER == 1 (wrong):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< TestSerialization />
< From attribute="0 0 0" />
< Till attribute="0 0 0&nl;&nl;" />
< /UniqueID>
< /TestOSG::TestStruct>

PS: I have added the space between "<" and the following xml text because otherwise the output does not show up.

Cheers,
Hartwig[/quote]
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12027

PostPosted: Tue Jan 16, 2018 9:58 am    Post subject:
XML serialisation issues / examples
Reply with quote

Hi Hartwig,

I'm really busy right now so can't look into it. Hopefully I'll be
able to look into later this week.

What versions of the OSG have you tried? Do the ascii and binary
serializers work OK?

Robert.

On 15 January 2018 at 23:54, Hartwig Wiesmann
<> wrote:
Quote:
Hi,

as previously mentioned there are some issues when using serialisation with XML. Here is a small code snippet:

Code:

#define USE_BRACKETS 1
#define USE_USER_SERIALIZER 1

namespace TestOSG
{
class TestStruct : public osg::Object
{
public:
TestStruct(void)
{
}
TestStruct(TestStruct const& test, osg::CopyOp const& copyOperator=osg::CopyOp::SHALLOW_COPY)
:osg::Object(test,copyOperator),
m_From(test.m_From), m_Till(test.m_Till)
{
}

META_Object(TestOSG,TestStruct);

osg::Vec3 m_From;
osg::Vec3 m_Till;

osg::Vec3 const& getFrom(void) const {return m_From;}
osg::Vec3 const& getTill(void) const {return m_Till;}

void setFrom(osg::Vec3 const& from) {m_From = from;}
void setTill(osg::Vec3 const& till) {m_Till = till;}
};
}

namespace
{
bool checkTestSerialization(TestOSG::TestStruct const&)
{
return true;
}

bool readTestSerialization(osgDB::InputStream& inputStream, TestOSG::TestStruct& testData)
{
inputStream >> inputStream.BEGIN_BRACKET;
inputStream >> inputStream.PROPERTY("From") >> testData.m_From;
inputStream >> inputStream.PROPERTY("Till") >> testData.m_Till;
inputStream >> inputStream.END_BRACKET;
return true;
}

bool writeTestSerialization(osgDB::OutputStream& outputStream, TestOSG::TestStruct const& testData)
{
#if (USE_BRACKETS)
outputStream << outputStream.BEGIN_BRACKET << std::endl;
#endif
outputStream << outputStream.PROPERTY("From") << testData.m_From << std::endl;
outputStream << outputStream.PROPERTY("Till") << testData.m_Till << std::endl;
#if (USE_BRACKETS)
outputStream << outputStream.END_BRACKET << std::endl;
#endif
return true;
}
}

#if (USE_USER_SERIALIZER)
REGISTER_OBJECT_WRAPPER(TestStruct,
new TestOSG::TestStruct,
TestOSG::TestStruct,
"osg::Object TestOSG::TestStruct")
{
ADD_USER_SERIALIZER(TestSerialization);
}
#else
REGISTER_OBJECT_WRAPPER(TestStruct,
new TestOSG::TestStruct,
TestOSG::TestStruct,
"osg::Object TestOSG::TestStruct")
{
ADD_VEC3_SERIALIZER(From,osg::Vec3(1,0,0));
ADD_VEC3_SERIALIZER(Till,osg::Vec3(1,0,0));
}
#endif

extern "C" void wrapper_serializer_library_TestOSG(void)
{
}

USE_SERIALIZER_WRAPPER(TestStruct)




The output depends on the flags.

USE_BRACKETS == 1
USE_USER_SERIALIZER == 0 (OK):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< From attribute="0 0 0" />
< Till attribute="0 0 0&nl;&nl;" />
< /UniqueID>
< /TestOSG::TestStruct>

USE_BRACKETS == 1
USE_USER_SERIALIZER == 1 (wrong):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< TestSerialization attribute="&nl;">
< From attribute="0 0 0&nl;">
< Till attribute="0 0 0&nl;&nl;&nl;" />
< /From>
< /TestSerialization>
< /UniqueID>
< /TestOSG::TestStruct>


USE_BRACKETS == 0
USE_USER_SERIALIZER == 1 (wrong):

< ?xml version="1.0" encoding="UTF-8" ?>
< TestOSG::TestStruct>
< UniqueID attribute="1&nl;">
< TestSerialization />
< From attribute="0 0 0" />
< Till attribute="0 0 0&nl;&nl;" />
< /UniqueID>
< /TestOSG::TestStruct>

PS: I have added the space between "<" and the following xml text because otherwise the output does not show up.

Cheers,
Hartwig


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72761#72761






[/quote]

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Tue Jan 16, 2018 6:25 pm    Post subject:
Reply with quote

Hi Robert,

I did the tests using 3.4.2 and had a look at source files of a more recent version (3.5.x) but did not find any real differences.

The ASCII and binary files - according to my experience and usage - seem to be OK.


Cheers,
Hartwig
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Cross-platform examples for Linux, ma... kornerr Announcement [ANN] 0 Tue Aug 14, 2018 10:51 am View latest post
No new posts osgText: two thread-safety issues gwaldron General 1 Tue Jul 31, 2018 2:54 pm View latest post
No new posts Volume rendering issues... tommwilliamson General 4 Wed Jul 25, 2018 12:19 pm View latest post
No new posts Graphics context issues eventhorizon5 General 6 Mon Jul 09, 2018 7:00 am View latest post
No new posts Cross-platform examples for Linux, ma... kornerr Announcement [ANN] 3 Mon Apr 09, 2018 9:36 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP