RavEngine
Loading...
Searching...
No Matches
SnXmlReader.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef SN_XML_READER_H
30#define SN_XML_READER_H
31
32#include "foundation/PxSimpleTypes.h"
33#include "extensions/PxRepXSimpleType.h"
34
35namespace physx {
36 namespace Sn { struct XmlNode; }
37
42 {
43 protected:
44 virtual ~XmlReader(){}
45 public:
47 virtual bool read( const char* inName, const char*& outData ) = 0;
49 virtual bool read( const char* inName, PxSerialObjectId& outId ) = 0;
51 virtual bool gotoChild( const char* inName ) = 0;
53 virtual bool gotoFirstChild() = 0;
55 virtual bool gotoNextSibling() = 0;
57 virtual PxU32 countChildren() = 0;
59 virtual const char* getCurrentItemName() = 0;
61 virtual const char* getCurrentItemValue() = 0;
63 virtual bool leaveChild() = 0;
65 virtual XmlReader* getParentReader() = 0;
66
71 virtual void pushCurrentContext() = 0;
73 virtual void popCurrentContext() = 0;
74 };
75
76 //Used when upgrading a repx collection
78 {
79 public:
80 //Clears the stack of nodes (push/pop current node reset)
81 //and sets the current node to inNode.
82 virtual void setNode( Sn::XmlNode& node ) = 0;
83 //If the child exists, add it.
84 //the either way goto that child.
85 virtual void addOrGotoChild( const char* name ) = 0;
86 //Value is copied into the collection, inValue has no further references
87 //to it.
88 virtual void setCurrentItemValue( const char* value ) = 0;
89 //Removes the child but does not release the char* name or char* data ptrs.
90 //Those pointers are never released and are shared among collections.
91 //Thus copying nodes is cheap and safe.
92 virtual bool removeChild( const char* name ) = 0;
93 virtual void release() = 0;
94
95 bool renameProperty( const char* oldName, const char* newName )
96 {
97 if ( gotoChild( oldName ) )
98 {
99 const char* value = getCurrentItemValue();
100 leaveChild();
101 removeChild( oldName );
102 addOrGotoChild( newName );
103 setCurrentItemValue( value );
104 leaveChild();
105 return true;
106 }
107 return false;
108 }
109 bool readAndRemoveProperty( const char* name, const char*& outValue )
110 {
111 bool retval = read( name, outValue );
112 if ( retval ) removeChild( name );
113 return retval;
114 }
115
116 bool writePropertyIfNotEmpty( const char* name, const char* value )
117 {
118 if ( value && *value )
119 {
120 addOrGotoChild( name );
121 setCurrentItemValue( value );
122 leaveChild();
123 return true;
124 }
125 return false;
126 }
127 };
128
129}
130#endif
Definition SnXmlReader.h:78
Definition SnXmlReader.h:42
virtual bool read(const char *inName, PxSerialObjectId &outId)=0
virtual const char * getCurrentItemName()=0
virtual void pushCurrentContext()=0
virtual bool gotoNextSibling()=0
virtual bool read(const char *inName, const char *&outData)=0
virtual const char * getCurrentItemValue()=0
virtual void popCurrentContext()=0
virtual bool leaveChild()=0
virtual XmlReader * getParentReader()=0
virtual bool gotoFirstChild()=0
virtual bool gotoChild(const char *inName)=0
virtual PxU32 countChildren()=0
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU64 PxSerialObjectId
ID type for PxBase objects in a PxCollection.
Definition PxSerialFramework.h:61
Definition SnXmlImpl.h:103