source: trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h @ 313

Revision 313, 7.0 KB checked in by mattausch, 19 years ago (diff)

bsp viewcells now work

Line 
1#ifndef _X3D_PARSER_XERCES__H
2#define _X3D_PARSER_XERCES__H
3
4// ---------------------------------------------------------------------------
5//  Includes
6// ---------------------------------------------------------------------------
7#include <xercesc/sax/HandlerBase.hpp>
8#include "Mesh.h"
9
10XERCES_CPP_NAMESPACE_USE
11XERCES_CPP_NAMESPACE_BEGIN
12class AttributeList;
13XERCES_CPP_NAMESPACE_END
14
15class SceneGraphNode;
16class Mesh;
17class Material;
18
19class X3dParseHandlers : public HandlerBase
20{
21public:
22  // -----------------------------------------------------------------------
23  //  Constructors and Destructor
24  // -----------------------------------------------------------------------
25  X3dParseHandlers(SceneGraphNode *root);
26  ~X3dParseHandlers();
27 
28 
29  // -----------------------------------------------------------------------
30  //  Getter methods
31  // -----------------------------------------------------------------------
32  unsigned int GetElementCount()
33  {
34    return mElementCount;
35  }
36 
37  unsigned int GetAttrCount()
38  {
39    return mAttrCount;
40  }
41 
42  unsigned int GetCharacterCount()
43  {
44    return mCharacterCount;
45  }
46 
47  unsigned int GetSpaceCount()
48  {
49    return mSpaceCount;
50  }
51
52
53  // -----------------------------------------------------------------------
54  //  Handlers for the SAX DocumentHandler interface
55  // -----------------------------------------------------------------------
56  void endElement(const XMLCh* const name);
57  void startElement(const XMLCh* const name, AttributeList& attributes);
58  void characters(const XMLCh* const chars, const unsigned int length);
59  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
60  void resetDocument();
61
62  SceneGraphNode *mCurrentNode;
63  Mesh *mCurrentMesh;
64  Material *mCurrentMaterial;
65 
66  // Handlers for X3D
67  void
68  StartIndexedFaceSet(
69                      AttributeList&  attributes);
70 
71  void
72  EndShape();
73
74  void
75  StartCoordinate(
76                  AttributeList&  attributes);
77
78  void
79  StartMaterial(
80                AttributeList&  attributes);
81 
82 
83  // -----------------------------------------------------------------------
84  //  Handlers for the SAX ErrorHandler interface
85  // -----------------------------------------------------------------------
86  void warning(const SAXParseException& exc);
87  void error(const SAXParseException& exc);
88  void fatalError(const SAXParseException& exc);
89 
90 
91private:
92  // -----------------------------------------------------------------------
93  //  Private data members
94  //
95  //  fAttrCount
96  //  fCharacterCount
97  //  fElementCount
98  //  fSpaceCount
99  //      These are just counters that are run upwards based on the input
100  //      from the document handlers.
101  // -----------------------------------------------------------------------
102  unsigned int    mAttrCount;
103  unsigned int    mCharacterCount;
104  unsigned int    mElementCount;
105  unsigned int    mSpaceCount;
106};
107
108/** Parser handlers for view cell x3d files.
109*/
110class X3dViewCellsParseHandlers : public HandlerBase
111{
112public:
113  // -----------------------------------------------------------------------
114  //  Constructors and Destructor
115  // -----------------------------------------------------------------------
116  X3dViewCellsParseHandlers(ViewCellContainer *mViewCells,
117                                                        float viewCellHeight);
118  ~X3dViewCellsParseHandlers();
119 
120 
121  // -----------------------------------------------------------------------
122  //  Getter methods
123  // -----------------------------------------------------------------------
124  unsigned int GetElementCount()
125  {
126    return mElementCount;
127  }
128 
129  unsigned int GetAttrCount()
130  {
131    return mAttrCount;
132  }
133 
134  unsigned int GetCharacterCount()
135  {
136    return mCharacterCount;
137  }
138 
139  unsigned int GetSpaceCount()
140  {
141    return mSpaceCount;
142  }
143
144
145  // -----------------------------------------------------------------------
146  //  Handlers for the SAX DocumentHandler interface
147  // -----------------------------------------------------------------------
148  void endElement(const XMLCh* const name);
149  void startElement(const XMLCh* const name, AttributeList& attributes);
150  void characters(const XMLCh* const chars, const unsigned int length);
151  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
152  void resetDocument();
153
154  ViewCellContainer *mViewCells;
155  float mViewCellHeight;
156
157  VertexIndexContainer mCurrentVertexIndices;
158
159  // Handlers for X3D
160  void
161  StartIndexedFaceSet(
162                      AttributeList&  attributes);
163 
164  void
165  EndShape();
166
167  void
168  StartCoordinate(
169                  AttributeList&  attributes);
170
171  void
172  StartMaterial(
173                AttributeList&  attributes);
174 
175 
176  // -----------------------------------------------------------------------
177  //  Handlers for the SAX ErrorHandler interface
178  // -----------------------------------------------------------------------
179  void warning(const SAXParseException& exc);
180  void error(const SAXParseException& exc);
181  void fatalError(const SAXParseException& exc);
182 
183 
184private:
185  // -----------------------------------------------------------------------
186  //  Private data members
187  //
188  //  fAttrCount
189  //  fCharacterCount
190  //  fElementCount
191  //  fSpaceCount
192  //      These are just counters that are run upwards based on the input
193  //      from the document handlers.
194  // -----------------------------------------------------------------------
195  unsigned int    mAttrCount;
196  unsigned int    mCharacterCount;
197  unsigned int    mElementCount;
198  unsigned int    mSpaceCount;
199};
200
201
202// ---------------------------------------------------------------------------
203//  This is a simple class that lets us do easy (though not terribly efficient)
204//  trancoding of XMLCh data to local code page for display.
205// ---------------------------------------------------------------------------
206class StrX
207{
208public :
209  // -----------------------------------------------------------------------
210  //  Constructors and Destructor
211  // -----------------------------------------------------------------------
212  StrX(const XMLCh* const toTranscode)
213  {
214    // Call the private transcoding method
215    mLocalForm = XMLString::transcode(toTranscode);
216  }
217 
218  ~StrX()
219  {
220    XMLString::release(&mLocalForm);
221  }
222 
223  // -----------------------------------------------------------------------
224  //  Getter methods
225  // -----------------------------------------------------------------------
226  const char* LocalForm() const
227  {
228    return mLocalForm;
229  }
230 
231private :
232  // -----------------------------------------------------------------------
233  //  Private data members
234  //
235  //  fLocalForm
236  //      This is the local code page form of the string.
237  // -----------------------------------------------------------------------
238  char*   mLocalForm;
239};
240
241inline XERCES_STD_QUALIFIER ostream&
242operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
243{
244  target << toDump.LocalForm();
245  return target;
246}
247
248#endif
Note: See TracBrowser for help on using the repository browser.