This file is indexed.

/usr/include/opencollada/GeneratedSaxParser/GeneratedSaxParserParserTemplateBase.h is in opencollada-dev 0.1.0~20160714.0ec5063+dfsg1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/*
    Copyright (c) 2008-2009 NetAllied Systems GmbH

    This file is part of GeneratedSaxParser.

    Licensed under the MIT Open Source License,
    for details please see LICENSE file or the website
    http://www.opensource.org/licenses/mit-license.php
*/

#ifndef __GENERATEDSAXPARSER_COLLADAPARSERAUTOGENBASE_H__
#define __GENERATEDSAXPARSER_COLLADAPARSERAUTOGENBASE_H__

#include "GeneratedSaxParserPrerequisites.h"
#include "GeneratedSaxParserParser.h"
#include "GeneratedSaxParserStackMemoryManager.h"
#include "GeneratedSaxParserUtils.h"
#include "GeneratedSaxParserParserError.h"


#include <map>
#include <stack>
#include <string.h> // needed for memcpy() and gcc



namespace GeneratedSaxParser
{
	class IErrorHandler;


	class ParserTemplateBase : public Parser
	{
	public:

		static const size_t STACK_SIZE = 1024*1024;

		/** Number of floats that fit into the buffer, used to convert text data to a float array.*/
		static const size_t TYPED_VALUES_BUFFER_SIZE = 1000;

		struct ElementData
		{
			StringHash elementHash;
			StringHash generatedElementHash;
            size_t typeID;
			void* validationData;
		};


        // We cannot use std::stack because we need access to elements somewhere in the middle.
        // deque is the container std::stack uses by default.
		typedef std::deque<ElementData> ElementDataStack;
		typedef std::map<StringHash, const char*> ElementNameMap;

	protected:
		ElementDataStack mElementDataStack;

		StackMemoryManager mStackMemoryManager;

        /** Stack containing validation data only. */
        StackMemoryManager mValidationDataStack;

        /** Indicates if input file shall be validated while parsed. */
        bool mValidate;

        /**
         * Points to begin of object on memory manager stack.
         * @see mStackMemoryManager.
         */
		ParserChar* mLastIncompleteFragmentInCharacterData;

        /**
         * When an object is allocated on mem manager stack and the containing
         * data don't fill out whole object, this pointer points to the end of
         * the data inside the object on stack.
         */
        ParserChar* mEndOfDataInCurrentObjectOnStack;

        ElementNameMap mHashNameMap;

	public:
		ParserTemplateBase(IErrorHandler* errorHandler)
			: Parser(errorHandler),
			mStackMemoryManager(STACK_SIZE),
            mValidationDataStack(STACK_SIZE),
            mValidate(true),
			mLastIncompleteFragmentInCharacterData(0){}
		virtual ~ParserTemplateBase(){};

		/** Returns the element or attribute name that corresponds to @a hash. Null is returned,
		if no corresponding name could be found.*/
		const char* getNameByStringHash(const StringHash& hash)const;

		/** Returns the element of the element in level @a level, where the previous element is level 0. 
		If level is invalid, 0 is returned.*/
		StringHash getElementHash( size_t level = 0 )const;


