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

Revision 261, 6.9 KB checked in by mattausch, 19 years ago (diff)

added viewcell loader

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  ~X3dViewCellsParseHandlers();
118 
119 
120  // -----------------------------------------------------------------------
121  //  Getter methods
122  // -----------------------------------------------------------------------
123  unsigned int GetElementCount()
124  {
125    return mElementCount;
126  }
127 
128  unsigned int GetAttrCount()
129  {
130    return mAttrCount;
131  }
132 
133  unsigned int GetCharacterCount()
134  {
135    return mCharacterCount;
136  }
137 
138  unsigned int GetSpaceCount()
139  {
140    return mSpaceCount;
141  }
142
143
144  // -----------------------------------------------------------------------
145  //  Handlers for the SAX DocumentHandler interface
146  // -----------------------------------------------------------------------
147  void endElement(const XMLCh* const name);
148  void startElement(const XMLCh* const name, AttributeList& attributes);
149  void characters(const XMLCh* const chars, const unsigned int length);
150  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
151  void resetDocument();
152
153  ViewCellContainer *mViewCells;
154  VertexIndexContainer mCurrentVertexIndices;
155
156  // Handlers for X3D
157  void
158  StartIndexedFaceSet(
159                      AttributeList&  attributes);
160 
161  void
162  EndShape();
163
164  void
165  StartCoordinate(
166                  AttributeList&  attributes);
167
168  void
169  StartMaterial(
170                AttributeList&  attributes);
171 
172 
173  // -----------------------------------------------------------------------
174  //  Handlers for the SAX ErrorHandler interface
175  // -----------------------------------------------------------------------
176  void warning(const SAXParseException& exc);
177  void error(const SAXParseException& exc);
178  void fatalError(const SAXParseException& exc);
179 
180 
181private:
182  // -----------------------------------------------------------------------
183  //  Private data members
184  //
185  //  fAttrCount
186  //  fCharacterCount
187  //  fElementCount
188  //  fSpaceCount
189  //      These are just counters that are run upwards based on the input
190  //      from the document handlers.
191  // -----------------------------------------------------------------------
192  unsigned int    mAttrCount;
193  unsigned int    mCharacterCount;
194  unsigned int    mElementCount;
195  unsigned int    mSpaceCount;
196};
197
198
199// ---------------------------------------------------------------------------
200//  This is a simple class that lets us do easy (though not terribly efficient)
201//  trancoding of XMLCh data to local code page for display.
202// ---------------------------------------------------------------------------
203class StrX
204{
205public :
206  // -----------------------------------------------------------------------
207  //  Constructors and Destructor
208  // -----------------------------------------------------------------------
209  StrX(const XMLCh* const toTranscode)
210  {
211    // Call the private transcoding method
212    mLocalForm = XMLString::transcode(toTranscode);
213  }
214 
215  ~StrX()
216  {
217    XMLString::release(&mLocalForm);
218  }
219 
220  // -----------------------------------------------------------------------
221  //  Getter methods
222  // -----------------------------------------------------------------------
223  const char* LocalForm() const
224  {
225    return mLocalForm;
226  }
227 
228private :
229  // -----------------------------------------------------------------------
230  //  Private data members
231  //
232  //  fLocalForm
233  //      This is the local code page form of the string.
234  // -----------------------------------------------------------------------
235  char*   mLocalForm;
236};
237
238inline XERCES_STD_QUALIFIER ostream&
239operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
240{
241  target << toDump.LocalForm();
242  return target;
243}
244
245#endif
Note: See TracBrowser for help on using the repository browser.