aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Samples/SampleFramework/framework/include/ODBlock.h
blob: 4f6483bfd1edf5da042c20829690156725132440 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
#ifndef ODBLOCK_H
#define ODBLOCK_H
/*----------------------------------------------------------------------------*\
|
|						     Ageia PhysX Technology
|
|							     www.ageia.com
|
\*----------------------------------------------------------------------------*/

/*
ObjectDescription Scripts
--------------------------
ODScript = Block
Statement = Block | Terminal
Block = indent '{' {Statement} '}'  
Terminal = ident ';'

Comments:
	# = line comment
	/ *  * / = multiline comment.  The / character cannot be used in identifiers.

idents may be enclosed in quotes, and should be unique to facilitate searching.

In a typical application, program would look for known Blocks, and read out its user set terminal(s).
Particular users define semantics:

SHIPFILE 
	{
	Shipname
		{
		Client
			{
			ShipModel
				{
				MeshFile 
					{
					Filename;
					lodlevels;
					}
				Texturefile 
					{
					Filename;
					}
				}
			CockpitModel
				{
				...
				}
			}
		Server
			{
			...
			}
		}
	}
*/
#include <stdio.h>
#include "FrameworkFoundation.h"
#include "SampleArray.h"

#define OD_MAXID 30								//max identifier length
class ODBlock; 
typedef SampleFramework::Array<ODBlock *> ODBlockList;


class ODBlock
/*-------------------------\
| Block = indent '{' {Statement} '}'  
| Terminals are simply empty blocks
|
|
\-------------------------*/
	{
	class ODSyntaxError 
		{
		public:
		enum Error { ODSE_UNEX_QUOTE, ODSE_UNEX_OBRACE, ODSE_UNEX_CBRACE, ODSE_UNEX_LITERAL,ODSE_UNEX_EOF,ODSE_ENC_UNKNOWN };
		private:
		Error err;
		public:
		ODSyntaxError(Error e) {err = e;}
		const char * asString();
		};
	enum State {WAIT_IDENT,IDENT,WAIT_BLOCK,BLOCK};
	char identifier[128];
	unsigned identSize;							//size of above array.
	bool bTerminal;
	ODBlockList subBlocks;	
	ODBlockList::Iterator termiter;				//iterator for reading terminals


	public:
	ODBlock();									//create a new one
	~ODBlock();
	bool loadScript(SampleFramework::File* fp);
	bool saveScript(SampleFramework::File* writeP, bool bQuote);//saves this block to scipt file.  set bQuote == true if you want to machine parse output.

	//reading:
	const char * ident();
	inline unsigned numSubBlocks() {return subBlocks.size(); }//returns number of sub blocks
	bool isTerminal();							//resets to first statement returns false if its a terminal == no contained Blocks
	
	//writing:	
	void ident(const char *);						//identifier of the block
	void addStatement(ODBlock &);

	//queries:  return true in success
	ODBlock * getBlock(const char * identifier,bool bRecursiveSearch=false);	//returns block with given identifier, or NULL.

	void reset();								//prepares to get first terminal or sub block of current block

	//getting terminals:
	bool moreTerminals();						//returns true if more terminals are available
	char * nextTerminal();					//returns a pointer to the next immediate terminal child of current block's identifier string.  

	//getting terminals:
	bool moreSubBlocks();						//returns true if more sub blocks (including terminals) are available
	ODBlock * nextSubBlock();					//returns a pointer to the next sub block.  

	// hig level macro functs, return true on success: (call for obj containing:)
	bool getBlockInt(const char * ident, int* p = 0, unsigned count = 1);	//reads blocks of form:		ident{ 123;}
	bool getBlockU32(const char * ident, physx::PxU32* p = 0, unsigned count = 1);		//reads blocks of form:		ident{ 123;}

	bool getBlockString(const char * ident, const char **);		//of form:				ident{abcdef;}
	bool getBlockStrings(const char * ident, const char **, unsigned  count);		//of form:				ident{abcdef; abcdef; ...}

	bool getBlockFloat(const char * ident, float * p = 0);		//of form:				ident{123.456;}
	bool getBlockFloats(const char * ident, float *, unsigned  count);//form:		ident{12.3; 12.3; 12.3; ... };

	bool addBlockFloats(const char * ident, float *, unsigned  count);
	bool addBlockInts(const char * ident, int *, unsigned  count);

	//errors
	static const char * lastError;
	};


#endif //ODBLOCK_H