	protected:
		/** Converts the first string representing a float within a ParserChar buffer with prefixedBuffer
		prefixed to a float and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		float toFloatPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


		/** Converts the first string representing a double within a ParserChar buffer with prefixedBuffer
		prefixed to a double and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		double toDoublePrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


		/** Converts the first string representing a char within a ParserChar buffer with prefixedBuffer
		prefixed to a char and advances the character interpreted to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		sint8 toSint8Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing an unsigned char within a ParserChar buffer with prefixedBuffer
		prefixed to an unsigned char and advances the character char to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		uint8 toUint8Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


		/** Converts the first string representing a short within a ParserChar buffer with prefixedBuffer
		prefixed to a short and advances the character interpreted to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		sint16 toSint16Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing an unsigned short within a ParserChar buffer with prefixedBuffer
		prefixed to an unsigned short and advances the character short to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		uint16 toUint16Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


		/** Converts the first string representing an integer within a ParserChar buffer with prefixedBuffer
		prefixed to an integer and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		sint32 toSint32Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing an unsigned integer within a ParserChar buffer with prefixedBuffer
		prefixed to an unsigned integer and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		uint32 toUint32Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing an integer within a ParserChar buffer with prefixedBuffer
		prefixed to an integer and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		sint64 toSint64Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing an unsigned integer within a ParserChar buffer with prefixedBuffer
		prefixed to an unsigned integer and advances the character pointer to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		uint64 toUint64Prefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);

		/** Converts the first string representing a bool within a ParserChar buffer with prefixedBuffer
		prefixed to a bool and advances the character interpreted to the first position after the last
		interpreted character in buffer. If buffer is set to bufferEnd, the end of the buffer was reached
		during conversion. In this case failed is always set to true.
		@param buffer Pointer to the first character in the buffer. Will be set to the first
		character after the last interpreted.
		@param bufferEnd the first character after the last in the buffer
		@param failed False if conversion succeeded, true on failure.*/
		bool toBoolPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


        /** @see toDataPrefix. */
        ParserString toStringListPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);


