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