[180] | 1 | #ifndef _X3D_PARSER_XERCES__H
|
---|
| 2 | #define _X3D_PARSER_XERCES__H
|
---|
| 3 |
|
---|
| 4 | // ---------------------------------------------------------------------------
|
---|
| 5 | // Includes
|
---|
| 6 | // ---------------------------------------------------------------------------
|
---|
| 7 | #include <xercesc/sax/HandlerBase.hpp>
|
---|
[261] | 8 | #include "Mesh.h"
|
---|
[180] | 9 |
|
---|
| 10 | XERCES_CPP_NAMESPACE_USE
|
---|
| 11 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 12 | class AttributeList;
|
---|
| 13 | XERCES_CPP_NAMESPACE_END
|
---|
| 14 |
|
---|
| 15 | class SceneGraphNode;
|
---|
| 16 | class Mesh;
|
---|
| 17 | class Material;
|
---|
| 18 |
|
---|
| 19 | class X3dParseHandlers : public HandlerBase
|
---|
| 20 | {
|
---|
| 21 | public:
|
---|
| 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 |
|
---|
| 91 | private:
|
---|
| 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 |
|
---|
[260] | 108 | /** Parser handlers for view cell x3d files.
|
---|
| 109 | */
|
---|
| 110 | class X3dViewCellsParseHandlers : public HandlerBase
|
---|
| 111 | {
|
---|
| 112 | public:
|
---|
| 113 | // -----------------------------------------------------------------------
|
---|
| 114 | // Constructors and Destructor
|
---|
| 115 | // -----------------------------------------------------------------------
|
---|
[312] | 116 | X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, float viewCellHeight);
|
---|
[260] | 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 | }
|
---|
[180] | 142 |
|
---|
[260] | 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;
|
---|
[312] | 154 | float mViewCellHeight;
|
---|
| 155 |
|
---|
[261] | 156 | VertexIndexContainer mCurrentVertexIndices;
|
---|
| 157 |
|
---|
[260] | 158 | // Handlers for X3D
|
---|
| 159 | void
|
---|
| 160 | StartIndexedFaceSet(
|
---|
| 161 | AttributeList& attributes);
|
---|
| 162 |
|
---|
| 163 | void
|
---|
| 164 | EndShape();
|
---|
| 165 |
|
---|
| 166 | void
|
---|
| 167 | StartCoordinate(
|
---|
| 168 | AttributeList& attributes);
|
---|
| 169 |
|
---|
| 170 | void
|
---|
| 171 | StartMaterial(
|
---|
| 172 | AttributeList& attributes);
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | // -----------------------------------------------------------------------
|
---|
| 176 | // Handlers for the SAX ErrorHandler interface
|
---|
| 177 | // -----------------------------------------------------------------------
|
---|
| 178 | void warning(const SAXParseException& exc);
|
---|
| 179 | void error(const SAXParseException& exc);
|
---|
| 180 | void fatalError(const SAXParseException& exc);
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | private:
|
---|
| 184 | // -----------------------------------------------------------------------
|
---|
| 185 | // Private data members
|
---|
| 186 | //
|
---|
| 187 | // fAttrCount
|
---|
| 188 | // fCharacterCount
|
---|
| 189 | // fElementCount
|
---|
| 190 | // fSpaceCount
|
---|
| 191 | // These are just counters that are run upwards based on the input
|
---|
| 192 | // from the document handlers.
|
---|
| 193 | // -----------------------------------------------------------------------
|
---|
| 194 | unsigned int mAttrCount;
|
---|
| 195 | unsigned int mCharacterCount;
|
---|
| 196 | unsigned int mElementCount;
|
---|
| 197 | unsigned int mSpaceCount;
|
---|
| 198 | };
|
---|
| 199 |
|
---|
| 200 |
|
---|
[180] | 201 | // ---------------------------------------------------------------------------
|
---|
| 202 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
| 203 | // trancoding of XMLCh data to local code page for display.
|
---|
| 204 | // ---------------------------------------------------------------------------
|
---|
| 205 | class StrX
|
---|
| 206 | {
|
---|
| 207 | public :
|
---|
| 208 | // -----------------------------------------------------------------------
|
---|
| 209 | // Constructors and Destructor
|
---|
| 210 | // -----------------------------------------------------------------------
|
---|
| 211 | StrX(const XMLCh* const toTranscode)
|
---|
| 212 | {
|
---|
| 213 | // Call the private transcoding method
|
---|
| 214 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | ~StrX()
|
---|
| 218 | {
|
---|
| 219 | XMLString::release(&mLocalForm);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | // -----------------------------------------------------------------------
|
---|
| 223 | // Getter methods
|
---|
| 224 | // -----------------------------------------------------------------------
|
---|
| 225 | const char* LocalForm() const
|
---|
| 226 | {
|
---|
| 227 | return mLocalForm;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | private :
|
---|
| 231 | // -----------------------------------------------------------------------
|
---|
| 232 | // Private data members
|
---|
| 233 | //
|
---|
| 234 | // fLocalForm
|
---|
| 235 | // This is the local code page form of the string.
|
---|
| 236 | // -----------------------------------------------------------------------
|
---|
| 237 | char* mLocalForm;
|
---|
| 238 | };
|
---|
| 239 |
|
---|
| 240 | inline XERCES_STD_QUALIFIER ostream&
|
---|
| 241 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
| 242 | {
|
---|
| 243 | target << toDump.LocalForm();
|
---|
| 244 | return target;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | #endif
|
---|