        /**
         * Handles remaining stuff from last data-call and converts it to a list of enums.
         * @see toDataPrefix
         */
        template<class EnumType, class BaseType, EnumType EnumMapCount,
            EnumType (*toEnum)(const ParserChar** buffer,
            const ParserChar* bufferEnd,
            bool& failed,
            const std::pair<BaseType, EnumType>* enumMap,
            BaseType (*baseConversionFunctionPtr)(const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed)
            )
        >
        EnumType toEnumDataPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed,
            const std::pair<BaseType, EnumType>* enumMap,
            BaseType (*baseConversionFunctionPtr)(const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed)
            );

        template<class DataType>
        DataType toDataPrefix(
            const ParserChar* prefixedBuffer,
            const ParserChar* prefixedBufferEnd,
            const ParserChar** buffer,
            const ParserChar* bufferEnd,
            bool& failed,
            DataType (*toData)(const ParserChar**, const ParserChar*, bool&)
            );


		/** Creates a new object of type @a DataType and sets the member variables to the default ones, using
		a static member of type @a DataType called DEFAULT. @a data is set to the created object and @a dataPtr
		to the address of the created object.
		@param DataType The type of the object, that should be created. Must have a static member of type @ DataType
		called DEFAULT.
		@param data Will be set to the location of the created object.
		@param dataPtr Will be set to the address of the created object.*/
		template<class DataType>
		DataType* newData(void** dataPtr);


		/** Passes an error with the specified properties to the error handler.
		@param severity The severity of the error.
		@param errorType The error type of the error.
		@param elementHash The hash of the element the error occurred in.
		@param attributeHash The hash of the element the error occurred in.
		@param additionalText Additional text describing the error.
        @return True when abort required, false when continue is possible.
        */
		bool handleError(ParserError::Severity severity,
						 ParserError::ErrorType errorType,
						 StringHash elementHash,
						 StringHash attributeHash,
						 const ParserChar* additionalText);


		/** Passes an error with the specified properties to the error handler. The last opened element
		is passed to the error handler.
		@param severity The severity of the error.
		@param errorType The error type of the error.
		@param attributeHash The hash of the attribute the error occurred in.
		@param additionalText Additional text describing the error.
        @return True when abort required, false when continue is possible.
        */
		bool handleError(ParserError::Severity severity,
        			     ParserError::ErrorType errorType,
			             StringHash attributeHash,
			             const ParserChar* additionalText);

        /** Passes an error with the specified properties to the error handler.
        @param severity The severity of the error.
        @param errorType The error type of the error.
        @param elementHash The hash of the element the error occurred in.
        @param attribute The name of the attribute the error occurred in.
        @param additionalText Additional text describing the error.
        @return True when abort required, false when continue is possible.
        */
        bool handleError( ParserError::Severity severity,
            ParserError::ErrorType errorType,
            StringHash elementHash,
            const ParserChar* attribute,
            const ParserChar* additionalText );


    protected:
    private:
		/** Disable default copy ctor. */
		ParserTemplateBase( const ParserTemplateBase& pre );
		/** Disable default assignment operator. */
		const ParserTemplateBase& operator= ( const ParserTemplateBase& pre );

        template<class DataType,
            DataType (*toData)(const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed)>
            DataType toDataPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed);
	};


    //--------------------------------------------------------------------
	template<class DataType>
	DataType* ParserTemplateBase::newData(void** dataPtr)
	{
		void* mem = mStackMemoryManager.newObject(sizeof(DataType));
		DataType* data = new(mem) DataType(DataType::DEFAULT);
		*dataPtr = data;
		return data;
	}

    //--------------------------------------------------------------------
    template<class EnumType, class BaseType, EnumType EnumMapCount,
        EnumType (*toEnum)(const ParserChar** buffer,
        const ParserChar* bufferEnd,
        bool& failed,
        const std::pair<BaseType, EnumType>* enumMap,
        BaseType (*baseConversionFunctionPtr)(const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed)
        )
    >
    EnumType ParserTemplateBase::toEnumDataPrefix(const ParserChar* prefixedBuffer, const ParserChar* prefixedBufferEnd, const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed,
        const std::pair<BaseType, EnumType>* enumMap,
        BaseType (*baseConversionFunctionPtr)(const ParserChar** buffer, const ParserChar* bufferEnd, bool& failed))
    {
        const ParserChar* prefixBufferPos = prefixedBuffer;
        const ParserChar* prefixBufferStartPos = 0;
        while ( prefixBufferPos != prefixedBufferEnd )
        {
            if (!Utils::isWhiteSpace(*prefixBufferPos ) && !prefixBufferStartPos)
                prefixBufferStartPos = prefixBufferPos;
            ++prefixBufferPos;
        }

        //if prefixedBuffer contains only white spaces, we can ignore it.
        if ( !prefixBufferStartPos )
            return toEnum(buffer, bufferEnd, failed, enumMap, baseConversionFunctionPtr);

        //find first whitespace in buffer
        const ParserChar* bufferPos = *buffer;
        while ( !Utils::isWhiteSpace(*bufferPos) )
            ++bufferPos;

        size_t prefixBufferSize = prefixBufferPos - prefixBufferStartPos;
        size_t bufferSize = bufferPos - *buffer;
        size_t newBufferSize = prefixBufferSize + bufferSize;
        ParserChar* newBuffer =  (ParserChar*)mStackMemoryManager.newObject((newBufferSize + 1)*sizeof(ParserChar));
        memcpy(newBuffer, prefixBufferStartPos, prefixBufferSize*sizeof(ParserChar));
        memcpy(newBuffer + prefixBufferSize, *buffer, bufferSize*sizeof(ParserChar));
        newBuffer[newBufferSize] = ' ';
        ParserChar* newBufferPostParse = newBuffer;
        EnumType value = toEnum( (const ParserChar**)&newBufferPostParse, newBuffer + newBufferSize + 1, failed, enumMap, baseConversionFunctionPtr);
        *buffer += (newBufferPostParse - newBuffer - prefixBufferSize);
        return value;
    }

    //--------------------------------------------------------------------
    template<class DataType,
        DataType (*toData)( const ParserChar**, const ParserChar*, bool& )>
        DataType ParserTemplateBase::toDataPrefix(
        const ParserChar* prefixedBuffer,
        const ParserChar* prefixedBufferEnd,
        const ParserChar** buffer,
        const ParserChar* bufferEnd,
        bool& failed
        )
    {
        const ParserChar* prefixBufferPos = prefixedBuffer;
        const ParserChar* prefixBufferStartPos = 0;
        while ( prefixBufferPos != prefixedBufferEnd )
        {
            if (!Utils::isWhiteSpace(*prefixBufferPos ) && !prefixBufferStartPos)
                prefixBufferStartPos = prefixBufferPos;
            ++prefixBufferPos;
        }

        //if prefixedBuffer contains only white spaces, we can ignore it.
        if ( !prefixBufferStartPos )
            return toData(buffer, bufferEnd, failed);

        //find first whitespace in buffer
        const ParserChar* bufferPos = *buffer;
        while ( !Utils::isWhiteSpace(*bufferPos) && bufferPos < bufferEnd )
            ++bufferPos;

        size_t prefixBufferSize = prefixBufferPos - prefixBufferStartPos;
        size_t bufferSize = bufferPos - *buffer;
        size_t newBufferSize = prefixBufferSize + bufferSize;
        ParserChar* newBuffer =  (ParserChar*)mStackMemoryManager.newObject((newBufferSize + 1)*sizeof(ParserChar));
        memcpy(newBuffer, prefixBufferStartPos, prefixBufferSize*sizeof(ParserChar));
        memcpy(newBuffer + prefixBufferSize, *buffer, bufferSize*sizeof(ParserChar));
        newBuffer[newBufferSize] = ' ';
        ParserChar* newBufferPostParse = newBuffer;
        DataType value = toData( (const ParserChar**)&newBufferPostParse, newBuffer + newBufferSize + 1, failed);
        *buffer += (newBufferPostParse - newBuffer - prefixBufferSize);
        // note: we cannot delete that object here because
        // DataType maybe ParserString and this deleteObject call
        // would delete the string ParserString::str points at.
        //mStackMemoryManager.deleteObject();
        return value;
    }

    //--------------------------------------------------------------------
    template<class DataType>
    DataType ParserTemplateBase::toDataPrefix(
        const ParserChar* prefixedBuffer,
        const ParserChar* prefixedBufferEnd,
        const ParserChar** buffer,
        const ParserChar* bufferEnd,
        bool& failed,
        DataType (*toData)( const ParserChar**, const ParserChar*, bool& )
        )
    {
        const ParserChar* prefixBufferPos = prefixedBuffer;
        const ParserChar* prefixBufferStartPos = 0;
        while ( prefixBufferPos != prefixedBufferEnd )
        {
            if (!Utils::isWhiteSpace(*prefixBufferPos ) && !prefixBufferStartPos)
                prefixBufferStartPos = prefixBufferPos;
            ++prefixBufferPos;
        }

        //if prefixedBuffer contains only white spaces, we can ignore it.
        if ( !prefixBufferStartPos )
            return toData(buffer, bufferEnd, failed);

        //find first whitespace in buffer
        const ParserChar* bufferPos = *buffer;
        while ( !Utils::isWhiteSpace(*bufferPos) )
            ++bufferPos;

        size_t prefixBufferSize = prefixBufferPos - prefixBufferStartPos;
        size_t bufferSize = bufferPos - *buffer;
        size_t newBufferSize = prefixBufferSize + bufferSize;
        ParserChar* newBuffer =  (ParserChar*)mStackMemoryManager.newObject((newBufferSize + 1)*sizeof(ParserChar));
        memcpy(newBuffer, prefixBufferStartPos, prefixBufferSize*sizeof(ParserChar));
        memcpy(newBuffer + prefixBufferSize, *buffer, bufferSize*sizeof(ParserChar));
        newBuffer[newBufferSize] = ' ';
        ParserChar* newBufferPostParse = newBuffer;
        DataType value = toData( (const ParserChar**)&newBufferPostParse, newBuffer + newBufferSize + 1, failed);
        *buffer += (newBufferPostParse - newBuffer - prefixBufferSize);

        // see comment in overloaded method
        //mStackMemoryManager.deleteObject();

        return value;
    }

} // namespace GeneratedSaxParser

#endif // __GENERATEDSAXPARSER_COLLADAPARSERAUTOGENBASE_H__