summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/assimp/contrib')
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcAdjacencyInfo.h155
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.cpp865
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.h339
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcBinaryStream.h433
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcCommon.h412
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDVEncodeParams.h62
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVector.h84
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.cpp278
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.h76
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp295
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.h79
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcFIFO.h97
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.h263
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.inl47
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.h111
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.inl850
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncodeParams.h140
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.h116
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.inl927
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTimer.h134
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTools.cpp22
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.cpp475
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.h291
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.h133
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.inl364
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.h101
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.inl719
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.h184
-rw-r--r--src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.inl317
-rw-r--r--src/3rdparty/assimp/contrib/clipper/License.txt29
-rw-r--r--src/3rdparty/assimp/contrib/clipper/clipper.cpp3451
-rw-r--r--src/3rdparty/assimp/contrib/clipper/clipper.hpp306
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/CXMLReaderImpl.h809
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/heapsort.h73
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/irrArray.h444
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/irrString.h664
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/irrTypes.h108
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/irrXML.cpp151
-rw-r--r--src/3rdparty/assimp/contrib/irrXML/irrXML.h540
-rw-r--r--src/3rdparty/assimp/contrib/irrXML_note.txt6
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/CMakeLists.txt170
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/CREDITS19
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/LICENSE22
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/README.md136
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/DDLNode.cpp217
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp212
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp384
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp1025
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp96
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/code/Value.cpp439
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/DDLNode.h173
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h246
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLExport.h80
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParser.h201
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h282
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLStream.h89
-rw-r--r--src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/Value.h273
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/AUTHORS8
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/LICENSE27
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/README51
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.cc365
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.h327
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h127
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/poly2tri.h38
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.cc108
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.h118
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.cc71
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.h105
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.cc799
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.h285
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.cc211
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.h186
-rw-r--r--src/3rdparty/assimp/contrib/poly2tri_patch.txt75
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/allocators.h271
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/document.h2613
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodedstream.h299
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodings.h716
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/en.h74
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/error.h161
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filereadstream.h99
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filewritestream.h104
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/fwd.h151
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/biginteger.h290
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/diyfp.h258
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/dtoa.h245
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/ieee754.h78
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/itoa.h304
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/meta.h181
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/pow10.h55
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/regex.h734
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h231
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strfunc.h69
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strtod.h269
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/swap.h46
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/istreamwrapper.h115
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorybuffer.h70
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorystream.h71
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/inttypes.h316
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/stdint.h300
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/ostreamwrapper.h81
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/pointer.h1358
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/prettywriter.h277
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/rapidjson.h628
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/reader.h2221
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/schema.h2016
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stream.h179
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stringbuffer.h121
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/writer.h711
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/license.txt57
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/readme.md160
-rw-r--r--src/3rdparty/assimp/contrib/unzip/crypt.h132
-rw-r--r--src/3rdparty/assimp/contrib/unzip/ioapi.c177
-rw-r--r--src/3rdparty/assimp/contrib/unzip/ioapi.h75
-rw-r--r--src/3rdparty/assimp/contrib/unzip/unzip.c1611
-rw-r--r--src/3rdparty/assimp/contrib/unzip/unzip.h354
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/doc/ReleaseNotes12
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/doc/utf8cpp.html1789
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/source/utf8.h34
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/source/utf8/checked.h327
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/source/utf8/core.h329
-rw-r--r--src/3rdparty/assimp/contrib/utf8cpp/source/utf8/unchecked.h228
-rw-r--r--src/3rdparty/assimp/contrib/zip/README.md139
-rw-r--r--src/3rdparty/assimp/contrib/zip/UNLICENSE26
-rw-r--r--src/3rdparty/assimp/contrib/zip/src/miniz.h4928
-rw-r--r--src/3rdparty/assimp/contrib/zip/src/zip.c640
-rw-r--r--src/3rdparty/assimp/contrib/zip/src/zip.h193
126 files changed, 0 insertions, 48838 deletions
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcAdjacencyInfo.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcAdjacencyInfo.h
deleted file mode 100644
index 72fe3d4c6..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcAdjacencyInfo.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_ADJACENCY_INFO_H
-#define O3DGC_ADJACENCY_INFO_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- const long O3DGC_MIN_NEIGHBORS_SIZE = 128;
- const long O3DGC_MIN_NUM_NEIGHBORS_SIZE = 16;
- //!
- class AdjacencyInfo
- {
- public:
- //! Constructor.
- AdjacencyInfo(long numNeighborsSize = O3DGC_MIN_NUM_NEIGHBORS_SIZE,
- long neighborsSize = O3DGC_MIN_NUM_NEIGHBORS_SIZE)
- {
- m_numElements = 0;
- m_neighborsSize = neighborsSize;
- m_numNeighborsSize = numNeighborsSize;
- m_numNeighbors = new long [m_numNeighborsSize];
- m_neighbors = new long [m_neighborsSize ];
- };
- //! Destructor.
- ~AdjacencyInfo(void)
- {
- delete [] m_neighbors;
- delete [] m_numNeighbors;
- };
- O3DGCErrorCode Allocate(long numNeighborsSize, long neighborsSize)
- {
- m_numElements = numNeighborsSize;
- if (neighborsSize > m_neighborsSize)
- {
- delete [] m_numNeighbors;
- m_neighborsSize = neighborsSize;
- m_numNeighbors = new long [m_numNeighborsSize];
- }
- if (numNeighborsSize > m_numNeighborsSize)
- {
- delete [] m_neighbors;
- m_numNeighborsSize = numNeighborsSize;
- m_neighbors = new long [m_neighborsSize];
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode AllocateNumNeighborsArray(long numElements)
- {
- if (numElements > m_numNeighborsSize)
- {
- delete [] m_numNeighbors;
- m_numNeighborsSize = numElements;
- m_numNeighbors = new long [m_numNeighborsSize];
- }
- m_numElements = numElements;
- return O3DGC_OK;
- }
- O3DGCErrorCode AllocateNeighborsArray()
- {
- for(long i = 1; i < m_numElements; ++i)
- {
- m_numNeighbors[i] += m_numNeighbors[i-1];
- }
- if (m_numNeighbors[m_numElements-1] > m_neighborsSize)
- {
- delete [] m_neighbors;
- m_neighborsSize = m_numNeighbors[m_numElements-1];
- m_neighbors = new long [m_neighborsSize];
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode ClearNumNeighborsArray()
- {
- memset(m_numNeighbors, 0x00, sizeof(long) * m_numElements);
- return O3DGC_OK;
- }
- O3DGCErrorCode ClearNeighborsArray()
- {
- memset(m_neighbors, 0xFF, sizeof(long) * m_neighborsSize);
- return O3DGC_OK;
- }
- O3DGCErrorCode AddNeighbor(long element, long neighbor)
- {
- assert(m_numNeighbors[element] <= m_numNeighbors[m_numElements-1]);
- long p0 = Begin(element);
- long p1 = End(element);
- for(long p = p0; p < p1; p++)
- {
- if (m_neighbors[p] == -1)
- {
- m_neighbors[p] = neighbor;
- return O3DGC_OK;
- }
- }
- return O3DGC_ERROR_BUFFER_FULL;
- }
- long Begin(long element) const
- {
- assert(element < m_numElements);
- assert(element >= 0);
- return (element>0)?m_numNeighbors[element-1]:0;
- }
- long End(long element) const
- {
- assert(element < m_numElements);
- assert(element >= 0);
- return m_numNeighbors[element];
- }
- long GetNeighbor(long element) const
- {
- assert(element < m_neighborsSize);
- assert(element >= 0);
- return m_neighbors[element];
- }
- long GetNumNeighbors(long element) const
- {
- return End(element) - Begin(element);
- }
- long * GetNumNeighborsBuffer() { return m_numNeighbors;}
- long * GetNeighborsBuffer() { return m_neighbors;}
-
- private:
- long m_neighborsSize; // actual allocated size for m_neighbors
- long m_numNeighborsSize; // actual allocated size for m_numNeighbors
- long m_numElements; // number of elements
- long * m_neighbors; //
- long * m_numNeighbors; //
- };
-}
-#endif // O3DGC_ADJACENCY_INFO_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.cpp b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.cpp
deleted file mode 100644
index 3597ec39a..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.cpp
+++ /dev/null
@@ -1,865 +0,0 @@
-/*
-Copyright (c) 2004 Amir Said (said@ieee.org) & William A. Pearlman (pearlw@ecse.rpi.edu)
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-- Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
-
-- Redistributions in binary form must reproduce the above copyright notice, this list of
- conditions and the following disclaimer in the documentation and/or other materials
- provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
-IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
-OF SUCH DAMAGE.
-
-*/
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// **************************** -
-// ARITHMETIC CODING EXAMPLES -
-// **************************** -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// Fast arithmetic coding implementation -
-// -> 32-bit variables, 32-bit product, periodic updates, table decoding -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// Version 1.00 - April 25, 2004 -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// WARNING -
-// ========= -
-// -
-// The only purpose of this program is to demonstrate the basic principles -
-// of arithmetic coding. It is provided as is, without any express or -
-// implied warranty, without even the warranty of fitness for any particular -
-// purpose, or that the implementations are correct. -
-// -
-// Permission to copy and redistribute this code is hereby granted, provided -
-// that this warning and copyright notices are not removed or altered. -
-// -
-// Copyright (c) 2004 by Amir Said (said@ieee.org) & -
-// William A. Pearlman (pearlw@ecse.rpi.edu) -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// A description of the arithmetic coding method used here is available in -
-// -
-// Lossless Compression Handbook, ed. K. Sayood -
-// Chapter 5: Arithmetic Coding (A. Said), pp. 101-152, Academic Press, 2003 -
-// -
-// A. Said, Introduction to Arithetic Coding Theory and Practice -
-// HP Labs report HPL-2004-76 - http://www.hpl.hp.com/techreports/ -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-// - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-#include <stdlib.h>
-#include "o3dgcArithmeticCodec.h"
-
-namespace o3dgc
-{
- // - - Constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- const unsigned AC__MinLength = 0x01000000U; // threshold for renormalization
- const unsigned AC__MaxLength = 0xFFFFFFFFU; // maximum AC interval length
-
- // Maximum values for binary models
- const unsigned BM__LengthShift = 13; // length bits discarded before mult.
- const unsigned BM__MaxCount = 1 << BM__LengthShift; // for adaptive models
-
- // Maximum values for general models
- const unsigned DM__LengthShift = 15; // length bits discarded before mult.
- const unsigned DM__MaxCount = 1 << DM__LengthShift; // for adaptive models
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Static functions - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- static void AC_Error(const char * msg)
- {
- fprintf(stderr, "\n\n -> Arithmetic coding error: ");
- fputs(msg, stderr);
- fputs("\n Execution terminated!\n", stderr);
- getchar();
- exit(1);
- }
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Coding implementations - - - - - - - - - - - - - - - - - - - - - - - -
-
- inline void Arithmetic_Codec::propagate_carry(void)
- {
- unsigned char * p; // carry propagation on compressed data buffer
- for (p = ac_pointer - 1; *p == 0xFFU; p--) *p = 0;
- ++*p;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- inline void Arithmetic_Codec::renorm_enc_interval(void)
- {
- do { // output and discard top byte
- *ac_pointer++ = (unsigned char)(base >> 24);
- base <<= 8;
- } while ((length <<= 8) < AC__MinLength); // length multiplied by 256
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- inline void Arithmetic_Codec::renorm_dec_interval(void)
- {
- do { // read least-significant byte
- value = (value << 8) | unsigned(*++ac_pointer);
- } while ((length <<= 8) < AC__MinLength); // length multiplied by 256
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::put_bit(unsigned bit)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- #endif
-
- length >>= 1; // halve interval
- if (bit) {
- unsigned init_base = base;
- base += length; // move base
- if (init_base > base) propagate_carry(); // overflow = carry
- }
-
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::get_bit(void)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- #endif
-
- length >>= 1; // halve interval
- unsigned bit = (value >= length); // decode bit
- if (bit) value -= length; // move base
-
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- return bit; // return data bit value
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::put_bits(unsigned data, unsigned bits)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- if ((bits < 1) || (bits > 20)) AC_Error("invalid number of bits");
- if (data >= (1U << bits)) AC_Error("invalid data");
- #endif
-
- unsigned init_base = base;
- base += data * (length >>= bits); // new interval base and length
-
- if (init_base > base) propagate_carry(); // overflow = carry
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::get_bits(unsigned bits)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- if ((bits < 1) || (bits > 20)) AC_Error("invalid number of bits");
- #endif
-
- unsigned s = value / (length >>= bits); // decode symbol, change length
-
- value -= length * s; // update interval
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- return s;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::encode(unsigned bit,
- Static_Bit_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- #endif
-
- unsigned x = M.bit_0_prob * (length >> BM__LengthShift); // product l x p0
- // update interval
- if (bit == 0)
- length = x;
- else {
- unsigned init_base = base;
- base += x;
- length -= x;
- if (init_base > base) propagate_carry(); // overflow = carry
- }
-
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::decode(Static_Bit_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- #endif
-
- unsigned x = M.bit_0_prob * (length >> BM__LengthShift); // product l x p0
- unsigned bit = (value >= x); // decision
- // update & shift interval
- if (bit == 0)
- length = x;
- else {
- value -= x; // shifted interval base = 0
- length -= x;
- }
-
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- return bit; // return data bit value
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::encode(unsigned bit,
- Adaptive_Bit_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- #endif
-
- unsigned x = M.bit_0_prob * (length >> BM__LengthShift); // product l x p0
- // update interval
- if (bit == 0) {
- length = x;
- ++M.bit_0_count;
- }
- else {
- unsigned init_base = base;
- base += x;
- length -= x;
- if (init_base > base) propagate_carry(); // overflow = carry
- }
-
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
-
- if (--M.bits_until_update == 0) M.update(); // periodic model update
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::decode(Adaptive_Bit_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- #endif
-
- unsigned x = M.bit_0_prob * (length >> BM__LengthShift); // product l x p0
- unsigned bit = (value >= x); // decision
- // update interval
- if (bit == 0) {
- length = x;
- ++M.bit_0_count;
- }
- else {
- value -= x;
- length -= x;
- }
-
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- if (--M.bits_until_update == 0) M.update(); // periodic model update
-
- return bit; // return data bit value
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::encode(unsigned data,
- Static_Data_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- if (data >= M.data_symbols) AC_Error("invalid data symbol");
- #endif
-
- unsigned x, init_base = base;
- // compute products
- if (data == M.last_symbol) {
- x = M.distribution[data] * (length >> DM__LengthShift);
- base += x; // update interval
- length -= x; // no product needed
- }
- else {
- x = M.distribution[data] * (length >>= DM__LengthShift);
- base += x; // update interval
- length = M.distribution[data+1] * length - x;
- }
-
- if (init_base > base) propagate_carry(); // overflow = carry
-
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::decode(Static_Data_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- #endif
-
- unsigned n, s, x, y = length;
-
- if (M.decoder_table) { // use table look-up for faster decoding
-
- unsigned dv = value / (length >>= DM__LengthShift);
- unsigned t = dv >> M.table_shift;
-
- s = M.decoder_table[t]; // initial decision based on table look-up
- n = M.decoder_table[t+1] + 1;
-
- while (n > s + 1) { // finish with bisection search
- unsigned m = (s + n) >> 1;
- if (M.distribution[m] > dv) n = m; else s = m;
- }
- // compute products
- x = M.distribution[s] * length;
- if (s != M.last_symbol) y = M.distribution[s+1] * length;
- }
-
- else { // decode using only multiplications
-
- x = s = 0;
- length >>= DM__LengthShift;
- unsigned m = (n = M.data_symbols) >> 1;
- // decode via bisection search
- do {
- unsigned z = length * M.distribution[m];
- if (z > value) {
- n = m;
- y = z; // value is smaller
- }
- else {
- s = m;
- x = z; // value is larger or equal
- }
- } while ((m = (s + n) >> 1) != s);
- }
-
- value -= x; // update interval
- length = y - x;
-
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- return s;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::encode(unsigned data,
- Adaptive_Data_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 1) AC_Error("encoder not initialized");
- if (data >= M.data_symbols)
- {
- AC_Error("invalid data symbol");
- }
- #endif
-
- unsigned x, init_base = base;
- // compute products
- if (data == M.last_symbol) {
- x = M.distribution[data] * (length >> DM__LengthShift);
- base += x; // update interval
- length -= x; // no product needed
- }
- else {
- x = M.distribution[data] * (length >>= DM__LengthShift);
- base += x; // update interval
- length = M.distribution[data+1] * length - x;
- }
-
- if (init_base > base) propagate_carry(); // overflow = carry
-
- if (length < AC__MinLength) renorm_enc_interval(); // renormalization
-
- ++M.symbol_count[data];
- if (--M.symbols_until_update == 0) M.update(true); // periodic model update
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::decode(Adaptive_Data_Model & M)
- {
- #ifdef _DEBUG
- if (mode != 2) AC_Error("decoder not initialized");
- #endif
-
- unsigned n, s, x, y = length;
-
- if (M.decoder_table) { // use table look-up for faster decoding
-
- unsigned dv = value / (length >>= DM__LengthShift);
- unsigned t = dv >> M.table_shift;
-
- s = M.decoder_table[t]; // initial decision based on table look-up
- n = M.decoder_table[t+1] + 1;
-
- while (n > s + 1) { // finish with bisection search
- unsigned m = (s + n) >> 1;
- if (M.distribution[m] > dv) n = m; else s = m;
- }
- // compute products
- x = M.distribution[s] * length;
- if (s != M.last_symbol) {
- y = M.distribution[s+1] * length;
- }
- }
-
- else { // decode using only multiplications
-
- x = s = 0;
- length >>= DM__LengthShift;
- unsigned m = (n = M.data_symbols) >> 1;
- // decode via bisection search
- do {
- unsigned z = length * M.distribution[m];
- if (z > value) {
- n = m;
- y = z; // value is smaller
- }
- else {
- s = m;
- x = z; // value is larger or equal
- }
- } while ((m = (s + n) >> 1) != s);
- }
-
- value -= x; // update interval
- length = y - x;
-
- if (length < AC__MinLength) renorm_dec_interval(); // renormalization
-
- ++M.symbol_count[s];
- if (--M.symbols_until_update == 0) M.update(false); // periodic model update
-
- return s;
- }
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Other Arithmetic_Codec implementations - - - - - - - - - - - - - - - -
-
- Arithmetic_Codec::Arithmetic_Codec(void)
- {
- mode = buffer_size = 0;
- new_buffer = code_buffer = 0;
- }
-
- Arithmetic_Codec::Arithmetic_Codec(unsigned max_code_bytes,
- unsigned char * user_buffer)
- {
- mode = buffer_size = 0;
- new_buffer = code_buffer = 0;
- set_buffer(max_code_bytes, user_buffer);
- }
-
- Arithmetic_Codec::~Arithmetic_Codec(void)
- {
- delete [] new_buffer;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::set_buffer(unsigned max_code_bytes,
- unsigned char * user_buffer)
- {
- // test for reasonable sizes
- if (!max_code_bytes)// || (max_code_bytes > 0x10000000U)) // updated by K. Mammou
- {
- AC_Error("invalid codec buffer size");
- }
- if (mode != 0) AC_Error("cannot set buffer while encoding or decoding");
-
- if (user_buffer != 0) { // user provides memory buffer
- buffer_size = max_code_bytes;
- code_buffer = user_buffer; // set buffer for compressed data
- delete [] new_buffer; // free anything previously assigned
- new_buffer = 0;
- return;
- }
-
- if (max_code_bytes <= buffer_size) return; // enough available
-
- buffer_size = max_code_bytes; // assign new memory
- delete [] new_buffer; // free anything previously assigned
- if ((new_buffer = new unsigned char[buffer_size+16]) == 0) // 16 extra bytes
- AC_Error("cannot assign memory for compressed data buffer");
- code_buffer = new_buffer; // set buffer for compressed data
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::start_encoder(void)
- {
- if (mode != 0) AC_Error("cannot start encoder");
- if (buffer_size == 0) AC_Error("no code buffer set");
-
- mode = 1;
- base = 0; // initialize encoder variables: interval and pointer
- length = AC__MaxLength;
- ac_pointer = code_buffer; // pointer to next data byte
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::start_decoder(void)
- {
- if (mode != 0) AC_Error("cannot start decoder");
- if (buffer_size == 0) AC_Error("no code buffer set");
-
- // initialize decoder: interval, pointer, initial code value
- mode = 2;
- length = AC__MaxLength;
- ac_pointer = code_buffer + 3;
- value = (unsigned(code_buffer[0]) << 24)|(unsigned(code_buffer[1]) << 16) |
- (unsigned(code_buffer[2]) << 8)| unsigned(code_buffer[3]);
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::read_from_file(FILE * code_file)
- {
- unsigned shift = 0, code_bytes = 0;
- int file_byte;
- // read variable-length header with number of code bytes
- do {
- if ((file_byte = getc(code_file)) == EOF)
- AC_Error("cannot read code from file");
- code_bytes |= unsigned(file_byte & 0x7F) << shift;
- shift += 7;
- } while (file_byte & 0x80);
- // read compressed data
- if (code_bytes > buffer_size) AC_Error("code buffer overflow");
- if (fread(code_buffer, 1, code_bytes, code_file) != code_bytes)
- AC_Error("cannot read code from file");
-
- start_decoder(); // initialize decoder
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::stop_encoder(void)
- {
- if (mode != 1) AC_Error("invalid to stop encoder");
- mode = 0;
-
- unsigned init_base = base; // done encoding: set final data bytes
-
- if (length > 2 * AC__MinLength) {
- base += AC__MinLength; // base offset
- length = AC__MinLength >> 1; // set new length for 1 more byte
- }
- else {
- base += AC__MinLength >> 1; // base offset
- length = AC__MinLength >> 9; // set new length for 2 more bytes
- }
-
- if (init_base > base) propagate_carry(); // overflow = carry
-
- renorm_enc_interval(); // renormalization = output last bytes
-
- unsigned code_bytes = unsigned(ac_pointer - code_buffer);
- if (code_bytes > buffer_size) AC_Error("code buffer overflow");
-
- return code_bytes; // number of bytes used
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- unsigned Arithmetic_Codec::write_to_file(FILE * code_file)
- {
- unsigned header_bytes = 0, code_bytes = stop_encoder(), nb = code_bytes;
-
- // write variable-length header with number of code bytes
- do {
- int file_byte = int(nb & 0x7FU);
- if ((nb >>= 7) > 0) file_byte |= 0x80;
- if (putc(file_byte, code_file) == EOF)
- AC_Error("cannot write compressed data to file");
- header_bytes++;
- } while (nb);
- // write compressed data
- if (fwrite(code_buffer, 1, code_bytes, code_file) != code_bytes)
- AC_Error("cannot write compressed data to file");
-
- return code_bytes + header_bytes; // bytes used
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Arithmetic_Codec::stop_decoder(void)
- {
- if (mode != 2) AC_Error("invalid to stop decoder");
- mode = 0;
- }
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - Static bit model implementation - - - - - - - - - - - - - - - - - - - - -
-
- Static_Bit_Model::Static_Bit_Model(void)
- {
- bit_0_prob = 1U << (BM__LengthShift - 1); // p0 = 0.5
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Static_Bit_Model::set_probability_0(double p0)
- {
- if ((p0 < 0.0001)||(p0 > 0.9999)) AC_Error("invalid bit probability");
- bit_0_prob = unsigned(p0 * (1 << BM__LengthShift));
- }
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - Adaptive bit model implementation - - - - - - - - - - - - - - - - - - - -
-
- Adaptive_Bit_Model::Adaptive_Bit_Model(void)
- {
- reset();
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Adaptive_Bit_Model::reset(void)
- {
- // initialization to equiprobable model
- bit_0_count = 1;
- bit_count = 2;
- bit_0_prob = 1U << (BM__LengthShift - 1);
- update_cycle = bits_until_update = 4; // start with frequent updates
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Adaptive_Bit_Model::update(void)
- {
- // halve counts when a threshold is reached
-
- if ((bit_count += update_cycle) > BM__MaxCount) {
- bit_count = (bit_count + 1) >> 1;
- bit_0_count = (bit_0_count + 1) >> 1;
- if (bit_0_count == bit_count) ++bit_count;
- }
- // compute scaled bit 0 probability
- unsigned scale = 0x80000000U / bit_count;
- bit_0_prob = (bit_0_count * scale) >> (31 - BM__LengthShift);
-
- // set frequency of model updates
- update_cycle = (5 * update_cycle) >> 2;
- if (update_cycle > 64) update_cycle = 64;
- bits_until_update = update_cycle;
- }
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Static data model implementation - - - - - - - - - - - - - - - - - - -
-
- Static_Data_Model::Static_Data_Model(void)
- {
- data_symbols = 0;
- distribution = 0;
- }
-
- Static_Data_Model::~Static_Data_Model(void)
- {
- delete [] distribution;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Static_Data_Model::set_distribution(unsigned number_of_symbols,
- const double probability[])
- {
- if ((number_of_symbols < 2) || (number_of_symbols > (1 << 11)))
- AC_Error("invalid number of data symbols");
-
- if (data_symbols != number_of_symbols) { // assign memory for data model
- data_symbols = number_of_symbols;
- last_symbol = data_symbols - 1;
- delete [] distribution;
- // define size of table for fast decoding
- if (data_symbols > 16) {
- unsigned table_bits = 3;
- while (data_symbols > (1U << (table_bits + 2))) ++table_bits;
- table_size = 1 << table_bits;
- table_shift = DM__LengthShift - table_bits;
- distribution = new unsigned[data_symbols+table_size+2];
- decoder_table = distribution + data_symbols;
- }
- else { // small alphabet: no table needed
- decoder_table = 0;
- table_size = table_shift = 0;
- distribution = new unsigned[data_symbols];
- }
- if (distribution == 0) AC_Error("cannot assign model memory");
- }
- // compute cumulative distribution, decoder table
- unsigned s = 0;
- double sum = 0.0, p = 1.0 / double(data_symbols);
-
- for (unsigned k = 0; k < data_symbols; k++) {
- if (probability) p = probability[k];
- if ((p < 0.0001) || (p > 0.9999)) AC_Error("invalid symbol probability");
- distribution[k] = unsigned(sum * (1 << DM__LengthShift));
- sum += p;
- if (table_size == 0) continue;
- unsigned w = distribution[k] >> table_shift;
- while (s < w) decoder_table[++s] = k - 1;
- }
-
- if (table_size != 0) {
- decoder_table[0] = 0;
- while (s <= table_size) decoder_table[++s] = data_symbols - 1;
- }
-
- if ((sum < 0.9999) || (sum > 1.0001)) AC_Error("invalid probabilities");
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Adaptive data model implementation - - - - - - - - - - - - - - - - - -
-
- Adaptive_Data_Model::Adaptive_Data_Model(void)
- {
- data_symbols = 0;
- distribution = 0;
- }
-
- Adaptive_Data_Model::Adaptive_Data_Model(unsigned number_of_symbols)
- {
- data_symbols = 0;
- distribution = 0;
- set_alphabet(number_of_symbols);
- }
-
- Adaptive_Data_Model::~Adaptive_Data_Model(void)
- {
- delete [] distribution;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Adaptive_Data_Model::set_alphabet(unsigned number_of_symbols)
- {
- if ((number_of_symbols < 2) || (number_of_symbols > (1 << 11)))
- AC_Error("invalid number of data symbols");
-
- if (data_symbols != number_of_symbols) { // assign memory for data model
- data_symbols = number_of_symbols;
- last_symbol = data_symbols - 1;
- delete [] distribution;
- // define size of table for fast decoding
- if (data_symbols > 16) {
- unsigned table_bits = 3;
- while (data_symbols > (1U << (table_bits + 2))) ++table_bits;
- table_size = 1 << table_bits;
- table_shift = DM__LengthShift - table_bits;
- distribution = new unsigned[2*data_symbols+table_size+2];
- decoder_table = distribution + 2 * data_symbols;
- }
- else { // small alphabet: no table needed
- decoder_table = 0;
- table_size = table_shift = 0;
- distribution = new unsigned[2*data_symbols];
- }
- symbol_count = distribution + data_symbols;
- if (distribution == 0) AC_Error("cannot assign model memory");
- }
-
- reset(); // initialize model
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Adaptive_Data_Model::update(bool from_encoder)
- {
- // halve counts when a threshold is reached
-
- if ((total_count += update_cycle) > DM__MaxCount) {
- total_count = 0;
- for (unsigned n = 0; n < data_symbols; n++)
- total_count += (symbol_count[n] = (symbol_count[n] + 1) >> 1);
- }
- assert(total_count > 0);
- // compute cumulative distribution, decoder table
- unsigned k, sum = 0, s = 0;
- unsigned scale = 0x80000000U / total_count;
-
- if (from_encoder || (table_size == 0))
- for (k = 0; k < data_symbols; k++) {
- distribution[k] = (scale * sum) >> (31 - DM__LengthShift);
- sum += symbol_count[k];
- }
- else {
- assert(decoder_table);
- for (k = 0; k < data_symbols; k++) {
- distribution[k] = (scale * sum) >> (31 - DM__LengthShift);
- sum += symbol_count[k];
- unsigned w = distribution[k] >> table_shift;
- while (s < w) decoder_table[++s] = k - 1;
- }
- decoder_table[0] = 0;
- while (s <= table_size) decoder_table[++s] = data_symbols - 1;
- }
- // set frequency of model updates
- update_cycle = (5 * update_cycle) >> 2;
- unsigned max_cycle = (data_symbols + 6) << 3;
- if (update_cycle > max_cycle) update_cycle = max_cycle;
- symbols_until_update = update_cycle;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- void Adaptive_Data_Model::reset(void)
- {
- if (data_symbols == 0) return;
-
- // restore probability estimates to uniform distribution
- total_count = 0;
- update_cycle = data_symbols;
- for (unsigned k = 0; k < data_symbols; k++) symbol_count[k] = 1;
- update(false);
- symbols_until_update = update_cycle = (data_symbols + 6) >> 1;
- }
-}
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.h
deleted file mode 100644
index d3cf6d14a..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcArithmeticCodec.h
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
-Copyright (c) 2004 Amir Said (said@ieee.org) & William A. Pearlman (pearlw@ecse.rpi.edu)
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-- Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
-
-- Redistributions in binary form must reproduce the above copyright notice, this list of
- conditions and the following disclaimer in the documentation and/or other materials
- provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
-IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
-OF SUCH DAMAGE.
-*/
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// **************************** -
-// ARITHMETIC CODING EXAMPLES -
-// **************************** -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// Fast arithmetic coding implementation -
-// -> 32-bit variables, 32-bit product, periodic updates, table decoding -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// Version 1.00 - April 25, 2004 -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// WARNING -
-// ========= -
-// -
-// The only purpose of this program is to demonstrate the basic principles -
-// of arithmetic coding. It is provided as is, without any express or -
-// implied warranty, without even the warranty of fitness for any particular -
-// purpose, or that the implementations are correct. -
-// -
-// Permission to copy and redistribute this code is hereby granted, provided -
-// that this warning and copyright notices are not removed or altered. -
-// -
-// Copyright (c) 2004 by Amir Said (said@ieee.org) & -
-// William A. Pearlman (pearlw@ecse.rpi.edu) -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// -
-// A description of the arithmetic coding method used here is available in -
-// -
-// Lossless Compression Handbook, ed. K. Sayood -
-// Chapter 5: Arithmetic Coding (A. Said), pp. 101-152, Academic Press, 2003 -
-// -
-// A. Said, Introduction to Arithetic Coding Theory and Practice -
-// HP Labs report HPL-2004-76 - http://www.hpl.hp.com/techreports/ -
-// -
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-// - - Definitions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-#ifndef O3DGC_ARITHMETIC_CODEC
-#define O3DGC_ARITHMETIC_CODEC
-
-#include <stdio.h>
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Class definitions - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- class Static_Bit_Model // static model for binary data
- {
- public:
-
- Static_Bit_Model(void);
-
- void set_probability_0(double); // set probability of symbol '0'
-
- private: // . . . . . . . . . . . . . . . . . . . . . .
- unsigned bit_0_prob;
- friend class Arithmetic_Codec;
- };
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- class Static_Data_Model // static model for general data
- {
- public:
-
- Static_Data_Model(void);
- ~Static_Data_Model(void);
-
- unsigned model_symbols(void) { return data_symbols; }
-
- void set_distribution(unsigned number_of_symbols,
- const double probability[] = 0); // 0 means uniform
-
- private: // . . . . . . . . . . . . . . . . . . . . . .
- unsigned * distribution, * decoder_table;
- unsigned data_symbols, last_symbol, table_size, table_shift;
- friend class Arithmetic_Codec;
- };
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- class Adaptive_Bit_Model // adaptive model for binary data
- {
- public:
-
- Adaptive_Bit_Model(void);
-
- void reset(void); // reset to equiprobable model
-
- private: // . . . . . . . . . . . . . . . . . . . . . .
- void update(void);
- unsigned update_cycle, bits_until_update;
- unsigned bit_0_prob, bit_0_count, bit_count;
- friend class Arithmetic_Codec;
- };
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- class Adaptive_Data_Model // adaptive model for binary data
- {
- public:
-
- Adaptive_Data_Model(void);
- Adaptive_Data_Model(unsigned number_of_symbols);
- ~Adaptive_Data_Model(void);
-
- unsigned model_symbols(void) { return data_symbols; }
-
- void reset(void); // reset to equiprobable model
- void set_alphabet(unsigned number_of_symbols);
-
- private: // . . . . . . . . . . . . . . . . . . . . . .
- void update(bool);
- unsigned * distribution, * symbol_count, * decoder_table;
- unsigned total_count, update_cycle, symbols_until_update;
- unsigned data_symbols, last_symbol, table_size, table_shift;
- friend class Arithmetic_Codec;
- };
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // - - Encoder and decoder class - - - - - - - - - - - - - - - - - - - - - - -
-
- // Class with both the arithmetic encoder and decoder. All compressed data is
- // saved to a memory buffer
-
- class Arithmetic_Codec
- {
- public:
-
- Arithmetic_Codec(void);
- ~Arithmetic_Codec(void);
- Arithmetic_Codec(unsigned max_code_bytes,
- unsigned char * user_buffer = 0); // 0 = assign new
-
- unsigned char * buffer(void) { return code_buffer; }
-
- void set_buffer(unsigned max_code_bytes,
- unsigned char * user_buffer = 0); // 0 = assign new
-
- void start_encoder(void);
- void start_decoder(void);
- void read_from_file(FILE * code_file); // read code data, start decoder
-
- unsigned stop_encoder(void); // returns number of bytes used
- unsigned write_to_file(FILE * code_file); // stop encoder, write code data
- void stop_decoder(void);
-
- void put_bit(unsigned bit);
- unsigned get_bit(void);
-
- void put_bits(unsigned data, unsigned number_of_bits);
- unsigned get_bits(unsigned number_of_bits);
-
- void encode(unsigned bit,
- Static_Bit_Model &);
- unsigned decode(Static_Bit_Model &);
-
- void encode(unsigned data,
- Static_Data_Model &);
- unsigned decode(Static_Data_Model &);
-
- void encode(unsigned bit,
- Adaptive_Bit_Model &);
- unsigned decode(Adaptive_Bit_Model &);
-
- void encode(unsigned data,
- Adaptive_Data_Model &);
- unsigned decode(Adaptive_Data_Model &);
-
-// This section was added by K. Mammou
- void ExpGolombEncode(unsigned int symbol,
- int k,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1)
- {
- while(1)
- {
- if (symbol >= (unsigned int)(1<<k))
- {
- encode(1, bModel1);
- symbol = symbol - (1<<k);
- k++;
- }
- else
- {
- encode(0, bModel1); // now terminated zero of unary part
- while (k--) // next binary part
- {
- encode((signed short)((symbol>>k)&1), bModel0);
- }
- break;
- }
- }
- }
-
-
- unsigned ExpGolombDecode(int k,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1)
- {
- unsigned int l;
- int symbol = 0;
- int binary_symbol = 0;
- do
- {
- l=decode(bModel1);
- if (l==1)
- {
- symbol += (1<<k);
- k++;
- }
- }
- while (l!=0);
- while (k--) //next binary part
- if (decode(bModel0)==1)
- {
- binary_symbol |= (1<<k);
- }
- return (unsigned int) (symbol+binary_symbol);
- }
-//----------------------------------------------------------
-
- private: // . . . . . . . . . . . . . . . . . . . . . .
- void propagate_carry(void);
- void renorm_enc_interval(void);
- void renorm_dec_interval(void);
- unsigned char * code_buffer, * new_buffer, * ac_pointer;
- unsigned base, value, length; // arithmetic coding state
- unsigned buffer_size, mode; // mode: 0 = undef, 1 = encoder, 2 = decoder
- };
- inline long DecodeIntACEGC(Arithmetic_Codec & acd,
- Adaptive_Data_Model & mModelValues,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1,
- const unsigned long exp_k,
- const unsigned long M)
- {
- unsigned long uiValue = acd.decode(mModelValues);
- if (uiValue == M)
- {
- uiValue += acd.ExpGolombDecode(exp_k, bModel0, bModel1);
- }
- return UIntToInt(uiValue);
- }
- inline unsigned long DecodeUIntACEGC(Arithmetic_Codec & acd,
- Adaptive_Data_Model & mModelValues,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1,
- const unsigned long exp_k,
- const unsigned long M)
- {
- unsigned long uiValue = acd.decode(mModelValues);
- if (uiValue == M)
- {
- uiValue += acd.ExpGolombDecode(exp_k, bModel0, bModel1);
- }
- return uiValue;
- }
-
- inline void EncodeIntACEGC(long predResidual,
- Arithmetic_Codec & ace,
- Adaptive_Data_Model & mModelValues,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1,
- const unsigned long M)
- {
- unsigned long uiValue = IntToUInt(predResidual);
- if (uiValue < M)
- {
- ace.encode(uiValue, mModelValues);
- }
- else
- {
- ace.encode(M, mModelValues);
- ace.ExpGolombEncode(uiValue-M, 0, bModel0, bModel1);
- }
- }
- inline void EncodeUIntACEGC(long predResidual,
- Arithmetic_Codec & ace,
- Adaptive_Data_Model & mModelValues,
- Static_Bit_Model & bModel0,
- Adaptive_Bit_Model & bModel1,
- const unsigned long M)
- {
- unsigned long uiValue = (unsigned long) predResidual;
- if (uiValue < M)
- {
- ace.encode(uiValue, mModelValues);
- }
- else
- {
- ace.encode(M, mModelValues);
- ace.ExpGolombEncode(uiValue-M, 0, bModel0, bModel1);
- }
- }
-
-}
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#endif
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcBinaryStream.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcBinaryStream.h
deleted file mode 100644
index b7b7678b7..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcBinaryStream.h
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_BINARY_STREAM_H
-#define O3DGC_BINARY_STREAM_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcVector.h"
-
-namespace o3dgc
-{
- const unsigned long O3DGC_BINARY_STREAM_DEFAULT_SIZE = 4096;
- const unsigned long O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0 = 7;
- const unsigned long O3DGC_BINARY_STREAM_MAX_SYMBOL0 = (1 << O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0) - 1;
- const unsigned long O3DGC_BINARY_STREAM_BITS_PER_SYMBOL1 = 6;
- const unsigned long O3DGC_BINARY_STREAM_MAX_SYMBOL1 = (1 << O3DGC_BINARY_STREAM_BITS_PER_SYMBOL1) - 1;
- const unsigned long O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32 = (32+O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0-1) /
- O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0;
-
- //!
- class BinaryStream
- {
- public:
- //! Constructor.
- BinaryStream(unsigned long size = O3DGC_BINARY_STREAM_DEFAULT_SIZE)
- {
- m_endianness = SystemEndianness();
- m_stream.Allocate(size);
- };
- //! Destructor.
- ~BinaryStream(void){};
-
- void WriteFloat32(float value, O3DGCStreamType streamType)
- {
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- WriteFloat32ASCII(value);
- }
- else
- {
- WriteFloat32Bin(value);
- }
- }
- void WriteUInt32(unsigned long position, unsigned long value, O3DGCStreamType streamType)
- {
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- WriteUInt32ASCII(position, value);
- }
- else
- {
- WriteUInt32Bin(position, value);
- }
- }
- void WriteUInt32(unsigned long value, O3DGCStreamType streamType)
- {
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- WriteUInt32ASCII(value);
- }
- else
- {
- WriteUInt32Bin(value);
- }
- }
- void WriteUChar(unsigned int position, unsigned char value, O3DGCStreamType streamType)
- {
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- WriteUInt32ASCII(position, value);
- }
- else
- {
- WriteUInt32Bin(position, value);
- }
- }
- void WriteUChar(unsigned char value, O3DGCStreamType streamType)
- {
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- WriteUCharASCII(value);
- }
- else
- {
- WriteUChar8Bin(value);
- }
- }
- float ReadFloat32(unsigned long & position, O3DGCStreamType streamType) const
- {
- float value;
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- value = ReadFloat32ASCII(position);
- }
- else
- {
- value = ReadFloat32Bin(position);
- }
- return value;
- }
- unsigned long ReadUInt32(unsigned long & position, O3DGCStreamType streamType) const
- {
- unsigned long value;
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- value = ReadUInt32ASCII(position);
- }
- else
- {
- value = ReadUInt32Bin(position);
- }
- return value;
- }
- unsigned char ReadUChar(unsigned long & position, O3DGCStreamType streamType) const
- {
- unsigned char value;
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- value = ReadUCharASCII(position);
- }
- else
- {
- value = ReadUChar8Bin(position);
- }
- return value;
- }
-
- void WriteFloat32Bin(unsigned long position, float value)
- {
- assert(position < m_stream.GetSize() - 4);
- unsigned char * ptr = (unsigned char *) (&value);
- if (m_endianness == O3DGC_BIG_ENDIAN)
- {
- m_stream[position++] = ptr[3];
- m_stream[position++] = ptr[2];
- m_stream[position++] = ptr[1];
- m_stream[position ] = ptr[0];
- }
- else
- {
- m_stream[position++] = ptr[0];
- m_stream[position++] = ptr[1];
- m_stream[position++] = ptr[2];
- m_stream[position ] = ptr[3];
- }
- }
- void WriteFloat32Bin(float value)
- {
- unsigned char * ptr = (unsigned char *) (&value);
- if (m_endianness == O3DGC_BIG_ENDIAN)
- {
- m_stream.PushBack(ptr[3]);
- m_stream.PushBack(ptr[2]);
- m_stream.PushBack(ptr[1]);
- m_stream.PushBack(ptr[0]);
- }
- else
- {
- m_stream.PushBack(ptr[0]);
- m_stream.PushBack(ptr[1]);
- m_stream.PushBack(ptr[2]);
- m_stream.PushBack(ptr[3]);
- }
- }
- void WriteUInt32Bin(unsigned long position, unsigned long value)
- {
- assert(position < m_stream.GetSize() - 4);
- unsigned char * ptr = (unsigned char *) (&value);
- if (m_endianness == O3DGC_BIG_ENDIAN)
- {
- m_stream[position++] = ptr[3];
- m_stream[position++] = ptr[2];
- m_stream[position++] = ptr[1];
- m_stream[position ] = ptr[0];
- }
- else
- {
- m_stream[position++] = ptr[0];
- m_stream[position++] = ptr[1];
- m_stream[position++] = ptr[2];
- m_stream[position ] = ptr[3];
- }
- }
- void WriteUInt32Bin(unsigned long value)
- {
- unsigned char * ptr = (unsigned char *) (&value);
- if (m_endianness == O3DGC_BIG_ENDIAN)
- {
- m_stream.PushBack(ptr[3]);
- m_stream.PushBack(ptr[2]);
- m_stream.PushBack(ptr[1]);
- m_stream.PushBack(ptr[0]);
- }
- else
- {
- m_stream.PushBack(ptr[0]);
- m_stream.PushBack(ptr[1]);
- m_stream.PushBack(ptr[2]);
- m_stream.PushBack(ptr[3]);
- }
- }
- void WriteUChar8Bin(unsigned int position, unsigned char value)
- {
- m_stream[position] = value;
- }
- void WriteUChar8Bin(unsigned char value)
- {
- m_stream.PushBack(value);
- }
- float ReadFloat32Bin(unsigned long & position) const
- {
- unsigned long value = ReadUInt32Bin(position);
- float fvalue;
- memcpy(&fvalue, &value, 4);
- return fvalue;
- }
- unsigned long ReadUInt32Bin(unsigned long & position) const
- {
- assert(position < m_stream.GetSize() - 4);
- unsigned long value = 0;
- if (m_endianness == O3DGC_BIG_ENDIAN)
- {
- value += (m_stream[position++]<<24);
- value += (m_stream[position++]<<16);
- value += (m_stream[position++]<<8);
- value += (m_stream[position++]);
- }
- else
- {
- value += (m_stream[position++]);
- value += (m_stream[position++]<<8);
- value += (m_stream[position++]<<16);
- value += (m_stream[position++]<<24);
- }
- return value;
- }
- unsigned char ReadUChar8Bin(unsigned long & position) const
- {
- return m_stream[position++];
- }
-
- void WriteFloat32ASCII(float value)
- {
- unsigned long uiValue;
- memcpy(&uiValue, &value, 4);
- WriteUInt32ASCII(uiValue);
- }
- void WriteUInt32ASCII(unsigned long position, unsigned long value)
- {
- assert(position < m_stream.GetSize() - O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32);
- unsigned long value0 = value;
- for(unsigned long i = 0; i < O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32; ++i)
- {
- m_stream[position++] = (value0 & O3DGC_BINARY_STREAM_MAX_SYMBOL0);
- value0 >>= O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0;
- }
- }
- void WriteUInt32ASCII(unsigned long value)
- {
- for(unsigned long i = 0; i < O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32; ++i)
- {
- m_stream.PushBack(value & O3DGC_BINARY_STREAM_MAX_SYMBOL0);
- value >>= O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0;
- }
- }
- void WriteIntASCII(long value)
- {
- WriteUIntASCII(IntToUInt(value));
- }
- void WriteUIntASCII(unsigned long value)
- {
- if (value >= O3DGC_BINARY_STREAM_MAX_SYMBOL0)
- {
- m_stream.PushBack(O3DGC_BINARY_STREAM_MAX_SYMBOL0);
- value -= O3DGC_BINARY_STREAM_MAX_SYMBOL0;
- unsigned char a, b;
- do
- {
- a = ((value & O3DGC_BINARY_STREAM_MAX_SYMBOL1) << 1);
- b = ( (value >>= O3DGC_BINARY_STREAM_BITS_PER_SYMBOL1) > 0);
- a += b;
- m_stream.PushBack(a);
- } while (b);
- }
- else
- {
- m_stream.PushBack((unsigned char) value);
- }
- }
- void WriteUCharASCII(unsigned char value)
- {
- assert(value <= O3DGC_BINARY_STREAM_MAX_SYMBOL0);
- m_stream.PushBack(value);
- }
- float ReadFloat32ASCII(unsigned long & position) const
- {
- unsigned long value = ReadUInt32ASCII(position);
- float fvalue;
- memcpy(&fvalue, &value, 4);
- return fvalue;
- }
- unsigned long ReadUInt32ASCII(unsigned long & position) const
- {
- assert(position < m_stream.GetSize() - O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32);
- unsigned long value = 0;
- unsigned long shift = 0;
- for(unsigned long i = 0; i < O3DGC_BINARY_STREAM_NUM_SYMBOLS_UINT32; ++i)
- {
- value += (m_stream[position++] << shift);
- shift += O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0;
- }
- return value;
- }
- long ReadIntASCII(unsigned long & position) const
- {
- return UIntToInt(ReadUIntASCII(position));
- }
- unsigned long ReadUIntASCII(unsigned long & position) const
- {
- unsigned long value = m_stream[position++];
- if (value == O3DGC_BINARY_STREAM_MAX_SYMBOL0)
- {
- long x;
- unsigned long i = 0;
- do
- {
- x = m_stream[position++];
- value += ( (x>>1) << i);
- i += O3DGC_BINARY_STREAM_BITS_PER_SYMBOL1;
- } while (x & 1);
- }
- return value;
- }
- unsigned char ReadUCharASCII(unsigned long & position) const
- {
- return m_stream[position++];
- }
- O3DGCErrorCode Save(const char * const fileName)
- {
- FILE * fout = fopen(fileName, "wb");
- if (!fout)
- {
- return O3DGC_ERROR_CREATE_FILE;
- }
- fwrite(m_stream.GetBuffer(), 1, m_stream.GetSize(), fout);
- fclose(fout);
- return O3DGC_OK;
- }
- O3DGCErrorCode Load(const char * const fileName)
- {
- FILE * fin = fopen(fileName, "rb");
- if (!fin)
- {
- return O3DGC_ERROR_OPEN_FILE;
- }
- fseek(fin, 0, SEEK_END);
- unsigned long size = ftell(fin);
- m_stream.Allocate(size);
- rewind(fin);
- unsigned int nread = (unsigned int) fread((void *) m_stream.GetBuffer(), 1, size, fin);
- m_stream.SetSize(size);
- if (nread != size)
- {
- return O3DGC_ERROR_READ_FILE;
- }
- fclose(fin);
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadFromBuffer(unsigned char * buffer, unsigned long bufferSize)
- {
- m_stream.Allocate(bufferSize);
- memcpy(m_stream.GetBuffer(), buffer, bufferSize);
- m_stream.SetSize(bufferSize);
- return O3DGC_OK;
- }
- unsigned long GetSize() const
- {
- return m_stream.GetSize();
- }
- const unsigned char * GetBuffer(unsigned long position) const
- {
- return m_stream.GetBuffer() + position;
- }
- unsigned char * GetBuffer(unsigned long position)
- {
- return (m_stream.GetBuffer() + position);
- }
- unsigned char * GetBuffer()
- {
- return m_stream.GetBuffer();
- }
- void GetBuffer(unsigned long position, unsigned char * & buffer) const
- {
- buffer = (unsigned char *) (m_stream.GetBuffer() + position); // fix me: ugly!
- }
- void SetSize(unsigned long size)
- {
- m_stream.SetSize(size);
- };
- void Allocate(unsigned long size)
- {
- m_stream.Allocate(size);
- }
-
- private:
- Vector<unsigned char> m_stream;
- O3DGCEndianness m_endianness;
- };
-
-}
-#endif // O3DGC_BINARY_STREAM_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcCommon.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcCommon.h
deleted file mode 100644
index ff6bf7558..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcCommon.h
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_COMMON_H
-#define O3DGC_COMMON_H
-
-#ifndef _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_WARNINGS
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <math.h>
-
-namespace o3dgc
-{
- typedef float Real;
- const double O3DGC_MAX_DOUBLE = 1.79769e+308;
- const long O3DGC_MIN_LONG = -2147483647;
- const long O3DGC_MAX_LONG = 2147483647;
- const long O3DGC_MAX_UCHAR8 = 255;
- const long O3DGC_MAX_TFAN_SIZE = 256;
- const unsigned long O3DGC_MAX_ULONG = 4294967295;
-
- const unsigned long O3DGC_SC3DMC_START_CODE = 0x00001F1;
- const unsigned long O3DGC_DV_START_CODE = 0x00001F2;
- const unsigned long O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES = 256;
- const unsigned long O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES = 256;
- const unsigned long O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES = 32;
-
- const unsigned long O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS = 2;
- const unsigned long O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS = 257;
-
- enum O3DGCEndianness
- {
- O3DGC_BIG_ENDIAN = 0,
- O3DGC_LITTLE_ENDIAN = 1
- };
- enum O3DGCErrorCode
- {
- O3DGC_OK,
- O3DGC_ERROR_BUFFER_FULL,
- O3DGC_ERROR_CREATE_FILE,
- O3DGC_ERROR_OPEN_FILE,
- O3DGC_ERROR_READ_FILE,
- O3DGC_ERROR_CORRUPTED_STREAM,
- O3DGC_ERROR_NON_SUPPORTED_FEATURE
- };
- enum O3DGCSC3DMCBinarization
- {
- O3DGC_SC3DMC_BINARIZATION_FL = 0, // Fixed Length (not supported)
- O3DGC_SC3DMC_BINARIZATION_BP = 1, // BPC (not supported)
- O3DGC_SC3DMC_BINARIZATION_FC = 2, // 4 bits Coding (not supported)
- O3DGC_SC3DMC_BINARIZATION_AC = 3, // Arithmetic Coding (not supported)
- O3DGC_SC3DMC_BINARIZATION_AC_EGC = 4, // Arithmetic Coding & EGCk
- O3DGC_SC3DMC_BINARIZATION_ASCII = 5 // Arithmetic Coding & EGCk
- };
- enum O3DGCStreamType
- {
- O3DGC_STREAM_TYPE_UNKOWN = 0,
- O3DGC_STREAM_TYPE_ASCII = 1,
- O3DGC_STREAM_TYPE_BINARY = 2
- };
- enum O3DGCSC3DMCQuantizationMode
- {
- O3DGC_SC3DMC_DIAG_BB = 0, // supported
- O3DGC_SC3DMC_MAX_ALL_DIMS = 1, // supported
- O3DGC_SC3DMC_MAX_SEP_DIM = 2 // supported
- };
- enum O3DGCSC3DMCPredictionMode
- {
- O3DGC_SC3DMC_NO_PREDICTION = 0, // supported
- O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION = 1, // supported
- O3DGC_SC3DMC_XOR_PREDICTION = 2, // not supported
- O3DGC_SC3DMC_ADAPTIVE_DIFFERENTIAL_PREDICTION = 3, // not supported
- O3DGC_SC3DMC_CIRCULAR_DIFFERENTIAL_PREDICTION = 4, // not supported
- O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION = 5, // supported
- O3DGC_SC3DMC_SURF_NORMALS_PREDICTION = 6 // supported
- };
- enum O3DGCSC3DMCEncodingMode
- {
- O3DGC_SC3DMC_ENCODE_MODE_QBCR = 0, // not supported
- O3DGC_SC3DMC_ENCODE_MODE_SVA = 1, // not supported
- O3DGC_SC3DMC_ENCODE_MODE_TFAN = 2, // supported
- };
- enum O3DGCDVEncodingMode
- {
- O3DGC_DYNAMIC_VECTOR_ENCODE_MODE_LIFT = 0
- };
- enum O3DGCIFSFloatAttributeType
- {
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_UNKOWN = 0,
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_POSITION = 1,
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_NORMAL = 2,
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_COLOR = 3,
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_TEXCOORD = 4,
- O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_WEIGHT = 5
-
- };
- enum O3DGCIFSIntAttributeType
- {
- O3DGC_IFS_INT_ATTRIBUTE_TYPE_UNKOWN = 0,
- O3DGC_IFS_INT_ATTRIBUTE_TYPE_INDEX = 1,
- O3DGC_IFS_INT_ATTRIBUTE_TYPE_JOINT_ID = 2,
- O3DGC_IFS_INT_ATTRIBUTE_TYPE_INDEX_BUFFER_ID = 3
- };
-
- template<class T>
- inline const T absolute(const T& a)
- {
- return (a < (T)(0)) ? -a : a;
- }
- template<class T>
- inline const T min(const T& a, const T& b)
- {
- return (b < a) ? b : a;
- }
- template<class T>
- inline const T max(const T& a, const T& b)
- {
- return (b > a) ? b : a;
- }
- template<class T>
- inline void swap(T& a, T& b)
- {
- T tmp = a;
- a = b;
- b = tmp;
- }
- inline double log2( double n )
- {
- return log(n) / log(2.0);
- }
-
- inline O3DGCEndianness SystemEndianness()
- {
- unsigned long num = 1;
- return ( *((char *)(&num)) == 1 )? O3DGC_LITTLE_ENDIAN : O3DGC_BIG_ENDIAN ;
- }
- class SC3DMCStats
- {
- public:
- SC3DMCStats(void)
- {
- memset(this, 0, sizeof(SC3DMCStats));
- };
- ~SC3DMCStats(void){};
-
- double m_timeCoord;
- double m_timeNormal;
- double m_timeCoordIndex;
- double m_timeFloatAttribute[O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- double m_timeIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
- double m_timeReorder;
-
- unsigned long m_streamSizeCoord;
- unsigned long m_streamSizeNormal;
- unsigned long m_streamSizeCoordIndex;
- unsigned long m_streamSizeFloatAttribute[O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- unsigned long m_streamSizeIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
-
- };
- typedef struct
- {
- long m_a;
- long m_b;
- long m_c;
- } SC3DMCTriplet;
-
- typedef struct
- {
- SC3DMCTriplet m_id;
- long m_pred[O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
- } SC3DMCPredictor;
-
- inline bool operator< (const SC3DMCTriplet& lhs, const SC3DMCTriplet& rhs)
- {
- if (lhs.m_c != rhs.m_c)
- {
- return (lhs.m_c < rhs.m_c);
- }
- else if (lhs.m_b != rhs.m_b)
- {
- return (lhs.m_b < rhs.m_b);
- }
- return (lhs.m_a < rhs.m_a);
- }
- inline bool operator== (const SC3DMCTriplet& lhs, const SC3DMCTriplet& rhs)
- {
- return (lhs.m_c == rhs.m_c && lhs.m_b == rhs.m_b && lhs.m_a == rhs.m_a);
- }
-
-
- // fix me: optimize this function (e.g., binary search)
- inline unsigned long Insert(SC3DMCTriplet e, unsigned long & nPred, SC3DMCPredictor * const list)
- {
- unsigned long pos = 0xFFFFFFFF;
- bool foundOrInserted = false;
- for (unsigned long j = 0; j < nPred; ++j)
- {
- if (e == list[j].m_id)
- {
- foundOrInserted = true;
- break;
- }
- else if (e < list[j].m_id)
- {
- if (nPred < O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS)
- {
- ++nPred;
- }
- for (unsigned long h = nPred-1; h > j; --h)
- {
- list[h] = list[h-1];
- }
- list[j].m_id = e;
- pos = j;
- foundOrInserted = true;
- break;
- }
- }
- if (!foundOrInserted && nPred < O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS)
- {
- pos = nPred;
- list[nPred++].m_id = e;
- }
- return pos;
- }
- template <class T>
- inline void SphereToCube(const T x, const T y, const T z,
- T & a, T & b, char & index)
- {
- T ax = absolute(x);
- T ay = absolute(y);
- T az = absolute(z);
- if (az >= ax && az >= ay)
- {
- if (z >= (T)(0))
- {
- index = 0;
- a = x;
- b = y;
- }
- else
- {
- index = 1;
- a = -x;
- b = -y;
- }
- }
- else if (ay >= ax && ay >= az)
- {
- if (y >= (T)(0))
- {
- index = 2;
- a = z;
- b = x;
- }
- else
- {
- index = 3;
- a = -z;
- b = -x;
- }
- }
- else if (ax >= ay && ax >= az)
- {
- if (x >= (T)(0))
- {
- index = 4;
- a = y;
- b = z;
- }
- else
- {
- index = 5;
- a = -y;
- b = -z;
- }
- }
- }
- inline void CubeToSphere(const Real a, const Real b, const char index,
- Real & x, Real & y, Real & z)
- {
- switch( index )
- {
- case 0:
- x = a;
- y = b;
- z = (Real) sqrt(max(0.0, 1.0 - x*x-y*y));
- break;
- case 1:
- x = -a;
- y = -b;
- z = -(Real) sqrt(max(0.0, 1.0 - x*x-y*y));
- break;
- case 2:
- z = a;
- x = b;
- y = (Real) sqrt(max(0.0, 1.0 - x*x-z*z));
- break;
- case 3:
- z = -a;
- x = -b;
- y = -(Real) sqrt(max(0.0, 1.0 - x*x-z*z));
- break;
- case 4:
- y = a;
- z = b;
- x = (Real) sqrt(max(0.0, 1.0 - y*y-z*z));
- break;
- case 5:
- y = -a;
- z = -b;
- x = -(Real) sqrt(max(0.0, 1.0 - y*y-z*z));
- break;
- }
- }
- inline unsigned long IntToUInt(long value)
- {
- return (value < 0)?(unsigned long) (-1 - (2 * value)):(unsigned long) (2 * value);
- }
- inline long UIntToInt(unsigned long uiValue)
- {
- return (uiValue & 1)?-((long) ((uiValue+1) >> 1)):((long) (uiValue >> 1));
- }
- inline void ComputeVectorMinMax(const Real * const tab,
- unsigned long size,
- unsigned long dim,
- unsigned long stride,
- Real * minTab,
- Real * maxTab,
- O3DGCSC3DMCQuantizationMode quantMode)
- {
- if (size == 0 || dim == 0)
- {
- return;
- }
- unsigned long p = 0;
- for(unsigned long d = 0; d < dim; ++d)
- {
- maxTab[d] = minTab[d] = tab[p++];
- }
- p = stride;
- for(unsigned long i = 1; i < size; ++i)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- if (maxTab[d] < tab[p+d]) maxTab[d] = tab[p+d];
- if (minTab[d] > tab[p+d]) minTab[d] = tab[p+d];
- }
- p += stride;
- }
-
- if (quantMode == O3DGC_SC3DMC_DIAG_BB)
- {
- Real diag = Real( 0.0 );
- Real r;
- for(unsigned long d = 0; d < dim; ++d)
- {
- r = (maxTab[d] - minTab[d]);
- diag += r*r;
- }
- diag = static_cast<Real>(sqrt(diag));
- for(unsigned long d = 0; d < dim; ++d)
- {
- maxTab[d] = minTab[d] + diag;
- }
- }
- else if (quantMode == O3DGC_SC3DMC_MAX_ALL_DIMS)
- {
- Real maxr = (maxTab[0] - minTab[0]);
- Real r;
- for(unsigned long d = 1; d < dim; ++d)
- {
- r = (maxTab[d] - minTab[d]);
- if ( r > maxr)
- {
- maxr = r;
- }
- }
- for(unsigned long d = 0; d < dim; ++d)
- {
- maxTab[d] = minTab[d] + maxr;
- }
- }
- }
-}
-#endif // O3DGC_COMMON_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDVEncodeParams.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDVEncodeParams.h
deleted file mode 100644
index 6f639f678..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDVEncodeParams.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_DV_ENCODE_PARAMS_H
-#define O3DGC_DV_ENCODE_PARAMS_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- class DVEncodeParams
- {
- public:
- //! Constructor.
- DVEncodeParams(void)
- {
- m_quantBits = 10;
- m_streamTypeMode = O3DGC_STREAM_TYPE_ASCII;
- m_encodeMode = O3DGC_DYNAMIC_VECTOR_ENCODE_MODE_LIFT;
- };
- //! Destructor.
- ~DVEncodeParams(void) {};
-
- unsigned long GetQuantBits() const { return m_quantBits;}
- O3DGCStreamType GetStreamType() const { return m_streamTypeMode;}
- O3DGCDVEncodingMode GetEncodeMode() const { return m_encodeMode;}
-
- void SetQuantBits (unsigned long quantBits ) { m_quantBits = quantBits;}
-
- void SetStreamType(O3DGCStreamType streamTypeMode) { m_streamTypeMode = streamTypeMode;}
- void SetEncodeMode(O3DGCDVEncodingMode encodeMode ) { m_encodeMode = encodeMode ;}
-
-
- private:
- unsigned long m_quantBits;
- O3DGCStreamType m_streamTypeMode;
- O3DGCDVEncodingMode m_encodeMode;
- };
-}
-#endif // O3DGC_DV_ENCODE_PARAMS_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVector.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVector.h
deleted file mode 100644
index aa7fb3142..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVector.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_DYNAMIC_VECTOR_SET_H
-#define O3DGC_DYNAMIC_VECTOR_SET_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- class DynamicVector
- {
- public:
- //! Constructor.
- DynamicVector(void)
- {
- m_num = 0;
- m_dim = 0;
- m_stride = 0;
- m_max = 0;
- m_min = 0;
- m_vectors = 0;
- };
- //! Destructor.
- ~DynamicVector(void) {};
-
- unsigned long GetNVector() const { return m_num;}
- unsigned long GetDimVector() const { return m_dim;}
- unsigned long GetStride() const { return m_stride;}
- const Real * GetMin() const { return m_min;}
- const Real * GetMax() const { return m_max;}
- const Real * GetVectors() const { return m_vectors;}
- Real * GetVectors() { return m_vectors;}
- Real GetMin(unsigned long j) const { return m_min[j];}
- Real GetMax(unsigned long j) const { return m_max[j];}
-
- void SetNVector (unsigned long num ) { m_num = num ;}
- void SetDimVector (unsigned long dim ) { m_dim = dim ;}
- void SetStride (unsigned long stride ) { m_stride = stride ;}
- void SetMin (Real * const min ) { m_min = min ;}
- void SetMax (Real * const max ) { m_max = max ;}
- void SetMin (unsigned long j, Real min) { m_min[j] = min ;}
- void SetMax (unsigned long j, Real max) { m_max[j] = max ;}
- void SetVectors (Real * const vectors) { m_vectors = vectors ;}
-
- void ComputeMinMax(O3DGCSC3DMCQuantizationMode quantMode)
- {
- assert( m_max && m_min && m_vectors && m_stride && m_dim && m_num);
- ComputeVectorMinMax(m_vectors, m_num , m_dim, m_stride, m_min , m_max , quantMode);
- }
-
- private:
- unsigned long m_num;
- unsigned long m_dim;
- unsigned long m_stride;
- Real * m_max;
- Real * m_min;
- Real * m_vectors;
- };
-
-}
-#endif // O3DGC_DYNAMIC_VECTOR_SET_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.cpp b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.cpp
deleted file mode 100644
index b92452eb6..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-#include "o3dgcDynamicVectorDecoder.h"
-#include "o3dgcArithmeticCodec.h"
-
-
-//#define DEBUG_VERBOSE
-
-namespace o3dgc
-{
-#ifdef DEBUG_VERBOSE
- FILE * g_fileDebugDVCDec = NULL;
-#endif //DEBUG_VERBOSE
-
- O3DGCErrorCode IUpdate(long * const data, const long size)
- {
- assert(size > 1);
- const long size1 = size - 1;
- long p = 2;
- data[0] -= data[1] >> 1;
- while(p < size1)
- {
- data[p] -= (data[p-1] + data[p+1] + 2) >> 2;
- p += 2;
- }
- if ( p == size1)
- {
- data[p] -= data[p-1]>>1;
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode IPredict(long * const data, const long size)
- {
- assert(size > 1);
- const long size1 = size - 1;
- long p = 1;
- while(p < size1)
- {
- data[p] += (data[p-1] + data[p+1] + 1) >> 1;
- p += 2;
- }
- if ( p == size1)
- {
- data[p] += data[p-1];
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode Merge(long * const data, const long size)
- {
- assert(size > 1);
- const long h = (size >> 1) + (size & 1);
- long a = h-1;
- long b = h;
- while (a > 0)
- {
- for (long i = a; i < b; i += 2)
- {
- swap(data[i], data[i+1]);
- }
- --a;
- ++b;
- }
- return O3DGC_OK;
- }
- inline O3DGCErrorCode ITransform(long * const data, const unsigned long size)
- {
- unsigned long n = size;
- unsigned long even = 0;
- unsigned long k = 0;
- even += ((n&1) << k++);
- while(n > 1)
- {
- n = (n >> 1) + (n & 1);
- even += ((n&1) << k++);
- }
- for(long i = k-2; i >= 0; --i)
- {
- n = (n << 1) - ((even>>i) & 1);
- Merge (data, n);
- IUpdate (data, n);
- IPredict(data, n);
- }
- return O3DGC_OK;
- }
- DynamicVectorDecoder::DynamicVectorDecoder(void)
- {
- m_streamSize = 0;
- m_maxNumVectors = 0;
- m_numVectors = 0;
- m_dimVectors = 0;
- m_quantVectors = 0;
- m_iterator = 0;
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- }
- DynamicVectorDecoder::~DynamicVectorDecoder()
- {
- delete [] m_quantVectors;
- }
- O3DGCErrorCode DynamicVectorDecoder::DecodeHeader(DynamicVector & dynamicVector,
- const BinaryStream & bstream)
- {
- unsigned long iterator0 = m_iterator;
- unsigned long start_code = bstream.ReadUInt32(m_iterator, O3DGC_STREAM_TYPE_BINARY);
- if (start_code != O3DGC_DV_START_CODE)
- {
- m_iterator = iterator0;
- start_code = bstream.ReadUInt32(m_iterator, O3DGC_STREAM_TYPE_ASCII);
- if (start_code != O3DGC_DV_START_CODE)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- else
- {
- m_streamType = O3DGC_STREAM_TYPE_ASCII;
- }
- }
- else
- {
- m_streamType = O3DGC_STREAM_TYPE_BINARY;
- }
- m_streamSize = bstream.ReadUInt32(m_iterator, m_streamType);
- m_params.SetEncodeMode( (O3DGCDVEncodingMode) bstream.ReadUChar(m_iterator, m_streamType));
- dynamicVector.SetNVector ( bstream.ReadUInt32(m_iterator, m_streamType) );
-
- if (dynamicVector.GetNVector() > 0)
- {
- dynamicVector.SetDimVector( bstream.ReadUInt32(m_iterator, m_streamType) );
- m_params.SetQuantBits(bstream.ReadUChar(m_iterator, m_streamType));
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode DynamicVectorDecoder::DecodePlayload(DynamicVector & dynamicVector,
- const BinaryStream & bstream)
- {
- O3DGCErrorCode ret = O3DGC_OK;
-#ifdef DEBUG_VERBOSE
- g_fileDebugDVCDec = fopen("dv_dec.txt", "w");
-#endif //DEBUG_VERBOSE
- unsigned long start = m_iterator;
- unsigned long streamSize = bstream.ReadUInt32(m_iterator, m_streamType); // bitsream size
-
- const unsigned long dim = dynamicVector.GetDimVector();
- const unsigned long num = dynamicVector.GetNVector();
- const unsigned long size = dim * num;
- for(unsigned long j=0 ; j < dynamicVector.GetDimVector() ; ++j)
- {
- dynamicVector.SetMin(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- dynamicVector.SetMax(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- }
- Arithmetic_Codec acd;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- unsigned char * buffer = 0;
- streamSize -= (m_iterator - start);
- unsigned int exp_k = 0;
- unsigned int M = 0;
- if (m_streamType == O3DGC_STREAM_TYPE_BINARY)
- {
- bstream.GetBuffer(m_iterator, buffer);
- m_iterator += streamSize;
- acd.set_buffer(streamSize, buffer);
- acd.start_decoder();
- exp_k = acd.ExpGolombDecode(0, bModel0, bModel1);
- M = acd.ExpGolombDecode(0, bModel0, bModel1);
- }
- Adaptive_Data_Model mModelValues(M+2);
-
- if (m_maxNumVectors < size)
- {
- delete [] m_quantVectors;
- m_maxNumVectors = size;
- m_quantVectors = new long [size];
- }
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- m_quantVectors[d * num + v] = bstream.ReadIntASCII(m_iterator);
- }
- }
- }
- else
- {
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- m_quantVectors[d * num + v] = DecodeIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- }
- }
- #ifdef DEBUG_VERBOSE
- printf("IntArray (%i, %i)\n", num, dim);
- fprintf(g_fileDebugDVCDec, "IntArray (%i, %i)\n", num, dim);
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- printf("%i\t %i \t %i\n", d * num + v, m_quantVectors[d * num + v], IntToUInt(m_quantVectors[d * num + v]));
- fprintf(g_fileDebugDVCDec, "%i\t %i \t %i\n", d * num + v, m_quantVectors[d * num + v], IntToUInt(m_quantVectors[d * num + v]));
- }
- }
- fflush(g_fileDebugDVCDec);
- #endif //DEBUG_VERBOSE
- for(unsigned long d = 0; d < dim; ++d)
- {
- ITransform(m_quantVectors + d * num, num);
- }
- IQuantize(dynamicVector.GetVectors(),
- num,
- dim,
- dynamicVector.GetStride(),
- dynamicVector.GetMin(),
- dynamicVector.GetMax(),
- m_params.GetQuantBits());
-
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugDVCDec);
-#endif //DEBUG_VERBOSE
- return ret;
- }
- O3DGCErrorCode DynamicVectorDecoder::IQuantize(Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits)
- {
- const unsigned long size = numFloatArray * dimFloatArray;
- Real r;
- if (m_maxNumVectors < size)
- {
- delete [] m_quantVectors;
- m_maxNumVectors = size;
- m_quantVectors = new long [m_maxNumVectors];
- }
- Real idelta;
- for(unsigned long d = 0; d < dimFloatArray; ++d)
- {
- r = maxFloatArray[d] - minFloatArray[d];
- if (r > 0.0f)
- {
- idelta = (float)(r) / ((1 << nQBits) - 1);
- }
- else
- {
- idelta = 1.0f;
- }
- for(unsigned long v = 0; v < numFloatArray; ++v)
- {
- floatArray[v * stride + d] = m_quantVectors[v + d * numFloatArray] * idelta + minFloatArray[d];
- }
- }
- return O3DGC_OK;
- }
-}
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.h
deleted file mode 100644
index 6e21b4fa3..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_DYNAMIC_VECTOR_DECODER_H
-#define O3DGC_DYNAMIC_VECTOR_DECODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcDVEncodeParams.h"
-#include "o3dgcDynamicVector.h"
-
-namespace o3dgc
-{
- //!
- class DynamicVectorDecoder
- {
- public:
- //! Constructor.
- DynamicVectorDecoder(void);
- //! Destructor.
- ~DynamicVectorDecoder(void);
- //!
- //!
- O3DGCErrorCode DecodeHeader(DynamicVector & dynamicVector,
- const BinaryStream & bstream);
- //!
- O3DGCErrorCode DecodePlayload(DynamicVector & dynamicVector,
- const BinaryStream & bstream);
-
- O3DGCStreamType GetStreamType() const { return m_streamType; }
- void SetStreamType(O3DGCStreamType streamType) { m_streamType = streamType; }
- unsigned long GetIterator() const { return m_iterator;}
- O3DGCErrorCode SetIterator(unsigned long iterator) { m_iterator = iterator; return O3DGC_OK; }
-
- private:
- O3DGCErrorCode IQuantize(Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits);
-
- unsigned long m_streamSize;
- unsigned long m_maxNumVectors;
- unsigned long m_numVectors;
- unsigned long m_dimVectors;
- unsigned long m_iterator;
- long * m_quantVectors;
- DVEncodeParams m_params;
- O3DGCStreamType m_streamType;
- };
-}
-#endif // O3DGC_DYNAMIC_VECTOR_DECODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp
deleted file mode 100644
index 00ae75e35..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-#include "o3dgcDVEncodeParams.h"
-#include "o3dgcDynamicVectorEncoder.h"
-#include "o3dgcArithmeticCodec.h"
-#include "o3dgcBinaryStream.h"
-
-//#define DEBUG_VERBOSE
-
-namespace o3dgc
-{
-#ifdef DEBUG_VERBOSE
- FILE * g_fileDebugDVEnc = NULL;
-#endif //DEBUG_VERBOSE
-
- inline O3DGCErrorCode Update(long * const data, const long size)
- {
- assert(size > 1);
- const long size1 = size - 1;
- long p = 2;
- data[0] += data[1] >> 1;
- while(p < size1)
- {
- data[p] += (data[p-1] + data[p+1] + 2) >> 2;
- p += 2;
- }
- if ( p == size1)
- {
- data[p] += data[p-1]>>1;
- }
- return O3DGC_OK;
- }
- inline O3DGCErrorCode Predict(long * const data, const long size)
- {
- assert(size > 1);
- const long size1 = size - 1;
- long p = 1;
- while(p < size1)
- {
- data[p] -= (data[p-1] + data[p+1] + 1) >> 1;
- p += 2;
- }
- if ( p == size1)
- {
- data[p] -= data[p-1];
- }
- return O3DGC_OK;
- }
- inline O3DGCErrorCode Split(long * const data, const long size)
- {
- assert(size > 1);
- long a = 1;
- long b = size-1;
- while (a < b)
- {
- for (long i = a; i < b; i += 2)
- {
- swap(data[i], data[i+1]);
- }
- ++a;
- --b;
- }
- return O3DGC_OK;
- }
- inline O3DGCErrorCode Transform(long * const data, const unsigned long size)
- {
- unsigned long n = size;
- while(n > 1)
- {
- Predict(data, n);
- Update (data, n);
- Split(data, n);
- n = (n >> 1) + (n & 1);
- }
- return O3DGC_OK;
- }
- DynamicVectorEncoder::DynamicVectorEncoder(void)
- {
- m_maxNumVectors = 0;
- m_numVectors = 0;
- m_dimVectors = 0;
- m_quantVectors = 0;
- m_sizeBufferAC = 0;
- m_bufferAC = 0;
- m_posSize = 0;
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- }
- DynamicVectorEncoder::~DynamicVectorEncoder()
- {
- delete [] m_quantVectors;
- delete [] m_bufferAC;
- }
- O3DGCErrorCode DynamicVectorEncoder::Encode(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream)
- {
- assert(params.GetQuantBits() > 0);
- assert(dynamicVector.GetNVector() > 0);
- assert(dynamicVector.GetDimVector() > 0);
- assert(dynamicVector.GetStride() >= dynamicVector.GetDimVector());
- assert(dynamicVector.GetVectors() && dynamicVector.GetMin() && dynamicVector.GetMax());
- assert(m_streamType != O3DGC_STREAM_TYPE_UNKOWN);
- // Encode header
- unsigned long start = bstream.GetSize();
- EncodeHeader(params, dynamicVector, bstream);
- // Encode payload
- EncodePayload(params, dynamicVector, bstream);
- bstream.WriteUInt32(m_posSize, bstream.GetSize() - start, m_streamType);
- return O3DGC_OK;
-
- }
- O3DGCErrorCode DynamicVectorEncoder::EncodeHeader(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream)
- {
- m_streamType = params.GetStreamType();
- bstream.WriteUInt32(O3DGC_DV_START_CODE, m_streamType);
- m_posSize = bstream.GetSize();
- bstream.WriteUInt32(0, m_streamType); // to be filled later
- bstream.WriteUChar((unsigned char) params.GetEncodeMode(), m_streamType);
- bstream.WriteUInt32(dynamicVector.GetNVector() , m_streamType);
- if (dynamicVector.GetNVector() > 0)
- {
- bstream.WriteUInt32(dynamicVector.GetDimVector(), m_streamType);
- bstream.WriteUChar ((unsigned char) params.GetQuantBits(), m_streamType);
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode DynamicVectorEncoder::EncodeAC(unsigned long num,
- unsigned long dim,
- unsigned long M,
- unsigned long & encodedBytes)
- {
- Arithmetic_Codec ace;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- Adaptive_Data_Model mModelValues(M+2);
- const unsigned int NMAX = num * dim * 8 + 100;
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- ace.ExpGolombEncode(0, 0, bModel0, bModel1);
- ace.ExpGolombEncode(M, 0, bModel0, bModel1);
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- EncodeIntACEGC(m_quantVectors[d * num + v], ace, mModelValues, bModel0, bModel1, M);
- }
- }
- encodedBytes = ace.stop_encoder();
- return O3DGC_OK;
- }
-
- O3DGCErrorCode DynamicVectorEncoder::EncodePayload(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream)
- {
-#ifdef DEBUG_VERBOSE
- g_fileDebugDVEnc = fopen("dv_enc.txt", "w");
-#endif //DEBUG_VERBOSE
- unsigned long start = bstream.GetSize();
- const unsigned long dim = dynamicVector.GetDimVector();
- const unsigned long num = dynamicVector.GetNVector();
-
- bstream.WriteUInt32(0, m_streamType);
-
- for(unsigned long j=0 ; j<dynamicVector.GetDimVector() ; ++j)
- {
- bstream.WriteFloat32((float) dynamicVector.GetMin(j), m_streamType);
- bstream.WriteFloat32((float) dynamicVector.GetMax(j), m_streamType);
- }
- Quantize(dynamicVector.GetVectors(),
- num,
- dim,
- dynamicVector.GetStride(),
- dynamicVector.GetMin(),
- dynamicVector.GetMax(),
- params.GetQuantBits());
- for(unsigned long d = 0; d < dim; ++d)
- {
- Transform(m_quantVectors + d * num, num);
- }
- #ifdef DEBUG_VERBOSE
- printf("IntArray (%i, %i)\n", num, dim);
- fprintf(g_fileDebugDVEnc, "IntArray (%i, %i)\n", num, dim);
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- printf("%i\t %i \t %i\n", d * num + v, m_quantVectors[d * num + v], IntToUInt(m_quantVectors[d * num + v]));
- fprintf(g_fileDebugDVEnc, "%i\t %i \t %i\n", d * num + v, m_quantVectors[d * num + v], IntToUInt(m_quantVectors[d * num + v]));
- }
- }
- #endif //DEBUG_VERBOSE
-
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- for(unsigned long v = 0; v < num; ++v)
- {
- for(unsigned long d = 0; d < dim; ++d)
- {
- bstream.WriteIntASCII(m_quantVectors[d * num + v]);
- }
- }
- }
- else
- {
- unsigned long encodedBytes = 0;
- unsigned long bestEncodedBytes = O3DGC_MAX_ULONG;
- unsigned long M = 1;
- unsigned long bestM = 1;
- while (M < 1024)
- {
- EncodeAC(num, dim, M, encodedBytes);
- if (encodedBytes > bestEncodedBytes)
- {
- break;
- }
- bestM = M;
- bestEncodedBytes = encodedBytes;
- M *= 2;
- }
- EncodeAC(num, dim, bestM, encodedBytes);
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32(start, bstream.GetSize() - start, m_streamType);
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugDVEnc);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- O3DGCErrorCode DynamicVectorEncoder::Quantize(const Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits)
- {
- const unsigned long size = numFloatArray * dimFloatArray;
- Real r;
- if (m_maxNumVectors < size)
- {
- delete [] m_quantVectors;
- m_maxNumVectors = size;
- m_quantVectors = new long [m_maxNumVectors];
- }
- Real delta;
- for(unsigned long d = 0; d < dimFloatArray; ++d)
- {
- r = maxFloatArray[d] - minFloatArray[d];
- if (r > 0.0f)
- {
- delta = (float)((1 << nQBits) - 1) / r;
- }
- else
- {
- delta = 1.0f;
- }
- for(unsigned long v = 0; v < numFloatArray; ++v)
- {
- m_quantVectors[v + d * numFloatArray] = (long)((floatArray[v * stride + d]-minFloatArray[d]) * delta + 0.5f);
- }
- }
- return O3DGC_OK;
- }
-}
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.h
deleted file mode 100644
index de42a020f..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorEncoder.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_DYNAMIC_VECTOR_ENCODER_H
-#define O3DGC_DYNAMIC_VECTOR_ENCODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcDynamicVector.h"
-
-namespace o3dgc
-{
- //!
- class DynamicVectorEncoder
- {
- public:
- //! Constructor.
- DynamicVectorEncoder(void);
- //! Destructor.
- ~DynamicVectorEncoder(void);
- //!
- O3DGCErrorCode Encode(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream);
- O3DGCStreamType GetStreamType() const { return m_streamType; }
- void SetStreamType(O3DGCStreamType streamType) { m_streamType = streamType; }
-
- private:
- O3DGCErrorCode EncodeHeader(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream);
- O3DGCErrorCode EncodePayload(const DVEncodeParams & params,
- const DynamicVector & dynamicVector,
- BinaryStream & bstream);
- O3DGCErrorCode Quantize(const Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits);
- O3DGCErrorCode EncodeAC(unsigned long num,
- unsigned long dim,
- unsigned long M,
- unsigned long & encodedBytes);
-
- unsigned long m_posSize;
- unsigned long m_sizeBufferAC;
- unsigned long m_maxNumVectors;
- unsigned long m_numVectors;
- unsigned long m_dimVectors;
- unsigned char * m_bufferAC;
- long * m_quantVectors;
- O3DGCStreamType m_streamType;
- };
-}
-#endif // O3DGC_DYNAMIC_VECTOR_ENCODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcFIFO.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcFIFO.h
deleted file mode 100644
index 4a5555f2a..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcFIFO.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_FIFO_H
-#define O3DGC_FIFO_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- //!
- template < typename T > class FIFO
- {
- public:
- //! Constructor.
- FIFO()
- {
- m_buffer = 0;
- m_allocated = 0;
- m_size = 0;
- m_start = 0;
- m_end = 0;
- };
- //! Destructor.
- ~FIFO(void)
- {
- delete [] m_buffer;
- };
- O3DGCErrorCode Allocate(unsigned long size)
- {
- assert(size > 0);
- if (size > m_allocated)
- {
- delete [] m_buffer;
- m_allocated = size;
- m_buffer = new T [m_allocated];
- }
- Clear();
- return O3DGC_OK;
- }
- const T & PopFirst()
- {
- assert(m_size > 0);
- --m_size;
- unsigned long current = m_start++;
- if (m_start == m_allocated)
- {
- m_end = 0;
- }
- return m_buffer[current];
- };
- void PushBack(const T & value)
- {
- assert( m_size < m_allocated);
- m_buffer[m_end] = value;
- ++m_size;
- ++m_end;
- if (m_end == m_allocated)
- {
- m_end = 0;
- }
- }
- unsigned long GetSize() const { return m_size;};
- unsigned long GetAllocatedSize() const { return m_allocated;};
- void Clear() { m_start = m_end = m_size = 0;};
-
- private:
- T * m_buffer;
- unsigned long m_allocated;
- unsigned long m_size;
- unsigned long m_start;
- unsigned long m_end;
- };
-}
-#endif // O3DGC_FIFO_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.h
deleted file mode 100644
index adb8cb001..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.h
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_INDEXED_FACE_SET_H
-#define O3DGC_INDEXED_FACE_SET_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- template<class T>
- class IndexedFaceSet
- {
- public:
- //! Constructor.
- IndexedFaceSet(void)
- {
- memset(this, 0, sizeof(IndexedFaceSet));
- m_ccw = true;
- m_solid = true;
- m_convex = true;
- m_isTriangularMesh = true;
- m_creaseAngle = 30;
- };
- //! Destructor.
- ~IndexedFaceSet(void) {};
-
- unsigned long GetNCoordIndex() const { return m_nCoordIndex ;}
- // only coordIndex is supported
- unsigned long GetNCoord() const { return m_nCoord ;}
- unsigned long GetNNormal() const { return m_nNormal ;}
- unsigned long GetNFloatAttribute(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_nFloatAttribute[a];
- }
- unsigned long GetNIntAttribute(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_nIntAttribute[a];
- }
- unsigned long GetNumFloatAttributes() const { return m_numFloatAttributes;}
- unsigned long GetNumIntAttributes() const { return m_numIntAttributes ;}
- const Real * GetCoordMin () const { return m_coordMin;}
- const Real * GetCoordMax () const { return m_coordMax;}
- const Real * GetNormalMin () const { return m_normalMin;}
- const Real * GetNormalMax () const { return m_normalMax;}
- Real GetCoordMin (int j) const { return m_coordMin[j] ;}
- Real GetCoordMax (int j) const { return m_coordMax[j] ;}
- Real GetNormalMin (int j) const { return m_normalMin[j] ;}
- Real GetNormalMax (int j) const { return m_normalMax[j] ;}
-
- O3DGCIFSFloatAttributeType GetFloatAttributeType(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_typeFloatAttribute[a];
- }
- O3DGCIFSIntAttributeType GetIntAttributeType(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_typeIntAttribute[a];
- }
- unsigned long GetFloatAttributeDim(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_dimFloatAttribute[a];
- }
- unsigned long GetIntAttributeDim(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_dimIntAttribute[a];
- }
- const Real * GetFloatAttributeMin(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return &(m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
- }
- const Real * GetFloatAttributeMax(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return &(m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
- }
- Real GetFloatAttributeMin(unsigned long a, unsigned long dim) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- return m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
- }
- Real GetFloatAttributeMax(unsigned long a, unsigned long dim) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- return m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
- }
- Real GetCreaseAngle() const { return m_creaseAngle ;}
- bool GetCCW() const { return m_ccw ;}
- bool GetSolid() const { return m_solid ;}
- bool GetConvex() const { return m_convex ;}
- bool GetIsTriangularMesh() const { return m_isTriangularMesh;}
- const unsigned long * GetIndexBufferID() const { return m_indexBufferID ;}
- const T * GetCoordIndex() const { return m_coordIndex;}
- T * GetCoordIndex() { return m_coordIndex;}
- Real * GetCoord() const { return m_coord ;}
- Real * GetNormal() const { return m_normal ;}
- Real * GetFloatAttribute(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_floatAttribute[a];
- }
- long * GetIntAttribute(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_intAttribute[a] ;
- }
- // only coordIndex is supported
- void SetNNormalIndex(unsigned long) {}
- void SetNTexCoordIndex(unsigned long) {}
- void SetNFloatAttributeIndex(int, unsigned long) {}
- void SetNIntAttributeIndex (int, unsigned long) {}
- // per triangle attributes not supported
- void SetNormalPerVertex(bool) {}
- void SetColorPerVertex(bool) {}
- void SetFloatAttributePerVertex(int, bool){}
- void SetIntAttributePerVertex (int, bool){}
- void SetNCoordIndex (unsigned long nCoordIndex) { m_nCoordIndex = nCoordIndex;}
- void SetNCoord (unsigned long nCoord) { m_nCoord = nCoord ;}
- void SetNNormal (unsigned long nNormal) { m_nNormal = nNormal ;}
- void SetNumFloatAttributes(unsigned long numFloatAttributes)
- {
- assert(numFloatAttributes < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_numFloatAttributes = numFloatAttributes;
- }
- void SetNumIntAttributes (unsigned long numIntAttributes)
- {
- assert(numIntAttributes < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_numIntAttributes = numIntAttributes;
- }
- void SetCreaseAngle (Real creaseAngle) { m_creaseAngle = creaseAngle ;}
- void SetCCW (bool ccw) { m_ccw = ccw ;}
- void SetSolid (bool solid) { m_solid = solid ;}
- void SetConvex (bool convex) { m_convex = convex ;}
- void SetIsTriangularMesh (bool isTriangularMesh) { m_isTriangularMesh = isTriangularMesh;}
- void SetCoordMin (int j, Real min) { m_coordMin[j] = min;}
- void SetCoordMax (int j, Real max) { m_coordMax[j] = max;}
- void SetNormalMin (int j, Real min) { m_normalMin[j] = min;}
- void SetNormalMax (int j, Real max) { m_normalMax[j] = max;}
- void SetNFloatAttribute(unsigned long a, unsigned long nFloatAttribute)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_nFloatAttribute[a] = nFloatAttribute;
- }
- void SetNIntAttribute(unsigned long a, unsigned long nIntAttribute)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_nIntAttribute[a] = nIntAttribute;
- }
- void SetFloatAttributeDim(unsigned long a, unsigned long d)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_dimFloatAttribute[a] = d;
- }
- void SetIntAttributeDim(unsigned long a, unsigned long d)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_dimIntAttribute[a] = d;
- }
- void SetFloatAttributeType(unsigned long a, O3DGCIFSFloatAttributeType t)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_typeFloatAttribute[a] = t;
- }
- void SetIntAttributeType(unsigned long a, O3DGCIFSIntAttributeType t)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_typeIntAttribute[a] = t;
- }
- void SetFloatAttributeMin(unsigned long a, unsigned long dim, Real min)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = min;
- }
- void SetFloatAttributeMax(unsigned long a, unsigned long dim, Real max)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = max;
- }
- void SetIndexBufferID (unsigned long * const indexBufferID) { m_indexBufferID = indexBufferID;}
- void SetCoordIndex (T * const coordIndex) { m_coordIndex = coordIndex;}
- void SetCoord (Real * const coord ) { m_coord = coord ;}
- void SetNormal (Real * const normal ) { m_normal = normal ;}
- void SetFloatAttribute (unsigned long a, Real * const floatAttribute)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_floatAttribute[a] = floatAttribute;
- }
- void SetIntAttribute (unsigned long a, long * const intAttribute)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_intAttribute[a] = intAttribute ;
- }
- void ComputeMinMax(O3DGCSC3DMCQuantizationMode quantMode);
-
- private:
- // triangles list
- unsigned long m_nCoordIndex;
- T * m_coordIndex;
- unsigned long * m_indexBufferID;
- // coord, normals, texcoord and color
- unsigned long m_nCoord;
- unsigned long m_nNormal;
- Real m_coordMin [3];
- Real m_coordMax [3];
- Real m_normalMin [3];
- Real m_normalMax [3];
- Real * m_coord;
- Real * m_normal;
- // other attributes
- unsigned long m_numFloatAttributes;
- unsigned long m_numIntAttributes;
- O3DGCIFSFloatAttributeType m_typeFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- O3DGCIFSIntAttributeType m_typeIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
- unsigned long m_nFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- unsigned long m_nIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
- unsigned long m_dimFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- unsigned long m_dimIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
- Real m_minFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
- Real m_maxFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
- Real * m_floatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- long * m_intAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- // mesh info
- Real m_creaseAngle;
- bool m_ccw;
- bool m_solid;
- bool m_convex;
- bool m_isTriangularMesh;
- };
-}
-#include "o3dgcIndexedFaceSet.inl" // template implementation
-#endif // O3DGC_INDEXED_FACE_SET_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.inl
deleted file mode 100644
index ddac26d76..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcIndexedFaceSet.inl
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_INDEXED_FACE_SET_INL
-#define O3DGC_INDEXED_FACE_SET_INL
-
-#include <math.h>
-namespace o3dgc
-{
- template <class T>
- void IndexedFaceSet<T>::ComputeMinMax(O3DGCSC3DMCQuantizationMode quantMode)
- {
- ComputeVectorMinMax(m_coord , m_nCoord , 3, 3, m_coordMin , m_coordMax , quantMode);
- ComputeVectorMinMax(m_normal , m_nNormal , 3, 3, m_normalMin , m_normalMax , quantMode);
- unsigned long numFloatAttributes = GetNumFloatAttributes();
- for(unsigned long a = 0; a < numFloatAttributes; ++a)
- {
- ComputeVectorMinMax(m_floatAttribute[a],
- m_nFloatAttribute[a],
- m_dimFloatAttribute[a],
- m_dimFloatAttribute[a], // stride
- m_minFloatAttribute + (a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES),
- m_maxFloatAttribute + (a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES), quantMode);
- }
- }
-}
-#endif // O3DGC_INDEXED_FACE_SET_INL
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.h
deleted file mode 100644
index f3f1617c4..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_SC3DMC_DECODER_H
-#define O3DGC_SC3DMC_DECODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcIndexedFaceSet.h"
-#include "o3dgcSC3DMCEncodeParams.h"
-#include "o3dgcTriangleListDecoder.h"
-
-namespace o3dgc
-{
- //!
- template <class T>
- class SC3DMCDecoder
- {
- public:
- //! Constructor.
- SC3DMCDecoder(void)
- {
- m_iterator = 0;
- m_streamSize = 0;
- m_quantFloatArray = 0;
- m_quantFloatArraySize = 0;
- m_normals = 0;
- m_normalsSize = 0;
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- };
- //! Destructor.
- ~SC3DMCDecoder(void)
- {
- delete [] m_normals;
- delete [] m_quantFloatArray;
- }
- //!
- O3DGCErrorCode DecodeHeader(IndexedFaceSet<T> & ifs,
- const BinaryStream & bstream);
- //!
- O3DGCErrorCode DecodePayload(IndexedFaceSet<T> & ifs,
- const BinaryStream & bstream);
- const SC3DMCStats & GetStats() const { return m_stats;}
- unsigned long GetIterator() const { return m_iterator;}
- O3DGCErrorCode SetIterator(unsigned long iterator) { m_iterator = iterator; return O3DGC_OK; }
-
-
- private:
- O3DGCErrorCode DecodeFloatArray(Real * const floatArray,
- unsigned long numfloatArraySize,
- unsigned long dimfloatArraySize,
- unsigned long stride,
- const Real * const minfloatArray,
- const Real * const maxfloatArray,
- unsigned long nQBits,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode & predMode,
- const BinaryStream & bstream);
- O3DGCErrorCode IQuantizeFloatArray(Real * const floatArray,
- unsigned long numfloatArraySize,
- unsigned long dimfloatArraySize,
- unsigned long stride,
- const Real * const minfloatArray,
- const Real * const maxfloatArray,
- unsigned long nQBits);
- O3DGCErrorCode DecodeIntArray(long * const intArray,
- unsigned long numIntArraySize,
- unsigned long dimIntArraySize,
- unsigned long stride,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode & predMode,
- const BinaryStream & bstream);
- O3DGCErrorCode ProcessNormals(const IndexedFaceSet<T> & ifs);
-
- unsigned long m_iterator;
- unsigned long m_streamSize;
- SC3DMCEncodeParams m_params;
- TriangleListDecoder<T> m_triangleListDecoder;
- long * m_quantFloatArray;
- unsigned long m_quantFloatArraySize;
- Vector<char> m_orientation;
- Real * m_normals;
- unsigned long m_normalsSize;
- SC3DMCStats m_stats;
- O3DGCStreamType m_streamType;
- };
-}
-#include "o3dgcSC3DMCDecoder.inl" // template implementation
-#endif // O3DGC_SC3DMC_DECODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.inl
deleted file mode 100644
index aa6f24b73..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCDecoder.inl
+++ /dev/null
@@ -1,850 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_SC3DMC_DECODER_INL
-#define O3DGC_SC3DMC_DECODER_INL
-
-#include "o3dgcArithmeticCodec.h"
-#include "o3dgcTimer.h"
-
-//#define DEBUG_VERBOSE
-
-namespace o3dgc
-{
-#ifdef DEBUG_VERBOSE
- FILE * g_fileDebugSC3DMCDec = NULL;
-#endif //DEBUG_VERBOSE
-
- template<class T>
- O3DGCErrorCode SC3DMCDecoder<T>::DecodeHeader(IndexedFaceSet<T> & ifs,
- const BinaryStream & bstream)
- {
- unsigned long iterator0 = m_iterator;
- unsigned long start_code = bstream.ReadUInt32(m_iterator, O3DGC_STREAM_TYPE_BINARY);
- if (start_code != O3DGC_SC3DMC_START_CODE)
- {
- m_iterator = iterator0;
- start_code = bstream.ReadUInt32(m_iterator, O3DGC_STREAM_TYPE_ASCII);
- if (start_code != O3DGC_SC3DMC_START_CODE)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- else
- {
- m_streamType = O3DGC_STREAM_TYPE_ASCII;
- }
- }
- else
- {
- m_streamType = O3DGC_STREAM_TYPE_BINARY;
- }
-
- m_streamSize = bstream.ReadUInt32(m_iterator, m_streamType);
- m_params.SetEncodeMode( (O3DGCSC3DMCEncodingMode) bstream.ReadUChar(m_iterator, m_streamType));
-
- ifs.SetCreaseAngle((Real) bstream.ReadFloat32(m_iterator, m_streamType));
-
- unsigned char mask = bstream.ReadUChar(m_iterator, m_streamType);
-
- ifs.SetCCW ((mask & 1) == 1);
- ifs.SetSolid ((mask & 2) == 1);
- ifs.SetConvex ((mask & 4) == 1);
- ifs.SetIsTriangularMesh((mask & 8) == 1);
- //bool markerBit0 = (mask & 16 ) == 1;
- //bool markerBit1 = (mask & 32 ) == 1;
- //bool markerBit2 = (mask & 64 ) == 1;
- //bool markerBit3 = (mask & 128) == 1;
-
- ifs.SetNCoord (bstream.ReadUInt32(m_iterator, m_streamType));
- ifs.SetNNormal (bstream.ReadUInt32(m_iterator, m_streamType));
-
-
- ifs.SetNumFloatAttributes(bstream.ReadUInt32(m_iterator, m_streamType));
- ifs.SetNumIntAttributes (bstream.ReadUInt32(m_iterator, m_streamType));
-
- if (ifs.GetNCoord() > 0)
- {
- ifs.SetNCoordIndex(bstream.ReadUInt32(m_iterator, m_streamType));
- for(int j=0 ; j<3 ; ++j)
- {
- ifs.SetCoordMin(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- ifs.SetCoordMax(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- }
- m_params.SetCoordQuantBits( bstream.ReadUChar(m_iterator, m_streamType) );
- }
- if (ifs.GetNNormal() > 0)
- {
- ifs.SetNNormalIndex(bstream.ReadUInt32(m_iterator, m_streamType));
- for(int j=0 ; j<3 ; ++j)
- {
- ifs.SetNormalMin(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- ifs.SetNormalMax(j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- }
- ifs.SetNormalPerVertex(bstream.ReadUChar(m_iterator, m_streamType) == 1);
- m_params.SetNormalQuantBits(bstream.ReadUChar(m_iterator, m_streamType));
- }
-
- for(unsigned long a = 0; a < ifs.GetNumFloatAttributes(); ++a)
- {
- ifs.SetNFloatAttribute(a, bstream.ReadUInt32(m_iterator, m_streamType));
- if (ifs.GetNFloatAttribute(a) > 0)
- {
- ifs.SetNFloatAttributeIndex(a, bstream.ReadUInt32(m_iterator, m_streamType));
- unsigned char d = bstream.ReadUChar(m_iterator, m_streamType);
- ifs.SetFloatAttributeDim(a, d);
- for(unsigned char j = 0 ; j < d ; ++j)
- {
- ifs.SetFloatAttributeMin(a, j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- ifs.SetFloatAttributeMax(a, j, (Real) bstream.ReadFloat32(m_iterator, m_streamType));
- }
- ifs.SetFloatAttributePerVertex(a, bstream.ReadUChar(m_iterator, m_streamType) == 1);
- ifs.SetFloatAttributeType(a, (O3DGCIFSFloatAttributeType) bstream.ReadUChar(m_iterator, m_streamType));
- m_params.SetFloatAttributeQuantBits(a, bstream.ReadUChar(m_iterator, m_streamType));
- }
- }
- for(unsigned long a = 0; a < ifs.GetNumIntAttributes(); ++a)
- {
- ifs.SetNIntAttribute(a, bstream.ReadUInt32(m_iterator, m_streamType));
- if (ifs.GetNIntAttribute(a) > 0)
- {
- ifs.SetNIntAttributeIndex(a, bstream.ReadUInt32(m_iterator, m_streamType));
- ifs.SetIntAttributeDim(a, bstream.ReadUChar(m_iterator, m_streamType));
- ifs.SetIntAttributePerVertex(a, bstream.ReadUChar(m_iterator, m_streamType) == 1);
- ifs.SetIntAttributeType(a, (O3DGCIFSIntAttributeType) bstream.ReadUChar(m_iterator, m_streamType));
- }
- }
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode SC3DMCDecoder<T>::DecodePayload(IndexedFaceSet<T> & ifs,
- const BinaryStream & bstream)
- {
- O3DGCErrorCode ret = O3DGC_OK;
-#ifdef DEBUG_VERBOSE
- g_fileDebugSC3DMCDec = fopen("tfans_dec_main.txt", "w");
-#endif //DEBUG_VERBOSE
-
- m_triangleListDecoder.SetStreamType(m_streamType);
- m_stats.m_streamSizeCoordIndex = m_iterator;
- Timer timer;
- timer.Tic();
- m_triangleListDecoder.Decode(ifs.GetCoordIndex(), ifs.GetNCoordIndex(), ifs.GetNCoord(), bstream, m_iterator);
- timer.Toc();
- m_stats.m_timeCoordIndex = timer.GetElapsedTime();
- m_stats.m_streamSizeCoordIndex = m_iterator - m_stats.m_streamSizeCoordIndex;
-
- // decode coord
- m_stats.m_streamSizeCoord = m_iterator;
- timer.Tic();
- if (ifs.GetNCoord() > 0)
- {
- ret = DecodeFloatArray(ifs.GetCoord(), ifs.GetNCoord(), 3, 3, ifs.GetCoordMin(), ifs.GetCoordMax(),
- m_params.GetCoordQuantBits(), ifs, m_params.GetCoordPredMode(), bstream);
- }
- if (ret != O3DGC_OK)
- {
- return ret;
- }
- timer.Toc();
- m_stats.m_timeCoord = timer.GetElapsedTime();
- m_stats.m_streamSizeCoord = m_iterator - m_stats.m_streamSizeCoord;
-
- // decode Normal
- m_stats.m_streamSizeNormal = m_iterator;
- timer.Tic();
- if (ifs.GetNNormal() > 0)
- {
- DecodeFloatArray(ifs.GetNormal(), ifs.GetNNormal(), 3, 3, ifs.GetNormalMin(), ifs.GetNormalMax(),
- m_params.GetNormalQuantBits(), ifs, m_params.GetNormalPredMode(), bstream);
- }
- if (ret != O3DGC_OK)
- {
- return ret;
- }
- timer.Toc();
- m_stats.m_timeNormal = timer.GetElapsedTime();
- m_stats.m_streamSizeNormal = m_iterator - m_stats.m_streamSizeNormal;
-
- // decode FloatAttributes
- for(unsigned long a = 0; a < ifs.GetNumFloatAttributes(); ++a)
- {
- m_stats.m_streamSizeFloatAttribute[a] = m_iterator;
- timer.Tic();
- DecodeFloatArray(ifs.GetFloatAttribute(a), ifs.GetNFloatAttribute(a), ifs.GetFloatAttributeDim(a), ifs.GetFloatAttributeDim(a),
- ifs.GetFloatAttributeMin(a), ifs.GetFloatAttributeMax(a),
- m_params.GetFloatAttributeQuantBits(a), ifs, m_params.GetFloatAttributePredMode(a), bstream);
- timer.Toc();
- m_stats.m_timeFloatAttribute[a] = timer.GetElapsedTime();
- m_stats.m_streamSizeFloatAttribute[a] = m_iterator - m_stats.m_streamSizeFloatAttribute[a];
- }
- if (ret != O3DGC_OK)
- {
- return ret;
- }
-
- // decode IntAttributes
- for(unsigned long a = 0; a < ifs.GetNumIntAttributes(); ++a)
- {
- m_stats.m_streamSizeIntAttribute[a] = m_iterator;
- timer.Tic();
- DecodeIntArray(ifs.GetIntAttribute(a), ifs.GetNIntAttribute(a), ifs.GetIntAttributeDim(a), ifs.GetIntAttributeDim(a),
- ifs, m_params.GetIntAttributePredMode(a), bstream);
- timer.Toc();
- m_stats.m_timeIntAttribute[a] = timer.GetElapsedTime();
- m_stats.m_streamSizeIntAttribute[a] = m_iterator - m_stats.m_streamSizeIntAttribute[a];
- }
- if (ret != O3DGC_OK)
- {
- return ret;
- }
-
- timer.Tic();
- m_triangleListDecoder.Reorder();
- timer.Toc();
- m_stats.m_timeReorder = timer.GetElapsedTime();
-
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugSC3DMCDec);
-#endif //DEBUG_VERBOSE
- return ret;
- }
- template<class T>
- O3DGCErrorCode SC3DMCDecoder<T>::DecodeIntArray(long * const intArray,
- unsigned long numIntArray,
- unsigned long dimIntArray,
- unsigned long stride,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode & predMode,
- const BinaryStream & bstream)
- {
- assert(dimIntArray < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- long predResidual;
- SC3DMCPredictor m_neighbors [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
- Arithmetic_Codec acd;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- Adaptive_Data_Model mModelPreds(O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS+1);
- unsigned long nPred;
-
- const AdjacencyInfo & v2T = m_triangleListDecoder.GetVertexToTriangle();
- const T * const triangles = ifs.GetCoordIndex();
- const long nvert = (long) numIntArray;
- unsigned char * buffer = 0;
- unsigned long start = m_iterator;
- unsigned long streamSize = bstream.ReadUInt32(m_iterator, m_streamType); // bitsream size
- unsigned char mask = bstream.ReadUChar(m_iterator, m_streamType);
- O3DGCSC3DMCBinarization binarization = (O3DGCSC3DMCBinarization)((mask >> 4) & 7);
- predMode = (O3DGCSC3DMCPredictionMode)(mask & 7);
- streamSize -= (m_iterator - start);
- unsigned long iteratorPred = m_iterator + streamSize;
- unsigned int exp_k = 0;
- unsigned int M = 0;
- if (m_streamType != O3DGC_STREAM_TYPE_ASCII)
- {
- if (binarization != O3DGC_SC3DMC_BINARIZATION_AC_EGC)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- bstream.GetBuffer(m_iterator, buffer);
- m_iterator += streamSize;
- acd.set_buffer(streamSize, buffer);
- acd.start_decoder();
- exp_k = acd.ExpGolombDecode(0, bModel0, bModel1);
- M = acd.ExpGolombDecode(0, bModel0, bModel1);
- }
- else
- {
- if (binarization != O3DGC_SC3DMC_BINARIZATION_ASCII)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- bstream.ReadUInt32(iteratorPred, m_streamType); // predictors bitsream size
- }
- Adaptive_Data_Model mModelValues(M+2);
-
-#ifdef DEBUG_VERBOSE
- printf("IntArray (%i, %i)\n", numIntArray, dimIntArray);
- fprintf(g_fileDebugSC3DMCDec, "IntArray (%i, %i)\n", numIntArray, dimIntArray);
-#endif //DEBUG_VERBOSE
-
- for (long v=0; v < nvert; ++v)
- {
- nPred = 0;
- if ( v2T.GetNumNeighbors(v) > 0 &&
- predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- if (ta < 0)
- {
- break;
- }
- for(long k = 0; k < 3; ++k)
- {
- long w = triangles[ta*3 + k];
- if ( w < v )
- {
- SC3DMCTriplet id = {-1, -1, w};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- m_neighbors[p].m_pred[i] = intArray[w*stride+i];
- }
- }
- }
- }
- }
- }
- if (nPred > 1)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t vm %i\n", v);
- fprintf(g_fileDebugSC3DMCDec, "\t\t vm %i\n", v);
- for (unsigned long p = 0; p < nPred; ++p)
- {
- printf("\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- fprintf(g_fileDebugSC3DMCDec, "\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- for (unsigned long i = 0; i < dimIntArray; ++i)
- {
- printf("\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- fprintf(g_fileDebugSC3DMCDec, "\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- }
- }
-#endif //DEBUG_VERBOSE
- unsigned long bestPred;
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bestPred = bstream.ReadUCharASCII(iteratorPred);
- }
- else
- {
- bestPred = acd.decode(mModelPreds);
- }
-#ifdef DEBUG_VERBOSE1
- printf("best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
- fprintf(g_fileDebugSC3DMCDec, "best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
-#endif //DEBUG_VERBOSE
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- intArray[v*stride+i] = predResidual + m_neighbors[bestPred].m_pred[i];
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i \t [%i]\n", v*dimIntArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i \t [%i]\n", v*dimIntArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
-#endif //DEBUG_VERBOSE
- }
- }
- else if (v > 0 && predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- intArray[v*stride+i] = predResidual + intArray[(v-1)*stride+i];
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", v*dimIntArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i\n", v*dimIntArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- else
- {
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadUIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeUIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- intArray[v*stride+i] = predResidual;
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", v*dimIntArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i\n", v*dimIntArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- }
- m_iterator = iteratorPred;
-#ifdef DEBUG_VERBOSE
- fflush(g_fileDebugSC3DMCDec);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode SC3DMCDecoder<T>::ProcessNormals(const IndexedFaceSet<T> & ifs)
- {
- const long nvert = (long) ifs.GetNNormal();
- const unsigned long normalSize = ifs.GetNNormal() * 2;
- if (m_normalsSize < normalSize)
- {
- delete [] m_normals;
- m_normalsSize = normalSize;
- m_normals = new Real [normalSize];
- }
- const AdjacencyInfo & v2T = m_triangleListDecoder.GetVertexToTriangle();
- const T * const triangles = ifs.GetCoordIndex();
- Vec3<long> p1, p2, p3, n0, nt;
- long na0 = 0, nb0 = 0;
- Real rna0, rnb0, norm0;
- char ni0 = 0, ni1 = 0;
- long a, b, c;
- for (long v=0; v < nvert; ++v)
- {
- n0.X() = 0;
- n0.Y() = 0;
- n0.Z() = 0;
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- if (ta == -1)
- {
- break;
- }
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 1];
- c = triangles[ta*3 + 2];
- p1.X() = m_quantFloatArray[3*a];
- p1.Y() = m_quantFloatArray[3*a+1];
- p1.Z() = m_quantFloatArray[3*a+2];
- p2.X() = m_quantFloatArray[3*b];
- p2.Y() = m_quantFloatArray[3*b+1];
- p2.Z() = m_quantFloatArray[3*b+2];
- p3.X() = m_quantFloatArray[3*c];
- p3.Y() = m_quantFloatArray[3*c+1];
- p3.Z() = m_quantFloatArray[3*c+2];
- nt = (p2-p1)^(p3-p1);
- n0 += nt;
- }
- norm0 = (Real) n0.GetNorm();
- if (norm0 == 0.0)
- {
- norm0 = 1.0;
- }
- SphereToCube(n0.X(), n0.Y(), n0.Z(), na0, nb0, ni0);
-
-
- rna0 = na0 / norm0;
- rnb0 = nb0 / norm0;
- ni1 = ni0 + m_orientation[v];
- m_orientation[v] = ni1;
- if ( (ni1 >> 1) != (ni0 >> 1) )
- {
- rna0 = Real(0.0);
- rnb0 = Real(0.0);
- }
- m_normals[2*v] = rna0;
- m_normals[2*v+1] = rnb0;
-
-#ifdef DEBUG_VERBOSE1
- printf("n0 \t %i \t %i \t %i \t %i (%f, %f)\n", v, n0.X(), n0.Y(), n0.Z(), rna0, rnb0);
- fprintf(g_fileDebugSC3DMCDec, "n0 \t %i \t %i \t %i \t %i (%f, %f)\n", v, n0.X(), n0.Y(), n0.Z(), rna0, rnb0);
-#endif //DEBUG_VERBOSE
-
- }
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode SC3DMCDecoder<T>::DecodeFloatArray(Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode & predMode,
- const BinaryStream & bstream)
- {
- assert(dimFloatArray < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- long predResidual;
- SC3DMCPredictor m_neighbors [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
- Arithmetic_Codec acd;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- Adaptive_Data_Model mModelPreds(O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS+1);
- unsigned long nPred;
-
- const AdjacencyInfo & v2T = m_triangleListDecoder.GetVertexToTriangle();
- const T * const triangles = ifs.GetCoordIndex();
- const long nvert = (long) numFloatArray;
- const unsigned long size = numFloatArray * dimFloatArray;
- unsigned char * buffer = 0;
- unsigned long start = m_iterator;
- unsigned long streamSize = bstream.ReadUInt32(m_iterator, m_streamType); // bitsream size
- unsigned char mask = bstream.ReadUChar(m_iterator, m_streamType);
- O3DGCSC3DMCBinarization binarization = (O3DGCSC3DMCBinarization)((mask >> 4) & 7);
- predMode = (O3DGCSC3DMCPredictionMode)(mask & 7);
- streamSize -= (m_iterator - start);
- unsigned long iteratorPred = m_iterator + streamSize;
- unsigned int exp_k = 0;
- unsigned int M = 0;
- if (m_streamType != O3DGC_STREAM_TYPE_ASCII)
- {
- if (binarization != O3DGC_SC3DMC_BINARIZATION_AC_EGC)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- bstream.GetBuffer(m_iterator, buffer);
- m_iterator += streamSize;
- acd.set_buffer(streamSize, buffer);
- acd.start_decoder();
- exp_k = acd.ExpGolombDecode(0, bModel0, bModel1);
- M = acd.ExpGolombDecode(0, bModel0, bModel1);
- }
- else
- {
- if (binarization != O3DGC_SC3DMC_BINARIZATION_ASCII)
- {
- return O3DGC_ERROR_CORRUPTED_STREAM;
- }
- bstream.ReadUInt32(iteratorPred, m_streamType); // predictors bitsream size
- }
- Adaptive_Data_Model mModelValues(M+2);
-
-
- if (predMode == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION)
- {
- m_orientation.Allocate(size);
- m_orientation.Clear();
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- for(unsigned long i = 0; i < numFloatArray; ++i)
- {
- m_orientation.PushBack((unsigned char) bstream.ReadIntASCII(m_iterator));
- }
- }
- else
- {
- Adaptive_Data_Model dModel(12);
- for(unsigned long i = 0; i < numFloatArray; ++i)
- {
- m_orientation.PushBack((unsigned char) UIntToInt(acd.decode(dModel)));
- }
- }
- ProcessNormals(ifs);
- dimFloatArray = 2;
- }
-#ifdef DEBUG_VERBOSE
- printf("FloatArray (%i, %i)\n", numFloatArray, dimFloatArray);
- fprintf(g_fileDebugSC3DMCDec, "FloatArray (%i, %i)\n", numFloatArray, dimFloatArray);
-#endif //DEBUG_VERBOSE
-
- if (m_quantFloatArraySize < size)
- {
- delete [] m_quantFloatArray;
- m_quantFloatArraySize = size;
- m_quantFloatArray = new long [size];
- }
- for (long v=0; v < nvert; ++v)
- {
- nPred = 0;
- if ( v2T.GetNumNeighbors(v) > 0 &&
- predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- if (ta < 0)
- {
- break;
- }
- if (predMode == O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION)
- {
- long a,b;
- if ((long) triangles[ta*3] == v)
- {
- a = triangles[ta*3 + 1];
- b = triangles[ta*3 + 2];
- }
- else if ((long)triangles[ta*3 + 1] == v)
- {
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 2];
- }
- else
- {
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 1];
- }
- if ( a < v && b < v)
- {
- int u0 = v2T.Begin(a);
- int u1 = v2T.End(a);
- for (long u = u0; u < u1; u++)
- {
- long tb = v2T.GetNeighbor(u);
- if (tb < 0)
- {
- break;
- }
- long c = -1;
- bool foundB = false;
- for(long k = 0; k < 3; ++k)
- {
- long x = triangles[tb*3 + k];
- if (x == b)
- {
- foundB = true;
- }
- if (x < v && x != a && x != b)
- {
- c = x;
- }
- }
- if (c != -1 && foundB)
- {
- SC3DMCTriplet id = {min(a, b), max(a, b), -c-1};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- m_neighbors[p].m_pred[i] = m_quantFloatArray[a*stride+i] +
- m_quantFloatArray[b*stride+i] -
- m_quantFloatArray[c*stride+i];
- }
- }
- }
- }
- }
- }
- if ( predMode == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION ||
- predMode == O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION ||
- predMode == O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION )
- {
- for(long k = 0; k < 3; ++k)
- {
- long w = triangles[ta*3 + k];
- if ( w < v )
- {
- SC3DMCTriplet id = {-1, -1, w};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- m_neighbors[p].m_pred[i] = m_quantFloatArray[w*stride+i];
- }
- }
- }
- }
- }
- }
- }
- if (nPred > 1)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t vm %i\n", v);
- fprintf(g_fileDebugSC3DMCDec, "\t\t vm %i\n", v);
- for (unsigned long p = 0; p < nPred; ++p)
- {
- printf("\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- fprintf(g_fileDebugSC3DMCDec, "\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- for (unsigned long i = 0; i < dimFloatArray; ++i)
- {
- printf("\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- fprintf(g_fileDebugSC3DMCDec, "\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- }
- }
-#endif //DEBUG_VERBOSE
- unsigned long bestPred;
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bestPred = bstream.ReadUCharASCII(iteratorPred);
- }
- else
- {
- bestPred = acd.decode(mModelPreds);
- }
-#ifdef DEBUG_VERBOSE1
- printf("best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
- fprintf(g_fileDebugSC3DMCDec, "best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
-#endif //DEBUG_VERBOSE
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- m_quantFloatArray[v*stride+i] = predResidual + m_neighbors[bestPred].m_pred[i];
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i \t [%i]\n", v*dimFloatArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i \t [%i]\n", v*dimFloatArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
-#endif //DEBUG_VERBOSE
- }
- }
- else if (v > 0 && predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- m_quantFloatArray[v*stride+i] = predResidual + m_quantFloatArray[(v-1)*stride+i];
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", v*dimFloatArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i\n", v*dimFloatArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- else
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- predResidual = bstream.ReadUIntASCII(m_iterator);
- }
- else
- {
- predResidual = DecodeUIntACEGC(acd, mModelValues, bModel0, bModel1, exp_k, M);
- }
- m_quantFloatArray[v*stride+i] = predResidual;
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", v*dimFloatArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCDec, "%i \t %i\n", v*dimFloatArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- }
- m_iterator = iteratorPred;
- if (predMode == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION)
- {
- const Real minNormal[2] = {(Real)(-2),(Real)(-2)};
- const Real maxNormal[2] = {(Real)(2),(Real)(2)};
- Real na1, nb1;
- Real na0, nb0;
- char ni1;
- IQuantizeFloatArray(floatArray, numFloatArray, dimFloatArray, stride, minNormal, maxNormal, nQBits+1);
- for (long v=0; v < nvert; ++v)
- {
- na0 = m_normals[2*v];
- nb0 = m_normals[2*v+1];
- na1 = floatArray[stride*v] + na0;
- nb1 = floatArray[stride*v+1] + nb0;
- ni1 = m_orientation[v];
-
- CubeToSphere(na1, nb1, ni1,
- floatArray[stride*v],
- floatArray[stride*v+1],
- floatArray[stride*v+2]);
-
-#ifdef DEBUG_VERBOSE1
- printf("normal \t %i \t %f \t %f \t %f \t (%i, %f, %f) \t (%f, %f)\n",
- v,
- floatArray[stride*v],
- floatArray[stride*v+1],
- floatArray[stride*v+2],
- ni1, na1, nb1,
- na0, nb0);
- fprintf(g_fileDebugSC3DMCDec, "normal \t %i \t %f \t %f \t %f \t (%i, %f, %f) \t (%f, %f)\n",
- v,
- floatArray[stride*v],
- floatArray[stride*v+1],
- floatArray[stride*v+2],
- ni1, na1, nb1,
- na0, nb0);
-#endif //DEBUG_VERBOSE
- }
- }
- else
- {
- IQuantizeFloatArray(floatArray, numFloatArray, dimFloatArray, stride, minFloatArray, maxFloatArray, nQBits);
- }
-#ifdef DEBUG_VERBOSE
- fflush(g_fileDebugSC3DMCDec);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode SC3DMCDecoder<T>::IQuantizeFloatArray(Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits)
- {
-
- Real idelta[O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
- Real r;
- for(unsigned long d = 0; d < dimFloatArray; d++)
- {
- r = maxFloatArray[d] - minFloatArray[d];
- if (r > 0.0f)
- {
- idelta[d] = r/(float)((1 << nQBits) - 1);
- }
- else
- {
- idelta[d] = 1.0f;
- }
- }
- for(unsigned long v = 0; v < numFloatArray; ++v)
- {
- for(unsigned long d = 0; d < dimFloatArray; ++d)
- {
-// floatArray[v * stride + d] = m_quantFloatArray[v * stride + d];
- floatArray[v * stride + d] = m_quantFloatArray[v * stride + d] * idelta[d] + minFloatArray[d];
- }
- }
- return O3DGC_OK;
- }
-}
-#endif // O3DGC_SC3DMC_DECODER_INL
-
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncodeParams.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncodeParams.h
deleted file mode 100644
index 5f3db969c..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncodeParams.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_SC3DMC_ENCODE_PARAMS_H
-#define O3DGC_SC3DMC_ENCODE_PARAMS_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- class SC3DMCEncodeParams
- {
- public:
- //! Constructor.
- SC3DMCEncodeParams(void)
- {
- memset(this, 0, sizeof(SC3DMCEncodeParams));
- m_encodeMode = O3DGC_SC3DMC_ENCODE_MODE_TFAN;
- m_streamTypeMode = O3DGC_STREAM_TYPE_ASCII;
- m_coordQuantBits = 14;
- m_normalQuantBits = 8;
- m_coordPredMode = O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION;
- m_normalPredMode = O3DGC_SC3DMC_SURF_NORMALS_PREDICTION;
- for(unsigned long a = 0; a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES; ++a)
- {
- m_floatAttributePredMode[a] = O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION;
- }
- for(unsigned long a = 0; a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES; ++a)
- {
- m_intAttributePredMode[a] = O3DGC_SC3DMC_NO_PREDICTION;
- }
- };
- //! Destructor.
- ~SC3DMCEncodeParams(void) {};
-
- O3DGCStreamType GetStreamType() const { return m_streamTypeMode;}
- O3DGCSC3DMCEncodingMode GetEncodeMode() const { return m_encodeMode;}
-
- unsigned long GetNumFloatAttributes() const { return m_numFloatAttributes;}
- unsigned long GetNumIntAttributes() const { return m_numIntAttributes;}
- unsigned long GetCoordQuantBits() const { return m_coordQuantBits;}
- unsigned long GetNormalQuantBits() const { return m_normalQuantBits;}
- unsigned long GetFloatAttributeQuantBits(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_floatAttributeQuantBits[a];
- }
- O3DGCSC3DMCPredictionMode GetCoordPredMode() const { return m_coordPredMode; }
- O3DGCSC3DMCPredictionMode GetNormalPredMode() const { return m_normalPredMode; }
- O3DGCSC3DMCPredictionMode GetFloatAttributePredMode(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_floatAttributePredMode[a];
- }
- O3DGCSC3DMCPredictionMode GetIntAttributePredMode(unsigned long a) const
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_intAttributePredMode[a];
- }
- O3DGCSC3DMCPredictionMode & GetCoordPredMode() { return m_coordPredMode; }
- O3DGCSC3DMCPredictionMode & GetNormalPredMode() { return m_normalPredMode; }
- O3DGCSC3DMCPredictionMode & GetFloatAttributePredMode(unsigned long a)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- return m_floatAttributePredMode[a];
- }
- O3DGCSC3DMCPredictionMode & GetIntAttributePredMode(unsigned long a)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- return m_intAttributePredMode[a];
- }
- void SetStreamType(O3DGCStreamType streamTypeMode) { m_streamTypeMode = streamTypeMode;}
- void SetEncodeMode(O3DGCSC3DMCEncodingMode encodeMode) { m_encodeMode = encodeMode;}
- void SetNumFloatAttributes(unsigned long numFloatAttributes)
- {
- assert(numFloatAttributes < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_numFloatAttributes = numFloatAttributes;
- }
- void SetNumIntAttributes (unsigned long numIntAttributes)
- {
- assert(numIntAttributes < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_numIntAttributes = numIntAttributes;
- }
- void SetCoordQuantBits (unsigned int coordQuantBits ) { m_coordQuantBits = coordQuantBits ; }
- void SetNormalQuantBits (unsigned int normalQuantBits ) { m_normalQuantBits = normalQuantBits ; }
- void SetFloatAttributeQuantBits(unsigned long a, unsigned long q)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_floatAttributeQuantBits[a] = q;
- }
- void SetCoordPredMode (O3DGCSC3DMCPredictionMode coordPredMode ) { m_coordPredMode = coordPredMode ; }
- void SetNormalPredMode (O3DGCSC3DMCPredictionMode normalPredMode ) { m_normalPredMode = normalPredMode ; }
- void SetFloatAttributePredMode(unsigned long a, O3DGCSC3DMCPredictionMode p)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
- m_floatAttributePredMode[a] = p;
- }
- void SetIntAttributePredMode(unsigned long a, O3DGCSC3DMCPredictionMode p)
- {
- assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
- m_intAttributePredMode[a] = p;
- }
- private:
- unsigned long m_numFloatAttributes;
- unsigned long m_numIntAttributes;
- unsigned long m_coordQuantBits;
- unsigned long m_normalQuantBits;
- unsigned long m_floatAttributeQuantBits[O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
-
- O3DGCSC3DMCPredictionMode m_coordPredMode;
- O3DGCSC3DMCPredictionMode m_normalPredMode;
- O3DGCSC3DMCPredictionMode m_floatAttributePredMode[O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
- O3DGCSC3DMCPredictionMode m_intAttributePredMode [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES];
- O3DGCStreamType m_streamTypeMode;
- O3DGCSC3DMCEncodingMode m_encodeMode;
- };
-}
-#endif // O3DGC_SC3DMC_ENCODE_PARAMS_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.h
deleted file mode 100644
index 9c4e95026..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_SC3DMC_ENCODER_H
-#define O3DGC_SC3DMC_ENCODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcIndexedFaceSet.h"
-#include "o3dgcSC3DMCEncodeParams.h"
-#include "o3dgcTriangleListEncoder.h"
-
-namespace o3dgc
-{
- //!
- template<class T>
- class SC3DMCEncoder
- {
- public:
- //! Constructor.
- SC3DMCEncoder(void)
- {
- m_posSize = 0;
- m_quantFloatArray = 0;
- m_quantFloatArraySize = 0;
- m_sizeBufferAC = 0;
- m_bufferAC = 0;
- m_normals = 0;
- m_normalsSize = 0;
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- };
- //! Destructor.
- ~SC3DMCEncoder(void)
- {
- delete [] m_normals;
- delete [] m_quantFloatArray;
- delete [] m_bufferAC;
- }
- //!
- O3DGCErrorCode Encode(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream);
- const SC3DMCStats & GetStats() const { return m_stats;}
-
- private:
- O3DGCErrorCode EncodeHeader(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream);
- O3DGCErrorCode EncodePayload(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream);
- O3DGCErrorCode EncodeFloatArray(const Real * const floatArray,
- unsigned long numfloatArray,
- unsigned long dimfloatArray,
- unsigned long stride,
- const Real * const minfloatArray,
- const Real * const maxfloatArray,
- unsigned long nQBits,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode predMode,
- BinaryStream & bstream);
- O3DGCErrorCode QuantizeFloatArray(const Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minfloatArray,
- const Real * const maxfloatArray,
- unsigned long nQBits);
- O3DGCErrorCode EncodeIntArray(const long * const intArray,
- unsigned long numIntArray,
- unsigned long dimIntArray,
- unsigned long stride,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode predMode,
- BinaryStream & bstream);
- O3DGCErrorCode ProcessNormals(const IndexedFaceSet<T> & ifs);
- TriangleListEncoder<T> m_triangleListEncoder;
- long * m_quantFloatArray;
- unsigned long m_posSize;
- unsigned long m_quantFloatArraySize;
- unsigned char * m_bufferAC;
- unsigned long m_sizeBufferAC;
- SC3DMCPredictor m_neighbors [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
- unsigned long m_freqSymbols[O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS];
- unsigned long m_freqPreds [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
- Vector<long> m_predictors;
- Real * m_normals;
- unsigned long m_normalsSize;
- SC3DMCStats m_stats;
- O3DGCStreamType m_streamType;
- };
-}
-#include "o3dgcSC3DMCEncoder.inl" // template implementation
-#endif // O3DGC_SC3DMC_ENCODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.inl
deleted file mode 100644
index 2d30b05a2..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcSC3DMCEncoder.inl
+++ /dev/null
@@ -1,927 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_SC3DMC_ENCODER_INL
-#define O3DGC_SC3DMC_ENCODER_INL
-
-
-#include "o3dgcArithmeticCodec.h"
-#include "o3dgcTimer.h"
-#include "o3dgcVector.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcCommon.h"
-
-//#define DEBUG_VERBOSE
-
-namespace o3dgc
-{
-#ifdef DEBUG_VERBOSE
- FILE * g_fileDebugSC3DMCEnc = NULL;
-#endif //DEBUG_VERBOSE
-
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::Encode(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream)
- {
- // Encode header
- unsigned long start = bstream.GetSize();
- EncodeHeader(params, ifs, bstream);
- // Encode payload
- EncodePayload(params, ifs, bstream);
- bstream.WriteUInt32(m_posSize, bstream.GetSize() - start, m_streamType);
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::EncodeHeader(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream)
- {
- m_streamType = params.GetStreamType();
- bstream.WriteUInt32(O3DGC_SC3DMC_START_CODE, m_streamType);
- m_posSize = bstream.GetSize();
- bstream.WriteUInt32(0, m_streamType); // to be filled later
-
- bstream.WriteUChar(O3DGC_SC3DMC_ENCODE_MODE_TFAN, m_streamType);
- bstream.WriteFloat32((float)ifs.GetCreaseAngle(), m_streamType);
-
- unsigned char mask = 0;
- bool markerBit0 = false;
- bool markerBit1 = false;
- bool markerBit2 = false;
- bool markerBit3 = false;
-
- mask += (ifs.GetCCW() );
- mask += (ifs.GetSolid() << 1);
- mask += (ifs.GetConvex() << 2);
- mask += (ifs.GetIsTriangularMesh() << 3);
- mask += (markerBit0 << 4);
- mask += (markerBit1 << 5);
- mask += (markerBit2 << 6);
- mask += (markerBit3 << 7);
-
- bstream.WriteUChar(mask, m_streamType);
-
- bstream.WriteUInt32(ifs.GetNCoord(), m_streamType);
- bstream.WriteUInt32(ifs.GetNNormal(), m_streamType);
- bstream.WriteUInt32(ifs.GetNumFloatAttributes(), m_streamType);
- bstream.WriteUInt32(ifs.GetNumIntAttributes(), m_streamType);
-
- if (ifs.GetNCoord() > 0)
- {
- bstream.WriteUInt32(ifs.GetNCoordIndex(), m_streamType);
- for(int j=0 ; j<3 ; ++j)
- {
- bstream.WriteFloat32((float) ifs.GetCoordMin(j), m_streamType);
- bstream.WriteFloat32((float) ifs.GetCoordMax(j), m_streamType);
- }
- bstream.WriteUChar((unsigned char) params.GetCoordQuantBits(), m_streamType);
- }
- if (ifs.GetNNormal() > 0)
- {
- bstream.WriteUInt32(0, m_streamType);
- for(int j=0 ; j<3 ; ++j)
- {
- bstream.WriteFloat32((float) ifs.GetNormalMin(j), m_streamType);
- bstream.WriteFloat32((float) ifs.GetNormalMax(j), m_streamType);
- }
- bstream.WriteUChar(true, m_streamType); //(unsigned char) ifs.GetNormalPerVertex()
- bstream.WriteUChar((unsigned char) params.GetNormalQuantBits(), m_streamType);
- }
- for(unsigned long a = 0; a < ifs.GetNumFloatAttributes(); ++a)
- {
- bstream.WriteUInt32(ifs.GetNFloatAttribute(a), m_streamType);
- if (ifs.GetNFloatAttribute(a) > 0)
- {
- assert(ifs.GetFloatAttributeDim(a) < (unsigned long) O3DGC_MAX_UCHAR8);
- bstream.WriteUInt32(0, m_streamType);
- unsigned char d = (unsigned char) ifs.GetFloatAttributeDim(a);
- bstream.WriteUChar(d, m_streamType);
- for(unsigned char j = 0 ; j < d ; ++j)
- {
- bstream.WriteFloat32((float) ifs.GetFloatAttributeMin(a, j), m_streamType);
- bstream.WriteFloat32((float) ifs.GetFloatAttributeMax(a, j), m_streamType);
- }
- bstream.WriteUChar(true, m_streamType); //(unsigned char) ifs.GetFloatAttributePerVertex(a)
- bstream.WriteUChar((unsigned char) ifs.GetFloatAttributeType(a), m_streamType);
- bstream.WriteUChar((unsigned char) params.GetFloatAttributeQuantBits(a), m_streamType);
- }
- }
- for(unsigned long a = 0; a < ifs.GetNumIntAttributes(); ++a)
- {
- bstream.WriteUInt32(ifs.GetNIntAttribute(a), m_streamType);
- if (ifs.GetNIntAttribute(a) > 0)
- {
- assert(ifs.GetFloatAttributeDim(a) < (unsigned long) O3DGC_MAX_UCHAR8);
- bstream.WriteUInt32(0, m_streamType);
- bstream.WriteUChar((unsigned char) ifs.GetIntAttributeDim(a), m_streamType);
- bstream.WriteUChar(true, m_streamType); // (unsigned char) ifs.GetIntAttributePerVertex(a)
- bstream.WriteUChar((unsigned char) ifs.GetIntAttributeType(a), m_streamType);
- }
- }
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::QuantizeFloatArray(const Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits)
- {
- const unsigned long size = numFloatArray * dimFloatArray;
- Real delta[O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
- Real r;
- for(unsigned long d = 0; d < dimFloatArray; d++)
- {
- r = maxFloatArray[d] - minFloatArray[d];
- if (r > 0.0f)
- {
- delta[d] = (float)((1 << nQBits) - 1) / r;
- }
- else
- {
- delta[d] = 1.0f;
- }
- }
- if (m_quantFloatArraySize < size)
- {
- delete [] m_quantFloatArray;
- m_quantFloatArraySize = size;
- m_quantFloatArray = new long [size];
- }
- for(unsigned long v = 0; v < numFloatArray; ++v)
- {
- for(unsigned long d = 0; d < dimFloatArray; ++d)
- {
- m_quantFloatArray[v * stride + d] = (long)((floatArray[v * stride + d]-minFloatArray[d]) * delta[d] + 0.5f);
- }
- }
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::EncodeFloatArray(const Real * const floatArray,
- unsigned long numFloatArray,
- unsigned long dimFloatArray,
- unsigned long stride,
- const Real * const minFloatArray,
- const Real * const maxFloatArray,
- unsigned long nQBits,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode predMode,
- BinaryStream & bstream)
- {
- assert(dimFloatArray < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- long predResidual, v, uPredResidual;
- unsigned long nPred;
- Arithmetic_Codec ace;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
-
- const AdjacencyInfo & v2T = m_triangleListEncoder.GetVertexToTriangle();
- const long * const vmap = m_triangleListEncoder.GetVMap();
- const long * const invVMap = m_triangleListEncoder.GetInvVMap();
- const T * const triangles = ifs.GetCoordIndex();
- const long nvert = (long) numFloatArray;
- unsigned long start = bstream.GetSize();
- unsigned char mask = predMode & 7;
- const unsigned long M = O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS - 1;
- unsigned long nSymbols = O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS;
- unsigned long nPredictors = O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS;
-
-
- Adaptive_Data_Model mModelValues(M+2);
- Adaptive_Data_Model mModelPreds(O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS+1);
-
- memset(m_freqSymbols, 0, sizeof(unsigned long) * O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS);
- memset(m_freqPreds , 0, sizeof(unsigned long) * O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS);
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- mask += (O3DGC_SC3DMC_BINARIZATION_ASCII & 7)<<4;
- m_predictors.Allocate(nvert);
- m_predictors.Clear();
- }
- else
- {
- mask += (O3DGC_SC3DMC_BINARIZATION_AC_EGC & 7)<<4;
- const unsigned int NMAX = numFloatArray * dimFloatArray * 8 + 100;
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- ace.ExpGolombEncode(0, 0, bModel0, bModel1);
- ace.ExpGolombEncode(M, 0, bModel0, bModel1);
- }
- bstream.WriteUInt32(0, m_streamType);
- bstream.WriteUChar(mask, m_streamType);
-
-#ifdef DEBUG_VERBOSE
- printf("FloatArray (%i, %i)\n", numFloatArray, dimFloatArray);
- fprintf(g_fileDebugSC3DMCEnc, "FloatArray (%i, %i)\n", numFloatArray, dimFloatArray);
-#endif //DEBUG_VERBOSE
-
- if (predMode == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION)
- {
- const Real minFloatArray[2] = {(Real)(-2.0),(Real)(-2.0)};
- const Real maxFloatArray[2] = {(Real)(2.0),(Real)(2.0)};
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- for(unsigned long i = 0; i < numFloatArray; ++i)
- {
- bstream.WriteIntASCII(m_predictors[i]);
- }
- }
- else
- {
- Adaptive_Data_Model dModel(12);
- for(unsigned long i = 0; i < numFloatArray; ++i)
- {
- ace.encode(IntToUInt(m_predictors[i]), dModel);
- }
- }
- QuantizeFloatArray(floatArray, numFloatArray, dimFloatArray, stride, minFloatArray, maxFloatArray, nQBits+1);
- }
- else
- {
- QuantizeFloatArray(floatArray, numFloatArray, dimFloatArray, stride, minFloatArray, maxFloatArray, nQBits);
- }
-
- for (long vm=0; vm < nvert; ++vm)
- {
- nPred = 0;
- v = invVMap[vm];
- assert( v >= 0 && v < nvert);
- if ( v2T.GetNumNeighbors(v) > 0 &&
- predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- if ( predMode == O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION )
- {
- long a,b;
- if ((long) triangles[ta*3] == v)
- {
- a = triangles[ta*3 + 1];
- b = triangles[ta*3 + 2];
- }
- else if ((long) triangles[ta*3 + 1] == v)
- {
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 2];
- }
- else
- {
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 1];
- }
- if ( vmap[a] < vm && vmap[b] < vm)
- {
- int u0 = v2T.Begin(a);
- int u1 = v2T.End(a);
- for (long u = u0; u < u1; u++)
- {
- long tb = v2T.GetNeighbor(u);
- long c = -1;
- bool foundB = false;
- for(long k = 0; k < 3; ++k)
- {
- long x = triangles[tb*3 + k];
- if (x == b)
- {
- foundB = true;
- }
- if (vmap[x] < vm && x != a && x != b)
- {
- c = x;
- }
- }
- if (c != -1 && foundB)
- {
- SC3DMCTriplet id = {min(vmap[a], vmap[b]), max(vmap[a], vmap[b]), -vmap[c]-1};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- m_neighbors[p].m_pred[i] = m_quantFloatArray[a*stride+i] +
- m_quantFloatArray[b*stride+i] -
- m_quantFloatArray[c*stride+i];
- }
- }
- }
- }
- }
- }
- if ( predMode == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION ||
- predMode == O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION ||
- predMode == O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION )
- {
- for(long k = 0; k < 3; ++k)
- {
- long w = triangles[ta*3 + k];
- if ( vmap[w] < vm )
- {
- SC3DMCTriplet id = {-1, -1, vmap[w]};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- m_neighbors[p].m_pred[i] = m_quantFloatArray[w*stride+i];
- }
- }
- }
- }
- }
- }
- }
- if (nPred > 1)
- {
- // find best predictor
- unsigned long bestPred = 0xFFFFFFFF;
- double bestCost = O3DGC_MAX_DOUBLE;
- double cost;
-#ifdef DEBUG_VERBOSE1
- printf("\t\t vm %i\n", vm);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t vm %i\n", vm);
-#endif //DEBUG_VERBOSE
-
- for (unsigned long p = 0; p < nPred; ++p)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
-#endif //DEBUG_VERBOSE
- cost = -log2((m_freqPreds[p]+1.0) / nPredictors );
- for (unsigned long i = 0; i < dimFloatArray; ++i)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t\t %i\n", m_neighbors[p].m_pred[i]);
-#endif //DEBUG_VERBOSE
-
- predResidual = (long) IntToUInt(m_quantFloatArray[v*stride+i] - m_neighbors[p].m_pred[i]);
- if (predResidual < (long) M)
- {
- cost += -log2((m_freqSymbols[predResidual]+1.0) / nSymbols );
- }
- else
- {
- cost += -log2((m_freqSymbols[M] + 1.0) / nSymbols ) + log2((double) (predResidual-M));
- }
- }
- if (cost < bestCost)
- {
- bestCost = cost;
- bestPred = p;
- }
- }
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- m_predictors.PushBack((unsigned char) bestPred);
- }
- else
- {
- ace.encode(bestPred, mModelPreds);
- }
-#ifdef DEBUG_VERBOSE1
- printf("best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
- fprintf(g_fileDebugSC3DMCEnc, "best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
-#endif //DEBUG_VERBOSE
- // use best predictor
- for (unsigned long i = 0; i < dimFloatArray; ++i)
- {
- predResidual = m_quantFloatArray[v*stride+i] - m_neighbors[bestPred].m_pred[i];
- uPredResidual = IntToUInt(predResidual);
- ++m_freqSymbols[(uPredResidual < (long) M)? uPredResidual : M];
-
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i \t [%i]\n", vm*dimFloatArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i \t [%i]\n", vm*dimFloatArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
-#endif //DEBUG_VERBOSE
-
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteIntASCII(predResidual);
- }
- else
- {
- EncodeIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
- }
- ++m_freqPreds[bestPred];
- nSymbols += dimFloatArray;
- ++nPredictors;
- }
- else if ( vm > 0 && predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- long prev = invVMap[vm-1];
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- predResidual = m_quantFloatArray[v*stride+i] - m_quantFloatArray[prev*stride+i];
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteIntASCII(predResidual);
- }
- else
- {
- EncodeIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", vm*dimFloatArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i\n", vm*dimFloatArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- else
- {
- for (unsigned long i = 0; i < dimFloatArray; i++)
- {
- predResidual = m_quantFloatArray[v*stride+i];
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteUIntASCII(predResidual);
- }
- else
- {
- EncodeUIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", vm*dimFloatArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i\n", vm*dimFloatArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- }
- if (m_streamType != O3DGC_STREAM_TYPE_ASCII)
- {
- unsigned long encodedBytes = ace.stop_encoder();
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32(start, bstream.GetSize() - start, m_streamType);
-
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- unsigned long start = bstream.GetSize();
- bstream.WriteUInt32ASCII(0);
- const unsigned long size = m_predictors.GetSize();
- for(unsigned long i = 0; i < size; ++i)
- {
- bstream.WriteUCharASCII((unsigned char) m_predictors[i]);
- }
- bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
- }
-#ifdef DEBUG_VERBOSE
- fflush(g_fileDebugSC3DMCEnc);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
-
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::EncodeIntArray(const long * const intArray,
- unsigned long numIntArray,
- unsigned long dimIntArray,
- unsigned long stride,
- const IndexedFaceSet<T> & ifs,
- O3DGCSC3DMCPredictionMode predMode,
- BinaryStream & bstream)
- {
- assert(dimIntArray < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
- long predResidual, v, uPredResidual;
- unsigned long nPred;
- Arithmetic_Codec ace;
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
-
- const AdjacencyInfo & v2T = m_triangleListEncoder.GetVertexToTriangle();
- const long * const vmap = m_triangleListEncoder.GetVMap();
- const long * const invVMap = m_triangleListEncoder.GetInvVMap();
- const T * const triangles = ifs.GetCoordIndex();
- const long nvert = (long) numIntArray;
- unsigned long start = bstream.GetSize();
- unsigned char mask = predMode & 7;
- const unsigned long M = O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS - 1;
- unsigned long nSymbols = O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS;
- unsigned long nPredictors = O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS;
-
-
- Adaptive_Data_Model mModelValues(M+2);
- Adaptive_Data_Model mModelPreds(O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS+1);
-
- memset(m_freqSymbols, 0, sizeof(unsigned long) * O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS);
- memset(m_freqPreds , 0, sizeof(unsigned long) * O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS);
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- mask += (O3DGC_SC3DMC_BINARIZATION_ASCII & 7)<<4;
- m_predictors.Allocate(nvert);
- m_predictors.Clear();
- }
- else
- {
- mask += (O3DGC_SC3DMC_BINARIZATION_AC_EGC & 7)<<4;
- const unsigned int NMAX = numIntArray * dimIntArray * 8 + 100;
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- ace.ExpGolombEncode(0, 0, bModel0, bModel1);
- ace.ExpGolombEncode(M, 0, bModel0, bModel1);
- }
- bstream.WriteUInt32(0, m_streamType);
- bstream.WriteUChar(mask, m_streamType);
-
-#ifdef DEBUG_VERBOSE
- printf("IntArray (%i, %i)\n", numIntArray, dimIntArray);
- fprintf(g_fileDebugSC3DMCEnc, "IntArray (%i, %i)\n", numIntArray, dimIntArray);
-#endif //DEBUG_VERBOSE
-
- for (long vm=0; vm < nvert; ++vm)
- {
- nPred = 0;
- v = invVMap[vm];
- assert( v >= 0 && v < nvert);
- if ( v2T.GetNumNeighbors(v) > 0 &&
- predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- for(long k = 0; k < 3; ++k)
- {
- long w = triangles[ta*3 + k];
- if ( vmap[w] < vm )
- {
- SC3DMCTriplet id = {-1, -1, vmap[w]};
- unsigned long p = Insert(id, nPred, m_neighbors);
- if (p != 0xFFFFFFFF)
- {
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- m_neighbors[p].m_pred[i] = intArray[w*stride+i];
- }
- }
- }
- }
- }
- }
- if (nPred > 1)
- {
- // find best predictor
- unsigned long bestPred = 0xFFFFFFFF;
- double bestCost = O3DGC_MAX_DOUBLE;
- double cost;
-#ifdef DEBUG_VERBOSE1
- printf("\t\t vm %i\n", vm);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t vm %i\n", vm);
-#endif //DEBUG_VERBOSE
-
- for (unsigned long p = 0; p < nPred; ++p)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t pred a = %i b = %i c = %i \n", m_neighbors[p].m_id.m_a, m_neighbors[p].m_id.m_b, m_neighbors[p].m_id.m_c);
-#endif //DEBUG_VERBOSE
- cost = -log2((m_freqPreds[p]+1.0) / nPredictors );
- for (unsigned long i = 0; i < dimIntArray; ++i)
- {
-#ifdef DEBUG_VERBOSE1
- printf("\t\t\t %i\n", m_neighbors[p].m_pred[i]);
- fprintf(g_fileDebugSC3DMCEnc, "\t\t\t %i\n", m_neighbors[p].m_pred[i]);
-#endif //DEBUG_VERBOSE
-
- predResidual = (long) IntToUInt(intArray[v*stride+i] - m_neighbors[p].m_pred[i]);
- if (predResidual < (long) M)
- {
- cost += -log2((m_freqSymbols[predResidual]+1.0) / nSymbols );
- }
- else
- {
- cost += -log2((m_freqSymbols[M] + 1.0) / nSymbols ) + log2((double) (predResidual-M));
- }
- }
- if (cost < bestCost)
- {
- bestCost = cost;
- bestPred = p;
- }
- }
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- m_predictors.PushBack((unsigned char) bestPred);
- }
- else
- {
- ace.encode(bestPred, mModelPreds);
- }
-#ifdef DEBUG_VERBOSE1
- printf("best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
- fprintf(g_fileDebugSC3DMCEnc, "best (%i, %i, %i) \t pos %i\n", m_neighbors[bestPred].m_id.m_a, m_neighbors[bestPred].m_id.m_b, m_neighbors[bestPred].m_id.m_c, bestPred);
-#endif //DEBUG_VERBOSE
- // use best predictor
- for (unsigned long i = 0; i < dimIntArray; ++i)
- {
- predResidual = intArray[v*stride+i] - m_neighbors[bestPred].m_pred[i];
- uPredResidual = IntToUInt(predResidual);
- ++m_freqSymbols[(uPredResidual < (long) M)? uPredResidual : M];
-
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i \t [%i]\n", vm*dimIntArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i \t [%i]\n", vm*dimIntArray+i, predResidual, m_neighbors[bestPred].m_pred[i]);
-#endif //DEBUG_VERBOSE
-
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteIntASCII(predResidual);
- }
- else
- {
- EncodeIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
- }
- ++m_freqPreds[bestPred];
- nSymbols += dimIntArray;
- ++nPredictors;
- }
- else if ( vm > 0 && predMode != O3DGC_SC3DMC_NO_PREDICTION)
- {
- long prev = invVMap[vm-1];
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- predResidual = intArray[v*stride+i] - intArray[prev*stride+i];
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteIntASCII(predResidual);
- }
- else
- {
- EncodeIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", vm*dimIntArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i\n", vm*dimIntArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- else
- {
- for (unsigned long i = 0; i < dimIntArray; i++)
- {
- predResidual = intArray[v*stride+i];
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- bstream.WriteUIntASCII(predResidual);
- }
- else
- {
- EncodeUIntACEGC(predResidual, ace, mModelValues, bModel0, bModel1, M);
- }
-#ifdef DEBUG_VERBOSE
- printf("%i \t %i\n", vm*dimIntArray+i, predResidual);
- fprintf(g_fileDebugSC3DMCEnc, "%i \t %i\n", vm*dimIntArray+i, predResidual);
-#endif //DEBUG_VERBOSE
- }
- }
- }
- if (m_streamType != O3DGC_STREAM_TYPE_ASCII)
- {
- unsigned long encodedBytes = ace.stop_encoder();
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32(start, bstream.GetSize() - start, m_streamType);
-
- if (m_streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- unsigned long start = bstream.GetSize();
- bstream.WriteUInt32ASCII(0);
- const unsigned long size = m_predictors.GetSize();
- for(unsigned long i = 0; i < size; ++i)
- {
- bstream.WriteUCharASCII((unsigned char) m_predictors[i]);
- }
- bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
- }
-#ifdef DEBUG_VERBOSE
- fflush(g_fileDebugSC3DMCEnc);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::ProcessNormals(const IndexedFaceSet<T> & ifs)
- {
- const long nvert = (long) ifs.GetNNormal();
- const unsigned long normalSize = ifs.GetNNormal() * 2;
- if (m_normalsSize < normalSize)
- {
- delete [] m_normals;
- m_normalsSize = normalSize;
- m_normals = new Real [normalSize];
- }
- const AdjacencyInfo & v2T = m_triangleListEncoder.GetVertexToTriangle();
- const long * const invVMap = m_triangleListEncoder.GetInvVMap();
- const T * const triangles = ifs.GetCoordIndex();
- const Real * const originalNormals = ifs.GetNormal();
- Vec3<long> p1, p2, p3, n0, nt;
- Vec3<Real> n1;
- long na0 = 0, nb0 = 0;
- Real rna0, rnb0, na1 = 0, nb1 = 0, norm0, norm1;
- char ni0 = 0, ni1 = 0;
- long a, b, c, v;
- m_predictors.Clear();
- for (long i=0; i < nvert; ++i)
- {
- v = invVMap[i];
- n0.X() = 0;
- n0.Y() = 0;
- n0.Z() = 0;
- int u0 = v2T.Begin(v);
- int u1 = v2T.End(v);
- for (long u = u0; u < u1; u++)
- {
- long ta = v2T.GetNeighbor(u);
- a = triangles[ta*3 + 0];
- b = triangles[ta*3 + 1];
- c = triangles[ta*3 + 2];
- p1.X() = m_quantFloatArray[3*a];
- p1.Y() = m_quantFloatArray[3*a+1];
- p1.Z() = m_quantFloatArray[3*a+2];
- p2.X() = m_quantFloatArray[3*b];
- p2.Y() = m_quantFloatArray[3*b+1];
- p2.Z() = m_quantFloatArray[3*b+2];
- p3.X() = m_quantFloatArray[3*c];
- p3.Y() = m_quantFloatArray[3*c+1];
- p3.Z() = m_quantFloatArray[3*c+2];
- nt = (p2-p1)^(p3-p1);
- n0 += nt;
- }
- norm0 = (Real) n0.GetNorm();
- if (norm0 == 0.0)
- {
- norm0 = 1.0;
- }
- SphereToCube(n0.X(), n0.Y(), n0.Z(), na0, nb0, ni0);
- rna0 = na0 / norm0;
- rnb0 = nb0 / norm0;
-
- n1.X() = originalNormals[3*v];
- n1.Y() = originalNormals[3*v+1];
- n1.Z() = originalNormals[3*v+2];
- norm1 = (Real) n1.GetNorm();
- if (norm1 != 0.0)
- {
- n1.X() /= norm1;
- n1.Y() /= norm1;
- n1.Z() /= norm1;
- }
- SphereToCube(n1.X(), n1.Y(), n1.Z(), na1, nb1, ni1);
- m_predictors.PushBack(ni1 - ni0);
- if ( (ni1 >> 1) != (ni0 >> 1) )
- {
- rna0 = (Real)0.0;
- rnb0 = (Real)0.0;
- }
- m_normals[2*v] = na1 - rna0;
- m_normals[2*v+1] = nb1 - rnb0;
-
-#ifdef DEBUG_VERBOSE1
- printf("n0 \t %i \t %i \t %i \t %i (%f, %f)\n", i, n0.X(), n0.Y(), n0.Z(), rna0, rnb0);
- fprintf(g_fileDebugSC3DMCEnc,"n0 \t %i \t %i \t %i \t %i (%f, %f)\n", i, n0.X(), n0.Y(), n0.Z(), rna0, rnb0);
-#endif //DEBUG_VERBOSE
-
-#ifdef DEBUG_VERBOSE1
- printf("normal \t %i \t %f \t %f \t %f \t (%i, %f, %f) \t (%f, %f)\n", i, n1.X(), n1.Y(), n1.Z(), ni1, na1, nb1, rna0, rnb0);
- fprintf(g_fileDebugSC3DMCEnc, "normal \t %i \t %f \t %f \t %f \t (%i, %f, %f) \t (%f, %f)\n", i, n1.X(), n1.Y(), n1.Z(), ni1, na1, nb1, rna0, rnb0);
-#endif //DEBUG_VERBOSE
-
- }
- return O3DGC_OK;
- }
-
- template <class T>
- O3DGCErrorCode SC3DMCEncoder<T>::EncodePayload(const SC3DMCEncodeParams & params,
- const IndexedFaceSet<T> & ifs,
- BinaryStream & bstream)
- {
-#ifdef DEBUG_VERBOSE
- g_fileDebugSC3DMCEnc = fopen("tfans_enc_main.txt", "w");
-#endif //DEBUG_VERBOSE
-
- // encode triangle list
- m_triangleListEncoder.SetStreamType(params.GetStreamType());
- m_stats.m_streamSizeCoordIndex = bstream.GetSize();
- Timer timer;
- timer.Tic();
- m_triangleListEncoder.Encode(ifs.GetCoordIndex(), ifs.GetIndexBufferID(), ifs.GetNCoordIndex(), ifs.GetNCoord(), bstream);
- timer.Toc();
- m_stats.m_timeCoordIndex = timer.GetElapsedTime();
- m_stats.m_streamSizeCoordIndex = bstream.GetSize() - m_stats.m_streamSizeCoordIndex;
-
- // encode coord
- m_stats.m_streamSizeCoord = bstream.GetSize();
- timer.Tic();
- if (ifs.GetNCoord() > 0)
- {
- EncodeFloatArray(ifs.GetCoord(), ifs.GetNCoord(), 3, 3, ifs.GetCoordMin(), ifs.GetCoordMax(),
- params.GetCoordQuantBits(), ifs, params.GetCoordPredMode(), bstream);
- }
- timer.Toc();
- m_stats.m_timeCoord = timer.GetElapsedTime();
- m_stats.m_streamSizeCoord = bstream.GetSize() - m_stats.m_streamSizeCoord;
-
-
- // encode Normal
- m_stats.m_streamSizeNormal = bstream.GetSize();
- timer.Tic();
- if (ifs.GetNNormal() > 0)
- {
- if (params.GetNormalPredMode() == O3DGC_SC3DMC_SURF_NORMALS_PREDICTION)
- {
- ProcessNormals(ifs);
- EncodeFloatArray(m_normals, ifs.GetNNormal(), 2, 2, ifs.GetNormalMin(), ifs.GetNormalMax(),
- params.GetNormalQuantBits(), ifs, params.GetNormalPredMode(), bstream);
- }
- else
- {
- EncodeFloatArray(ifs.GetNormal(), ifs.GetNNormal(), 3, 3, ifs.GetNormalMin(), ifs.GetNormalMax(),
- params.GetNormalQuantBits(), ifs, params.GetNormalPredMode(), bstream);
- }
- }
- timer.Toc();
- m_stats.m_timeNormal = timer.GetElapsedTime();
- m_stats.m_streamSizeNormal = bstream.GetSize() - m_stats.m_streamSizeNormal;
-
-
- // encode FloatAttribute
- for(unsigned long a = 0; a < ifs.GetNumFloatAttributes(); ++a)
- {
- m_stats.m_streamSizeFloatAttribute[a] = bstream.GetSize();
- timer.Tic();
- EncodeFloatArray(ifs.GetFloatAttribute(a), ifs.GetNFloatAttribute(a),
- ifs.GetFloatAttributeDim(a), ifs.GetFloatAttributeDim(a),
- ifs.GetFloatAttributeMin(a), ifs.GetFloatAttributeMax(a),
- params.GetFloatAttributeQuantBits(a), ifs,
- params.GetFloatAttributePredMode(a), bstream);
- timer.Toc();
- m_stats.m_timeFloatAttribute[a] = timer.GetElapsedTime();
- m_stats.m_streamSizeFloatAttribute[a] = bstream.GetSize() - m_stats.m_streamSizeFloatAttribute[a];
- }
-
- // encode IntAttribute
- for(unsigned long a = 0; a < ifs.GetNumIntAttributes(); ++a)
- {
- m_stats.m_streamSizeIntAttribute[a] = bstream.GetSize();
- timer.Tic();
- EncodeIntArray(ifs.GetIntAttribute(a), ifs.GetNIntAttribute(a), ifs.GetIntAttributeDim(a),
- ifs.GetIntAttributeDim(a), ifs, params.GetIntAttributePredMode(a), bstream);
- timer.Toc();
- m_stats.m_timeIntAttribute[a] = timer.GetElapsedTime();
- m_stats.m_streamSizeIntAttribute[a] = bstream.GetSize() - m_stats.m_streamSizeIntAttribute[a];
- }
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugSC3DMCEnc);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
-}
-#endif // O3DGC_SC3DMC_ENCODER_INL
-
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTimer.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTimer.h
deleted file mode 100644
index 00fe5b653..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTimer.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_TIMER_H
-#define O3DGC_TIMER_H
-
-#include "o3dgcCommon.h"
-
-#ifdef _WIN32
-/* Thank you, Microsoft, for file WinDef.h with min/max redefinition. */
-#define NOMINMAX
-#include <windows.h>
-#elif __MACH__
-#include <mach/clock.h>
-#include <mach/mach.h>
-#else
-#include <time.h>
-#include <sys/time.h>
-#endif
-
-
-
-namespace o3dgc
-{
-#ifdef _WIN32
- class Timer
- {
- public:
- Timer(void)
- {
- m_start.QuadPart = 0;
- m_stop.QuadPart = 0;
- QueryPerformanceFrequency( &m_freq ) ;
- };
- ~Timer(void){};
- void Tic()
- {
- QueryPerformanceCounter(&m_start) ;
- }
- void Toc()
- {
- QueryPerformanceCounter(&m_stop);
- }
- double GetElapsedTime() // in ms
- {
- LARGE_INTEGER delta;
- delta.QuadPart = m_stop.QuadPart - m_start.QuadPart;
- return (1000.0 * delta.QuadPart) / (double)m_freq.QuadPart;
- }
- private:
- LARGE_INTEGER m_start;
- LARGE_INTEGER m_stop;
- LARGE_INTEGER m_freq;
-
- };
-#elif __MACH__
- class Timer
- {
- public:
- Timer(void)
- {
- memset(this, 0, sizeof(Timer));
- host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, & m_cclock);
- };
- ~Timer(void)
- {
- mach_port_deallocate(mach_task_self(), m_cclock);
- };
- void Tic()
- {
- clock_get_time( m_cclock, &m_start);
- }
- void Toc()
- {
- clock_get_time( m_cclock, &m_stop);
- }
- double GetElapsedTime() // in ms
- {
- return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
- }
- private:
- clock_serv_t m_cclock;
- mach_timespec_t m_start;
- mach_timespec_t m_stop;
- };
-#else
- class Timer
- {
- public:
- Timer(void)
- {
- memset(this, 0, sizeof(Timer));
- };
- ~Timer(void){};
- void Tic()
- {
- clock_gettime(CLOCK_REALTIME, &m_start);
- }
- void Toc()
- {
- clock_gettime(CLOCK_REALTIME, &m_stop);
- }
- double GetElapsedTime() // in ms
- {
- return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
- }
- private:
- struct timespec m_start;
- struct timespec m_stop;
- };
-#endif
-
-}
-#endif // O3DGC_TIMER_H
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTools.cpp b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTools.cpp
deleted file mode 100644
index 52b552304..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTools.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.cpp b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.cpp
deleted file mode 100644
index 078ed16e6..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.cpp
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "o3dgcTriangleFans.h"
-#include "o3dgcArithmeticCodec.h"
-
-//#define DEBUG_VERBOSE
-
-namespace o3dgc
-{
-#ifdef DEBUG_VERBOSE
- FILE* g_fileDebugTF = NULL;
-#endif //DEBUG_VERBOSE
-
- O3DGCErrorCode SaveUIntData(const Vector<long> & data,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- bstream.WriteUInt32ASCII(0);
- const unsigned long size = data.GetSize();
- bstream.WriteUInt32ASCII(size);
- for(unsigned long i = 0; i < size; ++i)
- {
- bstream.WriteUIntASCII(data[i]);
- }
- bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
- O3DGCErrorCode SaveIntData(const Vector<long> & data,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- bstream.WriteUInt32ASCII(0);
- const unsigned long size = data.GetSize();
- bstream.WriteUInt32ASCII(size);
- for(unsigned long i = 0; i < size; ++i)
- {
- bstream.WriteIntASCII(data[i]);
- }
- bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
- O3DGCErrorCode SaveBinData(const Vector<long> & data,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- bstream.WriteUInt32ASCII(0);
- const unsigned long size = data.GetSize();
- long symbol;
- bstream.WriteUInt32ASCII(size);
- for(unsigned long i = 0; i < size; )
- {
- symbol = 0;
- for(unsigned long h = 0; h < O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0 && i < size; ++h)
- {
- symbol += (data[i] << h);
- ++i;
- }
- bstream.WriteUCharASCII((unsigned char) symbol);
- }
- bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
- O3DGCErrorCode CompressedTriangleFans::SaveUIntAC(const Vector<long> & data,
- const unsigned long M,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- const unsigned int NMAX = data.GetSize() * 8 + 100;
- const unsigned long size = data.GetSize();
- long minValue = O3DGC_MAX_LONG;
- bstream.WriteUInt32Bin(0);
- bstream.WriteUInt32Bin(size);
- if (size > 0)
- {
- #ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i, start %i\n", size, start);
- fprintf(g_fileDebugTF, "-----------\nsize %i, start %i\n", size, start);
- #endif //DEBUG_VERBOSE
-
- for(unsigned long i = 0; i < size; ++i)
- {
- if (minValue > data[i])
- {
- minValue = data[i];
- }
- #ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
- #endif //DEBUG_VERBOSE
- }
- bstream.WriteUInt32Bin(minValue);
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- Arithmetic_Codec ace;
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- Adaptive_Data_Model mModelValues(M+1);
- for(unsigned long i = 0; i < size; ++i)
- {
- ace.encode(data[i]-minValue, mModelValues);
- }
- unsigned long encodedBytes = ace.stop_encoder();
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32Bin(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
- O3DGCErrorCode CompressedTriangleFans::SaveBinAC(const Vector<long> & data,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- const unsigned int NMAX = data.GetSize() * 8 + 100;
- const unsigned long size = data.GetSize();
- bstream.WriteUInt32Bin(0);
- bstream.WriteUInt32Bin(size);
- if (size > 0)
- {
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- Arithmetic_Codec ace;
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- Adaptive_Bit_Model bModel;
- #ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i, start %i\n", size, start);
- fprintf(g_fileDebugTF, "-----------\nsize %i, start %i\n", size, start);
- #endif //DEBUG_VERBOSE
- for(unsigned long i = 0; i < size; ++i)
- {
- ace.encode(data[i], bModel);
- #ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
- #endif //DEBUG_VERBOSE
- }
- unsigned long encodedBytes = ace.stop_encoder();
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32Bin(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
-
- O3DGCErrorCode CompressedTriangleFans::SaveIntACEGC(const Vector<long> & data,
- const unsigned long M,
- BinaryStream & bstream)
- {
- unsigned long start = bstream.GetSize();
- const unsigned int NMAX = data.GetSize() * 8 + 100;
- const unsigned long size = data.GetSize();
- long minValue = 0;
- bstream.WriteUInt32Bin(0);
- bstream.WriteUInt32Bin(size);
- if (size > 0)
- {
-#ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i, start %i\n", size, start);
- fprintf(g_fileDebugTF, "-----------\nsize %i, start %i\n", size, start);
-#endif //DEBUG_VERBOSE
- for(unsigned long i = 0; i < size; ++i)
- {
- if (minValue > data[i])
- {
- minValue = data[i];
- }
-#ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
-#endif //DEBUG_VERBOSE
- }
- bstream.WriteUInt32Bin(minValue + O3DGC_MAX_LONG);
- if ( m_sizeBufferAC < NMAX )
- {
- delete [] m_bufferAC;
- m_sizeBufferAC = NMAX;
- m_bufferAC = new unsigned char [m_sizeBufferAC];
- }
- Arithmetic_Codec ace;
- ace.set_buffer(NMAX, m_bufferAC);
- ace.start_encoder();
- Adaptive_Data_Model mModelValues(M+2);
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- unsigned long value;
- for(unsigned long i = 0; i < size; ++i)
- {
- value = data[i]-minValue;
- if (value < M)
- {
- ace.encode(value, mModelValues);
- }
- else
- {
- ace.encode(M, mModelValues);
- ace.ExpGolombEncode(value-M, 0, bModel0, bModel1);
- }
- }
- unsigned long encodedBytes = ace.stop_encoder();
- for(unsigned long i = 0; i < encodedBytes; ++i)
- {
- bstream.WriteUChar8Bin(m_bufferAC[i]);
- }
- }
- bstream.WriteUInt32Bin(start, bstream.GetSize() - start);
- return O3DGC_OK;
- }
- O3DGCErrorCode CompressedTriangleFans::Save(BinaryStream & bstream, bool encodeTrianglesOrder, O3DGCStreamType streamType)
- {
-#ifdef DEBUG_VERBOSE
- g_fileDebugTF = fopen("SaveIntACEGC_new.txt", "w");
-#endif //DEBUG_VERBOSE
-
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- SaveUIntData(m_numTFANs , bstream);
- SaveUIntData(m_degrees , bstream);
- SaveUIntData(m_configs , bstream);
- SaveBinData (m_operations, bstream);
- SaveIntData (m_indices , bstream);
- if (encodeTrianglesOrder)
- {
- SaveUIntData(m_trianglesOrder, bstream);
- }
- }
- else
- {
- SaveIntACEGC(m_numTFANs , 4 , bstream);
- SaveIntACEGC(m_degrees , 16, bstream);
- SaveUIntAC (m_configs , 10, bstream);
- SaveBinAC (m_operations, bstream);
- SaveIntACEGC(m_indices , 8 , bstream);
- if (encodeTrianglesOrder)
- {
- SaveIntACEGC(m_trianglesOrder , 16, bstream);
- }
- }
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugTF);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadUIntData(Vector<long> & data,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- bstream.ReadUInt32ASCII(iterator);
- const unsigned long size = bstream.ReadUInt32ASCII(iterator);
- data.Allocate(size);
- data.Clear();
- for(unsigned long i = 0; i < size; ++i)
- {
- data.PushBack(bstream.ReadUIntASCII(iterator));
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadIntData(Vector<long> & data,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- bstream.ReadUInt32ASCII(iterator);
- const unsigned long size = bstream.ReadUInt32ASCII(iterator);
- data.Allocate(size);
- data.Clear();
- for(unsigned long i = 0; i < size; ++i)
- {
- data.PushBack(bstream.ReadIntASCII(iterator));
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadBinData(Vector<long> & data,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- bstream.ReadUInt32ASCII(iterator);
- const unsigned long size = bstream.ReadUInt32ASCII(iterator);
- long symbol;
- data.Allocate(size * O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0);
- data.Clear();
- for(unsigned long i = 0; i < size;)
- {
- symbol = bstream.ReadUCharASCII(iterator);
- for(unsigned long h = 0; h < O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0; ++h)
- {
- data.PushBack(symbol & 1);
- symbol >>= 1;
- ++i;
- }
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadUIntAC(Vector<long> & data,
- const unsigned long M,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- unsigned long sizeSize = bstream.ReadUInt32Bin(iterator) - 12;
- unsigned long size = bstream.ReadUInt32Bin(iterator);
- if (size == 0)
- {
- return O3DGC_OK;
- }
- long minValue = bstream.ReadUInt32Bin(iterator);
- unsigned char * buffer = 0;
- bstream.GetBuffer(iterator, buffer);
- iterator += sizeSize;
- data.Allocate(size);
- Arithmetic_Codec acd;
- acd.set_buffer(sizeSize, buffer);
- acd.start_decoder();
- Adaptive_Data_Model mModelValues(M+1);
-#ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i\n", size);
- fprintf(g_fileDebugTF, "size %i\n", size);
-#endif //DEBUG_VERBOSE
- for(unsigned long i = 0; i < size; ++i)
- {
- data.PushBack(acd.decode(mModelValues)+minValue);
-#ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
-#endif //DEBUG_VERBOSE
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadIntACEGC(Vector<long> & data,
- const unsigned long M,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- unsigned long sizeSize = bstream.ReadUInt32Bin(iterator) - 12;
- unsigned long size = bstream.ReadUInt32Bin(iterator);
- if (size == 0)
- {
- return O3DGC_OK;
- }
- long minValue = bstream.ReadUInt32Bin(iterator) - O3DGC_MAX_LONG;
- unsigned char * buffer = 0;
- bstream.GetBuffer(iterator, buffer);
- iterator += sizeSize;
- data.Allocate(size);
- Arithmetic_Codec acd;
- acd.set_buffer(sizeSize, buffer);
- acd.start_decoder();
- Adaptive_Data_Model mModelValues(M+2);
- Static_Bit_Model bModel0;
- Adaptive_Bit_Model bModel1;
- unsigned long value;
-
-#ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i\n", size);
- fprintf(g_fileDebugTF, "size %i\n", size);
-#endif //DEBUG_VERBOSE
- for(unsigned long i = 0; i < size; ++i)
- {
- value = acd.decode(mModelValues);
- if ( value == M)
- {
- value += acd.ExpGolombDecode(0, bModel0, bModel1);
- }
- data.PushBack(value + minValue);
-#ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
-#endif //DEBUG_VERBOSE
- }
-#ifdef DEBUG_VERBOSE
- fflush(g_fileDebugTF);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
- O3DGCErrorCode LoadBinAC(Vector<long> & data,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- unsigned long sizeSize = bstream.ReadUInt32Bin(iterator) - 8;
- unsigned long size = bstream.ReadUInt32Bin(iterator);
- if (size == 0)
- {
- return O3DGC_OK;
- }
- unsigned char * buffer = 0;
- bstream.GetBuffer(iterator, buffer);
- iterator += sizeSize;
- data.Allocate(size);
- Arithmetic_Codec acd;
- acd.set_buffer(sizeSize, buffer);
- acd.start_decoder();
- Adaptive_Bit_Model bModel;
-#ifdef DEBUG_VERBOSE
- printf("-----------\nsize %i\n", size);
- fprintf(g_fileDebugTF, "size %i\n", size);
-#endif //DEBUG_VERBOSE
- for(unsigned long i = 0; i < size; ++i)
- {
- data.PushBack(acd.decode(bModel));
-#ifdef DEBUG_VERBOSE
- printf("%i\t%i\n", i, data[i]);
- fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
-#endif //DEBUG_VERBOSE
- }
- return O3DGC_OK;
- }
- O3DGCErrorCode CompressedTriangleFans::Load(const BinaryStream & bstream,
- unsigned long & iterator,
- bool decodeTrianglesOrder,
- O3DGCStreamType streamType)
- {
-#ifdef DEBUG_VERBOSE
- g_fileDebugTF = fopen("Load_new.txt", "w");
-#endif //DEBUG_VERBOSE
- if (streamType == O3DGC_STREAM_TYPE_ASCII)
- {
- LoadUIntData(m_numTFANs , bstream, iterator);
- LoadUIntData(m_degrees , bstream, iterator);
- LoadUIntData(m_configs , bstream, iterator);
- LoadBinData (m_operations, bstream, iterator);
- LoadIntData (m_indices , bstream, iterator);
- if (decodeTrianglesOrder)
- {
- LoadUIntData(m_trianglesOrder , bstream, iterator);
- }
- }
- else
- {
- LoadIntACEGC(m_numTFANs , 4 , bstream, iterator);
- LoadIntACEGC(m_degrees , 16, bstream, iterator);
- LoadUIntAC (m_configs , 10, bstream, iterator);
- LoadBinAC (m_operations, bstream, iterator);
- LoadIntACEGC(m_indices , 8 , bstream, iterator);
- if (decodeTrianglesOrder)
- {
- LoadIntACEGC(m_trianglesOrder , 16, bstream, iterator);
- }
- }
-
-#ifdef DEBUG_VERBOSE
- fclose(g_fileDebugTF);
-#endif //DEBUG_VERBOSE
- return O3DGC_OK;
- }
-}
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.h
deleted file mode 100644
index 861836428..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleFans.h
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_TRIANGLE_FANS_H
-#define O3DGC_TRIANGLE_FANS_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcVector.h"
-#include "o3dgcBinaryStream.h"
-
-
-namespace o3dgc
-{
- const long O3DGC_TFANS_MIN_SIZE_ALLOCATED_VERTICES_BUFFER = 128;
- const long O3DGC_TFANS_MIN_SIZE_TFAN_SIZE_BUFFER = 8;
-
- class CompressedTriangleFans
- {
- public:
- //! Constructor.
- CompressedTriangleFans(void)
- {
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- m_bufferAC = 0;
- m_sizeBufferAC = 0;
- };
- //! Destructor.
- ~CompressedTriangleFans(void)
- {
- delete [] m_bufferAC;
- };
- O3DGCStreamType GetStreamType() const { return m_streamType; }
- void SetStreamType(O3DGCStreamType streamType) { m_streamType = streamType; }
-
- O3DGCErrorCode Allocate(long numVertices, long numTriangles)
- {
- assert(numVertices > 0);
- m_numTFANs.Allocate(numVertices);
- m_degrees.Allocate(2*numVertices);
- m_configs.Allocate(2*numVertices);
- m_operations.Allocate(2*numVertices);
- m_indices.Allocate(2*numVertices);
- m_trianglesOrder.Allocate(numTriangles);
- Clear();
- return O3DGC_OK;
- }
- O3DGCErrorCode PushNumTFans(long numTFans)
- {
- m_numTFANs.PushBack(numTFans);
- return O3DGC_OK;
- }
- long ReadNumTFans(unsigned long & iterator) const
- {
- assert(iterator < m_numTFANs.GetSize());
- return m_numTFANs[iterator++];
- }
- O3DGCErrorCode PushDegree(long degree)
- {
- m_degrees.PushBack(degree);
- return O3DGC_OK;
- }
- long ReadDegree(unsigned long & iterator) const
- {
- assert(iterator < m_degrees.GetSize());
- return m_degrees[iterator++];
- }
- O3DGCErrorCode PushConfig(long config)
- {
- m_configs.PushBack(config);
- return O3DGC_OK;
- }
- long ReadConfig(unsigned long & iterator) const
- {
- assert(iterator < m_configs.GetSize());
- return m_configs[iterator++];
- }
- O3DGCErrorCode PushOperation(long op)
- {
- m_operations.PushBack(op);
- return O3DGC_OK;
- }
- long ReadOperation(unsigned long & iterator) const
- {
- assert(iterator < m_operations.GetSize());
- return m_operations[iterator++];
- }
- O3DGCErrorCode PushIndex(long index)
- {
- m_indices.PushBack(index);
- return O3DGC_OK;
- }
- long ReadIndex(unsigned long & iterator) const
- {
- assert(iterator < m_indices.GetSize());
- return m_indices[iterator++];
- }
- O3DGCErrorCode PushTriangleIndex(long index)
- {
- m_trianglesOrder.PushBack(IntToUInt(index));
- return O3DGC_OK;
- }
- long ReadTriangleIndex(unsigned long & iterator) const
- {
- assert(iterator < m_trianglesOrder.GetSize());
- return UIntToInt(m_trianglesOrder[iterator++]);
- }
- O3DGCErrorCode Clear()
- {
- m_numTFANs.Clear();
- m_degrees.Clear();
- m_configs.Clear();
- m_operations.Clear();
- m_indices.Clear();
- return O3DGC_OK;
- }
- O3DGCErrorCode Save(BinaryStream & bstream,
- bool encodeTrianglesOrder,
- O3DGCStreamType streamType);
- O3DGCErrorCode Load(const BinaryStream & bstream,
- unsigned long & iterator,
- bool decodeTrianglesOrder,
- O3DGCStreamType streamType);
-
- private:
- O3DGCErrorCode SaveBinAC(const Vector<long> & data,
- BinaryStream & bstream);
- O3DGCErrorCode SaveUIntAC(const Vector<long> & data,
- const unsigned long M,
- BinaryStream & bstream);
- O3DGCErrorCode SaveIntACEGC(const Vector<long> & data,
- const unsigned long M,
- BinaryStream & bstream);
-
- Vector<long> m_numTFANs;
- Vector<long> m_degrees;
- Vector<long> m_configs;
- Vector<long> m_operations;
- Vector<long> m_indices;
- Vector<long> m_trianglesOrder;
- unsigned char * m_bufferAC;
- unsigned long m_sizeBufferAC;
- O3DGCStreamType m_streamType;
- };
-
- //!
- class TriangleFans
- {
- public:
- //! Constructor.
- TriangleFans(long sizeTFAN = O3DGC_TFANS_MIN_SIZE_TFAN_SIZE_BUFFER,
- long verticesSize = O3DGC_TFANS_MIN_SIZE_ALLOCATED_VERTICES_BUFFER)
- {
- assert(sizeTFAN > 0);
- assert(verticesSize > 0);
- m_numTFANs = 0;
- m_numVertices = 0;
- m_verticesAllocatedSize = verticesSize;
- m_sizeTFANAllocatedSize = sizeTFAN;
- m_sizeTFAN = new long [m_sizeTFANAllocatedSize];
- m_vertices = new long [m_verticesAllocatedSize];
- };
- //! Destructor.
- ~TriangleFans(void)
- {
- delete [] m_vertices;
- delete [] m_sizeTFAN;
- };
-
- O3DGCErrorCode Allocate(long sizeTFAN, long verticesSize)
- {
- assert(sizeTFAN > 0);
- assert(verticesSize > 0);
- m_numTFANs = 0;
- m_numVertices = 0;
- if (m_verticesAllocatedSize < verticesSize)
- {
- delete [] m_vertices;
- m_verticesAllocatedSize = verticesSize;
- m_vertices = new long [m_verticesAllocatedSize];
- }
- if (m_sizeTFANAllocatedSize < sizeTFAN)
- {
- delete [] m_sizeTFAN;
- m_sizeTFANAllocatedSize = sizeTFAN;
- m_sizeTFAN = new long [m_sizeTFANAllocatedSize];
- }
- return O3DGC_OK;
- };
- O3DGCErrorCode Clear()
- {
- m_numTFANs = 0;
- m_numVertices = 0;
- return O3DGC_OK;
- }
- O3DGCErrorCode AddVertex(long vertex)
- {
- assert(m_numTFANs >= 0);
- assert(m_numTFANs < m_sizeTFANAllocatedSize);
- assert(m_numVertices >= 0);
- ++m_numVertices;
- if (m_numVertices == m_verticesAllocatedSize)
- {
- m_verticesAllocatedSize *= 2;
- long * tmp = m_vertices;
- m_vertices = new long [m_verticesAllocatedSize];
- memcpy(m_vertices, tmp, sizeof(long) * m_numVertices);
- delete [] tmp;
- }
- m_vertices[m_numVertices-1] = vertex;
- ++m_sizeTFAN[m_numTFANs-1];
- return O3DGC_OK;
- }
- O3DGCErrorCode AddTFAN()
- {
- assert(m_numTFANs >= 0);
- ++m_numTFANs;
- if (m_numTFANs == m_sizeTFANAllocatedSize)
- {
- m_sizeTFANAllocatedSize *= 2;
- long * tmp = m_sizeTFAN;
- m_sizeTFAN = new long [m_sizeTFANAllocatedSize];
- memcpy(m_sizeTFAN, tmp, sizeof(long) * m_numTFANs);
- delete [] tmp;
- }
- m_sizeTFAN[m_numTFANs-1] = (m_numTFANs > 1) ? m_sizeTFAN[m_numTFANs-2] : 0;
- return O3DGC_OK;
- }
- long Begin(long tfan) const
- {
- assert(tfan < m_numTFANs);
- assert(tfan >= 0);
- return (tfan>0)?m_sizeTFAN[tfan-1]:0;
- }
- long End(long tfan) const
- {
- assert(tfan < m_numTFANs);
- assert(tfan >= 0);
- return m_sizeTFAN[tfan];
- }
- long GetVertex(long vertex) const
- {
- assert(vertex < m_numVertices);
- assert(vertex >= 0);
- return m_vertices[vertex];
- }
- long GetTFANSize(long tfan) const
- {
- return End(tfan) - Begin(tfan);
- }
- long GetNumTFANs() const
- {
- return m_numTFANs;
- }
- long GetNumVertices() const
- {
- return m_numVertices;
- }
-
- private:
- long m_verticesAllocatedSize;
- long m_sizeTFANAllocatedSize;
- long m_numTFANs;
- long m_numVertices;
- long * m_vertices;
- long * m_sizeTFAN;
-
- };
-}
-#endif // O3DGC_TRIANGLE_FANS_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.h
deleted file mode 100644
index 65df526d1..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_TRIANGLE_LIST_DECODER_H
-#define O3DGC_TRIANGLE_LIST_DECODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcTriangleFans.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcAdjacencyInfo.h"
-
-namespace o3dgc
-{
-
- //!
- template <class T>
- class TriangleListDecoder
- {
- public:
- //! Constructor.
- TriangleListDecoder(void)
- {
- m_vertexCount = 0;
- m_triangleCount = 0;
- m_numTriangles = 0;
- m_numVertices = 0;
- m_triangles = 0;
- m_numConqueredTriangles = 0;
- m_numVisitedVertices = 0;
- m_visitedVertices = 0;
- m_visitedVerticesValence = 0;
- m_maxNumVertices = 0;
- m_maxNumTriangles = 0;
- m_itNumTFans = 0;
- m_itDegree = 0;
- m_itConfig = 0;
- m_itOperation = 0;
- m_itIndex = 0;
- m_tempTriangles = 0;
- m_tempTrianglesSize = 0;
- m_decodeTrianglesOrder = false;
- m_decodeVerticesOrder = false;
- };
- //! Destructor.
- ~TriangleListDecoder(void)
- {
- delete [] m_tempTriangles;
- };
-
- O3DGCStreamType GetStreamType() const { return m_streamType; }
- bool GetReorderTriangles() const { return m_decodeTrianglesOrder; }
- bool GetReorderVertices() const { return m_decodeVerticesOrder; }
- void SetStreamType(O3DGCStreamType streamType) { m_streamType = streamType; }
- const AdjacencyInfo & GetVertexToTriangle() const { return m_vertexToTriangle;}
- O3DGCErrorCode Decode(T * const triangles,
- const long numTriangles,
- const long numVertices,
- const BinaryStream & bstream,
- unsigned long & iterator)
- {
- unsigned char compressionMask = bstream.ReadUChar(iterator, m_streamType);
- m_decodeTrianglesOrder = ( (compressionMask&2) != 0);
- m_decodeVerticesOrder = ( (compressionMask&1) != 0);
- if (m_decodeVerticesOrder) // vertices reordering not supported
- {
- return O3DGC_ERROR_NON_SUPPORTED_FEATURE;
- }
- unsigned long maxSizeV2T = bstream.ReadUInt32(iterator, m_streamType);
- Init(triangles, numTriangles, numVertices, maxSizeV2T);
- m_ctfans.Load(bstream, iterator, m_decodeTrianglesOrder, m_streamType);
- Decompress();
- return O3DGC_OK;
- }
- O3DGCErrorCode Reorder();
-
- private:
- O3DGCErrorCode Init(T * const triangles,
- const long numTriangles,
- const long numVertices,
- const long maxSizeV2T);
- O3DGCErrorCode Decompress();
- O3DGCErrorCode CompueLocalConnectivityInfo(const long focusVertex);
- O3DGCErrorCode DecompressTFAN(const long focusVertex);
-
- unsigned long m_itNumTFans;
- unsigned long m_itDegree;
- unsigned long m_itConfig;
- unsigned long m_itOperation;
- unsigned long m_itIndex;
- long m_maxNumVertices;
- long m_maxNumTriangles;
- long m_numTriangles;
- long m_numVertices;
- long m_tempTrianglesSize;
- T * m_triangles;
- T * m_tempTriangles;
- long m_vertexCount;
- long m_triangleCount;
- long m_numConqueredTriangles;
- long m_numVisitedVertices;
- long * m_visitedVertices;
- long * m_visitedVerticesValence;
- AdjacencyInfo m_vertexToTriangle;
- CompressedTriangleFans m_ctfans;
- TriangleFans m_tfans;
- O3DGCStreamType m_streamType;
- bool m_decodeTrianglesOrder;
- bool m_decodeVerticesOrder;
- };
-}
-#include "o3dgcTriangleListDecoder.inl" // template implementation
-#endif // O3DGC_TRIANGLE_LIST_DECODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.inl
deleted file mode 100644
index dd3af4aa7..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListDecoder.inl
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_TRIANGLE_LIST_DECODER_INL
-#define O3DGC_TRIANGLE_LIST_DECODER_INL
-
-namespace o3dgc
-{
- template<class T>
- O3DGCErrorCode TriangleListDecoder<T>::Init(T * const triangles,
- const long numTriangles,
- const long numVertices,
- const long maxSizeV2T)
- {
- assert(numVertices > 0);
- assert(numTriangles > 0);
- m_numTriangles = numTriangles;
- m_numVertices = numVertices;
- m_triangles = triangles;
- m_vertexCount = 0;
- m_triangleCount = 0;
- m_itNumTFans = 0;
- m_itDegree = 0;
- m_itConfig = 0;
- m_itOperation = 0;
- m_itIndex = 0;
- if (m_numVertices > m_maxNumVertices)
- {
- m_maxNumVertices = m_numVertices;
- delete [] m_visitedVerticesValence;
- delete [] m_visitedVertices;
- m_visitedVerticesValence = new long [m_numVertices];
- m_visitedVertices = new long [m_numVertices];
- }
-
- if (m_decodeTrianglesOrder && m_tempTrianglesSize < m_numTriangles)
- {
- delete [] m_tempTriangles;
- m_tempTrianglesSize = m_numTriangles;
- m_tempTriangles = new T [3*m_tempTrianglesSize];
- }
-
- m_ctfans.SetStreamType(m_streamType);
- m_ctfans.Allocate(m_numVertices, m_numTriangles);
- m_tfans.Allocate(2 * m_numVertices, 8 * m_numVertices);
-
- // compute vertex-to-triangle adjacency information
- m_vertexToTriangle.AllocateNumNeighborsArray(numVertices);
- long * numNeighbors = m_vertexToTriangle.GetNumNeighborsBuffer();
- for(long i = 0; i < numVertices; ++i)
- {
- numNeighbors[i] = maxSizeV2T;
- }
- m_vertexToTriangle.AllocateNeighborsArray();
- m_vertexToTriangle.ClearNeighborsArray();
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode TriangleListDecoder<T>::Decompress()
- {
- for(long focusVertex = 0; focusVertex < m_numVertices; ++focusVertex)
- {
- if (focusVertex == m_vertexCount)
- {
- m_vertexCount++; // insert focusVertex
- }
- CompueLocalConnectivityInfo(focusVertex);
- DecompressTFAN(focusVertex);
- }
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode TriangleListDecoder<T>::Reorder()
- {
- if (m_decodeTrianglesOrder)
- {
- unsigned long itTriangleIndex = 0;
- long prevTriangleIndex = 0;
- long t;
- memcpy(m_tempTriangles, m_triangles, m_numTriangles * 3 * sizeof(T));
- for(long i = 0; i < m_numTriangles; ++i)
- {
- t = m_ctfans.ReadTriangleIndex(itTriangleIndex) + prevTriangleIndex;
- assert( t >= 0 && t < m_numTriangles);
- memcpy(m_triangles + 3 * t, m_tempTriangles + 3 * i, sizeof(T) * 3);
- prevTriangleIndex = t + 1;
- }
- }
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode TriangleListDecoder<T>::CompueLocalConnectivityInfo(const long focusVertex)
- {
- long t = 0;
- long p, v;
- m_numConqueredTriangles = 0;
- m_numVisitedVertices = 0;
- for(long i = m_vertexToTriangle.Begin(focusVertex); (t >= 0) && (i < m_vertexToTriangle.End(focusVertex)); ++i)
- {
- t = m_vertexToTriangle.GetNeighbor(i);
- if ( t >= 0)
- {
- ++m_numConqueredTriangles;
- p = 3*t;
- // extract visited vertices
- for(long k = 0; k < 3; ++k)
- {
- v = m_triangles[p+k];
- if (v > focusVertex) // vertices are insertices by increasing traversal order
- {
- bool foundOrInserted = false;
- for (long j = 0; j < m_numVisitedVertices; ++j)
- {
- if (v == m_visitedVertices[j])
- {
- m_visitedVerticesValence[j]++;
- foundOrInserted = true;
- break;
- }
- else if (v < m_visitedVertices[j])
- {
- ++m_numVisitedVertices;
- for (long h = m_numVisitedVertices-1; h > j; --h)
- {
- m_visitedVertices[h] = m_visitedVertices[h-1];
- m_visitedVerticesValence[h] = m_visitedVerticesValence[h-1];
- }
- m_visitedVertices[j] = v;
- m_visitedVerticesValence[j] = 1;
- foundOrInserted = true;
- break;
- }
- }
- if (!foundOrInserted)
- {
- m_visitedVertices[m_numVisitedVertices] = v;
- m_visitedVerticesValence[m_numVisitedVertices] = 1;
- m_numVisitedVertices++;
- }
- }
- }
- }
- }
- // re-order visited vertices by taking into account their valence (i.e., # of conquered triangles incident to each vertex)
- // in order to avoid config. 9
- if (m_numVisitedVertices > 2)
- {
- long y;
- for(long x = 1; x < m_numVisitedVertices; ++x)
- {
-
- if (m_visitedVerticesValence[x] == 1)
- {
- y = x;
- while( (y > 0) && (m_visitedVerticesValence[y] < m_visitedVerticesValence[y-1]) )
- {
- swap(m_visitedVerticesValence[y], m_visitedVerticesValence[y-1]);
- swap(m_visitedVertices[y], m_visitedVertices[y-1]);
- --y;
- }
- }
- }
- }
- return O3DGC_OK;
- }
- template<class T>
- O3DGCErrorCode TriangleListDecoder<T>::DecompressTFAN(const long focusVertex)
- {
- long ntfans;
- long degree, config;
- long op;
- long index;
- long k0, k1;
- long b, c, t;
-
- ntfans = m_ctfans.ReadNumTFans(m_itNumTFans);
- if (ntfans > 0)
- {
- for(long f = 0; f != ntfans; f++)
- {
- m_tfans.AddTFAN();
- degree = m_ctfans.ReadDegree(m_itDegree) +2 - m_numConqueredTriangles;
- config = m_ctfans.ReadConfig(m_itConfig);
- k0 = m_tfans.GetNumVertices();
- m_tfans.AddVertex(focusVertex);
- switch(config)
- {
- case 0:// ops: 1000001 vertices: -1 -2
- m_tfans.AddVertex(m_visitedVertices[0]);
- for(long u = 1; u < degree-1; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- m_tfans.AddVertex(m_visitedVertices[1]);
- break;
- case 1: // ops: 1xxxxxx1 vertices: -1 x x x x x -2
- m_tfans.AddVertex(m_visitedVertices[0]);
- for(long u = 1; u < degree-1; u++)
- {
- op = m_ctfans.ReadOperation(m_itOperation);
- if (op == 1)
- {
- index = m_ctfans.ReadIndex(m_itIndex);
- if ( index < 0)
- {
- m_tfans.AddVertex(m_visitedVertices[-index-1]);
- }
- else
- {
- m_tfans.AddVertex(index + focusVertex);
- }
- }
- else
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- }
- m_tfans.AddVertex(m_visitedVertices[1]);
- break;
- case 2: // ops: 00000001 vertices: -1
- for(long u = 0; u < degree-1; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- m_tfans.AddVertex(m_visitedVertices[0]);
- break;
- case 3: // ops: 00000001 vertices: -2
- for(long u=0; u < degree-1; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- m_tfans.AddVertex(m_visitedVertices[1]);
- break;
- case 4: // ops: 10000000 vertices: -1
- m_tfans.AddVertex(m_visitedVertices[0]);
- for(long u = 1; u < degree; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- break;
- case 5: // ops: 10000000 vertices: -2
- m_tfans.AddVertex(m_visitedVertices[1]);
- for(long u = 1; u < degree; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- break;
- case 6:// ops: 00000000 vertices:
- for(long u = 0; u < degree; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- break;
- case 7: // ops: 1000001 vertices: -2 -1
- m_tfans.AddVertex(m_visitedVertices[1]);
- for(long u = 1; u < degree-1; u++)
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- m_tfans.AddVertex(m_visitedVertices[0]);
- break;
- case 8: // ops: 1xxxxxx1 vertices: -2 x x x x x -1
- m_tfans.AddVertex(m_visitedVertices[1]);
- for(long u = 1; u < degree-1; u++)
- {
- op = m_ctfans.ReadOperation(m_itOperation);
- if (op == 1)
- {
- index = m_ctfans.ReadIndex(m_itIndex);
- if ( index < 0)
- {
- m_tfans.AddVertex(m_visitedVertices[-index-1]);
- }
- else
- {
- m_tfans.AddVertex(index + focusVertex);
- }
- }
- else
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- }
- m_tfans.AddVertex(m_visitedVertices[0]);
- break;
- case 9: // general case
- for(long u = 0; u < degree; u++)
- {
- op = m_ctfans.ReadOperation(m_itOperation);
- if (op == 1)
- {
- index = m_ctfans.ReadIndex(m_itIndex);
- if ( index < 0)
- {
- m_tfans.AddVertex(m_visitedVertices[-index-1]);
- }
- else
- {
- m_tfans.AddVertex(index + focusVertex);
- }
- }
- else
- {
- m_visitedVertices[m_numVisitedVertices++] = m_vertexCount;
- m_tfans.AddVertex(m_vertexCount++);
- }
- }
- break;
-
- }
- //logger.write_2_log("\t degree=%i \t cas = %i\n", degree, cas);
- k1 = m_tfans.GetNumVertices();
- b = m_tfans.GetVertex(k0+1);
- for (long k = k0+2; k < k1; k++)
- {
- c = m_tfans.GetVertex(k);
- t = m_triangleCount*3;
-
- m_triangles[t++] = (T) focusVertex;
- m_triangles[t++] = (T) b;
- m_triangles[t ] = (T) c;
-
- m_vertexToTriangle.AddNeighbor(focusVertex, m_triangleCount);
- m_vertexToTriangle.AddNeighbor(b , m_triangleCount);
- m_vertexToTriangle.AddNeighbor(c , m_triangleCount);
- b=c;
- m_triangleCount++;
- }
- }
- }
- return O3DGC_OK;
- }
-}
-#endif //O3DGC_TRIANGLE_LIST_DECODER_INL
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.h
deleted file mode 100644
index c09172273..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#pragma once
-#ifndef O3DGC_TRIANGLE_LIST_ENCODER_H
-#define O3DGC_TRIANGLE_LIST_ENCODER_H
-
-#include "o3dgcCommon.h"
-#include "o3dgcAdjacencyInfo.h"
-#include "o3dgcBinaryStream.h"
-#include "o3dgcFIFO.h"
-#include "o3dgcTriangleFans.h"
-
-namespace o3dgc
-{
- //!
- template <class T>
- class TriangleListEncoder
- {
- public:
- //! Constructor.
- TriangleListEncoder(void);
- //! Destructor.
- ~TriangleListEncoder(void);
- //!
- O3DGCErrorCode Encode(const T * const triangles,
- const unsigned long * const indexBufferIDs,
- const long numTriangles,
- const long numVertices,
- BinaryStream & bstream);
- O3DGCStreamType GetStreamType() const { return m_streamType; }
- void SetStreamType(O3DGCStreamType streamType) { m_streamType = streamType; }
- const long * GetInvVMap() const { return m_invVMap;}
- const long * GetInvTMap() const { return m_invTMap;}
- const long * GetVMap() const { return m_vmap;}
- const long * GetTMap() const { return m_tmap;}
- const AdjacencyInfo & GetVertexToTriangle() const { return m_vertexToTriangle;}
-
- private:
- O3DGCErrorCode Init(const T * const triangles,
- long numTriangles,
- long numVertices);
- O3DGCErrorCode CompueLocalConnectivityInfo(const long focusVertex);
- O3DGCErrorCode ProcessVertex( long focusVertex);
- O3DGCErrorCode ComputeTFANDecomposition(const long focusVertex);
- O3DGCErrorCode CompressTFAN(const long focusVertex);
-
- long m_vertexCount;
- long m_triangleCount;
- long m_maxNumVertices;
- long m_maxNumTriangles;
- long m_numNonConqueredTriangles;
- long m_numConqueredTriangles;
- long m_numVisitedVertices;
- long m_numTriangles;
- long m_numVertices;
- long m_maxSizeVertexToTriangle;
- T const * m_triangles;
- long * m_vtags;
- long * m_ttags;
- long * m_vmap;
- long * m_invVMap;
- long * m_tmap;
- long * m_invTMap;
- long * m_count;
- long * m_nonConqueredTriangles;
- long * m_nonConqueredEdges;
- long * m_visitedVertices;
- long * m_visitedVerticesValence;
- FIFO<long> m_vfifo;
- AdjacencyInfo m_vertexToTriangle;
- AdjacencyInfo m_triangleToTriangle;
- AdjacencyInfo m_triangleToTriangleInv;
- TriangleFans m_tfans;
- CompressedTriangleFans m_ctfans;
- O3DGCStreamType m_streamType;
- };
-}
-#include "o3dgcTriangleListEncoder.inl" // template implementation
-#endif // O3DGC_TRIANGLE_LIST_ENCODER_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.inl
deleted file mode 100644
index 017dd86bf..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcTriangleListEncoder.inl
+++ /dev/null
@@ -1,719 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_TRIANGLE_LIST_ENCODER_INL
-#define O3DGC_TRIANGLE_LIST_ENCODER_INL
-
-namespace o3dgc
-{
- // extract opposite edge
- template <class T>
- inline void CompueOppositeEdge(const long focusVertex,
- const T * triangle,
- long & a, long & b)
- {
- if ((long) triangle[0] == focusVertex)
- {
- a = triangle[1];
- b = triangle[2];
- }
- else if ((long) triangle[1] == focusVertex)
- {
- a = triangle[2];
- b = triangle[0];
- }
- else
- {
- a = triangle[0];
- b = triangle[1];
- }
- }
- inline bool IsCase0(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 1000001 vertices: -1 -2
- if ((numIndices != 2) || (degree < 2)) {
- return false;
- }
- if ((indices[0] != -1) ||(indices[1] != -2) ||
- (ops[0] != 1) ||(ops[degree-1] != 1) ) return false;
- for (long u = 1; u < degree-1; u++) {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase1(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 1xxxxxx1 indices: -1 x x x x x -2
- if ((degree < 2) || (numIndices < 1))
- {
- return false;
- }
- if ((indices[0] != -1) ||(indices[numIndices-1] != -2) ||
- (ops[0] != 1) ||(ops[degree-1] != 1) ) return false;
- return true;
- }
- inline bool IsCase2(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 00000001 indices: -1
- if ((degree < 2) || (numIndices!= 1))
- {
- return false;
- }
- if ((indices[0] != -1) || (ops[degree-1] != 1) ) return false;
- for (long u = 0; u < degree-1; u++) {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase3(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 00000001 indices: -2
- if ((degree < 2) || (numIndices!= 1))
- {
- return false;
- }
- if ((indices[0] != -2) || (ops[degree-1] != 1) ) return false;
- for (long u = 0; u < degree-1; u++) {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase4(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 10000000 indices: -1
- if ((degree < 2) || (numIndices!= 1))
- {
- return false;
- }
- if ((indices[0] != -1) || (ops[0] != 1) ) return false;
- for (long u = 1; u < degree; u++)
- {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase5(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 10000000 indices: -2
- if ((degree < 2) || (numIndices!= 1))
- {
- return false;
- }
- if ((indices[0] != -2) || (ops[0] != 1) ) return false;
- for (long u = 1; u < degree; u++) {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase6(long degree, long numIndices, const long * const ops, const long * const /*indices*/)
- {
- // ops: 0000000 indices:
- if (numIndices!= 0)
- {
- return false;
- }
- for (long u = 0; u < degree; u++)
- {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase7(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 1000001 indices: -2 -1
- if ((numIndices!= 2) || (degree < 2))
- {
- return false;
- }
- if ((indices[0] != -2) ||(indices[1] != -1) ||
- (ops[0] != 1) ||(ops[degree-1] != 1) ) return false;
- for (long u = 1; u < degree-1; u++)
- {
- if (ops[u] != 0) return false;
- }
- return true;
- }
- inline bool IsCase8(long degree, long numIndices, const long * const ops, const long * const indices)
- {
- // ops: 1xxxxxx1 indices: -1 x x x x x -2
- if ((degree < 2) || (numIndices < 1))
- {
- return false;
- }
- if ((indices[0] != -2) ||(indices[numIndices-1] != -1) ||
- (ops[0] != 1) ||(ops[degree-1] != 1) ) return false;
- return true;
- }
- template <class T>
- TriangleListEncoder<T>::TriangleListEncoder(void)
- {
- m_vtags = 0;
- m_ttags = 0;
- m_tmap = 0;
- m_vmap = 0;
- m_count = 0;
- m_invVMap = 0;
- m_invTMap = 0;
- m_nonConqueredTriangles = 0;
- m_nonConqueredEdges = 0;
- m_visitedVertices = 0;
- m_visitedVerticesValence = 0;
- m_vertexCount = 0;
- m_triangleCount = 0;
- m_maxNumVertices = 0;
- m_maxNumTriangles = 0;
- m_numTriangles = 0;
- m_numVertices = 0;
- m_triangles = 0;
- m_maxSizeVertexToTriangle = 0;
- m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
- }
- template <class T>
- TriangleListEncoder<T>::~TriangleListEncoder()
- {
- delete [] m_vtags;
- delete [] m_vmap;
- delete [] m_invVMap;
- delete [] m_invTMap;
- delete [] m_visitedVerticesValence;
- delete [] m_visitedVertices;
- delete [] m_ttags;
- delete [] m_tmap;
- delete [] m_count;
- delete [] m_nonConqueredTriangles;
- delete [] m_nonConqueredEdges;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::Init(const T * const triangles,
- long numTriangles,
- long numVertices)
- {
- assert(numVertices > 0);
- assert(numTriangles > 0);
-
- m_numTriangles = numTriangles;
- m_numVertices = numVertices;
- m_triangles = triangles;
- m_vertexCount = 0;
- m_triangleCount = 0;
-
- if (m_numVertices > m_maxNumVertices)
- {
- delete [] m_vtags;
- delete [] m_vmap;
- delete [] m_invVMap;
- delete [] m_visitedVerticesValence;
- delete [] m_visitedVertices;
- m_maxNumVertices = m_numVertices;
- m_vtags = new long [m_numVertices];
- m_vmap = new long [m_numVertices];
- m_invVMap = new long [m_numVertices];
- m_visitedVerticesValence = new long [m_numVertices];
- m_visitedVertices = new long [m_numVertices];
- }
-
- if (m_numTriangles > m_maxNumTriangles)
- {
- delete [] m_ttags;
- delete [] m_tmap;
- delete [] m_invTMap;
- delete [] m_nonConqueredTriangles;
- delete [] m_nonConqueredEdges;
- delete [] m_count;
- m_maxNumTriangles = m_numTriangles;
- m_ttags = new long [m_numTriangles];
- m_tmap = new long [m_numTriangles];
- m_invTMap = new long [m_numTriangles];
- m_count = new long [m_numTriangles+1];
- m_nonConqueredTriangles = new long [m_numTriangles];
- m_nonConqueredEdges = new long [2*m_numTriangles];
- }
-
- memset(m_vtags , 0x00, sizeof(long) * m_numVertices );
- memset(m_vmap , 0xFF, sizeof(long) * m_numVertices );
- memset(m_invVMap, 0xFF, sizeof(long) * m_numVertices );
- memset(m_ttags , 0x00, sizeof(long) * m_numTriangles);
- memset(m_tmap , 0xFF, sizeof(long) * m_numTriangles);
- memset(m_invTMap, 0xFF, sizeof(long) * m_numTriangles);
- memset(m_count , 0x00, sizeof(long) * (m_numTriangles+1));
-
- m_vfifo.Allocate(m_numVertices);
- m_ctfans.SetStreamType(m_streamType);
- m_ctfans.Allocate(m_numVertices, m_numTriangles);
-
- // compute vertex-to-triangle adjacency information
- m_vertexToTriangle.AllocateNumNeighborsArray(numVertices);
- m_vertexToTriangle.ClearNumNeighborsArray();
- long * numNeighbors = m_vertexToTriangle.GetNumNeighborsBuffer();
- for(long i = 0, t = 0; i < m_numTriangles; ++i, t+=3)
- {
- ++numNeighbors[ triangles[t ] ];
- ++numNeighbors[ triangles[t+1] ];
- ++numNeighbors[ triangles[t+2] ];
- }
- m_maxSizeVertexToTriangle = 0;
- for(long i = 0; i < numVertices; ++i)
- {
- if (m_maxSizeVertexToTriangle < numNeighbors[i])
- {
- m_maxSizeVertexToTriangle = numNeighbors[i];
- }
- }
- m_vertexToTriangle.AllocateNeighborsArray();
- m_vertexToTriangle.ClearNeighborsArray();
- for(long i = 0, t = 0; i < m_numTriangles; ++i, t+=3)
- {
- m_vertexToTriangle.AddNeighbor(triangles[t ], i);
- m_vertexToTriangle.AddNeighbor(triangles[t+1], i);
- m_vertexToTriangle.AddNeighbor(triangles[t+2], i);
- }
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::Encode(const T * const triangles,
- const unsigned long * const indexBufferIDs,
- const long numTriangles,
- const long numVertices,
- BinaryStream & bstream)
- {
- assert(numVertices > 0);
- assert(numTriangles > 0);
-
- Init(triangles, numTriangles, numVertices);
- unsigned char mask = 0;
- bool encodeTrianglesOrder = (indexBufferIDs != 0);
-
-
- if (encodeTrianglesOrder)
- {
- long numBufferIDs = 0;
- for (long t = 0; t < numTriangles; t++)
- {
- if (numBufferIDs <= (long) indexBufferIDs[t])
- {
- ++numBufferIDs;
- assert(numBufferIDs <= numTriangles);
- }
- ++m_count[indexBufferIDs[t]+1];
- }
- for (long i = 2; i <= numBufferIDs; i++)
- {
- m_count[i] += m_count[i-1];
- }
- mask += 2; // preserved triangles order
- }
- bstream.WriteUChar(mask, m_streamType);
- bstream.WriteUInt32(m_maxSizeVertexToTriangle, m_streamType);
-
- long v0;
- for (long v = 0; v < m_numVertices; v++)
- {
- if (!m_vtags[v])
- {
- m_vfifo.PushBack(v);
- m_vtags[v] = 1;
- m_vmap[v] = m_vertexCount++;
- m_invVMap[m_vmap[v]] = v;
- while (m_vfifo.GetSize() > 0 )
- {
- v0 = m_vfifo.PopFirst();
- ProcessVertex(v0);
- }
- }
- }
- if (encodeTrianglesOrder)
- {
- long t, prev = 0;
- long pred;
- for (long i = 0; i < numTriangles; ++i)
- {
- t = m_invTMap[i];
- m_tmap[t] = m_count[ indexBufferIDs[t] ]++;
- pred = m_tmap[t] - prev;
- m_ctfans.PushTriangleIndex(pred);
- prev = m_tmap[t] + 1;
- }
- for (long t = 0; t < numTriangles; ++t)
- {
- m_invTMap[m_tmap[t]] = t;
- }
- }
- m_ctfans.Save(bstream, encodeTrianglesOrder, m_streamType);
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::CompueLocalConnectivityInfo(const long focusVertex)
- {
- long t, v, p;
- m_numNonConqueredTriangles = 0;
- m_numConqueredTriangles = 0;
- m_numVisitedVertices = 0;
- for(long i = m_vertexToTriangle.Begin(focusVertex); i < m_vertexToTriangle.End(focusVertex); ++i)
- {
- t = m_vertexToTriangle.GetNeighbor(i);
-
- if ( m_ttags[t] == 0) // non-processed triangle
- {
- m_nonConqueredTriangles[m_numNonConqueredTriangles] = t;
- CompueOppositeEdge( focusVertex,
- m_triangles + (3*t),
- m_nonConqueredEdges[m_numNonConqueredTriangles*2],
- m_nonConqueredEdges[m_numNonConqueredTriangles*2+1]);
- ++m_numNonConqueredTriangles;
- }
- else // triangle already processed
- {
- m_numConqueredTriangles++;
- p = 3*t;
- // extract visited vertices
- for(long k = 0; k < 3; ++k)
- {
- v = m_triangles[p+k];
- if (m_vmap[v] > m_vmap[focusVertex]) // vertices are insertices by increasing traversal order
- {
- bool foundOrInserted = false;
- for (long j = 0; j < m_numVisitedVertices; ++j)
- {
-
- if (m_vmap[v] == m_visitedVertices[j])
- {
- m_visitedVerticesValence[j]++;
- foundOrInserted = true;
- break;
- }
- else if (m_vmap[v] < m_visitedVertices[j])
- {
- ++m_numVisitedVertices;
- for (long h = m_numVisitedVertices-1; h > j; --h)
- {
- m_visitedVertices[h] = m_visitedVertices[h-1];
- m_visitedVerticesValence[h] = m_visitedVerticesValence[h-1];
- }
- m_visitedVertices[j] = m_vmap[v];
- m_visitedVerticesValence[j] = 1;
- foundOrInserted = true;
- break;
- }
- }
- if (!foundOrInserted)
- {
- m_visitedVertices[m_numVisitedVertices] = m_vmap[v];
- m_visitedVerticesValence[m_numVisitedVertices] = 1;
- m_numVisitedVertices++;
- }
- }
- }
- }
- }
- // re-order visited vertices by taking into account their valence (i.e., # of conquered triangles incident to each vertex)
- // in order to avoid config. 9
- if (m_numVisitedVertices > 2)
- {
- long y;
- for(long x = 1; x < m_numVisitedVertices; ++x)
- {
-
- if (m_visitedVerticesValence[x] == 1)
- {
- y = x;
- while( (y > 0) && (m_visitedVerticesValence[y] < m_visitedVerticesValence[y-1]) )
- {
- swap(m_visitedVerticesValence[y], m_visitedVerticesValence[y-1]);
- swap(m_visitedVertices[y], m_visitedVertices[y-1]);
- --y;
- }
- }
- }
- }
- if (m_numNonConqueredTriangles > 0)
- {
- // compute triangle-to-triangle adjacency information
- m_triangleToTriangle.AllocateNumNeighborsArray(m_numNonConqueredTriangles);
- m_triangleToTriangle.ClearNumNeighborsArray();
- m_triangleToTriangleInv.AllocateNumNeighborsArray(m_numNonConqueredTriangles);
- m_triangleToTriangleInv.ClearNumNeighborsArray();
- long * const numNeighbors = m_triangleToTriangle.GetNumNeighborsBuffer();
- long * const invNumNeighbors = m_triangleToTriangleInv.GetNumNeighborsBuffer();
- for(long i = 0; i < m_numNonConqueredTriangles; ++i)
- {
- for(long j = i+1; j < m_numNonConqueredTriangles; ++j)
- {
- if (m_nonConqueredEdges[2*i+1] == m_nonConqueredEdges[2*j]) // edge i is connected to edge j
- {
- ++numNeighbors[i];
- ++invNumNeighbors[j];
- }
- if (m_nonConqueredEdges[2*i] == m_nonConqueredEdges[2*j+1]) // edge i is connected to edge j
- {
- ++numNeighbors[j];
- ++invNumNeighbors[i];
- }
- }
- }
- m_triangleToTriangle.AllocateNeighborsArray();
- m_triangleToTriangle.ClearNeighborsArray();
- m_triangleToTriangleInv.AllocateNeighborsArray();
- m_triangleToTriangleInv.ClearNeighborsArray();
- for(long i = 0; i < m_numNonConqueredTriangles; ++i)
- {
- for(long j = 1; j < m_numNonConqueredTriangles; ++j)
- {
- if (m_nonConqueredEdges[2*i+1] == m_nonConqueredEdges[2*j]) // edge i is connected to edge j
- {
- m_triangleToTriangle.AddNeighbor(i, j);
- m_triangleToTriangleInv.AddNeighbor(j, i);
- }
- if (m_nonConqueredEdges[2*i] == m_nonConqueredEdges[2*j+1]) // edge i is connected to edge j
- {
- m_triangleToTriangle.AddNeighbor(j, i);
- m_triangleToTriangleInv.AddNeighbor(i, j);
- }
- }
- }
- }
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::ComputeTFANDecomposition(const long focusVertex)
- {
- long processedTriangles = 0;
- long minNumInputEdges;
- long numInputEdges;
- long indexSeedTriangle;
- long seedTriangle;
- long currentIndex;
- long currentTriangle;
- long i0, i1, index;
-
- m_tfans.Clear();
- while (processedTriangles != m_numNonConqueredTriangles)
- {
- // find non processed triangle with lowest number of inputs
- minNumInputEdges = m_numTriangles;
- indexSeedTriangle = -1;
- for(long i = 0; i < m_numNonConqueredTriangles; ++i)
- {
- numInputEdges = m_triangleToTriangleInv.GetNumNeighbors(i);
- if ( !m_ttags[m_nonConqueredTriangles[i]] &&
- numInputEdges < minNumInputEdges )
- {
- minNumInputEdges = numInputEdges;
- indexSeedTriangle = i;
- if (minNumInputEdges == 0) // found boundary triangle
- {
- break;
- }
- }
- }
- assert(indexSeedTriangle >= 0);
- seedTriangle = m_nonConqueredTriangles[indexSeedTriangle];
- m_tfans.AddTFAN();
- m_tfans.AddVertex( focusVertex );
- m_tfans.AddVertex( m_nonConqueredEdges[indexSeedTriangle*2] );
- m_tfans.AddVertex( m_nonConqueredEdges[indexSeedTriangle*2 + 1] );
- m_ttags[ seedTriangle ] = 1; // mark triangle as processed
- m_tmap[seedTriangle] = m_triangleCount++;
- m_invTMap[m_tmap[seedTriangle]] = seedTriangle;
- ++processedTriangles;
- currentIndex = indexSeedTriangle;
- currentTriangle = seedTriangle;
- do
- {
- // find next triangle
- i0 = m_triangleToTriangle.Begin(currentIndex);
- i1 = m_triangleToTriangle.End(currentIndex);
- currentIndex = -1;
- for(long i = i0; i < i1; ++i)
- {
- index = m_triangleToTriangle.GetNeighbor(i);
- currentTriangle = m_nonConqueredTriangles[index];
- if ( !m_ttags[currentTriangle] )
- {
- currentIndex = index;
- m_tfans.AddVertex( m_nonConqueredEdges[currentIndex*2+1] );
- m_ttags[currentTriangle] = 1; // mark triangle as processed
- m_tmap [currentTriangle] = m_triangleCount++;
- m_invTMap[m_tmap [currentTriangle]] = currentTriangle;
- ++processedTriangles;
- break;
- }
- }
- } while (currentIndex != -1);
- }
-
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::CompressTFAN(const long focusVertex)
- {
- m_ctfans.PushNumTFans(m_tfans.GetNumTFANs());
-
- const long ntfans = m_tfans.GetNumTFANs();
- long degree;
- long k0, k1;
- long v0;
- long ops[O3DGC_MAX_TFAN_SIZE];
- long indices[O3DGC_MAX_TFAN_SIZE];
-
- long numOps;
- long numIndices;
- long pos;
- long found;
-
- if (m_tfans.GetNumTFANs() > 0)
- {
- for(long f = 0; f != ntfans; f++)
- {
- degree = m_tfans.GetTFANSize(f) - 1;
- m_ctfans.PushDegree(degree-2+ m_numConqueredTriangles);
- numOps = 0;
- numIndices = 0;
- k0 = 1 + m_tfans.Begin(f);
- k1 = m_tfans.End(f);
- for(long k = k0; k < k1; k++)
- {
- v0 = m_tfans.GetVertex(k);
- if (m_vtags[v0] == 0)
- {
- ops[numOps++] = 0;
- m_vtags[v0] = 1;
- m_vmap[v0] = m_vertexCount++;
- m_invVMap[m_vmap[v0]] = v0;
- m_vfifo.PushBack(v0);
- m_visitedVertices[m_numVisitedVertices++] = m_vmap[v0];
- }
- else
- {
- ops[numOps++] = 1;
- pos = 0;
- found = 0;
- for(long u=0; u < m_numVisitedVertices; ++u)
- {
- pos++;
- if (m_visitedVertices[u] == m_vmap[v0])
- {
- found = 1;
- break;
- }
- }
- if (found == 1)
- {
- indices[numIndices++] = -pos;
- }
- else
- {
- indices[numIndices++] = m_vmap[v0] - m_vmap[focusVertex];
- }
- }
- }
- //-----------------------------------------------
- if (IsCase0(degree, numIndices, ops, indices))
- {
- // ops: 1000001 vertices: -1 -2
- m_ctfans.PushConfig(0);
- }
- else if (IsCase1(degree, numIndices, ops, indices))
- {
- // ops: 1xxxxxx1 vertices: -1 x x x x x -2
- long u = 1;
- for(u = 1; u < degree-1; u++)
- {
- m_ctfans.PushOperation(ops[u]);
- }
- for(u =1; u < numIndices-1; u++)
- {
- m_ctfans.PushIndex(indices[u]);
- }
- m_ctfans.PushConfig(1);
- }
- else if (IsCase2(degree, numIndices, ops, indices))
- {
- // ops: 00000001 vertices: -1
- m_ctfans.PushConfig(2);
- }
- else if (IsCase3(degree, numIndices, ops, indices))
- {
- // ops: 00000001 vertices: -2
- m_ctfans.PushConfig(3);
- }
- else if (IsCase4(degree, numIndices, ops, indices))
- {
- // ops: 10000000 vertices: -1
- m_ctfans.PushConfig(4);
- }
- else if (IsCase5(degree, numIndices, ops, indices))
- {
- // ops: 10000000 vertices: -2
- m_ctfans.PushConfig(5);
- }
- else if (IsCase6(degree, numIndices, ops, indices))
- {
- // ops: 00000000 vertices:
- m_ctfans.PushConfig(6);
- }
- else if (IsCase7(degree, numIndices, ops, indices))
- {
- // ops: 1000001 vertices: -1 -2
- m_ctfans.PushConfig(7);
- }
- else if (IsCase8(degree, numIndices, ops, indices))
- {
- // ops: 1xxxxxx1 vertices: -2 x x x x x -1
- long u = 1;
- for(u =1; u < degree-1; u++)
- {
- m_ctfans.PushOperation(ops[u]);
- }
- for(u =1; u < numIndices-1; u++)
- {
- m_ctfans.PushIndex(indices[u]);
- }
- m_ctfans.PushConfig(8);
- }
- else
- {
- long u = 0;
- for(u =0; u < degree; u++)
- {
- m_ctfans.PushOperation(ops[u]);
- }
- for(u =0; u < numIndices; u++)
- {
- m_ctfans.PushIndex(indices[u]);
- }
- m_ctfans.PushConfig(9);
- }
- }
- }
- return O3DGC_OK;
- }
- template <class T>
- O3DGCErrorCode TriangleListEncoder<T>::ProcessVertex(const long focusVertex)
- {
- CompueLocalConnectivityInfo(focusVertex);
- ComputeTFANDecomposition(focusVertex);
- CompressTFAN(focusVertex);
- return O3DGC_OK;
- }
-}
-#endif //O3DGC_TRIANGLE_LIST_ENCODER_INL
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.h b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.h
deleted file mode 100644
index 08d3ed564..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_VECTOR_H
-#define O3DGC_VECTOR_H
-
-#include "o3dgcCommon.h"
-
-namespace o3dgc
-{
- const unsigned long O3DGC_DEFAULT_VECTOR_SIZE = 32;
-
- //!
- template < typename T > class Vector
- {
- public:
- //! Constructor.
- Vector()
- {
- m_allocated = 0;
- m_size = 0;
- m_buffer = 0;
- };
- //! Destructor.
- ~Vector(void)
- {
- delete [] m_buffer;
- };
- T & operator[](unsigned long i)
- {
- return m_buffer[i];
- }
- const T & operator[](unsigned long i) const
- {
- return m_buffer[i];
- }
- void Allocate(unsigned long size)
- {
- if (size > m_allocated)
- {
- m_allocated = size;
- T * tmp = new T [m_allocated];
- if (m_size > 0)
- {
- memcpy(tmp, m_buffer, m_size * sizeof(T) );
- delete [] m_buffer;
- }
- m_buffer = tmp;
- }
- };
- void PushBack(const T & value)
- {
- if (m_size == m_allocated)
- {
- m_allocated *= 2;
- if (m_allocated < O3DGC_DEFAULT_VECTOR_SIZE)
- {
- m_allocated = O3DGC_DEFAULT_VECTOR_SIZE;
- }
- T * tmp = new T [m_allocated];
- if (m_size > 0)
- {
- memcpy(tmp, m_buffer, m_size * sizeof(T) );
- delete [] m_buffer;
- }
- m_buffer = tmp;
- }
- assert(m_size < m_allocated);
- m_buffer[m_size++] = value;
- }
- const T * GetBuffer() const { return m_buffer;};
- T * GetBuffer() { return m_buffer;};
- unsigned long GetSize() const { return m_size;};
- void SetSize(unsigned long size)
- {
- assert(size <= m_allocated);
- m_size = size;
- };
- unsigned long GetAllocatedSize() const { return m_allocated;};
- void Clear(){ m_size = 0;};
-
- private:
- T * m_buffer;
- unsigned long m_allocated;
- unsigned long m_size;
- };
-
-
-
-
- //! Vector dim 3.
- template < typename T > class Vec3
- {
- public:
- T & operator[](unsigned long i) { return m_data[i];}
- const T & operator[](unsigned long i) const { return m_data[i];}
- T & X();
- T & Y();
- T & Z();
- const T & X() const;
- const T & Y() const;
- const T & Z() const;
- double GetNorm() const;
- void operator= (const Vec3 & rhs);
- void operator+=(const Vec3 & rhs);
- void operator-=(const Vec3 & rhs);
- void operator-=(T a);
- void operator+=(T a);
- void operator/=(T a);
- void operator*=(T a);
- Vec3 operator^ (const Vec3 & rhs) const;
- T operator* (const Vec3 & rhs) const;
- Vec3 operator+ (const Vec3 & rhs) const;
- Vec3 operator- (const Vec3 & rhs) const;
- Vec3 operator- () const;
- Vec3 operator* (T rhs) const;
- Vec3 operator/ (T rhs) const;
- Vec3();
- Vec3(T a);
- Vec3(T x, T y, T z);
- Vec3(const Vec3 & rhs);
- ~Vec3(void);
-
- private:
- T m_data[3];
- };
- //! Vector dim 2.
- template < typename T > class Vec2
- {
- public:
- T & operator[](unsigned long i) { return m_data[i];}
- const T & operator[](unsigned long i) const { return m_data[i];}
- T & X();
- T & Y();
- const T & X() const;
- const T & Y() const;
- double GetNorm() const;
- void operator= (const Vec2 & rhs);
- void operator+=(const Vec2 & rhs);
- void operator-=(const Vec2 & rhs);
- void operator-=(T a);
- void operator+=(T a);
- void operator/=(T a);
- void operator*=(T a);
- T operator^ (const Vec2 & rhs) const;
- T operator* (const Vec2 & rhs) const;
- Vec2 operator+ (const Vec2 & rhs) const;
- Vec2 operator- (const Vec2 & rhs) const;
- Vec2 operator- () const;
- Vec2 operator* (T rhs) const;
- Vec2 operator/ (T rhs) const;
- Vec2();
- Vec2(T a);
- Vec2(T x, T y);
- Vec2(const Vec2 & rhs);
- ~Vec2(void);
-
- private:
- T m_data[2];
- };
-}
-#include "o3dgcVector.inl" // template implementation
-#endif // O3DGC_VECTOR_H
-
diff --git a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.inl b/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.inl
deleted file mode 100644
index 5549b00ce..000000000
--- a/src/3rdparty/assimp/contrib/Open3DGC/o3dgcVector.inl
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
-Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-#ifndef O3DGC_VECTOR_INL
-#define O3DGC_VECTOR_INL
-namespace o3dgc
-{
- template <typename T>
- inline Vec3<T> operator*(T lhs, const Vec3<T> & rhs)
- {
- return Vec3<T>(lhs * rhs.X(), lhs * rhs.Y(), lhs * rhs.Z());
- }
- template <typename T>
- inline T & Vec3<T>::X()
- {
- return m_data[0];
- }
- template <typename T>
- inline T & Vec3<T>::Y()
- {
- return m_data[1];
- }
- template <typename T>
- inline T & Vec3<T>::Z()
- {
- return m_data[2];
- }
- template <typename T>
- inline const T & Vec3<T>::X() const
- {
- return m_data[0];
- }
- template <typename T>
- inline const T & Vec3<T>::Y() const
- {
- return m_data[1];
- }
- template <typename T>
- inline const T & Vec3<T>::Z() const
- {
- return m_data[2];
- }
- template <typename T>
- inline double Vec3<T>::GetNorm() const
- {
- double a = (double) (m_data[0]);
- double b = (double) (m_data[1]);
- double c = (double) (m_data[2]);
- return sqrt(a*a+b*b+c*c);
- }
- template <typename T>
- inline void Vec3<T>::operator= (const Vec3 & rhs)
- {
- this->m_data[0] = rhs.m_data[0];
- this->m_data[1] = rhs.m_data[1];
- this->m_data[2] = rhs.m_data[2];
- }
- template <typename T>
- inline void Vec3<T>::operator+=(const Vec3 & rhs)
- {
- this->m_data[0] += rhs.m_data[0];
- this->m_data[1] += rhs.m_data[1];
- this->m_data[2] += rhs.m_data[2];
- }
- template <typename T>
- inline void Vec3<T>::operator-=(const Vec3 & rhs)
- {
- this->m_data[0] -= rhs.m_data[0];
- this->m_data[1] -= rhs.m_data[1];
- this->m_data[2] -= rhs.m_data[2];
- }
- template <typename T>
- inline void Vec3<T>::operator-=(T a)
- {
- this->m_data[0] -= a;
- this->m_data[1] -= a;
- this->m_data[2] -= a;
- }
- template <typename T>
- inline void Vec3<T>::operator+=(T a)
- {
- this->m_data[0] += a;
- this->m_data[1] += a;
- this->m_data[2] += a;
- }
- template <typename T>
- inline void Vec3<T>::operator/=(T a)
- {
- this->m_data[0] /= a;
- this->m_data[1] /= a;
- this->m_data[2] /= a;
- }
- template <typename T>
- inline void Vec3<T>::operator*=(T a)
- {
- this->m_data[0] *= a;
- this->m_data[1] *= a;
- this->m_data[2] *= a;
- }
- template <typename T>
- inline Vec3<T> Vec3<T>::operator^ (const Vec3<T> & rhs) const
- {
- return Vec3<T>(m_data[1] * rhs.m_data[2] - m_data[2] * rhs.m_data[1],
- m_data[2] * rhs.m_data[0] - m_data[0] * rhs.m_data[2],
- m_data[0] * rhs.m_data[1] - m_data[1] * rhs.m_data[0]);
- }
- template <typename T>
- inline T Vec3<T>::operator*(const Vec3<T> & rhs) const
- {
- return (m_data[0] * rhs.m_data[0] + m_data[1] * rhs.m_data[1] + m_data[2] * rhs.m_data[2]);
- }
- template <typename T>
- inline Vec3<T> Vec3<T>::operator+(const Vec3<T> & rhs) const
- {
- return Vec3<T>(m_data[0] + rhs.m_data[0],m_data[1] + rhs.m_data[1],m_data[2] + rhs.m_data[2]);
- }
- template <typename T>
- inline Vec3<T> Vec3<T>::operator-(const Vec3<T> & rhs) const
- {
- return Vec3<T>(m_data[0] - rhs.m_data[0],m_data[1] - rhs.m_data[1],m_data[2] - rhs.m_data[2]);
- }
- template <typename T>
- inline Vec3<T> Vec3<T>::operator-() const
- {
- return Vec3<T>(-m_data[0],-m_data[1],-m_data[2]);
- }
-
- template <typename T>
- inline Vec3<T> Vec3<T>::operator*(T rhs) const
- {
- return Vec3<T>(rhs * this->m_data[0], rhs * this->m_data[1], rhs * this->m_data[2]);
- }
- template <typename T>
- inline Vec3<T> Vec3<T>::operator/ (T rhs) const
- {
- return Vec3<T>(m_data[0] / rhs, m_data[1] / rhs, m_data[2] / rhs);
- }
- template <typename T>
- inline Vec3<T>::Vec3(T a)
- {
- m_data[0] = m_data[1] = m_data[2] = a;
- }
- template <typename T>
- inline Vec3<T>::Vec3(T x, T y, T z)
- {
- m_data[0] = x;
- m_data[1] = y;
- m_data[2] = z;
- }
- template <typename T>
- inline Vec3<T>::Vec3(const Vec3 & rhs)
- {
- m_data[0] = rhs.m_data[0];
- m_data[1] = rhs.m_data[1];
- m_data[2] = rhs.m_data[2];
- }
- template <typename T>
- inline Vec3<T>::~Vec3(void){};
-
- template <typename T>
- inline Vec3<T>::Vec3() {}
-
- template <typename T>
- inline Vec2<T> operator*(T lhs, const Vec2<T> & rhs)
- {
- return Vec2<T>(lhs * rhs.X(), lhs * rhs.Y());
- }
- template <typename T>
- inline T & Vec2<T>::X()
- {
- return m_data[0];
- }
- template <typename T>
- inline T & Vec2<T>::Y()
- {
- return m_data[1];
- }
- template <typename T>
- inline const T & Vec2<T>::X() const
- {
- return m_data[0];
- }
- template <typename T>
- inline const T & Vec2<T>::Y() const
- {
- return m_data[1];
- }
- template <typename T>
- inline double Vec2<T>::GetNorm() const
- {
- double a = (double) (m_data[0]);
- double b = (double) (m_data[1]);
- return sqrt(a*a+b*b);
- }
- template <typename T>
- inline void Vec2<T>::operator= (const Vec2 & rhs)
- {
- this->m_data[0] = rhs.m_data[0];
- this->m_data[1] = rhs.m_data[1];
- }
- template <typename T>
- inline void Vec2<T>::operator+=(const Vec2 & rhs)
- {
- this->m_data[0] += rhs.m_data[0];
- this->m_data[1] += rhs.m_data[1];
- }
- template <typename T>
- inline void Vec2<T>::operator-=(const Vec2 & rhs)
- {
- this->m_data[0] -= rhs.m_data[0];
- this->m_data[1] -= rhs.m_data[1];
- }
- template <typename T>
- inline void Vec2<T>::operator-=(T a)
- {
- this->m_data[0] -= a;
- this->m_data[1] -= a;
- }
- template <typename T>
- inline void Vec2<T>::operator+=(T a)
- {
- this->m_data[0] += a;
- this->m_data[1] += a;
- }
- template <typename T>
- inline void Vec2<T>::operator/=(T a)
- {
- this->m_data[0] /= a;
- this->m_data[1] /= a;
- }
- template <typename T>
- inline void Vec2<T>::operator*=(T a)
- {
- this->m_data[0] *= a;
- this->m_data[1] *= a;
- }
- template <typename T>
- inline T Vec2<T>::operator^ (const Vec2<T> & rhs) const
- {
- return m_data[0] * rhs.m_data[1] - m_data[1] * rhs.m_data[0];
- }
- template <typename T>
- inline T Vec2<T>::operator*(const Vec2<T> & rhs) const
- {
- return (m_data[0] * rhs.m_data[0] + m_data[1] * rhs.m_data[1]);
- }
- template <typename T>
- inline Vec2<T> Vec2<T>::operator+(const Vec2<T> & rhs) const
- {
- return Vec2<T>(m_data[0] + rhs.m_data[0],m_data[1] + rhs.m_data[1]);
- }
- template <typename T>
- inline Vec2<T> Vec2<T>::operator-(const Vec2<T> & rhs) const
- {
- return Vec2<T>(m_data[0] - rhs.m_data[0],m_data[1] - rhs.m_data[1]);
- }
- template <typename T>
- inline Vec2<T> Vec2<T>::operator-() const
- {
- return Vec2<T>(-m_data[0],-m_data[1]) ;
- }
-
- template <typename T>
- inline Vec2<T> Vec2<T>::operator*(T rhs) const
- {
- return Vec2<T>(rhs * this->m_data[0], rhs * this->m_data[1]);
- }
- template <typename T>
- inline Vec2<T> Vec2<T>::operator/ (T rhs) const
- {
- return Vec2<T>(m_data[0] / rhs, m_data[1] / rhs);
- }
- template <typename T>
- inline Vec2<T>::Vec2(T a)
- {
- m_data[0] = m_data[1] = a;
- }
- template <typename T>
- inline Vec2<T>::Vec2(T x, T y)
- {
- m_data[0] = x;
- m_data[1] = y;
- }
- template <typename T>
- inline Vec2<T>::Vec2(const Vec2 & rhs)
- {
- m_data[0] = rhs.m_data[0];
- m_data[1] = rhs.m_data[1];
- }
- template <typename T>
- inline Vec2<T>::~Vec2(void){};
-
- template <typename T>
- inline Vec2<T>::Vec2() {}
-}
-#endif //O3DGC_VECTOR_INL
-
diff --git a/src/3rdparty/assimp/contrib/clipper/License.txt b/src/3rdparty/assimp/contrib/clipper/License.txt
deleted file mode 100644
index 8e2278cef..000000000
--- a/src/3rdparty/assimp/contrib/clipper/License.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-The Clipper code library, the "Software" (that includes Delphi, C++ & C#
-source code, accompanying samples and documentation), has been released
-under the following license, terms and conditions:
-
-Boost Software License - Version 1.0 - August 17th, 2003
-http://www.boost.org/LICENSE_1_0.txt
-
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
diff --git a/src/3rdparty/assimp/contrib/clipper/clipper.cpp b/src/3rdparty/assimp/contrib/clipper/clipper.cpp
deleted file mode 100644
index 074f22b21..000000000
--- a/src/3rdparty/assimp/contrib/clipper/clipper.cpp
+++ /dev/null
@@ -1,3451 +0,0 @@
-/*******************************************************************************
-* *
-* Author : Angus Johnson *
-* Version : 4.8.8 *
-* Date : 30 August 2012 *
-* Website : http://www.angusj.com *
-* Copyright : Angus Johnson 2010-2012 *
-* *
-* License: *
-* Use, modification & distribution is subject to Boost Software License Ver 1. *
-* http://www.boost.org/LICENSE_1_0.txt *
-* *
-* Attributions: *
-* The code in this library is an extension of Bala Vatti's clipping algorithm: *
-* "A generic solution to polygon clipping" *
-* Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. *
-* http://portal.acm.org/citation.cfm?id=129906 *
-* *
-* Computer graphics and geometric modeling: implementation and algorithms *
-* By Max K. Agoston *
-* Springer; 1 edition (January 4, 2005) *
-* http://books.google.com/books?q=vatti+clipping+agoston *
-* *
-* See also: *
-* "Polygon Offsetting by Computing Winding Numbers" *
-* Paper no. DETC2005-85513 pp. 565-575 *
-* ASME 2005 International Design Engineering Technical Conferences *
-* and Computers and Information in Engineering Conference (IDETC/CIE2005) *
-* September 24-28, 2005 , Long Beach, California, USA *
-* http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf *
-* *
-*******************************************************************************/
-
-/*******************************************************************************
-* *
-* This is a translation of the Delphi Clipper library and the naming style *
-* used has retained a Delphi flavour. *
-* *
-*******************************************************************************/
-
-#include "clipper.hpp"
-#include <cmath>
-#include <vector>
-#include <algorithm>
-#include <stdexcept>
-#include <cassert>
-#include <cstring>
-#include <cstdlib>
-#include <ostream>
-
-namespace ClipperLib {
-
-static long64 const loRange = 0x3FFFFFFF;
-static long64 const hiRange = 0x3FFFFFFFFFFFFFFFLL;
-static double const pi = 3.141592653589793238;
-enum Direction { dRightToLeft, dLeftToRight };
-
-#define HORIZONTAL (-1.0E+40)
-#define TOLERANCE (1.0e-20)
-#define NEAR_ZERO(val) (((val) > -TOLERANCE) && ((val) < TOLERANCE))
-#define NEAR_EQUAL(a, b) NEAR_ZERO((a) - (b))
-
-inline long64 Abs(long64 val)
-{
- return val < 0 ? -val : val;
-}
-//------------------------------------------------------------------------------
-
-//------------------------------------------------------------------------------
-// Int128 class (enables safe math on signed 64bit integers)
-// eg Int128 val1((long64)9223372036854775807); //ie 2^63 -1
-// Int128 val2((long64)9223372036854775807);
-// Int128 val3 = val1 * val2;
-// val3.AsString => "85070591730234615847396907784232501249" (8.5e+37)
-//------------------------------------------------------------------------------
-
-class Int128
-{
- public:
-
- Int128(long64 _lo = 0)
- {
- lo = _lo;
- if (lo < 0) hi = -1; else hi = 0;
- }
-
- Int128(const Int128 &val): hi(val.hi), lo(val.lo){}
-
- long64 operator = (const long64 &val)
- {
- lo = val;
- if (lo < 0) hi = -1; else hi = 0;
- return val;
- }
-
- bool operator == (const Int128 &val) const
- {return (hi == val.hi && lo == val.lo);}
-
- bool operator != (const Int128 &val) const
- { return !(*this == val);}
-
- bool operator > (const Int128 &val) const
- {
- if (hi != val.hi)
- return hi > val.hi;
- else
- return lo > val.lo;
- }
-
- bool operator < (const Int128 &val) const
- {
- if (hi != val.hi)
- return hi < val.hi;
- else
- return lo < val.lo;
- }
-
- bool operator >= (const Int128 &val) const
- { return !(*this < val);}
-
- bool operator <= (const Int128 &val) const
- { return !(*this > val);}
-
- Int128& operator += (const Int128 &rhs)
- {
- hi += rhs.hi;
- lo += rhs.lo;
- if (ulong64(lo) < ulong64(rhs.lo)) hi++;
- return *this;
- }
-
- Int128 operator + (const Int128 &rhs) const
- {
- Int128 result(*this);
- result+= rhs;
- return result;
- }
-
- Int128& operator -= (const Int128 &rhs)
- {
- Int128 tmp(rhs);
- Negate(tmp);
- *this += tmp;
- return *this;
- }
-
- //Int128 operator -() const
- //{
- // Int128 result(*this);
- // if (result.lo == 0) {
- // if (result.hi != 0) result.hi = -1;
- // }
- // else {
- // result.lo = -result.lo;
- // result.hi = ~result.hi;
- // }
- // return result;
- //}
-
- Int128 operator - (const Int128 &rhs) const
- {
- Int128 result(*this);
- result -= rhs;
- return result;
- }
-
- Int128 operator * (const Int128 &rhs) const
- {
- if ( !(hi == 0 || hi == -1) || !(rhs.hi == 0 || rhs.hi == -1))
- throw "Int128 operator*: overflow error";
- bool negate = (hi < 0) != (rhs.hi < 0);
-
- Int128 tmp(*this);
- if (tmp.hi < 0) Negate(tmp);
- ulong64 int1Hi = ulong64(tmp.lo) >> 32;
- ulong64 int1Lo = ulong64(tmp.lo & 0xFFFFFFFF);
-
- tmp = rhs;
- if (tmp.hi < 0) Negate(tmp);
- ulong64 int2Hi = ulong64(tmp.lo) >> 32;
- ulong64 int2Lo = ulong64(tmp.lo & 0xFFFFFFFF);
-
- //nb: see comments in clipper.pas
- ulong64 a = int1Hi * int2Hi;
- ulong64 b = int1Lo * int2Lo;
- ulong64 c = int1Hi * int2Lo + int1Lo * int2Hi;
-
- tmp.hi = long64(a + (c >> 32));
- tmp.lo = long64(c << 32);
- tmp.lo += long64(b);
- if (ulong64(tmp.lo) < b) tmp.hi++;
- if (negate) Negate(tmp);
- return tmp;
- }
-
- Int128 operator/ (const Int128 &rhs) const
- {
- if (rhs.lo == 0 && rhs.hi == 0)
- throw "Int128 operator/: divide by zero";
- bool negate = (rhs.hi < 0) != (hi < 0);
- Int128 result(*this), denom(rhs);
- if (result.hi < 0) Negate(result);
- if (denom.hi < 0) Negate(denom);
- if (denom > result) return Int128(0); //result is only a fraction of 1
- Negate(denom);
-
- Int128 p(0);
- for (int i = 0; i < 128; ++i)
- {
- p.hi = p.hi << 1;
- if (p.lo < 0) p.hi++;
- p.lo = long64(p.lo) << 1;
- if (result.hi < 0) p.lo++;
- result.hi = result.hi << 1;
- if (result.lo < 0) result.hi++;
- result.lo = long64(result.lo) << 1;
- Int128 p2(p);
- p += denom;
- if (p.hi < 0) p = p2;
- else result.lo++;
- }
- if (negate) Negate(result);
- return result;
- }
-
- double AsDouble() const
- {
- const double shift64 = 18446744073709551616.0; //2^64
- const double bit64 = 9223372036854775808.0;
- if (hi < 0)
- {
- Int128 tmp(*this);
- Negate(tmp);
- if (tmp.lo < 0)
- return (double)tmp.lo - bit64 - tmp.hi * shift64;
- else
- return -(double)tmp.lo - tmp.hi * shift64;
- }
- else if (lo < 0)
- return -(double)lo + bit64 + hi * shift64;
- else
- return (double)lo + (double)hi * shift64;
- }
-
- //for bug testing ...
- //std::string AsString() const
- //{
- // std::string result;
- // unsigned char r = 0;
- // Int128 tmp(0), val(*this);
- // if (hi < 0) Negate(val);
- // result.resize(50);
- // std::string::size_type i = result.size() -1;
- // while (val.hi != 0 || val.lo != 0)
- // {
- // Div10(val, tmp, r);
- // result[i--] = char('0' + r);
- // val = tmp;
- // }
- // if (hi < 0) result[i--] = '-';
- // result.erase(0,i+1);
- // if (result.size() == 0) result = "0";
- // return result;
- //}
-
-private:
- long64 hi;
- long64 lo;
-
- static void Negate(Int128 &val)
- {
- if (val.lo == 0) {
- if (val.hi != 0) val.hi = -val.hi;;
- }
- else {
- val.lo = -val.lo;
- val.hi = ~val.hi;
- }
- }
-
- //debugging only ...
- //void Div10(const Int128 val, Int128& result, unsigned char & remainder) const
- //{
- // remainder = 0;
- // result = 0;
- // for (int i = 63; i >= 0; --i)
- // {
- // if ((val.hi & ((long64)1 << i)) != 0)
- // remainder = char((remainder * 2) + 1); else
- // remainder *= char(2);
- // if (remainder >= 10)
- // {
- // result.hi += ((long64)1 << i);
- // remainder -= char(10);
- // }
- // }
- // for (int i = 63; i >= 0; --i)
- // {
- // if ((val.lo & ((long64)1 << i)) != 0)
- // remainder = char((remainder * 2) + 1); else
- // remainder *= char(2);
- // if (remainder >= 10)
- // {
- // result.lo += ((long64)1 << i);
- // remainder -= char(10);
- // }
- // }
- //}
-};
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-bool FullRangeNeeded(const Polygon &pts)
-{
- bool result = false;
- for (Polygon::size_type i = 0; i < pts.size(); ++i)
- {
- if (Abs(pts[i].X) > hiRange || Abs(pts[i].Y) > hiRange)
- throw "Coordinate exceeds range bounds.";
- else if (Abs(pts[i].X) > loRange || Abs(pts[i].Y) > loRange)
- result = true;
- }
- return result;
-}
-//------------------------------------------------------------------------------
-
-bool Orientation(const Polygon &poly)
-{
- int highI = (int)poly.size() -1;
- if (highI < 2) return false;
-
- int j = 0, jplus, jminus;
- for (int i = 0; i <= highI; ++i)
- {
- if (poly[i].Y < poly[j].Y) continue;
- if ((poly[i].Y > poly[j].Y || poly[i].X < poly[j].X)) j = i;
- };
- if (j == highI) jplus = 0;
- else jplus = j +1;
- if (j == 0) jminus = highI;
- else jminus = j -1;
-
- IntPoint vec1, vec2;
- //get cross product of vectors of the edges adjacent to highest point ...
- vec1.X = poly[j].X - poly[jminus].X;
- vec1.Y = poly[j].Y - poly[jminus].Y;
- vec2.X = poly[jplus].X - poly[j].X;
- vec2.Y = poly[jplus].Y - poly[j].Y;
-
- if (Abs(vec1.X) > loRange || Abs(vec1.Y) > loRange ||
- Abs(vec2.X) > loRange || Abs(vec2.Y) > loRange)
- {
- if (Abs(vec1.X) > hiRange || Abs(vec1.Y) > hiRange ||
- Abs(vec2.X) > hiRange || Abs(vec2.Y) > hiRange)
- throw "Coordinate exceeds range bounds.";
- Int128 cross = Int128(vec1.X) * Int128(vec2.Y) -
- Int128(vec2.X) * Int128(vec1.Y);
- return cross >= 0;
- }
- else
- return (vec1.X * vec2.Y - vec2.X * vec1.Y) >= 0;
-}
-//------------------------------------------------------------------------------
-
-inline bool PointsEqual( const IntPoint &pt1, const IntPoint &pt2)
-{
- return ( pt1.X == pt2.X && pt1.Y == pt2.Y );
-}
-//------------------------------------------------------------------------------
-
-bool Orientation(OutRec *outRec, bool UseFullInt64Range)
-{
- //first make sure bottomPt is correctly assigned ...
- OutPt *opBottom = outRec->pts, *op = outRec->pts->next;
- while (op != outRec->pts)
- {
- if (op->pt.Y >= opBottom->pt.Y)
- {
- if (op->pt.Y > opBottom->pt.Y || op->pt.X < opBottom->pt.X)
- opBottom = op;
- }
- op = op->next;
- }
- outRec->bottomPt = opBottom;
- opBottom->idx = outRec->idx;
-
- op = opBottom;
- //find vertices either side of bottomPt (skipping duplicate points) ....
- OutPt *opPrev = op->prev;
- OutPt *opNext = op->next;
- while (op != opPrev && PointsEqual(op->pt, opPrev->pt))
- opPrev = opPrev->prev;
- while (op != opNext && PointsEqual(op->pt, opNext->pt))
- opNext = opNext->next;
-
- IntPoint ip1, ip2;
- ip1.X = op->pt.X - opPrev->pt.X;
- ip1.Y = op->pt.Y - opPrev->pt.Y;
- ip2.X = opNext->pt.X - op->pt.X;
- ip2.Y = opNext->pt.Y - op->pt.Y;
-
- if (UseFullInt64Range)
- return Int128(ip1.X) * Int128(ip2.Y) - Int128(ip2.X) * Int128(ip1.Y) >= 0;
- else
- return (ip1.X * ip2.Y - ip2.X * ip1.Y) >= 0;
-}
-//------------------------------------------------------------------------------
-
-double Area(const Polygon &poly)
-{
- int highI = (int)poly.size() -1;
- if (highI < 2) return 0;
-
- if (FullRangeNeeded(poly)) {
- Int128 a;
- a = (Int128(poly[highI].X) * Int128(poly[0].Y)) -
- Int128(poly[0].X) * Int128(poly[highI].Y);
- for (int i = 0; i < highI; ++i)
- a += Int128(poly[i].X) * Int128(poly[i+1].Y) -
- Int128(poly[i+1].X) * Int128(poly[i].Y);
- return a.AsDouble() / 2;
- }
- else
- {
- double a;
- a = (double)poly[highI].X * poly[0].Y - (double)poly[0].X * poly[highI].Y;
- for (int i = 0; i < highI; ++i)
- a += (double)poly[i].X * poly[i+1].Y - (double)poly[i+1].X * poly[i].Y;
- return a/2;
- }
-}
-//------------------------------------------------------------------------------
-
-double Area(const OutRec &outRec, bool UseFullInt64Range)
-{
- OutPt *op = outRec.pts;
- if (UseFullInt64Range) {
- Int128 a(0);
- do {
- a += (Int128(op->prev->pt.X) * Int128(op->pt.Y)) -
- Int128(op->pt.X) * Int128(op->prev->pt.Y);
- op = op->next;
- } while (op != outRec.pts);
- return a.AsDouble() / 2;
- }
- else
- {
- double a = 0;
- do {
- a += (op->prev->pt.X * op->pt.Y) - (op->pt.X * op->prev->pt.Y);
- op = op->next;
- } while (op != outRec.pts);
- return a/2;
- }
-}
-//------------------------------------------------------------------------------
-
-bool PointIsVertex(const IntPoint &pt, OutPt *pp)
-{
- OutPt *pp2 = pp;
- do
- {
- if (PointsEqual(pp2->pt, pt)) return true;
- pp2 = pp2->next;
- }
- while (pp2 != pp);
- return false;
-}
-//------------------------------------------------------------------------------
-
-bool PointInPolygon(const IntPoint &pt, OutPt *pp, bool UseFullInt64Range)
-{
- OutPt *pp2 = pp;
- bool result = false;
- if (UseFullInt64Range) {
- do
- {
- if ((((pp2->pt.Y <= pt.Y) && (pt.Y < pp2->prev->pt.Y)) ||
- ((pp2->prev->pt.Y <= pt.Y) && (pt.Y < pp2->pt.Y))) &&
- Int128(pt.X - pp2->pt.X) < (Int128(pp2->prev->pt.X - pp2->pt.X) *
- Int128(pt.Y - pp2->pt.Y)) / Int128(pp2->prev->pt.Y - pp2->pt.Y))
- result = !result;
- pp2 = pp2->next;
- }
- while (pp2 != pp);
- }
- else
- {
- do
- {
- if ((((pp2->pt.Y <= pt.Y) && (pt.Y < pp2->prev->pt.Y)) ||
- ((pp2->prev->pt.Y <= pt.Y) && (pt.Y < pp2->pt.Y))) &&
- (pt.X < (pp2->prev->pt.X - pp2->pt.X) * (pt.Y - pp2->pt.Y) /
- (pp2->prev->pt.Y - pp2->pt.Y) + pp2->pt.X )) result = !result;
- pp2 = pp2->next;
- }
- while (pp2 != pp);
- }
- return result;
-}
-//------------------------------------------------------------------------------
-
-bool SlopesEqual(TEdge &e1, TEdge &e2, bool UseFullInt64Range)
-{
- if (UseFullInt64Range)
- return Int128(e1.ytop - e1.ybot) * Int128(e2.xtop - e2.xbot) ==
- Int128(e1.xtop - e1.xbot) * Int128(e2.ytop - e2.ybot);
- else return (e1.ytop - e1.ybot)*(e2.xtop - e2.xbot) ==
- (e1.xtop - e1.xbot)*(e2.ytop - e2.ybot);
-}
-//------------------------------------------------------------------------------
-
-bool SlopesEqual(const IntPoint pt1, const IntPoint pt2,
- const IntPoint pt3, bool UseFullInt64Range)
-{
- if (UseFullInt64Range)
- return Int128(pt1.Y-pt2.Y) * Int128(pt2.X-pt3.X) ==
- Int128(pt1.X-pt2.X) * Int128(pt2.Y-pt3.Y);
- else return (pt1.Y-pt2.Y)*(pt2.X-pt3.X) == (pt1.X-pt2.X)*(pt2.Y-pt3.Y);
-}
-//------------------------------------------------------------------------------
-
-bool SlopesEqual(const IntPoint pt1, const IntPoint pt2,
- const IntPoint pt3, const IntPoint pt4, bool UseFullInt64Range)
-{
- if (UseFullInt64Range)
- return Int128(pt1.Y-pt2.Y) * Int128(pt3.X-pt4.X) ==
- Int128(pt1.X-pt2.X) * Int128(pt3.Y-pt4.Y);
- else return (pt1.Y-pt2.Y)*(pt3.X-pt4.X) == (pt1.X-pt2.X)*(pt3.Y-pt4.Y);
-}
-//------------------------------------------------------------------------------
-
-double GetDx(const IntPoint pt1, const IntPoint pt2)
-{
- return (pt1.Y == pt2.Y) ?
- HORIZONTAL : (double)(pt2.X - pt1.X) / (double)(pt2.Y - pt1.Y);
-}
-//---------------------------------------------------------------------------
-
-void SetDx(TEdge &e)
-{
- if (e.ybot == e.ytop) e.dx = HORIZONTAL;
- else e.dx = (double)(e.xtop - e.xbot) / (double)(e.ytop - e.ybot);
-}
-//---------------------------------------------------------------------------
-
-void SwapSides(TEdge &edge1, TEdge &edge2)
-{
- EdgeSide side = edge1.side;
- edge1.side = edge2.side;
- edge2.side = side;
-}
-//------------------------------------------------------------------------------
-
-void SwapPolyIndexes(TEdge &edge1, TEdge &edge2)
-{
- int outIdx = edge1.outIdx;
- edge1.outIdx = edge2.outIdx;
- edge2.outIdx = outIdx;
-}
-//------------------------------------------------------------------------------
-
-inline long64 Round(double val)
-{
- return (val < 0) ?
- static_cast<long64>(val - 0.5) : static_cast<long64>(val + 0.5);
-}
-//------------------------------------------------------------------------------
-
-long64 TopX(TEdge &edge, const long64 currentY)
-{
- return ( currentY == edge.ytop ) ?
- edge.xtop : edge.xbot + Round(edge.dx *(currentY - edge.ybot));
-}
-//------------------------------------------------------------------------------
-
-long64 TopX(const IntPoint pt1, const IntPoint pt2, const long64 currentY)
-{
- //preconditions: pt1.Y <> pt2.Y and pt1.Y > pt2.Y
- if (currentY >= pt1.Y) return pt1.X;
- else if (currentY == pt2.Y) return pt2.X;
- else if (pt1.X == pt2.X) return pt1.X;
- else
- {
- double q = (double)(pt1.X-pt2.X)/(double)(pt1.Y-pt2.Y);
- return Round(pt1.X + (currentY - pt1.Y) *q);
- }
-}
-//------------------------------------------------------------------------------
-
-bool IntersectPoint(TEdge &edge1, TEdge &edge2,
- IntPoint &ip, bool UseFullInt64Range)
-{
- double b1, b2;
- if (SlopesEqual(edge1, edge2, UseFullInt64Range)) return false;
- else if (NEAR_ZERO(edge1.dx))
- {
- ip.X = edge1.xbot;
- if (NEAR_EQUAL(edge2.dx, HORIZONTAL))
- {
- ip.Y = edge2.ybot;
- } else
- {
- b2 = edge2.ybot - (edge2.xbot/edge2.dx);
- ip.Y = Round(ip.X/edge2.dx + b2);
- }
- }
- else if (NEAR_ZERO(edge2.dx))
- {
- ip.X = edge2.xbot;
- if (NEAR_EQUAL(edge1.dx, HORIZONTAL))
- {
- ip.Y = edge1.ybot;
- } else
- {
- b1 = edge1.ybot - (edge1.xbot/edge1.dx);
- ip.Y = Round(ip.X/edge1.dx + b1);
- }
- } else
- {
- b1 = edge1.xbot - edge1.ybot * edge1.dx;
- b2 = edge2.xbot - edge2.ybot * edge2.dx;
- b2 = (b2-b1)/(edge1.dx - edge2.dx);
- ip.Y = Round(b2);
- ip.X = Round(edge1.dx * b2 + b1);
- }
-
- return
- //can be *so close* to the top of one edge that the rounded Y equals one ytop ...
- (ip.Y == edge1.ytop && ip.Y >= edge2.ytop && edge1.tmpX > edge2.tmpX) ||
- (ip.Y == edge2.ytop && ip.Y >= edge1.ytop && edge1.tmpX > edge2.tmpX) ||
- (ip.Y > edge1.ytop && ip.Y > edge2.ytop);
-}
-//------------------------------------------------------------------------------
-
-void ReversePolyPtLinks(OutPt &pp)
-{
- OutPt *pp1, *pp2;
- pp1 = &pp;
- do {
- pp2 = pp1->next;
- pp1->next = pp1->prev;
- pp1->prev = pp2;
- pp1 = pp2;
- } while( pp1 != &pp );
-}
-//------------------------------------------------------------------------------
-
-void DisposeOutPts(OutPt*& pp)
-{
- if (pp == 0) return;
- pp->prev->next = 0;
- while( pp )
- {
- OutPt *tmpPp = pp;
- pp = pp->next;
- delete tmpPp ;
- }
-}
-//------------------------------------------------------------------------------
-
-void InitEdge(TEdge *e, TEdge *eNext,
- TEdge *ePrev, const IntPoint &pt, PolyType polyType)
-{
- std::memset( e, 0, sizeof( TEdge ));
-
- e->next = eNext;
- e->prev = ePrev;
- e->xcurr = pt.X;
- e->ycurr = pt.Y;
- if (e->ycurr >= e->next->ycurr)
- {
- e->xbot = e->xcurr;
- e->ybot = e->ycurr;
- e->xtop = e->next->xcurr;
- e->ytop = e->next->ycurr;
- e->windDelta = 1;
- } else
- {
- e->xtop = e->xcurr;
- e->ytop = e->ycurr;
- e->xbot = e->next->xcurr;
- e->ybot = e->next->ycurr;
- e->windDelta = -1;
- }
- SetDx(*e);
- e->polyType = polyType;
- e->outIdx = -1;
-}
-//------------------------------------------------------------------------------
-
-inline void SwapX(TEdge &e)
-{
- //swap horizontal edges' top and bottom x's so they follow the natural
- //progression of the bounds - ie so their xbots will align with the
- //adjoining lower edge. [Helpful in the ProcessHorizontal() method.]
- e.xcurr = e.xtop;
- e.xtop = e.xbot;
- e.xbot = e.xcurr;
-}
-//------------------------------------------------------------------------------
-
-void SwapPoints(IntPoint &pt1, IntPoint &pt2)
-{
- IntPoint tmp = pt1;
- pt1 = pt2;
- pt2 = tmp;
-}
-//------------------------------------------------------------------------------
-
-bool GetOverlapSegment(IntPoint pt1a, IntPoint pt1b, IntPoint pt2a,
- IntPoint pt2b, IntPoint &pt1, IntPoint &pt2)
-{
- //precondition: segments are colinear.
- if ( pt1a.Y == pt1b.Y || Abs((pt1a.X - pt1b.X)/(pt1a.Y - pt1b.Y)) > 1 )
- {
- if (pt1a.X > pt1b.X) SwapPoints(pt1a, pt1b);
- if (pt2a.X > pt2b.X) SwapPoints(pt2a, pt2b);
- if (pt1a.X > pt2a.X) pt1 = pt1a; else pt1 = pt2a;
- if (pt1b.X < pt2b.X) pt2 = pt1b; else pt2 = pt2b;
- return pt1.X < pt2.X;
- } else
- {
- if (pt1a.Y < pt1b.Y) SwapPoints(pt1a, pt1b);
- if (pt2a.Y < pt2b.Y) SwapPoints(pt2a, pt2b);
- if (pt1a.Y < pt2a.Y) pt1 = pt1a; else pt1 = pt2a;
- if (pt1b.Y > pt2b.Y) pt2 = pt1b; else pt2 = pt2b;
- return pt1.Y > pt2.Y;
- }
-}
-//------------------------------------------------------------------------------
-
-bool FirstIsBottomPt(const OutPt* btmPt1, const OutPt* btmPt2)
-{
- OutPt *p = btmPt1->prev;
- while (PointsEqual(p->pt, btmPt1->pt) && (p != btmPt1)) p = p->prev;
- double dx1p = std::fabs(GetDx(btmPt1->pt, p->pt));
- p = btmPt1->next;
- while (PointsEqual(p->pt, btmPt1->pt) && (p != btmPt1)) p = p->next;
- double dx1n = std::fabs(GetDx(btmPt1->pt, p->pt));
-
- p = btmPt2->prev;
- while (PointsEqual(p->pt, btmPt2->pt) && (p != btmPt2)) p = p->prev;
- double dx2p = std::fabs(GetDx(btmPt2->pt, p->pt));
- p = btmPt2->next;
- while (PointsEqual(p->pt, btmPt2->pt) && (p != btmPt2)) p = p->next;
- double dx2n = std::fabs(GetDx(btmPt2->pt, p->pt));
- return (dx1p >= dx2p && dx1p >= dx2n) || (dx1n >= dx2p && dx1n >= dx2n);
-}
-//------------------------------------------------------------------------------
-
-OutPt* GetBottomPt(OutPt *pp)
-{
- OutPt* dups = 0;
- OutPt* p = pp->next;
- while (p != pp)
- {
- if (p->pt.Y > pp->pt.Y)
- {
- pp = p;
- dups = 0;
- }
- else if (p->pt.Y == pp->pt.Y && p->pt.X <= pp->pt.X)
- {
- if (p->pt.X < pp->pt.X)
- {
- dups = 0;
- pp = p;
- } else
- {
- if (p->next != pp && p->prev != pp) dups = p;
- }
- }
- p = p->next;
- }
- if (dups)
- {
- //there appears to be at least 2 vertices at bottomPt so ...
- while (dups != p)
- {
- if (!FirstIsBottomPt(p, dups)) pp = dups;
- dups = dups->next;
- while (!PointsEqual(dups->pt, pp->pt)) dups = dups->next;
- }
- }
- return pp;
-}
-//------------------------------------------------------------------------------
-
-bool FindSegment(OutPt* &pp, IntPoint &pt1, IntPoint &pt2)
-{
- //outPt1 & outPt2 => the overlap segment (if the function returns true)
- if (!pp) return false;
- OutPt* pp2 = pp;
- IntPoint pt1a = pt1, pt2a = pt2;
- do
- {
- if (SlopesEqual(pt1a, pt2a, pp->pt, pp->prev->pt, true) &&
- SlopesEqual(pt1a, pt2a, pp->pt, true) &&
- GetOverlapSegment(pt1a, pt2a, pp->pt, pp->prev->pt, pt1, pt2))
- return true;
- pp = pp->next;
- }
- while (pp != pp2);
- return false;
-}
-//------------------------------------------------------------------------------
-
-bool Pt3IsBetweenPt1AndPt2(const IntPoint pt1,
- const IntPoint pt2, const IntPoint pt3)
-{
- if (PointsEqual(pt1, pt3) || PointsEqual(pt2, pt3)) return true;
- else if (pt1.X != pt2.X) return (pt1.X < pt3.X) == (pt3.X < pt2.X);
- else return (pt1.Y < pt3.Y) == (pt3.Y < pt2.Y);
-}
-//------------------------------------------------------------------------------
-
-OutPt* InsertPolyPtBetween(OutPt* p1, OutPt* p2, const IntPoint pt)
-{
- if (p1 == p2) throw "JoinError";
- OutPt* result = new OutPt;
- result->pt = pt;
- if (p2 == p1->next)
- {
- p1->next = result;
- p2->prev = result;
- result->next = p2;
- result->prev = p1;
- } else
- {
- p2->next = result;
- p1->prev = result;
- result->next = p1;
- result->prev = p2;
- }
- return result;
-}
-
-//------------------------------------------------------------------------------
-// ClipperBase class methods ...
-//------------------------------------------------------------------------------
-
-ClipperBase::ClipperBase() //constructor
-{
- m_MinimaList = 0;
- m_CurrentLM = 0;
- m_UseFullRange = true;
-}
-//------------------------------------------------------------------------------
-
-ClipperBase::~ClipperBase() //destructor
-{
- Clear();
-}
-//------------------------------------------------------------------------------
-
-bool ClipperBase::AddPolygon( const Polygon &pg, PolyType polyType)
-{
- int len = (int)pg.size();
- if (len < 3) return false;
- Polygon p(len);
- p[0] = pg[0];
- int j = 0;
-
- long64 maxVal;
- if (m_UseFullRange) maxVal = hiRange; else maxVal = loRange;
-
- for (int i = 0; i < len; ++i)
- {
- if (Abs(pg[i].X) > maxVal || Abs(pg[i].Y) > maxVal)
- {
- if (Abs(pg[i].X) > hiRange || Abs(pg[i].Y) > hiRange)
- throw "Coordinate exceeds range bounds";
- maxVal = hiRange;
- m_UseFullRange = true;
- }
-
- if (i == 0 || PointsEqual(p[j], pg[i])) continue;
- else if (j > 0 && SlopesEqual(p[j-1], p[j], pg[i], m_UseFullRange))
- {
- if (PointsEqual(p[j-1], pg[i])) j--;
- } else j++;
- p[j] = pg[i];
- }
- if (j < 2) return false;
-
- len = j+1;
- while (len > 2)
- {
- //nb: test for point equality before testing slopes ...
- if (PointsEqual(p[j], p[0])) j--;
- else if (PointsEqual(p[0], p[1]) ||
- SlopesEqual(p[j], p[0], p[1], m_UseFullRange))
- p[0] = p[j--];
- else if (SlopesEqual(p[j-1], p[j], p[0], m_UseFullRange)) j--;
- else if (SlopesEqual(p[0], p[1], p[2], m_UseFullRange))
- {
- for (int i = 2; i <= j; ++i) p[i-1] = p[i];
- j--;
- }
- else break;
- len--;
- }
- if (len < 3) return false;
-
- //create a new edge array ...
- TEdge *edges = new TEdge [len];
- m_edges.push_back(edges);
-
- //convert vertices to a double-linked-list of edges and initialize ...
- edges[0].xcurr = p[0].X;
- edges[0].ycurr = p[0].Y;
- InitEdge(&edges[len-1], &edges[0], &edges[len-2], p[len-1], polyType);
- for (int i = len-2; i > 0; --i)
- InitEdge(&edges[i], &edges[i+1], &edges[i-1], p[i], polyType);
- InitEdge(&edges[0], &edges[1], &edges[len-1], p[0], polyType);
-
- //reset xcurr & ycurr and find 'eHighest' (given the Y axis coordinates
- //increase downward so the 'highest' edge will have the smallest ytop) ...
- TEdge *e = &edges[0];
- TEdge *eHighest = e;
- do
- {
- e->xcurr = e->xbot;
- e->ycurr = e->ybot;
- if (e->ytop < eHighest->ytop) eHighest = e;
- e = e->next;
- }
- while ( e != &edges[0]);
-
- //make sure eHighest is positioned so the following loop works safely ...
- if (eHighest->windDelta > 0) eHighest = eHighest->next;
- if (NEAR_EQUAL(eHighest->dx, HORIZONTAL)) eHighest = eHighest->next;
-
- //finally insert each local minima ...
- e = eHighest;
- do {
- e = AddBoundsToLML(e);
- }
- while( e != eHighest );
- return true;
-}
-//------------------------------------------------------------------------------
-
-void ClipperBase::InsertLocalMinima(LocalMinima *newLm)
-{
- if( ! m_MinimaList )
- {
- m_MinimaList = newLm;
- }
- else if( newLm->Y >= m_MinimaList->Y )
- {
- newLm->next = m_MinimaList;
- m_MinimaList = newLm;
- } else
- {
- LocalMinima* tmpLm = m_MinimaList;
- while( tmpLm->next && ( newLm->Y < tmpLm->next->Y ) )
- tmpLm = tmpLm->next;
- newLm->next = tmpLm->next;
- tmpLm->next = newLm;
- }
-}
-//------------------------------------------------------------------------------
-
-TEdge* ClipperBase::AddBoundsToLML(TEdge *e)
-{
- //Starting at the top of one bound we progress to the bottom where there's
- //a local minima. We then go to the top of the next bound. These two bounds
- //form the left and right (or right and left) bounds of the local minima.
- e->nextInLML = 0;
- e = e->next;
- for (;;)
- {
- if (NEAR_EQUAL(e->dx, HORIZONTAL))
- {
- //nb: proceed through horizontals when approaching from their right,
- // but break on horizontal minima if approaching from their left.
- // This ensures 'local minima' are always on the left of horizontals.
- if (e->next->ytop < e->ytop && e->next->xbot > e->prev->xbot) break;
- if (e->xtop != e->prev->xbot) SwapX(*e);
- e->nextInLML = e->prev;
- }
- else if (e->ycurr == e->prev->ycurr) break;
- else e->nextInLML = e->prev;
- e = e->next;
- }
-
- //e and e.prev are now at a local minima ...
- LocalMinima* newLm = new LocalMinima;
- newLm->next = 0;
- newLm->Y = e->prev->ybot;
-
- if ( NEAR_EQUAL(e->dx, HORIZONTAL) ) //horizontal edges never start a left bound
- {
- if (e->xbot != e->prev->xbot) SwapX(*e);
- newLm->leftBound = e->prev;
- newLm->rightBound = e;
- } else if (e->dx < e->prev->dx)
- {
- newLm->leftBound = e->prev;
- newLm->rightBound = e;
- } else
- {
- newLm->leftBound = e;
- newLm->rightBound = e->prev;
- }
- newLm->leftBound->side = esLeft;
- newLm->rightBound->side = esRight;
- InsertLocalMinima( newLm );
-
- for (;;)
- {
- if ( e->next->ytop == e->ytop && !NEAR_EQUAL(e->next->dx, HORIZONTAL) ) break;
- e->nextInLML = e->next;
- e = e->next;
- if ( NEAR_EQUAL(e->dx, HORIZONTAL) && e->xbot != e->prev->xtop) SwapX(*e);
- }
- return e->next;
-}
-//------------------------------------------------------------------------------
-
-bool ClipperBase::AddPolygons(const Polygons &ppg, PolyType polyType)
-{
- bool result = false;
- for (Polygons::size_type i = 0; i < ppg.size(); ++i)
- if (AddPolygon(ppg[i], polyType)) result = true;
- return result;
-}
-//------------------------------------------------------------------------------
-
-void ClipperBase::Clear()
-{
- DisposeLocalMinimaList();
- for (EdgeList::size_type i = 0; i < m_edges.size(); ++i) delete [] m_edges[i];
- m_edges.clear();
- m_UseFullRange = false;
-}
-//------------------------------------------------------------------------------
-
-void ClipperBase::Reset()
-{
- m_CurrentLM = m_MinimaList;
- if( !m_CurrentLM ) return; //ie nothing to process
-
- //reset all edges ...
- LocalMinima* lm = m_MinimaList;
- while( lm )
- {
- TEdge* e = lm->leftBound;
- while( e )
- {
- e->xcurr = e->xbot;
- e->ycurr = e->ybot;
- e->side = esLeft;
- e->outIdx = -1;
- e = e->nextInLML;
- }
- e = lm->rightBound;
- while( e )
- {
- e->xcurr = e->xbot;
- e->ycurr = e->ybot;
- e->side = esRight;
- e->outIdx = -1;
- e = e->nextInLML;
- }
- lm = lm->next;
- }
-}
-//------------------------------------------------------------------------------
-
-void ClipperBase::DisposeLocalMinimaList()
-{
- while( m_MinimaList )
- {
- LocalMinima* tmpLm = m_MinimaList->next;
- delete m_MinimaList;
- m_MinimaList = tmpLm;
- }
- m_CurrentLM = 0;
-}
-//------------------------------------------------------------------------------
-
-void ClipperBase::PopLocalMinima()
-{
- if( ! m_CurrentLM ) return;
- m_CurrentLM = m_CurrentLM->next;
-}
-//------------------------------------------------------------------------------
-
-IntRect ClipperBase::GetBounds()
-{
- IntRect result;
- LocalMinima* lm = m_MinimaList;
- if (!lm)
- {
- result.left = result.top = result.right = result.bottom = 0;
- return result;
- }
- result.left = lm->leftBound->xbot;
- result.top = lm->leftBound->ybot;
- result.right = lm->leftBound->xbot;
- result.bottom = lm->leftBound->ybot;
- while (lm)
- {
- if (lm->leftBound->ybot > result.bottom)
- result.bottom = lm->leftBound->ybot;
- TEdge* e = lm->leftBound;
- for (;;) {
- TEdge* bottomE = e;
- while (e->nextInLML)
- {
- if (e->xbot < result.left) result.left = e->xbot;
- if (e->xbot > result.right) result.right = e->xbot;
- e = e->nextInLML;
- }
- if (e->xbot < result.left) result.left = e->xbot;
- if (e->xbot > result.right) result.right = e->xbot;
- if (e->xtop < result.left) result.left = e->xtop;
- if (e->xtop > result.right) result.right = e->xtop;
- if (e->ytop < result.top) result.top = e->ytop;
-
- if (bottomE == lm->leftBound) e = lm->rightBound;
- else break;
- }
- lm = lm->next;
- }
- return result;
-}
-
-
-//------------------------------------------------------------------------------
-// TClipper methods ...
-//------------------------------------------------------------------------------
-
-Clipper::Clipper() : ClipperBase() //constructor
-{
- m_Scanbeam = 0;
- m_ActiveEdges = 0;
- m_SortedEdges = 0;
- m_IntersectNodes = 0;
- m_ExecuteLocked = false;
- m_UseFullRange = false;
- m_ReverseOutput = false;
-}
-//------------------------------------------------------------------------------
-
-Clipper::~Clipper() //destructor
-{
- Clear();
- DisposeScanbeamList();
-}
-//------------------------------------------------------------------------------
-
-void Clipper::Clear()
-{
- if (m_edges.size() == 0) return; //avoids problems with ClipperBase destructor
- DisposeAllPolyPts();
- ClipperBase::Clear();
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DisposeScanbeamList()
-{
- while ( m_Scanbeam ) {
- Scanbeam* sb2 = m_Scanbeam->next;
- delete m_Scanbeam;
- m_Scanbeam = sb2;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::Reset()
-{
- ClipperBase::Reset();
- m_Scanbeam = 0;
- m_ActiveEdges = 0;
- m_SortedEdges = 0;
- DisposeAllPolyPts();
- LocalMinima* lm = m_MinimaList;
- while (lm)
- {
- InsertScanbeam(lm->Y);
- InsertScanbeam(lm->leftBound->ytop);
- lm = lm->next;
- }
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::Execute(ClipType clipType, Polygons &solution,
- PolyFillType subjFillType, PolyFillType clipFillType)
-{
- if( m_ExecuteLocked ) return false;
- m_ExecuteLocked = true;
- solution.resize(0);
- m_SubjFillType = subjFillType;
- m_ClipFillType = clipFillType;
- m_ClipType = clipType;
- bool succeeded = ExecuteInternal(false);
- if (succeeded) BuildResult(solution);
- m_ExecuteLocked = false;
- return succeeded;
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::Execute(ClipType clipType, ExPolygons &solution,
- PolyFillType subjFillType, PolyFillType clipFillType)
-{
- if( m_ExecuteLocked ) return false;
- m_ExecuteLocked = true;
- solution.resize(0);
- m_SubjFillType = subjFillType;
- m_ClipFillType = clipFillType;
- m_ClipType = clipType;
- bool succeeded = ExecuteInternal(true);
- if (succeeded) BuildResultEx(solution);
- m_ExecuteLocked = false;
- return succeeded;
-}
-//------------------------------------------------------------------------------
-
-bool PolySort(OutRec *or1, OutRec *or2)
-{
- if (or1 == or2) return false;
- if (!or1->pts || !or2->pts)
- {
- if (or1->pts != or2->pts)
- {
- return or1->pts ? true : false;
- }
- else return false;
- }
- int i1, i2;
- if (or1->isHole)
- i1 = or1->FirstLeft->idx; else
- i1 = or1->idx;
- if (or2->isHole)
- i2 = or2->FirstLeft->idx; else
- i2 = or2->idx;
- int result = i1 - i2;
- if (result == 0 && (or1->isHole != or2->isHole))
- {
- return or1->isHole ? false : true;
- }
- else return result < 0;
-}
-//------------------------------------------------------------------------------
-
-OutRec* FindAppendLinkEnd(OutRec *outRec)
-{
- while (outRec->AppendLink) outRec = outRec->AppendLink;
- return outRec;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::FixHoleLinkage(OutRec *outRec)
-{
- OutRec *tmp;
- if (outRec->bottomPt)
- tmp = m_PolyOuts[outRec->bottomPt->idx]->FirstLeft;
- else
- tmp = outRec->FirstLeft;
- if (outRec == tmp) throw clipperException("HoleLinkage error");
-
- if (tmp)
- {
- if (tmp->AppendLink) tmp = FindAppendLinkEnd(tmp);
- if (tmp == outRec) tmp = 0;
- else if (tmp->isHole)
- {
- FixHoleLinkage(tmp);
- tmp = tmp->FirstLeft;
- }
- }
- outRec->FirstLeft = tmp;
- if (!tmp) outRec->isHole = false;
- outRec->AppendLink = 0;
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::ExecuteInternal(bool fixHoleLinkages)
-{
- bool succeeded;
- try {
- Reset();
- if (!m_CurrentLM ) return true;
- long64 botY = PopScanbeam();
- do {
- InsertLocalMinimaIntoAEL(botY);
- ClearHorzJoins();
- ProcessHorizontals();
- long64 topY = PopScanbeam();
- succeeded = ProcessIntersections(botY, topY);
- if (!succeeded) break;
- ProcessEdgesAtTopOfScanbeam(topY);
- botY = topY;
- } while( m_Scanbeam );
- }
- catch(...) {
- succeeded = false;
- }
-
- if (succeeded)
- {
- //tidy up output polygons and fix orientations where necessary ...
- for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i)
- {
- OutRec *outRec = m_PolyOuts[i];
- if (!outRec->pts) continue;
- FixupOutPolygon(*outRec);
- if (!outRec->pts) continue;
- if (outRec->isHole && fixHoleLinkages) FixHoleLinkage(outRec);
-
- if (outRec->bottomPt == outRec->bottomFlag &&
- (Orientation(outRec, m_UseFullRange) != (Area(*outRec, m_UseFullRange) > 0)))
- DisposeBottomPt(*outRec);
-
- if (outRec->isHole ==
- (m_ReverseOutput ^ Orientation(outRec, m_UseFullRange)))
- ReversePolyPtLinks(*outRec->pts);
- }
-
- JoinCommonEdges(fixHoleLinkages);
- if (fixHoleLinkages)
- std::sort(m_PolyOuts.begin(), m_PolyOuts.end(), PolySort);
- }
-
- ClearJoins();
- ClearHorzJoins();
- return succeeded;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::InsertScanbeam(const long64 Y)
-{
- if( !m_Scanbeam )
- {
- m_Scanbeam = new Scanbeam;
- m_Scanbeam->next = 0;
- m_Scanbeam->Y = Y;
- }
- else if( Y > m_Scanbeam->Y )
- {
- Scanbeam* newSb = new Scanbeam;
- newSb->Y = Y;
- newSb->next = m_Scanbeam;
- m_Scanbeam = newSb;
- } else
- {
- Scanbeam* sb2 = m_Scanbeam;
- while( sb2->next && ( Y <= sb2->next->Y ) ) sb2 = sb2->next;
- if( Y == sb2->Y ) return; //ie ignores duplicates
- Scanbeam* newSb = new Scanbeam;
- newSb->Y = Y;
- newSb->next = sb2->next;
- sb2->next = newSb;
- }
-}
-//------------------------------------------------------------------------------
-
-long64 Clipper::PopScanbeam()
-{
- long64 Y = m_Scanbeam->Y;
- Scanbeam* sb2 = m_Scanbeam;
- m_Scanbeam = m_Scanbeam->next;
- delete sb2;
- return Y;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DisposeAllPolyPts(){
- for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i)
- DisposeOutRec(i);
- m_PolyOuts.clear();
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DisposeOutRec(PolyOutList::size_type index)
-{
- OutRec *outRec = m_PolyOuts[index];
- if (outRec->pts) DisposeOutPts(outRec->pts);
- delete outRec;
- m_PolyOuts[index] = 0;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::SetWindingCount(TEdge &edge)
-{
- TEdge *e = edge.prevInAEL;
- //find the edge of the same polytype that immediately preceeds 'edge' in AEL
- while ( e && e->polyType != edge.polyType ) e = e->prevInAEL;
- if ( !e )
- {
- edge.windCnt = edge.windDelta;
- edge.windCnt2 = 0;
- e = m_ActiveEdges; //ie get ready to calc windCnt2
- } else if ( IsEvenOddFillType(edge) )
- {
- //EvenOdd filling ...
- edge.windCnt = 1;
- edge.windCnt2 = e->windCnt2;
- e = e->nextInAEL; //ie get ready to calc windCnt2
- } else
- {
- //nonZero, Positive or Negative filling ...
- if ( e->windCnt * e->windDelta < 0 )
- {
- if (Abs(e->windCnt) > 1)
- {
- if (e->windDelta * edge.windDelta < 0) edge.windCnt = e->windCnt;
- else edge.windCnt = e->windCnt + edge.windDelta;
- } else
- edge.windCnt = e->windCnt + e->windDelta + edge.windDelta;
- } else
- {
- if ( Abs(e->windCnt) > 1 && e->windDelta * edge.windDelta < 0)
- edge.windCnt = e->windCnt;
- else if ( e->windCnt + edge.windDelta == 0 )
- edge.windCnt = e->windCnt;
- else edge.windCnt = e->windCnt + edge.windDelta;
- }
- edge.windCnt2 = e->windCnt2;
- e = e->nextInAEL; //ie get ready to calc windCnt2
- }
-
- //update windCnt2 ...
- if ( IsEvenOddAltFillType(edge) )
- {
- //EvenOdd filling ...
- while ( e != &edge )
- {
- edge.windCnt2 = (edge.windCnt2 == 0) ? 1 : 0;
- e = e->nextInAEL;
- }
- } else
- {
- //nonZero, Positive or Negative filling ...
- while ( e != &edge )
- {
- edge.windCnt2 += e->windDelta;
- e = e->nextInAEL;
- }
- }
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::IsEvenOddFillType(const TEdge& edge) const
-{
- if (edge.polyType == ptSubject)
- return m_SubjFillType == pftEvenOdd; else
- return m_ClipFillType == pftEvenOdd;
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::IsEvenOddAltFillType(const TEdge& edge) const
-{
- if (edge.polyType == ptSubject)
- return m_ClipFillType == pftEvenOdd; else
- return m_SubjFillType == pftEvenOdd;
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::IsContributing(const TEdge& edge) const
-{
- PolyFillType pft, pft2;
- if (edge.polyType == ptSubject)
- {
- pft = m_SubjFillType;
- pft2 = m_ClipFillType;
- } else
- {
- pft = m_ClipFillType;
- pft2 = m_SubjFillType;
- }
-
- switch(pft)
- {
- case pftEvenOdd:
- case pftNonZero:
- if (Abs(edge.windCnt) != 1) return false;
- break;
- case pftPositive:
- if (edge.windCnt != 1) return false;
- break;
- default: //pftNegative
- if (edge.windCnt != -1) return false;
- }
-
- switch(m_ClipType)
- {
- case ctIntersection:
- switch(pft2)
- {
- case pftEvenOdd:
- case pftNonZero:
- return (edge.windCnt2 != 0);
- case pftPositive:
- return (edge.windCnt2 > 0);
- default:
- return (edge.windCnt2 < 0);
- }
- case ctUnion:
- switch(pft2)
- {
- case pftEvenOdd:
- case pftNonZero:
- return (edge.windCnt2 == 0);
- case pftPositive:
- return (edge.windCnt2 <= 0);
- default:
- return (edge.windCnt2 >= 0);
- }
- case ctDifference:
- if (edge.polyType == ptSubject)
- switch(pft2)
- {
- case pftEvenOdd:
- case pftNonZero:
- return (edge.windCnt2 == 0);
- case pftPositive:
- return (edge.windCnt2 <= 0);
- default:
- return (edge.windCnt2 >= 0);
- }
- else
- switch(pft2)
- {
- case pftEvenOdd:
- case pftNonZero:
- return (edge.windCnt2 != 0);
- case pftPositive:
- return (edge.windCnt2 > 0);
- default:
- return (edge.windCnt2 < 0);
- }
- default:
- return true;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt)
-{
- TEdge *e, *prevE;
- if( NEAR_EQUAL(e2->dx, HORIZONTAL) || ( e1->dx > e2->dx ) )
- {
- AddOutPt( e1, pt );
- e2->outIdx = e1->outIdx;
- e1->side = esLeft;
- e2->side = esRight;
- e = e1;
- if (e->prevInAEL == e2)
- prevE = e2->prevInAEL;
- else
- prevE = e->prevInAEL;
- } else
- {
- AddOutPt( e2, pt );
- e1->outIdx = e2->outIdx;
- e1->side = esRight;
- e2->side = esLeft;
- e = e2;
- if (e->prevInAEL == e1)
- prevE = e1->prevInAEL;
- else
- prevE = e->prevInAEL;
- }
- if (prevE && prevE->outIdx >= 0 &&
- (TopX(*prevE, pt.Y) == TopX(*e, pt.Y)) &&
- SlopesEqual(*e, *prevE, m_UseFullRange))
- AddJoin(e, prevE, -1, -1);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt)
-{
- AddOutPt( e1, pt );
- if( e1->outIdx == e2->outIdx )
- {
- e1->outIdx = -1;
- e2->outIdx = -1;
- }
- else if (e1->outIdx < e2->outIdx)
- AppendPolygon(e1, e2);
- else
- AppendPolygon(e2, e1);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddEdgeToSEL(TEdge *edge)
-{
- //SEL pointers in PEdge are reused to build a list of horizontal edges.
- //However, we don't need to worry about order with horizontal edge processing.
- if( !m_SortedEdges )
- {
- m_SortedEdges = edge;
- edge->prevInSEL = 0;
- edge->nextInSEL = 0;
- }
- else
- {
- edge->nextInSEL = m_SortedEdges;
- edge->prevInSEL = 0;
- m_SortedEdges->prevInSEL = edge;
- m_SortedEdges = edge;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::CopyAELToSEL()
-{
- TEdge* e = m_ActiveEdges;
- m_SortedEdges = e;
- if (!m_ActiveEdges) return;
- m_SortedEdges->prevInSEL = 0;
- e = e->nextInAEL;
- while ( e )
- {
- e->prevInSEL = e->prevInAEL;
- e->prevInSEL->nextInSEL = e;
- e->nextInSEL = 0;
- e = e->nextInAEL;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddJoin(TEdge *e1, TEdge *e2, int e1OutIdx, int e2OutIdx)
-{
- JoinRec* jr = new JoinRec;
- if (e1OutIdx >= 0)
- jr->poly1Idx = e1OutIdx; else
- jr->poly1Idx = e1->outIdx;
- jr->pt1a = IntPoint(e1->xcurr, e1->ycurr);
- jr->pt1b = IntPoint(e1->xtop, e1->ytop);
- if (e2OutIdx >= 0)
- jr->poly2Idx = e2OutIdx; else
- jr->poly2Idx = e2->outIdx;
- jr->pt2a = IntPoint(e2->xcurr, e2->ycurr);
- jr->pt2b = IntPoint(e2->xtop, e2->ytop);
- m_Joins.push_back(jr);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ClearJoins()
-{
- for (JoinList::size_type i = 0; i < m_Joins.size(); i++)
- delete m_Joins[i];
- m_Joins.resize(0);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddHorzJoin(TEdge *e, int idx)
-{
- HorzJoinRec* hj = new HorzJoinRec;
- hj->edge = e;
- hj->savedIdx = idx;
- m_HorizJoins.push_back(hj);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ClearHorzJoins()
-{
- for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); i++)
- delete m_HorizJoins[i];
- m_HorizJoins.resize(0);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::InsertLocalMinimaIntoAEL( const long64 botY)
-{
- while( m_CurrentLM && ( m_CurrentLM->Y == botY ) )
- {
- TEdge* lb = m_CurrentLM->leftBound;
- TEdge* rb = m_CurrentLM->rightBound;
-
- InsertEdgeIntoAEL( lb );
- InsertScanbeam( lb->ytop );
- InsertEdgeIntoAEL( rb );
-
- if (IsEvenOddFillType(*lb))
- {
- lb->windDelta = 1;
- rb->windDelta = 1;
- }
- else
- {
- rb->windDelta = -lb->windDelta;
- }
- SetWindingCount( *lb );
- rb->windCnt = lb->windCnt;
- rb->windCnt2 = lb->windCnt2;
-
- if( NEAR_EQUAL(rb->dx, HORIZONTAL) )
- {
- //nb: only rightbounds can have a horizontal bottom edge
- AddEdgeToSEL( rb );
- InsertScanbeam( rb->nextInLML->ytop );
- }
- else
- InsertScanbeam( rb->ytop );
-
- if( IsContributing(*lb) )
- AddLocalMinPoly( lb, rb, IntPoint(lb->xcurr, m_CurrentLM->Y) );
-
- //if any output polygons share an edge, they'll need joining later ...
- if (rb->outIdx >= 0)
- {
- if (NEAR_EQUAL(rb->dx, HORIZONTAL))
- {
- for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); ++i)
- {
- IntPoint pt, pt2; //returned by GetOverlapSegment() but unused here.
- HorzJoinRec* hj = m_HorizJoins[i];
- //if horizontals rb and hj.edge overlap, flag for joining later ...
- if (GetOverlapSegment(IntPoint(hj->edge->xbot, hj->edge->ybot),
- IntPoint(hj->edge->xtop, hj->edge->ytop),
- IntPoint(rb->xbot, rb->ybot),
- IntPoint(rb->xtop, rb->ytop), pt, pt2))
- AddJoin(hj->edge, rb, hj->savedIdx);
- }
- }
- }
-
- if( lb->nextInAEL != rb )
- {
- if (rb->outIdx >= 0 && rb->prevInAEL->outIdx >= 0 &&
- SlopesEqual(*rb->prevInAEL, *rb, m_UseFullRange))
- AddJoin(rb, rb->prevInAEL);
-
- TEdge* e = lb->nextInAEL;
- IntPoint pt = IntPoint(lb->xcurr, lb->ycurr);
- while( e != rb )
- {
- if(!e) throw clipperException("InsertLocalMinimaIntoAEL: missing rightbound!");
- //nb: For calculating winding counts etc, IntersectEdges() assumes
- //that param1 will be to the right of param2 ABOVE the intersection ...
- IntersectEdges( rb , e , pt , ipNone); //order important here
- e = e->nextInAEL;
- }
- }
- PopLocalMinima();
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DeleteFromAEL(TEdge *e)
-{
- TEdge* AelPrev = e->prevInAEL;
- TEdge* AelNext = e->nextInAEL;
- if( !AelPrev && !AelNext && (e != m_ActiveEdges) ) return; //already deleted
- if( AelPrev ) AelPrev->nextInAEL = AelNext;
- else m_ActiveEdges = AelNext;
- if( AelNext ) AelNext->prevInAEL = AelPrev;
- e->nextInAEL = 0;
- e->prevInAEL = 0;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DeleteFromSEL(TEdge *e)
-{
- TEdge* SelPrev = e->prevInSEL;
- TEdge* SelNext = e->nextInSEL;
- if( !SelPrev && !SelNext && (e != m_SortedEdges) ) return; //already deleted
- if( SelPrev ) SelPrev->nextInSEL = SelNext;
- else m_SortedEdges = SelNext;
- if( SelNext ) SelNext->prevInSEL = SelPrev;
- e->nextInSEL = 0;
- e->prevInSEL = 0;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::IntersectEdges(TEdge *e1, TEdge *e2,
- const IntPoint &pt, IntersectProtects protects)
-{
- //e1 will be to the left of e2 BELOW the intersection. Therefore e1 is before
- //e2 in AEL except when e1 is being inserted at the intersection point ...
- bool e1stops = !(ipLeft & protects) && !e1->nextInLML &&
- e1->xtop == pt.X && e1->ytop == pt.Y;
- bool e2stops = !(ipRight & protects) && !e2->nextInLML &&
- e2->xtop == pt.X && e2->ytop == pt.Y;
- bool e1Contributing = ( e1->outIdx >= 0 );
- bool e2contributing = ( e2->outIdx >= 0 );
-
- //update winding counts...
- //assumes that e1 will be to the right of e2 ABOVE the intersection
- if ( e1->polyType == e2->polyType )
- {
- if ( IsEvenOddFillType( *e1) )
- {
- int oldE1WindCnt = e1->windCnt;
- e1->windCnt = e2->windCnt;
- e2->windCnt = oldE1WindCnt;
- } else
- {
- if (e1->windCnt + e2->windDelta == 0 ) e1->windCnt = -e1->windCnt;
- else e1->windCnt += e2->windDelta;
- if ( e2->windCnt - e1->windDelta == 0 ) e2->windCnt = -e2->windCnt;
- else e2->windCnt -= e1->windDelta;
- }
- } else
- {
- if (!IsEvenOddFillType(*e2)) e1->windCnt2 += e2->windDelta;
- else e1->windCnt2 = ( e1->windCnt2 == 0 ) ? 1 : 0;
- if (!IsEvenOddFillType(*e1)) e2->windCnt2 -= e1->windDelta;
- else e2->windCnt2 = ( e2->windCnt2 == 0 ) ? 1 : 0;
- }
-
- PolyFillType e1FillType, e2FillType, e1FillType2, e2FillType2;
- if (e1->polyType == ptSubject)
- {
- e1FillType = m_SubjFillType;
- e1FillType2 = m_ClipFillType;
- } else
- {
- e1FillType = m_ClipFillType;
- e1FillType2 = m_SubjFillType;
- }
- if (e2->polyType == ptSubject)
- {
- e2FillType = m_SubjFillType;
- e2FillType2 = m_ClipFillType;
- } else
- {
- e2FillType = m_ClipFillType;
- e2FillType2 = m_SubjFillType;
- }
-
- long64 e1Wc, e2Wc;
- switch (e1FillType)
- {
- case pftPositive: e1Wc = e1->windCnt; break;
- case pftNegative: e1Wc = -e1->windCnt; break;
- default: e1Wc = Abs(e1->windCnt);
- }
- switch(e2FillType)
- {
- case pftPositive: e2Wc = e2->windCnt; break;
- case pftNegative: e2Wc = -e2->windCnt; break;
- default: e2Wc = Abs(e2->windCnt);
- }
-
- if ( e1Contributing && e2contributing )
- {
- if ( e1stops || e2stops ||
- (e1Wc != 0 && e1Wc != 1) || (e2Wc != 0 && e2Wc != 1) ||
- (e1->polyType != e2->polyType && m_ClipType != ctXor) )
- AddLocalMaxPoly(e1, e2, pt);
- else
- DoBothEdges( e1, e2, pt );
- }
- else if ( e1Contributing )
- {
- if ((e2Wc == 0 || e2Wc == 1) &&
- (m_ClipType != ctIntersection ||
- e2->polyType == ptSubject || (e2->windCnt2 != 0)))
- DoEdge1(e1, e2, pt);
- }
- else if ( e2contributing )
- {
- if ((e1Wc == 0 || e1Wc == 1) &&
- (m_ClipType != ctIntersection ||
- e1->polyType == ptSubject || (e1->windCnt2 != 0)))
- DoEdge2(e1, e2, pt);
- }
- else if ( (e1Wc == 0 || e1Wc == 1) &&
- (e2Wc == 0 || e2Wc == 1) && !e1stops && !e2stops )
- {
- //neither edge is currently contributing ...
-
- long64 e1Wc2, e2Wc2;
- switch (e1FillType2)
- {
- case pftPositive: e1Wc2 = e1->windCnt2; break;
- case pftNegative : e1Wc2 = -e1->windCnt2; break;
- default: e1Wc2 = Abs(e1->windCnt2);
- }
- switch (e2FillType2)
- {
- case pftPositive: e2Wc2 = e2->windCnt2; break;
- case pftNegative: e2Wc2 = -e2->windCnt2; break;
- default: e2Wc2 = Abs(e2->windCnt2);
- }
-
- if (e1->polyType != e2->polyType)
- AddLocalMinPoly(e1, e2, pt);
- else if (e1Wc == 1 && e2Wc == 1)
- switch( m_ClipType ) {
- case ctIntersection:
- if (e1Wc2 > 0 && e2Wc2 > 0)
- AddLocalMinPoly(e1, e2, pt);
- break;
- case ctUnion:
- if ( e1Wc2 <= 0 && e2Wc2 <= 0 )
- AddLocalMinPoly(e1, e2, pt);
- break;
- case ctDifference:
- if (((e1->polyType == ptClip) && (e1Wc2 > 0) && (e2Wc2 > 0)) ||
- ((e1->polyType == ptSubject) && (e1Wc2 <= 0) && (e2Wc2 <= 0)))
- AddLocalMinPoly(e1, e2, pt);
- break;
- case ctXor:
- AddLocalMinPoly(e1, e2, pt);
- }
- else
- SwapSides( *e1, *e2 );
- }
-
- if( (e1stops != e2stops) &&
- ( (e1stops && (e1->outIdx >= 0)) || (e2stops && (e2->outIdx >= 0)) ) )
- {
- SwapSides( *e1, *e2 );
- SwapPolyIndexes( *e1, *e2 );
- }
-
- //finally, delete any non-contributing maxima edges ...
- if( e1stops ) DeleteFromAEL( e1 );
- if( e2stops ) DeleteFromAEL( e2 );
-}
-//------------------------------------------------------------------------------
-
-void Clipper::SetHoleState(TEdge *e, OutRec *outRec)
-{
- bool isHole = false;
- TEdge *e2 = e->prevInAEL;
- while (e2)
- {
- if (e2->outIdx >= 0)
- {
- isHole = !isHole;
- if (! outRec->FirstLeft)
- outRec->FirstLeft = m_PolyOuts[e2->outIdx];
- }
- e2 = e2->prevInAEL;
- }
- if (isHole) outRec->isHole = true;
-}
-//------------------------------------------------------------------------------
-
-OutRec* GetLowermostRec(OutRec *outRec1, OutRec *outRec2)
-{
- //work out which polygon fragment has the correct hole state ...
- OutPt *outPt1 = outRec1->bottomPt;
- OutPt *outPt2 = outRec2->bottomPt;
- if (outPt1->pt.Y > outPt2->pt.Y) return outRec1;
- else if (outPt1->pt.Y < outPt2->pt.Y) return outRec2;
- else if (outPt1->pt.X < outPt2->pt.X) return outRec1;
- else if (outPt1->pt.X > outPt2->pt.X) return outRec2;
- else if (outPt1->next == outPt1) return outRec2;
- else if (outPt2->next == outPt2) return outRec1;
- else if (FirstIsBottomPt(outPt1, outPt2)) return outRec1;
- else return outRec2;
-}
-//------------------------------------------------------------------------------
-
-bool Param1RightOfParam2(OutRec* outRec1, OutRec* outRec2)
-{
- do
- {
- outRec1 = outRec1->FirstLeft;
- if (outRec1 == outRec2) return true;
- } while (outRec1);
- return false;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AppendPolygon(TEdge *e1, TEdge *e2)
-{
- //get the start and ends of both output polygons ...
- OutRec *outRec1 = m_PolyOuts[e1->outIdx];
- OutRec *outRec2 = m_PolyOuts[e2->outIdx];
-
- OutRec *holeStateRec;
- if (Param1RightOfParam2(outRec1, outRec2)) holeStateRec = outRec2;
- else if (Param1RightOfParam2(outRec2, outRec1)) holeStateRec = outRec1;
- else holeStateRec = GetLowermostRec(outRec1, outRec2);
-
- OutPt* p1_lft = outRec1->pts;
- OutPt* p1_rt = p1_lft->prev;
- OutPt* p2_lft = outRec2->pts;
- OutPt* p2_rt = p2_lft->prev;
-
- EdgeSide side;
- //join e2 poly onto e1 poly and delete pointers to e2 ...
- if( e1->side == esLeft )
- {
- if( e2->side == esLeft )
- {
- //z y x a b c
- ReversePolyPtLinks(*p2_lft);
- p2_lft->next = p1_lft;
- p1_lft->prev = p2_lft;
- p1_rt->next = p2_rt;
- p2_rt->prev = p1_rt;
- outRec1->pts = p2_rt;
- } else
- {
- //x y z a b c
- p2_rt->next = p1_lft;
- p1_lft->prev = p2_rt;
- p2_lft->prev = p1_rt;
- p1_rt->next = p2_lft;
- outRec1->pts = p2_lft;
- }
- side = esLeft;
- } else
- {
- if( e2->side == esRight )
- {
- //a b c z y x
- ReversePolyPtLinks( *p2_lft );
- p1_rt->next = p2_rt;
- p2_rt->prev = p1_rt;
- p2_lft->next = p1_lft;
- p1_lft->prev = p2_lft;
- } else
- {
- //a b c x y z
- p1_rt->next = p2_lft;
- p2_lft->prev = p1_rt;
- p1_lft->prev = p2_rt;
- p2_rt->next = p1_lft;
- }
- side = esRight;
- }
-
- if (holeStateRec == outRec2)
- {
- outRec1->bottomPt = outRec2->bottomPt;
- outRec1->bottomPt->idx = outRec1->idx;
- if (outRec2->FirstLeft != outRec1)
- outRec1->FirstLeft = outRec2->FirstLeft;
- outRec1->isHole = outRec2->isHole;
- }
- outRec2->pts = 0;
- outRec2->bottomPt = 0;
- outRec2->AppendLink = outRec1;
- int OKIdx = e1->outIdx;
- int ObsoleteIdx = e2->outIdx;
-
- e1->outIdx = -1; //nb: safe because we only get here via AddLocalMaxPoly
- e2->outIdx = -1;
-
- TEdge* e = m_ActiveEdges;
- while( e )
- {
- if( e->outIdx == ObsoleteIdx )
- {
- e->outIdx = OKIdx;
- e->side = side;
- break;
- }
- e = e->nextInAEL;
- }
-
- for (JoinList::size_type i = 0; i < m_Joins.size(); ++i)
- {
- if (m_Joins[i]->poly1Idx == ObsoleteIdx) m_Joins[i]->poly1Idx = OKIdx;
- if (m_Joins[i]->poly2Idx == ObsoleteIdx) m_Joins[i]->poly2Idx = OKIdx;
- }
-
- for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); ++i)
- {
- if (m_HorizJoins[i]->savedIdx == ObsoleteIdx)
- m_HorizJoins[i]->savedIdx = OKIdx;
- }
-
-}
-//------------------------------------------------------------------------------
-
-OutRec* Clipper::CreateOutRec()
-{
- OutRec* result = new OutRec;
- result->isHole = false;
- result->FirstLeft = 0;
- result->AppendLink = 0;
- result->pts = 0;
- result->bottomPt = 0;
- result->sides = esNeither;
- result->bottomFlag = 0;
-
- return result;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DisposeBottomPt(OutRec &outRec)
-{
- OutPt* next = outRec.bottomPt->next;
- OutPt* prev = outRec.bottomPt->prev;
- if (outRec.pts == outRec.bottomPt) outRec.pts = next;
- delete outRec.bottomPt;
- next->prev = prev;
- prev->next = next;
- outRec.bottomPt = next;
- FixupOutPolygon(outRec);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddOutPt(TEdge *e, const IntPoint &pt)
-{
- bool ToFront = (e->side == esLeft);
- if( e->outIdx < 0 )
- {
- OutRec *outRec = CreateOutRec();
- m_PolyOuts.push_back(outRec);
- outRec->idx = (int)m_PolyOuts.size()-1;
- e->outIdx = outRec->idx;
- OutPt* op = new OutPt;
- outRec->pts = op;
- outRec->bottomPt = op;
- op->pt = pt;
- op->idx = outRec->idx;
- op->next = op;
- op->prev = op;
- SetHoleState(e, outRec);
- } else
- {
- OutRec *outRec = m_PolyOuts[e->outIdx];
- OutPt* op = outRec->pts;
- if ((ToFront && PointsEqual(pt, op->pt)) ||
- (!ToFront && PointsEqual(pt, op->prev->pt))) return;
-
- if ((e->side | outRec->sides) != outRec->sides)
- {
- //check for 'rounding' artefacts ...
- if (outRec->sides == esNeither && pt.Y == op->pt.Y)
- {
- if (ToFront)
- {
- if (pt.X == op->pt.X +1) return; //ie wrong side of bottomPt
- }
- else if (pt.X == op->pt.X -1) return; //ie wrong side of bottomPt
- }
-
- outRec->sides = (EdgeSide)(outRec->sides | e->side);
- if (outRec->sides == esBoth)
- {
- //A vertex from each side has now been added.
- //Vertices of one side of an output polygon are quite commonly close to
- //or even 'touching' edges of the other side of the output polygon.
- //Very occasionally vertices from one side can 'cross' an edge on the
- //the other side. The distance 'crossed' is always less that a unit
- //and is purely an artefact of coordinate rounding. Nevertheless, this
- //results in very tiny self-intersections. Because of the way
- //orientation is calculated, even tiny self-intersections can cause
- //the Orientation function to return the wrong result. Therefore, it's
- //important to ensure that any self-intersections close to BottomPt are
- //detected and removed before orientation is assigned.
-
- OutPt *opBot, *op2;
- if (ToFront)
- {
- opBot = outRec->pts;
- op2 = opBot->next; //op2 == right side
- if (opBot->pt.Y != op2->pt.Y && opBot->pt.Y != pt.Y &&
- ((opBot->pt.X - pt.X)/(opBot->pt.Y - pt.Y) <
- (opBot->pt.X - op2->pt.X)/(opBot->pt.Y - op2->pt.Y)))
- outRec->bottomFlag = opBot;
- } else
- {
- opBot = outRec->pts->prev;
- op2 = opBot->prev; //op2 == left side
- if (opBot->pt.Y != op2->pt.Y && opBot->pt.Y != pt.Y &&
- ((opBot->pt.X - pt.X)/(opBot->pt.Y - pt.Y) >
- (opBot->pt.X - op2->pt.X)/(opBot->pt.Y - op2->pt.Y)))
- outRec->bottomFlag = opBot;
- }
- }
- }
-
- OutPt* op2 = new OutPt;
- op2->pt = pt;
- op2->idx = outRec->idx;
- if (op2->pt.Y == outRec->bottomPt->pt.Y &&
- op2->pt.X < outRec->bottomPt->pt.X)
- outRec->bottomPt = op2;
- op2->next = op;
- op2->prev = op->prev;
- op2->prev->next = op2;
- op->prev = op2;
- if (ToFront) outRec->pts = op2;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ProcessHorizontals()
-{
- TEdge* horzEdge = m_SortedEdges;
- while( horzEdge )
- {
- DeleteFromSEL( horzEdge );
- ProcessHorizontal( horzEdge );
- horzEdge = m_SortedEdges;
- }
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::IsTopHorz(const long64 XPos)
-{
- TEdge* e = m_SortedEdges;
- while( e )
- {
- if( ( XPos >= std::min(e->xcurr, e->xtop) ) &&
- ( XPos <= std::max(e->xcurr, e->xtop) ) ) return false;
- e = e->nextInSEL;
- }
- return true;
-}
-//------------------------------------------------------------------------------
-
-bool IsMinima(TEdge *e)
-{
- return e && (e->prev->nextInLML != e) && (e->next->nextInLML != e);
-}
-//------------------------------------------------------------------------------
-
-bool IsMaxima(TEdge *e, const long64 Y)
-{
- return e && e->ytop == Y && !e->nextInLML;
-}
-//------------------------------------------------------------------------------
-
-bool IsIntermediate(TEdge *e, const long64 Y)
-{
- return e->ytop == Y && e->nextInLML;
-}
-//------------------------------------------------------------------------------
-
-TEdge *GetMaximaPair(TEdge *e)
-{
- if( !IsMaxima(e->next, e->ytop) || e->next->xtop != e->xtop )
- return e->prev; else
- return e->next;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::SwapPositionsInAEL(TEdge *edge1, TEdge *edge2)
-{
- if( !edge1->nextInAEL && !edge1->prevInAEL ) return;
- if( !edge2->nextInAEL && !edge2->prevInAEL ) return;
-
- if( edge1->nextInAEL == edge2 )
- {
- TEdge* next = edge2->nextInAEL;
- if( next ) next->prevInAEL = edge1;
- TEdge* prev = edge1->prevInAEL;
- if( prev ) prev->nextInAEL = edge2;
- edge2->prevInAEL = prev;
- edge2->nextInAEL = edge1;
- edge1->prevInAEL = edge2;
- edge1->nextInAEL = next;
- }
- else if( edge2->nextInAEL == edge1 )
- {
- TEdge* next = edge1->nextInAEL;
- if( next ) next->prevInAEL = edge2;
- TEdge* prev = edge2->prevInAEL;
- if( prev ) prev->nextInAEL = edge1;
- edge1->prevInAEL = prev;
- edge1->nextInAEL = edge2;
- edge2->prevInAEL = edge1;
- edge2->nextInAEL = next;
- }
- else
- {
- TEdge* next = edge1->nextInAEL;
- TEdge* prev = edge1->prevInAEL;
- edge1->nextInAEL = edge2->nextInAEL;
- if( edge1->nextInAEL ) edge1->nextInAEL->prevInAEL = edge1;
- edge1->prevInAEL = edge2->prevInAEL;
- if( edge1->prevInAEL ) edge1->prevInAEL->nextInAEL = edge1;
- edge2->nextInAEL = next;
- if( edge2->nextInAEL ) edge2->nextInAEL->prevInAEL = edge2;
- edge2->prevInAEL = prev;
- if( edge2->prevInAEL ) edge2->prevInAEL->nextInAEL = edge2;
- }
-
- if( !edge1->prevInAEL ) m_ActiveEdges = edge1;
- else if( !edge2->prevInAEL ) m_ActiveEdges = edge2;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::SwapPositionsInSEL(TEdge *edge1, TEdge *edge2)
-{
- if( !( edge1->nextInSEL ) && !( edge1->prevInSEL ) ) return;
- if( !( edge2->nextInSEL ) && !( edge2->prevInSEL ) ) return;
-
- if( edge1->nextInSEL == edge2 )
- {
- TEdge* next = edge2->nextInSEL;
- if( next ) next->prevInSEL = edge1;
- TEdge* prev = edge1->prevInSEL;
- if( prev ) prev->nextInSEL = edge2;
- edge2->prevInSEL = prev;
- edge2->nextInSEL = edge1;
- edge1->prevInSEL = edge2;
- edge1->nextInSEL = next;
- }
- else if( edge2->nextInSEL == edge1 )
- {
- TEdge* next = edge1->nextInSEL;
- if( next ) next->prevInSEL = edge2;
- TEdge* prev = edge2->prevInSEL;
- if( prev ) prev->nextInSEL = edge1;
- edge1->prevInSEL = prev;
- edge1->nextInSEL = edge2;
- edge2->prevInSEL = edge1;
- edge2->nextInSEL = next;
- }
- else
- {
- TEdge* next = edge1->nextInSEL;
- TEdge* prev = edge1->prevInSEL;
- edge1->nextInSEL = edge2->nextInSEL;
- if( edge1->nextInSEL ) edge1->nextInSEL->prevInSEL = edge1;
- edge1->prevInSEL = edge2->prevInSEL;
- if( edge1->prevInSEL ) edge1->prevInSEL->nextInSEL = edge1;
- edge2->nextInSEL = next;
- if( edge2->nextInSEL ) edge2->nextInSEL->prevInSEL = edge2;
- edge2->prevInSEL = prev;
- if( edge2->prevInSEL ) edge2->prevInSEL->nextInSEL = edge2;
- }
-
- if( !edge1->prevInSEL ) m_SortedEdges = edge1;
- else if( !edge2->prevInSEL ) m_SortedEdges = edge2;
-}
-//------------------------------------------------------------------------------
-
-TEdge* GetNextInAEL(TEdge *e, Direction dir)
-{
- return dir == dLeftToRight ? e->nextInAEL : e->prevInAEL;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ProcessHorizontal(TEdge *horzEdge)
-{
- Direction dir;
- long64 horzLeft, horzRight;
-
- if( horzEdge->xcurr < horzEdge->xtop )
- {
- horzLeft = horzEdge->xcurr;
- horzRight = horzEdge->xtop;
- dir = dLeftToRight;
- } else
- {
- horzLeft = horzEdge->xtop;
- horzRight = horzEdge->xcurr;
- dir = dRightToLeft;
- }
-
- TEdge* eMaxPair;
- if( horzEdge->nextInLML ) eMaxPair = 0;
- else eMaxPair = GetMaximaPair(horzEdge);
-
- TEdge* e = GetNextInAEL( horzEdge , dir );
- while( e )
- {
- TEdge* eNext = GetNextInAEL( e, dir );
-
- if (eMaxPair ||
- ((dir == dLeftToRight) && (e->xcurr <= horzRight)) ||
- ((dir == dRightToLeft) && (e->xcurr >= horzLeft)))
- {
- //ok, so far it looks like we're still in range of the horizontal edge
- if ( e->xcurr == horzEdge->xtop && !eMaxPair )
- {
- assert(horzEdge->nextInLML);
- if (SlopesEqual(*e, *horzEdge->nextInLML, m_UseFullRange))
- {
- //if output polygons share an edge, they'll need joining later ...
- if (horzEdge->outIdx >= 0 && e->outIdx >= 0)
- AddJoin(horzEdge->nextInLML, e, horzEdge->outIdx);
- break; //we've reached the end of the horizontal line
- }
- else if (e->dx < horzEdge->nextInLML->dx)
- //we really have got to the end of the intermediate horz edge so quit.
- //nb: More -ve slopes follow more +ve slopes ABOVE the horizontal.
- break;
- }
-
- if( e == eMaxPair )
- {
- //horzEdge is evidently a maxima horizontal and we've arrived at its end.
- if (dir == dLeftToRight)
- IntersectEdges(horzEdge, e, IntPoint(e->xcurr, horzEdge->ycurr), ipNone);
- else
- IntersectEdges(e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr), ipNone);
- if (eMaxPair->outIdx >= 0) throw clipperException("ProcessHorizontal error");
- return;
- }
- else if( NEAR_EQUAL(e->dx, HORIZONTAL) && !IsMinima(e) && !(e->xcurr > e->xtop) )
- {
- //An overlapping horizontal edge. Overlapping horizontal edges are
- //processed as if layered with the current horizontal edge (horizEdge)
- //being infinitesimally lower that the next (e). Therfore, we
- //intersect with e only if e.xcurr is within the bounds of horzEdge ...
- if( dir == dLeftToRight )
- IntersectEdges( horzEdge , e, IntPoint(e->xcurr, horzEdge->ycurr),
- (IsTopHorz( e->xcurr ))? ipLeft : ipBoth );
- else
- IntersectEdges( e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr),
- (IsTopHorz( e->xcurr ))? ipRight : ipBoth );
- }
- else if( dir == dLeftToRight )
- {
- IntersectEdges( horzEdge, e, IntPoint(e->xcurr, horzEdge->ycurr),
- (IsTopHorz( e->xcurr ))? ipLeft : ipBoth );
- }
- else
- {
- IntersectEdges( e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr),
- (IsTopHorz( e->xcurr ))? ipRight : ipBoth );
- }
- SwapPositionsInAEL( horzEdge, e );
- }
- else if( (dir == dLeftToRight && e->xcurr > horzRight && m_SortedEdges) ||
- (dir == dRightToLeft && e->xcurr < horzLeft && m_SortedEdges) ) break;
- e = eNext;
- } //end while
-
- if( horzEdge->nextInLML )
- {
- if( horzEdge->outIdx >= 0 )
- AddOutPt( horzEdge, IntPoint(horzEdge->xtop, horzEdge->ytop));
- UpdateEdgeIntoAEL( horzEdge );
- }
- else
- {
- if ( horzEdge->outIdx >= 0 )
- IntersectEdges( horzEdge, eMaxPair,
- IntPoint(horzEdge->xtop, horzEdge->ycurr), ipBoth);
- assert(eMaxPair);
- if (eMaxPair->outIdx >= 0) throw clipperException("ProcessHorizontal error");
- DeleteFromAEL(eMaxPair);
- DeleteFromAEL(horzEdge);
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::UpdateEdgeIntoAEL(TEdge *&e)
-{
- if( !e->nextInLML ) throw
- clipperException("UpdateEdgeIntoAEL: invalid call");
- TEdge* AelPrev = e->prevInAEL;
- TEdge* AelNext = e->nextInAEL;
- e->nextInLML->outIdx = e->outIdx;
- if( AelPrev ) AelPrev->nextInAEL = e->nextInLML;
- else m_ActiveEdges = e->nextInLML;
- if( AelNext ) AelNext->prevInAEL = e->nextInLML;
- e->nextInLML->side = e->side;
- e->nextInLML->windDelta = e->windDelta;
- e->nextInLML->windCnt = e->windCnt;
- e->nextInLML->windCnt2 = e->windCnt2;
- e = e->nextInLML;
- e->prevInAEL = AelPrev;
- e->nextInAEL = AelNext;
- if( !NEAR_EQUAL(e->dx, HORIZONTAL) ) InsertScanbeam( e->ytop );
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::ProcessIntersections(const long64 botY, const long64 topY)
-{
- if( !m_ActiveEdges ) return true;
- try {
- BuildIntersectList(botY, topY);
- if ( !m_IntersectNodes) return true;
- if ( FixupIntersections() ) ProcessIntersectList();
- else return false;
- }
- catch(...) {
- m_SortedEdges = 0;
- DisposeIntersectNodes();
- throw clipperException("ProcessIntersections error");
- }
- return true;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DisposeIntersectNodes()
-{
- while ( m_IntersectNodes )
- {
- IntersectNode* iNode = m_IntersectNodes->next;
- delete m_IntersectNodes;
- m_IntersectNodes = iNode;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::BuildIntersectList(const long64 botY, const long64 topY)
-{
- if ( !m_ActiveEdges ) return;
-
- //prepare for sorting ...
- TEdge* e = m_ActiveEdges;
- e->tmpX = TopX( *e, topY );
- m_SortedEdges = e;
- m_SortedEdges->prevInSEL = 0;
- e = e->nextInAEL;
- while( e )
- {
- e->prevInSEL = e->prevInAEL;
- e->prevInSEL->nextInSEL = e;
- e->nextInSEL = 0;
- e->tmpX = TopX( *e, topY );
- e = e->nextInAEL;
- }
-
- //bubblesort ...
- bool isModified = true;
- while( isModified && m_SortedEdges )
- {
- isModified = false;
- e = m_SortedEdges;
- while( e->nextInSEL )
- {
- TEdge *eNext = e->nextInSEL;
- IntPoint pt;
- if(e->tmpX > eNext->tmpX &&
- IntersectPoint(*e, *eNext, pt, m_UseFullRange))
- {
- if (pt.Y > botY)
- {
- pt.Y = botY;
- pt.X = TopX(*e, pt.Y);
- }
- AddIntersectNode( e, eNext, pt );
- SwapPositionsInSEL(e, eNext);
- isModified = true;
- }
- else
- e = eNext;
- }
- if( e->prevInSEL ) e->prevInSEL->nextInSEL = 0;
- else break;
- }
- m_SortedEdges = 0;
-}
-//------------------------------------------------------------------------------
-
-bool ProcessParam1BeforeParam2(IntersectNode &node1, IntersectNode &node2)
-{
- bool result;
- if (node1.pt.Y == node2.pt.Y)
- {
- if (node1.edge1 == node2.edge1 || node1.edge2 == node2.edge1)
- {
- result = node2.pt.X > node1.pt.X;
- return node2.edge1->dx > 0 ? !result : result;
- }
- else if (node1.edge1 == node2.edge2 || node1.edge2 == node2.edge2)
- {
- result = node2.pt.X > node1.pt.X;
- return node2.edge2->dx > 0 ? !result : result;
- }
- else return node2.pt.X > node1.pt.X;
- }
- else return node1.pt.Y > node2.pt.Y;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::AddIntersectNode(TEdge *e1, TEdge *e2, const IntPoint &pt)
-{
- IntersectNode* newNode = new IntersectNode;
- newNode->edge1 = e1;
- newNode->edge2 = e2;
- newNode->pt = pt;
- newNode->next = 0;
- if( !m_IntersectNodes ) m_IntersectNodes = newNode;
- else if( ProcessParam1BeforeParam2(*newNode, *m_IntersectNodes) )
- {
- newNode->next = m_IntersectNodes;
- m_IntersectNodes = newNode;
- }
- else
- {
- IntersectNode* iNode = m_IntersectNodes;
- while( iNode->next && ProcessParam1BeforeParam2(*iNode->next, *newNode) )
- iNode = iNode->next;
- newNode->next = iNode->next;
- iNode->next = newNode;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ProcessIntersectList()
-{
- while( m_IntersectNodes )
- {
- IntersectNode* iNode = m_IntersectNodes->next;
- {
- IntersectEdges( m_IntersectNodes->edge1 ,
- m_IntersectNodes->edge2 , m_IntersectNodes->pt, ipBoth );
- SwapPositionsInAEL( m_IntersectNodes->edge1 , m_IntersectNodes->edge2 );
- }
- delete m_IntersectNodes;
- m_IntersectNodes = iNode;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::DoMaxima(TEdge *e, long64 topY)
-{
- TEdge* eMaxPair = GetMaximaPair(e);
- long64 X = e->xtop;
- TEdge* eNext = e->nextInAEL;
- while( eNext != eMaxPair )
- {
- if (!eNext) throw clipperException("DoMaxima error");
- IntersectEdges( e, eNext, IntPoint(X, topY), ipBoth );
- eNext = eNext->nextInAEL;
- }
- if( e->outIdx < 0 && eMaxPair->outIdx < 0 )
- {
- DeleteFromAEL( e );
- DeleteFromAEL( eMaxPair );
- }
- else if( e->outIdx >= 0 && eMaxPair->outIdx >= 0 )
- {
- IntersectEdges( e, eMaxPair, IntPoint(X, topY), ipNone );
- }
- else throw clipperException("DoMaxima error");
-}
-//------------------------------------------------------------------------------
-
-void Clipper::ProcessEdgesAtTopOfScanbeam(const long64 topY)
-{
- TEdge* e = m_ActiveEdges;
- while( e )
- {
- //1. process maxima, treating them as if they're 'bent' horizontal edges,
- // but exclude maxima with horizontal edges. nb: e can't be a horizontal.
- if( IsMaxima(e, topY) && !NEAR_EQUAL(GetMaximaPair(e)->dx, HORIZONTAL) )
- {
- //'e' might be removed from AEL, as may any following edges so ...
- TEdge* ePrior = e->prevInAEL;
- DoMaxima(e, topY);
- if( !ePrior ) e = m_ActiveEdges;
- else e = ePrior->nextInAEL;
- }
- else
- {
- //2. promote horizontal edges, otherwise update xcurr and ycurr ...
- if( IsIntermediate(e, topY) && NEAR_EQUAL(e->nextInLML->dx, HORIZONTAL) )
- {
- if (e->outIdx >= 0)
- {
- AddOutPt(e, IntPoint(e->xtop, e->ytop));
-
- for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); ++i)
- {
- IntPoint pt, pt2;
- HorzJoinRec* hj = m_HorizJoins[i];
- if (GetOverlapSegment(IntPoint(hj->edge->xbot, hj->edge->ybot),
- IntPoint(hj->edge->xtop, hj->edge->ytop),
- IntPoint(e->nextInLML->xbot, e->nextInLML->ybot),
- IntPoint(e->nextInLML->xtop, e->nextInLML->ytop), pt, pt2))
- AddJoin(hj->edge, e->nextInLML, hj->savedIdx, e->outIdx);
- }
-
- AddHorzJoin(e->nextInLML, e->outIdx);
- }
- UpdateEdgeIntoAEL(e);
- AddEdgeToSEL(e);
- } else
- {
- //this just simplifies horizontal processing ...
- e->xcurr = TopX( *e, topY );
- e->ycurr = topY;
- }
- e = e->nextInAEL;
- }
- }
-
- //3. Process horizontals at the top of the scanbeam ...
- ProcessHorizontals();
-
- //4. Promote intermediate vertices ...
- e = m_ActiveEdges;
- while( e )
- {
- if( IsIntermediate( e, topY ) )
- {
- if( e->outIdx >= 0 ) AddOutPt(e, IntPoint(e->xtop,e->ytop));
- UpdateEdgeIntoAEL(e);
-
- //if output polygons share an edge, they'll need joining later ...
- if (e->outIdx >= 0 && e->prevInAEL && e->prevInAEL->outIdx >= 0 &&
- e->prevInAEL->xcurr == e->xbot && e->prevInAEL->ycurr == e->ybot &&
- SlopesEqual(IntPoint(e->xbot,e->ybot), IntPoint(e->xtop, e->ytop),
- IntPoint(e->xbot,e->ybot),
- IntPoint(e->prevInAEL->xtop, e->prevInAEL->ytop), m_UseFullRange))
- {
- AddOutPt(e->prevInAEL, IntPoint(e->xbot, e->ybot));
- AddJoin(e, e->prevInAEL);
- }
- else if (e->outIdx >= 0 && e->nextInAEL && e->nextInAEL->outIdx >= 0 &&
- e->nextInAEL->ycurr > e->nextInAEL->ytop &&
- e->nextInAEL->ycurr <= e->nextInAEL->ybot &&
- e->nextInAEL->xcurr == e->xbot && e->nextInAEL->ycurr == e->ybot &&
- SlopesEqual(IntPoint(e->xbot,e->ybot), IntPoint(e->xtop, e->ytop),
- IntPoint(e->xbot,e->ybot),
- IntPoint(e->nextInAEL->xtop, e->nextInAEL->ytop), m_UseFullRange))
- {
- AddOutPt(e->nextInAEL, IntPoint(e->xbot, e->ybot));
- AddJoin(e, e->nextInAEL);
- }
- }
- e = e->nextInAEL;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::FixupOutPolygon(OutRec &outRec)
-{
- //FixupOutPolygon() - removes duplicate points and simplifies consecutive
- //parallel edges by removing the middle vertex.
- OutPt *lastOK = 0;
- outRec.pts = outRec.bottomPt;
- OutPt *pp = outRec.bottomPt;
-
- for (;;)
- {
- if (pp->prev == pp || pp->prev == pp->next )
- {
- DisposeOutPts(pp);
- outRec.pts = 0;
- outRec.bottomPt = 0;
- return;
- }
- //test for duplicate points and for same slope (cross-product) ...
- if ( PointsEqual(pp->pt, pp->next->pt) ||
- SlopesEqual(pp->prev->pt, pp->pt, pp->next->pt, m_UseFullRange) )
- {
- lastOK = 0;
- OutPt *tmp = pp;
- if (pp == outRec.bottomPt)
- outRec.bottomPt = 0; //flags need for updating
- pp->prev->next = pp->next;
- pp->next->prev = pp->prev;
- pp = pp->prev;
- delete tmp;
- }
- else if (pp == lastOK) break;
- else
- {
- if (!lastOK) lastOK = pp;
- pp = pp->next;
- }
- }
- if (!outRec.bottomPt) {
- outRec.bottomPt = GetBottomPt(pp);
- outRec.bottomPt->idx = outRec.idx;
- outRec.pts = outRec.bottomPt;
- }
-}
-//------------------------------------------------------------------------------
-
-void Clipper::BuildResult(Polygons &polys)
-{
- int k = 0;
- polys.resize(m_PolyOuts.size());
- for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i)
- {
- if (m_PolyOuts[i]->pts)
- {
- Polygon* pg = &polys[k];
- pg->clear();
- OutPt* p = m_PolyOuts[i]->pts;
- do
- {
- pg->push_back(p->pt);
- p = p->next;
- } while (p != m_PolyOuts[i]->pts);
- //make sure each polygon has at least 3 vertices ...
- if (pg->size() < 3) pg->clear(); else k++;
- }
- }
- polys.resize(k);
-}
-//------------------------------------------------------------------------------
-
-void Clipper::BuildResultEx(ExPolygons &polys)
-{
- PolyOutList::size_type i = 0;
- int k = 0;
- polys.resize(0);
- polys.reserve(m_PolyOuts.size());
- while (i < m_PolyOuts.size() && m_PolyOuts[i]->pts)
- {
- ExPolygon epg;
- OutPt* p = m_PolyOuts[i]->pts;
- do {
- epg.outer.push_back(p->pt);
- p = p->next;
- } while (p != m_PolyOuts[i]->pts);
- i++;
- //make sure polygons have at least 3 vertices ...
- if (epg.outer.size() < 3) continue;
- while (i < m_PolyOuts.size()
- && m_PolyOuts[i]->pts && m_PolyOuts[i]->isHole)
- {
- Polygon pg;
- p = m_PolyOuts[i]->pts;
- do {
- pg.push_back(p->pt);
- p = p->next;
- } while (p != m_PolyOuts[i]->pts);
- epg.holes.push_back(pg);
- i++;
- }
- polys.push_back(epg);
- k++;
- }
- polys.resize(k);
-}
-//------------------------------------------------------------------------------
-
-void SwapIntersectNodes(IntersectNode &int1, IntersectNode &int2)
-{
- TEdge *e1 = int1.edge1;
- TEdge *e2 = int1.edge2;
- IntPoint p = int1.pt;
-
- int1.edge1 = int2.edge1;
- int1.edge2 = int2.edge2;
- int1.pt = int2.pt;
-
- int2.edge1 = e1;
- int2.edge2 = e2;
- int2.pt = p;
-}
-//------------------------------------------------------------------------------
-
-bool Clipper::FixupIntersections()
-{
- if ( !m_IntersectNodes->next ) return true;
-
- CopyAELToSEL();
- IntersectNode *int1 = m_IntersectNodes;
- IntersectNode *int2 = m_IntersectNodes->next;
- while (int2)
- {
- TEdge *e1 = int1->edge1;
- TEdge *e2;
- if (e1->prevInSEL == int1->edge2) e2 = e1->prevInSEL;
- else if (e1->nextInSEL == int1->edge2) e2 = e1->nextInSEL;
- else
- {
- //The current intersection is out of order, so try and swap it with
- //a subsequent intersection ...
- while (int2)
- {
- if (int2->edge1->nextInSEL == int2->edge2 ||
- int2->edge1->prevInSEL == int2->edge2) break;
- else int2 = int2->next;
- }
- if ( !int2 ) return false; //oops!!!
-
- //found an intersect node that can be swapped ...
- SwapIntersectNodes(*int1, *int2);
- e1 = int1->edge1;
- e2 = int1->edge2;
- }
- SwapPositionsInSEL(e1, e2);
- int1 = int1->next;
- int2 = int1->next;
- }
-
- m_SortedEdges = 0;
-
- //finally, check the last intersection too ...
- return (int1->edge1->prevInSEL == int1->edge2 ||
- int1->edge1->nextInSEL == int1->edge2);
-}
-//------------------------------------------------------------------------------
-
-bool E2InsertsBeforeE1(TEdge &e1, TEdge &e2)
-{
- return e2.xcurr == e1.xcurr ? e2.dx > e1.dx : e2.xcurr < e1.xcurr;
-}
-//------------------------------------------------------------------------------
-
-void Clipper::InsertEdgeIntoAEL(TEdge *edge)
-{
- edge->prevInAEL = 0;
- edge->nextInAEL = 0;
- if( !m_ActiveEdges )
- {
- m_ActiveEdges = edge;
- }
- else if( E2InsertsBeforeE1(*m_ActiveEdges, *edge) )
- {
- edge->nextInAEL = m_ActiveEdges;
- m_ActiveEdges->prevInAEL = edge;
- m_ActiveEdges = edge;
- } else
- {
- TEdge* e = m_ActiveEdges;
- while( e->nextInAEL && !E2InsertsBeforeE1(*e->nextInAEL , *edge) )
- e = e->nextInAEL;
- edge->nextInAEL = e->nextInAEL;
- if( e->nextInAEL ) e->nextInAEL->prevInAEL = edge;
- edge->prevInAEL = e;
- e->nextInAEL = edge;
- }
-}
-//----------------------------------------------------------------------
-
-void Clipper::DoEdge1(TEdge *edge1, TEdge *edge2, const IntPoint &pt)
-{
- AddOutPt(edge1, pt);
- SwapSides(*edge1, *edge2);
- SwapPolyIndexes(*edge1, *edge2);
-}
-//----------------------------------------------------------------------
-
-void Clipper::DoEdge2(TEdge *edge1, TEdge *edge2, const IntPoint &pt)
-{
- AddOutPt(edge2, pt);
- SwapSides(*edge1, *edge2);
- SwapPolyIndexes(*edge1, *edge2);
-}
-//----------------------------------------------------------------------
-
-void Clipper::DoBothEdges(TEdge *edge1, TEdge *edge2, const IntPoint &pt)
-{
- AddOutPt(edge1, pt);
- AddOutPt(edge2, pt);
- SwapSides( *edge1 , *edge2 );
- SwapPolyIndexes( *edge1 , *edge2 );
-}
-//----------------------------------------------------------------------
-
-void Clipper::CheckHoleLinkages1(OutRec *outRec1, OutRec *outRec2)
-{
- //when a polygon is split into 2 polygons, make sure any holes the original
- //polygon contained link to the correct polygon ...
- for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i)
- {
- OutRec *orec = m_PolyOuts[i];
- if (orec->isHole && orec->bottomPt && orec->FirstLeft == outRec1 &&
- !PointInPolygon(orec->bottomPt->pt, outRec1->pts, m_UseFullRange))
- orec->FirstLeft = outRec2;
- }
-}
-//----------------------------------------------------------------------
-
-void Clipper::CheckHoleLinkages2(OutRec *outRec1, OutRec *outRec2)
-{
- //if a hole is owned by outRec2 then make it owned by outRec1 ...
- for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i)
- if (m_PolyOuts[i]->isHole && m_PolyOuts[i]->bottomPt &&
- m_PolyOuts[i]->FirstLeft == outRec2)
- m_PolyOuts[i]->FirstLeft = outRec1;
-}
-//----------------------------------------------------------------------
-
-void Clipper::JoinCommonEdges(bool fixHoleLinkages)
-{
- for (JoinList::size_type i = 0; i < m_Joins.size(); i++)
- {
- JoinRec* j = m_Joins[i];
- OutRec *outRec1 = m_PolyOuts[j->poly1Idx];
- OutPt *pp1a = outRec1->pts;
- OutRec *outRec2 = m_PolyOuts[j->poly2Idx];
- OutPt *pp2a = outRec2->pts;
- IntPoint pt1 = j->pt2a, pt2 = j->pt2b;
- IntPoint pt3 = j->pt1a, pt4 = j->pt1b;
- if (!FindSegment(pp1a, pt1, pt2)) continue;
- if (j->poly1Idx == j->poly2Idx)
- {
- //we're searching the same polygon for overlapping segments so
- //segment 2 mustn't be the same as segment 1 ...
- pp2a = pp1a->next;
- if (!FindSegment(pp2a, pt3, pt4) || (pp2a == pp1a)) continue;
- }
- else if (!FindSegment(pp2a, pt3, pt4)) continue;
-
- if (!GetOverlapSegment(pt1, pt2, pt3, pt4, pt1, pt2)) continue;
-
- OutPt *p1, *p2, *p3, *p4;
- OutPt *prev = pp1a->prev;
- //get p1 & p2 polypts - the overlap start & endpoints on poly1
- if (PointsEqual(pp1a->pt, pt1)) p1 = pp1a;
- else if (PointsEqual(prev->pt, pt1)) p1 = prev;
- else p1 = InsertPolyPtBetween(pp1a, prev, pt1);
-
- if (PointsEqual(pp1a->pt, pt2)) p2 = pp1a;
- else if (PointsEqual(prev->pt, pt2)) p2 = prev;
- else if ((p1 == pp1a) || (p1 == prev))
- p2 = InsertPolyPtBetween(pp1a, prev, pt2);
- else if (Pt3IsBetweenPt1AndPt2(pp1a->pt, p1->pt, pt2))
- p2 = InsertPolyPtBetween(pp1a, p1, pt2); else
- p2 = InsertPolyPtBetween(p1, prev, pt2);
-
- //get p3 & p4 polypts - the overlap start & endpoints on poly2
- prev = pp2a->prev;
- if (PointsEqual(pp2a->pt, pt1)) p3 = pp2a;
- else if (PointsEqual(prev->pt, pt1)) p3 = prev;
- else p3 = InsertPolyPtBetween(pp2a, prev, pt1);
-
- if (PointsEqual(pp2a->pt, pt2)) p4 = pp2a;
- else if (PointsEqual(prev->pt, pt2)) p4 = prev;
- else if ((p3 == pp2a) || (p3 == prev))
- p4 = InsertPolyPtBetween(pp2a, prev, pt2);
- else if (Pt3IsBetweenPt1AndPt2(pp2a->pt, p3->pt, pt2))
- p4 = InsertPolyPtBetween(pp2a, p3, pt2); else
- p4 = InsertPolyPtBetween(p3, prev, pt2);
-
- //p1.pt == p3.pt and p2.pt == p4.pt so join p1 to p3 and p2 to p4 ...
- if (p1->next == p2 && p3->prev == p4)
- {
- p1->next = p3;
- p3->prev = p1;
- p2->prev = p4;
- p4->next = p2;
- }
- else if (p1->prev == p2 && p3->next == p4)
- {
- p1->prev = p3;
- p3->next = p1;
- p2->next = p4;
- p4->prev = p2;
- }
- else
- continue; //an orientation is probably wrong
-
- if (j->poly2Idx == j->poly1Idx)
- {
- //instead of joining two polygons, we've just created a new one by
- //splitting one polygon into two.
- outRec1->pts = GetBottomPt(p1);
- outRec1->bottomPt = outRec1->pts;
- outRec1->bottomPt->idx = outRec1->idx;
- outRec2 = CreateOutRec();
- m_PolyOuts.push_back(outRec2);
- outRec2->idx = (int)m_PolyOuts.size()-1;
- j->poly2Idx = outRec2->idx;
- outRec2->pts = GetBottomPt(p2);
- outRec2->bottomPt = outRec2->pts;
- outRec2->bottomPt->idx = outRec2->idx;
-
- if (PointInPolygon(outRec2->pts->pt, outRec1->pts, m_UseFullRange))
- {
- //outRec2 is contained by outRec1 ...
- outRec2->isHole = !outRec1->isHole;
- outRec2->FirstLeft = outRec1;
- if (outRec2->isHole ==
- (m_ReverseOutput ^ Orientation(outRec2, m_UseFullRange)))
- ReversePolyPtLinks(*outRec2->pts);
- } else if (PointInPolygon(outRec1->pts->pt, outRec2->pts, m_UseFullRange))
- {
- //outRec1 is contained by outRec2 ...
- outRec2->isHole = outRec1->isHole;
- outRec1->isHole = !outRec2->isHole;
- outRec2->FirstLeft = outRec1->FirstLeft;
- outRec1->FirstLeft = outRec2;
- if (outRec1->isHole ==
- (m_ReverseOutput ^ Orientation(outRec1, m_UseFullRange)))
- ReversePolyPtLinks(*outRec1->pts);
- //make sure any contained holes now link to the correct polygon ...
- if (fixHoleLinkages) CheckHoleLinkages1(outRec1, outRec2);
- } else
- {
- outRec2->isHole = outRec1->isHole;
- outRec2->FirstLeft = outRec1->FirstLeft;
- //make sure any contained holes now link to the correct polygon ...
- if (fixHoleLinkages) CheckHoleLinkages1(outRec1, outRec2);
- }
-
- //now fixup any subsequent joins that match this polygon
- for (JoinList::size_type k = i+1; k < m_Joins.size(); k++)
- {
- JoinRec* j2 = m_Joins[k];
- if (j2->poly1Idx == j->poly1Idx && PointIsVertex(j2->pt1a, p2))
- j2->poly1Idx = j->poly2Idx;
- if (j2->poly2Idx == j->poly1Idx && PointIsVertex(j2->pt2a, p2))
- j2->poly2Idx = j->poly2Idx;
- }
-
- //now cleanup redundant edges too ...
- FixupOutPolygon(*outRec1);
- FixupOutPolygon(*outRec2);
-
- if (Orientation(outRec1, m_UseFullRange) != (Area(*outRec1, m_UseFullRange) > 0))
- DisposeBottomPt(*outRec1);
- if (Orientation(outRec2, m_UseFullRange) != (Area(*outRec2, m_UseFullRange) > 0))
- DisposeBottomPt(*outRec2);
-
- } else
- {
- //joined 2 polygons together ...
-
- //make sure any holes contained by outRec2 now link to outRec1 ...
- if (fixHoleLinkages) CheckHoleLinkages2(outRec1, outRec2);
-
- //now cleanup redundant edges too ...
- FixupOutPolygon(*outRec1);
-
- if (outRec1->pts)
- {
- outRec1->isHole = !Orientation(outRec1, m_UseFullRange);
- if (outRec1->isHole && !outRec1->FirstLeft)
- outRec1->FirstLeft = outRec2->FirstLeft;
- }
-
- //delete the obsolete pointer ...
- int OKIdx = outRec1->idx;
- int ObsoleteIdx = outRec2->idx;
- outRec2->pts = 0;
- outRec2->bottomPt = 0;
- outRec2->AppendLink = outRec1;
-
- //now fixup any subsequent Joins that match this polygon
- for (JoinList::size_type k = i+1; k < m_Joins.size(); k++)
- {
- JoinRec* j2 = m_Joins[k];
- if (j2->poly1Idx == ObsoleteIdx) j2->poly1Idx = OKIdx;
- if (j2->poly2Idx == ObsoleteIdx) j2->poly2Idx = OKIdx;
- }
- }
- }
-}
-//------------------------------------------------------------------------------
-
-void ReversePolygon(Polygon& p)
-{
- std::reverse(p.begin(), p.end());
-}
-//------------------------------------------------------------------------------
-
-void ReversePolygons(Polygons& p)
-{
- for (Polygons::size_type i = 0; i < p.size(); ++i)
- ReversePolygon(p[i]);
-}
-
-//------------------------------------------------------------------------------
-// OffsetPolygon functions ...
-//------------------------------------------------------------------------------
-
-struct DoublePoint
-{
- double X;
- double Y;
- DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
-};
-//------------------------------------------------------------------------------
-
-Polygon BuildArc(const IntPoint &pt,
- const double a1, const double a2, const double r)
-{
- long64 steps = std::max(6, int(std::sqrt(std::fabs(r)) * std::fabs(a2 - a1)));
- if (steps > 0x100000) steps = 0x100000;
- int n = (unsigned)steps;
- Polygon result(n);
- double da = (a2 - a1) / (n -1);
- double a = a1;
- for (int i = 0; i < n; ++i)
- {
- result[i].X = pt.X + Round(std::cos(a)*r);
- result[i].Y = pt.Y + Round(std::sin(a)*r);
- a += da;
- }
- return result;
-}
-//------------------------------------------------------------------------------
-
-DoublePoint GetUnitNormal( const IntPoint &pt1, const IntPoint &pt2)
-{
- if(pt2.X == pt1.X && pt2.Y == pt1.Y)
- return DoublePoint(0, 0);
-
- double dx = (double)(pt2.X - pt1.X);
- double dy = (double)(pt2.Y - pt1.Y);
- double f = 1 *1.0/ std::sqrt( dx*dx + dy*dy );
- dx *= f;
- dy *= f;
- return DoublePoint(dy, -dx);
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class PolyOffsetBuilder
-{
-private:
- Polygons m_p;
- Polygon* m_curr_poly;
- std::vector<DoublePoint> normals;
- double m_delta, m_RMin, m_R;
- size_t m_i, m_j, m_k;
- static const int buffLength = 128;
- JoinType m_jointype;
-
-public:
-
-PolyOffsetBuilder(const Polygons& in_polys, Polygons& out_polys,
- double delta, JoinType jointype, double MiterLimit)
-{
- //nb precondition - out_polys != ptsin_polys
- if (NEAR_ZERO(delta))
- {
- out_polys = in_polys;
- return;
- }
-
- this->m_p = in_polys;
- this->m_delta = delta;
- this->m_jointype = jointype;
- if (MiterLimit <= 1) MiterLimit = 1;
- m_RMin = 2/(MiterLimit*MiterLimit);
-
- double deltaSq = delta*delta;
- out_polys.clear();
- out_polys.resize(in_polys.size());
- for (m_i = 0; m_i < in_polys.size(); m_i++)
- {
- m_curr_poly = &out_polys[m_i];
- size_t len = in_polys[m_i].size();
- if (len > 1 && m_p[m_i][0].X == m_p[m_i][len - 1].X &&
- m_p[m_i][0].Y == m_p[m_i][len-1].Y) len--;
-
- //when 'shrinking' polygons - to minimize artefacts
- //strip those polygons that have an area < pi * delta^2 ...
- double a1 = Area(in_polys[m_i]);
- if (delta < 0) { if (a1 > 0 && a1 < deltaSq *pi) len = 0; }
- else if (a1 < 0 && -a1 < deltaSq *pi) len = 0; //holes have neg. area
-
- if (len == 0 || (len < 3 && delta <= 0))
- continue;
- else if (len == 1)
- {
- Polygon arc;
- arc = BuildArc(in_polys[m_i][len-1], 0, 2 * pi, delta);
- out_polys[m_i] = arc;
- continue;
- }
-
- //build normals ...
- normals.clear();
- normals.resize(len);
- normals[len-1] = GetUnitNormal(in_polys[m_i][len-1], in_polys[m_i][0]);
- for (m_j = 0; m_j < len -1; ++m_j)
- normals[m_j] = GetUnitNormal(in_polys[m_i][m_j], in_polys[m_i][m_j+1]);
-
- m_k = len -1;
- for (m_j = 0; m_j < len; ++m_j)
- {
- switch (jointype)
- {
- case jtMiter:
- {
- m_R = 1 + (normals[m_j].X*normals[m_k].X +
- normals[m_j].Y*normals[m_k].Y);
- if (m_R >= m_RMin) DoMiter(); else DoSquare(MiterLimit);
- break;
- }
- case jtSquare: DoSquare(); break;
- case jtRound: DoRound(); break;
- }
- m_k = m_j;
- }
- }
-
- //finally, clean up untidy corners using Clipper ...
- Clipper clpr;
- clpr.AddPolygons(out_polys, ptSubject);
- if (delta > 0)
- {
- if (!clpr.Execute(ctUnion, out_polys, pftPositive, pftPositive))
- out_polys.clear();
- }
- else
- {
- IntRect r = clpr.GetBounds();
- Polygon outer(4);
- outer[0] = IntPoint(r.left - 10, r.bottom + 10);
- outer[1] = IntPoint(r.right + 10, r.bottom + 10);
- outer[2] = IntPoint(r.right + 10, r.top - 10);
- outer[3] = IntPoint(r.left - 10, r.top - 10);
-
- clpr.AddPolygon(outer, ptSubject);
- if (clpr.Execute(ctUnion, out_polys, pftNegative, pftNegative))
- {
- out_polys.erase(out_polys.begin());
- ReversePolygons(out_polys);
-
- } else
- out_polys.clear();
- }
-}
-//------------------------------------------------------------------------------
-
-private:
-
-void AddPoint(const IntPoint& pt)
-{
- Polygon::size_type len = m_curr_poly->size();
- if (len == m_curr_poly->capacity())
- m_curr_poly->reserve(len + buffLength);
- m_curr_poly->push_back(pt);
-}
-//------------------------------------------------------------------------------
-
-void DoSquare(double mul = 1.0)
-{
- IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X * m_delta),
- (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta));
- IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X * m_delta),
- (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta));
- if ((normals[m_k].X * normals[m_j].Y - normals[m_j].X * normals[m_k].Y) * m_delta >= 0)
- {
- double a1 = std::atan2(normals[m_k].Y, normals[m_k].X);
- double a2 = std::atan2(-normals[m_j].Y, -normals[m_j].X);
- a1 = std::fabs(a2 - a1);
- if (a1 > pi) a1 = pi * 2 - a1;
- double dx = std::tan((pi - a1)/4) * std::fabs(m_delta * mul);
- pt1 = IntPoint((long64)(pt1.X -normals[m_k].Y * dx),
- (long64)(pt1.Y + normals[m_k].X * dx));
- AddPoint(pt1);
- pt2 = IntPoint((long64)(pt2.X + normals[m_j].Y * dx),
- (long64)(pt2.Y -normals[m_j].X * dx));
- AddPoint(pt2);
- }
- else
- {
- AddPoint(pt1);
- AddPoint(m_p[m_i][m_j]);
- AddPoint(pt2);
- }
-}
-//------------------------------------------------------------------------------
-
-void DoMiter()
-{
- if ((normals[m_k].X * normals[m_j].Y - normals[m_j].X * normals[m_k].Y) * m_delta >= 0)
- {
- double q = m_delta / m_R;
- AddPoint(IntPoint((long64)Round(m_p[m_i][m_j].X +
- (normals[m_k].X + normals[m_j].X) * q),
- (long64)Round(m_p[m_i][m_j].Y + (normals[m_k].Y + normals[m_j].Y) * q)));
- }
- else
- {
- IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X *
- m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta));
- IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X *
- m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta));
- AddPoint(pt1);
- AddPoint(m_p[m_i][m_j]);
- AddPoint(pt2);
- }
-}
-//------------------------------------------------------------------------------
-
-void DoRound()
-{
- IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X * m_delta),
- (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta));
- IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X * m_delta),
- (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta));
- AddPoint(pt1);
- //round off reflex angles (ie > 180 deg) unless almost flat (ie < ~10deg).
- if ((normals[m_k].X*normals[m_j].Y - normals[m_j].X*normals[m_k].Y) * m_delta >= 0)
- {
- if (normals[m_j].X * normals[m_k].X + normals[m_j].Y * normals[m_k].Y < 0.985)
- {
- double a1 = std::atan2(normals[m_k].Y, normals[m_k].X);
- double a2 = std::atan2(normals[m_j].Y, normals[m_j].X);
- if (m_delta > 0 && a2 < a1) a2 += pi *2;
- else if (m_delta < 0 && a2 > a1) a2 -= pi *2;
- Polygon arc = BuildArc(m_p[m_i][m_j], a1, a2, m_delta);
- for (Polygon::size_type m = 0; m < arc.size(); m++)
- AddPoint(arc[m]);
- }
- }
- else
- AddPoint(m_p[m_i][m_j]);
- AddPoint(pt2);
-}
-//--------------------------------------------------------------------------
-
-}; //end PolyOffsetBuilder
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-void OffsetPolygons(const Polygons &in_polys, Polygons &out_polys,
- double delta, JoinType jointype, double MiterLimit)
-{
- if (&out_polys == &in_polys)
- {
- Polygons poly2(in_polys);
- PolyOffsetBuilder(poly2, out_polys, delta, jointype, MiterLimit);
- }
- else PolyOffsetBuilder(in_polys, out_polys, delta, jointype, MiterLimit);
-}
-//------------------------------------------------------------------------------
-
-void SimplifyPolygon(const Polygon &in_poly, Polygons &out_polys, PolyFillType fillType)
-{
- Clipper c;
- c.AddPolygon(in_poly, ptSubject);
- c.Execute(ctUnion, out_polys, fillType, fillType);
-}
-//------------------------------------------------------------------------------
-
-void SimplifyPolygons(const Polygons &in_polys, Polygons &out_polys, PolyFillType fillType)
-{
- Clipper c;
- c.AddPolygons(in_polys, ptSubject);
- c.Execute(ctUnion, out_polys, fillType, fillType);
-}
-//------------------------------------------------------------------------------
-
-void SimplifyPolygons(Polygons &polys, PolyFillType fillType)
-{
- SimplifyPolygons(polys, polys, fillType);
-}
-//------------------------------------------------------------------------------
-
-std::ostream& operator <<(std::ostream &s, IntPoint& p)
-{
- s << p.X << ' ' << p.Y << "\n";
- return s;
-}
-//------------------------------------------------------------------------------
-
-std::ostream& operator <<(std::ostream &s, Polygon &p)
-{
- for (Polygon::size_type i = 0; i < p.size(); i++)
- s << p[i];
- s << "\n";
- return s;
-}
-//------------------------------------------------------------------------------
-
-std::ostream& operator <<(std::ostream &s, Polygons &p)
-{
- for (Polygons::size_type i = 0; i < p.size(); i++)
- s << p[i];
- s << "\n";
- return s;
-}
-//------------------------------------------------------------------------------
-
-} //ClipperLib namespace
diff --git a/src/3rdparty/assimp/contrib/clipper/clipper.hpp b/src/3rdparty/assimp/contrib/clipper/clipper.hpp
deleted file mode 100644
index 7cdac6c3f..000000000
--- a/src/3rdparty/assimp/contrib/clipper/clipper.hpp
+++ /dev/null
@@ -1,306 +0,0 @@
-/*******************************************************************************
-* *
-* Author : Angus Johnson *
-* Version : 4.8.8 *
-* Date : 30 August 2012 *
-* Website : http://www.angusj.com *
-* Copyright : Angus Johnson 2010-2012 *
-* *
-* License: *
-* Use, modification & distribution is subject to Boost Software License Ver 1. *
-* http://www.boost.org/LICENSE_1_0.txt *
-* *
-* Attributions: *
-* The code in this library is an extension of Bala Vatti's clipping algorithm: *
-* "A generic solution to polygon clipping" *
-* Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. *
-* http://portal.acm.org/citation.cfm?id=129906 *
-* *
-* Computer graphics and geometric modeling: implementation and algorithms *
-* By Max K. Agoston *
-* Springer; 1 edition (January 4, 2005) *
-* http://books.google.com/books?q=vatti+clipping+agoston *
-* *
-* See also: *
-* "Polygon Offsetting by Computing Winding Numbers" *
-* Paper no. DETC2005-85513 pp. 565-575 *
-* ASME 2005 International Design Engineering Technical Conferences *
-* and Computers and Information in Engineering Conference (IDETC/CIE2005) *
-* September 24-28, 2005 , Long Beach, California, USA *
-* http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf *
-* *
-*******************************************************************************/
-
-#ifndef clipper_hpp
-#define clipper_hpp
-
-#include <vector>
-#include <stdexcept>
-#include <cstring>
-#include <cstdlib>
-#include <ostream>
-
-namespace ClipperLib {
-
-enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor };
-enum PolyType { ptSubject, ptClip };
-//By far the most widely used winding rules for polygon filling are
-//EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32)
-//Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL)
-//see http://glprogramming.com/red/chapter11.html
-enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
-
-typedef signed long long long64;
-typedef unsigned long long ulong64;
-
-struct IntPoint {
-public:
- long64 X;
- long64 Y;
- IntPoint(long64 x = 0, long64 y = 0): X(x), Y(y) {};
- friend std::ostream& operator <<(std::ostream &s, IntPoint &p);
-};
-
-typedef std::vector< IntPoint > Polygon;
-typedef std::vector< Polygon > Polygons;
-
-std::ostream& operator <<(std::ostream &s, Polygon &p);
-std::ostream& operator <<(std::ostream &s, Polygons &p);
-
-struct ExPolygon {
- Polygon outer;
- Polygons holes;
-};
-typedef std::vector< ExPolygon > ExPolygons;
-
-enum JoinType { jtSquare, jtRound, jtMiter };
-
-bool Orientation(const Polygon &poly);
-double Area(const Polygon &poly);
-void OffsetPolygons(const Polygons &in_polys, Polygons &out_polys,
- double delta, JoinType jointype = jtSquare, double MiterLimit = 2);
-void SimplifyPolygon(const Polygon &in_poly, Polygons &out_polys, PolyFillType fillType = pftEvenOdd);
-void SimplifyPolygons(const Polygons &in_polys, Polygons &out_polys, PolyFillType fillType = pftEvenOdd);
-void SimplifyPolygons(Polygons &polys, PolyFillType fillType = pftEvenOdd);
-
-void ReversePolygon(Polygon& p);
-void ReversePolygons(Polygons& p);
-
-//used internally ...
-enum EdgeSide { esNeither = 0, esLeft = 1, esRight = 2, esBoth = 3 };
-enum IntersectProtects { ipNone = 0, ipLeft = 1, ipRight = 2, ipBoth = 3 };
-
-struct TEdge {
- long64 xbot;
- long64 ybot;
- long64 xcurr;
- long64 ycurr;
- long64 xtop;
- long64 ytop;
- double dx;
- long64 tmpX;
- PolyType polyType;
- EdgeSide side;
- int windDelta; //1 or -1 depending on winding direction
- int windCnt;
- int windCnt2; //winding count of the opposite polytype
- int outIdx;
- TEdge *next;
- TEdge *prev;
- TEdge *nextInLML;
- TEdge *nextInAEL;
- TEdge *prevInAEL;
- TEdge *nextInSEL;
- TEdge *prevInSEL;
-};
-
-struct IntersectNode {
- TEdge *edge1;
- TEdge *edge2;
- IntPoint pt;
- IntersectNode *next;
-};
-
-struct LocalMinima {
- long64 Y;
- TEdge *leftBound;
- TEdge *rightBound;
- LocalMinima *next;
-};
-
-struct Scanbeam {
- long64 Y;
- Scanbeam *next;
-};
-
-struct OutPt; //forward declaration
-
-struct OutRec {
- int idx;
- bool isHole;
- OutRec *FirstLeft;
- OutRec *AppendLink;
- OutPt *pts;
- OutPt *bottomPt;
- OutPt *bottomFlag;
- EdgeSide sides;
-};
-
-struct OutPt {
- int idx;
- IntPoint pt;
- OutPt *next;
- OutPt *prev;
-};
-
-struct JoinRec {
- IntPoint pt1a;
- IntPoint pt1b;
- int poly1Idx;
- IntPoint pt2a;
- IntPoint pt2b;
- int poly2Idx;
-};
-
-struct HorzJoinRec {
- TEdge *edge;
- int savedIdx;
-};
-
-struct IntRect { long64 left; long64 top; long64 right; long64 bottom; };
-
-typedef std::vector < OutRec* > PolyOutList;
-typedef std::vector < TEdge* > EdgeList;
-typedef std::vector < JoinRec* > JoinList;
-typedef std::vector < HorzJoinRec* > HorzJoinList;
-
-//ClipperBase is the ancestor to the Clipper class. It should not be
-//instantiated directly. This class simply abstracts the conversion of sets of
-//polygon coordinates into edge objects that are stored in a LocalMinima list.
-class ClipperBase
-{
-public:
- ClipperBase();
- virtual ~ClipperBase();
- bool AddPolygon(const Polygon &pg, PolyType polyType);
- bool AddPolygons( const Polygons &ppg, PolyType polyType);
- virtual void Clear();
- IntRect GetBounds();
-protected:
- void DisposeLocalMinimaList();
- TEdge* AddBoundsToLML(TEdge *e);
- void PopLocalMinima();
- virtual void Reset();
- void InsertLocalMinima(LocalMinima *newLm);
- LocalMinima *m_CurrentLM;
- LocalMinima *m_MinimaList;
- bool m_UseFullRange;
- EdgeList m_edges;
-};
-
-class Clipper : public virtual ClipperBase
-{
-public:
- Clipper();
- ~Clipper();
- bool Execute(ClipType clipType,
- Polygons &solution,
- PolyFillType subjFillType = pftEvenOdd,
- PolyFillType clipFillType = pftEvenOdd);
- bool Execute(ClipType clipType,
- ExPolygons &solution,
- PolyFillType subjFillType = pftEvenOdd,
- PolyFillType clipFillType = pftEvenOdd);
- void Clear();
- bool ReverseSolution() {return m_ReverseOutput;};
- void ReverseSolution(bool value) {m_ReverseOutput = value;};
-protected:
- void Reset();
- virtual bool ExecuteInternal(bool fixHoleLinkages);
-private:
- PolyOutList m_PolyOuts;
- JoinList m_Joins;
- HorzJoinList m_HorizJoins;
- ClipType m_ClipType;
- Scanbeam *m_Scanbeam;
- TEdge *m_ActiveEdges;
- TEdge *m_SortedEdges;
- IntersectNode *m_IntersectNodes;
- bool m_ExecuteLocked;
- PolyFillType m_ClipFillType;
- PolyFillType m_SubjFillType;
- bool m_ReverseOutput;
- void DisposeScanbeamList();
- void SetWindingCount(TEdge& edge);
- bool IsEvenOddFillType(const TEdge& edge) const;
- bool IsEvenOddAltFillType(const TEdge& edge) const;
- void InsertScanbeam(const long64 Y);
- long64 PopScanbeam();
- void InsertLocalMinimaIntoAEL(const long64 botY);
- void InsertEdgeIntoAEL(TEdge *edge);
- void AddEdgeToSEL(TEdge *edge);
- void CopyAELToSEL();
- void DeleteFromSEL(TEdge *e);
- void DeleteFromAEL(TEdge *e);
- void UpdateEdgeIntoAEL(TEdge *&e);
- void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2);
- bool IsContributing(const TEdge& edge) const;
- bool IsTopHorz(const long64 XPos);
- void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2);
- void DoMaxima(TEdge *e, long64 topY);
- void ProcessHorizontals();
- void ProcessHorizontal(TEdge *horzEdge);
- void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
- void AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
- void AppendPolygon(TEdge *e1, TEdge *e2);
- void DoEdge1(TEdge *edge1, TEdge *edge2, const IntPoint &pt);
- void DoEdge2(TEdge *edge1, TEdge *edge2, const IntPoint &pt);
- void DoBothEdges(TEdge *edge1, TEdge *edge2, const IntPoint &pt);
- void IntersectEdges(TEdge *e1, TEdge *e2,
- const IntPoint &pt, IntersectProtects protects);
- OutRec* CreateOutRec();
- void AddOutPt(TEdge *e, const IntPoint &pt);
- void DisposeBottomPt(OutRec &outRec);
- void DisposeAllPolyPts();
- void DisposeOutRec(PolyOutList::size_type index);
- bool ProcessIntersections(const long64 botY, const long64 topY);
- void AddIntersectNode(TEdge *e1, TEdge *e2, const IntPoint &pt);
- void BuildIntersectList(const long64 botY, const long64 topY);
- void ProcessIntersectList();
- void ProcessEdgesAtTopOfScanbeam(const long64 topY);
- void BuildResult(Polygons& polys);
- void BuildResultEx(ExPolygons& polys);
- void SetHoleState(TEdge *e, OutRec *OutRec);
- void DisposeIntersectNodes();
- bool FixupIntersections();
- void FixupOutPolygon(OutRec &outRec);
- bool IsHole(TEdge *e);
- void FixHoleLinkage(OutRec *outRec);
- void CheckHoleLinkages1(OutRec *outRec1, OutRec *outRec2);
- void CheckHoleLinkages2(OutRec *outRec1, OutRec *outRec2);
- void AddJoin(TEdge *e1, TEdge *e2, int e1OutIdx = -1, int e2OutIdx = -1);
- void ClearJoins();
- void AddHorzJoin(TEdge *e, int idx);
- void ClearHorzJoins();
- void JoinCommonEdges(bool fixHoleLinkages);
-};
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class clipperException : public std::exception
-{
- public:
- clipperException(const char* description): m_descr(description) {}
- virtual ~clipperException() throw() {}
- virtual const char* what() const throw() {return m_descr.c_str();}
- private:
- std::string m_descr;
-};
-//------------------------------------------------------------------------------
-
-} //ClipperLib namespace
-
-#endif //clipper_hpp
-
-
diff --git a/src/3rdparty/assimp/contrib/irrXML/CXMLReaderImpl.h b/src/3rdparty/assimp/contrib/irrXML/CXMLReaderImpl.h
deleted file mode 100644
index 63b700dc1..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/CXMLReaderImpl.h
+++ /dev/null
@@ -1,809 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine" and the "irrXML" project.
-// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
-
-#ifndef __ICXML_READER_IMPL_H_INCLUDED__
-#define __ICXML_READER_IMPL_H_INCLUDED__
-
-#include "irrXML.h"
-#include "irrString.h"
-#include "irrArray.h"
-
-using namespace Assimp;
-
-#ifdef _DEBUG
-#define IRR_DEBUGPRINT(x) printf((x));
-#else // _DEBUG
-#define IRR_DEBUGPRINT(x)
-#endif // _DEBUG
-
-
-namespace irr
-{
-namespace io
-{
-
-
-//! implementation of the IrrXMLReader
-template<class char_type, class superclass>
-class CXMLReaderImpl : public IIrrXMLReader<char_type, superclass>
-{
-public:
-
- //! Constructor
- CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true)
- : TextData(0), P(0), TextBegin(0), TextSize(0), CurrentNodeType(EXN_NONE),
- SourceFormat(ETF_ASCII), TargetFormat(ETF_ASCII)
- {
- if (!callback)
- return;
-
- storeTargetFormat();
-
- // read whole xml file
-
- readFile(callback);
-
- // clean up
-
- if (deleteCallBack)
- delete callback;
-
- // create list with special characters
-
- createSpecialCharacterList();
-
- // set pointer to text begin
- P = TextBegin;
- }
-
-
- //! Destructor
- virtual ~CXMLReaderImpl()
- {
- delete [] TextData;
- }
-
-
- //! Reads forward to the next xml node.
- //! \return Returns false, if there was no further node.
- virtual bool read()
- {
- // if not end reached, parse the node
- if (P && (unsigned int)(P - TextBegin) < TextSize - 1 && *P != 0)
- {
- parseCurrentNode();
- return true;
- }
-
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
- return false;
- }
-
-
- //! Returns the type of the current XML node.
- virtual EXML_NODE getNodeType() const
- {
- return CurrentNodeType;
- }
-
-
- //! Returns attribute count of the current XML node.
- virtual int getAttributeCount() const
- {
- return Attributes.size();
- }
-
-
- //! Returns name of an attribute.
- virtual const char_type* getAttributeName(int idx) const
- {
- if (idx < 0 || idx >= (int)Attributes.size())
- return 0;
-
- return Attributes[idx].Name.c_str();
- }
-
-
- //! Returns the value of an attribute.
- virtual const char_type* getAttributeValue(int idx) const
- {
- if (idx < 0 || idx >= (int)Attributes.size())
- return 0;
-
- return Attributes[idx].Value.c_str();
- }
-
-
- //! Returns the value of an attribute.
- virtual const char_type* getAttributeValue(const char_type* name) const
- {
- const SAttribute* attr = getAttributeByName(name);
- if (!attr)
- return 0;
-
- return attr->Value.c_str();
- }
-
-
- //! Returns the value of an attribute
- virtual const char_type* getAttributeValueSafe(const char_type* name) const
- {
- const SAttribute* attr = getAttributeByName(name);
- if (!attr)
- return EmptyString.c_str();
-
- return attr->Value.c_str();
- }
-
-
-
- //! Returns the value of an attribute as integer.
- int getAttributeValueAsInt(const char_type* name) const
- {
- return (int)getAttributeValueAsFloat(name);
- }
-
-
- //! Returns the value of an attribute as integer.
- int getAttributeValueAsInt(int idx) const
- {
- return (int)getAttributeValueAsFloat(idx);
- }
-
-
- //! Returns the value of an attribute as float.
- float getAttributeValueAsFloat(const char_type* name) const
- {
- const SAttribute* attr = getAttributeByName(name);
- if (!attr)
- return 0;
-
- core::stringc c = attr->Value.c_str();
- return fast_atof(c.c_str());
- }
-
-
- //! Returns the value of an attribute as float.
- float getAttributeValueAsFloat(int idx) const
- {
- const char_type* attrvalue = getAttributeValue(idx);
- if (!attrvalue)
- return 0;
-
- core::stringc c = attrvalue;
- return fast_atof(c.c_str());
- }
-
-
- //! Returns the name of the current node.
- virtual const char_type* getNodeName() const
- {
- return NodeName.c_str();
- }
-
-
- //! Returns data of the current node.
- virtual const char_type* getNodeData() const
- {
- return NodeName.c_str();
- }
-
-
- //! Returns if an element is an empty element, like <foo />
- virtual bool isEmptyElement() const
- {
- return IsEmptyElement;
- }
-
- //! Returns format of the source xml file.
- virtual ETEXT_FORMAT getSourceFormat() const
- {
- return SourceFormat;
- }
-
- //! Returns format of the strings returned by the parser.
- virtual ETEXT_FORMAT getParserFormat() const
- {
- return TargetFormat;
- }
-
-private:
-
- // Reads the current xml node
- void parseCurrentNode()
- {
- char_type* start = P;
-
- // move forward until '<' found
- while(*P != L'<' && *P)
- ++P;
-
- if (!*P)
- return;
-
- if (P - start > 0)
- {
- // we found some text, store it
- if (setText(start, P))
- return;
- }
-
- ++P;
-
- // based on current token, parse and report next element
- switch(*P)
- {
- case L'/':
- parseClosingXMLElement();
- break;
- case L'?':
- ignoreDefinition();
- break;
- case L'!':
- if (!parseCDATA())
- parseComment();
- break;
- default:
- parseOpeningXMLElement();
- break;
- }
- }
-
-
- //! sets the state that text was found. Returns true if set should be set
- bool setText(char_type* start, char_type* end)
- {
- // check if text is more than 2 characters, and if not, check if there is
- // only white space, so that this text won't be reported
- if (end - start < 3)
- {
- char_type* p = start;
- for(; p != end; ++p)
- if (!isWhiteSpace(*p))
- break;
-
- if (p == end)
- return false;
- }
-
- // set current text to the parsed text, and replace xml special characters
- core::string<char_type> s(start, (int)(end - start));
- NodeName = replaceSpecialCharacters(s);
-
- // current XML node type is text
- CurrentNodeType = EXN_TEXT;
-
- return true;
- }
-
-
-
- //! ignores an xml definition like <?xml something />
- void ignoreDefinition()
- {
- CurrentNodeType = EXN_UNKNOWN;
-
- // move until end marked with '>' reached
- while(*P != L'>')
- ++P;
-
- ++P;
- }
-
-
- //! parses a comment
- void parseComment()
- {
- CurrentNodeType = EXN_COMMENT;
- P += 1;
-
- char_type *pCommentBegin = P;
-
- int count = 1;
-
- // move until end of comment reached
- while(count)
- {
- if (*P == L'>')
- --count;
- else
- if (*P == L'<')
- ++count;
-
- ++P;
- }
-
- P -= 3;
- NodeName = core::string<char_type>(pCommentBegin+2, (int)(P - pCommentBegin-2));
- P += 3;
- }
-
-
- //! parses an opening xml element and reads attributes
- void parseOpeningXMLElement()
- {
- CurrentNodeType = EXN_ELEMENT;
- IsEmptyElement = false;
- Attributes.clear();
-
- // find name
- const char_type* startName = P;
-
- // find end of element
- while(*P != L'>' && !isWhiteSpace(*P))
- ++P;
-
- const char_type* endName = P;
-
- // find Attributes
- while(*P != L'>')
- {
- if (isWhiteSpace(*P))
- ++P;
- else
- {
- if (*P != L'/')
- {
- // we've got an attribute
-
- // read the attribute names
- const char_type* attributeNameBegin = P;
-
- while(!isWhiteSpace(*P) && *P != L'=')
- ++P;
-
- const char_type* attributeNameEnd = P;
- ++P;
-
- // read the attribute value
- // check for quotes and single quotes, thx to murphy
- while( (*P != L'\"') && (*P != L'\'') && *P)
- ++P;
-
- if (!*P) // malformatted xml file
- return;
-
- const char_type attributeQuoteChar = *P;
-
- ++P;
- const char_type* attributeValueBegin = P;
-
- while(*P != attributeQuoteChar && *P)
- ++P;
-
- if (!*P) // malformatted xml file
- return;
-
- const char_type* attributeValueEnd = P;
- ++P;
-
- SAttribute attr;
- attr.Name = core::string<char_type>(attributeNameBegin,
- (int)(attributeNameEnd - attributeNameBegin));
-
- core::string<char_type> s(attributeValueBegin,
- (int)(attributeValueEnd - attributeValueBegin));
-
- attr.Value = replaceSpecialCharacters(s);
- Attributes.push_back(attr);
- }
- else
- {
- // tag is closed directly
- ++P;
- IsEmptyElement = true;
- break;
- }
- }
- }
-
- // check if this tag is closing directly
- if (endName > startName && *(endName-1) == L'/')
- {
- // directly closing tag
- IsEmptyElement = true;
- endName--;
- }
-
- NodeName = core::string<char_type>(startName, (int)(endName - startName));
-
- ++P;
- }
-
-
- //! parses an closing xml tag
- void parseClosingXMLElement()
- {
- CurrentNodeType = EXN_ELEMENT_END;
- IsEmptyElement = false;
- Attributes.clear();
-
- ++P;
- const char_type* pBeginClose = P;
-
- while(*P != L'>')
- ++P;
-
- // remove trailing whitespace, if any
- while( isspace( P[-1]))
- --P;
-
- NodeName = core::string<char_type>(pBeginClose, (int)(P - pBeginClose));
- ++P;
- }
-
- //! parses a possible CDATA section, returns false if begin was not a CDATA section
- bool parseCDATA()
- {
- if (*(P+1) != L'[')
- return false;
-
- CurrentNodeType = EXN_CDATA;
-
- // skip '<![CDATA['
- int count=0;
- while( *P && count<8 )
- {
- ++P;
- ++count;
- }
-
- if (!*P)
- return true;
-
- char_type *cDataBegin = P;
- char_type *cDataEnd = 0;
-
- // find end of CDATA
- while(*P && !cDataEnd)
- {
- if (*P == L'>' &&
- (*(P-1) == L']') &&
- (*(P-2) == L']'))
- {
- cDataEnd = P - 2;
- }
-
- ++P;
- }
-
- if ( cDataEnd )
- NodeName = core::string<char_type>(cDataBegin, (int)(cDataEnd - cDataBegin));
- else
- NodeName = "";
-
- return true;
- }
-
-
- // structure for storing attribute-name pairs
- struct SAttribute
- {
- core::string<char_type> Name;
- core::string<char_type> Value;
- };
-
- // finds a current attribute by name, returns 0 if not found
- const SAttribute* getAttributeByName(const char_type* name) const
- {
- if (!name)
- return 0;
-
- core::string<char_type> n = name;
-
- for (int i=0; i<(int)Attributes.size(); ++i)
- if (Attributes[i].Name == n)
- return &Attributes[i];
-
- return 0;
- }
-
- // replaces xml special characters in a string and creates a new one
- core::string<char_type> replaceSpecialCharacters(
- core::string<char_type>& origstr)
- {
- int pos = origstr.findFirst(L'&');
- int oldPos = 0;
-
- if (pos == -1)
- return origstr;
-
- core::string<char_type> newstr;
-
- while(pos != -1 && pos < origstr.size()-2)
- {
- // check if it is one of the special characters
-
- int specialChar = -1;
- for (int i=0; i<(int)SpecialCharacters.size(); ++i)
- {
- const char_type* p = &origstr.c_str()[pos]+1;
-
- if (equalsn(&SpecialCharacters[i][1], p, SpecialCharacters[i].size()-1))
- {
- specialChar = i;
- break;
- }
- }
-
- if (specialChar != -1)
- {
- newstr.append(origstr.subString(oldPos, pos - oldPos));
- newstr.append(SpecialCharacters[specialChar][0]);
- pos += SpecialCharacters[specialChar].size();
- }
- else
- {
- newstr.append(origstr.subString(oldPos, pos - oldPos + 1));
- pos += 1;
- }
-
- // find next &
- oldPos = pos;
- pos = origstr.findNext(L'&', pos);
- }
-
- if (oldPos < origstr.size()-1)
- newstr.append(origstr.subString(oldPos, origstr.size()-oldPos));
-
- return newstr;
- }
-
-
-
- //! reads the xml file and converts it into the wanted character format.
- bool readFile(IFileReadCallBack* callback)
- {
- int size = callback->getSize();
- size += 4; // We need two terminating 0's at the end.
- // For ASCII we need 1 0's, for UTF-16 2, for UTF-32 4.
-
- char* data8 = new char[size];
-
- if (!callback->read(data8, size-4))
- {
- delete [] data8;
- return false;
- }
-
- // add zeros at end
-
- data8[size-1] = 0;
- data8[size-2] = 0;
- data8[size-3] = 0;
- data8[size-4] = 0;
-
- char16* data16 = reinterpret_cast<char16*>(data8);
- char32* data32 = reinterpret_cast<char32*>(data8);
-
- // now we need to convert the data to the desired target format
- // based on the byte order mark.
-
- const unsigned char UTF8[] = {0xEF, 0xBB, 0xBF}; // 0xEFBBBF;
- const int UTF16_BE = 0xFFFE;
- const int UTF16_LE = 0xFEFF;
- const int UTF32_BE = 0xFFFE0000;
- const int UTF32_LE = 0x0000FEFF;
-
- // check source for all utf versions and convert to target data format
-
- if (size >= 4 && data32[0] == (char32)UTF32_BE)
- {
- // UTF-32, big endian
- SourceFormat = ETF_UTF32_BE;
- convertTextData(data32+1, data8, (size/4)); // data32+1 because we need to skip the header
- }
- else
- if (size >= 4 && data32[0] == (char32)UTF32_LE)
- {
- // UTF-32, little endian
- SourceFormat = ETF_UTF32_LE;
- convertTextData(data32+1, data8, (size/4)); // data32+1 because we need to skip the header
- }
- else
- if (size >= 2 && data16[0] == UTF16_BE)
- {
- // UTF-16, big endian
- SourceFormat = ETF_UTF16_BE;
- convertTextData(data16+1, data8, (size/2)); // data16+1 because we need to skip the header
- }
- else
- if (size >= 2 && data16[0] == UTF16_LE)
- {
- // UTF-16, little endian
- SourceFormat = ETF_UTF16_LE;
- convertTextData(data16+1, data8, (size/2)); // data16+1 because we need to skip the header
- }
- else
- if (size >= 3 && data8[0] == UTF8[0] && data8[1] == UTF8[1] && data8[2] == UTF8[2])
- {
- // UTF-8
- SourceFormat = ETF_UTF8;
- convertTextData(data8+3, data8, size); // data8+3 because we need to skip the header
- }
- else
- {
- // ASCII
- SourceFormat = ETF_ASCII;
- convertTextData(data8, data8, size);
- }
-
- return true;
- }
-
-
- //! converts the text file into the desired format.
- //! \param source: begin of the text (without byte order mark)
- //! \param pointerToStore: pointer to text data block which can be
- //! stored or deleted based on the nesessary conversion.
- //! \param sizeWithoutHeader: Text size in characters without header
- template<class src_char_type>
- void convertTextData(src_char_type* source, char* pointerToStore, int sizeWithoutHeader)
- {
- // convert little to big endian if necessary
- if (sizeof(src_char_type) > 1 &&
- isLittleEndian(TargetFormat) != isLittleEndian(SourceFormat))
- convertToLittleEndian(source);
-
- // check if conversion is necessary:
- if (sizeof(src_char_type) == sizeof(char_type))
- {
- // no need to convert
- TextBegin = (char_type*)source;
- TextData = (char_type*)pointerToStore;
- TextSize = sizeWithoutHeader;
- }
- else
- {
- // convert source into target data format.
- // TODO: implement a real conversion. This one just
- // copies bytes. This is a problem when there are
- // unicode symbols using more than one character.
-
- TextData = new char_type[sizeWithoutHeader];
-
- // MSVC debugger complains here about loss of data ...
-
-
- // FIXME - gcc complains about 'shift width larger than width of type'
- // for T == unsigned long. Avoid it by messing around volatile ..
- volatile unsigned int c = 3;
- const src_char_type cc = (src_char_type)((((uint64_t)1u << (sizeof( char_type)<<c)) - 1));
- for (int i=0; i<sizeWithoutHeader; ++i)
- TextData[i] = char_type( source[i] & cc);
-
- TextBegin = TextData;
- TextSize = sizeWithoutHeader;
-
- // delete original data because no longer needed
- delete [] pointerToStore;
- }
- }
-
- //! converts whole text buffer to little endian
- template<class src_char_type>
- void convertToLittleEndian(src_char_type* t)
- {
- if (sizeof(src_char_type) == 4)
- {
- // 32 bit
-
- while(*t)
- {
- *t = ((*t & 0xff000000) >> 24) |
- ((*t & 0x00ff0000) >> 8) |
- ((*t & 0x0000ff00) << 8) |
- ((*t & 0x000000ff) << 24);
- ++t;
- }
- }
- else
- {
- // 16 bit
-
- while(*t)
- {
- *t = (*t >> 8) | (*t << 8);
- ++t;
- }
- }
- }
-
- //! returns if a format is little endian
- inline bool isLittleEndian(ETEXT_FORMAT f)
- {
- return f == ETF_ASCII ||
- f == ETF_UTF8 ||
- f == ETF_UTF16_LE ||
- f == ETF_UTF32_LE;
- }
-
-
- //! returns true if a character is whitespace
- inline bool isWhiteSpace(char_type c)
- {
- return (c==' ' || c=='\t' || c=='\n' || c=='\r');
- }
-
-
- //! generates a list with xml special characters
- void createSpecialCharacterList()
- {
- // list of strings containing special symbols,
- // the first character is the special character,
- // the following is the symbol string without trailing &.
-
- SpecialCharacters.push_back("&amp;");
- SpecialCharacters.push_back("<lt;");
- SpecialCharacters.push_back(">gt;");
- SpecialCharacters.push_back("\"quot;");
- SpecialCharacters.push_back("'apos;");
-
- }
-
-
- //! compares the first n characters of the strings
- bool equalsn(const char_type* str1, const char_type* str2, int len)
- {
- int i;
- for(i=0; str1[i] && str2[i] && i < len; ++i)
- if (str1[i] != str2[i])
- return false;
-
- // if one (or both) of the strings was smaller then they
- // are only equal if they have the same lenght
- return (i == len) || (str1[i] == 0 && str2[i] == 0);
- }
-
-
- //! stores the target text format
- void storeTargetFormat()
- {
- // get target format. We could have done this using template specialization,
- // but VisualStudio 6 don't like it and we want to support it.
-
- switch(sizeof(char_type))
- {
- case 1:
- TargetFormat = ETF_UTF8;
- break;
- case 2:
- TargetFormat = ETF_UTF16_LE;
- break;
- case 4:
- TargetFormat = ETF_UTF32_LE;
- break;
- default:
- TargetFormat = ETF_ASCII; // should never happen.
- }
- }
-
-
- // instance variables:
-
- char_type* TextData; // data block of the text file
- char_type* P; // current point in text to parse
- char_type* TextBegin; // start of text to parse
- unsigned int TextSize; // size of text to parse in characters, not bytes
-
- EXML_NODE CurrentNodeType; // type of the currently parsed node
- ETEXT_FORMAT SourceFormat; // source format of the xml file
- ETEXT_FORMAT TargetFormat; // output format of this parser
-
- core::string<char_type> NodeName; // name of the node currently in
- core::string<char_type> EmptyString; // empty string to be returned by getSafe() methods
-
- bool IsEmptyElement; // is the currently parsed node empty?
-
- core::array< core::string<char_type> > SpecialCharacters; // see createSpecialCharacterList()
-
- core::array<SAttribute> Attributes; // attributes of current element
-
-}; // end CXMLReaderImpl
-
-
-} // end namespace
-} // end namespace
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/irrXML/heapsort.h b/src/3rdparty/assimp/contrib/irrXML/heapsort.h
deleted file mode 100644
index d0db319d0..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/heapsort.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine".
-// For conditions of distribution and use, see copyright notice in irrlicht.h
-
-#ifndef __IRR_HEAPSORT_H_INCLUDED__
-#define __IRR_HEAPSORT_H_INCLUDED__
-
-#include "irrTypes.h"
-
-namespace irr
-{
-namespace core
-{
-
-//! Sinks an element into the heap.
-template<class T>
-inline void heapsink(T*array, s32 element, s32 max)
-{
- while ((element<<1) < max) // there is a left child
- {
- s32 j = (element<<1);
-
- if (j+1 < max && array[j] < array[j+1])
- j = j+1; // take right child
-
- if (array[element] < array[j])
- {
- T t = array[j]; // swap elements
- array[j] = array[element];
- array[element] = t;
- element = j;
- }
- else
- return;
- }
-}
-
-
-//! Sorts an array with size 'size' using heapsort.
-template<class T>
-inline void heapsort(T* array_, s32 size)
-{
- // for heapsink we pretent this is not c++, where
- // arrays start with index 0. So we decrease the array pointer,
- // the maximum always +2 and the element always +1
-
- T* virtualArray = array_ - 1;
- s32 virtualSize = size + 2;
- s32 i;
-
- // build heap
-
- for (i=((size-1)/2); i>=0; --i)
- heapsink(virtualArray, i+1, virtualSize-1);
-
- // sort array
-
- for (i=size-1; i>=0; --i)
- {
- T t = array_[0];
- array_[0] = array_[i];
- array_[i] = t;
- heapsink(virtualArray, 1, i + 1);
- }
-}
-
-} // end namespace core
-} // end namespace irr
-
-
-
-#endif
-
diff --git a/src/3rdparty/assimp/contrib/irrXML/irrArray.h b/src/3rdparty/assimp/contrib/irrXML/irrArray.h
deleted file mode 100644
index 40c822590..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/irrArray.h
+++ /dev/null
@@ -1,444 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine" and the "irrXML" project.
-// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
-
-#ifndef __IRR_ARRAY_H_INCLUDED__
-#define __IRR_ARRAY_H_INCLUDED__
-
-#include "irrTypes.h"
-#include "heapsort.h"
-
-namespace irr
-{
-namespace core
-{
-
-//! Self reallocating template array (like stl vector) with additional features.
-/** Some features are: Heap sorting, binary search methods, easier debugging.
-*/
-template <class T>
-class array
-{
-
-public:
-
- array()
- : data(0), allocated(0), used(0),
- free_when_destroyed(true), is_sorted(true)
- {
- }
-
- //! Constructs a array and allocates an initial chunk of memory.
- //! \param start_count: Amount of elements to allocate.
- array(u32 start_count)
- : data(0), allocated(0), used(0),
- free_when_destroyed(true), is_sorted(true)
- {
- reallocate(start_count);
- }
-
-
- //! Copy constructor
- array(const array<T>& other)
- : data(0)
- {
- *this = other;
- }
-
-
-
- //! Destructor. Frees allocated memory, if set_free_when_destroyed
- //! was not set to false by the user before.
- ~array()
- {
- if (free_when_destroyed)
- delete [] data;
- }
-
-
-
- //! Reallocates the array, make it bigger or smaller.
- //! \param new_size: New size of array.
- void reallocate(u32 new_size)
- {
- T* old_data = data;
-
- data = new T[new_size];
- allocated = new_size;
-
- s32 end = used < new_size ? used : new_size;
- for (s32 i=0; i<end; ++i)
- data[i] = old_data[i];
-
- if (allocated < used)
- used = allocated;
-
- delete [] old_data;
- }
-
- //! Adds an element at back of array. If the array is to small to
- //! add this new element, the array is made bigger.
- //! \param element: Element to add at the back of the array.
- void push_back(const T& element)
- {
- if (used + 1 > allocated)
- {
- // reallocate(used * 2 +1);
- // this doesn't work if the element is in the same array. So
- // we'll copy the element first to be sure we'll get no data
- // corruption
-
- T e;
- e = element; // copy element
- reallocate(used * 2 +1); // increase data block
- data[used++] = e; // push_back
- is_sorted = false;
- return;
- }
-
- data[used++] = element;
- is_sorted = false;
- }
-
-
- //! Adds an element at the front of the array. If the array is to small to
- //! add this new element, the array is made bigger. Please note that this
- //! is slow, because the whole array needs to be copied for this.
- //! \param element: Element to add at the back of the array.
- void push_front(const T& element)
- {
- if (used + 1 > allocated)
- reallocate(used * 2 +1);
-
- for (int i=(int)used; i>0; --i)
- data[i] = data[i-1];
-
- data[0] = element;
- is_sorted = false;
- ++used;
- }
-
-
- //! Insert item into array at specified position. Please use this
- //! only if you know what you are doing (possible performance loss).
- //! The preferred method of adding elements should be push_back().
- //! \param element: Element to be inserted
- //! \param index: Where position to insert the new element.
- void insert(const T& element, u32 index=0)
- {
- _IRR_DEBUG_BREAK_IF(index>used) // access violation
-
- if (used + 1 > allocated)
- reallocate(used * 2 +1);
-
- for (u32 i=used++; i>index; i--)
- data[i] = data[i-1];
-
- data[index] = element;
- is_sorted = false;
- }
-
-
-
-
- //! Clears the array and deletes all allocated memory.
- void clear()
- {
- delete [] data;
- data = 0;
- used = 0;
- allocated = 0;
- is_sorted = true;
- }
-
-
-
- //! Sets pointer to new array, using this as new workspace.
- //! \param newPointer: Pointer to new array of elements.
- //! \param size: Size of the new array.
- void set_pointer(T* newPointer, u32 size)
- {
- delete [] data;
- data = newPointer;
- allocated = size;
- used = size;
- is_sorted = false;
- }
-
-
-
- //! Sets if the array should delete the memory it used.
- //! \param f: If true, the array frees the allocated memory in its
- //! destructor, otherwise not. The default is true.
- void set_free_when_destroyed(bool f)
- {
- free_when_destroyed = f;
- }
-
-
-
- //! Sets the size of the array.
- //! \param usedNow: Amount of elements now used.
- void set_used(u32 usedNow)
- {
- if (allocated < usedNow)
- reallocate(usedNow);
-
- used = usedNow;
- }
-
-
-
- //! Assignement operator
- void operator=(const array<T>& other)
- {
- if (data)
- delete [] data;
-
- //if (allocated < other.allocated)
- if (other.allocated == 0)
- data = 0;
- else
- data = new T[other.allocated];
-
- used = other.used;
- free_when_destroyed = other.free_when_destroyed;
- is_sorted = other.is_sorted;
- allocated = other.allocated;
-
- for (u32 i=0; i<other.used; ++i)
- data[i] = other.data[i];
- }
-
-
- //! Direct access operator
- T& operator [](u32 index)
- {
- _IRR_DEBUG_BREAK_IF(index>=used) // access violation
-
- return data[index];
- }
-
-
-
- //! Direct access operator
- const T& operator [](u32 index) const
- {
- _IRR_DEBUG_BREAK_IF(index>=used) // access violation
-
- return data[index];
- }
-
- //! Gets last frame
- const T& getLast() const
- {
- _IRR_DEBUG_BREAK_IF(!used) // access violation
-
- return data[used-1];
- }
-
- //! Gets last frame
- T& getLast()
- {
- _IRR_DEBUG_BREAK_IF(!used) // access violation
-
- return data[used-1];
- }
-
-
- //! Returns a pointer to the array.
- //! \return Pointer to the array.
- T* pointer()
- {
- return data;
- }
-
-
-
- //! Returns a const pointer to the array.
- //! \return Pointer to the array.
- const T* const_pointer() const
- {
- return data;
- }
-
-
-
- //! Returns size of used array.
- //! \return Size of elements in the array.
- u32 size() const
- {
- return used;
- }
-
-
-
- //! Returns amount memory allocated.
- //! \return Returns amount of memory allocated. The amount of bytes
- //! allocated would be allocated_size() * sizeof(ElementsUsed);
- u32 allocated_size() const
- {
- return allocated;
- }
-
-
-
- //! Returns true if array is empty
- //! \return True if the array is empty, false if not.
- bool empty() const
- {
- return used == 0;
- }
-
-
-
- //! Sorts the array using heapsort. There is no additional memory waste and
- //! the algorithm performs (O) n log n in worst case.
- void sort()
- {
- if (is_sorted || used<2)
- return;
-
- heapsort(data, used);
- is_sorted = true;
- }
-
-
-
- //! Performs a binary search for an element, returns -1 if not found.
- //! The array will be sorted before the binary search if it is not
- //! already sorted.
- //! \param element: Element to search for.
- //! \return Returns position of the searched element if it was found,
- //! otherwise -1 is returned.
- s32 binary_search(const T& element)
- {
- return binary_search(element, 0, used-1);
- }
-
-
-
- //! Performs a binary search for an element, returns -1 if not found.
- //! The array will be sorted before the binary search if it is not
- //! already sorted.
- //! \param element: Element to search for.
- //! \param left: First left index
- //! \param right: Last right index.
- //! \return Returns position of the searched element if it was found,
- //! otherwise -1 is returned.
- s32 binary_search(const T& element, s32 left, s32 right)
- {
- if (!used)
- return -1;
-
- sort();
-
- s32 m;
-
- do
- {
- m = (left+right)>>1;
-
- if (element < data[m])
- right = m - 1;
- else
- left = m + 1;
-
- } while((element < data[m] || data[m] < element) && left<=right);
-
- // this last line equals to:
- // " while((element != array[m]) && left<=right);"
- // but we only want to use the '<' operator.
- // the same in next line, it is "(element == array[m])"
-
- if (!(element < data[m]) && !(data[m] < element))
- return m;
-
- return -1;
- }
-
-
- //! Finds an element in linear time, which is very slow. Use
- //! binary_search for faster finding. Only works if =operator is implemented.
- //! \param element: Element to search for.
- //! \return Returns position of the searched element if it was found,
- //! otherwise -1 is returned.
- s32 linear_search(T& element)
- {
- for (u32 i=0; i<used; ++i)
- if (!(element < data[i]) && !(data[i] < element))
- return (s32)i;
-
- return -1;
- }
-
-
- //! Finds an element in linear time, which is very slow. Use
- //! binary_search for faster finding. Only works if =operator is implemented.
- //! \param element: Element to search for.
- //! \return Returns position of the searched element if it was found,
- //! otherwise -1 is returned.
- s32 linear_reverse_search(T& element)
- {
- for (s32 i=used-1; i>=0; --i)
- if (data[i] == element)
- return (s32)i;
-
- return -1;
- }
-
-
-
- //! Erases an element from the array. May be slow, because all elements
- //! following after the erased element have to be copied.
- //! \param index: Index of element to be erased.
- void erase(u32 index)
- {
- _IRR_DEBUG_BREAK_IF(index>=used || index<0) // access violation
-
- for (u32 i=index+1; i<used; ++i)
- data[i-1] = data[i];
-
- --used;
- }
-
-
- //! Erases some elements from the array. may be slow, because all elements
- //! following after the erased element have to be copied.
- //! \param index: Index of the first element to be erased.
- //! \param count: Amount of elements to be erased.
- void erase(u32 index, s32 count)
- {
- _IRR_DEBUG_BREAK_IF(index>=used || index<0 || count<1 || index+count>used) // access violation
-
- for (u32 i=index+count; i<used; ++i)
- data[i-count] = data[i];
-
- used-= count;
- }
-
-
- //! Sets if the array is sorted
- void set_sorted(bool _is_sorted)
- {
- is_sorted = _is_sorted;
- }
-
-
- private:
-
- T* data;
- u32 allocated;
- u32 used;
- bool free_when_destroyed;
- bool is_sorted;
-};
-
-
-} // end namespace core
-} // end namespace irr
-
-
-
-#endif
-
diff --git a/src/3rdparty/assimp/contrib/irrXML/irrString.h b/src/3rdparty/assimp/contrib/irrXML/irrString.h
deleted file mode 100644
index af21b8e51..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/irrString.h
+++ /dev/null
@@ -1,664 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine" and the "irrXML" project.
-// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
-
-#ifndef __IRR_STRING_H_INCLUDED__
-#define __IRR_STRING_H_INCLUDED__
-
-#include "irrTypes.h"
-
-namespace irr
-{
-namespace core
-{
-
-//! Very simple string class with some useful features.
-/** string<c8> and string<wchar_t> work both with unicode AND ascii,
-so you can assign unicode to string<c8> and ascii to string<wchar_t>
-(and the other way round) if your ever would want to.
-Note that the conversation between both is not done using an encoding.
-
-Known bugs:
-Special characters like 'Ä', 'Ü' and 'Ö' are ignored in the
-methods make_upper, make_lower and equals_ignore_case.
-*/
-template <class T>
-class string
-{
-public:
-
- //! Default constructor
- string()
- : array(0), allocated(1), used(1)
- {
- array = new T[1];
- array[0] = 0x0;
- }
-
-
-
- //! Constructor
- string(const string<T>& other)
- : array(0), allocated(0), used(0)
- {
- *this = other;
- }
-
-
- //! Constructs a string from an int
- string(int number)
- : array(0), allocated(0), used(0)
- {
- // store if negative and make positive
-
- bool negative = false;
- if (number < 0)
- {
- number *= -1;
- negative = true;
- }
-
- // temporary buffer for 16 numbers
-
- c8 tmpbuf[16];
- tmpbuf[15] = 0;
- s32 idx = 15;
-
- // special case '0'
-
- if (!number)
- {
- tmpbuf[14] = '0';
- *this = &tmpbuf[14];
- return;
- }
-
- // add numbers
-
- while(number && idx)
- {
- idx--;
- tmpbuf[idx] = (c8)('0' + (number % 10));
- number = number / 10;
- }
-
- // add sign
-
- if (negative)
- {
- idx--;
- tmpbuf[idx] = '-';
- }
-
- *this = &tmpbuf[idx];
- }
-
-
-
- //! Constructor for copying a string from a pointer with a given lenght
- template <class B>
- string(const B* c, s32 lenght)
- : array(0), allocated(0), used(0)
- {
- if (!c)
- return;
-
- allocated = used = lenght+1;
- array = new T[used];
-
- for (s32 l = 0; l<lenght; ++l)
- array[l] = (T)c[l];
-
- array[lenght] = 0;
- }
-
-
-
- //! Constructor for unicode and ascii strings
- template <class B>
- string(const B* c)
- : array(0),allocated(0), used(0)
- {
- *this = c;
- }
-
-
-
- //! destructor
- ~string()
- {
- delete [] array;
- }
-
-
-
- //! Assignment operator
- string<T>& operator=(const string<T>& other)
- {
- if (this == &other)
- return *this;
-
- delete [] array;
- allocated = used = other.size()+1;
- array = new T[used];
-
- const T* p = other.c_str();
- for (s32 i=0; i<used; ++i, ++p)
- array[i] = *p;
-
- return *this;
- }
-
-
-
- //! Assignment operator for strings, ascii and unicode
- template <class B>
- string<T>& operator=(const B* c)
- {
- if (!c)
- {
- if (!array)
- {
- array = new T[1];
- allocated = 1;
- used = 1;
- }
- array[0] = 0x0;
- return *this;
- }
-
- if ((void*)c == (void*)array)
- return *this;
-
- s32 len = 0;
- const B* p = c;
- while(*p)
- {
- ++len;
- ++p;
- }
-
- // we'll take the old string for a while, because the new string could be
- // a part of the current string.
- T* oldArray = array;
-
- allocated = used = len+1;
- array = new T[used];
-
- for (s32 l = 0; l<len+1; ++l)
- array[l] = (T)c[l];
-
- delete [] oldArray;
- return *this;
- }
-
- //! Add operator for other strings
- string<T> operator+(const string<T>& other)
- {
- string<T> str(*this);
- str.append(other);
-
- return str;
- }
-
- //! Add operator for strings, ascii and unicode
- template <class B>
- string<T> operator+(const B* c)
- {
- string<T> str(*this);
- str.append(c);
-
- return str;
- }
-
-
-
- //! Direct access operator
- T& operator [](const s32 index) const
- {
- _IRR_DEBUG_BREAK_IF(index>=used) // bad index
-
- return array[index];
- }
-
-
- //! Comparison operator
- bool operator ==(const T* str) const
- {
- int i;
- for(i=0; array[i] && str[i]; ++i)
- if (array[i] != str[i])
- return false;
-
- return !array[i] && !str[i];
- }
-
-
-
- //! Comparison operator
- bool operator ==(const string<T>& other) const
- {
- for(s32 i=0; array[i] && other.array[i]; ++i)
- if (array[i] != other.array[i])
- return false;
-
- return used == other.used;
- }
-
-
-
- //! Is smaller operator
- bool operator <(const string<T>& other) const
- {
- for(s32 i=0; array[i] && other.array[i]; ++i)
- if (array[i] != other.array[i])
- return (array[i] < other.array[i]);
-
- return used < other.used;
- }
-
-
-
- //! Equals not operator
- bool operator !=(const string<T>& other) const
- {
- return !(*this == other);
- }
-
-
-
- //! Returns length of string
- /** \return Returns length of the string in characters. */
- s32 size() const
- {
- return used-1;
- }
-
-
-
- //! Returns character string
- /** \return Returns pointer to C-style zero terminated string. */
- const T* c_str() const
- {
- return array;
- }
-
-
-
- //! Makes the string lower case.
- void make_lower()
- {
- const T A = (T)'A';
- const T Z = (T)'Z';
- const T diff = (T)'a' - A;
-
- for (s32 i=0; i<used; ++i)
- {
- if (array[i]>=A && array[i]<=Z)
- array[i] += diff;
- }
- }
-
-
-
- //! Makes the string upper case.
- void make_upper()
- {
- const T a = (T)'a';
- const T z = (T)'z';
- const T diff = (T)'A' - a;
-
- for (s32 i=0; i<used; ++i)
- {
- if (array[i]>=a && array[i]<=z)
- array[i] += diff;
- }
- }
-
-
-
- //! Compares the string ignoring case.
- /** \param other: Other string to compare.
- \return Returns true if the string are equal ignoring case. */
- bool equals_ignore_case(const string<T>& other) const
- {
- for(s32 i=0; array[i] && other[i]; ++i)
- if (toLower(array[i]) != toLower(other[i]))
- return false;
-
- return used == other.used;
- }
-
-
- //! compares the first n characters of the strings
- bool equalsn(const string<T>& other, int len)
- {
- int i;
- for(i=0; array[i] && other[i] && i < len; ++i)
- if (array[i] != other[i])
- return false;
-
- // if one (or both) of the strings was smaller then they
- // are only equal if they have the same lenght
- return (i == len) || (used == other.used);
- }
-
-
- //! compares the first n characters of the strings
- bool equalsn(const T* str, int len)
- {
- int i;
- for(i=0; array[i] && str[i] && i < len; ++i)
- if (array[i] != str[i])
- return false;
-
- // if one (or both) of the strings was smaller then they
- // are only equal if they have the same lenght
- return (i == len) || (array[i] == 0 && str[i] == 0);
- }
-
-
- //! Appends a character to this string
- /** \param character: Character to append. */
- void append(T character)
- {
- if (used + 1 > allocated)
- reallocate((s32)used + 1);
-
- used += 1;
-
- array[used-2] = character;
- array[used-1] = 0;
- }
-
- //! Appends a string to this string
- /** \param other: String to append. */
- void append(const string<T>& other)
- {
- --used;
-
- s32 len = other.size();
-
- if (used + len + 1 > allocated)
- reallocate((s32)used + (s32)len + 1);
-
- for (s32 l=0; l<len+1; ++l)
- array[l+used] = other[l];
-
- used = used + len + 1;
- }
-
-
- //! Appends a string of the length l to this string.
- /** \param other: other String to append to this string.
- \param length: How much characters of the other string to add to this one. */
- void append(const string<T>& other, s32 length)
- {
- s32 len = other.size();
-
- if (len < length)
- {
- append(other);
- return;
- }
-
- len = length;
- --used;
-
- if (used + len > allocated)
- reallocate((s32)used + (s32)len);
-
- for (s32 l=0; l<len; ++l)
- array[l+used] = other[l];
-
- used = used + len;
- }
-
-
- //! Reserves some memory.
- /** \param count: Amount of characters to reserve. */
- void reserve(s32 count)
- {
- if (count < allocated)
- return;
-
- reallocate(count);
- }
-
-
- //! finds first occurrence of character in string
- /** \param c: Character to search for.
- \return Returns position where the character has been found,
- or -1 if not found. */
- s32 findFirst(T c) const
- {
- for (s32 i=0; i<used; ++i)
- if (array[i] == c)
- return i;
-
- return -1;
- }
-
- //! finds first occurrence of a character of a list in string
- /** \param c: List of strings to find. For example if the method
- should find the first occurance of 'a' or 'b', this parameter should be "ab".
- \param count: Amount of characters in the list. Ususally,
- this should be strlen(ofParameter1)
- \return Returns position where one of the character has been found,
- or -1 if not found. */
- s32 findFirstChar(T* c, int count) const
- {
- for (s32 i=0; i<used; ++i)
- for (int j=0; j<count; ++j)
- if (array[i] == c[j])
- return i;
-
- return -1;
- }
-
-
- //! Finds first position of a character not in a given list.
- /** \param c: List of characters not to find. For example if the method
- should find the first occurance of a character not 'a' or 'b', this parameter should be "ab".
- \param count: Amount of characters in the list. Ususally,
- this should be strlen(ofParameter1)
- \return Returns position where the character has been found,
- or -1 if not found. */
- template <class B>
- s32 findFirstCharNotInList(B* c, int count) const
- {
- for (int i=0; i<used; ++i)
- {
- int j;
- for (j=0; j<count; ++j)
- if (array[i] == c[j])
- break;
-
- if (j==count)
- return i;
- }
-
- return -1;
- }
-
- //! Finds last position of a character not in a given list.
- /** \param c: List of characters not to find. For example if the method
- should find the first occurance of a character not 'a' or 'b', this parameter should be "ab".
- \param count: Amount of characters in the list. Ususally,
- this should be strlen(ofParameter1)
- \return Returns position where the character has been found,
- or -1 if not found. */
- template <class B>
- s32 findLastCharNotInList(B* c, int count) const
- {
- for (int i=used-2; i>=0; --i)
- {
- int j;
- for (j=0; j<count; ++j)
- if (array[i] == c[j])
- break;
-
- if (j==count)
- return i;
- }
-
- return -1;
- }
-
- //! finds next occurrence of character in string
- /** \param c: Character to search for.
- \param startPos: Position in string to start searching.
- \return Returns position where the character has been found,
- or -1 if not found. */
- s32 findNext(T c, s32 startPos) const
- {
- for (s32 i=startPos; i<used; ++i)
- if (array[i] == c)
- return i;
-
- return -1;
- }
-
-
- //! finds last occurrence of character in string
- //! \param c: Character to search for.
- //! \return Returns position where the character has been found,
- //! or -1 if not found.
- s32 findLast(T c) const
- {
- for (s32 i=used-1; i>=0; --i)
- if (array[i] == c)
- return i;
-
- return -1;
- }
-
-
- //! Returns a substring
- //! \param begin: Start of substring.
- //! \param length: Length of substring.
- string<T> subString(s32 begin, s32 length)
- {
- if (length <= 0)
- return string<T>("");
-
- string<T> o;
- o.reserve(length+1);
-
- for (s32 i=0; i<length; ++i)
- o.array[i] = array[i+begin];
-
- o.array[length] = 0;
- o.used = o.allocated;
-
- return o;
- }
-
-
- void operator += (T c)
- {
- append(c);
- }
-
- void operator += (const string<T>& other)
- {
- append(other);
- }
-
- void operator += (int i)
- {
- append(string<T>(i));
- }
-
- //! replaces all characters of a special type with another one
- void replace(T toReplace, T replaceWith)
- {
- for (s32 i=0; i<used; ++i)
- if (array[i] == toReplace)
- array[i] = replaceWith;
- }
-
- //! trims the string.
- /** Removes whitespace from begin and end of the string. */
- void trim()
- {
- const char whitespace[] = " \t\n";
- const int whitespacecount = 3;
-
- // find start and end of real string without whitespace
- int begin = findFirstCharNotInList(whitespace, whitespacecount);
- if (begin == -1)
- return;
-
- int end = findLastCharNotInList(whitespace, whitespacecount);
- if (end == -1)
- return;
-
- *this = subString(begin, (end +1) - begin);
- }
-
-
- //! Erases a character from the string. May be slow, because all elements
- //! following after the erased element have to be copied.
- //! \param index: Index of element to be erased.
- void erase(int index)
- {
- _IRR_DEBUG_BREAK_IF(index>=used || index<0) // access violation
-
- for (int i=index+1; i<used; ++i)
- array[i-1] = array[i];
-
- --used;
- }
-
-
-
-private:
-
- //! Returns a character converted to lower case
- T toLower(const T& t) const
- {
- if (t>=(T)'A' && t<=(T)'Z')
- return t + ((T)'a' - (T)'A');
- else
- return t;
- }
-
- //! Reallocate the array, make it bigger or smaler
- void reallocate(s32 new_size)
- {
- T* old_array = array;
-
- array = new T[new_size];
- allocated = new_size;
-
- s32 amount = used < new_size ? used : new_size;
- for (s32 i=0; i<amount; ++i)
- array[i] = old_array[i];
-
- if (allocated < used)
- used = allocated;
-
- delete [] old_array;
- }
-
-
- //--- member variables
-
- T* array;
- s32 allocated;
- s32 used;
-};
-
-
-//! Typedef for character strings
-typedef string<irr::c8> stringc;
-
-//! Typedef for wide character strings
-typedef string<wchar_t> stringw;
-
-} // end namespace core
-} // end namespace irr
-
-#endif
-
diff --git a/src/3rdparty/assimp/contrib/irrXML/irrTypes.h b/src/3rdparty/assimp/contrib/irrXML/irrTypes.h
deleted file mode 100644
index a7f12ec75..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/irrTypes.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine".
-// For conditions of distribution and use, see copyright notice in irrlicht.h
-
-#ifndef __IRR_TYPES_H_INCLUDED__
-#define __IRR_TYPES_H_INCLUDED__
-
-namespace irr
-{
-
-//! 8 bit unsigned variable.
-/** This is a typedef for unsigned char, it ensures portability of the engine. */
-typedef unsigned char u8;
-
-//! 8 bit signed variable.
-/** This is a typedef for signed char, it ensures portability of the engine. */
-typedef signed char s8;
-
-//! 8 bit character variable.
-/** This is a typedef for char, it ensures portability of the engine. */
-typedef char c8;
-
-
-
-//! 16 bit unsigned variable.
-/** This is a typedef for unsigned short, it ensures portability of the engine. */
-typedef unsigned short u16;
-
-//! 16 bit signed variable.
-/** This is a typedef for signed short, it ensures portability of the engine. */
-typedef signed short s16;
-
-
-
-//! 32 bit unsigned variable.
-/** This is a typedef for unsigned int, it ensures portability of the engine. */
-typedef unsigned int u32;
-
-//! 32 bit signed variable.
-/** This is a typedef for signed int, it ensures portability of the engine. */
-typedef signed int s32;
-
-
-
-// 64 bit signed variable.
-// This is a typedef for __int64, it ensures portability of the engine.
-// This type is currently not used by the engine and not supported by compilers
-// other than Microsoft Compilers, so it is outcommented.
-//typedef __int64 s64;
-
-
-
-//! 32 bit floating point variable.
-/** This is a typedef for float, it ensures portability of the engine. */
-typedef float f32;
-
-//! 64 bit floating point variable.
-/** This is a typedef for double, it ensures portability of the engine. */
-typedef double f64;
-
-
-} // end namespace
-
-
-// define the wchar_t type if not already built in.
-#ifdef _MSC_VER
-#ifndef _WCHAR_T_DEFINED
-//! A 16 bit wide character type.
-/**
- Defines the wchar_t-type.
- In VS6, its not possible to tell
- the standard compiler to treat wchar_t as a built-in type, and
- sometimes we just don't want to include the huge stdlib.h or wchar.h,
- so we'll use this.
-*/
-typedef unsigned short wchar_t;
-#define _WCHAR_T_DEFINED
-#endif // wchar is not defined
-#endif // microsoft compiler
-
-//! define a break macro for debugging only in Win32 mode.
-// WORKAROUND (assimp): remove __asm
-#if defined(WIN32) && defined(_MSC_VER) && defined(_DEBUG)
-#if defined(_M_IX86)
-#define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) /*if (_CONDITION_) {_asm int 3}*/
-#else
-#define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
-#endif
-#else
-#define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
-#endif
-
-//! Defines a small statement to work around a microsoft compiler bug.
-/** The microsft compiler 7.0 - 7.1 has a bug:
-When you call unmanaged code that returns a bool type value of false from managed code,
-the return value may appear as true. See
-http://support.microsoft.com/default.aspx?kbid=823071 for details.
-Compiler version defines: VC6.0 : 1200, VC7.0 : 1300, VC7.1 : 1310, VC8.0 : 1400*/
-
-// WORKAROUND (assimp): remove __asm
-#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400)
-#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX /*__asm mov eax,100*/
-#else
-#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX
-#endif // _IRR_MANAGED_MARSHALLING_BUGFIX
-
-#endif // __IRR_TYPES_H_INCLUDED__
-
diff --git a/src/3rdparty/assimp/contrib/irrXML/irrXML.cpp b/src/3rdparty/assimp/contrib/irrXML/irrXML.cpp
deleted file mode 100644
index 42509b5f3..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/irrXML.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine" and the "irrXML" project.
-// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
-
-// Need to include Assimp, too. We're using Assimp's version of fast_atof
-// so we need stdint.h. But no PCH.
-
-
-#include "irrXML.h"
-#include "irrString.h"
-#include "irrArray.h"
-#include "./../../code/fast_atof.h"
-#include "CXMLReaderImpl.h"
-
-namespace irr
-{
-namespace io
-{
-
-//! Implementation of the file read callback for ordinary files
-class CFileReadCallBack : public IFileReadCallBack
-{
-public:
-
- //! construct from filename
- CFileReadCallBack(const char* filename)
- : File(0), Size(0), Close(true)
- {
- // open file
- File = fopen(filename, "rb");
-
- if (File)
- getFileSize();
- }
-
- //! construct from FILE pointer
- CFileReadCallBack(FILE* file)
- : File(file), Size(0), Close(false)
- {
- if (File)
- getFileSize();
- }
-
- //! destructor
- virtual ~CFileReadCallBack()
- {
- if (Close && File)
- fclose(File);
- }
-
- //! Reads an amount of bytes from the file.
- virtual int read(void* buffer, int sizeToRead)
- {
- if (!File)
- return 0;
-
- return (int)fread(buffer, 1, sizeToRead, File);
- }
-
- //! Returns size of file in bytes
- virtual int getSize()
- {
- return Size;
- }
-
-private:
-
- //! retrieves the file size of the open file
- void getFileSize()
- {
- fseek(File, 0, SEEK_END);
- Size = ftell(File);
- fseek(File, 0, SEEK_SET);
- }
-
- FILE* File;
- int Size;
- bool Close;
-
-}; // end class CFileReadCallBack
-
-
-
-// FACTORY FUNCTIONS:
-
-
-//! Creates an instance of an UFT-8 or ASCII character xml parser.
-IrrXMLReader* createIrrXMLReader(const char* filename)
-{
- return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
-}
-
-
-//! Creates an instance of an UFT-8 or ASCII character xml parser.
-IrrXMLReader* createIrrXMLReader(FILE* file)
-{
- return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
-}
-
-
-//! Creates an instance of an UFT-8 or ASCII character xml parser.
-IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
-{
- return new CXMLReaderImpl<char, IXMLBase>(callback, false);
-}
-
-
-//! Creates an instance of an UTF-16 xml parser.
-IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
-{
- return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
-}
-
-
-//! Creates an instance of an UTF-16 xml parser.
-IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
-{
- return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
-}
-
-
-//! Creates an instance of an UTF-16 xml parser.
-IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
-{
- return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
-}
-
-
-//! Creates an instance of an UTF-32 xml parser.
-IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
-{
- return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
-}
-
-
-//! Creates an instance of an UTF-32 xml parser.
-IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
-{
- return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
-}
-
-
-//! Creates an instance of an UTF-32 xml parser.
-IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
-{
- return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
-}
-
-
-} // end namespace io
-} // end namespace irr
diff --git a/src/3rdparty/assimp/contrib/irrXML/irrXML.h b/src/3rdparty/assimp/contrib/irrXML/irrXML.h
deleted file mode 100644
index b51ddeb54..000000000
--- a/src/3rdparty/assimp/contrib/irrXML/irrXML.h
+++ /dev/null
@@ -1,540 +0,0 @@
-// Copyright (C) 2002-2005 Nikolaus Gebhardt
-// This file is part of the "Irrlicht Engine" and the "irrXML" project.
-// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
-
-#ifndef __IRR_XML_H_INCLUDED__
-#define __IRR_XML_H_INCLUDED__
-
-#include <stdio.h>
-
-/** \mainpage irrXML 1.2 API documentation
- <div align="center"><img src="logobig.png" ></div>
-
- \section intro Introduction
-
- Welcome to the irrXML API documentation.
- Here you'll find any information you'll need to develop applications with
- irrXML. If you look for a tutorial on how to start, take a look at the \ref irrxmlexample,
- at the homepage of irrXML at <A HREF="http://xml.irrlicht3d.org" >xml.irrlicht3d.org</A>
- or into the SDK in the directory \example.
-
- irrXML is intended to be a high speed and easy-to-use XML Parser for C++, and
- this documentation is an important part of it. If you have any questions or
- suggestions, just send a email to the author of the engine, Nikolaus Gebhardt
- (niko (at) irrlicht3d.org). For more informations about this parser, see \ref history.
-
- \section features Features
-
- irrXML provides forward-only, read-only
- access to a stream of non validated XML data. It was fully implemented by
- Nikolaus Gebhardt. Its current features are:
-
- - It it fast as lighting and has very low memory usage. It was
- developed with the intention of being used in 3D games, as it already has been.
- - irrXML is very small: It only consists of 60 KB of code and can be added easily
- to your existing project.
- - Of course, it is platform independent and works with lots of compilers.
- - It is able to parse ASCII, UTF-8, UTF-16 and UTF-32 text files, both in
- little and big endian format.
- - Independent of the input file format, the parser can return all strings in ASCII, UTF-8,
- UTF-16 and UTF-32 format.
- - With its optional file access abstraction it has the advantage that it can read not
- only from files but from any type of data (memory, network, ...). For example when
- used with the Irrlicht Engine, it directly reads from compressed .zip files.
- - Just like the Irrlicht Engine for which it was originally created, it is extremely easy
- to use.
- - It has no external dependencies, it does not even need the STL.
-
- Although irrXML has some strenghts, it currently also has the following limitations:
-
- - The input xml file is not validated and assumed to be correct.
-
- \section irrxmlexample Example
-
- The following code demonstrates the basic usage of irrXML. A simple xml
- file like this is parsed:
- \code
- <?xml version="1.0"?>
- <config>
- <!-- This is a config file for the mesh viewer -->
- <model file="dwarf.dea" />
- <messageText caption="Irrlicht Engine Mesh Viewer">
- Welcome to the Mesh Viewer of the &quot;Irrlicht Engine&quot;.
- </messageText>
- </config>
- \endcode
-
- The code for parsing this file would look like this:
- \code
- #include <irrXML.h>
- using namespace irr; // irrXML is located in the namespace irr::io
- using namespace io;
-
- #include <string> // we use STL strings to store data in this example
-
- void main()
- {
- // create the reader using one of the factory functions
-
- IrrXMLReader* xml = createIrrXMLReader("config.xml");
-
- // strings for storing the data we want to get out of the file
- std::string modelFile;
- std::string messageText;
- std::string caption;
-
- // parse the file until end reached
-
- while(xml && xml->read())
- {
- switch(xml->getNodeType())
- {
- case EXN_TEXT:
- // in this xml file, the only text which occurs is the messageText
- messageText = xml->getNodeData();
- break;
- case EXN_ELEMENT:
- {
- if (!strcmp("model", xml->getNodeName()))
- modelFile = xml->getAttributeValue("file");
- else
- if (!strcmp("messageText", xml->getNodeName()))
- caption = xml->getAttributeValue("caption");
- }
- break;
- }
- }
-
- // delete the xml parser after usage
- delete xml;
- }
- \endcode
-
- \section howto How to use
-
- Simply add the source files in the /src directory of irrXML to your project. Done.
-
- \section license License
-
- The irrXML license is based on the zlib license. Basicly, this means you can do with
- irrXML whatever you want:
-
- Copyright (C) 2002-2005 Nikolaus Gebhardt
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source distribution.
-
- \section history History
-
- As lots of references in this documentation and the source show, this xml
- parser has originally been a part of the
- <A HREF="http://irrlicht.sourceforge.net" >Irrlicht Engine</A>. But because
- the parser has become very useful with the latest release, people asked for a
- separate version of it, to be able to use it in non Irrlicht projects. With
- irrXML 1.0, this has now been done.
-*/
-
-namespace irr
-{
-namespace io
-{
- //! Enumeration of all supported source text file formats
- enum ETEXT_FORMAT
- {
- //! ASCII, file without byte order mark, or not a text file
- ETF_ASCII,
-
- //! UTF-8 format
- ETF_UTF8,
-
- //! UTF-16 format, big endian
- ETF_UTF16_BE,
-
- //! UTF-16 format, little endian
- ETF_UTF16_LE,
-
- //! UTF-32 format, big endian
- ETF_UTF32_BE,
-
- //! UTF-32 format, little endian
- ETF_UTF32_LE
- };
-
-
- //! Enumeration for all xml nodes which are parsed by IrrXMLReader
- enum EXML_NODE
- {
- //! No xml node. This is usually the node if you did not read anything yet.
- EXN_NONE,
-
- //! A xml element, like <foo>
- EXN_ELEMENT,
-
- //! End of an xml element, like </foo>
- EXN_ELEMENT_END,
-
- //! Text within a xml element: <foo> this is the text. </foo>
- EXN_TEXT,
-
- //! An xml comment like &lt;!-- I am a comment --&gt; or a DTD definition.
- EXN_COMMENT,
-
- //! An xml cdata section like &lt;![CDATA[ this is some CDATA ]]&gt;
- EXN_CDATA,
-
- //! Unknown element.
- EXN_UNKNOWN
- };
-
- //! Callback class for file read abstraction.
- /** With this, it is possible to make the xml parser read in other things
- than just files. The Irrlicht engine is using this for example to
- read xml from compressed .zip files. To make the parser read in
- any other data, derive a class from this interface, implement the
- two methods to read your data and give a pointer to an instance of
- your implementation when calling createIrrXMLReader(),
- createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
- class IFileReadCallBack
- {
- public:
-
- //! virtual destructor
- virtual ~IFileReadCallBack() {};
-
- //! Reads an amount of bytes from the file.
- /** \param buffer: Pointer to buffer where to read bytes will be written to.
- \param sizeToRead: Amount of bytes to read from the file.
- \return Returns how much bytes were read. */
- virtual int read(void* buffer, int sizeToRead) = 0;
-
- //! Returns size of file in bytes
- virtual int getSize() = 0;
- };
-
- //! Empty class to be used as parent class for IrrXMLReader.
- /** If you need another class as base class for the xml reader, you can do this by creating
- the reader using for example new CXMLReaderImpl<char, YourBaseClass>(yourcallback);
- The Irrlicht Engine for example needs IUnknown as base class for every object to
- let it automaticly reference countend, hence it replaces IXMLBase with IUnknown.
- See irrXML.cpp on how this can be done in detail. */
- class IXMLBase
- {
- };
-
- //! Interface providing easy read access to a XML file.
- /** You can create an instance of this reader using one of the factory functions
- createIrrXMLReader(), createIrrXMLReaderUTF16() and createIrrXMLReaderUTF32().
- If using the parser from the Irrlicht Engine, please use IFileSystem::createXMLReader()
- instead.
- For a detailed intro how to use the parser, see \ref irrxmlexample and \ref features.
-
- The typical usage of this parser looks like this:
- \code
- #include <irrXML.h>
- using namespace irr; // irrXML is located in the namespace irr::io
- using namespace io;
-
- void main()
- {
- // create the reader using one of the factory functions
- IrrXMLReader* xml = createIrrXMLReader("config.xml");
-
- if (xml == 0)
- return; // file could not be opened
-
- // parse the file until end reached
- while(xml->read())
- {
- // based on xml->getNodeType(), do something.
- }
-
- // delete the xml parser after usage
- delete xml;
- }
- \endcode
- See \ref irrxmlexample for a more detailed example.
- */
- template<class char_type, class super_class>
- class IIrrXMLReader : public super_class
- {
- public:
-
- //! Destructor
- virtual ~IIrrXMLReader() {};
-
- //! Reads forward to the next xml node.
- /** \return Returns false, if there was no further node. */
- virtual bool read() = 0;
-
- //! Returns the type of the current XML node.
- virtual EXML_NODE getNodeType() const = 0;
-
- //! Returns attribute count of the current XML node.
- /** This is usually
- non null if the current node is EXN_ELEMENT, and the element has attributes.
- \return Returns amount of attributes of this xml node. */
- virtual int getAttributeCount() const = 0;
-
- //! Returns name of an attribute.
- /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
- \return Name of the attribute, 0 if an attribute with this index does not exist. */
- virtual const char_type* getAttributeName(int idx) const = 0;
-
- //! Returns the value of an attribute.
- /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
- \return Value of the attribute, 0 if an attribute with this index does not exist. */
- virtual const char_type* getAttributeValue(int idx) const = 0;
-
- //! Returns the value of an attribute.
- /** \param name: Name of the attribute.
- \return Value of the attribute, 0 if an attribute with this name does not exist. */
- virtual const char_type* getAttributeValue(const char_type* name) const = 0;
-
- //! Returns the value of an attribute in a safe way.
- /** Like getAttributeValue(), but does not
- return 0 if the attribute does not exist. An empty string ("") is returned then.
- \param name: Name of the attribute.
- \return Value of the attribute, and "" if an attribute with this name does not exist */
- virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
-
- //! Returns the value of an attribute as integer.
- /** \param name Name of the attribute.
- \return Value of the attribute as integer, and 0 if an attribute with this name does not exist or
- the value could not be interpreted as integer. */
- virtual int getAttributeValueAsInt(const char_type* name) const = 0;
-
- //! Returns the value of an attribute as integer.
- /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
- \return Value of the attribute as integer, and 0 if an attribute with this index does not exist or
- the value could not be interpreted as integer. */
- virtual int getAttributeValueAsInt(int idx) const = 0;
-
- //! Returns the value of an attribute as float.
- /** \param name: Name of the attribute.
- \return Value of the attribute as float, and 0 if an attribute with this name does not exist or
- the value could not be interpreted as float. */
- virtual float getAttributeValueAsFloat(const char_type* name) const = 0;
-
- //! Returns the value of an attribute as float.
- /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
- \return Value of the attribute as float, and 0 if an attribute with this index does not exist or
- the value could not be interpreted as float. */
- virtual float getAttributeValueAsFloat(int idx) const = 0;
-
- //! Returns the name of the current node.
- /** Only non null, if the node type is EXN_ELEMENT.
- \return Name of the current node or 0 if the node has no name. */
- virtual const char_type* getNodeName() const = 0;
-
- //! Returns data of the current node.
- /** Only non null if the node has some
- data and it is of type EXN_TEXT or EXN_UNKNOWN. */
- virtual const char_type* getNodeData() const = 0;
-
- //! Returns if an element is an empty element, like <foo />
- virtual bool isEmptyElement() const = 0;
-
- //! Returns format of the source xml file.
- /** It is not necessary to use
- this method because the parser will convert the input file format
- to the format wanted by the user when creating the parser. This
- method is useful to get/display additional informations. */
- virtual ETEXT_FORMAT getSourceFormat() const = 0;
-
- //! Returns format of the strings returned by the parser.
- /** This will be UTF8 for example when you created a parser with
- IrrXMLReaderUTF8() and UTF32 when it has been created using
- IrrXMLReaderUTF32. It should not be necessary to call this
- method and only exists for informational purposes. */
- virtual ETEXT_FORMAT getParserFormat() const = 0;
- };
-
-
- //! defines the utf-16 type.
- /** Not using wchar_t for this because
- wchar_t has 16 bit on windows and 32 bit on other operating systems. */
- typedef unsigned short char16;
-
- //! defines the utf-32 type.
- /** Not using wchar_t for this because
- wchar_t has 16 bit on windows and 32 bit on other operating systems. */
- typedef unsigned long char32;
-
- //! A UTF-8 or ASCII character xml parser.
- /** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser.
- The file to read can be in any format, it will be converted to UTF-8 if it is not
- in this format.
- Create an instance of this with createIrrXMLReader();
- See IIrrXMLReader for description on how to use it. */
- typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
-
- //! A UTF-16 xml parser.
- /** This means that all character data will be returned in UTF-16 by this parser.
- The file to read can be in any format, it will be converted to UTF-16 if it is not
- in this format.
- Create an instance of this with createIrrXMLReaderUTF16();
- See IIrrXMLReader for description on how to use it. */
- typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
-
- //! A UTF-32 xml parser.
- /** This means that all character data will be returned in UTF-32 by this parser.
- The file to read can be in any format, it will be converted to UTF-32 if it is not
- in this format.
- Create an instance of this with createIrrXMLReaderUTF32();
- See IIrrXMLReader for description on how to use it. */
- typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
-
-
- //! Creates an instance of an UFT-8 or ASCII character xml parser.
- /** This means that all character data will be returned in 8 bit ASCII or UTF-8.
- The file to read can be in any format, it will be converted to UTF-8 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReaderUTF8() instead.
- \param filename: Name of file to be opened.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReader* createIrrXMLReader(const char* filename);
-
- //! Creates an instance of an UFT-8 or ASCII character xml parser.
- /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
- be in any format, it will be converted to UTF-8 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReaderUTF8() instead.
- \param file: Pointer to opened file, must have been opened in binary mode, e.g.
- using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReader* createIrrXMLReader(FILE* file);
-
- //! Creates an instance of an UFT-8 or ASCII character xml parser.
- /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
- be in any format, it will be converted to UTF-8 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReaderUTF8() instead.
- \param callback: Callback for file read abstraction. Implement your own
- callback to make the xml parser read in other things than just files. See
- IFileReadCallBack for more information about this.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback);
-
- //! Creates an instance of an UFT-16 xml parser.
- /** This means that
- all character data will be returned in UTF-16. The file to read can
- be in any format, it will be converted to UTF-16 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param filename: Name of file to be opened.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename);
-
- //! Creates an instance of an UFT-16 xml parser.
- /** This means that all character data will be returned in UTF-16. The file to read can
- be in any format, it will be converted to UTF-16 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param file: Pointer to opened file, must have been opened in binary mode, e.g.
- using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file);
-
- //! Creates an instance of an UFT-16 xml parser.
- /** This means that all character data will be returned in UTF-16. The file to read can
- be in any format, it will be converted to UTF-16 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param callback: Callback for file read abstraction. Implement your own
- callback to make the xml parser read in other things than just files. See
- IFileReadCallBack for more information about this.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback);
-
-
- //! Creates an instance of an UFT-32 xml parser.
- /** This means that all character data will be returned in UTF-32. The file to read can
- be in any format, it will be converted to UTF-32 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param filename: Name of file to be opened.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename);
-
- //! Creates an instance of an UFT-32 xml parser.
- /** This means that all character data will be returned in UTF-32. The file to read can
- be in any format, it will be converted to UTF-32 if it is not in this format.
- if you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param file: Pointer to opened file, must have been opened in binary mode, e.g.
- using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file);
-
- //! Creates an instance of an UFT-32 xml parser.
- /** This means that
- all character data will be returned in UTF-32. The file to read can
- be in any format, it will be converted to UTF-32 if it is not in this format.
- If you are using the Irrlicht Engine, it is better not to use this function but
- IFileSystem::createXMLReader() instead.
- \param callback: Callback for file read abstraction. Implement your own
- callback to make the xml parser read in other things than just files. See
- IFileReadCallBack for more information about this.
- \return Returns a pointer to the created xml parser. This pointer should be
- deleted using 'delete' after no longer needed. Returns 0 if an error occured
- and the file could not be opened. */
- IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback);
-
-
- /*! \file irrxml.h
- \brief Header file of the irrXML, the Irrlicht XML parser.
-
- This file includes everything needed for using irrXML,
- the XML parser of the Irrlicht Engine. To use irrXML,
- you only need to include this file in your project:
-
- \code
- #include <irrXML.h>
- \endcode
-
- It is also common to use the two namespaces in which irrXML is included,
- directly after #including irrXML.h:
-
- \code
- #include <irrXML.h>
- using namespace irr;
- using namespace io;
- \endcode
- */
-
-} // end namespace io
-} // end namespace irr
-
-#endif // __IRR_XML_H_INCLUDED__
-
diff --git a/src/3rdparty/assimp/contrib/irrXML_note.txt b/src/3rdparty/assimp/contrib/irrXML_note.txt
deleted file mode 100644
index ff7897ec2..000000000
--- a/src/3rdparty/assimp/contrib/irrXML_note.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-
-IrrXML
-Downloaded September 2008
-
-- fixed a minor compiler warning (vs 2005, shift too large)
-- fixed an issue regarding wchar_t/unsigned short
diff --git a/src/3rdparty/assimp/contrib/openddlparser/CMakeLists.txt b/src/3rdparty/assimp/contrib/openddlparser/CMakeLists.txt
deleted file mode 100644
index 9e903ca3f..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/CMakeLists.txt
+++ /dev/null
@@ -1,170 +0,0 @@
-CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )
-PROJECT( OpenDDL-Parser )
-SET ( OPENDDL_PARSER_VERSION_MAJOR 0 )
-SET ( OPENDDL_PARSER_VERSION_MINOR 1 )
-SET ( OPENDDL_PARSER_VERSION_PATCH 0 )
-SET ( OPENDDL_PARSER_VERSION ${OPENDDL_PARSER_VERSION_MAJOR}.${OPENDDL_PARSER_VERSION_MINOR}.${OPENDDL_PARSER_VERSION_PATCH} )
-SET ( PROJECT_VERSION "${OPENDDL_PARSER_VERSION}" )
-
-option( DDL_USE_CPP11 "Set to ON to use C++11 features ( always on on windows )." ON )
-option( DDL_DEBUG_OUTPUT "Set to ON to use output debug texts" OFF )
-option( DDL_STATIC_LIBRARY "Set to ON to build static libary of OpenDDL Parser." ON )
-option( COVERALLS "Generate coveralls data" OFF )
-
-if ( DDL_USE_CPP11 )
- if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
- set( OPENDDL_CXXFLAGS -std=c++0x )
- elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- set( OPENDDL_CXXFLAGS --std=c++11 )
- endif()
-else( DDL_USE_CPP11 )
- add_definitions( -DOPENDDL_NO_USE_CPP11 )
-endif( DDL_USE_CPP11)
-
-if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
- find_package(Threads)
-else()
- add_definitions( -D_CRT_SECURE_NO_WARNINGS )
-endif()
-
-if ( DDL_STATIC_LIBRARY )
- add_definitions( -DOPENDDL_STATIC_LIBARY )
-endif()
-
-add_definitions( -DOPENDDLPARSER_BUILD )
-add_definitions( -D_VARIADIC_MAX=10 )
-add_definitions( -DGTEST_HAS_PTHREAD=0 )
-if ( DDL_DEBUG_OUTPUT )
- add_definitions( -DDDL_DEBUG_HEADER_NAME)
-endif()
-
-INCLUDE_DIRECTORIES(
- ./
- include/
- contrib/gtest-1.7.0/include
- contrib/gtest-1.7.0/
-)
-
-link_directories(
- ${CMAKE_HOME_DIRECTORY}/lib
-)
-
-set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )
-SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
-SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
-SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
-
-if( WIN32 AND NOT CYGWIN )
- set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) # Force to always compile with W4
- if( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
- string( REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
- else()
- set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" )
- endif()
-elseif( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
- # Update if necessary
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic ${OPENDDL_CXXFLAGS}")
-elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic ${OPENDDL_CXXFLAGS} -Wwrite-strings")
-endif()
-
-if (COVERALLS)
- include(Coveralls)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
-endif()
-
-# Include the doc component.
-FIND_PACKAGE( doxygen )
-IF ( DOXYGEN_FOUND )
- CONFIGURE_FILE( doc/openddlparser_doc.in doc/doxygenfile @ONLY )
- ADD_CUSTOM_TARGET( doc ALL ${DOXYGEN_EXECUTABLE} doc/doxygenfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen" VERBATIM )
-ENDIF ( DOXYGEN_FOUND )
-
-SET ( openddl_parser_src
- code/OpenDDLCommon.cpp
- code/OpenDDLExport.cpp
- code/OpenDDLParser.cpp
- code/OpenDDLStream.cpp
- code/DDLNode.cpp
- code/Value.cpp
- include/openddlparser/OpenDDLCommon.h
- include/openddlparser/OpenDDLExport.h
- include/openddlparser/OpenDDLParser.h
- include/openddlparser/OpenDDLParserUtils.h
- include/openddlparser/OpenDDLStream.h
- include/openddlparser/DDLNode.h
- include/openddlparser/Value.h
- README.md
-)
-
-SOURCE_GROUP( code FILES ${openddl_parser_src} )
-
-if ( DDL_STATIC_LIBRARY )
- ADD_LIBRARY( openddl_parser STATIC
- ${openddl_parser_src}
- )
-else()
- ADD_LIBRARY( openddl_parser SHARED
- ${openddl_parser_src}
- )
-endif()
-
-SET ( GTEST_PATH contrib/gtest-1.7.0 )
-
-SET ( gtest_src
- ${GTEST_PATH}/src/gtest-death-test.cc
- ${GTEST_PATH}/src/gtest-filepath.cc
- ${GTEST_PATH}/src/gtest-internal-inl.h
- ${GTEST_PATH}/src/gtest-port.cc
- ${GTEST_PATH}/src/gtest-printers.cc
- ${GTEST_PATH}/src/gtest-test-part.cc
- ${GTEST_PATH}/src/gtest-typed-test.cc
- ${GTEST_PATH}/src/gtest.cc
- ${GTEST_PATH}/src/gtest_main.cc
-)
-
-SET( openddl_parser_unittest_src
- test/UnitTestCommon.h
- test/DDLNodeTest.cpp
- test/OpenDDLCommonTest.cpp
- test/OpenDDLExportTest.cpp
- test/OpenDDLParserTest.cpp
- test/OpenDDLParserUtilsTest.cpp
- test/OpenDDLStreamTest.cpp
- test/OpenDDLIntegrationTest.cpp
- test/ValueTest.cpp
- test/OpenDDLDefectsTest.cpp
-)
-
-SOURCE_GROUP( code FILES ${openddl_parser_unittest_src} )
-SOURCE_GROUP( gtest FILES ${gtest_src} )
-
-ADD_EXECUTABLE( openddl_parser_unittest
- ${gtest_src}
- ${openddl_parser_unittest_src}
-)
-
-target_link_libraries( openddl_parser_unittest openddl_parser ${CMAKE_THREAD_LIBS_INIT} )
-
-SET( openddl_parser_demo_src
- demo/main.cpp
-)
-
-if (COVERALLS)
- set(COVERAGE_SRCS ${gtest_src} ${openddl_parser_unittest_src} )
-
- # Create the coveralls target.
- coveralls_setup(
- "${COVERAGE_SRCS}" # The source files.
- ON # If we should upload.
- "${PROJECT_SOURCE_DIR}/cmake/") # (Optional) Alternate project cmake module path.
-endif()
-
-ADD_EXECUTABLE( openddl_parser_demo
- ${openddl_parser_demo_src}
-)
-
-target_link_libraries( openddl_parser_demo openddl_parser )
diff --git a/src/3rdparty/assimp/contrib/openddlparser/CREDITS b/src/3rdparty/assimp/contrib/openddlparser/CREDITS
deleted file mode 100644
index d3936af83..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/CREDITS
+++ /dev/null
@@ -1,19 +0,0 @@
-===============================================================
-OpenDDL-Parser
-Developers and Contributors
-===============================================================
-
-- Kim Kulling ( kimmi ):
-Founder
-
-- Fredrik Hansson ( FredrikHson ):
-Improvements value interface, serveral bugfixes.
-
-- Henry Read ( henrya2 ):
-Static build option, Interface improvements
-
-- (wise86-android)
-fix several mem-leaks
-
-- Paul Holland ( pkholland ):
-Bugfixes.
diff --git a/src/3rdparty/assimp/contrib/openddlparser/LICENSE b/src/3rdparty/assimp/contrib/openddlparser/LICENSE
deleted file mode 100644
index 4c1476bc4..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/LICENSE
+++ /dev/null
@@ -1,22 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
diff --git a/src/3rdparty/assimp/contrib/openddlparser/README.md b/src/3rdparty/assimp/contrib/openddlparser/README.md
deleted file mode 100644
index a48ea1be0..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/README.md
+++ /dev/null
@@ -1,136 +0,0 @@
-The OpenDDL-Parser
-==================
-
-The OpenDDL-Parser is a small and easy to use library for OpenDDL-file-format-parsing. OpenDDL is the shortcut for Open Data Description Language, a data-declaration language introduced by Eric Lengyel. Please check http://openddl.org/ if you want to learn more about it.
-
-Build status
-============
-Linux build status: [![Build Status](https://travis-ci.org/kimkulling/openddl-parser.png)](https://travis-ci.org/kimkulling/openddl-parser)
-Current coverity check status:
-<a href="https://scan.coverity.com/projects/5606">
- <img alt="Coverity Scan Build Status"
- src="https://scan.coverity.com/projects/5606/badge.svg"/>
-</a>
-Current test coverage:[![Coverage Status](https://coveralls.io/repos/github/kimkulling/openddl-parser/badge.svg?branch=master)](https://coveralls.io/github/kimkulling/openddl-parser?branch=cpp_coveralls)
-Get the source code
-===================
-You can get the code from our git repository, which is located at GitHub. You can clone the repository with the following command:
-
-> git clone https://github.com/kimkulling/openddl-parser.git
-
-Building the source from the GitHub-Repo
-========================================
-To build the library you need to install cmake first ( see http://www.cmake.org/ for more information ). Make also sure that a compiler tool-chain is installed on your machine.
-After installing it you can open a console and enter:
-
-> cmake CMakeLists.txt
-
-This command will generate a build environment for your preferred build tool ( for Visual-Studio-users the project files will be generated, for gcc-users the makefiles will be generated ).
-When using an IDE open the IDE and run the build. When using GNU-make type in your console:
-
-> make
-
-and that's all.
-
-When using Visual Studio CMake will generate you a solution for ythe library. Just build it there.
-
-Use the library
-===============
-To use the OpenDDL-parser you need to build the lib first. Now add the
-> <Repo-folder>/include
-
-to your include-path and the
-
-> <Repo-folder>/lib
-
-to your lib-folder. Link the openddl.lib to your application.
-
-Here is a small example how to use the lib:
-
-```cpp
-
-#include <iostream>
-#include <cassert>
-#include <openddlparser/OpenDDLParser.h>
-
-USE_ODDLPARSER_NS;
-
-int main( int argc, char *argv[] ) {
- if( argc < 3 ) {
- return 1;
- }
-
- char *filename( nullptr );
- if( 0 == strncmp( FileOption, argv[ 1 ], strlen( FileOption ) ) ) {
- filename = argv[ 2 ];
- }
- std::cout << "file to import: " << filename << std::endl;
- if( nullptr == filename ) {
- std::cerr << "Invalid filename." << std::endl;
- return Error;
- }
-
- FILE *fileStream = fopen( filename, "r+" );
- if( NULL == filename ) {
- std::cerr << "Cannot open file " << filename << std::endl;
- return 1;
- }
-
- // obtain file size:
- fseek( fileStream, 0, SEEK_END );
- const size_t size( ftell( fileStream ) );
- rewind( fileStream );
- if( size > 0 ) {
- char *buffer = new char[ size ];
- const size_t readSize( fread( buffer, sizeof( char ), size, fileStream ) );
- assert( readSize == size );
- OpenDDLParser theParser;
- theParser.setBuffer( buffer, size );
- const bool result( theParser.parse() );
- if( !result ) {
- std::cerr << "Error while parsing file " << filename << "." << std::endl;
- }
- }
- return 0;
-}
-
-```
-
-How to access the imported data
-===============================
-The data is organized as a tree. You can get the root-node of the tree with the following code:
-
-```cpp
-OpenDDLParser theParser;
-theParser.setBuffer( buffer, size );
-const bool result( theParser.parse() );
-if ( result ) {
- DDLNode *root = theParser.getRoot();
- DDLNode::DllNodeList childs = root->getChildNodeList();
- for ( size_t i=0; i<childs.size(); i++ ) {
- DDLNode *child = childs[ i ];
- Property *prop = child->getProperty(); // to get properties
- std::string type = child->getType(); // to get the node type
- Value *values = child->getValue(); // to get the data;
-
- // to loop through all values
- while ( values != ddl_nullptr ) {
- int current = values->getInt32();
- values = value->getNext();
- }
- }
-}
-
-```
-
-The node instance called root contains the data.
-
-All data lists are organized as linked lists.
-
-Reference documentation
-=======================
-Please check http://kimkulling.github.io/openddl-parser/doxygen_html/index.html.
-
-Projects using OpenDDL-Parser
-=============================
-- Asset Importer Lib: https://github.com/assimp/assimp .
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/DDLNode.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/DDLNode.cpp
deleted file mode 100644
index a7c557fc5..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/DDLNode.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/DDLNode.h>
-#include <openddlparser/OpenDDLParser.h>
-
-#include <algorithm>
-
-BEGIN_ODDLPARSER_NS
-
-DDLNode::DllNodeList DDLNode::s_allocatedNodes;
-
-template<class T>
-inline
-static void releaseDataType( T *ptr ) {
- if( ddl_nullptr == ptr ) {
- return;
- }
-
- T *current( ddl_nullptr );
- while( ptr ) {
- current = ptr;
- ptr = ptr->m_next;
- delete current;
- }
-}
-
-static void releaseReferencedNames( Reference *ref ) {
- if( ddl_nullptr == ref ) {
- return;
- }
-
- delete ref;
-}
-
-DDLNode::DDLNode( const std::string &type, const std::string &name, size_t idx, DDLNode *parent )
-: m_type( type )
-, m_name( name )
-, m_parent( parent )
-, m_children()
-, m_properties( ddl_nullptr )
-, m_value( ddl_nullptr )
-, m_dtArrayList( ddl_nullptr )
-, m_references( ddl_nullptr )
-, m_idx( idx ) {
- if( m_parent ) {
- m_parent->m_children.push_back( this );
- }
-}
-
-DDLNode::~DDLNode() {
- delete m_properties;
- delete m_value;
- releaseReferencedNames( m_references );
-
- delete m_dtArrayList;
- m_dtArrayList = ddl_nullptr;
- if( s_allocatedNodes[ m_idx ] == this ) {
- s_allocatedNodes[ m_idx ] = ddl_nullptr;
- }
- for ( size_t i = 0; i<m_children.size(); i++ ){
- delete m_children[ i ];
- }
-}
-
-void DDLNode::attachParent( DDLNode *parent ) {
- if( m_parent == parent ) {
- return;
- }
-
- m_parent = parent;
- if( ddl_nullptr != m_parent ) {
- m_parent->m_children.push_back( this );
- }
-}
-
-void DDLNode::detachParent() {
- if( ddl_nullptr != m_parent ) {
- DDLNodeIt it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
- if( m_parent->m_children.end() != it ) {
- m_parent->m_children.erase( it );
- }
- m_parent = ddl_nullptr;
- }
-}
-
-DDLNode *DDLNode::getParent() const {
- return m_parent;
-}
-
-const DDLNode::DllNodeList &DDLNode::getChildNodeList() const {
- return m_children;
-}
-
-void DDLNode::setType( const std::string &type ) {
- m_type = type;
-}
-
-const std::string &DDLNode::getType() const {
- return m_type;
-}
-
-void DDLNode::setName( const std::string &name ) {
- m_name = name;
-}
-
-const std::string &DDLNode::getName() const {
- return m_name;
-}
-
-void DDLNode::setProperties( Property *prop ) {
- if(m_properties!=ddl_nullptr)
- delete m_properties;
- m_properties = prop;
-}
-
-Property *DDLNode::getProperties() const {
- return m_properties;
-}
-
-bool DDLNode::hasProperty( const std::string &name ) {
- const Property *prop( findPropertyByName( name ) );
- return ( ddl_nullptr != prop );
-}
-
-bool DDLNode::hasProperties() const {
- return( ddl_nullptr != m_properties );
-}
-
-Property *DDLNode::findPropertyByName( const std::string &name ) {
- if( name.empty() ) {
- return ddl_nullptr;
- }
-
- if( ddl_nullptr == m_properties ) {
- return ddl_nullptr;
- }
-
- Property *current( m_properties );
- while( ddl_nullptr != current ) {
- int res = strncmp( current->m_key->m_buffer, name.c_str(), name.size() );
- if( 0 == res ) {
- return current;
- }
- current = current->m_next;
- }
-
- return ddl_nullptr;
-}
-
-void DDLNode::setValue( Value *val ) {
- m_value = val;
-}
-
-Value *DDLNode::getValue() const {
- return m_value;
-}
-
-void DDLNode::setDataArrayList( DataArrayList *dtArrayList ) {
- m_dtArrayList = dtArrayList;
-}
-
-DataArrayList *DDLNode::getDataArrayList() const {
- return m_dtArrayList;
-}
-
-void DDLNode::setReferences( Reference *refs ) {
- m_references = refs;
-}
-
-Reference *DDLNode::getReferences() const {
- return m_references;
-}
-
-void DDLNode::dump(IOStreamBase &/*stream*/) {
- // Todo!
-}
-
-DDLNode *DDLNode::create( const std::string &type, const std::string &name, DDLNode *parent ) {
- const size_t idx( s_allocatedNodes.size() );
- DDLNode *node = new DDLNode( type, name, idx, parent );
- s_allocatedNodes.push_back( node );
-
- return node;
-}
-
-void DDLNode::releaseNodes() {
- if( s_allocatedNodes.size() > 0 ) {
- for( DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
- if( *it ) {
- delete *it;
- }
- }
- s_allocatedNodes.clear();
- }
-}
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp
deleted file mode 100644
index 5c341a780..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp
+++ /dev/null
@@ -1,212 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/OpenDDLCommon.h>
-#include <openddlparser/DDLNode.h>
-#include <openddlparser/Value.h>
-
-BEGIN_ODDLPARSER_NS
-
-Text::Text( const char *buffer, size_t numChars )
-: m_capacity( 0 )
-, m_len( 0 )
-, m_buffer( ddl_nullptr ) {
- set( buffer, numChars );
-}
-
-Text::~Text() {
- clear();
-}
-
-void Text::clear() {
- delete[] m_buffer;
- m_buffer = ddl_nullptr;
- m_capacity = 0;
- m_len = 0;
-}
-
-void Text::set( const char *buffer, size_t numChars ) {
- clear();
- if( numChars > 0 ) {
- m_len = numChars;
- m_capacity = m_len + 1;
- m_buffer = new char[ m_capacity ];
- strncpy( m_buffer, buffer, numChars );
- m_buffer[ numChars ] = '\0';
- }
-}
-
-bool Text::operator == ( const std::string &name ) const {
- if( m_len != name.size() ) {
- return false;
- }
- const int res( strncmp( m_buffer, name.c_str(), name.size() ) );
-
- return ( 0 == res );
-}
-
-bool Text::operator == ( const Text &rhs ) const {
- if( m_len != rhs.m_len ) {
- return false;
- }
-
- const int res( strncmp( m_buffer, rhs.m_buffer, m_len ) );
-
- return ( 0 == res );
-}
-
-Name::Name( NameType type, Text *id )
-: m_type( type )
-, m_id( id ) {
- // empty
-}
-
-Name::~Name() {
- delete m_id;
- m_id = ddl_nullptr;
-}
-
-Name::Name( const Name &name ){
- m_type=name.m_type;
- m_id=new Text(name.m_id->m_buffer,name.m_id->m_len);
-}
-
-
-
- Reference::Reference()
-: m_numRefs( 0 )
-, m_referencedName( ddl_nullptr ) {
- // empty
-}
-
-Reference::Reference( size_t numrefs, Name **names )
-: m_numRefs( numrefs )
-, m_referencedName( ddl_nullptr ) {
- if ( numrefs > 0 ) {
- m_referencedName = new Name *[ numrefs ];
- for ( size_t i = 0; i < numrefs; i++ ) {
- m_referencedName[ i ] = names[i];
- }
- }
-}
-Reference::Reference(const Reference &ref) {
- m_numRefs=ref.m_numRefs;
- if(m_numRefs!=0){
- m_referencedName = new Name*[m_numRefs];
- for ( size_t i = 0; i < m_numRefs; i++ ) {
- m_referencedName[i] = new Name(*ref.m_referencedName[i]);
- }
- }
-}
-
-Reference::~Reference() {
- for( size_t i = 0; i < m_numRefs; i++ ) {
- delete m_referencedName[ i ];
- }
- m_numRefs = 0;
- delete [] m_referencedName;
- m_referencedName = ddl_nullptr;
-}
-
-size_t Reference::sizeInBytes() {
- if ( 0 == m_numRefs ) {
- return 0;
- }
-
- size_t size( 0 );
- for ( size_t i = 0; i < m_numRefs; i++ ) {
- Name *name( m_referencedName[ i ] );
- if ( ddl_nullptr != name ) {
- size += name->m_id->m_len;
- }
- }
-
- return size;
-}
-
-Property::Property( Text *id )
-: m_key( id )
-, m_value( ddl_nullptr )
-, m_ref( ddl_nullptr )
-, m_next( ddl_nullptr ) {
- // empty
-}
-
-Property::~Property() {
- delete m_key;
- if(m_value!=ddl_nullptr)
- delete m_value;
- if(m_ref!=ddl_nullptr)
- delete(m_ref);
- if(m_next!=ddl_nullptr)
- delete m_next;
-}
-
-DataArrayList::DataArrayList()
-: m_numItems( 0 )
-, m_dataList( ddl_nullptr )
-, m_next( ddl_nullptr )
-, m_refs(ddl_nullptr)
-, m_numRefs(0){
- // empty
-}
-
-DataArrayList::~DataArrayList() {
- delete m_dataList;
- if(m_next!=ddl_nullptr)
- delete m_next;
- if(m_refs!=ddl_nullptr)
- delete m_refs;
-}
-
-size_t DataArrayList::size() {
- size_t result( 0 );
- if ( ddl_nullptr == m_next ) {
- if ( m_dataList != ddl_nullptr ) {
- result = 1;
- }
- return result;
- }
-
- DataArrayList *n( m_next );
- while( ddl_nullptr != n ) {
- result++;
- n = n->m_next;
- }
- return result;
-}
-
-Context::Context()
-: m_root( ddl_nullptr ) {
- // empty
-}
-
-Context::~Context() {
- clear();
-}
-
-void Context::clear() {
- delete m_root;
- m_root = ddl_nullptr;
-}
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp
deleted file mode 100644
index e45fb041a..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/OpenDDLExport.h>
-#include <openddlparser/DDLNode.h>
-#include <openddlparser/Value.h>
-#include <openddlparser/OpenDDLParser.h>
-
-#include <sstream>
-
-BEGIN_ODDLPARSER_NS
-
-struct DDLNodeIterator {
- const DDLNode::DllNodeList &m_childs;
- size_t m_idx;
-
- DDLNodeIterator( const DDLNode::DllNodeList &childs )
- : m_childs( childs )
- , m_idx( 0 ) {
- // empty
- }
-
- ~DDLNodeIterator() {
- // empty
- }
-
- bool getNext( DDLNode **node ) {
- if( m_childs.size() > (m_idx+1) ) {
- m_idx++;
- *node = m_childs[ m_idx ];
- return true;
- }
-
- return false;
- }
-
-private:
- DDLNodeIterator() ddl_no_copy;
- DDLNodeIterator &operator = ( const DDLNodeIterator & ) ddl_no_copy;
-};
-
-static void writeLineEnd( std::string &statement ) {
- statement += "\n";
-}
-
-OpenDDLExport::OpenDDLExport( IOStreamBase *stream )
-: m_stream( stream ) {
- if (ddl_nullptr == m_stream) {
- m_stream = new IOStreamBase();
- }
-}
-
-OpenDDLExport::~OpenDDLExport() {
- if (ddl_nullptr != m_stream) {
- m_stream->close();
- }
- delete m_stream;
-}
-
-bool OpenDDLExport::exportContext( Context *ctx, const std::string &filename ) {
- if( ddl_nullptr == ctx ) {
- return false;
- }
-
- DDLNode *root( ctx->m_root );
- if ( ddl_nullptr == root ) {
- return true;
- }
-
- if (!filename.empty()) {
- if (!m_stream->open( filename )) {
- return false;
- }
- }
-
- const bool retValue( handleNode( root ) );
-
- return retValue;
-}
-
-bool OpenDDLExport::handleNode( DDLNode *node ) {
- if( ddl_nullptr == node ) {
- return true;
- }
-
- const DDLNode::DllNodeList &childs = node->getChildNodeList();
- if( childs.empty() ) {
- return true;
- }
- DDLNode *current( ddl_nullptr );
- DDLNodeIterator it( childs );
- std::string statement;
- bool success( true );
- while( it.getNext( &current ) ) {
- if( ddl_nullptr != current ) {
- success |= writeNode( current, statement );
- if( !handleNode( current ) ) {
- success = false;
- }
- }
- }
-
- return success;
-}
-
-bool OpenDDLExport::writeToStream( const std::string &statement ) {
- if (ddl_nullptr == m_stream ) {
- return false;
- }
-
- if ( !statement.empty()) {
- m_stream->write( statement );
- }
-
- return true;
-}
-
-bool OpenDDLExport::writeNode( DDLNode *node, std::string &statement ) {
- writeNodeHeader( node, statement );
- if (node->hasProperties()) {
- writeProperties( node, statement );
- }
- writeLineEnd( statement );
-
- statement = "}";
- DataArrayList *al( node->getDataArrayList() );
- if ( ddl_nullptr != al ) {
- writeValueType( al->m_dataList->m_type, al->m_numItems, statement );
- writeValueArray( al, statement );
- }
- Value *v( node->getValue() );
- if (ddl_nullptr != v ) {
- writeValueType( v->m_type, 1, statement );
- statement = "{";
- writeLineEnd( statement );
- writeValue( v, statement );
- statement = "}";
- writeLineEnd( statement );
- }
- statement = "}";
- writeLineEnd( statement );
-
- writeToStream( statement );
-
- return true;
-}
-
-bool OpenDDLExport::writeNodeHeader( DDLNode *node, std::string &statement ) {
- if (ddl_nullptr == node) {
- return false;
- }
-
- statement += node->getType();
- const std::string &name( node->getName() );
- if ( !name.empty() ) {
- statement += " ";
- statement += "$";
- statement += name;
- }
-
- return true;
-}
-
-bool OpenDDLExport::writeProperties( DDLNode *node, std::string &statement ) {
- if ( ddl_nullptr == node ) {
- return false;
- }
-
- Property *prop( node->getProperties() );
- // if no properties are there, return
- if ( ddl_nullptr == prop ) {
- return true;
- }
-
- if ( ddl_nullptr != prop ) {
- // for instance (attrib = "position", bla=2)
- statement += "(";
- bool first( true );
- while ( ddl_nullptr != prop ) {
- if (!first) {
- statement += ", ";
- } else {
- first = false;
- }
- statement += std::string( prop->m_key->m_buffer );
- statement += " = ";
- writeValue( prop->m_value, statement );
- prop = prop->m_next;
- }
-
- statement += ")";
- }
-
- return true;
-}
-
-bool OpenDDLExport::writeValueType( Value::ValueType type, size_t numItems, std::string &statement ) {
- if ( Value::ddl_types_max == type) {
- return false;
- }
-
- const std::string typeStr( getTypeToken( type ) );
- statement += typeStr;
- // if we have an array to write
- if ( numItems > 1 ) {
- statement += "[";
- char buffer[ 256 ];
- ::memset( buffer, '\0', 256 * sizeof( char ) );
- sprintf( buffer, "%d", static_cast<int>( numItems ) );
- statement += buffer;
- statement += "]";
- }
-
- return true;
-}
-
-bool OpenDDLExport::writeValue( Value *val, std::string &statement ) {
- if (ddl_nullptr == val) {
- return false;
- }
-
- switch ( val->m_type ) {
- case Value::ddl_bool:
- if ( true == val->getBool() ) {
- statement += "true";
- } else {
- statement += "false";
- }
- break;
- case Value::ddl_int8:
- {
- std::stringstream stream;
- const int i = static_cast<int>( val->getInt8() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_int16:
- {
- std::stringstream stream;
- char buffer[ 256 ];
- ::memset( buffer, '\0', 256 * sizeof( char ) );
- sprintf( buffer, "%d", val->getInt16() );
- statement += buffer;
- }
- break;
- case Value::ddl_int32:
- {
- std::stringstream stream;
- char buffer[ 256 ];
- ::memset( buffer, '\0', 256 * sizeof( char ) );
- const int i = static_cast< int >( val->getInt32() );
- sprintf( buffer, "%d", i );
- statement += buffer;
- }
- break;
- case Value::ddl_int64:
- {
- std::stringstream stream;
- const int i = static_cast< int >( val->getInt64() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_unsigned_int8:
- {
- std::stringstream stream;
- const int i = static_cast< unsigned int >( val->getUnsignedInt8() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_unsigned_int16:
- {
- std::stringstream stream;
- const int i = static_cast< unsigned int >( val->getUnsignedInt16() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_unsigned_int32:
- {
- std::stringstream stream;
- const int i = static_cast< unsigned int >( val->getUnsignedInt32() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_unsigned_int64:
- {
- std::stringstream stream;
- const int i = static_cast< unsigned int >( val->getUnsignedInt64() );
- stream << i;
- statement += stream.str();
- }
- break;
- case Value::ddl_half:
- break;
- case Value::ddl_float:
- {
- std::stringstream stream;
- stream << val->getFloat();
- statement += stream.str();
- }
- break;
- case Value::ddl_double:
- {
- std::stringstream stream;
- stream << val->getDouble();
- statement += stream.str();
- }
- break;
- case Value::ddl_string:
- {
- std::stringstream stream;
- stream << val->getString();
- statement += "\"";
- statement += stream.str();
- statement += "\"";
- }
- break;
- case Value::ddl_ref:
- break;
- case Value::ddl_none:
- case Value::ddl_types_max:
- default:
- break;
- }
-
- return true;
-}
-
-bool OpenDDLExport::writeValueArray( DataArrayList *al, std::string &statement ) {
- if (ddl_nullptr == al) {
- return false;
- }
-
- if (0 == al->m_numItems) {
- return true;
- }
-
- DataArrayList *nextDataArrayList = al ;
- while (ddl_nullptr != nextDataArrayList) {
- if (ddl_nullptr != nextDataArrayList) {
- statement += "{ ";
- Value *nextValue( nextDataArrayList->m_dataList );
- size_t idx( 0 );
- while (ddl_nullptr != nextValue) {
- if (idx > 0) {
- statement += ", ";
- }
- writeValue( nextValue, statement );
- nextValue = nextValue->m_next;
- idx++;
- }
- statement += " }";
- }
- nextDataArrayList = nextDataArrayList->m_next;
- }
-
- return true;
-}
-
-END_ODDLPARSER_NS
-
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp
deleted file mode 100644
index caa281364..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp
+++ /dev/null
@@ -1,1025 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/OpenDDLParser.h>
-#include <openddlparser/OpenDDLExport.h>
-
-#include <cassert>
-#include <iostream>
-#include <sstream>
-#include <algorithm>
-#include <memory>
-#include <math.h>
-
-#ifdef _WIN32
-# include <windows.h>
-#endif // _WIN32
-
-
-BEGIN_ODDLPARSER_NS
-
-static const char *Version = "0.4.0";
-
-namespace Grammar {
- static const char *OpenBracketToken = "{";
- static const char *CloseBracketToken = "}";
- static const char *OpenPropertyToken = "(";
- static const char *ClosePropertyToken = ")";
- static const char *OpenArrayToken = "[";
- static const char *CloseArrayToken = "]";
- static const char *BoolTrue = "true";
- static const char *BoolFalse = "false";
- static const char *CommaSeparator = ",";
-
- static const char *PrimitiveTypeToken[ Value::ddl_types_max ] = {
- "bool",
- "int8",
- "int16",
- "int32",
- "int64",
- "unsigned_int8",
- "unsigned_int16",
- "unsigned_int32",
- "unsigned_int64",
- "half",
- "float",
- "double",
- "string",
- "ref"
- };
-} // Namespace Grammar
-
-const char *getTypeToken( Value::ValueType type ) {
- return Grammar::PrimitiveTypeToken[ type ];
-}
-
-static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) {
- std::stringstream stream;
- stream << "Invalid token \"" << *in << "\"" << " expected \"" << exp << "\"" << std::endl;
- std::string full( in );
- std::string part( full.substr( 0, 50 ) );
- stream << part;
- callback( ddl_error_msg, stream.str() );
-}
-
-static bool isIntegerType( Value::ValueType integerType ) {
- if( integerType != Value::ddl_int8 && integerType != Value::ddl_int16 &&
- integerType != Value::ddl_int32 && integerType != Value::ddl_int64 ) {
- return false;
- }
-
- return true;
-}
-
-static bool isUnsignedIntegerType( Value::ValueType integerType ) {
- if( integerType != Value::ddl_unsigned_int8 && integerType != Value::ddl_unsigned_int16 &&
- integerType != Value::ddl_unsigned_int32 && integerType != Value::ddl_unsigned_int64 ) {
- return false;
- }
-
- return true;
-}
-
-static DDLNode *createDDLNode( Text *id, OpenDDLParser *parser ) {
- if( ddl_nullptr == id || ddl_nullptr == parser ) {
- return ddl_nullptr;
- }
-
- const std::string type( id->m_buffer );
- DDLNode *parent( parser->top() );
- DDLNode *node = DDLNode::create( type, "", parent );
-
- return node;
-}
-
-static void logMessage( LogSeverity severity, const std::string &msg ) {
- std::string log;
- if( ddl_debug_msg == severity ) {
- log += "Debug:";
- } else if( ddl_info_msg == severity ) {
- log += "Info :";
- } else if( ddl_warn_msg == severity ) {
- log += "Warn :";
- } else if( ddl_error_msg == severity ) {
- log += "Error:";
- } else {
- log += "None :";
- }
-
- log += msg;
- std::cout << log;
-}
-
-OpenDDLParser::OpenDDLParser()
-: m_logCallback( logMessage )
-, m_buffer()
-, m_stack()
-, m_context( ddl_nullptr ) {
- // empty
-}
-
-OpenDDLParser::OpenDDLParser( const char *buffer, size_t len )
-: m_logCallback( &logMessage )
-, m_buffer()
-, m_context( ddl_nullptr ) {
- if( 0 != len ) {
- setBuffer( buffer, len );
- }
-}
-
-OpenDDLParser::~OpenDDLParser() {
- clear();
-}
-
-void OpenDDLParser::setLogCallback( logCallback callback ) {
- if( ddl_nullptr != callback ) {
- // install user-specific log callback
- m_logCallback = callback;
- } else {
- // install default log callback
- m_logCallback = &logMessage;
- }
-}
-
-OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {
- return m_logCallback;
-}
-
-void OpenDDLParser::setBuffer( const char *buffer, size_t len ) {
- clear();
- if( 0 == len ) {
- return;
- }
-
- m_buffer.resize( len );
- ::memcpy(&m_buffer[ 0 ], buffer, len );
-}
-
-void OpenDDLParser::setBuffer( const std::vector<char> &buffer ) {
- clear();
- m_buffer.resize( buffer.size() );
- std::copy( buffer.begin(), buffer.end(), m_buffer.begin() );
-}
-
-const char *OpenDDLParser::getBuffer() const {
- if( m_buffer.empty() ) {
- return ddl_nullptr;
- }
-
- return &m_buffer[ 0 ];
-}
-
-size_t OpenDDLParser::getBufferSize() const {
- return m_buffer.size();
-}
-
-void OpenDDLParser::clear() {
- m_buffer.resize( 0 );
- if( ddl_nullptr != m_context ) {
- delete m_context;
- m_context=ddl_nullptr;
- }
-
-// DDLNode::releaseNodes();
-}
-
-bool OpenDDLParser::parse() {
- if( m_buffer.empty() ) {
- return false;
- }
-
- normalizeBuffer( m_buffer );
-
- m_context = new Context;
- m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
- pushNode( m_context->m_root );
-
- // do the main parsing
- char *current( &m_buffer[ 0 ] );
- char *end( &m_buffer[m_buffer.size() - 1 ] + 1 );
- size_t pos( current - &m_buffer[ 0 ] );
- while( pos < m_buffer.size() ) {
- current = parseNextNode( current, end );
- if ( current == ddl_nullptr ) {
- return false;
- }
- pos = current - &m_buffer[ 0 ];
- }
- return true;
-}
-
-bool OpenDDLParser::exportContext( Context *ctx, const std::string &filename ) {
- if( ddl_nullptr == ctx ) {
- return false;
- }
-
- OpenDDLExport myExporter;
- return myExporter.exportContext( ctx, filename );
-}
-
-char *OpenDDLParser::parseNextNode( char *in, char *end ) {
- in = parseHeader( in, end );
- in = parseStructure( in, end );
-
- return in;
-}
-
-#ifdef DEBUG_HEADER_NAME
-static void dumpId( Identifier *id ) {
- if( ddl_nullptr != id ) {
- if ( ddl_nullptr != id->m_text.m_buffer ) {
- std::cout << id->m_text.m_buffer << std::endl;
- }
- }
-}
-#endif
-
-char *OpenDDLParser::parseHeader( char *in, char *end ) {
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- Text *id( ddl_nullptr );
- in = OpenDDLParser::parseIdentifier( in, end, &id );
-
-#ifdef DEBUG_HEADER_NAME
- dumpId( id );
-#endif // DEBUG_HEADER_NAME
-
- in = lookForNextToken( in, end );
- if( ddl_nullptr != id ) {
- // store the node
- DDLNode *node( createDDLNode( id, this ) );
- if( ddl_nullptr != node ) {
- pushNode( node );
- } else {
- std::cerr << "nullptr returned by creating DDLNode." << std::endl;
- }
- delete id;
-
- Name *name_(ddl_nullptr);
- in = OpenDDLParser::parseName(in, end, &name_);
- std::unique_ptr<Name> name(name_);
- if( ddl_nullptr != name && ddl_nullptr != node ) {
- const std::string nodeName( name->m_id->m_buffer );
- node->setName( nodeName );
- }
-
-
- std::unique_ptr<Property> first;
- in = lookForNextToken(in, end);
- if (*in == Grammar::OpenPropertyToken[0]) {
- in++;
- std::unique_ptr<Property> prop, prev;
- while (*in != Grammar::ClosePropertyToken[0] && in != end) {
- Property *prop_(ddl_nullptr);
- in = OpenDDLParser::parseProperty(in, end, &prop_);
- prop.reset(prop_);
- in = lookForNextToken(in, end);
-
- if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) {
- logInvalidTokenError(in, Grammar::ClosePropertyToken, m_logCallback);
- return ddl_nullptr;
- }
-
- if (ddl_nullptr != prop && *in != Grammar::CommaSeparator[0]) {
- if (ddl_nullptr == first) {
- first = std::move(prop);
- }
- if (ddl_nullptr != prev) {
- prev->m_next = prop.release();
- }
- prev = std::move(prop);
- }
- }
- ++in;
- }
-
- // set the properties
- if (first && ddl_nullptr != node) {
- node->setProperties(first.release());
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseStructure( char *in, char *end ) {
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- bool error( false );
- in = lookForNextToken( in, end );
- if( *in == *Grammar::OpenBracketToken) {
- // loop over all children ( data and nodes )
- do {
- in = parseStructureBody( in, end, error );
- if(in == ddl_nullptr){
- return ddl_nullptr;
- }
- } while ( *in != *Grammar::CloseBracketToken);
- ++in;
- } else {
- ++in;
- logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
- return ddl_nullptr;
- }
- in = lookForNextToken( in, end );
-
- // pop node from stack after successful parsing
- if( !error ) {
- popNode();
- }
-
- return in;
-}
-
-static void setNodeValues( DDLNode *currentNode, Value *values ) {
- if( ddl_nullptr != values ){
- if( ddl_nullptr != currentNode ) {
- currentNode->setValue( values );
- }
- }
-}
-
-static void setNodeReferences( DDLNode *currentNode, Reference *refs ) {
- if( ddl_nullptr != refs ) {
- if( ddl_nullptr != currentNode ) {
- currentNode->setReferences( refs );
- }
- }
-}
-
-static void setNodeDataArrayList( DDLNode *currentNode, DataArrayList *dtArrayList ) {
- if( ddl_nullptr != dtArrayList ) {
- if( ddl_nullptr != currentNode ) {
- currentNode->setDataArrayList( dtArrayList );
- }
- }
-}
-
-char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
- if( !isNumeric( *in ) && !isCharacter( *in ) ) {
- ++in;
- }
-
- in = lookForNextToken( in, end );
- Value::ValueType type( Value::ddl_none );
- size_t arrayLen( 0 );
- in = OpenDDLParser::parsePrimitiveDataType( in, end, type, arrayLen );
- if( Value::ddl_none != type ) {
- // parse a primitive data type
- in = lookForNextToken( in, end );
- if( *in == Grammar::OpenBracketToken[ 0 ] ) {
- Reference *refs( ddl_nullptr );
- DataArrayList *dtArrayList( ddl_nullptr );
- Value *values( ddl_nullptr );
- if( 1 == arrayLen ) {
- size_t numRefs( 0 ), numValues( 0 );
- in = parseDataList( in, end, type, &values, numValues, &refs, numRefs );
- setNodeValues( top(), values );
- setNodeReferences( top(), refs );
- } else if( arrayLen > 1 ) {
- in = parseDataArrayList( in, end, type, &dtArrayList );
- setNodeDataArrayList( top(), dtArrayList );
- } else {
- std::cerr << "0 for array is invalid." << std::endl;
- error = true;
- }
- }
-
- in = lookForNextToken( in, end );
- if( *in != '}' ) {
- logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback );
- return ddl_nullptr;
- } else {
- //in++;
- }
- } else {
- // parse a complex data type
- in = parseNextNode( in, end );
- }
-
- return in;
-}
-
-void OpenDDLParser::pushNode( DDLNode *node ) {
- if( ddl_nullptr == node ) {
- return;
- }
-
- m_stack.push_back( node );
-}
-
-DDLNode *OpenDDLParser::popNode() {
- if( m_stack.empty() ) {
- return ddl_nullptr;
- }
-
- DDLNode *topNode( top() );
- m_stack.pop_back();
- return topNode;
-}
-
-DDLNode *OpenDDLParser::top() {
- if( m_stack.empty() ) {
- return ddl_nullptr;
- }
-
- DDLNode *top( m_stack.back() );
- return top;
-}
-
-DDLNode *OpenDDLParser::getRoot() const {
- if( ddl_nullptr == m_context ) {
- return ddl_nullptr;
- }
-
- return m_context->m_root;
-}
-
-Context *OpenDDLParser::getContext() const {
- return m_context;
-}
-
-void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
- if( buffer.empty() ) {
- return;
- }
-
- std::vector<char> newBuffer;
- const size_t len( buffer.size() );
- char *end( &buffer[ len-1 ] + 1 );
- for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
- char *c( &buffer[readIdx] );
- // check for a comment
- if (isCommentOpenTag(c, end)) {
- ++readIdx;
- while (!isCommentCloseTag(&buffer[readIdx], end)) {
- ++readIdx;
- }
- ++readIdx;
- ++readIdx;
- } else if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
- newBuffer.push_back( buffer[ readIdx ] );
- } else {
- if( isComment<char>( c, end ) ) {
- ++readIdx;
- // skip the comment and the rest of the line
- while( !isEndofLine( buffer[ readIdx ] ) ) {
- ++readIdx;
- }
- }
- }
- }
- buffer = newBuffer;
-}
-
-char *OpenDDLParser::parseName( char *in, char *end, Name **name ) {
- *name = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- // ignore blanks
- in = lookForNextToken( in, end );
- if( *in != '$' && *in != '%' ) {
- return in;
- }
-
- NameType ntype( GlobalName );
- if( *in == '%' ) {
- ntype = LocalName;
- }
- in++;
- Name *currentName( ddl_nullptr );
- Text *id( ddl_nullptr );
- in = parseIdentifier( in, end, &id );
- if( id ) {
- currentName = new Name( ntype, id );
- if( currentName ) {
- *name = currentName;
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseIdentifier( char *in, char *end, Text **id ) {
- *id = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- // ignore blanks
- in = lookForNextToken( in, end );
-
- // staring with a number is forbidden
- if( isNumeric<const char>( *in ) ) {
- return in;
- }
-
- // get size of id
- size_t idLen( 0 );
- char *start( in );
- while( !isSeparator( *in ) &&
- !isNewLine( *in ) && ( in != end ) &&
- *in != Grammar::OpenPropertyToken[ 0 ] &&
- *in != Grammar::ClosePropertyToken[ 0 ] &&
- *in != '$' ) {
- ++in;
- ++idLen;
- }
-
- const size_t len( idLen );
- *id = new Text( start, len );
-
- return in;
-}
-
-char *OpenDDLParser::parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len ) {
- type = Value::ddl_none;
- len = 0;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- size_t prim_len( 0 );
- for( unsigned int i = 0; i < Value::ddl_types_max; i++ ) {
- prim_len = strlen( Grammar::PrimitiveTypeToken[ i ] );
- if( 0 == strncmp( in, Grammar::PrimitiveTypeToken[ i ], prim_len ) ) {
- type = static_cast<Value::ValueType>( i );
- break;
- }
- }
-
- if( Value::ddl_none == type ) {
- in = lookForNextToken( in, end );
- return in;
- } else {
- in += prim_len;
- }
-
- bool ok( true );
- if( *in == Grammar::OpenArrayToken[ 0 ] ) {
- ok = false;
- ++in;
- char *start( in );
- while ( in != end ) {
- ++in;
- if( *in == Grammar::CloseArrayToken[ 0 ] ) {
- len = ::atoi( start );
- ok = true;
- ++in;
- break;
- }
- }
- } else {
- len = 1;
- }
- if( !ok ) {
- type = Value::ddl_none;
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseReference( char *in, char *end, std::vector<Name*> &names ) {
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- Name *nextName( ddl_nullptr );
- in = parseName( in, end, &nextName );
- if( nextName ) {
- names.push_back( nextName );
- }
- while( Grammar::CommaSeparator[ 0 ] == *in ) {
- in = getNextSeparator( in, end );
- if( Grammar::CommaSeparator[ 0 ] == *in ) {
- in = parseName( in, end, &nextName );
- if( nextName ) {
- names.push_back( nextName );
- }
- } else {
- break;
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean ) {
- *boolean = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- char *start( in );
- size_t len( 0 );
- while( !isSeparator( *in ) && in != end ) {
- ++in;
- ++len;
- }
- ++len;
- int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) );
- if( 0 != res ) {
- res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) );
- if( 0 != res ) {
- *boolean = ddl_nullptr;
- return in;
- }
- *boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
- (*boolean)->setBool( false );
- } else {
- *boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
- (*boolean)->setBool( true );
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType ) {
- *integer = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- if( !(isIntegerType( integerType ) || isUnsignedIntegerType(integerType)) ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- char *start( in );
- while( !isSeparator( *in ) && in != end ) {
- ++in;
- }
-
- if( isNumeric( *start ) ) {
-#ifdef OPENDDL_NO_USE_CPP11
- const int64 value( atol( start ) ); // maybe not really 64bit as atoll is but exists without c++11
- const uint64 uvalue( strtoul( start,ddl_nullptr,10 ) );
-#else
- const int64 value( atoll( start ) );
- const uint64 uvalue( strtoull( start,ddl_nullptr,10 ) );
-#endif
- *integer = ValueAllocator::allocPrimData( integerType );
- switch( integerType ) {
- case Value::ddl_int8:
- ( *integer )->setInt8( (int8) value );
- break;
- case Value::ddl_int16:
- ( *integer )->setInt16( ( int16 ) value );
- break;
- case Value::ddl_int32:
- ( *integer )->setInt32( ( int32 ) value );
- break;
- case Value::ddl_int64:
- ( *integer )->setInt64( ( int64 ) value );
- break;
- case Value::ddl_unsigned_int8:
- ( *integer )->setUnsignedInt8( (uint8) uvalue );
- break;
- case Value::ddl_unsigned_int16:
- ( *integer )->setUnsignedInt16( ( uint16 ) uvalue );
- break;
- case Value::ddl_unsigned_int32:
- ( *integer )->setUnsignedInt32( ( uint32 ) uvalue );
- break;
- case Value::ddl_unsigned_int64:
- ( *integer )->setUnsignedInt64( ( uint64 ) uvalue );
- break;
- default:
- break;
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating, Value::ValueType floatType) {
- *floating = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- char *start( in );
- while( !isSeparator( *in ) && in != end ) {
- ++in;
- }
-
- // parse the float value
- bool ok( false );
- if ( isHexLiteral( start, end ) ) {
- parseHexaLiteral( start, end, floating );
- return in;
- }
-
- if( isNumeric( *start ) ) {
- ok = true;
- } else {
- if( *start == '-' ) {
- if( isNumeric( *(start+1) ) ) {
- ok = true;
- }
- }
- }
-
- if( ok ) {
- if ( floatType == Value::ddl_double ) {
- const double value( atof( start ) );
- *floating = ValueAllocator::allocPrimData( Value::ddl_double );
- ( *floating )->setDouble( value );
- } else {
- const float value( ( float ) atof( start ) );
- *floating = ValueAllocator::allocPrimData( Value::ddl_float );
- ( *floating )->setFloat( value );
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData ) {
- *stringData = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- size_t len( 0 );
- char *start( in );
- if( *start == '\"' ) {
- ++start;
- ++in;
- while( *in != '\"' && in != end ) {
- ++in;
- ++len;
- }
-
- *stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
- ::strncpy( ( char* ) ( *stringData )->m_data, start, len );
- ( *stringData )->m_data[len] = '\0';
- ++in;
- }
-
- return in;
-}
-
-static void createPropertyWithData( Text *id, Value *primData, Property **prop ) {
- if( ddl_nullptr != primData ) {
- ( *prop ) = new Property( id );
- ( *prop )->m_value = primData;
- }
-}
-
-char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
- *data = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- if( *in != '0' ) {
- return in;
- }
-
- ++in;
- if( *in != 'x' && *in != 'X' ) {
- return in;
- }
-
- ++in;
- bool ok( true );
- char *start( in );
- int pos( 0 );
- while( !isSeparator( *in ) && in != end ) {
- if( ( *in < '0' && *in > '9' ) || ( *in < 'a' && *in > 'f' ) || ( *in < 'A' && *in > 'F' ) ) {
- ok = false;
- break;
- }
- ++pos;
- ++in;
- }
-
- if( !ok ) {
- return in;
- }
-
- int value( 0 );
- while( pos > 0 ) {
- int v = hex2Decimal( *start );
- --pos;
- value = ( value << 4 ) | v;
- ++start;
- }
-
- *data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
- if( ddl_nullptr != *data ) {
- ( *data )->setUnsignedInt64( value );
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
- *prop = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- Text *id( ddl_nullptr );
- in = parseIdentifier( in, end, &id );
- if( ddl_nullptr != id ) {
- in = lookForNextToken( in, end );
- if( *in == '=' ) {
- ++in;
- in = getNextToken( in, end );
- Value *primData( ddl_nullptr );
- if( isInteger( in, end ) ) {
- in = parseIntegerLiteral( in, end, &primData );
- createPropertyWithData( id, primData, prop );
- } else if( isFloat( in, end ) ) {
- in = parseFloatingLiteral( in, end, &primData );
- createPropertyWithData( id, primData, prop );
- } else if( isStringLiteral( *in ) ) { // string data
- in = parseStringLiteral( in, end, &primData );
- createPropertyWithData( id, primData, prop );
- } else { // reference data
- std::vector<Name*> names;
- in = parseReference( in, end, names );
- if( !names.empty() ) {
- Reference *ref = new Reference( names.size(), &names[ 0 ] );
- ( *prop ) = new Property( id );
- ( *prop )->m_ref = ref;
- }
- }
- } else {
- delete id;
- }
- }
-
- return in;
-}
-
-char *OpenDDLParser::parseDataList( char *in, char *end, Value::ValueType type, Value **data,
- size_t &numValues, Reference **refs, size_t &numRefs ) {
- *data = ddl_nullptr;
- numValues = numRefs = 0;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- if( *in == '{' ) {
- ++in;
- Value *current( ddl_nullptr ), *prev( ddl_nullptr );
- while( '}' != *in ) {
- current = ddl_nullptr;
- in = lookForNextToken( in, end );
- if ( Value::ddl_ref == type ) {
- std::vector<Name*> names;
- in = parseReference( in, end, names );
- if ( !names.empty() ) {
- Reference *ref = new Reference( names.size(), &names[ 0 ] );
- *refs = ref;
- numRefs = names.size();
- }
- } else if ( Value::ddl_none == type ) {
- if (isInteger( in, end )) {
- in = parseIntegerLiteral( in, end, &current );
- } else if (isFloat( in, end )) {
- in = parseFloatingLiteral( in, end, &current );
- } else if (isStringLiteral( *in )) {
- in = parseStringLiteral( in, end, &current );
- } else if (isHexLiteral( in, end )) {
- in = parseHexaLiteral( in, end, &current );
- }
- } else {
- switch(type){
- case Value::ddl_int8:
- case Value::ddl_int16:
- case Value::ddl_int32:
- case Value::ddl_int64:
- case Value::ddl_unsigned_int8:
- case Value::ddl_unsigned_int16:
- case Value::ddl_unsigned_int32:
- case Value::ddl_unsigned_int64:
- in = parseIntegerLiteral( in, end, &current, type);
- break;
- case Value::ddl_half:
- case Value::ddl_float:
- case Value::ddl_double:
- in = parseFloatingLiteral( in, end, &current, type);
- break;
- case Value::ddl_string:
- in = parseStringLiteral( in, end, &current );
- break;
- default:
- break;
- }
- }
-
- if( ddl_nullptr != current ) {
- if( ddl_nullptr == *data ) {
- *data = current;
- prev = current;
- } else {
- prev->setNext( current );
- prev = current;
- }
- ++numValues;
- }
-
- in = getNextSeparator( in, end );
- if( ',' != *in && Grammar::CloseBracketToken[ 0 ] != *in && !isSpace( *in ) ) {
- break;
- }
- }
- ++in;
- }
-
- return in;
-}
-
-static DataArrayList *createDataArrayList( Value *currentValue, size_t numValues,
- Reference *refs, size_t numRefs ) {
- DataArrayList *dataList( new DataArrayList );
- dataList->m_dataList = currentValue;
- dataList->m_numItems = numValues;
- dataList->m_refs = refs;
- dataList->m_numRefs = numRefs;
-
- return dataList;
-}
-
-char *OpenDDLParser::parseDataArrayList( char *in, char *end,Value::ValueType type,
- DataArrayList **dataArrayList ) {
- if ( ddl_nullptr == dataArrayList ) {
- return in;
- }
-
- *dataArrayList = ddl_nullptr;
- if( ddl_nullptr == in || in == end ) {
- return in;
- }
-
- in = lookForNextToken( in, end );
- if( *in == Grammar::OpenBracketToken[ 0 ] ) {
- ++in;
- Value *currentValue( ddl_nullptr );
- Reference *refs( ddl_nullptr );
- DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr );
- do {
- size_t numRefs( 0 ), numValues( 0 );
- currentValue = ddl_nullptr;
-
- in = parseDataList( in, end, type, &currentValue, numValues, &refs, numRefs );
- if( ddl_nullptr != currentValue || 0 != numRefs ) {
- if( ddl_nullptr == prev ) {
- *dataArrayList = createDataArrayList( currentValue, numValues, refs, numRefs );
- prev = *dataArrayList;
- } else {
- currentDataList = createDataArrayList( currentValue, numValues, refs, numRefs );
- if( ddl_nullptr != prev ) {
- prev->m_next = currentDataList;
- prev = currentDataList;
- }
- }
- }
- } while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
- in = lookForNextToken( in, end );
- ++in;
- }
-
- return in;
-}
-
-const char *OpenDDLParser::getVersion() {
- return Version;
-}
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp
deleted file mode 100644
index 7ea8331bd..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/OpenDDLStream.h>
-
-BEGIN_ODDLPARSER_NS
-
-StreamFormatterBase::StreamFormatterBase() {
- // empty
-}
-
-StreamFormatterBase::~StreamFormatterBase() {
- // empty
-}
-
-std::string StreamFormatterBase::format(const std::string &statement) {
- std::string tmp(statement);
- return tmp;
-}
-
-IOStreamBase::IOStreamBase(StreamFormatterBase *formatter)
- : m_formatter(formatter)
- , m_file(ddl_nullptr) {
- if (ddl_nullptr == m_formatter) {
- m_formatter = new StreamFormatterBase;
- }
-}
-
-IOStreamBase::~IOStreamBase() {
- delete m_formatter;
- m_formatter = ddl_nullptr;
-}
-
-bool IOStreamBase::open(const std::string &name) {
- m_file = ::fopen(name.c_str(), "a");
- if (m_file == ddl_nullptr) {
- return false;
- }
-
- return true;
-}
-
-bool IOStreamBase::close() {
- if (ddl_nullptr == m_file) {
- return false;
- }
-
- ::fclose(m_file);
- m_file = ddl_nullptr;
-
- return true;
-}
-
-bool IOStreamBase::isOpen() const {
- return ( ddl_nullptr != m_file );
-}
-
-size_t IOStreamBase::read( size_t sizeToRead, std::string &statement ) {
- if (ddl_nullptr == m_file) {
- return 0;
- }
-
- statement.resize(sizeToRead);
- const size_t readBytes = ::fread( &statement[0], 1, sizeToRead, m_file );
-
- return readBytes;
-}
-
-size_t IOStreamBase::write(const std::string &statement) {
- if (ddl_nullptr == m_file) {
- return 0;
- }
- std::string formatStatement = m_formatter->format(statement);
- return ::fwrite(formatStatement.c_str(), sizeof(char), formatStatement.size(), m_file);
-}
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/code/Value.cpp b/src/3rdparty/assimp/contrib/openddlparser/code/Value.cpp
deleted file mode 100644
index b5a35e722..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/code/Value.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#include <openddlparser/Value.h>
-
-#include <iostream>
-#include <cassert>
-
-BEGIN_ODDLPARSER_NS
-
-static Value::Iterator end( ddl_nullptr );
-
-Value::Iterator::Iterator()
-: m_start( ddl_nullptr )
-, m_current( ddl_nullptr ) {
- // empty
-}
-
-Value::Iterator::Iterator( Value *start )
-: m_start( start )
-, m_current( start ) {
- // empty
-}
-
-Value::Iterator::Iterator( const Iterator &rhs )
-: m_start( rhs.m_start )
-, m_current( rhs.m_current ) {
- // empty
-}
-
-Value::Iterator::~Iterator() {
- // empty
-}
-
-bool Value::Iterator::hasNext() const {
- if( ddl_nullptr == m_current ) {
- return false;
- }
- return ( ddl_nullptr != m_current->getNext() );
-}
-
-Value *Value::Iterator::getNext() {
- if( !hasNext() ) {
- return ddl_nullptr;
- }
-
- Value *v( m_current->getNext() );
- m_current = v;
-
- return v;
-}
-
-const Value::Iterator Value::Iterator::operator++( int ) {
- if( ddl_nullptr == m_current ) {
- return end;
- }
-
- m_current = m_current->getNext();
- Iterator inst( m_current );
-
- return inst;
-}
-
-Value::Iterator &Value::Iterator::operator++( ) {
- if( ddl_nullptr == m_current ) {
- return end;
- }
-
- m_current = m_current->getNext();
-
- return *this;
-}
-
-bool Value::Iterator::operator == ( const Iterator &rhs ) const {
- return ( m_current == rhs.m_current );
-}
-
-Value *Value::Iterator::operator->( ) const {
- if(ddl_nullptr == m_current ) {
- return ddl_nullptr;
- }
- return m_current;
-}
-
-Value::Value( ValueType type )
-: m_type( type )
-, m_size( 0 )
-, m_data( ddl_nullptr )
-, m_next( ddl_nullptr ) {
- // empty
-}
-
-Value::~Value() {
- if(m_data!=ddl_nullptr) {
- if (m_type == ddl_ref ) {
- Reference *tmp = (Reference *) m_data;
- if (tmp != ddl_nullptr)
- delete tmp;
- }else
- delete[] m_data;
-
- }
- if(m_next!=ddl_nullptr)
- delete m_next;
-}
-
-void Value::setBool( bool value ) {
- assert( ddl_bool == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-bool Value::getBool() {
- assert( ddl_bool == m_type );
- return ( *m_data == 1 );
-}
-
-void Value::setInt8( int8 value ) {
- assert( ddl_int8 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-int8 Value::getInt8() {
- assert( ddl_int8 == m_type );
- return ( int8 ) ( *m_data );
-}
-
-void Value::setInt16( int16 value ) {
- assert( ddl_int16 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-int16 Value::getInt16() {
- assert( ddl_int16 == m_type );
- int16 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setInt32( int32 value ) {
- assert( ddl_int32 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-int32 Value::getInt32() {
- assert( ddl_int32 == m_type );
- int32 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setInt64( int64 value ) {
- assert( ddl_int64 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-int64 Value::getInt64() {
- assert( ddl_int64 == m_type );
- int64 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setUnsignedInt8( uint8 value ) {
- assert( ddl_unsigned_int8 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-uint8 Value::getUnsignedInt8() const {
- assert( ddl_unsigned_int8 == m_type );
- uint8 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setUnsignedInt16( uint16 value ) {
- assert( ddl_unsigned_int16 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-uint16 Value::getUnsignedInt16() const {
- assert( ddl_unsigned_int16 == m_type );
- uint16 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setUnsignedInt32( uint32 value ) {
- assert( ddl_unsigned_int32 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-uint32 Value::getUnsignedInt32() const {
- assert( ddl_unsigned_int32 == m_type );
- uint32 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setUnsignedInt64( uint64 value ) {
- assert( ddl_unsigned_int64 == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-uint64 Value::getUnsignedInt64() const {
- assert( ddl_unsigned_int64 == m_type );
- uint64 i;
- ::memcpy( &i, m_data, m_size );
- return i;
-}
-
-void Value::setFloat( float value ) {
- assert( ddl_float == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-float Value::getFloat() const {
- if( m_type == ddl_float ) {
- float v;
- ::memcpy( &v, m_data, m_size );
- return ( float ) v;
- } else {
- float tmp;
- ::memcpy( &tmp, m_data, 4 );
- return ( float ) tmp;
- }
-}
-
-void Value::setDouble( double value ) {
- assert( ddl_double == m_type );
- ::memcpy( m_data, &value, m_size );
-}
-
-double Value::getDouble() const {
- if ( m_type == ddl_double ) {
- double v;
- ::memcpy( &v, m_data, m_size );
- return ( float ) v;
- }
- else {
- double tmp;
- ::memcpy( &tmp, m_data, 4 );
- return ( double ) tmp;
- }
-}
-
-void Value::setString( const std::string &str ) {
- assert( ddl_string == m_type );
- ::memcpy( m_data, str.c_str(), str.size() );
- m_data[ str.size() ] = '\0';
-}
-
-const char *Value::getString() const {
- assert( ddl_string == m_type );
- return (const char*) m_data;
-}
-
-void Value::setRef( Reference *ref ) {
- assert( ddl_ref == m_type );
-
- if ( ddl_nullptr != ref ) {
- const size_t sizeInBytes( ref->sizeInBytes() );
- if ( sizeInBytes > 0 ) {
- if ( ddl_nullptr != m_data ) {
- delete [] m_data;
- }
-
- m_data = (unsigned char*) new Reference(*ref);
- }
- }
-}
-
-Reference *Value::getRef() const {
- assert( ddl_ref == m_type );
-
- return (Reference*) m_data;
-}
-
-void Value::dump( IOStreamBase &/*stream*/ ) {
- switch( m_type ) {
- case ddl_none:
- std::cout << "None" << std::endl;
- break;
- case ddl_bool:
- std::cout << getBool() << std::endl;
- break;
- case ddl_int8:
- std::cout << getInt8() << std::endl;
- break;
- case ddl_int16:
- std::cout << getInt16() << std::endl;
- break;
- case ddl_int32:
- std::cout << getInt32() << std::endl;
- break;
- case ddl_int64:
- std::cout << getInt64() << std::endl;
- break;
- case ddl_unsigned_int8:
- std::cout << "Not supported" << std::endl;
- break;
- case ddl_unsigned_int16:
- std::cout << "Not supported" << std::endl;
- break;
- case ddl_unsigned_int32:
- std::cout << "Not supported" << std::endl;
- break;
- case ddl_unsigned_int64:
- std::cout << "Not supported" << std::endl;
- break;
- case ddl_half:
- std::cout << "Not supported" << std::endl;
- break;
- case ddl_float:
- std::cout << getFloat() << std::endl;
- break;
- case ddl_double:
- std::cout << getDouble() << std::endl;
- break;
- case ddl_string:
- std::cout << getString() << std::endl;
- break;
- case ddl_ref:
- std::cout << "Not supported" << std::endl;
- break;
- default:
- break;
- }
-}
-
-void Value::setNext( Value *next ) {
- m_next = next;
-}
-
-Value *Value::getNext() const {
- return m_next;
-}
-
-size_t Value::size() const{
- size_t result=1;
- Value *n=m_next;
- while( n!=ddl_nullptr) {
- result++;
- n=n->m_next;
- }
- return result;
-}
-
-Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
- if( type == Value::ddl_none || Value::ddl_types_max == type ) {
- return ddl_nullptr;
- }
-
- Value *data = new Value( type );
- switch( type ) {
- case Value::ddl_bool:
- data->m_size = sizeof( bool );
- break;
- case Value::ddl_int8:
- data->m_size = sizeof( int8 );
- break;
- case Value::ddl_int16:
- data->m_size = sizeof( int16 );
- break;
- case Value::ddl_int32:
- data->m_size = sizeof( int32 );
- break;
- case Value::ddl_int64:
- data->m_size = sizeof( int64 );
- break;
- case Value::ddl_unsigned_int8:
- data->m_size = sizeof( uint8 );
- break;
- case Value::ddl_unsigned_int16:
- data->m_size = sizeof( uint16 );
- break;
- case Value::ddl_unsigned_int32:
- data->m_size = sizeof( uint32 );
- break;
- case Value::ddl_unsigned_int64:
- data->m_size = sizeof( uint64 );
- break;
- case Value::ddl_half:
- data->m_size = sizeof( short );
- break;
- case Value::ddl_float:
- data->m_size = sizeof( float );
- break;
- case Value::ddl_double:
- data->m_size = sizeof( double );
- break;
- case Value::ddl_string:
- data->m_size = sizeof( char )*(len+1);
- break;
- case Value::ddl_ref:
- data->m_size = 0;
- break;
- case Value::ddl_none:
- case Value::ddl_types_max:
- default:
- break;
- }
-
- if( data->m_size ) {
- data->m_data = new unsigned char[ data->m_size ];
- ::memset(data->m_data,0,data->m_size);
- }
-
- return data;
-}
-
-void ValueAllocator::releasePrimData( Value **data ) {
- if( !data ) {
- return;
- }
-
- delete *data;
- *data = ddl_nullptr;
-}
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/DDLNode.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/DDLNode.h
deleted file mode 100644
index 915bd3041..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/DDLNode.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-
-#include <vector>
-#include <string>
-
-BEGIN_ODDLPARSER_NS
-
-// Forward declarations
-class IOStreamBase;
-class Value;
-class OpenDDLParser;
-
-struct Identifier;
-struct Reference;
-struct Property;
-struct DataArrayList;
-
-///
-/// @ingroup OpenDDLParser
-/// @brief This class represents one single instance in the object tree of the parsed OpenDDL-file.
-///
-/// A DDLNode represents one leaf in the OpenDDL-node tree. It can have one parent node and multiple children.
-/// You can assign special properties to a single DDLNode instance.
-/// A node instance can store values via a linked list. You can get the first value from the DDLNode.
-/// A node can store data-array-lists and references as well.
-///
-class DLL_ODDLPARSER_EXPORT DDLNode {
-public:
- friend class OpenDDLParser;
-
- /// @brief The child-node-list type.
- typedef std::vector<DDLNode*> DllNodeList;
-
- /// @brief The child-node-list iterator.
- typedef std::vector<DDLNode*>::iterator DDLNodeIt;
-
-public:
- /// @brief The class destructor.
- ~DDLNode();
-
- /// @brief Will attach a parent node instance, an older one will be released.
- /// @param parent [in] The parent node instance.
- void attachParent( DDLNode *parent );
-
- /// @brief Will try to detach a parent node instance, if there is any.
- void detachParent();
-
- /// @brief Returns the assigned parent node instance, will return ddl_nullptr id no parent is assigned.
- /// @return The parent node instance.
- DDLNode *getParent() const;
-
- /// @brief Returns the child node list.
- /// @return The list of child nodes.
- const DllNodeList &getChildNodeList() const;
-
- /// Set the type of the DDLNode instance.
- /// @param type [in] The type.
- void setType( const std::string &type );
-
- /// @brief Returns the type of the DDLNode instance.
- /// @return The type of the DDLNode instance.
- const std::string &getType() const;
-
- /// Set the name of the DDLNode instance.
- /// @param name [in] The name.
- void setName( const std::string &name );
-
- /// @brief Returns the name of the DDLNode instance.
- /// @return The name of the DDLNode instance.
- const std::string &getName() const;
-
- /// @brief Set a new property set.
- /// @param prop [in] The first element of the property set.
- void setProperties( Property *prop );
-
- /// @brief Returns the first element of the assigned property set.
- /// @return The first property of the assigned property set.
- Property *getProperties() const;
-
- /// @brief Looks for a given property.
- /// @param name [in] The name for the property to look for.
- /// @return true, if a corresponding property is assigned to the node, false if not.
- bool hasProperty( const std::string &name );
-
- /// @brief Will return true, if any properties are assigned to the node instance.
- /// @return True, if properties are assigned.
- bool hasProperties() const;
-
- /// @brief Search for a given property and returns it. Will return ddl_nullptr if no property was found.
- /// @param name [in] The name for the property to look for.
- /// @return The property or ddl_nullptr if no property was found.
- Property *findPropertyByName( const std::string &name );
-
- /// @brief Set a new value set.
- /// @param val [in] The first value instance of the value set.
- void setValue( Value *val );
-
- /// @brief Returns the first element of the assigned value set.
- /// @return The first property of the assigned value set.
- Value *getValue() const;
-
- /// @brief Set a new DataArrayList.
- /// @param dtArrayList [in] The DataArrayList instance.
- void setDataArrayList( DataArrayList *dtArrayList );
-
- /// @brief Returns the DataArrayList.
- /// @return The DataArrayList.
- DataArrayList *getDataArrayList() const;
-
- /// @brief Set a new Reference set.
- /// @param refs [in] The first value instance of the Reference set.
- void setReferences( Reference *refs );
-
- /// @brief Returns the first element of the assigned Reference set.
- /// @return The first property of the assigned Reference set.
- Reference *getReferences() const;
-
- /// @brief Will dump the node into the stream.
- /// @param stream [in] The stream to write to.
- void dump(IOStreamBase &stream);
-
- /// @brief The creation method.
- /// @param type [in] The DDLNode type.
- /// @param name [in] The name for the new DDLNode instance.
- /// @param parent [in] The parent node instance or ddl_nullptr if no parent node is there.
- /// @return The new created node instance.
- static DDLNode *create( const std::string &type, const std::string &name, DDLNode *parent = ddl_nullptr );
-
-private:
- DDLNode( const std::string &type, const std::string &name, size_t idx, DDLNode *parent = ddl_nullptr );
- DDLNode();
- DDLNode( const DDLNode & ) ddl_no_copy;
- DDLNode &operator = ( const DDLNode & ) ddl_no_copy;
- static void releaseNodes();
-
-private:
- std::string m_type;
- std::string m_name;
- DDLNode *m_parent;
- std::vector<DDLNode*> m_children;
- Property *m_properties;
- Value *m_value;
- DataArrayList *m_dtArrayList;
- Reference *m_references;
- size_t m_idx;
- static DllNodeList s_allocatedNodes;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h
deleted file mode 100644
index bec62cc9d..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h
+++ /dev/null
@@ -1,246 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <cstddef>
-#include <vector>
-#include <string>
-
-#include <stdio.h>
-#include <string.h>
-#ifndef _WIN32
-# include <inttypes.h>
-#endif
-
-#if defined(_MSC_VER) && !defined( OPENDDL_STATIC_LIBARY )
-
-# define TAG_DLL_EXPORT __declspec(dllexport)
-# define TAG_DLL_IMPORT __declspec(dllimport )
-# ifdef OPENDDLPARSER_BUILD
-# define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT
-# else
-# define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT
-# endif // OPENDDLPARSER_BUILD
-# pragma warning( disable : 4251 )
-#else
-# define DLL_ODDLPARSER_EXPORT
-#endif // _WIN32
-
-// Namespace declarations, override this to avoid any conflicts
-#define BEGIN_ODDLPARSER_NS namespace ODDLParser {
-#define END_ODDLPARSER_NS } // namespace ODDLParser
-#define USE_ODDLPARSER_NS using namespace ODDLParser;
-
-BEGIN_ODDLPARSER_NS
-
-// We will use C++11 optional
-#ifndef OPENDDL_NO_USE_CPP11
- // All C++11 constructs
-# define ddl_nullptr nullptr
-# define ddl_override override
-# define ddl_final final
-# define ddl_no_copy = delete
-#else
- // Fall-back for older compilers
-# define ddl_nullptr NULL
-# define ddl_override
-# define ddl_final
-# define ddl_no_copy
-#endif // OPENDDL_NO_USE_CPP11
-
-// Forward declarations
-class DDLNode;
-class Value;
-
-struct Name;
-struct Identifier;
-struct Reference;
-struct Property;
-struct DataArrayList;
-
-// Platform-specific typedefs
-#ifdef _WIN32
-typedef signed __int64 int64_impl;
-typedef unsigned __int64 uint64_impl;
-#else
-typedef int64_t int64_impl;
-typedef uint64_t uint64_impl;
-#endif
-
-// OpenDDL-specific data typedefs
-typedef signed char int8; ///< Signed integer, 1 byte
-typedef signed short int16; ///< Signed integer, 2 byte
-typedef signed int int32; ///< Signed integer, 4 byte
-typedef int64_impl int64; ///< Signed integer, 8 byte
-typedef unsigned char uint8; ///< Unsigned integer, 1 byte
-typedef unsigned short uint16; ///< Unsigned integer, 2 byte
-typedef unsigned int uint32; ///< Unsigned integer, 4 byte
-typedef uint64_impl uint64; ///< Unsigned integer, 8 byte
-
-/// @brief Stores a text.
-///
-/// A text is stored in a simple character buffer. Texts buffer can be
-/// greater than the number of stored characters in them.
-struct DLL_ODDLPARSER_EXPORT Text {
- size_t m_capacity; ///< The capacity of the text.
- size_t m_len; ///< The length of the text.
- char *m_buffer; ///< The buffer with the text.
-
- /// @brief The constructor with a given text buffer.
- /// @param buffer [in] The buffer.
- /// @param numChars [in] The number of characters in the buffer.
- Text( const char *buffer, size_t numChars );
-
- /// @brief The destructor.
- ~Text();
-
- /// @brief Clears the text.
- void clear();
-
- /// @brief Set a new text.
- /// @param buffer [in] The buffer.
- /// @param numChars [in] The number of characters in the buffer.
- void set( const char *buffer, size_t numChars );
-
- /// @brief The compare operator for std::strings.
- bool operator == ( const std::string &name ) const;
-
- /// @brief The compare operator for Texts.
- bool operator == ( const Text &rhs ) const;
-
-private:
- Text( const Text & ) ddl_no_copy;
- Text &operator = ( const Text & ) ddl_no_copy;
-};
-
-/// @brief Description of the type of a name.
-enum NameType {
- GlobalName, ///< Name is global.
- LocalName ///< Name is local.
-};
-
-/// @brief Stores an OpenDDL-specific name
-struct DLL_ODDLPARSER_EXPORT Name {
- NameType m_type; ///< The type of the name ( @see NameType ).
- Text *m_id; ///< The id.
-
- /// @brief The constructor with the type and the id.
- /// @param type [in] The name type.
- /// @param id [in] The id.
- Name( NameType type, Text *id );
- Name( const Name &name );
- /// @brief The destructor.
- ~Name();
-
-private:
-
- Name &operator = ( const Name& ) ddl_no_copy;
-};
-
-/// @brief Stores a bundle of references.
-struct DLL_ODDLPARSER_EXPORT Reference {
- size_t m_numRefs; ///< The number of stored references.
- Name **m_referencedName; ///< The reference names.
-
- /// @brief The default constructor.
- Reference();
- Reference( const Reference &ref );
- /// @brief The constructor with an array of ref names.
- /// @param numrefs [in] The number of ref names.
- /// @param names [in] The ref names.
- Reference( size_t numrefs, Name **names );
-
- /// @brief The destructor.
- ~Reference();
-
- /// @brief Returns the size in bytes to store one deep reference copy.
- /// @return The size on bytes.
- size_t sizeInBytes();
-
-private:
- Reference &operator = ( const Reference & ) ddl_no_copy;
-};
-
-/// @brief Stores a property list.
-struct DLL_ODDLPARSER_EXPORT Property {
- Text *m_key; ///< The identifier / key of the property.
- Value *m_value; ///< The value assigned to its key / id ( ddl_nullptr if none ).
- Reference *m_ref; ///< References assigned to its key / id ( ddl_nullptr if none ).
- Property *m_next; ///< The next property ( ddl_nullptr if none ).
-
- /// @brief The default constructor.
- Property();
-
- /// @brief The constructor for initialization.
- /// @param id [in] The identifier
- Property( Text *id );
-
- /// @brief The destructor.
- ~Property();
-
-private:
- Property( const Property & ) ddl_no_copy;
- Property &operator = ( const Property & ) ddl_no_copy;
-};
-
-/// @brief Stores a data array list.
-struct DLL_ODDLPARSER_EXPORT DataArrayList {
- size_t m_numItems; ///< The number of items in the list.
- Value *m_dataList; ///< The data list ( a Value ).
- DataArrayList *m_next; ///< The next data array list ( ddl_nullptr if last ).
- Reference *m_refs;
- size_t m_numRefs;
-
- /// @brief The default constructor for initialization.
- DataArrayList();
-
- /// @brief The destructor.
- ~DataArrayList();
-
- /// @brief Gets the length of the array
- size_t size();
-
-private:
- DataArrayList( const DataArrayList & ) ddl_no_copy;
- DataArrayList &operator = ( const DataArrayList & ) ddl_no_copy;
-};
-
-/// @brief Stores the context of a parsed OpenDDL declaration.
-struct DLL_ODDLPARSER_EXPORT Context {
- DDLNode *m_root; ///< The root node of the OpenDDL node tree.
-
- /// @brief Constructor for initialization.
- Context();
-
- /// @brief Destructor.
- ~Context();
-
- /// @brief Clears the whole node tree.
- void clear();
-
-private:
- Context( const Context & ) ddl_no_copy;
- Context &operator = ( const Context & ) ddl_no_copy;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLExport.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLExport.h
deleted file mode 100644
index 020d662a0..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLExport.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-#include <openddlparser/OpenDDLStream.h>
-#include <openddlparser/Value.h>
-
-BEGIN_ODDLPARSER_NS
-
-// Forward declarations
-class IOStreamBase;
-
-//-------------------------------------------------------------------------------------------------
-///
-/// @ingroup OpenDDLParser
-/// @brief This class represents the OpenDDLExporter.
-///
-//-------------------------------------------------------------------------------------------------
-class DLL_ODDLPARSER_EXPORT OpenDDLExport {
-public:
- /// @brief The class constructor
- OpenDDLExport( IOStreamBase *stream = ddl_nullptr );
-
- /// @brief The class destructor.
- ~OpenDDLExport();
-
- /// @brief Export the data of a parser context.
- /// @param ctx [in] Pointer to the context.
- /// @param filename [in] The filename for the export.
- /// @return True in case of success, false in case of an error.
- bool exportContext( Context *ctx, const std::string &filename );
-
- /// @brief Handles a node export.
- /// @param node [in] The node to handle with.
- /// @return True in case of success, false in case of an error.
- bool handleNode( DDLNode *node );
-
- /// @brief Writes the statement to the stream.
- /// @param statement [in] The content to write.
- /// @return True in case of success, false in case of an error.
- bool writeToStream( const std::string &statement );
-
-protected:
- bool writeNode( DDLNode *node, std::string &statement );
- bool writeNodeHeader( DDLNode *node, std::string &statement );
- bool writeProperties( DDLNode *node, std::string &statement );
- bool writeValueType( Value::ValueType type, size_t numItems, std::string &statement );
- bool writeValue( Value *val, std::string &statement );
- bool writeValueArray( DataArrayList *al, std::string &statement );
-
-private:
- OpenDDLExport( const OpenDDLExport & ) ddl_no_copy;
- OpenDDLExport &operator = ( const OpenDDLExport & ) ddl_no_copy;
-
-private:
- IOStreamBase *m_stream;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParser.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParser.h
deleted file mode 100644
index ef7f3a72e..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParser.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-#include <openddlparser/DDLNode.h>
-#include <openddlparser/OpenDDLParserUtils.h>
-#include <openddlparser/Value.h>
-
-#include <vector>
-#include <string>
-
-BEGIN_ODDLPARSER_NS
-
-class DDLNode;
-class Value;
-
-struct Identifier;
-struct Reference;
-struct Property;
-
-template<class T>
-inline
-bool isEmbeddedCommentOpenTag( T *in, T *end ) {
- if ( in == end ) {
- return false;
- }
-
- if ( in == '/' && in+1 == '*' ) {
- return true;
- }
-
- return false;
-}
-
-/// @brief Utility function to search for the next token or the end of the buffer.
-/// @param in [in] The start position in the buffer.
-/// @param end [in] The end position in the buffer.
-/// @return Pointer showing to the next token or the end of the buffer.
-/// @detail Will not increase buffer when already a valid buffer was found.
-template<class T>
-inline
-T *lookForNextToken( T *in, T *end ) {
- while( ( in != end ) && ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) ) {
- in++;
- }
- return in;
-}
-
-/// @brief Utility function to go for the next token or the end of the buffer.
-/// @param in [in] The start position in the buffer.
-/// @param end [in] The end position in the buffer.
-/// @return Pointer showing to the next token or the end of the buffer.
-/// @detail Will increase buffer by a minimum of one.
-template<class T>
-inline
-T *getNextToken( T *in, T *end ) {
- T *tmp( in );
- in = lookForNextToken( in, end );
- if( tmp == in ) {
- in++;
- }
- return in;
-}
-
-/// @brief Defines the log severity.
-enum LogSeverity {
- ddl_debug_msg = 0, ///< Debug message, for debugging
- ddl_info_msg, ///< Info messages, normal mode
- ddl_warn_msg, ///< Parser warnings
- ddl_error_msg ///< Parser errors
-};
-
-DLL_ODDLPARSER_EXPORT const char *getTypeToken( Value::ValueType type );
-
-//-------------------------------------------------------------------------------------------------
-/// @class OpenDDLParser
-/// @ingroup OpenDDLParser
-
-///
-/// @brief This is the main API for the OpenDDL-parser.
-///
-/// Use instances of this class to manage the parsing and handling of your parser contexts.
-//-------------------------------------------------------------------------------------------------
-class DLL_ODDLPARSER_EXPORT OpenDDLParser {
-public:
- /// @brief The log callback function pointer.
- typedef void( *logCallback )( LogSeverity severity, const std::string &msg );
-
-public:
- /// @brief The default class constructor.
- OpenDDLParser();
-
- /// @brief The class constructor.
- /// @param buffer [in] The buffer
- /// @param len [in] Size of the buffer
- OpenDDLParser( const char *buffer, size_t len );
-
- /// @brief The class destructor.
- ~OpenDDLParser();
-
- /// @brief Setter for an own log callback function.
- /// @param callback [in] The own callback.
- void setLogCallback( logCallback callback );
-
- /// @brief Getter for the log callback.
- /// @return The current log callback.
- logCallback getLogCallback() const;
-
- /// @brief Assigns a new buffer to parse.
- /// @param buffer [in] The buffer
- /// @param len [in] Size of the buffer
- void setBuffer( const char *buffer, size_t len );
-
- /// @brief Assigns a new buffer to parse.
- /// @param buffer [in] The buffer as a std::vector.
- void setBuffer( const std::vector<char> &buffer );
-
- /// @brief Returns the buffer pointer.
- /// @return The buffer pointer.
- const char *getBuffer() const;
-
- /// @brief Returns the size of the buffer.
- /// @return The buffer size.
- size_t getBufferSize() const;
-
- /// @brief Clears all parser data, including buffer and active context.
- void clear();
-
- /// @brief Starts the parsing of the OpenDDL-file.
- /// @return True in case of success, false in case of an error.
- /// @remark In case of errors check log.
- bool parse();
-
- bool exportContext( Context *ctx, const std::string &filename );
-
- /// @brief Returns the root node.
- /// @return The root node.
- DDLNode *getRoot() const;
-
- /// @brief Returns the parser context, only available in case of a succeeded parsing.
- /// @return Pointer to the active context or ddl_nullptr.
- Context *getContext() const;
-
-public: // parser helpers
- char *parseNextNode( char *current, char *end );
- char *parseHeader( char *in, char *end );
- char *parseStructure( char *in, char *end );
- char *parseStructureBody( char *in, char *end, bool &error );
- void pushNode( DDLNode *node );
- DDLNode *popNode();
- DDLNode *top();
- static void normalizeBuffer( std::vector<char> &buffer );
- static char *parseName( char *in, char *end, Name **name );
- static char *parseIdentifier( char *in, char *end, Text **id );
- static char *parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len );
- static char *parseReference( char *in, char *end, std::vector<Name*> &names );
- static char *parseBooleanLiteral( char *in, char *end, Value **boolean );
- static char *parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType = Value::ddl_int32 );
- static char *parseFloatingLiteral( char *in, char *end, Value **floating, Value::ValueType floatType= Value::ddl_float );
- static char *parseStringLiteral( char *in, char *end, Value **stringData );
- static char *parseHexaLiteral( char *in, char *end, Value **data );
- static char *parseProperty( char *in, char *end, Property **prop );
- static char *parseDataList( char *in, char *end, Value::ValueType type, Value **data, size_t &numValues, Reference **refs, size_t &numRefs );
- static char *parseDataArrayList( char *in, char *end, Value::ValueType type, DataArrayList **dataList );
- static const char *getVersion();
-
-private:
- OpenDDLParser( const OpenDDLParser & ) ddl_no_copy;
- OpenDDLParser &operator = ( const OpenDDLParser & ) ddl_no_copy;
-
-private:
- logCallback m_logCallback;
- std::vector<char> m_buffer;
-
- typedef std::vector<DDLNode*> DDLNodeStack;
- DDLNodeStack m_stack;
- Context *m_context;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h
deleted file mode 100644
index 64897436e..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h
+++ /dev/null
@@ -1,282 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-
-BEGIN_ODDLPARSER_NS
-
-template<class T>
-inline
-bool isUpperCase( T in ) {
- return ( in >= 'A' && in <= 'Z' );
-}
-
-template<class T>
-inline
-bool isLowerCase( T in ) {
- return ( in >= 'a' && in <= 'z' );
-}
-
-template<class T>
-inline
-bool isSpace( const T in ) {
- return ( ' ' == in || '\t' == in );
-}
-
-template<class T>
-inline
-bool isNewLine( const T in ) {
- return ( '\n' == in || ( '\r' == in ) );
-}
-
-template<class T>
-inline
-bool isSeparator( T in ) {
- if( isSpace( in ) || ',' == in || '{' == in || '}' == in || '[' == in || '(' == in || ')' == in ) {
- return true;
- }
- return false;
-}
-
-static const unsigned char chartype_table[ 256 ] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32-47
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 48-63
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 64-79
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80-95
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 96-111
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 112-127
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // > 127
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-template<class T>
-inline
-bool isNumeric( const T in ) {
- return ( chartype_table[ static_cast<size_t>( in ) ] == 1 );
-}
-
-template<class T>
-inline
-bool isNotEndOfToken( T *in, T *end ) {
- return ( '}' != *in && ',' != *in && !isSpace( *in ) && ')' != *in && in != end );
-}
-
-template<class T>
-inline
-bool isInteger( T *in, T *end ) {
- if( in != end ) {
- if( *in == '-' ) {
- ++in;
- }
- }
-
- bool result( false );
- while( isNotEndOfToken( in, end ) ) {
- result = isNumeric( *in );
- if( !result ) {
- break;
- }
- ++in;
- }
-
- return result;
-}
-
-template<class T>
-inline
-bool isFloat( T *in, T *end ) {
- if( in != end ) {
- if( *in == '-' ) {
- ++in;
- }
- }
-
- // check for <1>.0f
- bool result( false );
- while( isNotEndOfToken( in, end ) ) {
- if( *in == '.' ) {
- result = true;
- break;
- }
- result = isNumeric( *in );
- if( !result ) {
- return false;
- }
- ++in;
- }
-
- // check for 1<.>0f
- if( *in == '.' ) {
- ++in;
- } else {
- return false;
- }
-
- // check for 1.<0>f
- while( isNotEndOfToken( in, end ) ) {
- result = isNumeric( *in );
- if( !result ) {
- return false;
- }
- ++in;
- }
-
- return result;
-}
-
-template<class T>
-inline
-bool isCharacter( const T in ) {
- return ( ( in >= 'a' && in <= 'z' ) || ( in >= 'A' && in <= 'Z' ) );
-}
-
-template<class T>
-inline
-bool isStringLiteral( const T in ) {
- return ( in == '\"' );
-}
-
-template<class T>
-inline
-bool isHexLiteral( T *in, T *end ) {
- if( *in == '0' ) {
- if( in + 1 != end ) {
- if( *( in + 1 ) == 'x' || *( in + 1 ) == 'X' ) {
- return true;
- }
- }
- }
-
- return false;
-}
-
-template<class T>
-inline
-bool isReference( T *in, T *end ) {
- if( *in == 'r' ) {
- if( *(in+1) == 'e' ) {
- if( *(in+2) == 'f' ) {
- if( ( in + 2 ) != end ) {
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-template<class T>
-inline
-bool isEndofLine( const T in ) {
- return ( '\n' == in );
-}
-
-template<class T>
-inline
-static T *getNextSeparator( T *in, T *end ) {
- while( !isSeparator( *in ) || in == end ) {
- ++in;
- }
- return in;
-}
-
-static const int ErrorHex2Decimal = 9999999;
-
-inline
-int hex2Decimal( char in ) {
- if( isNumeric( in ) ) {
- return ( in - 48 );
- }
-
- char hexCodeLower( 'a' ), hexCodeUpper( 'A' );
- for( int i = 0; i<16; i++ ) {
- if( in == hexCodeLower + i || in == hexCodeUpper + i ) {
- return ( i+10 );
- }
- }
-
- return ErrorHex2Decimal;
-}
-
-template<class T>
-inline
-bool isComment( T *in, T *end ) {
- if ( *in=='/' ) {
- if ( in+1!=end ) {
- if ( *( in+1 )=='/' ) {
- char *drive( ( in+2 ) );
- if ( (isUpperCase<T>( *drive )||isLowerCase<T>( *drive ))&&*( drive+1 )=='/' ) {
- return false;
- } else {
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-template<class T>
-inline
-bool isCommentOpenTag(T *in, T *end ) {
- if (*in == '/') {
- if (in + 1 != end) {
- if (*(in + 1) == '*') {
- return true;
- }
- }
- }
-
- return false;
-}
-
-template<class T>
-inline
-bool isCommentCloseTag(T *in, T *end) {
- if (*in == '*') {
- if (in + 1 != end) {
- if (*(in + 1) == '/') {
- return true;
- }
- }
- }
-
- return false;
-}
-
-END_ODDLPARSER_NS
-
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLStream.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLStream.h
deleted file mode 100644
index 93370da03..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/OpenDDLStream.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-
-BEGIN_ODDLPARSER_NS
-
-//-------------------------------------------------------------------------------------------------
-/// @ingroup IOStreamBase
-/// @brief This class represents the stream to write out.
-//-------------------------------------------------------------------------------------------------
-class DLL_ODDLPARSER_EXPORT StreamFormatterBase {
-public:
- /// @brief The class constructor.
- StreamFormatterBase();
-
- /// @brief The class destructor, virtual.
- virtual ~StreamFormatterBase();
-
- /// @brief Will format the sring and return the new formatted result.
- /// @param statement [in] The string to reformat.
- /// @return The reformatted result.
- virtual std::string format(const std::string &statement);
-};
-
-//-------------------------------------------------------------------------------------------------
-/// @ingroup IOStreamBase
-/// @brief This class represents the stream to write out.
-//-------------------------------------------------------------------------------------------------
-class DLL_ODDLPARSER_EXPORT IOStreamBase {
-public:
- /// @brief The class constructor with the formatter.
- /// @param formatter [in] The formatter to use.
- explicit IOStreamBase(StreamFormatterBase *formatter = ddl_nullptr);
-
- /// @brief The class destructor, virtual.
- virtual ~IOStreamBase();
-
- /// @brief Will open the stream.
- /// @param name [in] The name for the stream.
- /// @return true, if the stream was opened successfully, false if not.
- virtual bool open(const std::string &name);
-
- /// @brief Will close the stream.
- /// @return true, if the stream was closed successfully, false if not.
- virtual bool close();
-
- /// @brief Returns true, if the stream is open.
- /// @return true, if the stream is open, false if not.
- virtual bool isOpen() const;
-
- /// @brief Will read a string from the stream.
- /// @param sizeToRead [in] The size to read in bytes.
- /// @param statement [out] The read statements.
- /// @return The bytes read from the stream.
- virtual size_t read( size_t sizeToRead, std::string &statement );
-
- /// @brief Will write a string into the stream.
- /// @param statement [in] The string to write.
- /// @return The bytes written into the stream.
- virtual size_t write(const std::string &statement);
-
-private:
- StreamFormatterBase *m_formatter;
- FILE *m_file;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/Value.h b/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/Value.h
deleted file mode 100644
index 77c6da06b..000000000
--- a/src/3rdparty/assimp/contrib/openddlparser/include/openddlparser/Value.h
+++ /dev/null
@@ -1,273 +0,0 @@
-/*-----------------------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2014-2015 Kim Kulling
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------------------*/
-#pragma once
-
-#include <openddlparser/OpenDDLCommon.h>
-
-#include <string>
-
-BEGIN_ODDLPARSER_NS
-
-// Forward declarations
-struct ValueAllocator;
-
-class IOStreamBase;
-
-///------------------------------------------------------------------------------------------------
-/// @brief This class implements a value.
-///
-/// Values are used to store data types like boolean, integer, floats, double and many mode. To get
-/// an overview please check the enum VylueType ( @see Value::ValueType ).
-/// Values can be single items or lists of items. They are implemented as linked lists.
-///------------------------------------------------------------------------------------------------
-class DLL_ODDLPARSER_EXPORT Value {
- friend struct ValueAllocator;
-
-public:
- /// @brief This class implements an iterator through a Value list.
- ///
- /// When getting a new value you need to know how to iterate through it. The Value::Iterator
- /// will help you here:
- /// @code
- /// Value *val = node->getValue();
- /// Value::Iterator it( val );
- /// while( it.hasNext() ) {
- /// Value v( it.getNext );
- /// }
- /// @endcode
- class DLL_ODDLPARSER_EXPORT Iterator {
- public:
- /// @brief The default class constructor.
- Iterator();
-
- /// @brief The class constructor with the start value.
- /// @param start [in] The first value for iteration,
- Iterator( Value *start );
-
- Iterator( const Iterator &rhs );
-
- /// @brief The class destructor.
- ~Iterator();
-
- /// @brief Will return true, if another value is in the list.
- /// @return true if another value is there.
- bool hasNext() const;
-
- /// @brief Returns the next item and moves the iterator to it.
- /// @return The next value, is ddl_nullptr in case of being the last item.
- Value *getNext();
-
- /// @brief The post-increment operator.
- const Iterator operator++( int );
-
- /// @brief The pre-increment operator.
- Iterator &operator++( );
-
- /// @brief The compare operator.
- /// @param rhs [in] The instance to compare.
- /// @return true if equal.
- bool operator == ( const Iterator &rhs ) const;
-
- /// @brief The * operator.
- /// @return The instance or ddl_nullptr if end of list is reached.
- Value *operator->( ) const;
-
- private:
- Value *m_start;
- Value *m_current;
-
- private:
- Iterator &operator = ( const Iterator & );
- };
-
- /// @brief This enum describes the data type stored in the value.
- enum ValueType {
- ddl_none = -1, ///< Nothing specified
- ddl_bool = 0, ///< A boolean type
- ddl_int8, ///< Integer type, 8 bytes
- ddl_int16, ///< Integer type, 16 bytes
- ddl_int32, ///< Integer type, 32 bytes
- ddl_int64, ///< Integer type, 64 bytes
- ddl_unsigned_int8, ///< Unsigned integer type, 8 bytes
- ddl_unsigned_int16, ///< Unsigned integer type, 16 bytes
- ddl_unsigned_int32, ///< Unsigned integer type, 32 bytes
- ddl_unsigned_int64, ///< Unsigned integer type, 64 bytes
- ddl_half, ///< Half data type.
- ddl_float, ///< float data type
- ddl_double, ///< Double data type.
- ddl_string, ///< String data type.
- ddl_ref, ///< Reference, used to define references to other data definitions.
- ddl_types_max ///< Upper limit.
- };
-
- /// @brief The class constructor.
- /// @param type [in] The value type.
- Value( ValueType type );
-
- /// @brief The class destructor.
- ~Value();
-
- /// @brief Assigns a boolean to the value.
- /// @param value [in9 The value.
- void setBool( bool value );
-
- /// @brief Returns the boolean value.
- /// @return The boolean value.
- bool getBool();
-
- /// @brief Assigns a int8 to the value.
- /// @param value [in] The value.
- void setInt8( int8 value );
-
- /// @brief Returns the int8 value.
- /// @return The int8 value.
- int8 getInt8();
-
- /// @brief Assigns a int16 to the value.
- /// @param value [in] The value.
- void setInt16( int16 value );
-
- /// @brief Returns the int16 value.
- /// @return The int16 value.
- int16 getInt16();
-
- /// @brief Assigns a int32 to the value.
- /// @param value [in] The value.
- void setInt32( int32 value );
-
- /// @brief Returns the int16 value.
- /// @return The int32 value.
- int32 getInt32();
-
- /// @brief Assigns a int64 to the value.
- /// @param value [in] The value.
- void setInt64( int64 value );
-
- /// @brief Returns the int16 value.
- /// @return The int64 value.
- int64 getInt64();
-
- /// @brief Assigns a unsigned int8 to the value.
- /// @param value [in] The value.
- void setUnsignedInt8( uint8 value );
-
- /// @brief Returns the unsigned int8 value.
- /// @return The unsigned int8 value.
- uint8 getUnsignedInt8() const;
-
- /// @brief Assigns a unsigned int16 to the value.
- /// @param value [in] The value.
- void setUnsignedInt16( uint16 value );
-
- /// @brief Returns the unsigned int16 value.
- /// @return The unsigned int16 value.
- uint16 getUnsignedInt16() const;
-
- /// @brief Assigns a unsigned int32 to the value.
- /// @param value [in] The value.
- void setUnsignedInt32( uint32 value );
-
- /// @brief Returns the unsigned int8 value.
- /// @return The unsigned int32 value.
- uint32 getUnsignedInt32() const;
-
- /// @brief Assigns a unsigned int64 to the value.
- /// @param value [in] The value.
- void setUnsignedInt64( uint64 value );
-
- /// @brief Returns the unsigned int64 value.
- /// @return The unsigned int64 value.
- uint64 getUnsignedInt64() const;
-
- /// @brief Assigns a float to the value.
- /// @param value [in] The value.
- void setFloat( float value );
-
- /// @brief Returns the float value.
- /// @return The float value.
- float getFloat() const;
-
- /// @brief Assigns a double to the value.
- /// @param value [in] The value.
- void setDouble( double value );
-
- /// @brief Returns the double value.
- /// @return The double value.
- double getDouble() const;
-
- /// @brief Assigns a std::string to the value.
- /// @param str [in] The value.
- void setString( const std::string &str );
-
- /// @brief Returns the std::string value.
- /// @return The std::string value.
- const char *getString() const;
-
- /// @brief Set the reference.
- /// @param ref [in] Pointer showing to the reference.
- void setRef( Reference *ref );
-
- /// @brief Returns the pointer showing to the reference.
- /// @return Pointer showing to the reference.
- Reference *getRef() const;
-
- /// @brief Dumps the value.
- /// @param stream [in] The stream to write in.
- void dump( IOStreamBase &stream );
-
- /// @brief Assigns the next value.
- /// @param next [n] The next value.
- void setNext( Value *next );
-
- /// @brief Returns the next value.
- /// @return The next value.s
- Value *getNext() const;
-
- /// @brief Gets the length of the array.
- /// @return The number of items in the array.
- size_t size() const;
-
- ValueType m_type;
- size_t m_size;
- unsigned char *m_data;
- Value *m_next;
-
-private:
- Value &operator =( const Value & ) ddl_no_copy;
- Value( const Value & ) ddl_no_copy;
-};
-
-///------------------------------------------------------------------------------------------------
-/// @brief This class implements the value allocator.
-///------------------------------------------------------------------------------------------------
-struct DLL_ODDLPARSER_EXPORT ValueAllocator {
- static Value *allocPrimData( Value::ValueType type, size_t len = 1 );
- static void releasePrimData( Value **data );
-
-private:
- ValueAllocator() ddl_no_copy;
- ValueAllocator( const ValueAllocator & ) ddl_no_copy;
- ValueAllocator &operator = ( const ValueAllocator & ) ddl_no_copy;
-};
-
-END_ODDLPARSER_NS
diff --git a/src/3rdparty/assimp/contrib/poly2tri/AUTHORS b/src/3rdparty/assimp/contrib/poly2tri/AUTHORS
deleted file mode 100644
index 1736f14bb..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/AUTHORS
+++ /dev/null
@@ -1,8 +0,0 @@
-Primary Contributors:
-
- Mason Green <mason.green@gmail.com> (C++, Python)
- Thomas Åhlén <thahlen@gmail.com> (Java)
-
-Other Contributors:
-
-
diff --git a/src/3rdparty/assimp/contrib/poly2tri/LICENSE b/src/3rdparty/assimp/contrib/poly2tri/LICENSE
deleted file mode 100644
index 9417c0836..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
-http://code.google.com/p/poly2tri/
-
-All rights reserved.
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-* Neither the name of Poly2Tri nor the names of its contributors may be
- used to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/3rdparty/assimp/contrib/poly2tri/README b/src/3rdparty/assimp/contrib/poly2tri/README
deleted file mode 100644
index 2857e2983..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/README
+++ /dev/null
@@ -1,51 +0,0 @@
-==================
-INSTALLATION GUIDE
-==================
-
-------------
-Dependencies
-------------
-
- Core poly2tri lib:
- - Standard Template Library (STL)
-
- Testbed:
- - gcc
- - OpenGL
- - GLFW (http://glfw.sf.net)
- - Python
-
-Waf (http://code.google.com/p/waf/) is used to compile the testbed.
-A waf script (86kb) is included in the repositoty.
-
-----------------------------------------------
-Building the Testbed
-----------------------------------------------
-
-Posix/MSYS environment:
-
- ./waf configure
- ./waf build
-
-Windows command line:
-
- python waf configure
- python waf build
-
-----------------------------------------------
-Running the Examples
-----------------------------------------------
-
-Load data points from a file:
-p2t <filename> <center_x> <center_y> <zoom>
-
-Random distribution of points inside a consrained box:
-p2t random <num_points> <box_radius> <zoom>
-
-Examples:
-
- ./p2t dude.dat 300 500 2
- ./p2t nazca_monkey.dat 0 0 9
-
- ./p2t random 10 100 5.0
- ./p2t random 1000 20000 0.025 \ No newline at end of file
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.cc b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.cc
deleted file mode 100644
index c94e11c03..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.cc
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "shapes.h"
-#include <iostream>
-
-namespace p2t {
-
-Triangle::Triangle(Point& a, Point& b, Point& c)
-{
- points_[0] = &a; points_[1] = &b; points_[2] = &c;
- neighbors_[0] = NULL; neighbors_[1] = NULL; neighbors_[2] = NULL;
- constrained_edge[0] = constrained_edge[1] = constrained_edge[2] = false;
- delaunay_edge[0] = delaunay_edge[1] = delaunay_edge[2] = false;
- interior_ = false;
-}
-
-// Update neighbor pointers
-void Triangle::MarkNeighbor(Point* p1, Point* p2, Triangle* t)
-{
- if ((p1 == points_[2] && p2 == points_[1]) || (p1 == points_[1] && p2 == points_[2]))
- neighbors_[0] = t;
- else if ((p1 == points_[0] && p2 == points_[2]) || (p1 == points_[2] && p2 == points_[0]))
- neighbors_[1] = t;
- else if ((p1 == points_[0] && p2 == points_[1]) || (p1 == points_[1] && p2 == points_[0]))
- neighbors_[2] = t;
- else
- assert(0);
-}
-
-// Exhaustive search to update neighbor pointers
-void Triangle::MarkNeighbor(Triangle& t)
-{
- if (t.Contains(points_[1], points_[2])) {
- neighbors_[0] = &t;
- t.MarkNeighbor(points_[1], points_[2], this);
- } else if (t.Contains(points_[0], points_[2])) {
- neighbors_[1] = &t;
- t.MarkNeighbor(points_[0], points_[2], this);
- } else if (t.Contains(points_[0], points_[1])) {
- neighbors_[2] = &t;
- t.MarkNeighbor(points_[0], points_[1], this);
- }
-}
-
-/**
- * Clears all references to all other triangles and points
- */
-void Triangle::Clear()
-{
- Triangle *t;
- for( int i=0; i<3; i++ )
- {
- t = neighbors_[i];
- if( t != NULL )
- {
- t->ClearNeighbor( this );
- }
- }
- ClearNeighbors();
- points_[0]=points_[1]=points_[2] = NULL;
-}
-
-void Triangle::ClearNeighbor(const Triangle *triangle )
-{
- if( neighbors_[0] == triangle )
- {
- neighbors_[0] = NULL;
- }
- else if( neighbors_[1] == triangle )
- {
- neighbors_[1] = NULL;
- }
- else
- {
- neighbors_[2] = NULL;
- }
-}
-
-void Triangle::ClearNeighbors()
-{
- neighbors_[0] = NULL;
- neighbors_[1] = NULL;
- neighbors_[2] = NULL;
-}
-
-void Triangle::ClearDelunayEdges()
-{
- delaunay_edge[0] = delaunay_edge[1] = delaunay_edge[2] = false;
-}
-
-Point* Triangle::OppositePoint(Triangle& t, const Point& p)
-{
- Point *cw = t.PointCW(p);
- return PointCW(*cw);
-}
-
-// Legalized triangle by rotating clockwise around point(0)
-void Triangle::Legalize(Point& point)
-{
- points_[1] = points_[0];
- points_[0] = points_[2];
- points_[2] = &point;
-}
-
-// Legalize triagnle by rotating clockwise around oPoint
-void Triangle::Legalize(Point& opoint, Point& npoint)
-{
- if (&opoint == points_[0]) {
- points_[1] = points_[0];
- points_[0] = points_[2];
- points_[2] = &npoint;
- } else if (&opoint == points_[1]) {
- points_[2] = points_[1];
- points_[1] = points_[0];
- points_[0] = &npoint;
- } else if (&opoint == points_[2]) {
- points_[0] = points_[2];
- points_[2] = points_[1];
- points_[1] = &npoint;
- } else {
- assert(0);
- }
-}
-
-int Triangle::Index(const Point* p)
-{
- if (p == points_[0]) {
- return 0;
- } else if (p == points_[1]) {
- return 1;
- } else if (p == points_[2]) {
- return 2;
- }
- assert(0);
- return -1;
-}
-
-int Triangle::EdgeIndex(const Point* p1, const Point* p2)
-{
- if (points_[0] == p1) {
- if (points_[1] == p2) {
- return 2;
- } else if (points_[2] == p2) {
- return 1;
- }
- } else if (points_[1] == p1) {
- if (points_[2] == p2) {
- return 0;
- } else if (points_[0] == p2) {
- return 2;
- }
- } else if (points_[2] == p1) {
- if (points_[0] == p2) {
- return 1;
- } else if (points_[1] == p2) {
- return 0;
- }
- }
- return -1;
-}
-
-void Triangle::MarkConstrainedEdge(int index)
-{
- constrained_edge[index] = true;
-}
-
-void Triangle::MarkConstrainedEdge(Edge& edge)
-{
- MarkConstrainedEdge(edge.p, edge.q);
-}
-
-// Mark edge as constrained
-void Triangle::MarkConstrainedEdge(Point* p, Point* q)
-{
- if ((q == points_[0] && p == points_[1]) || (q == points_[1] && p == points_[0])) {
- constrained_edge[2] = true;
- } else if ((q == points_[0] && p == points_[2]) || (q == points_[2] && p == points_[0])) {
- constrained_edge[1] = true;
- } else if ((q == points_[1] && p == points_[2]) || (q == points_[2] && p == points_[1])) {
- constrained_edge[0] = true;
- }
-}
-
-// The point counter-clockwise to given point
-Point* Triangle::PointCW(const Point& point)
-{
- if (&point == points_[0]) {
- return points_[2];
- } else if (&point == points_[1]) {
- return points_[0];
- } else if (&point == points_[2]) {
- return points_[1];
- }
- assert(0);
- return NULL;
-}
-
-// The point counter-clockwise to given point
-Point* Triangle::PointCCW(const Point& point)
-{
- if (&point == points_[0]) {
- return points_[1];
- } else if (&point == points_[1]) {
- return points_[2];
- } else if (&point == points_[2]) {
- return points_[0];
- }
- assert(0);
- return NULL;
-}
-
-// The neighbor clockwise to given point
-Triangle* Triangle::NeighborCW(const Point& point)
-{
- if (&point == points_[0]) {
- return neighbors_[1];
- } else if (&point == points_[1]) {
- return neighbors_[2];
- }
- return neighbors_[0];
-}
-
-// The neighbor counter-clockwise to given point
-Triangle* Triangle::NeighborCCW(const Point& point)
-{
- if (&point == points_[0]) {
- return neighbors_[2];
- } else if (&point == points_[1]) {
- return neighbors_[0];
- }
- return neighbors_[1];
-}
-
-bool Triangle::GetConstrainedEdgeCCW(const Point& p)
-{
- if (&p == points_[0]) {
- return constrained_edge[2];
- } else if (&p == points_[1]) {
- return constrained_edge[0];
- }
- return constrained_edge[1];
-}
-
-bool Triangle::GetConstrainedEdgeCW(const Point& p)
-{
- if (&p == points_[0]) {
- return constrained_edge[1];
- } else if (&p == points_[1]) {
- return constrained_edge[2];
- }
- return constrained_edge[0];
-}
-
-void Triangle::SetConstrainedEdgeCCW(const Point& p, bool ce)
-{
- if (&p == points_[0]) {
- constrained_edge[2] = ce;
- } else if (&p == points_[1]) {
- constrained_edge[0] = ce;
- } else {
- constrained_edge[1] = ce;
- }
-}
-
-void Triangle::SetConstrainedEdgeCW(const Point& p, bool ce)
-{
- if (&p == points_[0]) {
- constrained_edge[1] = ce;
- } else if (&p == points_[1]) {
- constrained_edge[2] = ce;
- } else {
- constrained_edge[0] = ce;
- }
-}
-
-bool Triangle::GetDelunayEdgeCCW(const Point& p)
-{
- if (&p == points_[0]) {
- return delaunay_edge[2];
- } else if (&p == points_[1]) {
- return delaunay_edge[0];
- }
- return delaunay_edge[1];
-}
-
-bool Triangle::GetDelunayEdgeCW(const Point& p)
-{
- if (&p == points_[0]) {
- return delaunay_edge[1];
- } else if (&p == points_[1]) {
- return delaunay_edge[2];
- }
- return delaunay_edge[0];
-}
-
-void Triangle::SetDelunayEdgeCCW(const Point& p, bool e)
-{
- if (&p == points_[0]) {
- delaunay_edge[2] = e;
- } else if (&p == points_[1]) {
- delaunay_edge[0] = e;
- } else {
- delaunay_edge[1] = e;
- }
-}
-
-void Triangle::SetDelunayEdgeCW(const Point& p, bool e)
-{
- if (&p == points_[0]) {
- delaunay_edge[1] = e;
- } else if (&p == points_[1]) {
- delaunay_edge[2] = e;
- } else {
- delaunay_edge[0] = e;
- }
-}
-
-// The neighbor across to given point
-Triangle& Triangle::NeighborAcross(const Point& opoint)
-{
- if (&opoint == points_[0]) {
- return *neighbors_[0];
- } else if (&opoint == points_[1]) {
- return *neighbors_[1];
- }
- return *neighbors_[2];
-}
-
-void Triangle::DebugPrint()
-{
- using namespace std;
- cout << points_[0]->x << "," << points_[0]->y << " ";
- cout << points_[1]->x << "," << points_[1]->y << " ";
- cout << points_[2]->x << "," << points_[2]->y << endl;
-}
-
-}
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.h
deleted file mode 100644
index d3660f716..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/shapes.h
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// Include guard
-#ifndef SHAPES_H
-#define SHAPES_H
-
-#include <vector>
-#include <cstddef>
-#include <stdexcept>
-#include <assert.h>
-#include <cmath>
-#include <string>
-
-namespace p2t {
-
-struct Edge;
-
-struct Point {
-
- double x, y;
-
- /// Default constructor does nothing (for performance).
- Point()
- {
- x = 0.0;
- y = 0.0;
- }
-
- /// The edges this point constitutes an upper ending point
- std::vector<Edge*> edge_list;
-
- /// Construct using coordinates.
- Point(double x, double y) : x(x), y(y) {}
-
- /// Set this point to all zeros.
- void set_zero()
- {
- x = 0.0;
- y = 0.0;
- }
-
- /// Set this point to some specified coordinates.
- void set(double x_, double y_)
- {
- x = x_;
- y = y_;
- }
-
- /// Negate this point.
- Point operator -() const
- {
- Point v;
- v.set(-x, -y);
- return v;
- }
-
- /// Add a point to this point.
- void operator +=(const Point& v)
- {
- x += v.x;
- y += v.y;
- }
-
- /// Subtract a point from this point.
- void operator -=(const Point& v)
- {
- x -= v.x;
- y -= v.y;
- }
-
- /// Multiply this point by a scalar.
- void operator *=(double a)
- {
- x *= a;
- y *= a;
- }
-
- /// Get the length of this point (the norm).
- double Length() const
- {
- return sqrt(x * x + y * y);
- }
-
- /// Convert this point into a unit point. Returns the Length.
- double Normalize()
- {
- const double len = Length();
- x /= len;
- y /= len;
- return len;
- }
-
-};
-
-// Represents a simple polygon's edge
-struct Edge {
-
- Point* p, *q;
-
- /// Constructor
- Edge(Point& p1, Point& p2) : p(&p1), q(&p2)
- {
- if (p1.y > p2.y) {
- q = &p1;
- p = &p2;
- } else if (p1.y == p2.y) {
- if (p1.x > p2.x) {
- q = &p1;
- p = &p2;
- } else if (p1.x == p2.x) {
- // Repeat points
- // ASSIMP_CHANGE (aramis_acg)
- throw std::runtime_error(std::string("repeat points"));
- //assert(false);
- }
- }
-
- q->edge_list.push_back(this);
- }
-};
-
-// Triangle-based data structures are know to have better performance than quad-edge structures
-// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
-// "Triangulations in CGAL"
-class Triangle {
-public:
-
-/// Constructor
-Triangle(Point& a, Point& b, Point& c);
-
-/// Flags to determine if an edge is a Constrained edge
-bool constrained_edge[3];
-/// Flags to determine if an edge is a Delauney edge
-bool delaunay_edge[3];
-
-Point* GetPoint(int index);
-Point* PointCW(const Point& point);
-Point* PointCCW(const Point& point);
-Point* OppositePoint(Triangle& t, const Point& p);
-
-Triangle* GetNeighbor(int index);
-void MarkNeighbor(Point* p1, Point* p2, Triangle* t);
-void MarkNeighbor(Triangle& t);
-
-void MarkConstrainedEdge(int index);
-void MarkConstrainedEdge(Edge& edge);
-void MarkConstrainedEdge(Point* p, Point* q);
-
-int Index(const Point* p);
-int EdgeIndex(const Point* p1, const Point* p2);
-
-Triangle* NeighborCW(const Point& point);
-Triangle* NeighborCCW(const Point& point);
-bool GetConstrainedEdgeCCW(const Point& p);
-bool GetConstrainedEdgeCW(const Point& p);
-void SetConstrainedEdgeCCW(const Point& p, bool ce);
-void SetConstrainedEdgeCW(const Point& p, bool ce);
-bool GetDelunayEdgeCCW(const Point& p);
-bool GetDelunayEdgeCW(const Point& p);
-void SetDelunayEdgeCCW(const Point& p, bool e);
-void SetDelunayEdgeCW(const Point& p, bool e);
-
-bool Contains(const Point* p);
-bool Contains(const Edge& e);
-bool Contains(const Point* p, const Point* q);
-void Legalize(Point& point);
-void Legalize(Point& opoint, Point& npoint);
-/**
- * Clears all references to all other triangles and points
- */
-void Clear();
-void ClearNeighbor(const Triangle *triangle);
-void ClearNeighbors();
-void ClearDelunayEdges();
-
-inline bool IsInterior();
-inline void IsInterior(bool b);
-
-Triangle& NeighborAcross(const Point& opoint);
-
-void DebugPrint();
-
-private:
-
-/// Triangle points
-Point* points_[3];
-/// Neighbor list
-Triangle* neighbors_[3];
-
-/// Has this triangle been marked as an interior triangle?
-bool interior_;
-};
-
-inline bool cmp(const Point* a, const Point* b)
-{
- if (a->y < b->y) {
- return true;
- } else if (a->y == b->y) {
- // Make sure q is point with greater x value
- if (a->x < b->x) {
- return true;
- }
- }
- return false;
-}
-
-/// Add two points_ component-wise.
-inline Point operator +(const Point& a, const Point& b)
-{
- return Point(a.x + b.x, a.y + b.y);
-}
-
-/// Subtract two points_ component-wise.
-inline Point operator -(const Point& a, const Point& b)
-{
- return Point(a.x - b.x, a.y - b.y);
-}
-
-/// Multiply point by scalar
-inline Point operator *(double s, const Point& a)
-{
- return Point(s * a.x, s * a.y);
-}
-
-inline bool operator ==(const Point& a, const Point& b)
-{
- return a.x == b.x && a.y == b.y;
-}
-
-inline bool operator !=(const Point& a, const Point& b)
-{
- return !(a.x == b.x) && !(a.y == b.y);
-}
-
-/// Peform the dot product on two vectors.
-inline double Dot(const Point& a, const Point& b)
-{
- return a.x * b.x + a.y * b.y;
-}
-
-/// Perform the cross product on two vectors. In 2D this produces a scalar.
-inline double Cross(const Point& a, const Point& b)
-{
- return a.x * b.y - a.y * b.x;
-}
-
-/// Perform the cross product on a point and a scalar. In 2D this produces
-/// a point.
-inline Point Cross(const Point& a, double s)
-{
- return Point(s * a.y, -s * a.x);
-}
-
-/// Perform the cross product on a scalar and a point. In 2D this produces
-/// a point.
-inline Point Cross(double s, const Point& a)
-{
- return Point(-s * a.y, s * a.x);
-}
-
-inline Point* Triangle::GetPoint(int index)
-{
- return points_[index];
-}
-
-inline Triangle* Triangle::GetNeighbor(int index)
-{
- return neighbors_[index];
-}
-
-inline bool Triangle::Contains(const Point* p)
-{
- return p == points_[0] || p == points_[1] || p == points_[2];
-}
-
-inline bool Triangle::Contains(const Edge& e)
-{
- return Contains(e.p) && Contains(e.q);
-}
-
-inline bool Triangle::Contains(const Point* p, const Point* q)
-{
- return Contains(p) && Contains(q);
-}
-
-inline bool Triangle::IsInterior()
-{
- return interior_;
-}
-
-inline void Triangle::IsInterior(bool b)
-{
- interior_ = b;
-}
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h
deleted file mode 100644
index 2424c712c..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef UTILS_H
-#define UTILS_H
-
-// Otherwise #defines like M_PI are undeclared under Visual Studio
-#define _USE_MATH_DEFINES
-
-#include <exception>
-#include <math.h>
-
-// C99 removes M_PI from math.h
-#ifndef M_PI
-#define M_PI 3.14159265358979323846264338327
-#endif
-
-namespace p2t {
-
-const double PI_3div4 = 3 * M_PI / 4;
-const double PI_div2 = 1.57079632679489661923;
-const double EPSILON = 1e-12;
-
-enum Orientation { CW, CCW, COLLINEAR };
-
-/**
- * Forumla to calculate signed area<br>
- * Positive if CCW<br>
- * Negative if CW<br>
- * 0 if collinear<br>
- * <pre>
- * A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1)
- * = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
- * </pre>
- */
-Orientation Orient2d(const Point& pa, const Point& pb, const Point& pc)
-{
- double detleft = (pa.x - pc.x) * (pb.y - pc.y);
- double detright = (pa.y - pc.y) * (pb.x - pc.x);
- double val = detleft - detright;
- if (val > -EPSILON && val < EPSILON) {
- return COLLINEAR;
- } else if (val > 0) {
- return CCW;
- }
- return CW;
-}
-
-/*
-bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
-{
- double pdx = pd.x;
- double pdy = pd.y;
- double adx = pa.x - pdx;
- double ady = pa.y - pdy;
- double bdx = pb.x - pdx;
- double bdy = pb.y - pdy;
-
- double adxbdy = adx * bdy;
- double bdxady = bdx * ady;
- double oabd = adxbdy - bdxady;
-
- if (oabd <= EPSILON) {
- return false;
- }
-
- double cdx = pc.x - pdx;
- double cdy = pc.y - pdy;
-
- double cdxady = cdx * ady;
- double adxcdy = adx * cdy;
- double ocad = cdxady - adxcdy;
-
- if (ocad <= EPSILON) {
- return false;
- }
-
- return true;
-}
-
-*/
-
-bool InScanArea(const Point& pa, const Point& pb, const Point& pc, const Point& pd)
-{
- double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y);
- if (oadb >= -EPSILON) {
- return false;
- }
-
- double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y);
- if (oadc <= EPSILON) {
- return false;
- }
- return true;
-}
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/poly2tri.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/poly2tri.h
deleted file mode 100644
index ba5cc159e..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/poly2tri.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef POLY2TRI_H
-#define POLY2TRI_H
-
-#include "common/shapes.h"
-#include "sweep/cdt.h"
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.cc b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.cc
deleted file mode 100644
index 9739babce..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.cc
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "advancing_front.h"
-
-namespace p2t {
-
-AdvancingFront::AdvancingFront(Node& head, Node& tail)
-{
- head_ = &head;
- tail_ = &tail;
- search_node_ = &head;
-}
-
-Node* AdvancingFront::LocateNode(double x)
-{
- Node* node = search_node_;
-
- if (x < node->value) {
- while ((node = node->prev) != NULL) {
- if (x >= node->value) {
- search_node_ = node;
- return node;
- }
- }
- } else {
- while ((node = node->next) != NULL) {
- if (x < node->value) {
- search_node_ = node->prev;
- return node->prev;
- }
- }
- }
- return NULL;
-}
-
-Node* AdvancingFront::FindSearchNode(double x)
-{
- (void)x; // suppress compiler warnings "unused parameter 'x'"
- // TODO: implement BST index
- return search_node_;
-}
-
-Node* AdvancingFront::LocatePoint(const Point* point)
-{
- const double px = point->x;
- Node* node = FindSearchNode(px);
- const double nx = node->point->x;
-
- if (px == nx) {
- if (point != node->point) {
- // We might have two nodes with same x value for a short time
- if (point == node->prev->point) {
- node = node->prev;
- } else if (point == node->next->point) {
- node = node->next;
- } else {
- assert(0);
- }
- }
- } else if (px < nx) {
- while ((node = node->prev) != NULL) {
- if (point == node->point) {
- break;
- }
- }
- } else {
- while ((node = node->next) != NULL) {
- if (point == node->point)
- break;
- }
- }
- if(node) search_node_ = node;
- return node;
-}
-
-AdvancingFront::~AdvancingFront()
-{
-}
-
-}
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.h
deleted file mode 100644
index 3bfec5368..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/advancing_front.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ADVANCED_FRONT_H
-#define ADVANCED_FRONT_H
-
-#include "../common/shapes.h"
-
-namespace p2t {
-
-struct Node;
-
-// Advancing front node
-struct Node {
- Point* point;
- Triangle* triangle;
-
- Node* next;
- Node* prev;
-
- double value;
-
- Node(Point& p) : point(&p), triangle(NULL), next(NULL), prev(NULL), value(p.x)
- {
- }
-
- Node(Point& p, Triangle& t) : point(&p), triangle(&t), next(NULL), prev(NULL), value(p.x)
- {
- }
-
-};
-
-// Advancing front
-class AdvancingFront {
-public:
-
-AdvancingFront(Node& head, Node& tail);
-// Destructor
-~AdvancingFront();
-
-Node* head();
-void set_head(Node* node);
-Node* tail();
-void set_tail(Node* node);
-Node* search();
-void set_search(Node* node);
-
-/// Locate insertion point along advancing front
-Node* LocateNode(double x);
-
-Node* LocatePoint(const Point* point);
-
-private:
-
-Node* head_, *tail_, *search_node_;
-
-Node* FindSearchNode(double x);
-};
-
-inline Node* AdvancingFront::head()
-{
- return head_;
-}
-inline void AdvancingFront::set_head(Node* node)
-{
- head_ = node;
-}
-
-inline Node* AdvancingFront::tail()
-{
- return tail_;
-}
-inline void AdvancingFront::set_tail(Node* node)
-{
- tail_ = node;
-}
-
-inline Node* AdvancingFront::search()
-{
- return search_node_;
-}
-
-inline void AdvancingFront::set_search(Node* node)
-{
- search_node_ = node;
-}
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.cc b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.cc
deleted file mode 100644
index b79f5a8de..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "cdt.h"
-
-namespace p2t {
-
-CDT::CDT(const std::vector<Point*>& polyline)
-{
- sweep_context_ = new SweepContext(polyline);
- sweep_ = new Sweep;
-}
-
-void CDT::AddHole(const std::vector<Point*>& polyline)
-{
- sweep_context_->AddHole(polyline);
-}
-
-void CDT::AddPoint(Point* point) {
- sweep_context_->AddPoint(point);
-}
-
-void CDT::Triangulate()
-{
- sweep_->Triangulate(*sweep_context_);
-}
-
-std::vector<p2t::Triangle*> CDT::GetTriangles()
-{
- return sweep_context_->GetTriangles();
-}
-
-std::list<p2t::Triangle*> CDT::GetMap()
-{
- return sweep_context_->GetMap();
-}
-
-CDT::~CDT()
-{
- delete sweep_context_;
- delete sweep_;
-}
-
-}
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.h
deleted file mode 100644
index 4a9a292d3..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/cdt.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CDT_H
-#define CDT_H
-
-#include "advancing_front.h"
-#include "sweep_context.h"
-#include "sweep.h"
-
-/**
- *
- * @author Mason Green <mason.green@gmail.com>
- *
- */
-
-namespace p2t {
-
-class CDT
-{
-public:
-
- /**
- * Constructor - add polyline with non repeating points
- *
- * @param polyline
- */
- CDT(const std::vector<Point*>& polyline);
-
- /**
- * Destructor - clean up memory
- */
- ~CDT();
-
- /**
- * Add a hole
- *
- * @param polyline
- */
- void AddHole(const std::vector<Point*>& polyline);
-
- /**
- * Add a steiner point
- *
- * @param point
- */
- void AddPoint(Point* point);
-
- /**
- * Triangulate - do this AFTER you've added the polyline, holes, and Steiner points
- */
- void Triangulate();
-
- /**
- * Get CDT triangles
- */
- std::vector<Triangle*> GetTriangles();
-
- /**
- * Get triangle map
- */
- std::list<Triangle*> GetMap();
-
- private:
-
- /**
- * Internals
- */
-
- SweepContext* sweep_context_;
- Sweep* sweep_;
-
-};
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.cc b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.cc
deleted file mode 100644
index 826905ceb..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.cc
+++ /dev/null
@@ -1,799 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <stdexcept>
-#include "sweep.h"
-#include "sweep_context.h"
-#include "advancing_front.h"
-#include "../common/utils.h"
-
-namespace p2t {
-
-// Triangulate simple polygon with holes
-void Sweep::Triangulate(SweepContext& tcx)
-{
- tcx.InitTriangulation();
- tcx.CreateAdvancingFront(nodes_);
- // Sweep points; build mesh
- SweepPoints(tcx);
- // Clean up
- FinalizationPolygon(tcx);
-}
-
-void Sweep::SweepPoints(SweepContext& tcx)
-{
- for (size_t i = 1; i < tcx.point_count(); i++) {
- Point& point = *tcx.GetPoint(i);
- Node* node = &PointEvent(tcx, point);
- for (unsigned int i = 0; i < point.edge_list.size(); i++) {
- EdgeEvent(tcx, point.edge_list[i], node);
- }
- }
-}
-
-void Sweep::FinalizationPolygon(SweepContext& tcx)
-{
- // Get an Internal triangle to start with
- Triangle* t = tcx.front()->head()->next->triangle;
- Point* p = tcx.front()->head()->next->point;
- while (!t->GetConstrainedEdgeCW(*p)) {
- t = t->NeighborCCW(*p);
- }
-
- // Collect interior triangles constrained by edges
- tcx.MeshClean(*t);
-}
-
-Node& Sweep::PointEvent(SweepContext& tcx, Point& point)
-{
- Node& node = tcx.LocateNode(point);
- Node& new_node = NewFrontTriangle(tcx, point, node);
-
- // Only need to check +epsilon since point never have smaller
- // x value than node due to how we fetch nodes from the front
- if (point.x <= node.point->x + EPSILON) {
- Fill(tcx, node);
- }
-
- //tcx.AddNode(new_node);
-
- FillAdvancingFront(tcx, new_node);
- return new_node;
-}
-
-void Sweep::EdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
-{
- tcx.edge_event.constrained_edge = edge;
- tcx.edge_event.right = (edge->p->x > edge->q->x);
-
- if (IsEdgeSideOfTriangle(*node->triangle, *edge->p, *edge->q)) {
- return;
- }
-
- // For now we will do all needed filling
- // TODO: integrate with flip process might give some better performance
- // but for now this avoid the issue with cases that needs both flips and fills
- FillEdgeEvent(tcx, edge, node);
- EdgeEvent(tcx, *edge->p, *edge->q, node->triangle, *edge->q);
-}
-
-void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point)
-{
- if (IsEdgeSideOfTriangle(*triangle, ep, eq)) {
- return;
- }
-
- Point* p1 = triangle->PointCCW(point);
- Orientation o1 = Orient2d(eq, *p1, ep);
- if (o1 == COLLINEAR) {
- // ASSIMP_CHANGE (aramis_acg)
- throw std::runtime_error("EdgeEvent - collinear points not supported");
- if( triangle->Contains(&eq, p1)) {
- triangle->MarkConstrainedEdge(&eq, p1 );
- // We are modifying the constraint maybe it would be better to
- // not change the given constraint and just keep a variable for the new constraint
- tcx.edge_event.constrained_edge->q = p1;
- triangle = &triangle->NeighborAcross(point);
- EdgeEvent( tcx, ep, *p1, triangle, *p1 );
- } else {
- // ASSIMP_CHANGE (aramis_acg)
- std::runtime_error("EdgeEvent - collinear points not supported");
- }
- return;
- }
-
- Point* p2 = triangle->PointCW(point);
- Orientation o2 = Orient2d(eq, *p2, ep);
- if (o2 == COLLINEAR) {
- // ASSIMP_CHANGE (aramis_acg)
- throw std::runtime_error("EdgeEvent - collinear points not supported");
-
- if( triangle->Contains(&eq, p2)) {
- triangle->MarkConstrainedEdge(&eq, p2 );
- // We are modifying the constraint maybe it would be better to
- // not change the given constraint and just keep a variable for the new constraint
- tcx.edge_event.constrained_edge->q = p2;
- triangle = &triangle->NeighborAcross(point);
- EdgeEvent( tcx, ep, *p2, triangle, *p2 );
- } else {
- // ASSIMP_CHANGE (aramis_acg)
- throw std::runtime_error("EdgeEvent - collinear points not supported");
- }
- return;
- }
-
- if (o1 == o2) {
- // Need to decide if we are rotating CW or CCW to get to a triangle
- // that will cross edge
- if (o1 == CW) {
- triangle = triangle->NeighborCCW(point);
- } else{
- triangle = triangle->NeighborCW(point);
- }
- EdgeEvent(tcx, ep, eq, triangle, point);
- } else {
- // This triangle crosses constraint so lets flippin start!
- FlipEdgeEvent(tcx, ep, eq, triangle, point);
- }
-}
-
-bool Sweep::IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq)
-{
- const int index = triangle.EdgeIndex(&ep, &eq);
-
- if (index != -1) {
- triangle.MarkConstrainedEdge(index);
- Triangle* t = triangle.GetNeighbor(index);
- if (t) {
- t->MarkConstrainedEdge(&ep, &eq);
- }
- return true;
- }
- return false;
-}
-
-Node& Sweep::NewFrontTriangle(SweepContext& tcx, Point& point, Node& node)
-{
- Triangle* triangle = new Triangle(point, *node.point, *node.next->point);
-
- triangle->MarkNeighbor(*node.triangle);
- tcx.AddToMap(triangle);
-
- Node* new_node = new Node(point);
- nodes_.push_back(new_node);
-
- new_node->next = node.next;
- new_node->prev = &node;
- node.next->prev = new_node;
- node.next = new_node;
-
- if (!Legalize(tcx, *triangle)) {
- tcx.MapTriangleToNodes(*triangle);
- }
-
- return *new_node;
-}
-
-void Sweep::Fill(SweepContext& tcx, Node& node)
-{
- Triangle* triangle = new Triangle(*node.prev->point, *node.point, *node.next->point);
-
- // TODO: should copy the constrained_edge value from neighbor triangles
- // for now constrained_edge values are copied during the legalize
- triangle->MarkNeighbor(*node.prev->triangle);
- triangle->MarkNeighbor(*node.triangle);
-
- tcx.AddToMap(triangle);
-
- // Update the advancing front
- node.prev->next = node.next;
- node.next->prev = node.prev;
-
- // If it was legalized the triangle has already been mapped
- if (!Legalize(tcx, *triangle)) {
- tcx.MapTriangleToNodes(*triangle);
- }
-
-}
-
-void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
-{
-
- // Fill right holes
- Node* node = n.next;
-
- while (node->next) {
- // if HoleAngle exceeds 90 degrees then break.
- if (LargeHole_DontFill(node)) break;
- Fill(tcx, *node);
- node = node->next;
- }
-
- // Fill left holes
- node = n.prev;
-
- while (node->prev) {
- // if HoleAngle exceeds 90 degrees then break.
- if (LargeHole_DontFill(node)) break;
- Fill(tcx, *node);
- node = node->prev;
- }
-
- // Fill right basins
- if (n.next && n.next->next) {
- const double angle = BasinAngle(n);
- if (angle < PI_3div4) {
- FillBasin(tcx, n);
- }
- }
-}
-
-// True if HoleAngle exceeds 90 degrees.
-bool Sweep::LargeHole_DontFill(const Node* node) const {
-
- const Node* nextNode = node->next;
- const Node* prevNode = node->prev;
- if (!AngleExceeds90Degrees(node->point, nextNode->point, prevNode->point))
- return false;
-
- // Check additional points on front.
- const Node* next2Node = nextNode->next;
- // "..Plus.." because only want angles on same side as point being added.
- if ((next2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, next2Node->point, prevNode->point))
- return false;
-
- const Node* prev2Node = prevNode->prev;
- // "..Plus.." because only want angles on same side as point being added.
- if ((prev2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, nextNode->point, prev2Node->point))
- return false;
-
- return true;
-}
-
-bool Sweep::AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const {
- const double angle = Angle(origin, pa, pb);
- return ((angle > PI_div2) || (angle < -PI_div2));
-}
-
-bool Sweep::AngleExceedsPlus90DegreesOrIsNegative(const Point* origin, const Point* pa, const Point* pb) const {
- const double angle = Angle(origin, pa, pb);
- return (angle > PI_div2) || (angle < 0);
-}
-
-double Sweep::Angle(const Point* origin, const Point* pa, const Point* pb) const {
- /* Complex plane
- * ab = cosA +i*sinA
- * ab = (ax + ay*i)(bx + by*i) = (ax*bx + ay*by) + i(ax*by-ay*bx)
- * atan2(y,x) computes the principal value of the argument function
- * applied to the complex number x+iy
- * Where x = ax*bx + ay*by
- * y = ax*by - ay*bx
- */
- const double px = origin->x;
- const double py = origin->y;
- const double ax = pa->x- px;
- const double ay = pa->y - py;
- const double bx = pb->x - px;
- const double by = pb->y - py;
- const double x = ax * by - ay * bx;
- const double y = ax * bx + ay * by;
- return atan2(x, y);
-}
-
-double Sweep::BasinAngle(const Node& node) const
-{
- const double ax = node.point->x - node.next->next->point->x;
- const double ay = node.point->y - node.next->next->point->y;
- return atan2(ay, ax);
-}
-
-double Sweep::HoleAngle(const Node& node) const
-{
- /* Complex plane
- * ab = cosA +i*sinA
- * ab = (ax + ay*i)(bx + by*i) = (ax*bx + ay*by) + i(ax*by-ay*bx)
- * atan2(y,x) computes the principal value of the argument function
- * applied to the complex number x+iy
- * Where x = ax*bx + ay*by
- * y = ax*by - ay*bx
- */
- const double ax = node.next->point->x - node.point->x;
- const double ay = node.next->point->y - node.point->y;
- const double bx = node.prev->point->x - node.point->x;
- const double by = node.prev->point->y - node.point->y;
- return atan2(ax * by - ay * bx, ax * bx + ay * by);
-}
-
-bool Sweep::Legalize(SweepContext& tcx, Triangle& t)
-{
- // To legalize a triangle we start by finding if any of the three edges
- // violate the Delaunay condition
- for (int i = 0; i < 3; i++) {
- if (t.delaunay_edge[i])
- continue;
-
- Triangle* ot = t.GetNeighbor(i);
-
- if (ot) {
- Point* p = t.GetPoint(i);
- Point* op = ot->OppositePoint(t, *p);
- int oi = ot->Index(op);
-
- // If this is a Constrained Edge or a Delaunay Edge(only during recursive legalization)
- // then we should not try to legalize
- if (ot->constrained_edge[oi] || ot->delaunay_edge[oi]) {
- t.constrained_edge[i] = ot->constrained_edge[oi];
- continue;
- }
-
- bool inside = Incircle(*p, *t.PointCCW(*p), *t.PointCW(*p), *op);
-
- if (inside) {
- // Lets mark this shared edge as Delaunay
- t.delaunay_edge[i] = true;
- ot->delaunay_edge[oi] = true;
-
- // Lets rotate shared edge one vertex CW to legalize it
- RotateTrianglePair(t, *p, *ot, *op);
-
- // We now got one valid Delaunay Edge shared by two triangles
- // This gives us 4 new edges to check for Delaunay
-
- // Make sure that triangle to node mapping is done only one time for a specific triangle
- bool not_legalized = !Legalize(tcx, t);
- if (not_legalized) {
- tcx.MapTriangleToNodes(t);
- }
-
- not_legalized = !Legalize(tcx, *ot);
- if (not_legalized)
- tcx.MapTriangleToNodes(*ot);
-
- // Reset the Delaunay edges, since they only are valid Delaunay edges
- // until we add a new triangle or point.
- // XXX: need to think about this. Can these edges be tried after we
- // return to previous recursive level?
- t.delaunay_edge[i] = false;
- ot->delaunay_edge[oi] = false;
-
- // If triangle have been legalized no need to check the other edges since
- // the recursive legalization will handles those so we can end here.
- return true;
- }
- }
- }
- return false;
-}
-
-bool Sweep::Incircle(const Point& pa, const Point& pb, const Point& pc, const Point& pd) const
-{
- const double adx = pa.x - pd.x;
- const double ady = pa.y - pd.y;
- const double bdx = pb.x - pd.x;
- const double bdy = pb.y - pd.y;
-
- const double adxbdy = adx * bdy;
- const double bdxady = bdx * ady;
- const double oabd = adxbdy - bdxady;
-
- if (oabd <= 0)
- return false;
-
- const double cdx = pc.x - pd.x;
- const double cdy = pc.y - pd.y;
-
- const double cdxady = cdx * ady;
- const double adxcdy = adx * cdy;
- const double ocad = cdxady - adxcdy;
-
- if (ocad <= 0)
- return false;
-
- const double bdxcdy = bdx * cdy;
- const double cdxbdy = cdx * bdy;
-
- const double alift = adx * adx + ady * ady;
- const double blift = bdx * bdx + bdy * bdy;
- const double clift = cdx * cdx + cdy * cdy;
-
- const double det = alift * (bdxcdy - cdxbdy) + blift * ocad + clift * oabd;
-
- return det > 0;
-}
-
-void Sweep::RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) const
-{
- Triangle* n1, *n2, *n3, *n4;
- n1 = t.NeighborCCW(p);
- n2 = t.NeighborCW(p);
- n3 = ot.NeighborCCW(op);
- n4 = ot.NeighborCW(op);
-
- bool ce1, ce2, ce3, ce4;
- ce1 = t.GetConstrainedEdgeCCW(p);
- ce2 = t.GetConstrainedEdgeCW(p);
- ce3 = ot.GetConstrainedEdgeCCW(op);
- ce4 = ot.GetConstrainedEdgeCW(op);
-
- bool de1, de2, de3, de4;
- de1 = t.GetDelunayEdgeCCW(p);
- de2 = t.GetDelunayEdgeCW(p);
- de3 = ot.GetDelunayEdgeCCW(op);
- de4 = ot.GetDelunayEdgeCW(op);
-
- t.Legalize(p, op);
- ot.Legalize(op, p);
-
- // Remap delaunay_edge
- ot.SetDelunayEdgeCCW(p, de1);
- t.SetDelunayEdgeCW(p, de2);
- t.SetDelunayEdgeCCW(op, de3);
- ot.SetDelunayEdgeCW(op, de4);
-
- // Remap constrained_edge
- ot.SetConstrainedEdgeCCW(p, ce1);
- t.SetConstrainedEdgeCW(p, ce2);
- t.SetConstrainedEdgeCCW(op, ce3);
- ot.SetConstrainedEdgeCW(op, ce4);
-
- // Remap neighbors
- // XXX: might optimize the markNeighbor by keeping track of
- // what side should be assigned to what neighbor after the
- // rotation. Now mark neighbor does lots of testing to find
- // the right side.
- t.ClearNeighbors();
- ot.ClearNeighbors();
- if (n1) ot.MarkNeighbor(*n1);
- if (n2) t.MarkNeighbor(*n2);
- if (n3) t.MarkNeighbor(*n3);
- if (n4) ot.MarkNeighbor(*n4);
- t.MarkNeighbor(ot);
-}
-
-void Sweep::FillBasin(SweepContext& tcx, Node& node)
-{
- if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) {
- tcx.basin.left_node = node.next->next;
- } else {
- tcx.basin.left_node = node.next;
- }
-
- // Find the bottom and right node
- tcx.basin.bottom_node = tcx.basin.left_node;
- while (tcx.basin.bottom_node->next
- && tcx.basin.bottom_node->point->y >= tcx.basin.bottom_node->next->point->y) {
- tcx.basin.bottom_node = tcx.basin.bottom_node->next;
- }
- if (tcx.basin.bottom_node == tcx.basin.left_node) {
- // No valid basin
- return;
- }
-
- tcx.basin.right_node = tcx.basin.bottom_node;
- while (tcx.basin.right_node->next
- && tcx.basin.right_node->point->y < tcx.basin.right_node->next->point->y) {
- tcx.basin.right_node = tcx.basin.right_node->next;
- }
- if (tcx.basin.right_node == tcx.basin.bottom_node) {
- // No valid basins
- return;
- }
-
- tcx.basin.width = tcx.basin.right_node->point->x - tcx.basin.left_node->point->x;
- tcx.basin.left_highest = tcx.basin.left_node->point->y > tcx.basin.right_node->point->y;
-
- FillBasinReq(tcx, tcx.basin.bottom_node);
-}
-
-void Sweep::FillBasinReq(SweepContext& tcx, Node* node)
-{
- // if shallow stop filling
- if (IsShallow(tcx, *node)) {
- return;
- }
-
- Fill(tcx, *node);
-
- if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) {
- return;
- } else if (node->prev == tcx.basin.left_node) {
- Orientation o = Orient2d(*node->point, *node->next->point, *node->next->next->point);
- if (o == CW) {
- return;
- }
- node = node->next;
- } else if (node->next == tcx.basin.right_node) {
- Orientation o = Orient2d(*node->point, *node->prev->point, *node->prev->prev->point);
- if (o == CCW) {
- return;
- }
- node = node->prev;
- } else {
- // Continue with the neighbor node with lowest Y value
- if (node->prev->point->y < node->next->point->y) {
- node = node->prev;
- } else {
- node = node->next;
- }
- }
-
- FillBasinReq(tcx, node);
-}
-
-bool Sweep::IsShallow(SweepContext& tcx, Node& node)
-{
- double height;
-
- if (tcx.basin.left_highest) {
- height = tcx.basin.left_node->point->y - node.point->y;
- } else {
- height = tcx.basin.right_node->point->y - node.point->y;
- }
-
- // if shallow stop filling
- if (tcx.basin.width > height) {
- return true;
- }
- return false;
-}
-
-void Sweep::FillEdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
-{
- if (tcx.edge_event.right) {
- FillRightAboveEdgeEvent(tcx, edge, node);
- } else {
- FillLeftAboveEdgeEvent(tcx, edge, node);
- }
-}
-
-void Sweep::FillRightAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
-{
- while (node->next->point->x < edge->p->x) {
- // Check if next node is below the edge
- if (Orient2d(*edge->q, *node->next->point, *edge->p) == CCW) {
- FillRightBelowEdgeEvent(tcx, edge, *node);
- } else {
- node = node->next;
- }
- }
-}
-
-void Sweep::FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- if (node.point->x < edge->p->x) {
- if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) {
- // Concave
- FillRightConcaveEdgeEvent(tcx, edge, node);
- } else{
- // Convex
- FillRightConvexEdgeEvent(tcx, edge, node);
- // Retry this one
- FillRightBelowEdgeEvent(tcx, edge, node);
- }
- }
-}
-
-void Sweep::FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- Fill(tcx, *node.next);
- if (node.next->point != edge->p) {
- // Next above or below edge?
- if (Orient2d(*edge->q, *node.next->point, *edge->p) == CCW) {
- // Below
- if (Orient2d(*node.point, *node.next->point, *node.next->next->point) == CCW) {
- // Next is concave
- FillRightConcaveEdgeEvent(tcx, edge, node);
- } else {
- // Next is convex
- }
- }
- }
-
-}
-
-void Sweep::FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- // Next concave or convex?
- if (Orient2d(*node.next->point, *node.next->next->point, *node.next->next->next->point) == CCW) {
- // Concave
- FillRightConcaveEdgeEvent(tcx, edge, *node.next);
- } else{
- // Convex
- // Next above or below edge?
- if (Orient2d(*edge->q, *node.next->next->point, *edge->p) == CCW) {
- // Below
- FillRightConvexEdgeEvent(tcx, edge, *node.next);
- } else{
- // Above
- }
- }
-}
-
-void Sweep::FillLeftAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
-{
- while (node->prev->point->x > edge->p->x) {
- // Check if next node is below the edge
- if (Orient2d(*edge->q, *node->prev->point, *edge->p) == CW) {
- FillLeftBelowEdgeEvent(tcx, edge, *node);
- } else {
- node = node->prev;
- }
- }
-}
-
-void Sweep::FillLeftBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- if (node.point->x > edge->p->x) {
- if (Orient2d(*node.point, *node.prev->point, *node.prev->prev->point) == CW) {
- // Concave
- FillLeftConcaveEdgeEvent(tcx, edge, node);
- } else {
- // Convex
- FillLeftConvexEdgeEvent(tcx, edge, node);
- // Retry this one
- FillLeftBelowEdgeEvent(tcx, edge, node);
- }
- }
-}
-
-void Sweep::FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- // Next concave or convex?
- if (Orient2d(*node.prev->point, *node.prev->prev->point, *node.prev->prev->prev->point) == CW) {
- // Concave
- FillLeftConcaveEdgeEvent(tcx, edge, *node.prev);
- } else{
- // Convex
- // Next above or below edge?
- if (Orient2d(*edge->q, *node.prev->prev->point, *edge->p) == CW) {
- // Below
- FillLeftConvexEdgeEvent(tcx, edge, *node.prev);
- } else{
- // Above
- }
- }
-}
-
-void Sweep::FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
-{
- Fill(tcx, *node.prev);
- if (node.prev->point != edge->p) {
- // Next above or below edge?
- if (Orient2d(*edge->q, *node.prev->point, *edge->p) == CW) {
- // Below
- if (Orient2d(*node.point, *node.prev->point, *node.prev->prev->point) == CW) {
- // Next is concave
- FillLeftConcaveEdgeEvent(tcx, edge, node);
- } else{
- // Next is convex
- }
- }
- }
-
-}
-
-void Sweep::FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* t, Point& p)
-{
- Triangle& ot = t->NeighborAcross(p);
- Point& op = *ot.OppositePoint(*t, p);
-
- if (InScanArea(p, *t->PointCCW(p), *t->PointCW(p), op)) {
- // Lets rotate shared edge one vertex CW
- RotateTrianglePair(*t, p, ot, op);
- tcx.MapTriangleToNodes(*t);
- tcx.MapTriangleToNodes(ot);
-
- if (p == eq && op == ep) {
- if (eq == *tcx.edge_event.constrained_edge->q && ep == *tcx.edge_event.constrained_edge->p) {
- t->MarkConstrainedEdge(&ep, &eq);
- ot.MarkConstrainedEdge(&ep, &eq);
- Legalize(tcx, *t);
- Legalize(tcx, ot);
- } else {
- // XXX: I think one of the triangles should be legalized here?
- }
- } else {
- Orientation o = Orient2d(eq, op, ep);
- t = &NextFlipTriangle(tcx, (int)o, *t, ot, p, op);
- FlipEdgeEvent(tcx, ep, eq, t, p);
- }
- } else {
- Point& newP = NextFlipPoint(ep, eq, ot, op);
- FlipScanEdgeEvent(tcx, ep, eq, *t, ot, newP);
- EdgeEvent(tcx, ep, eq, t, p);
- }
-}
-
-Triangle& Sweep::NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op)
-{
- if (o == CCW) {
- // ot is not crossing edge after flip
- int edge_index = ot.EdgeIndex(&p, &op);
- ot.delaunay_edge[edge_index] = true;
- Legalize(tcx, ot);
- ot.ClearDelunayEdges();
- return t;
- }
-
- // t is not crossing edge after flip
- int edge_index = t.EdgeIndex(&p, &op);
-
- t.delaunay_edge[edge_index] = true;
- Legalize(tcx, t);
- t.ClearDelunayEdges();
- return ot;
-}
-
-Point& Sweep::NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op)
-{
- Orientation o2d = Orient2d(eq, op, ep);
- if (o2d == CW) {
- // Right
- return *ot.PointCCW(op);
- } else if (o2d == CCW) {
- // Left
- return *ot.PointCW(op);
- }
- throw std::runtime_error("[Unsupported] Opposing point on constrained edge");
-}
-
-void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle,
- Triangle& t, Point& p)
-{
- Triangle& ot = t.NeighborAcross(p);
- Point& op = *ot.OppositePoint(t, p);
-
- if (InScanArea(eq, *flip_triangle.PointCCW(eq), *flip_triangle.PointCW(eq), op)) {
- // flip with new edge op->eq
- FlipEdgeEvent(tcx, eq, op, &ot, op);
- // TODO: Actually I just figured out that it should be possible to
- // improve this by getting the next ot and op before the the above
- // flip and continue the flipScanEdgeEvent here
- // set new ot and op here and loop back to inScanArea test
- // also need to set a new flip_triangle first
- // Turns out at first glance that this is somewhat complicated
- // so it will have to wait.
- } else{
- Point& newP = NextFlipPoint(ep, eq, ot, op);
- FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP);
- }
-}
-
-Sweep::~Sweep() {
-
- // Clean up memory
- for(size_t i = 0; i < nodes_.size(); i++) {
- delete nodes_[i];
- }
-
-}
-
-}
-
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.h
deleted file mode 100644
index ad429fd96..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep.h
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/**
- * Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V. and
- * Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation',
- * International Journal of Geographical Information Science
- *
- * "FlipScan" Constrained Edge Algorithm invented by Thomas ?hl?n, thahlen@gmail.com
- */
-
-#ifndef SWEEP_H
-#define SWEEP_H
-
-#include <vector>
-
-namespace p2t {
-
-class SweepContext;
-struct Node;
-struct Point;
-struct Edge;
-class Triangle;
-
-class Sweep
-{
-public:
-
- /**
- * Triangulate
- *
- * @param tcx
- */
- void Triangulate(SweepContext& tcx);
-
- /**
- * Destructor - clean up memory
- */
- ~Sweep();
-
-private:
-
- /**
- * Start sweeping the Y-sorted point set from bottom to top
- *
- * @param tcx
- */
- void SweepPoints(SweepContext& tcx);
-
- /**
- * Find closes node to the left of the new point and
- * create a new triangle. If needed new holes and basins
- * will be filled to.
- *
- * @param tcx
- * @param point
- * @return
- */
- Node& PointEvent(SweepContext& tcx, Point& point);
-
- /**
- *
- *
- * @param tcx
- * @param edge
- * @param node
- */
- void EdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
-
- void EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point);
-
- /**
- * Creates a new front triangle and legalize it
- *
- * @param tcx
- * @param point
- * @param node
- * @return
- */
- Node& NewFrontTriangle(SweepContext& tcx, Point& point, Node& node);
-
- /**
- * Adds a triangle to the advancing front to fill a hole.
- * @param tcx
- * @param node - middle node, that is the bottom of the hole
- */
- void Fill(SweepContext& tcx, Node& node);
-
- /**
- * Returns true if triangle was legalized
- */
- bool Legalize(SweepContext& tcx, Triangle& t);
-
- /**
- * <b>Requirement</b>:<br>
- * 1. a,b and c form a triangle.<br>
- * 2. a and d is know to be on opposite side of bc<br>
- * <pre>
- * a
- * +
- * / \
- * / \
- * b/ \c
- * +-------+
- * / d \
- * / \
- * </pre>
- * <b>Fact</b>: d has to be in area B to have a chance to be inside the circle formed by
- * a,b and c<br>
- * d is outside B if orient2d(a,b,d) or orient2d(c,a,d) is CW<br>
- * This preknowledge gives us a way to optimize the incircle test
- * @param a - triangle point, opposite d
- * @param b - triangle point
- * @param c - triangle point
- * @param d - point opposite a
- * @return true if d is inside circle, false if on circle edge
- */
- bool Incircle(const Point& pa, const Point& pb, const Point& pc, const Point& pd) const;
-
- /**
- * Rotates a triangle pair one vertex CW
- *<pre>
- * n2 n2
- * P +-----+ P +-----+
- * | t /| |\ t |
- * | / | | \ |
- * n1| / |n3 n1| \ |n3
- * | / | after CW | \ |
- * |/ oT | | oT \|
- * +-----+ oP +-----+
- * n4 n4
- * </pre>
- */
- void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) const;
-
- /**
- * Fills holes in the Advancing Front
- *
- *
- * @param tcx
- * @param n
- */
- void FillAdvancingFront(SweepContext& tcx, Node& n);
-
- // Decision-making about when to Fill hole.
- // Contributed by ToolmakerSteve2
- bool LargeHole_DontFill(const Node* node) const;
- bool AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const;
- bool AngleExceedsPlus90DegreesOrIsNegative(const Point* origin, const Point* pa, const Point* pb) const;
- double Angle(const Point* origin, const Point* pa, const Point* pb) const;
-
- /**
- *
- * @param node - middle node
- * @return the angle between 3 front nodes
- */
- double HoleAngle(const Node& node) const;
-
- /**
- * The basin angle is decided against the horizontal line [1,0]
- */
- double BasinAngle(const Node& node) const;
-
- /**
- * Fills a basin that has formed on the Advancing Front to the right
- * of given node.<br>
- * First we decide a left,bottom and right node that forms the
- * boundaries of the basin. Then we do a reqursive fill.
- *
- * @param tcx
- * @param node - starting node, this or next node will be left node
- */
- void FillBasin(SweepContext& tcx, Node& node);
-
- /**
- * Recursive algorithm to fill a Basin with triangles
- *
- * @param tcx
- * @param node - bottom_node
- * @param cnt - counter used to alternate on even and odd numbers
- */
- void FillBasinReq(SweepContext& tcx, Node* node);
-
- bool IsShallow(SweepContext& tcx, Node& node);
-
- bool IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq);
-
- void FillEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
-
- void FillRightAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
-
- void FillRightBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FillRightConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FillLeftAboveEdgeEvent(SweepContext& tcx, Edge* edge, Node* node);
-
- void FillLeftBelowEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FillLeftConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FillLeftConvexEdgeEvent(SweepContext& tcx, Edge* edge, Node& node);
-
- void FlipEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* t, Point& p);
-
- /**
- * After a flip we have two triangles and know that only one will still be
- * intersecting the edge. So decide which to contiune with and legalize the other
- *
- * @param tcx
- * @param o - should be the result of an orient2d( eq, op, ep )
- * @param t - triangle 1
- * @param ot - triangle 2
- * @param p - a point shared by both triangles
- * @param op - another point shared by both triangles
- * @return returns the triangle still intersecting the edge
- */
- Triangle& NextFlipTriangle(SweepContext& tcx, int o, Triangle& t, Triangle& ot, Point& p, Point& op);
-
- /**
- * When we need to traverse from one triangle to the next we need
- * the point in current triangle that is the opposite point to the next
- * triangle.
- *
- * @param ep
- * @param eq
- * @param ot
- * @param op
- * @return
- */
- Point& NextFlipPoint(Point& ep, Point& eq, Triangle& ot, Point& op);
-
- /**
- * Scan part of the FlipScan algorithm<br>
- * When a triangle pair isn't flippable we will scan for the next
- * point that is inside the flip triangle scan area. When found
- * we generate a new flipEdgeEvent
- *
- * @param tcx
- * @param ep - last point on the edge we are traversing
- * @param eq - first point on the edge we are traversing
- * @param flipTriangle - the current triangle sharing the point eq with edge
- * @param t
- * @param p
- */
- void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_triangle, Triangle& t, Point& p);
-
- void FinalizationPolygon(SweepContext& tcx);
-
- std::vector<Node*> nodes_;
-
-};
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.cc b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.cc
deleted file mode 100644
index a9f1fdf8e..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.cc
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "sweep_context.h"
-#include <algorithm>
-#include "advancing_front.h"
-
-namespace p2t {
-
-SweepContext::SweepContext(const std::vector<Point*>& polyline) : points_(polyline),
- front_(0),
- head_(0),
- tail_(0),
- af_head_(0),
- af_middle_(0),
- af_tail_(0)
-{
- InitEdges(points_);
-}
-
-void SweepContext::AddHole(const std::vector<Point*>& polyline)
-{
- InitEdges(polyline);
- for(unsigned int i = 0; i < polyline.size(); i++) {
- points_.push_back(polyline[i]);
- }
-}
-
-void SweepContext::AddPoint(Point* point) {
- points_.push_back(point);
-}
-
-std::vector<Triangle*> &SweepContext::GetTriangles()
-{
- return triangles_;
-}
-
-std::list<Triangle*> &SweepContext::GetMap()
-{
- return map_;
-}
-
-void SweepContext::InitTriangulation()
-{
- double xmax(points_[0]->x), xmin(points_[0]->x);
- double ymax(points_[0]->y), ymin(points_[0]->y);
-
- // Calculate bounds.
- for (unsigned int i = 0; i < points_.size(); i++) {
- Point& p = *points_[i];
- if (p.x > xmax)
- xmax = p.x;
- if (p.x < xmin)
- xmin = p.x;
- if (p.y > ymax)
- ymax = p.y;
- if (p.y < ymin)
- ymin = p.y;
- }
-
- double dx = kAlpha * (xmax - xmin);
- double dy = kAlpha * (ymax - ymin);
- head_ = new Point(xmax + dx, ymin - dy);
- tail_ = new Point(xmin - dx, ymin - dy);
-
- // Sort points along y-axis
- std::sort(points_.begin(), points_.end(), cmp);
-
-}
-
-void SweepContext::InitEdges(const std::vector<Point*>& polyline)
-{
- size_t num_points = polyline.size();
- for (size_t i = 0; i < num_points; i++) {
- size_t j = i < num_points - 1 ? i + 1 : 0;
- edge_list.push_back(new Edge(*polyline[i], *polyline[j]));
- }
-}
-
-Point* SweepContext::GetPoint(size_t index)
-{
- return points_[index];
-}
-
-void SweepContext::AddToMap(Triangle* triangle)
-{
- map_.push_back(triangle);
-}
-
-Node& SweepContext::LocateNode(const Point& point)
-{
- // TODO implement search tree
- return *front_->LocateNode(point.x);
-}
-
-void SweepContext::CreateAdvancingFront(const std::vector<Node*>& nodes)
-{
-
- (void) nodes;
- // Initial triangle
- Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
-
- map_.push_back(triangle);
-
- af_head_ = new Node(*triangle->GetPoint(1), *triangle);
- af_middle_ = new Node(*triangle->GetPoint(0), *triangle);
- af_tail_ = new Node(*triangle->GetPoint(2));
- front_ = new AdvancingFront(*af_head_, *af_tail_);
-
- // TODO: More intuitive if head is middles next and not previous?
- // so swap head and tail
- af_head_->next = af_middle_;
- af_middle_->next = af_tail_;
- af_middle_->prev = af_head_;
- af_tail_->prev = af_middle_;
-}
-
-void SweepContext::RemoveNode(Node* node)
-{
- delete node;
-}
-
-void SweepContext::MapTriangleToNodes(Triangle& t)
-{
- for (int i = 0; i < 3; i++) {
- if (!t.GetNeighbor(i)) {
- Node* n = front_->LocatePoint(t.PointCW(*t.GetPoint(i)));
- if (n)
- n->triangle = &t;
- }
- }
-}
-
-void SweepContext::RemoveFromMap(Triangle* triangle)
-{
- map_.remove(triangle);
-}
-
-void SweepContext::MeshClean(Triangle& triangle)
-{
- std::vector<Triangle *> triangles;
- triangles.push_back(&triangle);
-
- while(!triangles.empty()){
- Triangle *t = triangles.back();
- triangles.pop_back();
-
- if (t != NULL && !t->IsInterior()) {
- t->IsInterior(true);
- triangles_.push_back(t);
- for (int i = 0; i < 3; i++) {
- if (!t->constrained_edge[i])
- triangles.push_back(t->GetNeighbor(i));
- }
- }
- }
-}
-
-SweepContext::~SweepContext()
-{
-
- // Clean up memory
-
- delete head_;
- delete tail_;
- delete front_;
- delete af_head_;
- delete af_middle_;
- delete af_tail_;
-
- typedef std::list<Triangle*> type_list;
-
- for(type_list::iterator iter = map_.begin(); iter != map_.end(); ++iter) {
- Triangle* ptr = *iter;
- delete ptr;
- }
-
- for(unsigned int i = 0; i < edge_list.size(); i++) {
- delete edge_list[i];
- }
-
-}
-
-}
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.h
deleted file mode 100644
index ba0d06581..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/sweep/sweep_context.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
- * http://code.google.com/p/poly2tri/
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Poly2Tri nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SWEEP_CONTEXT_H
-#define SWEEP_CONTEXT_H
-
-#include <list>
-#include <vector>
-#include <cstddef>
-
-namespace p2t {
-
-// Inital triangle factor, seed triangle will extend 30% of
-// PointSet width to both left and right.
-const double kAlpha = 0.3;
-
-struct Point;
-class Triangle;
-struct Node;
-struct Edge;
-class AdvancingFront;
-
-class SweepContext {
-public:
-
-/// Constructor
-SweepContext(const std::vector<Point*>& polyline);
-/// Destructor
-~SweepContext();
-
-void set_head(Point* p1);
-
-Point* head() const;
-
-void set_tail(Point* p1);
-
-Point* tail() const;
-
-size_t point_count() const;
-
-Node& LocateNode(const Point& point);
-
-void RemoveNode(Node* node);
-
-void CreateAdvancingFront(const std::vector<Node*>& nodes);
-
-/// Try to map a node to all sides of this triangle that don't have a neighbor
-void MapTriangleToNodes(Triangle& t);
-
-void AddToMap(Triangle* triangle);
-
-Point* GetPoint(size_t index);
-
-Point* GetPoints();
-
-void RemoveFromMap(Triangle* triangle);
-
-void AddHole(const std::vector<Point*>& polyline);
-
-void AddPoint(Point* point);
-
-AdvancingFront* front() const;
-
-void MeshClean(Triangle& triangle);
-
-std::vector<Triangle*> &GetTriangles();
-std::list<Triangle*> &GetMap();
-
-std::vector<Edge*> edge_list;
-
-struct Basin {
- Node* left_node;
- Node* bottom_node;
- Node* right_node;
- double width;
- bool left_highest;
-
- Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
- {
- }
-
- void Clear()
- {
- left_node = NULL;
- bottom_node = NULL;
- right_node = NULL;
- width = 0.0;
- left_highest = false;
- }
-};
-
-struct EdgeEvent {
- Edge* constrained_edge;
- bool right;
-
- EdgeEvent() : constrained_edge(NULL), right(false)
- {
- }
-};
-
-Basin basin;
-EdgeEvent edge_event;
-
-private:
-
-friend class Sweep;
-
-std::vector<Triangle*> triangles_;
-std::list<Triangle*> map_;
-std::vector<Point*> points_;
-
-// Advancing front
-AdvancingFront* front_;
-// head point used with advancing front
-Point* head_;
-// tail point used with advancing front
-Point* tail_;
-
-Node *af_head_, *af_middle_, *af_tail_;
-
-void InitTriangulation();
-void InitEdges(const std::vector<Point*>& polyline);
-
-};
-
-inline AdvancingFront* SweepContext::front() const
-{
- return front_;
-}
-
-inline size_t SweepContext::point_count() const
-{
- return points_.size();
-}
-
-inline void SweepContext::set_head(Point* p1)
-{
- head_ = p1;
-}
-
-inline Point* SweepContext::head() const
-{
- return head_;
-}
-
-inline void SweepContext::set_tail(Point* p1)
-{
- tail_ = p1;
-}
-
-inline Point* SweepContext::tail() const
-{
- return tail_;
-}
-
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/poly2tri_patch.txt b/src/3rdparty/assimp/contrib/poly2tri_patch.txt
deleted file mode 100644
index e9cca4cec..000000000
--- a/src/3rdparty/assimp/contrib/poly2tri_patch.txt
+++ /dev/null
@@ -1,75 +0,0 @@
-diff -r 5de9623d6a50 poly2tri/common/shapes.h
---- a/poly2tri/common/shapes.h Mon Aug 08 22:26:41 2011 -0400
-+++ b/poly2tri/common/shapes.h Tue Jan 17 02:36:52 2012 +0100
-@@ -35,6 +35,7 @@
-
- #include <vector>
- #include <cstddef>
-+#include <stdexcept>
- #include <assert.h>
- #include <cmath>
-
-@@ -136,7 +137,9 @@
- p = &p2;
- } else if (p1.x == p2.x) {
- // Repeat points
-- assert(false);
-+ // ASSIMP_CHANGE (aramis_acg)
-+ throw std::runtime_error("repeat points");
-+ //assert(false);
- }
- }
-
-diff -r 5de9623d6a50 poly2tri/sweep/sweep.cc
---- a/poly2tri/sweep/sweep.cc Mon Aug 08 22:26:41 2011 -0400
-+++ b/poly2tri/sweep/sweep.cc Tue Jan 17 02:36:52 2012 +0100
-@@ -113,6 +113,8 @@
- Point* p1 = triangle->PointCCW(point);
- Orientation o1 = Orient2d(eq, *p1, ep);
- if (o1 == COLLINEAR) {
-+ // ASSIMP_CHANGE (aramis_acg)
-+ throw std::runtime_error("EdgeEvent - collinear points not supported");
- if( triangle->Contains(&eq, p1)) {
- triangle->MarkConstrainedEdge(&eq, p1 );
- // We are modifying the constraint maybe it would be better to
-@@ -121,8 +123,8 @@
- triangle = &triangle->NeighborAcross(point);
- EdgeEvent( tcx, ep, *p1, triangle, *p1 );
- } else {
-+ // ASSIMP_CHANGE (aramis_acg)
- std::runtime_error("EdgeEvent - collinear points not supported");
-- assert(0);
- }
- return;
- }
-@@ -130,6 +132,9 @@
- Point* p2 = triangle->PointCW(point);
- Orientation o2 = Orient2d(eq, *p2, ep);
- if (o2 == COLLINEAR) {
-+ // ASSIMP_CHANGE (aramis_acg)
-+ throw std::runtime_error("EdgeEvent - collinear points not supported");
-+
- if( triangle->Contains(&eq, p2)) {
- triangle->MarkConstrainedEdge(&eq, p2 );
- // We are modifying the constraint maybe it would be better to
-@@ -138,8 +143,8 @@
- triangle = &triangle->NeighborAcross(point);
- EdgeEvent( tcx, ep, *p2, triangle, *p2 );
- } else {
-- std::runtime_error("EdgeEvent - collinear points not supported");
-- assert(0);
-+ // ASSIMP_CHANGE (aramis_acg)
-+ throw std::runtime_error("EdgeEvent - collinear points not supported");
- }
- return;
- }
-@@ -712,7 +717,8 @@
- return *ot.PointCW(op);
- } else{
- //throw new RuntimeException("[Unsupported] Opposing point on constrained edge");
-- assert(0);
-+ // ASSIMP_CHANGE (aramis_acg)
-+ throw std::runtime_error("[Unsupported] Opposing point on constrained edge");
- }
- }
-
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/allocators.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/allocators.h
deleted file mode 100644
index 655f4a385..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/allocators.h
+++ /dev/null
@@ -1,271 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ALLOCATORS_H_
-#define RAPIDJSON_ALLOCATORS_H_
-
-#include "rapidjson.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// Allocator
-
-/*! \class rapidjson::Allocator
- \brief Concept for allocating, resizing and freeing memory block.
-
- Note that Malloc() and Realloc() are non-static but Free() is static.
-
- So if an allocator need to support Free(), it needs to put its pointer in
- the header of memory block.
-
-\code
-concept Allocator {
- static const bool kNeedFree; //!< Whether this allocator needs to call Free().
-
- // Allocate a memory block.
- // \param size of the memory block in bytes.
- // \returns pointer to the memory block.
- void* Malloc(size_t size);
-
- // Resize a memory block.
- // \param originalPtr The pointer to current memory block. Null pointer is permitted.
- // \param originalSize The current size in bytes. (Design issue: since some allocator may not book-keep this, explicitly pass to it can save memory.)
- // \param newSize the new size in bytes.
- void* Realloc(void* originalPtr, size_t originalSize, size_t newSize);
-
- // Free a memory block.
- // \param pointer to the memory block. Null pointer is permitted.
- static void Free(void *ptr);
-};
-\endcode
-*/
-
-///////////////////////////////////////////////////////////////////////////////
-// CrtAllocator
-
-//! C-runtime library allocator.
-/*! This class is just wrapper for standard C library memory routines.
- \note implements Allocator concept
-*/
-class CrtAllocator {
-public:
- static const bool kNeedFree = true;
- void* Malloc(size_t size) {
- if (size) // behavior of malloc(0) is implementation defined.
- return std::malloc(size);
- else
- return NULL; // standardize to returning NULL.
- }
- void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
- (void)originalSize;
- if (newSize == 0) {
- std::free(originalPtr);
- return NULL;
- }
- return std::realloc(originalPtr, newSize);
- }
- static void Free(void *ptr) { std::free(ptr); }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// MemoryPoolAllocator
-
-//! Default memory allocator used by the parser and DOM.
-/*! This allocator allocate memory blocks from pre-allocated memory chunks.
-
- It does not free memory blocks. And Realloc() only allocate new memory.
-
- The memory chunks are allocated by BaseAllocator, which is CrtAllocator by default.
-
- User may also supply a buffer as the first chunk.
-
- If the user-buffer is full then additional chunks are allocated by BaseAllocator.
-
- The user-buffer is not deallocated by this allocator.
-
- \tparam BaseAllocator the allocator type for allocating memory chunks. Default is CrtAllocator.
- \note implements Allocator concept
-*/
-template <typename BaseAllocator = CrtAllocator>
-class MemoryPoolAllocator {
-public:
- static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator)
-
- //! Constructor with chunkSize.
- /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize.
- \param baseAllocator The allocator for allocating memory chunks.
- */
- MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) :
- chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0)
- {
- }
-
- //! Constructor with user-supplied buffer.
- /*! The user buffer will be used firstly. When it is full, memory pool allocates new chunk with chunk size.
-
- The user buffer will not be deallocated when this allocator is destructed.
-
- \param buffer User supplied buffer.
- \param size Size of the buffer in bytes. It must at least larger than sizeof(ChunkHeader).
- \param chunkSize The size of memory chunk. The default is kDefaultChunkSize.
- \param baseAllocator The allocator for allocating memory chunks.
- */
- MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) :
- chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer), baseAllocator_(baseAllocator), ownBaseAllocator_(0)
- {
- RAPIDJSON_ASSERT(buffer != 0);
- RAPIDJSON_ASSERT(size > sizeof(ChunkHeader));
- chunkHead_ = reinterpret_cast<ChunkHeader*>(buffer);
- chunkHead_->capacity = size - sizeof(ChunkHeader);
- chunkHead_->size = 0;
- chunkHead_->next = 0;
- }
-
- //! Destructor.
- /*! This deallocates all memory chunks, excluding the user-supplied buffer.
- */
- ~MemoryPoolAllocator() {
- Clear();
- RAPIDJSON_DELETE(ownBaseAllocator_);
- }
-
- //! Deallocates all memory chunks, excluding the user-supplied buffer.
- void Clear() {
- while (chunkHead_ && chunkHead_ != userBuffer_) {
- ChunkHeader* next = chunkHead_->next;
- baseAllocator_->Free(chunkHead_);
- chunkHead_ = next;
- }
- if (chunkHead_ && chunkHead_ == userBuffer_)
- chunkHead_->size = 0; // Clear user buffer
- }
-
- //! Computes the total capacity of allocated memory chunks.
- /*! \return total capacity in bytes.
- */
- size_t Capacity() const {
- size_t capacity = 0;
- for (ChunkHeader* c = chunkHead_; c != 0; c = c->next)
- capacity += c->capacity;
- return capacity;
- }
-
- //! Computes the memory blocks allocated.
- /*! \return total used bytes.
- */
- size_t Size() const {
- size_t size = 0;
- for (ChunkHeader* c = chunkHead_; c != 0; c = c->next)
- size += c->size;
- return size;
- }
-
- //! Allocates a memory block. (concept Allocator)
- void* Malloc(size_t size) {
- if (!size)
- return NULL;
-
- size = RAPIDJSON_ALIGN(size);
- if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
- if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size))
- return NULL;
-
- void *buffer = reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size;
- chunkHead_->size += size;
- return buffer;
- }
-
- //! Resizes a memory block (concept Allocator)
- void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
- if (originalPtr == 0)
- return Malloc(newSize);
-
- if (newSize == 0)
- return NULL;
-
- originalSize = RAPIDJSON_ALIGN(originalSize);
- newSize = RAPIDJSON_ALIGN(newSize);
-
- // Do not shrink if new size is smaller than original
- if (originalSize >= newSize)
- return originalPtr;
-
- // Simply expand it if it is the last allocation and there is sufficient space
- if (originalPtr == reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) {
- size_t increment = static_cast<size_t>(newSize - originalSize);
- if (chunkHead_->size + increment <= chunkHead_->capacity) {
- chunkHead_->size += increment;
- return originalPtr;
- }
- }
-
- // Realloc process: allocate and copy memory, do not free original buffer.
- if (void* newBuffer = Malloc(newSize)) {
- if (originalSize)
- std::memcpy(newBuffer, originalPtr, originalSize);
- return newBuffer;
- }
- else
- return NULL;
- }
-
- //! Frees a memory block (concept Allocator)
- static void Free(void *ptr) { (void)ptr; } // Do nothing
-
-private:
- //! Copy constructor is not permitted.
- MemoryPoolAllocator(const MemoryPoolAllocator& rhs) /* = delete */;
- //! Copy assignment operator is not permitted.
- MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) /* = delete */;
-
- //! Creates a new chunk.
- /*! \param capacity Capacity of the chunk in bytes.
- \return true if success.
- */
- bool AddChunk(size_t capacity) {
- if (!baseAllocator_)
- ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)();
- if (ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) {
- chunk->capacity = capacity;
- chunk->size = 0;
- chunk->next = chunkHead_;
- chunkHead_ = chunk;
- return true;
- }
- else
- return false;
- }
-
- static const int kDefaultChunkCapacity = 64 * 1024; //!< Default chunk capacity.
-
- //! Chunk header for perpending to each chunk.
- /*! Chunks are stored as a singly linked list.
- */
- struct ChunkHeader {
- size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself).
- size_t size; //!< Current size of allocated memory in bytes.
- ChunkHeader *next; //!< Next chunk in the linked list.
- };
-
- ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head chunk serves allocation.
- size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated.
- void *userBuffer_; //!< User supplied buffer.
- BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks.
- BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object.
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_ENCODINGS_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/document.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/document.h
deleted file mode 100644
index 93b091f64..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/document.h
+++ /dev/null
@@ -1,2613 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_DOCUMENT_H_
-#define RAPIDJSON_DOCUMENT_H_
-
-/*! \file document.h */
-
-#include "reader.h"
-#include "internal/meta.h"
-#include "internal/strfunc.h"
-#include "memorystream.h"
-#include "encodedstream.h"
-#include <new> // placement new
-#include <limits>
-
-RAPIDJSON_DIAG_PUSH
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
-RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_OFF(padded)
-RAPIDJSON_DIAG_OFF(switch-enum)
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_OFF(effc++)
-#if __GNUC__ >= 6
-RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_NOEXCEPT functions
-#endif
-#endif // __GNUC__
-
-#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
-#include <iterator> // std::iterator, std::random_access_iterator_tag
-#endif
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
-#include <utility> // std::move
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-// Forward declaration.
-template <typename Encoding, typename Allocator>
-class GenericValue;
-
-template <typename Encoding, typename Allocator, typename StackAllocator>
-class GenericDocument;
-
-//! Name-value pair in a JSON object value.
-/*!
- This class was internal to GenericValue. It used to be a inner struct.
- But a compiler (IBM XL C/C++ for AIX) have reported to have problem with that so it moved as a namespace scope struct.
- https://code.google.com/p/rapidjson/issues/detail?id=64
-*/
-template <typename Encoding, typename Allocator>
-struct GenericMember {
- GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
- GenericValue<Encoding, Allocator> value; //!< value of member.
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericMemberIterator
-
-#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
-
-//! (Constant) member iterator for a JSON object value
-/*!
- \tparam Const Is this a constant iterator?
- \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document)
- \tparam Allocator Allocator type for allocating memory of object, array and string.
-
- This class implements a Random Access Iterator for GenericMember elements
- of a GenericValue, see ISO/IEC 14882:2003(E) C++ standard, 24.1 [lib.iterator.requirements].
-
- \note This iterator implementation is mainly intended to avoid implicit
- conversions from iterator values to \c NULL,
- e.g. from GenericValue::FindMember.
-
- \note Define \c RAPIDJSON_NOMEMBERITERATORCLASS to fall back to a
- pointer-based implementation, if your platform doesn't provide
- the C++ <iterator> header.
-
- \see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator
- */
-template <bool Const, typename Encoding, typename Allocator>
-class GenericMemberIterator
- : public std::iterator<std::random_access_iterator_tag
- , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
-
- friend class GenericValue<Encoding,Allocator>;
- template <bool, typename, typename> friend class GenericMemberIterator;
-
- typedef GenericMember<Encoding,Allocator> PlainType;
- typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
- typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
-
-public:
- //! Iterator type itself
- typedef GenericMemberIterator Iterator;
- //! Constant iterator type
- typedef GenericMemberIterator<true,Encoding,Allocator> ConstIterator;
- //! Non-constant iterator type
- typedef GenericMemberIterator<false,Encoding,Allocator> NonConstIterator;
-
- //! Pointer to (const) GenericMember
- typedef typename BaseType::pointer Pointer;
- //! Reference to (const) GenericMember
- typedef typename BaseType::reference Reference;
- //! Signed integer type (e.g. \c ptrdiff_t)
- typedef typename BaseType::difference_type DifferenceType;
-
- //! Default constructor (singular value)
- /*! Creates an iterator pointing to no element.
- \note All operations, except for comparisons, are undefined on such values.
- */
- GenericMemberIterator() : ptr_() {}
-
- //! Iterator conversions to more const
- /*!
- \param it (Non-const) iterator to copy from
-
- Allows the creation of an iterator from another GenericMemberIterator
- that is "less const". Especially, creating a non-constant iterator
- from a constant iterator are disabled:
- \li const -> non-const (not ok)
- \li const -> const (ok)
- \li non-const -> const (ok)
- \li non-const -> non-const (ok)
-
- \note If the \c Const template parameter is already \c false, this
- constructor effectively defines a regular copy-constructor.
- Otherwise, the copy constructor is implicitly defined.
- */
- GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {}
- Iterator& operator=(const NonConstIterator & it) { ptr_ = it.ptr_; return *this; }
-
- //! @name stepping
- //@{
- Iterator& operator++(){ ++ptr_; return *this; }
- Iterator& operator--(){ --ptr_; return *this; }
- Iterator operator++(int){ Iterator old(*this); ++ptr_; return old; }
- Iterator operator--(int){ Iterator old(*this); --ptr_; return old; }
- //@}
-
- //! @name increment/decrement
- //@{
- Iterator operator+(DifferenceType n) const { return Iterator(ptr_+n); }
- Iterator operator-(DifferenceType n) const { return Iterator(ptr_-n); }
-
- Iterator& operator+=(DifferenceType n) { ptr_+=n; return *this; }
- Iterator& operator-=(DifferenceType n) { ptr_-=n; return *this; }
- //@}
-
- //! @name relations
- //@{
- bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
- bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
- bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
- bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
- bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
- bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
- //@}
-
- //! @name dereference
- //@{
- Reference operator*() const { return *ptr_; }
- Pointer operator->() const { return ptr_; }
- Reference operator[](DifferenceType n) const { return ptr_[n]; }
- //@}
-
- //! Distance
- DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; }
-
-private:
- //! Internal constructor from plain pointer
- explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
-
- Pointer ptr_; //!< raw pointer
-};
-
-#else // RAPIDJSON_NOMEMBERITERATORCLASS
-
-// class-based member iterator implementation disabled, use plain pointers
-
-template <bool Const, typename Encoding, typename Allocator>
-struct GenericMemberIterator;
-
-//! non-const GenericMemberIterator
-template <typename Encoding, typename Allocator>
-struct GenericMemberIterator<false,Encoding,Allocator> {
- //! use plain pointer as iterator type
- typedef GenericMember<Encoding,Allocator>* Iterator;
-};
-//! const GenericMemberIterator
-template <typename Encoding, typename Allocator>
-struct GenericMemberIterator<true,Encoding,Allocator> {
- //! use plain const pointer as iterator type
- typedef const GenericMember<Encoding,Allocator>* Iterator;
-};
-
-#endif // RAPIDJSON_NOMEMBERITERATORCLASS
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericStringRef
-
-//! Reference to a constant string (not taking a copy)
-/*!
- \tparam CharType character type of the string
-
- This helper class is used to automatically infer constant string
- references for string literals, especially from \c const \b (!)
- character arrays.
-
- The main use is for creating JSON string values without copying the
- source string via an \ref Allocator. This requires that the referenced
- string pointers have a sufficient lifetime, which exceeds the lifetime
- of the associated GenericValue.
-
- \b Example
- \code
- Value v("foo"); // ok, no need to copy & calculate length
- const char foo[] = "foo";
- v.SetString(foo); // ok
-
- const char* bar = foo;
- // Value x(bar); // not ok, can't rely on bar's lifetime
- Value x(StringRef(bar)); // lifetime explicitly guaranteed by user
- Value y(StringRef(bar, 3)); // ok, explicitly pass length
- \endcode
-
- \see StringRef, GenericValue::SetString
-*/
-template<typename CharType>
-struct GenericStringRef {
- typedef CharType Ch; //!< character type of the string
-
- //! Create string reference from \c const character array
-#ifndef __clang__ // -Wdocumentation
- /*!
- This constructor implicitly creates a constant string reference from
- a \c const character array. It has better performance than
- \ref StringRef(const CharType*) by inferring the string \ref length
- from the array length, and also supports strings containing null
- characters.
-
- \tparam N length of the string, automatically inferred
-
- \param str Constant character array, lifetime assumed to be longer
- than the use of the string in e.g. a GenericValue
-
- \post \ref s == str
-
- \note Constant complexity.
- \note There is a hidden, private overload to disallow references to
- non-const character arrays to be created via this constructor.
- By this, e.g. function-scope arrays used to be filled via
- \c snprintf are excluded from consideration.
- In such cases, the referenced string should be \b copied to the
- GenericValue instead.
- */
-#endif
- template<SizeType N>
- GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
- : s(str), length(N-1) {}
-
- //! Explicitly create string reference from \c const character pointer
-#ifndef __clang__ // -Wdocumentation
- /*!
- This constructor can be used to \b explicitly create a reference to
- a constant string pointer.
-
- \see StringRef(const CharType*)
-
- \param str Constant character pointer, lifetime assumed to be longer
- than the use of the string in e.g. a GenericValue
-
- \post \ref s == str
-
- \note There is a hidden, private overload to disallow references to
- non-const character arrays to be created via this constructor.
- By this, e.g. function-scope arrays used to be filled via
- \c snprintf are excluded from consideration.
- In such cases, the referenced string should be \b copied to the
- GenericValue instead.
- */
-#endif
- explicit GenericStringRef(const CharType* str)
- : s(str), length(NotNullStrLen(str)) {}
-
- //! Create constant string reference from pointer and length
-#ifndef __clang__ // -Wdocumentation
- /*! \param str constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
- \param len length of the string, excluding the trailing NULL terminator
-
- \post \ref s == str && \ref length == len
- \note Constant complexity.
- */
-#endif
- GenericStringRef(const CharType* str, SizeType len)
- : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) { RAPIDJSON_ASSERT(str != 0 || len == 0u); }
-
- GenericStringRef(const GenericStringRef& rhs) : s(rhs.s), length(rhs.length) {}
-
- //! implicit conversion to plain CharType pointer
- operator const Ch *() const { return s; }
-
- const Ch* const s; //!< plain CharType pointer
- const SizeType length; //!< length of the string (excluding the trailing NULL terminator)
-
-private:
- SizeType NotNullStrLen(const CharType* str) {
- RAPIDJSON_ASSERT(str != 0);
- return internal::StrLen(str);
- }
-
- /// Empty string - used when passing in a NULL pointer
- static const Ch emptyString[];
-
- //! Disallow construction from non-const array
- template<SizeType N>
- GenericStringRef(CharType (&str)[N]) /* = delete */;
- //! Copy assignment operator not permitted - immutable type
- GenericStringRef& operator=(const GenericStringRef& rhs) /* = delete */;
-};
-
-template<typename CharType>
-const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
-
-//! Mark a character pointer as constant string
-/*! Mark a plain character pointer as a "string literal". This function
- can be used to avoid copying a character string to be referenced as a
- value in a JSON GenericValue object, if the string's lifetime is known
- to be valid long enough.
- \tparam CharType Character type of the string
- \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
- \return GenericStringRef string reference object
- \relatesalso GenericStringRef
-
- \see GenericValue::GenericValue(StringRefType), GenericValue::operator=(StringRefType), GenericValue::SetString(StringRefType), GenericValue::PushBack(StringRefType, Allocator&), GenericValue::AddMember
-*/
-template<typename CharType>
-inline GenericStringRef<CharType> StringRef(const CharType* str) {
- return GenericStringRef<CharType>(str);
-}
-
-//! Mark a character pointer as constant string
-/*! Mark a plain character pointer as a "string literal". This function
- can be used to avoid copying a character string to be referenced as a
- value in a JSON GenericValue object, if the string's lifetime is known
- to be valid long enough.
-
- This version has better performance with supplied length, and also
- supports string containing null characters.
-
- \tparam CharType character type of the string
- \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
- \param length The length of source string.
- \return GenericStringRef string reference object
- \relatesalso GenericStringRef
-*/
-template<typename CharType>
-inline GenericStringRef<CharType> StringRef(const CharType* str, size_t length) {
- return GenericStringRef<CharType>(str, SizeType(length));
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-//! Mark a string object as constant string
-/*! Mark a string object (e.g. \c std::string) as a "string literal".
- This function can be used to avoid copying a string to be referenced as a
- value in a JSON GenericValue object, if the string's lifetime is known
- to be valid long enough.
-
- \tparam CharType character type of the string
- \param str Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue
- \return GenericStringRef string reference object
- \relatesalso GenericStringRef
- \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
-*/
-template<typename CharType>
-inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& str) {
- return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
-}
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericValue type traits
-namespace internal {
-
-template <typename T, typename Encoding = void, typename Allocator = void>
-struct IsGenericValueImpl : FalseType {};
-
-// select candidates according to nested encoding and allocator types
-template <typename T> struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
- : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
-
-// helper to match arbitrary GenericValue instantiations, including derived classes
-template <typename T> struct IsGenericValue : IsGenericValueImpl<T>::Type {};
-
-} // namespace internal
-
-///////////////////////////////////////////////////////////////////////////////
-// TypeHelper
-
-namespace internal {
-
-template <typename ValueType, typename T>
-struct TypeHelper {};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, bool> {
- static bool Is(const ValueType& v) { return v.IsBool(); }
- static bool Get(const ValueType& v) { return v.GetBool(); }
- static ValueType& Set(ValueType& v, bool data) { return v.SetBool(data); }
- static ValueType& Set(ValueType& v, bool data, typename ValueType::AllocatorType&) { return v.SetBool(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, int> {
- static bool Is(const ValueType& v) { return v.IsInt(); }
- static int Get(const ValueType& v) { return v.GetInt(); }
- static ValueType& Set(ValueType& v, int data) { return v.SetInt(data); }
- static ValueType& Set(ValueType& v, int data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, unsigned> {
- static bool Is(const ValueType& v) { return v.IsUint(); }
- static unsigned Get(const ValueType& v) { return v.GetUint(); }
- static ValueType& Set(ValueType& v, unsigned data) { return v.SetUint(data); }
- static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, int64_t> {
- static bool Is(const ValueType& v) { return v.IsInt64(); }
- static int64_t Get(const ValueType& v) { return v.GetInt64(); }
- static ValueType& Set(ValueType& v, int64_t data) { return v.SetInt64(data); }
- static ValueType& Set(ValueType& v, int64_t data, typename ValueType::AllocatorType&) { return v.SetInt64(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, uint64_t> {
- static bool Is(const ValueType& v) { return v.IsUint64(); }
- static uint64_t Get(const ValueType& v) { return v.GetUint64(); }
- static ValueType& Set(ValueType& v, uint64_t data) { return v.SetUint64(data); }
- static ValueType& Set(ValueType& v, uint64_t data, typename ValueType::AllocatorType&) { return v.SetUint64(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, double> {
- static bool Is(const ValueType& v) { return v.IsDouble(); }
- static double Get(const ValueType& v) { return v.GetDouble(); }
- static ValueType& Set(ValueType& v, double data) { return v.SetDouble(data); }
- static ValueType& Set(ValueType& v, double data, typename ValueType::AllocatorType&) { return v.SetDouble(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, float> {
- static bool Is(const ValueType& v) { return v.IsFloat(); }
- static float Get(const ValueType& v) { return v.GetFloat(); }
- static ValueType& Set(ValueType& v, float data) { return v.SetFloat(data); }
- static ValueType& Set(ValueType& v, float data, typename ValueType::AllocatorType&) { return v.SetFloat(data); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, const typename ValueType::Ch*> {
- typedef const typename ValueType::Ch* StringType;
- static bool Is(const ValueType& v) { return v.IsString(); }
- static StringType Get(const ValueType& v) { return v.GetString(); }
- static ValueType& Set(ValueType& v, const StringType data) { return v.SetString(typename ValueType::StringRefType(data)); }
- static ValueType& Set(ValueType& v, const StringType data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
-};
-
-#if RAPIDJSON_HAS_STDSTRING
-template<typename ValueType>
-struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
- typedef std::basic_string<typename ValueType::Ch> StringType;
- static bool Is(const ValueType& v) { return v.IsString(); }
- static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); }
- static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
-};
-#endif
-
-template<typename ValueType>
-struct TypeHelper<ValueType, typename ValueType::Array> {
- typedef typename ValueType::Array ArrayType;
- static bool Is(const ValueType& v) { return v.IsArray(); }
- static ArrayType Get(ValueType& v) { return v.GetArray(); }
- static ValueType& Set(ValueType& v, ArrayType data) { return v = data; }
- static ValueType& Set(ValueType& v, ArrayType data, typename ValueType::AllocatorType&) { return v = data; }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, typename ValueType::ConstArray> {
- typedef typename ValueType::ConstArray ArrayType;
- static bool Is(const ValueType& v) { return v.IsArray(); }
- static ArrayType Get(const ValueType& v) { return v.GetArray(); }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, typename ValueType::Object> {
- typedef typename ValueType::Object ObjectType;
- static bool Is(const ValueType& v) { return v.IsObject(); }
- static ObjectType Get(ValueType& v) { return v.GetObject(); }
- static ValueType& Set(ValueType& v, ObjectType data) { return v = data; }
- static ValueType& Set(ValueType& v, ObjectType data, typename ValueType::AllocatorType&) { return v = data; }
-};
-
-template<typename ValueType>
-struct TypeHelper<ValueType, typename ValueType::ConstObject> {
- typedef typename ValueType::ConstObject ObjectType;
- static bool Is(const ValueType& v) { return v.IsObject(); }
- static ObjectType Get(const ValueType& v) { return v.GetObject(); }
-};
-
-} // namespace internal
-
-// Forward declarations
-template <bool, typename> class GenericArray;
-template <bool, typename> class GenericObject;
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericValue
-
-//! Represents a JSON value. Use Value for UTF8 encoding and default allocator.
-/*!
- A JSON value can be one of 7 types. This class is a variant type supporting
- these types.
-
- Use the Value if UTF8 and default allocator
-
- \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document)
- \tparam Allocator Allocator type for allocating memory of object, array and string.
-*/
-template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
-class GenericValue {
-public:
- //! Name-value pair in an object.
- typedef GenericMember<Encoding, Allocator> Member;
- typedef Encoding EncodingType; //!< Encoding type from template parameter.
- typedef Allocator AllocatorType; //!< Allocator type from template parameter.
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
- typedef GenericStringRef<Ch> StringRefType; //!< Reference to a constant string
- typedef typename GenericMemberIterator<false,Encoding,Allocator>::Iterator MemberIterator; //!< Member iterator for iterating in object.
- typedef typename GenericMemberIterator<true,Encoding,Allocator>::Iterator ConstMemberIterator; //!< Constant member iterator for iterating in object.
- typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array.
- typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array.
- typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of itself.
- typedef GenericArray<false, ValueType> Array;
- typedef GenericArray<true, ValueType> ConstArray;
- typedef GenericObject<false, ValueType> Object;
- typedef GenericObject<true, ValueType> ConstObject;
-
- //!@name Constructors and destructor.
- //@{
-
- //! Default constructor creates a null value.
- GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Move constructor in C++11
- GenericValue(GenericValue&& rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
- rhs.data_.f.flags = kNullFlag; // give up contents
- }
-#endif
-
-private:
- //! Copy constructor is not permitted.
- GenericValue(const GenericValue& rhs);
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Moving from a GenericDocument is not permitted.
- template <typename StackAllocator>
- GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
-
- //! Move assignment from a GenericDocument is not permitted.
- template <typename StackAllocator>
- GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
-#endif
-
-public:
-
- //! Constructor with JSON value type.
- /*! This creates a Value of specified type with default content.
- \param type Type of the value.
- \note Default content for number is zero.
- */
- explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
- static const uint16_t defaultFlags[7] = {
- kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
- kNumberAnyFlag
- };
- RAPIDJSON_ASSERT(type >= kNullType && type <= kNumberType);
- data_.f.flags = defaultFlags[type];
-
- // Use ShortString to store empty string.
- if (type == kStringType)
- data_.ss.SetLength(0);
- }
-
- //! Explicit copy constructor (with allocator)
- /*! Creates a copy of a Value by using the given Allocator
- \tparam SourceAllocator allocator of \c rhs
- \param rhs Value to copy from (read-only)
- \param allocator Allocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator().
- \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer)
- \see CopyFrom()
- */
- template <typename SourceAllocator>
- GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
- switch (rhs.GetType()) {
- case kObjectType: {
- SizeType count = rhs.data_.o.size;
- Member* lm = reinterpret_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
- const typename GenericValue<Encoding,SourceAllocator>::Member* rm = rhs.GetMembersPointer();
- for (SizeType i = 0; i < count; i++) {
- new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
- new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
- }
- data_.f.flags = kObjectFlag;
- data_.o.size = data_.o.capacity = count;
- SetMembersPointer(lm);
- }
- break;
- case kArrayType: {
- SizeType count = rhs.data_.a.size;
- GenericValue* le = reinterpret_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
- const GenericValue<Encoding,SourceAllocator>* re = rhs.GetElementsPointer();
- for (SizeType i = 0; i < count; i++)
- new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
- data_.f.flags = kArrayFlag;
- data_.a.size = data_.a.capacity = count;
- SetElementsPointer(le);
- }
- break;
- case kStringType:
- if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
- data_.f.flags = rhs.data_.f.flags;
- data_ = *reinterpret_cast<const Data*>(&rhs.data_);
- }
- else
- SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
- break;
- default:
- data_.f.flags = rhs.data_.f.flags;
- data_ = *reinterpret_cast<const Data*>(&rhs.data_);
- break;
- }
- }
-
- //! Constructor for boolean value.
- /*! \param b Boolean value
- \note This constructor is limited to \em real boolean values and rejects
- implicitly converted types like arbitrary pointers. Use an explicit cast
- to \c bool, if you want to construct a boolean JSON value in such cases.
- */
-#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
- template <typename T>
- explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT // See #472
-#else
- explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
-#endif
- : data_() {
- // safe-guard against failing SFINAE
- RAPIDJSON_STATIC_ASSERT((internal::IsSame<bool,T>::Value));
- data_.f.flags = b ? kTrueFlag : kFalseFlag;
- }
-
- //! Constructor for int value.
- explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() {
- data_.n.i64 = i;
- data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
- }
-
- //! Constructor for unsigned value.
- explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() {
- data_.n.u64 = u;
- data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
- }
-
- //! Constructor for int64_t value.
- explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() {
- data_.n.i64 = i64;
- data_.f.flags = kNumberInt64Flag;
- if (i64 >= 0) {
- data_.f.flags |= kNumberUint64Flag;
- if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
- data_.f.flags |= kUintFlag;
- if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
- data_.f.flags |= kIntFlag;
- }
- else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
- data_.f.flags |= kIntFlag;
- }
-
- //! Constructor for uint64_t value.
- explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() {
- data_.n.u64 = u64;
- data_.f.flags = kNumberUint64Flag;
- if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
- data_.f.flags |= kInt64Flag;
- if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
- data_.f.flags |= kUintFlag;
- if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
- data_.f.flags |= kIntFlag;
- }
-
- //! Constructor for double value.
- explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
-
- //! Constructor for float value.
- explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
-
- //! Constructor for constant string (i.e. do not make a copy of string)
- GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(StringRef(s, length)); }
-
- //! Constructor for constant string (i.e. do not make a copy of string)
- explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(s); }
-
- //! Constructor for copy-string (i.e. do make a copy of string)
- GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_() { SetStringRaw(StringRef(s, length), allocator); }
-
- //! Constructor for copy-string (i.e. do make a copy of string)
- GenericValue(const Ch*s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Constructor for copy-string from a string object (i.e. do make a copy of string)
- /*! \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
- */
- GenericValue(const std::basic_string<Ch>& s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
-#endif
-
- //! Constructor for Array.
- /*!
- \param a An array obtained by \c GetArray().
- \note \c Array is always pass-by-value.
- \note the source array is moved into this value and the sourec array becomes empty.
- */
- GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) {
- a.value_.data_ = Data();
- a.value_.data_.f.flags = kArrayFlag;
- }
-
- //! Constructor for Object.
- /*!
- \param o An object obtained by \c GetObject().
- \note \c Object is always pass-by-value.
- \note the source object is moved into this value and the sourec object becomes empty.
- */
- GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) {
- o.value_.data_ = Data();
- o.value_.data_.f.flags = kObjectFlag;
- }
-
- //! Destructor.
- /*! Need to destruct elements of array, members of object, or copy-string.
- */
- ~GenericValue() {
- if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
- switch(data_.f.flags) {
- case kArrayFlag:
- {
- GenericValue* e = GetElementsPointer();
- for (GenericValue* v = e; v != e + data_.a.size; ++v)
- v->~GenericValue();
- Allocator::Free(e);
- }
- break;
-
- case kObjectFlag:
- for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
- m->~Member();
- Allocator::Free(GetMembersPointer());
- break;
-
- case kCopyStringFlag:
- Allocator::Free(const_cast<Ch*>(GetStringPointer()));
- break;
-
- default:
- break; // Do nothing for other types.
- }
- }
- }
-
- //@}
-
- //!@name Assignment operators
- //@{
-
- //! Assignment with move semantics.
- /*! \param rhs Source of the assignment. It will become a null value after assignment.
- */
- GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
- RAPIDJSON_ASSERT(this != &rhs);
- this->~GenericValue();
- RawAssign(rhs);
- return *this;
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Move assignment in C++11
- GenericValue& operator=(GenericValue&& rhs) RAPIDJSON_NOEXCEPT {
- return *this = rhs.Move();
- }
-#endif
-
- //! Assignment of constant string reference (no copy)
- /*! \param str Constant string reference to be assigned
- \note This overload is needed to avoid clashes with the generic primitive type assignment overload below.
- \see GenericStringRef, operator=(T)
- */
- GenericValue& operator=(StringRefType str) RAPIDJSON_NOEXCEPT {
- GenericValue s(str);
- return *this = s;
- }
-
- //! Assignment with primitive types.
- /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
- \param value The value to be assigned.
-
- \note The source type \c T explicitly disallows all pointer types,
- especially (\c const) \ref Ch*. This helps avoiding implicitly
- referencing character strings with insufficient lifetime, use
- \ref SetString(const Ch*, Allocator&) (for copying) or
- \ref StringRef() (to explicitly mark the pointer as constant) instead.
- All other pointer types would implicitly convert to \c bool,
- use \ref SetBool() instead.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (GenericValue&))
- operator=(T value) {
- GenericValue v(value);
- return *this = v;
- }
-
- //! Deep-copy assignment from Value
- /*! Assigns a \b copy of the Value to the current Value object
- \tparam SourceAllocator Allocator type of \c rhs
- \param rhs Value to copy from (read-only)
- \param allocator Allocator to use for copying
- \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer)
- */
- template <typename SourceAllocator>
- GenericValue& CopyFrom(const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
- RAPIDJSON_ASSERT(static_cast<void*>(this) != static_cast<void const*>(&rhs));
- this->~GenericValue();
- new (this) GenericValue(rhs, allocator, copyConstStrings);
- return *this;
- }
-
- //! Exchange the contents of this value with those of other.
- /*!
- \param other Another value.
- \note Constant complexity.
- */
- GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
- GenericValue temp;
- temp.RawAssign(*this);
- RawAssign(other);
- other.RawAssign(temp);
- return *this;
- }
-
- //! free-standing swap function helper
- /*!
- Helper function to enable support for common swap implementation pattern based on \c std::swap:
- \code
- void swap(MyClass& a, MyClass& b) {
- using std::swap;
- swap(a.value, b.value);
- // ...
- }
- \endcode
- \see Swap()
- */
- friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
-
- //! Prepare Value for move semantics
- /*! \return *this */
- GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; }
- //@}
-
- //!@name Equal-to and not-equal-to operators
- //@{
- //! Equal-to operator
- /*!
- \note If an object contains duplicated named member, comparing equality with any object is always \c false.
- \note Linear time complexity (number of all values in the subtree and total lengths of all strings).
- */
- template <typename SourceAllocator>
- bool operator==(const GenericValue<Encoding, SourceAllocator>& rhs) const {
- typedef GenericValue<Encoding, SourceAllocator> RhsType;
- if (GetType() != rhs.GetType())
- return false;
-
- switch (GetType()) {
- case kObjectType: // Warning: O(n^2) inner-loop
- if (data_.o.size != rhs.data_.o.size)
- return false;
- for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
- typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
- if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
- return false;
- }
- return true;
-
- case kArrayType:
- if (data_.a.size != rhs.data_.a.size)
- return false;
- for (SizeType i = 0; i < data_.a.size; i++)
- if ((*this)[i] != rhs[i])
- return false;
- return true;
-
- case kStringType:
- return StringEqual(rhs);
-
- case kNumberType:
- if (IsDouble() || rhs.IsDouble()) {
- double a = GetDouble(); // May convert from integer to double.
- double b = rhs.GetDouble(); // Ditto
- return a >= b && a <= b; // Prevent -Wfloat-equal
- }
- else
- return data_.n.u64 == rhs.data_.n.u64;
-
- default:
- return true;
- }
- }
-
- //! Equal-to operator with const C-string pointer
- bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Equal-to operator with string object
- /*! \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
- */
- bool operator==(const std::basic_string<Ch>& rhs) const { return *this == GenericValue(StringRef(rhs)); }
-#endif
-
- //! Equal-to operator with primitive types
- /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c double, \c true, \c false
- */
- template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); }
-
- //! Not-equal-to operator
- /*! \return !(*this == rhs)
- */
- template <typename SourceAllocator>
- bool operator!=(const GenericValue<Encoding, SourceAllocator>& rhs) const { return !(*this == rhs); }
-
- //! Not-equal-to operator with const C-string pointer
- bool operator!=(const Ch* rhs) const { return !(*this == rhs); }
-
- //! Not-equal-to operator with arbitrary types
- /*! \return !(*this == rhs)
- */
- template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& rhs) const { return !(*this == rhs); }
-
- //! Equal-to operator with arbitrary types (symmetric version)
- /*! \return (rhs == lhs)
- */
- template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; }
-
- //! Not-Equal-to operator with arbitrary types (symmetric version)
- /*! \return !(rhs == lhs)
- */
- template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); }
- //@}
-
- //!@name Type
- //@{
-
- Type GetType() const { return static_cast<Type>(data_.f.flags & kTypeMask); }
- bool IsNull() const { return data_.f.flags == kNullFlag; }
- bool IsFalse() const { return data_.f.flags == kFalseFlag; }
- bool IsTrue() const { return data_.f.flags == kTrueFlag; }
- bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; }
- bool IsObject() const { return data_.f.flags == kObjectFlag; }
- bool IsArray() const { return data_.f.flags == kArrayFlag; }
- bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; }
- bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; }
- bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; }
- bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; }
- bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; }
- bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; }
- bool IsString() const { return (data_.f.flags & kStringFlag) != 0; }
-
- // Checks whether a number can be losslessly converted to a double.
- bool IsLosslessDouble() const {
- if (!IsNumber()) return false;
- if (IsUint64()) {
- uint64_t u = GetUint64();
- volatile double d = static_cast<double>(u);
- return (d >= 0.0)
- && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
- && (u == static_cast<uint64_t>(d));
- }
- if (IsInt64()) {
- int64_t i = GetInt64();
- volatile double d = static_cast<double>(i);
- return (d >= static_cast<double>((std::numeric_limits<int64_t>::min)()))
- && (d < static_cast<double>((std::numeric_limits<int64_t>::max)()))
- && (i == static_cast<int64_t>(d));
- }
- return true; // double, int, uint are always lossless
- }
-
- // Checks whether a number is a float (possible lossy).
- bool IsFloat() const {
- if ((data_.f.flags & kDoubleFlag) == 0)
- return false;
- double d = GetDouble();
- return d >= -3.4028234e38 && d <= 3.4028234e38;
- }
- // Checks whether a number can be losslessly converted to a float.
- bool IsLosslessFloat() const {
- if (!IsNumber()) return false;
- double a = GetDouble();
- if (a < static_cast<double>(-(std::numeric_limits<float>::max)())
- || a > static_cast<double>((std::numeric_limits<float>::max)()))
- return false;
- double b = static_cast<double>(static_cast<float>(a));
- return a >= b && a <= b; // Prevent -Wfloat-equal
- }
-
- //@}
-
- //!@name Null
- //@{
-
- GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
-
- //@}
-
- //!@name Bool
- //@{
-
- bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return data_.f.flags == kTrueFlag; }
- //!< Set boolean value
- /*! \post IsBool() == true */
- GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
-
- //@}
-
- //!@name Object
- //@{
-
- //! Set this value as an empty object.
- /*! \post IsObject() == true */
- GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
-
- //! Get the number of members in the object.
- SizeType MemberCount() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size; }
-
- //! Check whether the object is empty.
- bool ObjectEmpty() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size == 0; }
-
- //! Get a value from an object associated with the name.
- /*! \pre IsObject() == true
- \tparam T Either \c Ch or \c const \c Ch (template used for disambiguation with \ref operator[](SizeType))
- \note In version 0.1x, if the member is not found, this function returns a null value. This makes issue 7.
- Since 0.2, if the name is not correct, it will assert.
- If user is unsure whether a member exists, user should use HasMember() first.
- A better approach is to use FindMember().
- \note Linear time complexity.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(GenericValue&)) operator[](T* name) {
- GenericValue n(StringRef(name));
- return (*this)[n];
- }
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(const GenericValue&)) operator[](T* name) const { return const_cast<GenericValue&>(*this)[name]; }
-
- //! Get a value from an object associated with the name.
- /*! \pre IsObject() == true
- \tparam SourceAllocator Allocator of the \c name value
-
- \note Compared to \ref operator[](T*), this version is faster because it does not need a StrLen().
- And it can also handle strings with embedded null characters.
-
- \note Linear time complexity.
- */
- template <typename SourceAllocator>
- GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) {
- MemberIterator member = FindMember(name);
- if (member != MemberEnd())
- return member->value;
- else {
- RAPIDJSON_ASSERT(false); // see above note
-
- // This will generate -Wexit-time-destructors in clang
- // static GenericValue NullValue;
- // return NullValue;
-
- // Use static buffer and placement-new to prevent destruction
- static char buffer[sizeof(GenericValue)];
- return *new (buffer) GenericValue();
- }
- }
- template <typename SourceAllocator>
- const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Get a value from an object associated with name (string object).
- GenericValue& operator[](const std::basic_string<Ch>& name) { return (*this)[GenericValue(StringRef(name))]; }
- const GenericValue& operator[](const std::basic_string<Ch>& name) const { return (*this)[GenericValue(StringRef(name))]; }
-#endif
-
- //! Const member iterator
- /*! \pre IsObject() == true */
- ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer()); }
- //! Const \em past-the-end member iterator
- /*! \pre IsObject() == true */
- ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer() + data_.o.size); }
- //! Member iterator
- /*! \pre IsObject() == true */
- MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer()); }
- //! \em Past-the-end member iterator
- /*! \pre IsObject() == true */
- MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); }
-
- //! Check whether a member exists in the object.
- /*!
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Whether a member with that name exists.
- \note It is better to use FindMember() directly if you need the obtain the value as well.
- \note Linear time complexity.
- */
- bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Check whether a member exists in the object with string object.
- /*!
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Whether a member with that name exists.
- \note It is better to use FindMember() directly if you need the obtain the value as well.
- \note Linear time complexity.
- */
- bool HasMember(const std::basic_string<Ch>& name) const { return FindMember(name) != MemberEnd(); }
-#endif
-
- //! Check whether a member exists in the object with GenericValue name.
- /*!
- This version is faster because it does not need a StrLen(). It can also handle string with null character.
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Whether a member with that name exists.
- \note It is better to use FindMember() directly if you need the obtain the value as well.
- \note Linear time complexity.
- */
- template <typename SourceAllocator>
- bool HasMember(const GenericValue<Encoding, SourceAllocator>& name) const { return FindMember(name) != MemberEnd(); }
-
- //! Find member by name.
- /*!
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Iterator to member, if it exists.
- Otherwise returns \ref MemberEnd().
-
- \note Earlier versions of Rapidjson returned a \c NULL pointer, in case
- the requested member doesn't exist. For consistency with e.g.
- \c std::map, this has been changed to MemberEnd() now.
- \note Linear time complexity.
- */
- MemberIterator FindMember(const Ch* name) {
- GenericValue n(StringRef(name));
- return FindMember(n);
- }
-
- ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
-
- //! Find member by name.
- /*!
- This version is faster because it does not need a StrLen(). It can also handle string with null character.
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Iterator to member, if it exists.
- Otherwise returns \ref MemberEnd().
-
- \note Earlier versions of Rapidjson returned a \c NULL pointer, in case
- the requested member doesn't exist. For consistency with e.g.
- \c std::map, this has been changed to MemberEnd() now.
- \note Linear time complexity.
- */
- template <typename SourceAllocator>
- MemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) {
- RAPIDJSON_ASSERT(IsObject());
- RAPIDJSON_ASSERT(name.IsString());
- MemberIterator member = MemberBegin();
- for ( ; member != MemberEnd(); ++member)
- if (name.StringEqual(member->name))
- break;
- return member;
- }
- template <typename SourceAllocator> ConstMemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Find member by string object name.
- /*!
- \param name Member name to be searched.
- \pre IsObject() == true
- \return Iterator to member, if it exists.
- Otherwise returns \ref MemberEnd().
- */
- MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(GenericValue(StringRef(name))); }
- ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(GenericValue(StringRef(name))); }
-#endif
-
- //! Add a member (name-value pair) to the object.
- /*! \param name A string value as name of member.
- \param value Value of any type.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \note The ownership of \c name and \c value will be transferred to this object on success.
- \pre IsObject() && name.IsString()
- \post name.IsNull() && value.IsNull()
- \note Amortized Constant time complexity.
- */
- GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
- RAPIDJSON_ASSERT(IsObject());
- RAPIDJSON_ASSERT(name.IsString());
-
- ObjectData& o = data_.o;
- if (o.size >= o.capacity) {
- if (o.capacity == 0) {
- o.capacity = kDefaultObjectCapacity;
- SetMembersPointer(reinterpret_cast<Member*>(allocator.Malloc(o.capacity * sizeof(Member))));
- }
- else {
- SizeType oldCapacity = o.capacity;
- o.capacity += (oldCapacity + 1) / 2; // grow by factor 1.5
- SetMembersPointer(reinterpret_cast<Member*>(allocator.Realloc(GetMembersPointer(), oldCapacity * sizeof(Member), o.capacity * sizeof(Member))));
- }
- }
- Member* members = GetMembersPointer();
- members[o.size].name.RawAssign(name);
- members[o.size].value.RawAssign(value);
- o.size++;
- return *this;
- }
-
- //! Add a constant string value as member (name-value pair) to the object.
- /*! \param name A string value as name of member.
- \param value constant string reference as value of member.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \pre IsObject()
- \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
- \note Amortized Constant time complexity.
- */
- GenericValue& AddMember(GenericValue& name, StringRefType value, Allocator& allocator) {
- GenericValue v(value);
- return AddMember(name, v, allocator);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Add a string object as member (name-value pair) to the object.
- /*! \param name A string value as name of member.
- \param value constant string reference as value of member.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \pre IsObject()
- \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
- \note Amortized Constant time complexity.
- */
- GenericValue& AddMember(GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
- GenericValue v(value, allocator);
- return AddMember(name, v, allocator);
- }
-#endif
-
- //! Add any primitive value as member (name-value pair) to the object.
- /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
- \param name A string value as name of member.
- \param value Value of primitive type \c T as value of member
- \param allocator Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \pre IsObject()
-
- \note The source type \c T explicitly disallows all pointer types,
- especially (\c const) \ref Ch*. This helps avoiding implicitly
- referencing character strings with insufficient lifetime, use
- \ref AddMember(StringRefType, GenericValue&, Allocator&) or \ref
- AddMember(StringRefType, StringRefType, Allocator&).
- All other pointer types would implicitly convert to \c bool,
- use an explicit cast instead, if needed.
- \note Amortized Constant time complexity.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
- AddMember(GenericValue& name, T value, Allocator& allocator) {
- GenericValue v(value);
- return AddMember(name, v, allocator);
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) {
- return AddMember(name, value, allocator);
- }
- GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) {
- return AddMember(name, value, allocator);
- }
- GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) {
- return AddMember(name, value, allocator);
- }
- GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) {
- GenericValue n(name);
- return AddMember(n, value, allocator);
- }
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
-
-
- //! Add a member (name-value pair) to the object.
- /*! \param name A constant string reference as name of member.
- \param value Value of any type.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \note The ownership of \c value will be transferred to this object on success.
- \pre IsObject()
- \post value.IsNull()
- \note Amortized Constant time complexity.
- */
- GenericValue& AddMember(StringRefType name, GenericValue& value, Allocator& allocator) {
- GenericValue n(name);
- return AddMember(n, value, allocator);
- }
-
- //! Add a constant string value as member (name-value pair) to the object.
- /*! \param name A constant string reference as name of member.
- \param value constant string reference as value of member.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \pre IsObject()
- \note This overload is needed to avoid clashes with the generic primitive type AddMember(StringRefType,T,Allocator&) overload below.
- \note Amortized Constant time complexity.
- */
- GenericValue& AddMember(StringRefType name, StringRefType value, Allocator& allocator) {
- GenericValue v(value);
- return AddMember(name, v, allocator);
- }
-
- //! Add any primitive value as member (name-value pair) to the object.
- /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
- \param name A constant string reference as name of member.
- \param value Value of primitive type \c T as value of member
- \param allocator Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \pre IsObject()
-
- \note The source type \c T explicitly disallows all pointer types,
- especially (\c const) \ref Ch*. This helps avoiding implicitly
- referencing character strings with insufficient lifetime, use
- \ref AddMember(StringRefType, GenericValue&, Allocator&) or \ref
- AddMember(StringRefType, StringRefType, Allocator&).
- All other pointer types would implicitly convert to \c bool,
- use an explicit cast instead, if needed.
- \note Amortized Constant time complexity.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
- AddMember(StringRefType name, T value, Allocator& allocator) {
- GenericValue n(name);
- return AddMember(n, value, allocator);
- }
-
- //! Remove all members in the object.
- /*! This function do not deallocate memory in the object, i.e. the capacity is unchanged.
- \note Linear time complexity.
- */
- void RemoveAllMembers() {
- RAPIDJSON_ASSERT(IsObject());
- for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
- m->~Member();
- data_.o.size = 0;
- }
-
- //! Remove a member in object by its name.
- /*! \param name Name of member to be removed.
- \return Whether the member existed.
- \note This function may reorder the object members. Use \ref
- EraseMember(ConstMemberIterator) if you need to preserve the
- relative order of the remaining members.
- \note Linear time complexity.
- */
- bool RemoveMember(const Ch* name) {
- GenericValue n(StringRef(name));
- return RemoveMember(n);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool RemoveMember(const std::basic_string<Ch>& name) { return RemoveMember(GenericValue(StringRef(name))); }
-#endif
-
- template <typename SourceAllocator>
- bool RemoveMember(const GenericValue<Encoding, SourceAllocator>& name) {
- MemberIterator m = FindMember(name);
- if (m != MemberEnd()) {
- RemoveMember(m);
- return true;
- }
- else
- return false;
- }
-
- //! Remove a member in object by iterator.
- /*! \param m member iterator (obtained by FindMember() or MemberBegin()).
- \return the new iterator after removal.
- \note This function may reorder the object members. Use \ref
- EraseMember(ConstMemberIterator) if you need to preserve the
- relative order of the remaining members.
- \note Constant time complexity.
- */
- MemberIterator RemoveMember(MemberIterator m) {
- RAPIDJSON_ASSERT(IsObject());
- RAPIDJSON_ASSERT(data_.o.size > 0);
- RAPIDJSON_ASSERT(GetMembersPointer() != 0);
- RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd());
-
- MemberIterator last(GetMembersPointer() + (data_.o.size - 1));
- if (data_.o.size > 1 && m != last)
- *m = *last; // Move the last one to this place
- else
- m->~Member(); // Only one left, just destroy
- --data_.o.size;
- return m;
- }
-
- //! Remove a member from an object by iterator.
- /*! \param pos iterator to the member to remove
- \pre IsObject() == true && \ref MemberBegin() <= \c pos < \ref MemberEnd()
- \return Iterator following the removed element.
- If the iterator \c pos refers to the last element, the \ref MemberEnd() iterator is returned.
- \note This function preserves the relative order of the remaining object
- members. If you do not need this, use the more efficient \ref RemoveMember(MemberIterator).
- \note Linear time complexity.
- */
- MemberIterator EraseMember(ConstMemberIterator pos) {
- return EraseMember(pos, pos +1);
- }
-
- //! Remove members in the range [first, last) from an object.
- /*! \param first iterator to the first member to remove
- \param last iterator following the last member to remove
- \pre IsObject() == true && \ref MemberBegin() <= \c first <= \c last <= \ref MemberEnd()
- \return Iterator following the last removed element.
- \note This function preserves the relative order of the remaining object
- members.
- \note Linear time complexity.
- */
- MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) {
- RAPIDJSON_ASSERT(IsObject());
- RAPIDJSON_ASSERT(data_.o.size > 0);
- RAPIDJSON_ASSERT(GetMembersPointer() != 0);
- RAPIDJSON_ASSERT(first >= MemberBegin());
- RAPIDJSON_ASSERT(first <= last);
- RAPIDJSON_ASSERT(last <= MemberEnd());
-
- MemberIterator pos = MemberBegin() + (first - MemberBegin());
- for (MemberIterator itr = pos; itr != last; ++itr)
- itr->~Member();
- std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
- data_.o.size -= static_cast<SizeType>(last - first);
- return pos;
- }
-
- //! Erase a member in object by its name.
- /*! \param name Name of member to be removed.
- \return Whether the member existed.
- \note Linear time complexity.
- */
- bool EraseMember(const Ch* name) {
- GenericValue n(StringRef(name));
- return EraseMember(n);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
-#endif
-
- template <typename SourceAllocator>
- bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
- MemberIterator m = FindMember(name);
- if (m != MemberEnd()) {
- EraseMember(m);
- return true;
- }
- else
- return false;
- }
-
- Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
- ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
-
- //@}
-
- //!@name Array
- //@{
-
- //! Set this value as an empty array.
- /*! \post IsArray == true */
- GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
-
- //! Get the number of elements in array.
- SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
-
- //! Get the capacity of array.
- SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
-
- //! Check whether the array is empty.
- bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
-
- //! Remove all elements in the array.
- /*! This function do not deallocate memory in the array, i.e. the capacity is unchanged.
- \note Linear time complexity.
- */
- void Clear() {
- RAPIDJSON_ASSERT(IsArray());
- GenericValue* e = GetElementsPointer();
- for (GenericValue* v = e; v != e + data_.a.size; ++v)
- v->~GenericValue();
- data_.a.size = 0;
- }
-
- //! Get an element from array by index.
- /*! \pre IsArray() == true
- \param index Zero-based index of element.
- \see operator[](T*)
- */
- GenericValue& operator[](SizeType index) {
- RAPIDJSON_ASSERT(IsArray());
- RAPIDJSON_ASSERT(index < data_.a.size);
- return GetElementsPointer()[index];
- }
- const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
-
- //! Element iterator
- /*! \pre IsArray() == true */
- ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer(); }
- //! \em Past-the-end element iterator
- /*! \pre IsArray() == true */
- ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer() + data_.a.size; }
- //! Constant element iterator
- /*! \pre IsArray() == true */
- ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
- //! Constant \em past-the-end element iterator
- /*! \pre IsArray() == true */
- ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
-
- //! Request the array to have enough capacity to store elements.
- /*! \param newCapacity The capacity that the array at least need to have.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \note Linear time complexity.
- */
- GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
- RAPIDJSON_ASSERT(IsArray());
- if (newCapacity > data_.a.capacity) {
- SetElementsPointer(reinterpret_cast<GenericValue*>(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue))));
- data_.a.capacity = newCapacity;
- }
- return *this;
- }
-
- //! Append a GenericValue at the end of the array.
- /*! \param value Value to be appended.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \pre IsArray() == true
- \post value.IsNull() == true
- \return The value itself for fluent API.
- \note The ownership of \c value will be transferred to this array on success.
- \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
- \note Amortized constant time complexity.
- */
- GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
- RAPIDJSON_ASSERT(IsArray());
- if (data_.a.size >= data_.a.capacity)
- Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
- GetElementsPointer()[data_.a.size++].RawAssign(value);
- return *this;
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericValue& PushBack(GenericValue&& value, Allocator& allocator) {
- return PushBack(value, allocator);
- }
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
-
- //! Append a constant string reference at the end of the array.
- /*! \param value Constant string reference to be appended.
- \param allocator Allocator for reallocating memory. It must be the same one used previously. Commonly use GenericDocument::GetAllocator().
- \pre IsArray() == true
- \return The value itself for fluent API.
- \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
- \note Amortized constant time complexity.
- \see GenericStringRef
- */
- GenericValue& PushBack(StringRefType value, Allocator& allocator) {
- return (*this).template PushBack<StringRefType>(value, allocator);
- }
-
- //! Append a primitive value at the end of the array.
- /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
- \param value Value of primitive type T to be appended.
- \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
- \pre IsArray() == true
- \return The value itself for fluent API.
- \note If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
-
- \note The source type \c T explicitly disallows all pointer types,
- especially (\c const) \ref Ch*. This helps avoiding implicitly
- referencing character strings with insufficient lifetime, use
- \ref PushBack(GenericValue&, Allocator&) or \ref
- PushBack(StringRefType, Allocator&).
- All other pointer types would implicitly convert to \c bool,
- use an explicit cast instead, if needed.
- \note Amortized constant time complexity.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
- PushBack(T value, Allocator& allocator) {
- GenericValue v(value);
- return PushBack(v, allocator);
- }
-
- //! Remove the last element in the array.
- /*!
- \note Constant time complexity.
- */
- GenericValue& PopBack() {
- RAPIDJSON_ASSERT(IsArray());
- RAPIDJSON_ASSERT(!Empty());
- GetElementsPointer()[--data_.a.size].~GenericValue();
- return *this;
- }
-
- //! Remove an element of array by iterator.
- /*!
- \param pos iterator to the element to remove
- \pre IsArray() == true && \ref Begin() <= \c pos < \ref End()
- \return Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned.
- \note Linear time complexity.
- */
- ValueIterator Erase(ConstValueIterator pos) {
- return Erase(pos, pos + 1);
- }
-
- //! Remove elements in the range [first, last) of the array.
- /*!
- \param first iterator to the first element to remove
- \param last iterator following the last element to remove
- \pre IsArray() == true && \ref Begin() <= \c first <= \c last <= \ref End()
- \return Iterator following the last removed element.
- \note Linear time complexity.
- */
- ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) {
- RAPIDJSON_ASSERT(IsArray());
- RAPIDJSON_ASSERT(data_.a.size > 0);
- RAPIDJSON_ASSERT(GetElementsPointer() != 0);
- RAPIDJSON_ASSERT(first >= Begin());
- RAPIDJSON_ASSERT(first <= last);
- RAPIDJSON_ASSERT(last <= End());
- ValueIterator pos = Begin() + (first - Begin());
- for (ValueIterator itr = pos; itr != last; ++itr)
- itr->~GenericValue();
- std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
- data_.a.size -= static_cast<SizeType>(last - first);
- return pos;
- }
-
- Array GetArray() { RAPIDJSON_ASSERT(IsArray()); return Array(*this); }
- ConstArray GetArray() const { RAPIDJSON_ASSERT(IsArray()); return ConstArray(*this); }
-
- //@}
-
- //!@name Number
- //@{
-
- int GetInt() const { RAPIDJSON_ASSERT(data_.f.flags & kIntFlag); return data_.n.i.i; }
- unsigned GetUint() const { RAPIDJSON_ASSERT(data_.f.flags & kUintFlag); return data_.n.u.u; }
- int64_t GetInt64() const { RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag); return data_.n.i64; }
- uint64_t GetUint64() const { RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag); return data_.n.u64; }
-
- //! Get the value as double type.
- /*! \note If the value is 64-bit integer type, it may lose precision. Use \c IsLosslessDouble() to check whether the converison is lossless.
- */
- double GetDouble() const {
- RAPIDJSON_ASSERT(IsNumber());
- if ((data_.f.flags & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
- if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
- if ((data_.f.flags & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
- if ((data_.f.flags & kInt64Flag) != 0) return static_cast<double>(data_.n.i64); // int64_t -> double (may lose precision)
- RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0); return static_cast<double>(data_.n.u64); // uint64_t -> double (may lose precision)
- }
-
- //! Get the value as float type.
- /*! \note If the value is 64-bit integer type, it may lose precision. Use \c IsLosslessFloat() to check whether the converison is lossless.
- */
- float GetFloat() const {
- return static_cast<float>(GetDouble());
- }
-
- GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
- GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
- GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
- GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
- GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
- GenericValue& SetFloat(float f) { this->~GenericValue(); new (this) GenericValue(static_cast<double>(f)); return *this; }
-
- //@}
-
- //!@name String
- //@{
-
- const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
-
- //! Get the length of string.
- /*! Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().
- */
- SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); }
-
- //! Set this value as a string without copying source string.
- /*! This version has better performance with supplied length, and also support string containing null character.
- \param s source string pointer.
- \param length The length of source string, excluding the trailing null terminator.
- \return The value itself for fluent API.
- \post IsString() == true && GetString() == s && GetStringLength() == length
- \see SetString(StringRefType)
- */
- GenericValue& SetString(const Ch* s, SizeType length) { return SetString(StringRef(s, length)); }
-
- //! Set this value as a string without copying source string.
- /*! \param s source string reference
- \return The value itself for fluent API.
- \post IsString() == true && GetString() == s && GetStringLength() == s.length
- */
- GenericValue& SetString(StringRefType s) { this->~GenericValue(); SetStringRaw(s); return *this; }
-
- //! Set this value as a string by copying from source string.
- /*! This version has better performance with supplied length, and also support string containing null character.
- \param s source string.
- \param length The length of source string, excluding the trailing null terminator.
- \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \post IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length
- */
- GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { return SetString(StringRef(s, length), allocator); }
-
- //! Set this value as a string by copying from source string.
- /*! \param s source string.
- \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \post IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length
- */
- GenericValue& SetString(const Ch* s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
-
- //! Set this value as a string by copying from source string.
- /*! \param s source string reference
- \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \post IsString() == true && GetString() != s.s && strcmp(GetString(),s) == 0 && GetStringLength() == length
- */
- GenericValue& SetString(StringRefType s, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, allocator); return *this; }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Set this value as a string by copying from source string.
- /*! \param s source string.
- \param allocator Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().
- \return The value itself for fluent API.
- \post IsString() == true && GetString() != s.data() && strcmp(GetString(),s.data() == 0 && GetStringLength() == s.size()
- \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
- */
- GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
-#endif
-
- //@}
-
- //!@name Array
- //@{
-
- //! Templated version for checking whether this value is type T.
- /*!
- \tparam T Either \c bool, \c int, \c unsigned, \c int64_t, \c uint64_t, \c double, \c float, \c const \c char*, \c std::basic_string<Ch>
- */
- template <typename T>
- bool Is() const { return internal::TypeHelper<ValueType, T>::Is(*this); }
-
- template <typename T>
- T Get() const { return internal::TypeHelper<ValueType, T>::Get(*this); }
-
- template <typename T>
- T Get() { return internal::TypeHelper<ValueType, T>::Get(*this); }
-
- template<typename T>
- ValueType& Set(const T& data) { return internal::TypeHelper<ValueType, T>::Set(*this, data); }
-
- template<typename T>
- ValueType& Set(const T& data, AllocatorType& allocator) { return internal::TypeHelper<ValueType, T>::Set(*this, data, allocator); }
-
- //@}
-
- //! Generate events of this value to a Handler.
- /*! This function adopts the GoF visitor pattern.
- Typical usage is to output this JSON value as JSON text via Writer, which is a Handler.
- It can also be used to deep clone this value via GenericDocument, which is also a Handler.
- \tparam Handler type of handler.
- \param handler An object implementing concept Handler.
- */
- template <typename Handler>
- bool Accept(Handler& handler) const {
- switch(GetType()) {
- case kNullType: return handler.Null();
- case kFalseType: return handler.Bool(false);
- case kTrueType: return handler.Bool(true);
-
- case kObjectType:
- if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
- return false;
- for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
- RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of name by MemberIterator.
- if (RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
- return false;
- if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler)))
- return false;
- }
- return handler.EndObject(data_.o.size);
-
- case kArrayType:
- if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
- return false;
- for (const GenericValue* v = Begin(); v != End(); ++v)
- if (RAPIDJSON_UNLIKELY(!v->Accept(handler)))
- return false;
- return handler.EndArray(data_.a.size);
-
- case kStringType:
- return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
-
- default:
- RAPIDJSON_ASSERT(GetType() == kNumberType);
- if (IsDouble()) return handler.Double(data_.n.d);
- else if (IsInt()) return handler.Int(data_.n.i.i);
- else if (IsUint()) return handler.Uint(data_.n.u.u);
- else if (IsInt64()) return handler.Int64(data_.n.i64);
- else return handler.Uint64(data_.n.u64);
- }
- }
-
-private:
- template <typename, typename> friend class GenericValue;
- template <typename, typename, typename> friend class GenericDocument;
-
- enum {
- kBoolFlag = 0x0008,
- kNumberFlag = 0x0010,
- kIntFlag = 0x0020,
- kUintFlag = 0x0040,
- kInt64Flag = 0x0080,
- kUint64Flag = 0x0100,
- kDoubleFlag = 0x0200,
- kStringFlag = 0x0400,
- kCopyFlag = 0x0800,
- kInlineStrFlag = 0x1000,
-
- // Initial flags of different types.
- kNullFlag = kNullType,
- kTrueFlag = kTrueType | kBoolFlag,
- kFalseFlag = kFalseType | kBoolFlag,
- kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
- kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
- kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag,
- kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag,
- kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag,
- kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
- kConstStringFlag = kStringType | kStringFlag,
- kCopyStringFlag = kStringType | kStringFlag | kCopyFlag,
- kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
- kObjectFlag = kObjectType,
- kArrayFlag = kArrayType,
-
- kTypeMask = 0x07
- };
-
- static const SizeType kDefaultArrayCapacity = 16;
- static const SizeType kDefaultObjectCapacity = 16;
-
- struct Flag {
-#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
- char payload[sizeof(SizeType) * 2 + 6]; // 2 x SizeType + lower 48-bit pointer
-#elif RAPIDJSON_64BIT
- char payload[sizeof(SizeType) * 2 + sizeof(void*) + 6]; // 6 padding bytes
-#else
- char payload[sizeof(SizeType) * 2 + sizeof(void*) + 2]; // 2 padding bytes
-#endif
- uint16_t flags;
- };
-
- struct String {
- SizeType length;
- SizeType hashcode; //!< reserved
- const Ch* str;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- // implementation detail: ShortString can represent zero-terminated strings up to MaxSize chars
- // (excluding the terminating zero) and store a value to determine the length of the contained
- // string in the last character str[LenPos] by storing "MaxSize - length" there. If the string
- // to store has the maximal length of MaxSize then str[LenPos] will be 0 and therefore act as
- // the string terminator as well. For getting the string length back from that value just use
- // "MaxSize - str[LenPos]".
- // This allows to store 13-chars strings in 32-bit mode, 21-chars strings in 64-bit mode,
- // 13-chars strings for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded strings).
- struct ShortString {
- enum { MaxChars = sizeof(static_cast<Flag*>(0)->payload) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
- Ch str[MaxChars];
-
- inline static bool Usable(SizeType len) { return (MaxSize >= len); }
- inline void SetLength(SizeType len) { str[LenPos] = static_cast<Ch>(MaxSize - len); }
- inline SizeType GetLength() const { return static_cast<SizeType>(MaxSize - str[LenPos]); }
- }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- // By using proper binary layout, retrieval of different integer types do not need conversions.
- union Number {
-#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
- struct I {
- int i;
- char padding[4];
- }i;
- struct U {
- unsigned u;
- char padding2[4];
- }u;
-#else
- struct I {
- char padding[4];
- int i;
- }i;
- struct U {
- char padding2[4];
- unsigned u;
- }u;
-#endif
- int64_t i64;
- uint64_t u64;
- double d;
- }; // 8 bytes
-
- struct ObjectData {
- SizeType size;
- SizeType capacity;
- Member* members;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- struct ArrayData {
- SizeType size;
- SizeType capacity;
- GenericValue* elements;
- }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
-
- union Data {
- String s;
- ShortString ss;
- Number n;
- ObjectData o;
- ArrayData a;
- Flag f;
- }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION
-
- RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
- RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
- RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
- RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
- RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
- RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
-
- // Initialize this value as array with initial data, without calling destructor.
- void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
- data_.f.flags = kArrayFlag;
- if (count) {
- GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
- SetElementsPointer(e);
- std::memcpy(e, values, count * sizeof(GenericValue));
- }
- else
- SetElementsPointer(0);
- data_.a.size = data_.a.capacity = count;
- }
-
- //! Initialize this value as object with initial data, without calling destructor.
- void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
- data_.f.flags = kObjectFlag;
- if (count) {
- Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
- SetMembersPointer(m);
- std::memcpy(m, members, count * sizeof(Member));
- }
- else
- SetMembersPointer(0);
- data_.o.size = data_.o.capacity = count;
- }
-
- //! Initialize this value as constant string, without calling destructor.
- void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
- data_.f.flags = kConstStringFlag;
- SetStringPointer(s);
- data_.s.length = s.length;
- }
-
- //! Initialize this value as copy string with initial data, without calling destructor.
- void SetStringRaw(StringRefType s, Allocator& allocator) {
- Ch* str = 0;
- if (ShortString::Usable(s.length)) {
- data_.f.flags = kShortStringFlag;
- data_.ss.SetLength(s.length);
- str = data_.ss.str;
- } else {
- data_.f.flags = kCopyStringFlag;
- data_.s.length = s.length;
- str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
- SetStringPointer(str);
- }
- std::memcpy(str, s, s.length * sizeof(Ch));
- str[s.length] = '\0';
- }
-
- //! Assignment without calling destructor
- void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
- data_ = rhs.data_;
- // data_.f.flags = rhs.data_.f.flags;
- rhs.data_.f.flags = kNullFlag;
- }
-
- template <typename SourceAllocator>
- bool StringEqual(const GenericValue<Encoding, SourceAllocator>& rhs) const {
- RAPIDJSON_ASSERT(IsString());
- RAPIDJSON_ASSERT(rhs.IsString());
-
- const SizeType len1 = GetStringLength();
- const SizeType len2 = rhs.GetStringLength();
- if(len1 != len2) { return false; }
-
- const Ch* const str1 = GetString();
- const Ch* const str2 = rhs.GetString();
- if(str1 == str2) { return true; } // fast path for constant string
-
- return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
- }
-
- Data data_;
-};
-
-//! GenericValue with UTF8 encoding
-typedef GenericValue<UTF8<> > Value;
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericDocument
-
-//! A document for parsing JSON text as DOM.
-/*!
- \note implements Handler concept
- \tparam Encoding Encoding for both parsing and string storage.
- \tparam Allocator Allocator for allocating memory for the DOM
- \tparam StackAllocator Allocator for allocating memory for stack during parsing.
- \warning Although GenericDocument inherits from GenericValue, the API does \b not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not \c delete a GenericDocument object via a pointer to a GenericValue.
-*/
-template <typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
-class GenericDocument : public GenericValue<Encoding, Allocator> {
-public:
- typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
- typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of the document.
- typedef Allocator AllocatorType; //!< Allocator type from template parameter.
-
- //! Constructor
- /*! Creates an empty document of specified type.
- \param type Mandatory type of object to create.
- \param allocator Optional allocator for allocating memory.
- \param stackCapacity Optional initial capacity of stack in bytes.
- \param stackAllocator Optional allocator for allocating memory for stack.
- */
- explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
- GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
- {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
- }
-
- //! Constructor
- /*! Creates an empty document which type is Null.
- \param allocator Optional allocator for allocating memory.
- \param stackCapacity Optional initial capacity of stack in bytes.
- \param stackAllocator Optional allocator for allocating memory for stack.
- */
- GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
- allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
- {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Move constructor in C++11
- GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
- : ValueType(std::forward<ValueType>(rhs)), // explicit cast to avoid prohibited move from Document
- allocator_(rhs.allocator_),
- ownAllocator_(rhs.ownAllocator_),
- stack_(std::move(rhs.stack_)),
- parseResult_(rhs.parseResult_)
- {
- rhs.allocator_ = 0;
- rhs.ownAllocator_ = 0;
- rhs.parseResult_ = ParseResult();
- }
-#endif
-
- ~GenericDocument() {
- Destroy();
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Move assignment in C++11
- GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
- {
- // The cast to ValueType is necessary here, because otherwise it would
- // attempt to call GenericValue's templated assignment operator.
- ValueType::operator=(std::forward<ValueType>(rhs));
-
- // Calling the destructor here would prematurely call stack_'s destructor
- Destroy();
-
- allocator_ = rhs.allocator_;
- ownAllocator_ = rhs.ownAllocator_;
- stack_ = std::move(rhs.stack_);
- parseResult_ = rhs.parseResult_;
-
- rhs.allocator_ = 0;
- rhs.ownAllocator_ = 0;
- rhs.parseResult_ = ParseResult();
-
- return *this;
- }
-#endif
-
- //! Exchange the contents of this document with those of another.
- /*!
- \param rhs Another document.
- \note Constant complexity.
- \see GenericValue::Swap
- */
- GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
- ValueType::Swap(rhs);
- stack_.Swap(rhs.stack_);
- internal::Swap(allocator_, rhs.allocator_);
- internal::Swap(ownAllocator_, rhs.ownAllocator_);
- internal::Swap(parseResult_, rhs.parseResult_);
- return *this;
- }
-
- // Allow Swap with ValueType.
- // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
- using ValueType::Swap;
-
- //! free-standing swap function helper
- /*!
- Helper function to enable support for common swap implementation pattern based on \c std::swap:
- \code
- void swap(MyClass& a, MyClass& b) {
- using std::swap;
- swap(a.doc, b.doc);
- // ...
- }
- \endcode
- \see Swap()
- */
- friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
-
- //! Populate this document by a generator which produces SAX events.
- /*! \tparam Generator A functor with <tt>bool f(Handler)</tt> prototype.
- \param g Generator functor which sends SAX events to the parameter.
- \return The document itself for fluent API.
- */
- template <typename Generator>
- GenericDocument& Populate(Generator& g) {
- ClearStackOnExit scope(*this);
- if (g(*this)) {
- RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
- ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
- }
- return *this;
- }
-
- //!@name Parse from stream
- //!@{
-
- //! Parse JSON text from an input stream (with Encoding conversion)
- /*! \tparam parseFlags Combination of \ref ParseFlag.
- \tparam SourceEncoding Encoding of input stream
- \tparam InputStream Type of input stream, implementing Stream concept
- \param is Input stream to be parsed.
- \return The document itself for fluent API.
- */
- template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
- GenericDocument& ParseStream(InputStream& is) {
- GenericReader<SourceEncoding, Encoding, StackAllocator> reader(
- stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
- ClearStackOnExit scope(*this);
- parseResult_ = reader.template Parse<parseFlags>(is, *this);
- if (parseResult_) {
- RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
- ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
- }
- return *this;
- }
-
- //! Parse JSON text from an input stream
- /*! \tparam parseFlags Combination of \ref ParseFlag.
- \tparam InputStream Type of input stream, implementing Stream concept
- \param is Input stream to be parsed.
- \return The document itself for fluent API.
- */
- template <unsigned parseFlags, typename InputStream>
- GenericDocument& ParseStream(InputStream& is) {
- return ParseStream<parseFlags, Encoding, InputStream>(is);
- }
-
- //! Parse JSON text from an input stream (with \ref kParseDefaultFlags)
- /*! \tparam InputStream Type of input stream, implementing Stream concept
- \param is Input stream to be parsed.
- \return The document itself for fluent API.
- */
- template <typename InputStream>
- GenericDocument& ParseStream(InputStream& is) {
- return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
- }
- //!@}
-
- //!@name Parse in-place from mutable string
- //!@{
-
- //! Parse JSON text from a mutable string
- /*! \tparam parseFlags Combination of \ref ParseFlag.
- \param str Mutable zero-terminated string to be parsed.
- \return The document itself for fluent API.
- */
- template <unsigned parseFlags>
- GenericDocument& ParseInsitu(Ch* str) {
- GenericInsituStringStream<Encoding> s(str);
- return ParseStream<parseFlags | kParseInsituFlag>(s);
- }
-
- //! Parse JSON text from a mutable string (with \ref kParseDefaultFlags)
- /*! \param str Mutable zero-terminated string to be parsed.
- \return The document itself for fluent API.
- */
- GenericDocument& ParseInsitu(Ch* str) {
- return ParseInsitu<kParseDefaultFlags>(str);
- }
- //!@}
-
- //!@name Parse from read-only string
- //!@{
-
- //! Parse JSON text from a read-only string (with Encoding conversion)
- /*! \tparam parseFlags Combination of \ref ParseFlag (must not contain \ref kParseInsituFlag).
- \tparam SourceEncoding Transcoding from input Encoding
- \param str Read-only zero-terminated string to be parsed.
- */
- template <unsigned parseFlags, typename SourceEncoding>
- GenericDocument& Parse(const typename SourceEncoding::Ch* str) {
- RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
- GenericStringStream<SourceEncoding> s(str);
- return ParseStream<parseFlags, SourceEncoding>(s);
- }
-
- //! Parse JSON text from a read-only string
- /*! \tparam parseFlags Combination of \ref ParseFlag (must not contain \ref kParseInsituFlag).
- \param str Read-only zero-terminated string to be parsed.
- */
- template <unsigned parseFlags>
- GenericDocument& Parse(const Ch* str) {
- return Parse<parseFlags, Encoding>(str);
- }
-
- //! Parse JSON text from a read-only string (with \ref kParseDefaultFlags)
- /*! \param str Read-only zero-terminated string to be parsed.
- */
- GenericDocument& Parse(const Ch* str) {
- return Parse<kParseDefaultFlags>(str);
- }
-
- template <unsigned parseFlags, typename SourceEncoding>
- GenericDocument& Parse(const typename SourceEncoding::Ch* str, size_t length) {
- RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
- MemoryStream ms(reinterpret_cast<const char*>(str), length * sizeof(typename SourceEncoding::Ch));
- EncodedInputStream<SourceEncoding, MemoryStream> is(ms);
- ParseStream<parseFlags, SourceEncoding>(is);
- return *this;
- }
-
- template <unsigned parseFlags>
- GenericDocument& Parse(const Ch* str, size_t length) {
- return Parse<parseFlags, Encoding>(str, length);
- }
-
- GenericDocument& Parse(const Ch* str, size_t length) {
- return Parse<kParseDefaultFlags>(str, length);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- template <unsigned parseFlags, typename SourceEncoding>
- GenericDocument& Parse(const std::basic_string<typename SourceEncoding::Ch>& str) {
- // c_str() is constant complexity according to standard. Should be faster than Parse(const char*, size_t)
- return Parse<parseFlags, SourceEncoding>(str.c_str());
- }
-
- template <unsigned parseFlags>
- GenericDocument& Parse(const std::basic_string<Ch>& str) {
- return Parse<parseFlags, Encoding>(str.c_str());
- }
-
- GenericDocument& Parse(const std::basic_string<Ch>& str) {
- return Parse<kParseDefaultFlags>(str);
- }
-#endif // RAPIDJSON_HAS_STDSTRING
-
- //!@}
-
- //!@name Handling parse errors
- //!@{
-
- //! Whether a parse error has occured in the last parsing.
- bool HasParseError() const { return parseResult_.IsError(); }
-
- //! Get the \ref ParseErrorCode of last parsing.
- ParseErrorCode GetParseError() const { return parseResult_.Code(); }
-
- //! Get the position of last parsing error in input, 0 otherwise.
- size_t GetErrorOffset() const { return parseResult_.Offset(); }
-
- //! Implicit conversion to get the last parse result
-#ifndef __clang // -Wdocumentation
- /*! \return \ref ParseResult of the last parse operation
-
- \code
- Document doc;
- ParseResult ok = doc.Parse(json);
- if (!ok)
- printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());
- \endcode
- */
-#endif
- operator ParseResult() const { return parseResult_; }
- //!@}
-
- //! Get the allocator of this document.
- Allocator& GetAllocator() {
- RAPIDJSON_ASSERT(allocator_);
- return *allocator_;
- }
-
- //! Get the capacity of stack in bytes.
- size_t GetStackCapacity() const { return stack_.GetCapacity(); }
-
-private:
- // clear stack on any exit from ParseStream, e.g. due to exception
- struct ClearStackOnExit {
- explicit ClearStackOnExit(GenericDocument& d) : d_(d) {}
- ~ClearStackOnExit() { d_.ClearStack(); }
- private:
- ClearStackOnExit(const ClearStackOnExit&);
- ClearStackOnExit& operator=(const ClearStackOnExit&);
- GenericDocument& d_;
- };
-
- // callers of the following private Handler functions
- // template <typename,typename,typename> friend class GenericReader; // for parsing
- template <typename, typename> friend class GenericValue; // for deep copying
-
-public:
- // Implementation of Handler
- bool Null() { new (stack_.template Push<ValueType>()) ValueType(); return true; }
- bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
- bool Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
- bool Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
- bool Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
- bool Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
- bool Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); return true; }
-
- bool RawNumber(const Ch* str, SizeType length, bool copy) {
- if (copy)
- new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
- else
- new (stack_.template Push<ValueType>()) ValueType(str, length);
- return true;
- }
-
- bool String(const Ch* str, SizeType length, bool copy) {
- if (copy)
- new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
- else
- new (stack_.template Push<ValueType>()) ValueType(str, length);
- return true;
- }
-
- bool StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
-
- bool Key(const Ch* str, SizeType length, bool copy) { return String(str, length, copy); }
-
- bool EndObject(SizeType memberCount) {
- typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
- stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
- return true;
- }
-
- bool StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
-
- bool EndArray(SizeType elementCount) {
- ValueType* elements = stack_.template Pop<ValueType>(elementCount);
- stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
- return true;
- }
-
-private:
- //! Prohibit copying
- GenericDocument(const GenericDocument&);
- //! Prohibit assignment
- GenericDocument& operator=(const GenericDocument&);
-
- void ClearStack() {
- if (Allocator::kNeedFree)
- while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
- (stack_.template Pop<ValueType>(1))->~ValueType();
- else
- stack_.Clear();
- stack_.ShrinkToFit();
- }
-
- void Destroy() {
- RAPIDJSON_DELETE(ownAllocator_);
- }
-
- static const size_t kDefaultStackCapacity = 1024;
- Allocator* allocator_;
- Allocator* ownAllocator_;
- internal::Stack<StackAllocator> stack_;
- ParseResult parseResult_;
-};
-
-//! GenericDocument with UTF8 encoding
-typedef GenericDocument<UTF8<> > Document;
-
-//! Helper class for accessing Value of array type.
-/*!
- Instance of this helper class is obtained by \c GenericValue::GetArray().
- In addition to all APIs for array type, it provides range-based for loop if \c RAPIDJSON_HAS_CXX11_RANGE_FOR=1.
-*/
-template <bool Const, typename ValueT>
-class GenericArray {
-public:
- typedef GenericArray<true, ValueT> ConstArray;
- typedef GenericArray<false, ValueT> Array;
- typedef ValueT PlainType;
- typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
- typedef ValueType* ValueIterator; // This may be const or non-const iterator
- typedef const ValueT* ConstValueIterator;
- typedef typename ValueType::AllocatorType AllocatorType;
- typedef typename ValueType::StringRefType StringRefType;
-
- template <typename, typename>
- friend class GenericValue;
-
- GenericArray(const GenericArray& rhs) : value_(rhs.value_) {}
- GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
- ~GenericArray() {}
-
- SizeType Size() const { return value_.Size(); }
- SizeType Capacity() const { return value_.Capacity(); }
- bool Empty() const { return value_.Empty(); }
- void Clear() const { value_.Clear(); }
- ValueType& operator[](SizeType index) const { return value_[index]; }
- ValueIterator Begin() const { return value_.Begin(); }
- ValueIterator End() const { return value_.End(); }
- GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const { value_.Reserve(newCapacity, allocator); return *this; }
- GenericArray PushBack(ValueType& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericArray PushBack(ValueType&& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericArray PushBack(StringRefType value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
- template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (const GenericArray&)) PushBack(T value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
- GenericArray PopBack() const { value_.PopBack(); return *this; }
- ValueIterator Erase(ConstValueIterator pos) const { return value_.Erase(pos); }
- ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const { return value_.Erase(first, last); }
-
-#if RAPIDJSON_HAS_CXX11_RANGE_FOR
- ValueIterator begin() const { return value_.Begin(); }
- ValueIterator end() const { return value_.End(); }
-#endif
-
-private:
- GenericArray();
- GenericArray(ValueType& value) : value_(value) {}
- ValueType& value_;
-};
-
-//! Helper class for accessing Value of object type.
-/*!
- Instance of this helper class is obtained by \c GenericValue::GetObject().
- In addition to all APIs for array type, it provides range-based for loop if \c RAPIDJSON_HAS_CXX11_RANGE_FOR=1.
-*/
-template <bool Const, typename ValueT>
-class GenericObject {
-public:
- typedef GenericObject<true, ValueT> ConstObject;
- typedef GenericObject<false, ValueT> Object;
- typedef ValueT PlainType;
- typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
- typedef GenericMemberIterator<Const, typename ValueT::EncodingType, typename ValueT::AllocatorType> MemberIterator; // This may be const or non-const iterator
- typedef GenericMemberIterator<true, typename ValueT::EncodingType, typename ValueT::AllocatorType> ConstMemberIterator;
- typedef typename ValueType::AllocatorType AllocatorType;
- typedef typename ValueType::StringRefType StringRefType;
- typedef typename ValueType::EncodingType EncodingType;
- typedef typename ValueType::Ch Ch;
-
- template <typename, typename>
- friend class GenericValue;
-
- GenericObject(const GenericObject& rhs) : value_(rhs.value_) {}
- GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
- ~GenericObject() {}
-
- SizeType MemberCount() const { return value_.MemberCount(); }
- bool ObjectEmpty() const { return value_.ObjectEmpty(); }
- template <typename T> ValueType& operator[](T* name) const { return value_[name]; }
- template <typename SourceAllocator> ValueType& operator[](const GenericValue<EncodingType, SourceAllocator>& name) const { return value_[name]; }
-#if RAPIDJSON_HAS_STDSTRING
- ValueType& operator[](const std::basic_string<Ch>& name) const { return value_[name]; }
-#endif
- MemberIterator MemberBegin() const { return value_.MemberBegin(); }
- MemberIterator MemberEnd() const { return value_.MemberEnd(); }
- bool HasMember(const Ch* name) const { return value_.HasMember(name); }
-#if RAPIDJSON_HAS_STDSTRING
- bool HasMember(const std::basic_string<Ch>& name) const { return value_.HasMember(name); }
-#endif
- template <typename SourceAllocator> bool HasMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.HasMember(name); }
- MemberIterator FindMember(const Ch* name) const { return value_.FindMember(name); }
- template <typename SourceAllocator> MemberIterator FindMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.FindMember(name); }
-#if RAPIDJSON_HAS_STDSTRING
- MemberIterator FindMember(const std::basic_string<Ch>& name) const { return value_.FindMember(name); }
-#endif
- GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
-#if RAPIDJSON_HAS_STDSTRING
- GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
-#endif
- template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&)) AddMember(ValueType& name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericObject)) AddMember(StringRefType name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
- void RemoveAllMembers() { value_.RemoveAllMembers(); }
- bool RemoveMember(const Ch* name) const { return value_.RemoveMember(name); }
-#if RAPIDJSON_HAS_STDSTRING
- bool RemoveMember(const std::basic_string<Ch>& name) const { return value_.RemoveMember(name); }
-#endif
- template <typename SourceAllocator> bool RemoveMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.RemoveMember(name); }
- MemberIterator RemoveMember(MemberIterator m) const { return value_.RemoveMember(m); }
- MemberIterator EraseMember(ConstMemberIterator pos) const { return value_.EraseMember(pos); }
- MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const { return value_.EraseMember(first, last); }
- bool EraseMember(const Ch* name) const { return value_.EraseMember(name); }
-#if RAPIDJSON_HAS_STDSTRING
- bool EraseMember(const std::basic_string<Ch>& name) const { return EraseMember(ValueType(StringRef(name))); }
-#endif
- template <typename SourceAllocator> bool EraseMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.EraseMember(name); }
-
-#if RAPIDJSON_HAS_CXX11_RANGE_FOR
- MemberIterator begin() const { return value_.MemberBegin(); }
- MemberIterator end() const { return value_.MemberEnd(); }
-#endif
-
-private:
- GenericObject();
- GenericObject(ValueType& value) : value_(value) {}
- ValueType& value_;
-};
-
-RAPIDJSON_NAMESPACE_END
-RAPIDJSON_DIAG_POP
-
-#endif // RAPIDJSON_DOCUMENT_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodedstream.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodedstream.h
deleted file mode 100644
index 223601c05..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodedstream.h
+++ /dev/null
@@ -1,299 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ENCODEDSTREAM_H_
-#define RAPIDJSON_ENCODEDSTREAM_H_
-
-#include "stream.h"
-#include "memorystream.h"
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Input byte stream wrapper with a statically bound encoding.
-/*!
- \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.
- \tparam InputByteStream Type of input byte stream. For example, FileReadStream.
-*/
-template <typename Encoding, typename InputByteStream>
-class EncodedInputStream {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
-public:
- typedef typename Encoding::Ch Ch;
-
- EncodedInputStream(InputByteStream& is) : is_(is) {
- current_ = Encoding::TakeBOM(is_);
- }
-
- Ch Peek() const { return current_; }
- Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; }
- size_t Tell() const { return is_.Tell(); }
-
- // Not implemented
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- EncodedInputStream(const EncodedInputStream&);
- EncodedInputStream& operator=(const EncodedInputStream&);
-
- InputByteStream& is_;
- Ch current_;
-};
-
-//! Specialized for UTF8 MemoryStream.
-template <>
-class EncodedInputStream<UTF8<>, MemoryStream> {
-public:
- typedef UTF8<>::Ch Ch;
-
- EncodedInputStream(MemoryStream& is) : is_(is) {
- if (static_cast<unsigned char>(is_.Peek()) == 0xEFu) is_.Take();
- if (static_cast<unsigned char>(is_.Peek()) == 0xBBu) is_.Take();
- if (static_cast<unsigned char>(is_.Peek()) == 0xBFu) is_.Take();
- }
- Ch Peek() const { return is_.Peek(); }
- Ch Take() { return is_.Take(); }
- size_t Tell() const { return is_.Tell(); }
-
- // Not implemented
- void Put(Ch) {}
- void Flush() {}
- Ch* PutBegin() { return 0; }
- size_t PutEnd(Ch*) { return 0; }
-
- MemoryStream& is_;
-
-private:
- EncodedInputStream(const EncodedInputStream&);
- EncodedInputStream& operator=(const EncodedInputStream&);
-};
-
-//! Output byte stream wrapper with statically bound encoding.
-/*!
- \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.
- \tparam OutputByteStream Type of input byte stream. For example, FileWriteStream.
-*/
-template <typename Encoding, typename OutputByteStream>
-class EncodedOutputStream {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
-public:
- typedef typename Encoding::Ch Ch;
-
- EncodedOutputStream(OutputByteStream& os, bool putBOM = true) : os_(os) {
- if (putBOM)
- Encoding::PutBOM(os_);
- }
-
- void Put(Ch c) { Encoding::Put(os_, c); }
- void Flush() { os_.Flush(); }
-
- // Not implemented
- Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
- Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
- size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- EncodedOutputStream(const EncodedOutputStream&);
- EncodedOutputStream& operator=(const EncodedOutputStream&);
-
- OutputByteStream& os_;
-};
-
-#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
-
-//! Input stream wrapper with dynamically bound encoding and automatic encoding detection.
-/*!
- \tparam CharType Type of character for reading.
- \tparam InputByteStream type of input byte stream to be wrapped.
-*/
-template <typename CharType, typename InputByteStream>
-class AutoUTFInputStream {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
-public:
- typedef CharType Ch;
-
- //! Constructor.
- /*!
- \param is input stream to be wrapped.
- \param type UTF encoding type if it is not detected from the stream.
- */
- AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) {
- RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
- DetectType();
- static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) };
- takeFunc_ = f[type_];
- current_ = takeFunc_(*is_);
- }
-
- UTFType GetType() const { return type_; }
- bool HasBOM() const { return hasBOM_; }
-
- Ch Peek() const { return current_; }
- Ch Take() { Ch c = current_; current_ = takeFunc_(*is_); return c; }
- size_t Tell() const { return is_->Tell(); }
-
- // Not implemented
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- AutoUTFInputStream(const AutoUTFInputStream&);
- AutoUTFInputStream& operator=(const AutoUTFInputStream&);
-
- // Detect encoding type with BOM or RFC 4627
- void DetectType() {
- // BOM (Byte Order Mark):
- // 00 00 FE FF UTF-32BE
- // FF FE 00 00 UTF-32LE
- // FE FF UTF-16BE
- // FF FE UTF-16LE
- // EF BB BF UTF-8
-
- const unsigned char* c = reinterpret_cast<const unsigned char *>(is_->Peek4());
- if (!c)
- return;
-
- unsigned bom = static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
- hasBOM_ = false;
- if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
- else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
- else if ((bom & 0xFFFF) == 0xFFFE) { type_ = kUTF16BE; hasBOM_ = true; is_->Take(); is_->Take(); }
- else if ((bom & 0xFFFF) == 0xFEFF) { type_ = kUTF16LE; hasBOM_ = true; is_->Take(); is_->Take(); }
- else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ = kUTF8; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); }
-
- // RFC 4627: Section 3
- // "Since the first two characters of a JSON text will always be ASCII
- // characters [RFC0020], it is possible to determine whether an octet
- // stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
- // at the pattern of nulls in the first four octets."
- // 00 00 00 xx UTF-32BE
- // 00 xx 00 xx UTF-16BE
- // xx 00 00 00 UTF-32LE
- // xx 00 xx 00 UTF-16LE
- // xx xx xx xx UTF-8
-
- if (!hasBOM_) {
- int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
- switch (pattern) {
- case 0x08: type_ = kUTF32BE; break;
- case 0x0A: type_ = kUTF16BE; break;
- case 0x01: type_ = kUTF32LE; break;
- case 0x05: type_ = kUTF16LE; break;
- case 0x0F: type_ = kUTF8; break;
- default: break; // Use type defined by user.
- }
- }
-
- // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
- if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
- if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
- }
-
- typedef Ch (*TakeFunc)(InputByteStream& is);
- InputByteStream* is_;
- UTFType type_;
- Ch current_;
- TakeFunc takeFunc_;
- bool hasBOM_;
-};
-
-//! Output stream wrapper with dynamically bound encoding and automatic encoding detection.
-/*!
- \tparam CharType Type of character for writing.
- \tparam OutputByteStream type of output byte stream to be wrapped.
-*/
-template <typename CharType, typename OutputByteStream>
-class AutoUTFOutputStream {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
-public:
- typedef CharType Ch;
-
- //! Constructor.
- /*!
- \param os output stream to be wrapped.
- \param type UTF encoding type.
- \param putBOM Whether to write BOM at the beginning of the stream.
- */
- AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) {
- RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE);
-
- // Runtime check whether the size of character type is sufficient. It only perform checks with assertion.
- if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
- if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
-
- static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) };
- putFunc_ = f[type_];
-
- if (putBOM)
- PutBOM();
- }
-
- UTFType GetType() const { return type_; }
-
- void Put(Ch c) { putFunc_(*os_, c); }
- void Flush() { os_->Flush(); }
-
- // Not implemented
- Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
- Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
- size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- AutoUTFOutputStream(const AutoUTFOutputStream&);
- AutoUTFOutputStream& operator=(const AutoUTFOutputStream&);
-
- void PutBOM() {
- typedef void (*PutBOMFunc)(OutputByteStream&);
- static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
- f[type_](*os_);
- }
-
- typedef void (*PutFunc)(OutputByteStream&, Ch);
-
- OutputByteStream* os_;
- UTFType type_;
- PutFunc putFunc_;
-};
-
-#undef RAPIDJSON_ENCODINGS_FUNC
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_FILESTREAM_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodings.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodings.h
deleted file mode 100644
index 0df1c3435..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/encodings.h
+++ /dev/null
@@ -1,716 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ENCODINGS_H_
-#define RAPIDJSON_ENCODINGS_H_
-
-#include "rapidjson.h"
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data
-RAPIDJSON_DIAG_OFF(4702) // unreachable code
-#elif defined(__GNUC__)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-RAPIDJSON_DIAG_OFF(overflow)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// Encoding
-
-/*! \class rapidjson::Encoding
- \brief Concept for encoding of Unicode characters.
-
-\code
-concept Encoding {
- typename Ch; //! Type of character. A "character" is actually a code unit in unicode's definition.
-
- enum { supportUnicode = 1 }; // or 0 if not supporting unicode
-
- //! \brief Encode a Unicode codepoint to an output stream.
- //! \param os Output stream.
- //! \param codepoint An unicode codepoint, ranging from 0x0 to 0x10FFFF inclusively.
- template<typename OutputStream>
- static void Encode(OutputStream& os, unsigned codepoint);
-
- //! \brief Decode a Unicode codepoint from an input stream.
- //! \param is Input stream.
- //! \param codepoint Output of the unicode codepoint.
- //! \return true if a valid codepoint can be decoded from the stream.
- template <typename InputStream>
- static bool Decode(InputStream& is, unsigned* codepoint);
-
- //! \brief Validate one Unicode codepoint from an encoded stream.
- //! \param is Input stream to obtain codepoint.
- //! \param os Output for copying one codepoint.
- //! \return true if it is valid.
- //! \note This function just validating and copying the codepoint without actually decode it.
- template <typename InputStream, typename OutputStream>
- static bool Validate(InputStream& is, OutputStream& os);
-
- // The following functions are deal with byte streams.
-
- //! Take a character from input byte stream, skip BOM if exist.
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is);
-
- //! Take a character from input byte stream.
- template <typename InputByteStream>
- static Ch Take(InputByteStream& is);
-
- //! Put BOM to output byte stream.
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os);
-
- //! Put a character to output byte stream.
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, Ch c);
-};
-\endcode
-*/
-
-///////////////////////////////////////////////////////////////////////////////
-// UTF8
-
-//! UTF-8 encoding.
-/*! http://en.wikipedia.org/wiki/UTF-8
- http://tools.ietf.org/html/rfc3629
- \tparam CharType Code unit for storing 8-bit UTF-8 data. Default is char.
- \note implements Encoding concept
-*/
-template<typename CharType = char>
-struct UTF8 {
- typedef CharType Ch;
-
- enum { supportUnicode = 1 };
-
- template<typename OutputStream>
- static void Encode(OutputStream& os, unsigned codepoint) {
- if (codepoint <= 0x7F)
- os.Put(static_cast<Ch>(codepoint & 0xFF));
- else if (codepoint <= 0x7FF) {
- os.Put(static_cast<Ch>(0xC0 | ((codepoint >> 6) & 0xFF)));
- os.Put(static_cast<Ch>(0x80 | ((codepoint & 0x3F))));
- }
- else if (codepoint <= 0xFFFF) {
- os.Put(static_cast<Ch>(0xE0 | ((codepoint >> 12) & 0xFF)));
- os.Put(static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
- os.Put(static_cast<Ch>(0x80 | (codepoint & 0x3F)));
- }
- else {
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- os.Put(static_cast<Ch>(0xF0 | ((codepoint >> 18) & 0xFF)));
- os.Put(static_cast<Ch>(0x80 | ((codepoint >> 12) & 0x3F)));
- os.Put(static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
- os.Put(static_cast<Ch>(0x80 | (codepoint & 0x3F)));
- }
- }
-
- template<typename OutputStream>
- static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
- if (codepoint <= 0x7F)
- PutUnsafe(os, static_cast<Ch>(codepoint & 0xFF));
- else if (codepoint <= 0x7FF) {
- PutUnsafe(os, static_cast<Ch>(0xC0 | ((codepoint >> 6) & 0xFF)));
- PutUnsafe(os, static_cast<Ch>(0x80 | ((codepoint & 0x3F))));
- }
- else if (codepoint <= 0xFFFF) {
- PutUnsafe(os, static_cast<Ch>(0xE0 | ((codepoint >> 12) & 0xFF)));
- PutUnsafe(os, static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
- PutUnsafe(os, static_cast<Ch>(0x80 | (codepoint & 0x3F)));
- }
- else {
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- PutUnsafe(os, static_cast<Ch>(0xF0 | ((codepoint >> 18) & 0xFF)));
- PutUnsafe(os, static_cast<Ch>(0x80 | ((codepoint >> 12) & 0x3F)));
- PutUnsafe(os, static_cast<Ch>(0x80 | ((codepoint >> 6) & 0x3F)));
- PutUnsafe(os, static_cast<Ch>(0x80 | (codepoint & 0x3F)));
- }
- }
-
- template <typename InputStream>
- static bool Decode(InputStream& is, unsigned* codepoint) {
-#define COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
-#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
-#define TAIL() COPY(); TRANS(0x70)
- typename InputStream::Ch c = is.Take();
- if (!(c & 0x80)) {
- *codepoint = static_cast<unsigned char>(c);
- return true;
- }
-
- unsigned char type = GetRange(static_cast<unsigned char>(c));
- if (type >= 32) {
- *codepoint = 0;
- } else {
- *codepoint = (0xFFu >> type) & static_cast<unsigned char>(c);
- }
- bool result = true;
- switch (type) {
- case 2: TAIL(); return result;
- case 3: TAIL(); TAIL(); return result;
- case 4: COPY(); TRANS(0x50); TAIL(); return result;
- case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
- case 6: TAIL(); TAIL(); TAIL(); return result;
- case 10: COPY(); TRANS(0x20); TAIL(); return result;
- case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
- default: return false;
- }
-#undef COPY
-#undef TRANS
-#undef TAIL
- }
-
- template <typename InputStream, typename OutputStream>
- static bool Validate(InputStream& is, OutputStream& os) {
-#define COPY() os.Put(c = is.Take())
-#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
-#define TAIL() COPY(); TRANS(0x70)
- Ch c;
- COPY();
- if (!(c & 0x80))
- return true;
-
- bool result = true;
- switch (GetRange(static_cast<unsigned char>(c))) {
- case 2: TAIL(); return result;
- case 3: TAIL(); TAIL(); return result;
- case 4: COPY(); TRANS(0x50); TAIL(); return result;
- case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
- case 6: TAIL(); TAIL(); TAIL(); return result;
- case 10: COPY(); TRANS(0x20); TAIL(); return result;
- case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
- default: return false;
- }
-#undef COPY
-#undef TRANS
-#undef TAIL
- }
-
- static unsigned char GetRange(unsigned char c) {
- // Referring to DFA of http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
- // With new mapping 1 -> 0x10, 7 -> 0x20, 9 -> 0x40, such that AND operation can test multiple types.
- static const unsigned char type[] = {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
- 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
- 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
- 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
- 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
- 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
- };
- return type[c];
- }
-
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- typename InputByteStream::Ch c = Take(is);
- if (static_cast<unsigned char>(c) != 0xEFu) return c;
- c = is.Take();
- if (static_cast<unsigned char>(c) != 0xBBu) return c;
- c = is.Take();
- if (static_cast<unsigned char>(c) != 0xBFu) return c;
- c = is.Take();
- return c;
- }
-
- template <typename InputByteStream>
- static Ch Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- return static_cast<Ch>(is.Take());
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(0xEFu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xBBu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xBFu));
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, Ch c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(c));
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// UTF16
-
-//! UTF-16 encoding.
-/*! http://en.wikipedia.org/wiki/UTF-16
- http://tools.ietf.org/html/rfc2781
- \tparam CharType Type for storing 16-bit UTF-16 data. Default is wchar_t. C++11 may use char16_t instead.
- \note implements Encoding concept
-
- \note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness.
- For streaming, use UTF16LE and UTF16BE, which handle endianness.
-*/
-template<typename CharType = wchar_t>
-struct UTF16 {
- typedef CharType Ch;
- RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 2);
-
- enum { supportUnicode = 1 };
-
- template<typename OutputStream>
- static void Encode(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
- if (codepoint <= 0xFFFF) {
- RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
- os.Put(static_cast<typename OutputStream::Ch>(codepoint));
- }
- else {
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- unsigned v = codepoint - 0x10000;
- os.Put(static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
- os.Put(static_cast<typename OutputStream::Ch>((v & 0x3FF) | 0xDC00));
- }
- }
-
-
- template<typename OutputStream>
- static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
- if (codepoint <= 0xFFFF) {
- RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
- PutUnsafe(os, static_cast<typename OutputStream::Ch>(codepoint));
- }
- else {
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- unsigned v = codepoint - 0x10000;
- PutUnsafe(os, static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
- PutUnsafe(os, static_cast<typename OutputStream::Ch>((v & 0x3FF) | 0xDC00));
- }
- }
-
- template <typename InputStream>
- static bool Decode(InputStream& is, unsigned* codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
- typename InputStream::Ch c = is.Take();
- if (c < 0xD800 || c > 0xDFFF) {
- *codepoint = static_cast<unsigned>(c);
- return true;
- }
- else if (c <= 0xDBFF) {
- *codepoint = (static_cast<unsigned>(c) & 0x3FF) << 10;
- c = is.Take();
- *codepoint |= (static_cast<unsigned>(c) & 0x3FF);
- *codepoint += 0x10000;
- return c >= 0xDC00 && c <= 0xDFFF;
- }
- return false;
- }
-
- template <typename InputStream, typename OutputStream>
- static bool Validate(InputStream& is, OutputStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
- typename InputStream::Ch c;
- os.Put(static_cast<typename OutputStream::Ch>(c = is.Take()));
- if (c < 0xD800 || c > 0xDFFF)
- return true;
- else if (c <= 0xDBFF) {
- os.Put(c = is.Take());
- return c >= 0xDC00 && c <= 0xDFFF;
- }
- return false;
- }
-};
-
-//! UTF-16 little endian encoding.
-template<typename CharType = wchar_t>
-struct UTF16LE : UTF16<CharType> {
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- CharType c = Take(is);
- return static_cast<uint16_t>(c) == 0xFEFFu ? Take(is) : c;
- }
-
- template <typename InputByteStream>
- static CharType Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- unsigned c = static_cast<uint8_t>(is.Take());
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
- return static_cast<CharType>(c);
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, CharType c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(static_cast<unsigned>(c) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((static_cast<unsigned>(c) >> 8) & 0xFFu));
- }
-};
-
-//! UTF-16 big endian encoding.
-template<typename CharType = wchar_t>
-struct UTF16BE : UTF16<CharType> {
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- CharType c = Take(is);
- return static_cast<uint16_t>(c) == 0xFEFFu ? Take(is) : c;
- }
-
- template <typename InputByteStream>
- static CharType Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- unsigned c = static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
- c |= static_cast<uint8_t>(is.Take());
- return static_cast<CharType>(c);
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, CharType c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>((static_cast<unsigned>(c) >> 8) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>(static_cast<unsigned>(c) & 0xFFu));
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// UTF32
-
-//! UTF-32 encoding.
-/*! http://en.wikipedia.org/wiki/UTF-32
- \tparam CharType Type for storing 32-bit UTF-32 data. Default is unsigned. C++11 may use char32_t instead.
- \note implements Encoding concept
-
- \note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness.
- For streaming, use UTF32LE and UTF32BE, which handle endianness.
-*/
-template<typename CharType = unsigned>
-struct UTF32 {
- typedef CharType Ch;
- RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 4);
-
- enum { supportUnicode = 1 };
-
- template<typename OutputStream>
- static void Encode(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4);
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- os.Put(codepoint);
- }
-
- template<typename OutputStream>
- static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4);
- RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
- PutUnsafe(os, codepoint);
- }
-
- template <typename InputStream>
- static bool Decode(InputStream& is, unsigned* codepoint) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4);
- Ch c = is.Take();
- *codepoint = c;
- return c <= 0x10FFFF;
- }
-
- template <typename InputStream, typename OutputStream>
- static bool Validate(InputStream& is, OutputStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 4);
- Ch c;
- os.Put(c = is.Take());
- return c <= 0x10FFFF;
- }
-};
-
-//! UTF-32 little endian enocoding.
-template<typename CharType = unsigned>
-struct UTF32LE : UTF32<CharType> {
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- CharType c = Take(is);
- return static_cast<uint32_t>(c) == 0x0000FEFFu ? Take(is) : c;
- }
-
- template <typename InputByteStream>
- static CharType Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- unsigned c = static_cast<uint8_t>(is.Take());
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 16;
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 24;
- return static_cast<CharType>(c);
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
- os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, CharType c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(c & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 8) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 16) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 24) & 0xFFu));
- }
-};
-
-//! UTF-32 big endian encoding.
-template<typename CharType = unsigned>
-struct UTF32BE : UTF32<CharType> {
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- CharType c = Take(is);
- return static_cast<uint32_t>(c) == 0x0000FEFFu ? Take(is) : c;
- }
-
- template <typename InputByteStream>
- static CharType Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- unsigned c = static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 24;
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 16;
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
- c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take()));
- return static_cast<CharType>(c);
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
- os.Put(static_cast<typename OutputByteStream::Ch>(0x00u));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
- os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, CharType c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 24) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 16) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>((c >> 8) & 0xFFu));
- os.Put(static_cast<typename OutputByteStream::Ch>(c & 0xFFu));
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// ASCII
-
-//! ASCII encoding.
-/*! http://en.wikipedia.org/wiki/ASCII
- \tparam CharType Code unit for storing 7-bit ASCII data. Default is char.
- \note implements Encoding concept
-*/
-template<typename CharType = char>
-struct ASCII {
- typedef CharType Ch;
-
- enum { supportUnicode = 0 };
-
- template<typename OutputStream>
- static void Encode(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_ASSERT(codepoint <= 0x7F);
- os.Put(static_cast<Ch>(codepoint & 0xFF));
- }
-
- template<typename OutputStream>
- static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
- RAPIDJSON_ASSERT(codepoint <= 0x7F);
- PutUnsafe(os, static_cast<Ch>(codepoint & 0xFF));
- }
-
- template <typename InputStream>
- static bool Decode(InputStream& is, unsigned* codepoint) {
- uint8_t c = static_cast<uint8_t>(is.Take());
- *codepoint = c;
- return c <= 0X7F;
- }
-
- template <typename InputStream, typename OutputStream>
- static bool Validate(InputStream& is, OutputStream& os) {
- uint8_t c = static_cast<uint8_t>(is.Take());
- os.Put(static_cast<typename OutputStream::Ch>(c));
- return c <= 0x7F;
- }
-
- template <typename InputByteStream>
- static CharType TakeBOM(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- uint8_t c = static_cast<uint8_t>(Take(is));
- return static_cast<Ch>(c);
- }
-
- template <typename InputByteStream>
- static Ch Take(InputByteStream& is) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
- return static_cast<Ch>(is.Take());
- }
-
- template <typename OutputByteStream>
- static void PutBOM(OutputByteStream& os) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- (void)os;
- }
-
- template <typename OutputByteStream>
- static void Put(OutputByteStream& os, Ch c) {
- RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
- os.Put(static_cast<typename OutputByteStream::Ch>(c));
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// AutoUTF
-
-//! Runtime-specified UTF encoding type of a stream.
-enum UTFType {
- kUTF8 = 0, //!< UTF-8.
- kUTF16LE = 1, //!< UTF-16 little endian.
- kUTF16BE = 2, //!< UTF-16 big endian.
- kUTF32LE = 3, //!< UTF-32 little endian.
- kUTF32BE = 4 //!< UTF-32 big endian.
-};
-
-//! Dynamically select encoding according to stream's runtime-specified UTF encoding type.
-/*! \note This class can be used with AutoUTFInputtStream and AutoUTFOutputStream, which provides GetType().
-*/
-template<typename CharType>
-struct AutoUTF {
- typedef CharType Ch;
-
- enum { supportUnicode = 1 };
-
-#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
-
- template<typename OutputStream>
- static RAPIDJSON_FORCEINLINE void Encode(OutputStream& os, unsigned codepoint) {
- typedef void (*EncodeFunc)(OutputStream&, unsigned);
- static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Encode) };
- (*f[os.GetType()])(os, codepoint);
- }
-
- template<typename OutputStream>
- static RAPIDJSON_FORCEINLINE void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
- typedef void (*EncodeFunc)(OutputStream&, unsigned);
- static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(EncodeUnsafe) };
- (*f[os.GetType()])(os, codepoint);
- }
-
- template <typename InputStream>
- static RAPIDJSON_FORCEINLINE bool Decode(InputStream& is, unsigned* codepoint) {
- typedef bool (*DecodeFunc)(InputStream&, unsigned*);
- static const DecodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Decode) };
- return (*f[is.GetType()])(is, codepoint);
- }
-
- template <typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
- typedef bool (*ValidateFunc)(InputStream&, OutputStream&);
- static const ValidateFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Validate) };
- return (*f[is.GetType()])(is, os);
- }
-
-#undef RAPIDJSON_ENCODINGS_FUNC
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Transcoder
-
-//! Encoding conversion.
-template<typename SourceEncoding, typename TargetEncoding>
-struct Transcoder {
- //! Take one Unicode codepoint from source encoding, convert it to target encoding and put it to the output stream.
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) {
- unsigned codepoint;
- if (!SourceEncoding::Decode(is, &codepoint))
- return false;
- TargetEncoding::Encode(os, codepoint);
- return true;
- }
-
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) {
- unsigned codepoint;
- if (!SourceEncoding::Decode(is, &codepoint))
- return false;
- TargetEncoding::EncodeUnsafe(os, codepoint);
- return true;
- }
-
- //! Validate one Unicode codepoint from an encoded stream.
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
- return Transcode(is, os); // Since source/target encoding is different, must transcode.
- }
-};
-
-// Forward declaration.
-template<typename Stream>
-inline void PutUnsafe(Stream& stream, typename Stream::Ch c);
-
-//! Specialization of Transcoder with same source and target encoding.
-template<typename Encoding>
-struct Transcoder<Encoding, Encoding> {
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) {
- os.Put(is.Take()); // Just copy one code unit. This semantic is different from primary template class.
- return true;
- }
-
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) {
- PutUnsafe(os, is.Take()); // Just copy one code unit. This semantic is different from primary template class.
- return true;
- }
-
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
- return Encoding::Validate(is, os); // source/target encoding are the same
- }
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__GNUC__) || defined(_MSC_VER)
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_ENCODINGS_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/en.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/en.h
deleted file mode 100644
index 2db838bff..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/en.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ERROR_EN_H_
-#define RAPIDJSON_ERROR_EN_H_
-
-#include "error.h"
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(switch-enum)
-RAPIDJSON_DIAG_OFF(covered-switch-default)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Maps error code of parsing into error message.
-/*!
- \ingroup RAPIDJSON_ERRORS
- \param parseErrorCode Error code obtained in parsing.
- \return the error message.
- \note User can make a copy of this function for localization.
- Using switch-case is safer for future modification of error codes.
-*/
-inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) {
- switch (parseErrorCode) {
- case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
-
- case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
- case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
-
- case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
-
- case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
- case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
- case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
-
- case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
-
- case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
- case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
- case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
- case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
- case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
-
- case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
- case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
- case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
-
- case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
- case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
-
- default: return RAPIDJSON_ERROR_STRING("Unknown error.");
- }
-}
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_ERROR_EN_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/error.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/error.h
deleted file mode 100644
index 9311d2f03..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/error/error.h
+++ /dev/null
@@ -1,161 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ERROR_ERROR_H_
-#define RAPIDJSON_ERROR_ERROR_H_
-
-#include "../rapidjson.h"
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-/*! \file error.h */
-
-/*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_ERROR_CHARTYPE
-
-//! Character type of error messages.
-/*! \ingroup RAPIDJSON_ERRORS
- The default character type is \c char.
- On Windows, user can define this macro as \c TCHAR for supporting both
- unicode/non-unicode settings.
-*/
-#ifndef RAPIDJSON_ERROR_CHARTYPE
-#define RAPIDJSON_ERROR_CHARTYPE char
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_ERROR_STRING
-
-//! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[].
-/*! \ingroup RAPIDJSON_ERRORS
- By default this conversion macro does nothing.
- On Windows, user can define this macro as \c _T(x) for supporting both
- unicode/non-unicode settings.
-*/
-#ifndef RAPIDJSON_ERROR_STRING
-#define RAPIDJSON_ERROR_STRING(x) x
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// ParseErrorCode
-
-//! Error code of parsing.
-/*! \ingroup RAPIDJSON_ERRORS
- \see GenericReader::Parse, GenericReader::GetParseErrorCode
-*/
-enum ParseErrorCode {
- kParseErrorNone = 0, //!< No error.
-
- kParseErrorDocumentEmpty, //!< The document is empty.
- kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values.
-
- kParseErrorValueInvalid, //!< Invalid value.
-
- kParseErrorObjectMissName, //!< Missing a name for object member.
- kParseErrorObjectMissColon, //!< Missing a colon after a name of object member.
- kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member.
-
- kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element.
-
- kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string.
- kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid.
- kParseErrorStringEscapeInvalid, //!< Invalid escape character in string.
- kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string.
- kParseErrorStringInvalidEncoding, //!< Invalid encoding in string.
-
- kParseErrorNumberTooBig, //!< Number too big to be stored in double.
- kParseErrorNumberMissFraction, //!< Miss fraction part in number.
- kParseErrorNumberMissExponent, //!< Miss exponent in number.
-
- kParseErrorTermination, //!< Parsing was terminated.
- kParseErrorUnspecificSyntaxError //!< Unspecific syntax error.
-};
-
-//! Result of parsing (wraps ParseErrorCode)
-/*!
- \ingroup RAPIDJSON_ERRORS
- \code
- Document doc;
- ParseResult ok = doc.Parse("[42]");
- if (!ok) {
- fprintf(stderr, "JSON parse error: %s (%u)",
- GetParseError_En(ok.Code()), ok.Offset());
- exit(EXIT_FAILURE);
- }
- \endcode
- \see GenericReader::Parse, GenericDocument::Parse
-*/
-struct ParseResult {
- //!! Unspecified boolean type
- typedef bool (ParseResult::*BooleanType)() const;
-public:
- //! Default constructor, no error.
- ParseResult() : code_(kParseErrorNone), offset_(0) {}
- //! Constructor to set an error.
- ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {}
-
- //! Get the error code.
- ParseErrorCode Code() const { return code_; }
- //! Get the error offset, if \ref IsError(), 0 otherwise.
- size_t Offset() const { return offset_; }
-
- //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError().
- operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; }
- //! Whether the result is an error.
- bool IsError() const { return code_ != kParseErrorNone; }
-
- bool operator==(const ParseResult& that) const { return code_ == that.code_; }
- bool operator==(ParseErrorCode code) const { return code_ == code; }
- friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; }
-
- bool operator!=(const ParseResult& that) const { return !(*this == that); }
- bool operator!=(ParseErrorCode code) const { return !(*this == code); }
- friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; }
-
- //! Reset error code.
- void Clear() { Set(kParseErrorNone); }
- //! Update error code and offset.
- void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; }
-
-private:
- ParseErrorCode code_;
- size_t offset_;
-};
-
-//! Function pointer type of GetParseError().
-/*! \ingroup RAPIDJSON_ERRORS
-
- This is the prototype for \c GetParseError_X(), where \c X is a locale.
- User can dynamically change locale in runtime, e.g.:
-\code
- GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
- const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
-\endcode
-*/
-typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_ERROR_ERROR_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filereadstream.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filereadstream.h
deleted file mode 100644
index b56ea13b3..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filereadstream.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_FILEREADSTREAM_H_
-#define RAPIDJSON_FILEREADSTREAM_H_
-
-#include "stream.h"
-#include <cstdio>
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-RAPIDJSON_DIAG_OFF(unreachable-code)
-RAPIDJSON_DIAG_OFF(missing-noreturn)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! File byte stream for input using fread().
-/*!
- \note implements Stream concept
-*/
-class FileReadStream {
-public:
- typedef char Ch; //!< Character type (byte).
-
- //! Constructor.
- /*!
- \param fp File pointer opened for read.
- \param buffer user-supplied buffer.
- \param bufferSize size of buffer in bytes. Must >=4 bytes.
- */
- FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
- RAPIDJSON_ASSERT(fp_ != 0);
- RAPIDJSON_ASSERT(bufferSize >= 4);
- Read();
- }
-
- Ch Peek() const { return *current_; }
- Ch Take() { Ch c = *current_; Read(); return c; }
- size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
-
- // Not implemented
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
- // For encoding detection only.
- const Ch* Peek4() const {
- return (current_ + 4 <= bufferLast_) ? current_ : 0;
- }
-
-private:
- void Read() {
- if (current_ < bufferLast_)
- ++current_;
- else if (!eof_) {
- count_ += readCount_;
- readCount_ = fread(buffer_, 1, bufferSize_, fp_);
- bufferLast_ = buffer_ + readCount_ - 1;
- current_ = buffer_;
-
- if (readCount_ < bufferSize_) {
- buffer_[readCount_] = '\0';
- ++bufferLast_;
- eof_ = true;
- }
- }
- }
-
- std::FILE* fp_;
- Ch *buffer_;
- size_t bufferSize_;
- Ch *bufferLast_;
- Ch *current_;
- size_t readCount_;
- size_t count_; //!< Number of characters read
- bool eof_;
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_FILESTREAM_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filewritestream.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filewritestream.h
deleted file mode 100644
index 6378dd60e..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/filewritestream.h
+++ /dev/null
@@ -1,104 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_FILEWRITESTREAM_H_
-#define RAPIDJSON_FILEWRITESTREAM_H_
-
-#include "stream.h"
-#include <cstdio>
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(unreachable-code)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Wrapper of C file stream for input using fread().
-/*!
- \note implements Stream concept
-*/
-class FileWriteStream {
-public:
- typedef char Ch; //!< Character type. Only support char.
-
- FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
- RAPIDJSON_ASSERT(fp_ != 0);
- }
-
- void Put(char c) {
- if (current_ >= bufferEnd_)
- Flush();
-
- *current_++ = c;
- }
-
- void PutN(char c, size_t n) {
- size_t avail = static_cast<size_t>(bufferEnd_ - current_);
- while (n > avail) {
- std::memset(current_, c, avail);
- current_ += avail;
- Flush();
- n -= avail;
- avail = static_cast<size_t>(bufferEnd_ - current_);
- }
-
- if (n > 0) {
- std::memset(current_, c, n);
- current_ += n;
- }
- }
-
- void Flush() {
- if (current_ != buffer_) {
- size_t result = fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
- if (result < static_cast<size_t>(current_ - buffer_)) {
- // failure deliberately ignored at this time
- // added to avoid warn_unused_result build errors
- }
- current_ = buffer_;
- }
- }
-
- // Not implemented
- char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
- char Take() { RAPIDJSON_ASSERT(false); return 0; }
- size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
- char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- // Prohibit copy constructor & assignment operator.
- FileWriteStream(const FileWriteStream&);
- FileWriteStream& operator=(const FileWriteStream&);
-
- std::FILE* fp_;
- char *buffer_;
- char *bufferEnd_;
- char *current_;
-};
-
-//! Implement specialized version of PutN() with memset() for better performance.
-template<>
-inline void PutN(FileWriteStream& stream, char c, size_t n) {
- stream.PutN(c, n);
-}
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_FILESTREAM_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/fwd.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/fwd.h
deleted file mode 100644
index e8104e841..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/fwd.h
+++ /dev/null
@@ -1,151 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_FWD_H_
-#define RAPIDJSON_FWD_H_
-
-#include "rapidjson.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-// encodings.h
-
-template<typename CharType> struct UTF8;
-template<typename CharType> struct UTF16;
-template<typename CharType> struct UTF16BE;
-template<typename CharType> struct UTF16LE;
-template<typename CharType> struct UTF32;
-template<typename CharType> struct UTF32BE;
-template<typename CharType> struct UTF32LE;
-template<typename CharType> struct ASCII;
-template<typename CharType> struct AutoUTF;
-
-template<typename SourceEncoding, typename TargetEncoding>
-struct Transcoder;
-
-// allocators.h
-
-class CrtAllocator;
-
-template <typename BaseAllocator>
-class MemoryPoolAllocator;
-
-// stream.h
-
-template <typename Encoding>
-struct GenericStringStream;
-
-typedef GenericStringStream<UTF8<char> > StringStream;
-
-template <typename Encoding>
-struct GenericInsituStringStream;
-
-typedef GenericInsituStringStream<UTF8<char> > InsituStringStream;
-
-// stringbuffer.h
-
-template <typename Encoding, typename Allocator>
-class GenericStringBuffer;
-
-typedef GenericStringBuffer<UTF8<char>, CrtAllocator> StringBuffer;
-
-// filereadstream.h
-
-class FileReadStream;
-
-// filewritestream.h
-
-class FileWriteStream;
-
-// memorybuffer.h
-
-template <typename Allocator>
-struct GenericMemoryBuffer;
-
-typedef GenericMemoryBuffer<CrtAllocator> MemoryBuffer;
-
-// memorystream.h
-
-struct MemoryStream;
-
-// reader.h
-
-template<typename Encoding, typename Derived>
-struct BaseReaderHandler;
-
-template <typename SourceEncoding, typename TargetEncoding, typename StackAllocator>
-class GenericReader;
-
-typedef GenericReader<UTF8<char>, UTF8<char>, CrtAllocator> Reader;
-
-// writer.h
-
-template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
-class Writer;
-
-// prettywriter.h
-
-template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
-class PrettyWriter;
-
-// document.h
-
-template <typename Encoding, typename Allocator>
-struct GenericMember;
-
-template <bool Const, typename Encoding, typename Allocator>
-class GenericMemberIterator;
-
-template<typename CharType>
-struct GenericStringRef;
-
-template <typename Encoding, typename Allocator>
-class GenericValue;
-
-typedef GenericValue<UTF8<char>, MemoryPoolAllocator<CrtAllocator> > Value;
-
-template <typename Encoding, typename Allocator, typename StackAllocator>
-class GenericDocument;
-
-typedef GenericDocument<UTF8<char>, MemoryPoolAllocator<CrtAllocator>, CrtAllocator> Document;
-
-// pointer.h
-
-template <typename ValueType, typename Allocator>
-class GenericPointer;
-
-typedef GenericPointer<Value, CrtAllocator> Pointer;
-
-// schema.h
-
-template <typename SchemaDocumentType>
-class IGenericRemoteSchemaDocumentProvider;
-
-template <typename ValueT, typename Allocator>
-class GenericSchemaDocument;
-
-typedef GenericSchemaDocument<Value, CrtAllocator> SchemaDocument;
-typedef IGenericRemoteSchemaDocumentProvider<SchemaDocument> IRemoteSchemaDocumentProvider;
-
-template <
- typename SchemaDocumentType,
- typename OutputHandler,
- typename StateAllocator>
-class GenericSchemaValidator;
-
-typedef GenericSchemaValidator<SchemaDocument, BaseReaderHandler<UTF8<char>, void>, CrtAllocator> SchemaValidator;
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_RAPIDJSONFWD_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/biginteger.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/biginteger.h
deleted file mode 100644
index 9d3e88c99..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/biginteger.h
+++ /dev/null
@@ -1,290 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_BIGINTEGER_H_
-#define RAPIDJSON_BIGINTEGER_H_
-
-#include "../rapidjson.h"
-
-#if defined(_MSC_VER) && defined(_M_AMD64)
-#include <intrin.h> // for _umul128
-#pragma intrinsic(_umul128)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-class BigInteger {
-public:
- typedef uint64_t Type;
-
- BigInteger(const BigInteger& rhs) : count_(rhs.count_) {
- std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
- }
-
- explicit BigInteger(uint64_t u) : count_(1) {
- digits_[0] = u;
- }
-
- BigInteger(const char* decimals, size_t length) : count_(1) {
- RAPIDJSON_ASSERT(length > 0);
- digits_[0] = 0;
- size_t i = 0;
- const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19
- while (length >= kMaxDigitPerIteration) {
- AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration);
- length -= kMaxDigitPerIteration;
- i += kMaxDigitPerIteration;
- }
-
- if (length > 0)
- AppendDecimal64(decimals + i, decimals + i + length);
- }
-
- BigInteger& operator=(const BigInteger &rhs)
- {
- if (this != &rhs) {
- count_ = rhs.count_;
- std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
- }
- return *this;
- }
-
- BigInteger& operator=(uint64_t u) {
- digits_[0] = u;
- count_ = 1;
- return *this;
- }
-
- BigInteger& operator+=(uint64_t u) {
- Type backup = digits_[0];
- digits_[0] += u;
- for (size_t i = 0; i < count_ - 1; i++) {
- if (digits_[i] >= backup)
- return *this; // no carry
- backup = digits_[i + 1];
- digits_[i + 1] += 1;
- }
-
- // Last carry
- if (digits_[count_ - 1] < backup)
- PushBack(1);
-
- return *this;
- }
-
- BigInteger& operator*=(uint64_t u) {
- if (u == 0) return *this = 0;
- if (u == 1) return *this;
- if (*this == 1) return *this = u;
-
- uint64_t k = 0;
- for (size_t i = 0; i < count_; i++) {
- uint64_t hi;
- digits_[i] = MulAdd64(digits_[i], u, k, &hi);
- k = hi;
- }
-
- if (k > 0)
- PushBack(k);
-
- return *this;
- }
-
- BigInteger& operator*=(uint32_t u) {
- if (u == 0) return *this = 0;
- if (u == 1) return *this;
- if (*this == 1) return *this = u;
-
- uint64_t k = 0;
- for (size_t i = 0; i < count_; i++) {
- const uint64_t c = digits_[i] >> 32;
- const uint64_t d = digits_[i] & 0xFFFFFFFF;
- const uint64_t uc = u * c;
- const uint64_t ud = u * d;
- const uint64_t p0 = ud + k;
- const uint64_t p1 = uc + (p0 >> 32);
- digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32);
- k = p1 >> 32;
- }
-
- if (k > 0)
- PushBack(k);
-
- return *this;
- }
-
- BigInteger& operator<<=(size_t shift) {
- if (IsZero() || shift == 0) return *this;
-
- size_t offset = shift / kTypeBit;
- size_t interShift = shift % kTypeBit;
- RAPIDJSON_ASSERT(count_ + offset <= kCapacity);
-
- if (interShift == 0) {
- std::memmove(&digits_[count_ - 1 + offset], &digits_[count_ - 1], count_ * sizeof(Type));
- count_ += offset;
- }
- else {
- digits_[count_] = 0;
- for (size_t i = count_; i > 0; i--)
- digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift));
- digits_[offset] = digits_[0] << interShift;
- count_ += offset;
- if (digits_[count_])
- count_++;
- }
-
- std::memset(digits_, 0, offset * sizeof(Type));
-
- return *this;
- }
-
- bool operator==(const BigInteger& rhs) const {
- return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0;
- }
-
- bool operator==(const Type rhs) const {
- return count_ == 1 && digits_[0] == rhs;
- }
-
- BigInteger& MultiplyPow5(unsigned exp) {
- static const uint32_t kPow5[12] = {
- 5,
- 5 * 5,
- 5 * 5 * 5,
- 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
- 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5
- };
- if (exp == 0) return *this;
- for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27
- for (; exp >= 13; exp -= 13) *this *= static_cast<uint32_t>(1220703125u); // 5^13
- if (exp > 0) *this *= kPow5[exp - 1];
- return *this;
- }
-
- // Compute absolute difference of this and rhs.
- // Assume this != rhs
- bool Difference(const BigInteger& rhs, BigInteger* out) const {
- int cmp = Compare(rhs);
- RAPIDJSON_ASSERT(cmp != 0);
- const BigInteger *a, *b; // Makes a > b
- bool ret;
- if (cmp < 0) { a = &rhs; b = this; ret = true; }
- else { a = this; b = &rhs; ret = false; }
-
- Type borrow = 0;
- for (size_t i = 0; i < a->count_; i++) {
- Type d = a->digits_[i] - borrow;
- if (i < b->count_)
- d -= b->digits_[i];
- borrow = (d > a->digits_[i]) ? 1 : 0;
- out->digits_[i] = d;
- if (d != 0)
- out->count_ = i + 1;
- }
-
- return ret;
- }
-
- int Compare(const BigInteger& rhs) const {
- if (count_ != rhs.count_)
- return count_ < rhs.count_ ? -1 : 1;
-
- for (size_t i = count_; i-- > 0;)
- if (digits_[i] != rhs.digits_[i])
- return digits_[i] < rhs.digits_[i] ? -1 : 1;
-
- return 0;
- }
-
- size_t GetCount() const { return count_; }
- Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; }
- bool IsZero() const { return count_ == 1 && digits_[0] == 0; }
-
-private:
- void AppendDecimal64(const char* begin, const char* end) {
- uint64_t u = ParseUint64(begin, end);
- if (IsZero())
- *this = u;
- else {
- unsigned exp = static_cast<unsigned>(end - begin);
- (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u
- }
- }
-
- void PushBack(Type digit) {
- RAPIDJSON_ASSERT(count_ < kCapacity);
- digits_[count_++] = digit;
- }
-
- static uint64_t ParseUint64(const char* begin, const char* end) {
- uint64_t r = 0;
- for (const char* p = begin; p != end; ++p) {
- RAPIDJSON_ASSERT(*p >= '0' && *p <= '9');
- r = r * 10u + static_cast<unsigned>(*p - '0');
- }
- return r;
- }
-
- // Assume a * b + k < 2^128
- static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) {
-#if defined(_MSC_VER) && defined(_M_AMD64)
- uint64_t low = _umul128(a, b, outHigh) + k;
- if (low < k)
- (*outHigh)++;
- return low;
-#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
- __extension__ typedef unsigned __int128 uint128;
- uint128 p = static_cast<uint128>(a) * static_cast<uint128>(b);
- p += k;
- *outHigh = static_cast<uint64_t>(p >> 64);
- return static_cast<uint64_t>(p);
-#else
- const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32;
- uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1;
- x1 += (x0 >> 32); // can't give carry
- x1 += x2;
- if (x1 < x2)
- x3 += (static_cast<uint64_t>(1) << 32);
- uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF);
- uint64_t hi = x3 + (x1 >> 32);
-
- lo += k;
- if (lo < k)
- hi++;
- *outHigh = hi;
- return lo;
-#endif
- }
-
- static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000
- static const size_t kCapacity = kBitCount / sizeof(Type);
- static const size_t kTypeBit = sizeof(Type) * 8;
-
- Type digits_[kCapacity];
- size_t count_;
-};
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_BIGINTEGER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/diyfp.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/diyfp.h
deleted file mode 100644
index 29abf8046..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/diyfp.h
+++ /dev/null
@@ -1,258 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-// This is a C++ header-only implementation of Grisu2 algorithm from the publication:
-// Loitsch, Florian. "Printing floating-point numbers quickly and accurately with
-// integers." ACM Sigplan Notices 45.6 (2010): 233-243.
-
-#ifndef RAPIDJSON_DIYFP_H_
-#define RAPIDJSON_DIYFP_H_
-
-#include "../rapidjson.h"
-
-#if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER)
-#include <intrin.h>
-#pragma intrinsic(_BitScanReverse64)
-#pragma intrinsic(_umul128)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-struct DiyFp {
- DiyFp() : f(), e() {}
-
- DiyFp(uint64_t fp, int exp) : f(fp), e(exp) {}
-
- explicit DiyFp(double d) {
- union {
- double d;
- uint64_t u64;
- } u = { d };
-
- int biased_e = static_cast<int>((u.u64 & kDpExponentMask) >> kDpSignificandSize);
- uint64_t significand = (u.u64 & kDpSignificandMask);
- if (biased_e != 0) {
- f = significand + kDpHiddenBit;
- e = biased_e - kDpExponentBias;
- }
- else {
- f = significand;
- e = kDpMinExponent + 1;
- }
- }
-
- DiyFp operator-(const DiyFp& rhs) const {
- return DiyFp(f - rhs.f, e);
- }
-
- DiyFp operator*(const DiyFp& rhs) const {
-#if defined(_MSC_VER) && defined(_M_AMD64)
- uint64_t h;
- uint64_t l = _umul128(f, rhs.f, &h);
- if (l & (uint64_t(1) << 63)) // rounding
- h++;
- return DiyFp(h, e + rhs.e + 64);
-#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
- __extension__ typedef unsigned __int128 uint128;
- uint128 p = static_cast<uint128>(f) * static_cast<uint128>(rhs.f);
- uint64_t h = static_cast<uint64_t>(p >> 64);
- uint64_t l = static_cast<uint64_t>(p);
- if (l & (uint64_t(1) << 63)) // rounding
- h++;
- return DiyFp(h, e + rhs.e + 64);
-#else
- const uint64_t M32 = 0xFFFFFFFF;
- const uint64_t a = f >> 32;
- const uint64_t b = f & M32;
- const uint64_t c = rhs.f >> 32;
- const uint64_t d = rhs.f & M32;
- const uint64_t ac = a * c;
- const uint64_t bc = b * c;
- const uint64_t ad = a * d;
- const uint64_t bd = b * d;
- uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
- tmp += 1U << 31; /// mult_round
- return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
-#endif
- }
-
- DiyFp Normalize() const {
-#if defined(_MSC_VER) && defined(_M_AMD64)
- unsigned long index;
- _BitScanReverse64(&index, f);
- return DiyFp(f << (63 - index), e - (63 - index));
-#elif defined(__GNUC__) && __GNUC__ >= 4
- int s = __builtin_clzll(f);
- return DiyFp(f << s, e - s);
-#else
- DiyFp res = *this;
- while (!(res.f & (static_cast<uint64_t>(1) << 63))) {
- res.f <<= 1;
- res.e--;
- }
- return res;
-#endif
- }
-
- DiyFp NormalizeBoundary() const {
- DiyFp res = *this;
- while (!(res.f & (kDpHiddenBit << 1))) {
- res.f <<= 1;
- res.e--;
- }
- res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
- res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
- return res;
- }
-
- void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {
- DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
- DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
- mi.f <<= mi.e - pl.e;
- mi.e = pl.e;
- *plus = pl;
- *minus = mi;
- }
-
- double ToDouble() const {
- union {
- double d;
- uint64_t u64;
- }u;
- const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
- static_cast<uint64_t>(e + kDpExponentBias);
- u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
- return u.d;
- }
-
- static const int kDiySignificandSize = 64;
- static const int kDpSignificandSize = 52;
- static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
- static const int kDpMaxExponent = 0x7FF - kDpExponentBias;
- static const int kDpMinExponent = -kDpExponentBias;
- static const int kDpDenormalExponent = -kDpExponentBias + 1;
- static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
- static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
- static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
-
- uint64_t f;
- int e;
-};
-
-inline DiyFp GetCachedPowerByIndex(size_t index) {
- // 10^-348, 10^-340, ..., 10^340
- static const uint64_t kCachedPowers_F[] = {
- RAPIDJSON_UINT64_C2(0xfa8fd5a0, 0x081c0288), RAPIDJSON_UINT64_C2(0xbaaee17f, 0xa23ebf76),
- RAPIDJSON_UINT64_C2(0x8b16fb20, 0x3055ac76), RAPIDJSON_UINT64_C2(0xcf42894a, 0x5dce35ea),
- RAPIDJSON_UINT64_C2(0x9a6bb0aa, 0x55653b2d), RAPIDJSON_UINT64_C2(0xe61acf03, 0x3d1a45df),
- RAPIDJSON_UINT64_C2(0xab70fe17, 0xc79ac6ca), RAPIDJSON_UINT64_C2(0xff77b1fc, 0xbebcdc4f),
- RAPIDJSON_UINT64_C2(0xbe5691ef, 0x416bd60c), RAPIDJSON_UINT64_C2(0x8dd01fad, 0x907ffc3c),
- RAPIDJSON_UINT64_C2(0xd3515c28, 0x31559a83), RAPIDJSON_UINT64_C2(0x9d71ac8f, 0xada6c9b5),
- RAPIDJSON_UINT64_C2(0xea9c2277, 0x23ee8bcb), RAPIDJSON_UINT64_C2(0xaecc4991, 0x4078536d),
- RAPIDJSON_UINT64_C2(0x823c1279, 0x5db6ce57), RAPIDJSON_UINT64_C2(0xc2109436, 0x4dfb5637),
- RAPIDJSON_UINT64_C2(0x9096ea6f, 0x3848984f), RAPIDJSON_UINT64_C2(0xd77485cb, 0x25823ac7),
- RAPIDJSON_UINT64_C2(0xa086cfcd, 0x97bf97f4), RAPIDJSON_UINT64_C2(0xef340a98, 0x172aace5),
- RAPIDJSON_UINT64_C2(0xb23867fb, 0x2a35b28e), RAPIDJSON_UINT64_C2(0x84c8d4df, 0xd2c63f3b),
- RAPIDJSON_UINT64_C2(0xc5dd4427, 0x1ad3cdba), RAPIDJSON_UINT64_C2(0x936b9fce, 0xbb25c996),
- RAPIDJSON_UINT64_C2(0xdbac6c24, 0x7d62a584), RAPIDJSON_UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
- RAPIDJSON_UINT64_C2(0xf3e2f893, 0xdec3f126), RAPIDJSON_UINT64_C2(0xb5b5ada8, 0xaaff80b8),
- RAPIDJSON_UINT64_C2(0x87625f05, 0x6c7c4a8b), RAPIDJSON_UINT64_C2(0xc9bcff60, 0x34c13053),
- RAPIDJSON_UINT64_C2(0x964e858c, 0x91ba2655), RAPIDJSON_UINT64_C2(0xdff97724, 0x70297ebd),
- RAPIDJSON_UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), RAPIDJSON_UINT64_C2(0xf8a95fcf, 0x88747d94),
- RAPIDJSON_UINT64_C2(0xb9447093, 0x8fa89bcf), RAPIDJSON_UINT64_C2(0x8a08f0f8, 0xbf0f156b),
- RAPIDJSON_UINT64_C2(0xcdb02555, 0x653131b6), RAPIDJSON_UINT64_C2(0x993fe2c6, 0xd07b7fac),
- RAPIDJSON_UINT64_C2(0xe45c10c4, 0x2a2b3b06), RAPIDJSON_UINT64_C2(0xaa242499, 0x697392d3),
- RAPIDJSON_UINT64_C2(0xfd87b5f2, 0x8300ca0e), RAPIDJSON_UINT64_C2(0xbce50864, 0x92111aeb),
- RAPIDJSON_UINT64_C2(0x8cbccc09, 0x6f5088cc), RAPIDJSON_UINT64_C2(0xd1b71758, 0xe219652c),
- RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), RAPIDJSON_UINT64_C2(0xe8d4a510, 0x00000000),
- RAPIDJSON_UINT64_C2(0xad78ebc5, 0xac620000), RAPIDJSON_UINT64_C2(0x813f3978, 0xf8940984),
- RAPIDJSON_UINT64_C2(0xc097ce7b, 0xc90715b3), RAPIDJSON_UINT64_C2(0x8f7e32ce, 0x7bea5c70),
- RAPIDJSON_UINT64_C2(0xd5d238a4, 0xabe98068), RAPIDJSON_UINT64_C2(0x9f4f2726, 0x179a2245),
- RAPIDJSON_UINT64_C2(0xed63a231, 0xd4c4fb27), RAPIDJSON_UINT64_C2(0xb0de6538, 0x8cc8ada8),
- RAPIDJSON_UINT64_C2(0x83c7088e, 0x1aab65db), RAPIDJSON_UINT64_C2(0xc45d1df9, 0x42711d9a),
- RAPIDJSON_UINT64_C2(0x924d692c, 0xa61be758), RAPIDJSON_UINT64_C2(0xda01ee64, 0x1a708dea),
- RAPIDJSON_UINT64_C2(0xa26da399, 0x9aef774a), RAPIDJSON_UINT64_C2(0xf209787b, 0xb47d6b85),
- RAPIDJSON_UINT64_C2(0xb454e4a1, 0x79dd1877), RAPIDJSON_UINT64_C2(0x865b8692, 0x5b9bc5c2),
- RAPIDJSON_UINT64_C2(0xc83553c5, 0xc8965d3d), RAPIDJSON_UINT64_C2(0x952ab45c, 0xfa97a0b3),
- RAPIDJSON_UINT64_C2(0xde469fbd, 0x99a05fe3), RAPIDJSON_UINT64_C2(0xa59bc234, 0xdb398c25),
- RAPIDJSON_UINT64_C2(0xf6c69a72, 0xa3989f5c), RAPIDJSON_UINT64_C2(0xb7dcbf53, 0x54e9bece),
- RAPIDJSON_UINT64_C2(0x88fcf317, 0xf22241e2), RAPIDJSON_UINT64_C2(0xcc20ce9b, 0xd35c78a5),
- RAPIDJSON_UINT64_C2(0x98165af3, 0x7b2153df), RAPIDJSON_UINT64_C2(0xe2a0b5dc, 0x971f303a),
- RAPIDJSON_UINT64_C2(0xa8d9d153, 0x5ce3b396), RAPIDJSON_UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
- RAPIDJSON_UINT64_C2(0xbb764c4c, 0xa7a44410), RAPIDJSON_UINT64_C2(0x8bab8eef, 0xb6409c1a),
- RAPIDJSON_UINT64_C2(0xd01fef10, 0xa657842c), RAPIDJSON_UINT64_C2(0x9b10a4e5, 0xe9913129),
- RAPIDJSON_UINT64_C2(0xe7109bfb, 0xa19c0c9d), RAPIDJSON_UINT64_C2(0xac2820d9, 0x623bf429),
- RAPIDJSON_UINT64_C2(0x80444b5e, 0x7aa7cf85), RAPIDJSON_UINT64_C2(0xbf21e440, 0x03acdd2d),
- RAPIDJSON_UINT64_C2(0x8e679c2f, 0x5e44ff8f), RAPIDJSON_UINT64_C2(0xd433179d, 0x9c8cb841),
- RAPIDJSON_UINT64_C2(0x9e19db92, 0xb4e31ba9), RAPIDJSON_UINT64_C2(0xeb96bf6e, 0xbadf77d9),
- RAPIDJSON_UINT64_C2(0xaf87023b, 0x9bf0ee6b)
- };
- static const int16_t kCachedPowers_E[] = {
- -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
- -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
- -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
- -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
- -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
- 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
- 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
- 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
- 907, 933, 960, 986, 1013, 1039, 1066
- };
- return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
-}
-
-inline DiyFp GetCachedPower(int e, int* K) {
-
- //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
- double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
- int k = static_cast<int>(dk);
- if (dk - k > 0.0)
- k++;
-
- unsigned index = static_cast<unsigned>((k >> 3) + 1);
- *K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
-
- return GetCachedPowerByIndex(index);
-}
-
-inline DiyFp GetCachedPower10(int exp, int *outExp) {
- unsigned index = (static_cast<unsigned>(exp) + 348u) / 8u;
- *outExp = -348 + static_cast<int>(index) * 8;
- return GetCachedPowerByIndex(index);
- }
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_DIYFP_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/dtoa.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/dtoa.h
deleted file mode 100644
index bf2e9b2e5..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/dtoa.h
+++ /dev/null
@@ -1,245 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-// This is a C++ header-only implementation of Grisu2 algorithm from the publication:
-// Loitsch, Florian. "Printing floating-point numbers quickly and accurately with
-// integers." ACM Sigplan Notices 45.6 (2010): 233-243.
-
-#ifndef RAPIDJSON_DTOA_
-#define RAPIDJSON_DTOA_
-
-#include "itoa.h" // GetDigitsLut()
-#include "diyfp.h"
-#include "ieee754.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
-#endif
-
-inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
- while (rest < wp_w && delta - rest >= ten_kappa &&
- (rest + ten_kappa < wp_w || /// closer
- wp_w - rest > rest + ten_kappa - wp_w)) {
- buffer[len - 1]--;
- rest += ten_kappa;
- }
-}
-
-inline int CountDecimalDigit32(uint32_t n) {
- // Simple pure C++ implementation was faster than __builtin_clz version in this situation.
- if (n < 10) return 1;
- if (n < 100) return 2;
- if (n < 1000) return 3;
- if (n < 10000) return 4;
- if (n < 100000) return 5;
- if (n < 1000000) return 6;
- if (n < 10000000) return 7;
- if (n < 100000000) return 8;
- // Will not reach 10 digits in DigitGen()
- //if (n < 1000000000) return 9;
- //return 10;
- return 9;
-}
-
-inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
- static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
- const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
- const DiyFp wp_w = Mp - W;
- uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
- uint64_t p2 = Mp.f & (one.f - 1);
- int kappa = CountDecimalDigit32(p1); // kappa in [0, 9]
- *len = 0;
-
- while (kappa > 0) {
- uint32_t d = 0;
- switch (kappa) {
- case 9: d = p1 / 100000000; p1 %= 100000000; break;
- case 8: d = p1 / 10000000; p1 %= 10000000; break;
- case 7: d = p1 / 1000000; p1 %= 1000000; break;
- case 6: d = p1 / 100000; p1 %= 100000; break;
- case 5: d = p1 / 10000; p1 %= 10000; break;
- case 4: d = p1 / 1000; p1 %= 1000; break;
- case 3: d = p1 / 100; p1 %= 100; break;
- case 2: d = p1 / 10; p1 %= 10; break;
- case 1: d = p1; p1 = 0; break;
- default:;
- }
- if (d || *len)
- buffer[(*len)++] = static_cast<char>('0' + static_cast<char>(d));
- kappa--;
- uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
- if (tmp <= delta) {
- *K += kappa;
- GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
- return;
- }
- }
-
- // kappa = 0
- for (;;) {
- p2 *= 10;
- delta *= 10;
- char d = static_cast<char>(p2 >> -one.e);
- if (d || *len)
- buffer[(*len)++] = static_cast<char>('0' + d);
- p2 &= one.f - 1;
- kappa--;
- if (p2 < delta) {
- *K += kappa;
- int index = -kappa;
- GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0));
- return;
- }
- }
-}
-
-inline void Grisu2(double value, char* buffer, int* length, int* K) {
- const DiyFp v(value);
- DiyFp w_m, w_p;
- v.NormalizedBoundaries(&w_m, &w_p);
-
- const DiyFp c_mk = GetCachedPower(w_p.e, K);
- const DiyFp W = v.Normalize() * c_mk;
- DiyFp Wp = w_p * c_mk;
- DiyFp Wm = w_m * c_mk;
- Wm.f++;
- Wp.f--;
- DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
-}
-
-inline char* WriteExponent(int K, char* buffer) {
- if (K < 0) {
- *buffer++ = '-';
- K = -K;
- }
-
- if (K >= 100) {
- *buffer++ = static_cast<char>('0' + static_cast<char>(K / 100));
- K %= 100;
- const char* d = GetDigitsLut() + K * 2;
- *buffer++ = d[0];
- *buffer++ = d[1];
- }
- else if (K >= 10) {
- const char* d = GetDigitsLut() + K * 2;
- *buffer++ = d[0];
- *buffer++ = d[1];
- }
- else
- *buffer++ = static_cast<char>('0' + static_cast<char>(K));
-
- return buffer;
-}
-
-inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
- const int kk = length + k; // 10^(kk-1) <= v < 10^kk
-
- if (0 <= k && kk <= 21) {
- // 1234e7 -> 12340000000
- for (int i = length; i < kk; i++)
- buffer[i] = '0';
- buffer[kk] = '.';
- buffer[kk + 1] = '0';
- return &buffer[kk + 2];
- }
- else if (0 < kk && kk <= 21) {
- // 1234e-2 -> 12.34
- std::memmove(&buffer[kk + 1], &buffer[kk], static_cast<size_t>(length - kk));
- buffer[kk] = '.';
- if (0 > k + maxDecimalPlaces) {
- // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1
- // Remove extra trailing zeros (at least one) after truncation.
- for (int i = kk + maxDecimalPlaces; i > kk + 1; i--)
- if (buffer[i] != '0')
- return &buffer[i + 1];
- return &buffer[kk + 2]; // Reserve one zero
- }
- else
- return &buffer[length + 1];
- }
- else if (-6 < kk && kk <= 0) {
- // 1234e-6 -> 0.001234
- const int offset = 2 - kk;
- std::memmove(&buffer[offset], &buffer[0], static_cast<size_t>(length));
- buffer[0] = '0';
- buffer[1] = '.';
- for (int i = 2; i < offset; i++)
- buffer[i] = '0';
- if (length - kk > maxDecimalPlaces) {
- // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1
- // Remove extra trailing zeros (at least one) after truncation.
- for (int i = maxDecimalPlaces + 1; i > 2; i--)
- if (buffer[i] != '0')
- return &buffer[i + 1];
- return &buffer[3]; // Reserve one zero
- }
- else
- return &buffer[length + offset];
- }
- else if (kk < -maxDecimalPlaces) {
- // Truncate to zero
- buffer[0] = '0';
- buffer[1] = '.';
- buffer[2] = '0';
- return &buffer[3];
- }
- else if (length == 1) {
- // 1e30
- buffer[1] = 'e';
- return WriteExponent(kk - 1, &buffer[2]);
- }
- else {
- // 1234e30 -> 1.234e33
- std::memmove(&buffer[2], &buffer[1], static_cast<size_t>(length - 1));
- buffer[1] = '.';
- buffer[length + 1] = 'e';
- return WriteExponent(kk - 1, &buffer[0 + length + 2]);
- }
-}
-
-inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) {
- RAPIDJSON_ASSERT(maxDecimalPlaces >= 1);
- Double d(value);
- if (d.IsZero()) {
- if (d.Sign())
- *buffer++ = '-'; // -0.0, Issue #289
- buffer[0] = '0';
- buffer[1] = '.';
- buffer[2] = '0';
- return &buffer[3];
- }
- else {
- if (value < 0) {
- *buffer++ = '-';
- value = -value;
- }
- int length, K;
- Grisu2(value, buffer, &length, &K);
- return Prettify(buffer, length, K, maxDecimalPlaces);
- }
-}
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_POP
-#endif
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_DTOA_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/ieee754.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/ieee754.h
deleted file mode 100644
index c2684ba2a..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/ieee754.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_IEEE754_
-#define RAPIDJSON_IEEE754_
-
-#include "../rapidjson.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-class Double {
-public:
- Double() {}
- Double(double d) : d_(d) {}
- Double(uint64_t u) : u_(u) {}
-
- double Value() const { return d_; }
- uint64_t Uint64Value() const { return u_; }
-
- double NextPositiveDouble() const {
- RAPIDJSON_ASSERT(!Sign());
- return Double(u_ + 1).Value();
- }
-
- bool Sign() const { return (u_ & kSignMask) != 0; }
- uint64_t Significand() const { return u_ & kSignificandMask; }
- int Exponent() const { return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
-
- bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
- bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
- bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; }
- bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; }
- bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
-
- uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); }
- int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
- uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
-
- static int EffectiveSignificandSize(int order) {
- if (order >= -1021)
- return 53;
- else if (order <= -1074)
- return 0;
- else
- return order + 1074;
- }
-
-private:
- static const int kSignificandSize = 52;
- static const int kExponentBias = 0x3FF;
- static const int kDenormalExponent = 1 - kExponentBias;
- static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000);
- static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
- static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
- static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
-
- union {
- double d_;
- uint64_t u_;
- };
-};
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_IEEE754_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/itoa.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/itoa.h
deleted file mode 100644
index 01a4e7e72..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/itoa.h
+++ /dev/null
@@ -1,304 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ITOA_
-#define RAPIDJSON_ITOA_
-
-#include "../rapidjson.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-inline const char* GetDigitsLut() {
- static const char cDigitsLut[200] = {
- '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
- '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
- '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
- '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
- '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
- '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
- '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
- '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
- '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
- '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
- };
- return cDigitsLut;
-}
-
-inline char* u32toa(uint32_t value, char* buffer) {
- const char* cDigitsLut = GetDigitsLut();
-
- if (value < 10000) {
- const uint32_t d1 = (value / 100) << 1;
- const uint32_t d2 = (value % 100) << 1;
-
- if (value >= 1000)
- *buffer++ = cDigitsLut[d1];
- if (value >= 100)
- *buffer++ = cDigitsLut[d1 + 1];
- if (value >= 10)
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
- }
- else if (value < 100000000) {
- // value = bbbbcccc
- const uint32_t b = value / 10000;
- const uint32_t c = value % 10000;
-
- const uint32_t d1 = (b / 100) << 1;
- const uint32_t d2 = (b % 100) << 1;
-
- const uint32_t d3 = (c / 100) << 1;
- const uint32_t d4 = (c % 100) << 1;
-
- if (value >= 10000000)
- *buffer++ = cDigitsLut[d1];
- if (value >= 1000000)
- *buffer++ = cDigitsLut[d1 + 1];
- if (value >= 100000)
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
-
- *buffer++ = cDigitsLut[d3];
- *buffer++ = cDigitsLut[d3 + 1];
- *buffer++ = cDigitsLut[d4];
- *buffer++ = cDigitsLut[d4 + 1];
- }
- else {
- // value = aabbbbcccc in decimal
-
- const uint32_t a = value / 100000000; // 1 to 42
- value %= 100000000;
-
- if (a >= 10) {
- const unsigned i = a << 1;
- *buffer++ = cDigitsLut[i];
- *buffer++ = cDigitsLut[i + 1];
- }
- else
- *buffer++ = static_cast<char>('0' + static_cast<char>(a));
-
- const uint32_t b = value / 10000; // 0 to 9999
- const uint32_t c = value % 10000; // 0 to 9999
-
- const uint32_t d1 = (b / 100) << 1;
- const uint32_t d2 = (b % 100) << 1;
-
- const uint32_t d3 = (c / 100) << 1;
- const uint32_t d4 = (c % 100) << 1;
-
- *buffer++ = cDigitsLut[d1];
- *buffer++ = cDigitsLut[d1 + 1];
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
- *buffer++ = cDigitsLut[d3];
- *buffer++ = cDigitsLut[d3 + 1];
- *buffer++ = cDigitsLut[d4];
- *buffer++ = cDigitsLut[d4 + 1];
- }
- return buffer;
-}
-
-inline char* i32toa(int32_t value, char* buffer) {
- uint32_t u = static_cast<uint32_t>(value);
- if (value < 0) {
- *buffer++ = '-';
- u = ~u + 1;
- }
-
- return u32toa(u, buffer);
-}
-
-inline char* u64toa(uint64_t value, char* buffer) {
- const char* cDigitsLut = GetDigitsLut();
- const uint64_t kTen8 = 100000000;
- const uint64_t kTen9 = kTen8 * 10;
- const uint64_t kTen10 = kTen8 * 100;
- const uint64_t kTen11 = kTen8 * 1000;
- const uint64_t kTen12 = kTen8 * 10000;
- const uint64_t kTen13 = kTen8 * 100000;
- const uint64_t kTen14 = kTen8 * 1000000;
- const uint64_t kTen15 = kTen8 * 10000000;
- const uint64_t kTen16 = kTen8 * kTen8;
-
- if (value < kTen8) {
- uint32_t v = static_cast<uint32_t>(value);
- if (v < 10000) {
- const uint32_t d1 = (v / 100) << 1;
- const uint32_t d2 = (v % 100) << 1;
-
- if (v >= 1000)
- *buffer++ = cDigitsLut[d1];
- if (v >= 100)
- *buffer++ = cDigitsLut[d1 + 1];
- if (v >= 10)
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
- }
- else {
- // value = bbbbcccc
- const uint32_t b = v / 10000;
- const uint32_t c = v % 10000;
-
- const uint32_t d1 = (b / 100) << 1;
- const uint32_t d2 = (b % 100) << 1;
-
- const uint32_t d3 = (c / 100) << 1;
- const uint32_t d4 = (c % 100) << 1;
-
- if (value >= 10000000)
- *buffer++ = cDigitsLut[d1];
- if (value >= 1000000)
- *buffer++ = cDigitsLut[d1 + 1];
- if (value >= 100000)
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
-
- *buffer++ = cDigitsLut[d3];
- *buffer++ = cDigitsLut[d3 + 1];
- *buffer++ = cDigitsLut[d4];
- *buffer++ = cDigitsLut[d4 + 1];
- }
- }
- else if (value < kTen16) {
- const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
- const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
-
- const uint32_t b0 = v0 / 10000;
- const uint32_t c0 = v0 % 10000;
-
- const uint32_t d1 = (b0 / 100) << 1;
- const uint32_t d2 = (b0 % 100) << 1;
-
- const uint32_t d3 = (c0 / 100) << 1;
- const uint32_t d4 = (c0 % 100) << 1;
-
- const uint32_t b1 = v1 / 10000;
- const uint32_t c1 = v1 % 10000;
-
- const uint32_t d5 = (b1 / 100) << 1;
- const uint32_t d6 = (b1 % 100) << 1;
-
- const uint32_t d7 = (c1 / 100) << 1;
- const uint32_t d8 = (c1 % 100) << 1;
-
- if (value >= kTen15)
- *buffer++ = cDigitsLut[d1];
- if (value >= kTen14)
- *buffer++ = cDigitsLut[d1 + 1];
- if (value >= kTen13)
- *buffer++ = cDigitsLut[d2];
- if (value >= kTen12)
- *buffer++ = cDigitsLut[d2 + 1];
- if (value >= kTen11)
- *buffer++ = cDigitsLut[d3];
- if (value >= kTen10)
- *buffer++ = cDigitsLut[d3 + 1];
- if (value >= kTen9)
- *buffer++ = cDigitsLut[d4];
- if (value >= kTen8)
- *buffer++ = cDigitsLut[d4 + 1];
-
- *buffer++ = cDigitsLut[d5];
- *buffer++ = cDigitsLut[d5 + 1];
- *buffer++ = cDigitsLut[d6];
- *buffer++ = cDigitsLut[d6 + 1];
- *buffer++ = cDigitsLut[d7];
- *buffer++ = cDigitsLut[d7 + 1];
- *buffer++ = cDigitsLut[d8];
- *buffer++ = cDigitsLut[d8 + 1];
- }
- else {
- const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844
- value %= kTen16;
-
- if (a < 10)
- *buffer++ = static_cast<char>('0' + static_cast<char>(a));
- else if (a < 100) {
- const uint32_t i = a << 1;
- *buffer++ = cDigitsLut[i];
- *buffer++ = cDigitsLut[i + 1];
- }
- else if (a < 1000) {
- *buffer++ = static_cast<char>('0' + static_cast<char>(a / 100));
-
- const uint32_t i = (a % 100) << 1;
- *buffer++ = cDigitsLut[i];
- *buffer++ = cDigitsLut[i + 1];
- }
- else {
- const uint32_t i = (a / 100) << 1;
- const uint32_t j = (a % 100) << 1;
- *buffer++ = cDigitsLut[i];
- *buffer++ = cDigitsLut[i + 1];
- *buffer++ = cDigitsLut[j];
- *buffer++ = cDigitsLut[j + 1];
- }
-
- const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
- const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
-
- const uint32_t b0 = v0 / 10000;
- const uint32_t c0 = v0 % 10000;
-
- const uint32_t d1 = (b0 / 100) << 1;
- const uint32_t d2 = (b0 % 100) << 1;
-
- const uint32_t d3 = (c0 / 100) << 1;
- const uint32_t d4 = (c0 % 100) << 1;
-
- const uint32_t b1 = v1 / 10000;
- const uint32_t c1 = v1 % 10000;
-
- const uint32_t d5 = (b1 / 100) << 1;
- const uint32_t d6 = (b1 % 100) << 1;
-
- const uint32_t d7 = (c1 / 100) << 1;
- const uint32_t d8 = (c1 % 100) << 1;
-
- *buffer++ = cDigitsLut[d1];
- *buffer++ = cDigitsLut[d1 + 1];
- *buffer++ = cDigitsLut[d2];
- *buffer++ = cDigitsLut[d2 + 1];
- *buffer++ = cDigitsLut[d3];
- *buffer++ = cDigitsLut[d3 + 1];
- *buffer++ = cDigitsLut[d4];
- *buffer++ = cDigitsLut[d4 + 1];
- *buffer++ = cDigitsLut[d5];
- *buffer++ = cDigitsLut[d5 + 1];
- *buffer++ = cDigitsLut[d6];
- *buffer++ = cDigitsLut[d6 + 1];
- *buffer++ = cDigitsLut[d7];
- *buffer++ = cDigitsLut[d7 + 1];
- *buffer++ = cDigitsLut[d8];
- *buffer++ = cDigitsLut[d8 + 1];
- }
-
- return buffer;
-}
-
-inline char* i64toa(int64_t value, char* buffer) {
- uint64_t u = static_cast<uint64_t>(value);
- if (value < 0) {
- *buffer++ = '-';
- u = ~u + 1;
- }
-
- return u64toa(u, buffer);
-}
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_ITOA_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/meta.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/meta.h
deleted file mode 100644
index 5a9aaa428..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/meta.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_INTERNAL_META_H_
-#define RAPIDJSON_INTERNAL_META_H_
-
-#include "../rapidjson.h"
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-#if defined(_MSC_VER)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(6334)
-#endif
-
-#if RAPIDJSON_HAS_CXX11_TYPETRAITS
-#include <type_traits>
-#endif
-
-//@cond RAPIDJSON_INTERNAL
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
-template <typename T> struct Void { typedef void Type; };
-
-///////////////////////////////////////////////////////////////////////////////
-// BoolType, TrueType, FalseType
-//
-template <bool Cond> struct BoolType {
- static const bool Value = Cond;
- typedef BoolType Type;
-};
-typedef BoolType<true> TrueType;
-typedef BoolType<false> FalseType;
-
-
-///////////////////////////////////////////////////////////////////////////////
-// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
-//
-
-template <bool C> struct SelectIfImpl { template <typename T1, typename T2> struct Apply { typedef T1 Type; }; };
-template <> struct SelectIfImpl<false> { template <typename T1, typename T2> struct Apply { typedef T2 Type; }; };
-template <bool C, typename T1, typename T2> struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
-template <typename C, typename T1, typename T2> struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
-
-template <bool Cond1, bool Cond2> struct AndExprCond : FalseType {};
-template <> struct AndExprCond<true, true> : TrueType {};
-template <bool Cond1, bool Cond2> struct OrExprCond : TrueType {};
-template <> struct OrExprCond<false, false> : FalseType {};
-
-template <typename C> struct BoolExpr : SelectIf<C,TrueType,FalseType>::Type {};
-template <typename C> struct NotExpr : SelectIf<C,FalseType,TrueType>::Type {};
-template <typename C1, typename C2> struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
-template <typename C1, typename C2> struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
-
-
-///////////////////////////////////////////////////////////////////////////////
-// AddConst, MaybeAddConst, RemoveConst
-template <typename T> struct AddConst { typedef const T Type; };
-template <bool Constify, typename T> struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
-template <typename T> struct RemoveConst { typedef T Type; };
-template <typename T> struct RemoveConst<const T> { typedef T Type; };
-
-
-///////////////////////////////////////////////////////////////////////////////
-// IsSame, IsConst, IsMoreConst, IsPointer
-//
-template <typename T, typename U> struct IsSame : FalseType {};
-template <typename T> struct IsSame<T, T> : TrueType {};
-
-template <typename T> struct IsConst : FalseType {};
-template <typename T> struct IsConst<const T> : TrueType {};
-
-template <typename CT, typename T>
-struct IsMoreConst
- : AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
- BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >::Type {};
-
-template <typename T> struct IsPointer : FalseType {};
-template <typename T> struct IsPointer<T*> : TrueType {};
-
-///////////////////////////////////////////////////////////////////////////////
-// IsBaseOf
-//
-#if RAPIDJSON_HAS_CXX11_TYPETRAITS
-
-template <typename B, typename D> struct IsBaseOf
- : BoolType< ::std::is_base_of<B,D>::value> {};
-
-#else // simplified version adopted from Boost
-
-template<typename B, typename D> struct IsBaseOfImpl {
- RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0);
- RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0);
-
- typedef char (&Yes)[1];
- typedef char (&No) [2];
-
- template <typename T>
- static Yes Check(const D*, T);
- static No Check(const B*, int);
-
- struct Host {
- operator const B*() const;
- operator const D*();
- };
-
- enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) };
-};
-
-template <typename B, typename D> struct IsBaseOf
- : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >::Type {};
-
-#endif // RAPIDJSON_HAS_CXX11_TYPETRAITS
-
-
-//////////////////////////////////////////////////////////////////////////
-// EnableIf / DisableIf
-//
-template <bool Condition, typename T = void> struct EnableIfCond { typedef T Type; };
-template <typename T> struct EnableIfCond<false, T> { /* empty */ };
-
-template <bool Condition, typename T = void> struct DisableIfCond { typedef T Type; };
-template <typename T> struct DisableIfCond<true, T> { /* empty */ };
-
-template <typename Condition, typename T = void>
-struct EnableIf : EnableIfCond<Condition::Value, T> {};
-
-template <typename Condition, typename T = void>
-struct DisableIf : DisableIfCond<Condition::Value, T> {};
-
-// SFINAE helpers
-struct SfinaeTag {};
-template <typename T> struct RemoveSfinaeTag;
-template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type; };
-
-#define RAPIDJSON_REMOVEFPTR_(type) \
- typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
- < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
-
-#define RAPIDJSON_ENABLEIF(cond) \
- typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
- <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
-
-#define RAPIDJSON_DISABLEIF(cond) \
- typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
- <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
-
-#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
- typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
- <RAPIDJSON_REMOVEFPTR_(cond), \
- RAPIDJSON_REMOVEFPTR_(returntype)>::Type
-
-#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
- typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
- <RAPIDJSON_REMOVEFPTR_(cond), \
- RAPIDJSON_REMOVEFPTR_(returntype)>::Type
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-//@endcond
-
-#if defined(__GNUC__) || defined(_MSC_VER)
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_INTERNAL_META_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/pow10.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/pow10.h
deleted file mode 100644
index 02f475d70..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/pow10.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_POW10_
-#define RAPIDJSON_POW10_
-
-#include "../rapidjson.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-//! Computes integer powers of 10 in double (10.0^n).
-/*! This function uses lookup table for fast and accurate results.
- \param n non-negative exponent. Must <= 308.
- \return 10.0^n
-*/
-inline double Pow10(int n) {
- static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes
- 1e+0,
- 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
- 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40,
- 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
- 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
- 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
- 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
- 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
- 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
- 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
- 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
- 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
- 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
- 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
- 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
- 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
- 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
- };
- RAPIDJSON_ASSERT(n >= 0 && n <= 308);
- return e[n];
-}
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_POW10_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/regex.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/regex.h
deleted file mode 100644
index e1a2faae5..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/regex.h
+++ /dev/null
@@ -1,734 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_INTERNAL_REGEX_H_
-#define RAPIDJSON_INTERNAL_REGEX_H_
-
-#include "../allocators.h"
-#include "../stream.h"
-#include "stack.h"
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-RAPIDJSON_DIAG_OFF(switch-enum)
-RAPIDJSON_DIAG_OFF(implicit-fallthrough)
-#endif
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#if __GNUC__ >= 7
-RAPIDJSON_DIAG_OFF(implicit-fallthrough)
-#endif
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
-#endif
-
-#ifndef RAPIDJSON_REGEX_VERBOSE
-#define RAPIDJSON_REGEX_VERBOSE 0
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-///////////////////////////////////////////////////////////////////////////////
-// DecodedStream
-
-template <typename SourceStream, typename Encoding>
-class DecodedStream {
-public:
- DecodedStream(SourceStream& ss) : ss_(ss), codepoint_() { Decode(); }
- unsigned Peek() { return codepoint_; }
- unsigned Take() {
- unsigned c = codepoint_;
- if (c) // No further decoding when '\0'
- Decode();
- return c;
- }
-
-private:
- void Decode() {
- if (!Encoding::Decode(ss_, &codepoint_))
- codepoint_ = 0;
- }
-
- SourceStream& ss_;
- unsigned codepoint_;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericRegex
-
-static const SizeType kRegexInvalidState = ~SizeType(0); //!< Represents an invalid index in GenericRegex::State::out, out1
-static const SizeType kRegexInvalidRange = ~SizeType(0);
-
-template <typename Encoding, typename Allocator>
-class GenericRegexSearch;
-
-//! Regular expression engine with subset of ECMAscript grammar.
-/*!
- Supported regular expression syntax:
- - \c ab Concatenation
- - \c a|b Alternation
- - \c a? Zero or one
- - \c a* Zero or more
- - \c a+ One or more
- - \c a{3} Exactly 3 times
- - \c a{3,} At least 3 times
- - \c a{3,5} 3 to 5 times
- - \c (ab) Grouping
- - \c ^a At the beginning
- - \c a$ At the end
- - \c . Any character
- - \c [abc] Character classes
- - \c [a-c] Character class range
- - \c [a-z0-9_] Character class combination
- - \c [^abc] Negated character classes
- - \c [^a-c] Negated character class range
- - \c [\b] Backspace (U+0008)
- - \c \\| \\\\ ... Escape characters
- - \c \\f Form feed (U+000C)
- - \c \\n Line feed (U+000A)
- - \c \\r Carriage return (U+000D)
- - \c \\t Tab (U+0009)
- - \c \\v Vertical tab (U+000B)
-
- \note This is a Thompson NFA engine, implemented with reference to
- Cox, Russ. "Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby,...).",
- https://swtch.com/~rsc/regexp/regexp1.html
-*/
-template <typename Encoding, typename Allocator = CrtAllocator>
-class GenericRegex {
-public:
- typedef Encoding EncodingType;
- typedef typename Encoding::Ch Ch;
- template <typename, typename> friend class GenericRegexSearch;
-
- GenericRegex(const Ch* source, Allocator* allocator = 0) :
- states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(),
- anchorBegin_(), anchorEnd_()
- {
- GenericStringStream<Encoding> ss(source);
- DecodedStream<GenericStringStream<Encoding>, Encoding> ds(ss);
- Parse(ds);
- }
-
- ~GenericRegex() {}
-
- bool IsValid() const {
- return root_ != kRegexInvalidState;
- }
-
-private:
- enum Operator {
- kZeroOrOne,
- kZeroOrMore,
- kOneOrMore,
- kConcatenation,
- kAlternation,
- kLeftParenthesis
- };
-
- static const unsigned kAnyCharacterClass = 0xFFFFFFFF; //!< For '.'
- static const unsigned kRangeCharacterClass = 0xFFFFFFFE;
- static const unsigned kRangeNegationFlag = 0x80000000;
-
- struct Range {
- unsigned start; //
- unsigned end;
- SizeType next;
- };
-
- struct State {
- SizeType out; //!< Equals to kInvalid for matching state
- SizeType out1; //!< Equals to non-kInvalid for split
- SizeType rangeStart;
- unsigned codepoint;
- };
-
- struct Frag {
- Frag(SizeType s, SizeType o, SizeType m) : start(s), out(o), minIndex(m) {}
- SizeType start;
- SizeType out; //!< link-list of all output states
- SizeType minIndex;
- };
-
- State& GetState(SizeType index) {
- RAPIDJSON_ASSERT(index < stateCount_);
- return states_.template Bottom<State>()[index];
- }
-
- const State& GetState(SizeType index) const {
- RAPIDJSON_ASSERT(index < stateCount_);
- return states_.template Bottom<State>()[index];
- }
-
- Range& GetRange(SizeType index) {
- RAPIDJSON_ASSERT(index < rangeCount_);
- return ranges_.template Bottom<Range>()[index];
- }
-
- const Range& GetRange(SizeType index) const {
- RAPIDJSON_ASSERT(index < rangeCount_);
- return ranges_.template Bottom<Range>()[index];
- }
-
- template <typename InputStream>
- void Parse(DecodedStream<InputStream, Encoding>& ds) {
- Allocator allocator;
- Stack<Allocator> operandStack(&allocator, 256); // Frag
- Stack<Allocator> operatorStack(&allocator, 256); // Operator
- Stack<Allocator> atomCountStack(&allocator, 256); // unsigned (Atom per parenthesis)
-
- *atomCountStack.template Push<unsigned>() = 0;
-
- unsigned codepoint;
- while (ds.Peek() != 0) {
- switch (codepoint = ds.Take()) {
- case '^':
- anchorBegin_ = true;
- break;
-
- case '$':
- anchorEnd_ = true;
- break;
-
- case '|':
- while (!operatorStack.Empty() && *operatorStack.template Top<Operator>() < kAlternation)
- if (!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
- return;
- *operatorStack.template Push<Operator>() = kAlternation;
- *atomCountStack.template Top<unsigned>() = 0;
- break;
-
- case '(':
- *operatorStack.template Push<Operator>() = kLeftParenthesis;
- *atomCountStack.template Push<unsigned>() = 0;
- break;
-
- case ')':
- while (!operatorStack.Empty() && *operatorStack.template Top<Operator>() != kLeftParenthesis)
- if (!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
- return;
- if (operatorStack.Empty())
- return;
- operatorStack.template Pop<Operator>(1);
- atomCountStack.template Pop<unsigned>(1);
- ImplicitConcatenation(atomCountStack, operatorStack);
- break;
-
- case '?':
- if (!Eval(operandStack, kZeroOrOne))
- return;
- break;
-
- case '*':
- if (!Eval(operandStack, kZeroOrMore))
- return;
- break;
-
- case '+':
- if (!Eval(operandStack, kOneOrMore))
- return;
- break;
-
- case '{':
- {
- unsigned n, m;
- if (!ParseUnsigned(ds, &n))
- return;
-
- if (ds.Peek() == ',') {
- ds.Take();
- if (ds.Peek() == '}')
- m = kInfinityQuantifier;
- else if (!ParseUnsigned(ds, &m) || m < n)
- return;
- }
- else
- m = n;
-
- if (!EvalQuantifier(operandStack, n, m) || ds.Peek() != '}')
- return;
- ds.Take();
- }
- break;
-
- case '.':
- PushOperand(operandStack, kAnyCharacterClass);
- ImplicitConcatenation(atomCountStack, operatorStack);
- break;
-
- case '[':
- {
- SizeType range;
- if (!ParseRange(ds, &range))
- return;
- SizeType s = NewState(kRegexInvalidState, kRegexInvalidState, kRangeCharacterClass);
- GetState(s).rangeStart = range;
- *operandStack.template Push<Frag>() = Frag(s, s, s);
- }
- ImplicitConcatenation(atomCountStack, operatorStack);
- break;
-
- case '\\': // Escape character
- if (!CharacterEscape(ds, &codepoint))
- return; // Unsupported escape character
- // fall through to default
-
- default: // Pattern character
- PushOperand(operandStack, codepoint);
- ImplicitConcatenation(atomCountStack, operatorStack);
- }
- }
-
- while (!operatorStack.Empty())
- if (!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
- return;
-
- // Link the operand to matching state.
- if (operandStack.GetSize() == sizeof(Frag)) {
- Frag* e = operandStack.template Pop<Frag>(1);
- Patch(e->out, NewState(kRegexInvalidState, kRegexInvalidState, 0));
- root_ = e->start;
-
-#if RAPIDJSON_REGEX_VERBOSE
- printf("root: %d\n", root_);
- for (SizeType i = 0; i < stateCount_ ; i++) {
- State& s = GetState(i);
- printf("[%2d] out: %2d out1: %2d c: '%c'\n", i, s.out, s.out1, (char)s.codepoint);
- }
- printf("\n");
-#endif
- }
- }
-
- SizeType NewState(SizeType out, SizeType out1, unsigned codepoint) {
- State* s = states_.template Push<State>();
- s->out = out;
- s->out1 = out1;
- s->codepoint = codepoint;
- s->rangeStart = kRegexInvalidRange;
- return stateCount_++;
- }
-
- void PushOperand(Stack<Allocator>& operandStack, unsigned codepoint) {
- SizeType s = NewState(kRegexInvalidState, kRegexInvalidState, codepoint);
- *operandStack.template Push<Frag>() = Frag(s, s, s);
- }
-
- void ImplicitConcatenation(Stack<Allocator>& atomCountStack, Stack<Allocator>& operatorStack) {
- if (*atomCountStack.template Top<unsigned>())
- *operatorStack.template Push<Operator>() = kConcatenation;
- (*atomCountStack.template Top<unsigned>())++;
- }
-
- SizeType Append(SizeType l1, SizeType l2) {
- SizeType old = l1;
- while (GetState(l1).out != kRegexInvalidState)
- l1 = GetState(l1).out;
- GetState(l1).out = l2;
- return old;
- }
-
- void Patch(SizeType l, SizeType s) {
- for (SizeType next; l != kRegexInvalidState; l = next) {
- next = GetState(l).out;
- GetState(l).out = s;
- }
- }
-
- bool Eval(Stack<Allocator>& operandStack, Operator op) {
- switch (op) {
- case kConcatenation:
- RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag) * 2);
- {
- Frag e2 = *operandStack.template Pop<Frag>(1);
- Frag e1 = *operandStack.template Pop<Frag>(1);
- Patch(e1.out, e2.start);
- *operandStack.template Push<Frag>() = Frag(e1.start, e2.out, Min(e1.minIndex, e2.minIndex));
- }
- return true;
-
- case kAlternation:
- if (operandStack.GetSize() >= sizeof(Frag) * 2) {
- Frag e2 = *operandStack.template Pop<Frag>(1);
- Frag e1 = *operandStack.template Pop<Frag>(1);
- SizeType s = NewState(e1.start, e2.start, 0);
- *operandStack.template Push<Frag>() = Frag(s, Append(e1.out, e2.out), Min(e1.minIndex, e2.minIndex));
- return true;
- }
- return false;
-
- case kZeroOrOne:
- if (operandStack.GetSize() >= sizeof(Frag)) {
- Frag e = *operandStack.template Pop<Frag>(1);
- SizeType s = NewState(kRegexInvalidState, e.start, 0);
- *operandStack.template Push<Frag>() = Frag(s, Append(e.out, s), e.minIndex);
- return true;
- }
- return false;
-
- case kZeroOrMore:
- if (operandStack.GetSize() >= sizeof(Frag)) {
- Frag e = *operandStack.template Pop<Frag>(1);
- SizeType s = NewState(kRegexInvalidState, e.start, 0);
- Patch(e.out, s);
- *operandStack.template Push<Frag>() = Frag(s, s, e.minIndex);
- return true;
- }
- return false;
-
- default:
- RAPIDJSON_ASSERT(op == kOneOrMore);
- if (operandStack.GetSize() >= sizeof(Frag)) {
- Frag e = *operandStack.template Pop<Frag>(1);
- SizeType s = NewState(kRegexInvalidState, e.start, 0);
- Patch(e.out, s);
- *operandStack.template Push<Frag>() = Frag(e.start, s, e.minIndex);
- return true;
- }
- return false;
- }
- }
-
- bool EvalQuantifier(Stack<Allocator>& operandStack, unsigned n, unsigned m) {
- RAPIDJSON_ASSERT(n <= m);
- RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag));
-
- if (n == 0) {
- if (m == 0) // a{0} not support
- return false;
- else if (m == kInfinityQuantifier)
- Eval(operandStack, kZeroOrMore); // a{0,} -> a*
- else {
- Eval(operandStack, kZeroOrOne); // a{0,5} -> a?
- for (unsigned i = 0; i < m - 1; i++)
- CloneTopOperand(operandStack); // a{0,5} -> a? a? a? a? a?
- for (unsigned i = 0; i < m - 1; i++)
- Eval(operandStack, kConcatenation); // a{0,5} -> a?a?a?a?a?
- }
- return true;
- }
-
- for (unsigned i = 0; i < n - 1; i++) // a{3} -> a a a
- CloneTopOperand(operandStack);
-
- if (m == kInfinityQuantifier)
- Eval(operandStack, kOneOrMore); // a{3,} -> a a a+
- else if (m > n) {
- CloneTopOperand(operandStack); // a{3,5} -> a a a a
- Eval(operandStack, kZeroOrOne); // a{3,5} -> a a a a?
- for (unsigned i = n; i < m - 1; i++)
- CloneTopOperand(operandStack); // a{3,5} -> a a a a? a?
- for (unsigned i = n; i < m; i++)
- Eval(operandStack, kConcatenation); // a{3,5} -> a a aa?a?
- }
-
- for (unsigned i = 0; i < n - 1; i++)
- Eval(operandStack, kConcatenation); // a{3} -> aaa, a{3,} -> aaa+, a{3.5} -> aaaa?a?
-
- return true;
- }
-
- static SizeType Min(SizeType a, SizeType b) { return a < b ? a : b; }
-
- void CloneTopOperand(Stack<Allocator>& operandStack) {
- const Frag src = *operandStack.template Top<Frag>(); // Copy constructor to prevent invalidation
- SizeType count = stateCount_ - src.minIndex; // Assumes top operand contains states in [src->minIndex, stateCount_)
- State* s = states_.template Push<State>(count);
- memcpy(s, &GetState(src.minIndex), count * sizeof(State));
- for (SizeType j = 0; j < count; j++) {
- if (s[j].out != kRegexInvalidState)
- s[j].out += count;
- if (s[j].out1 != kRegexInvalidState)
- s[j].out1 += count;
- }
- *operandStack.template Push<Frag>() = Frag(src.start + count, src.out + count, src.minIndex + count);
- stateCount_ += count;
- }
-
- template <typename InputStream>
- bool ParseUnsigned(DecodedStream<InputStream, Encoding>& ds, unsigned* u) {
- unsigned r = 0;
- if (ds.Peek() < '0' || ds.Peek() > '9')
- return false;
- while (ds.Peek() >= '0' && ds.Peek() <= '9') {
- if (r >= 429496729 && ds.Peek() > '5') // 2^32 - 1 = 4294967295
- return false; // overflow
- r = r * 10 + (ds.Take() - '0');
- }
- *u = r;
- return true;
- }
-
- template <typename InputStream>
- bool ParseRange(DecodedStream<InputStream, Encoding>& ds, SizeType* range) {
- bool isBegin = true;
- bool negate = false;
- int step = 0;
- SizeType start = kRegexInvalidRange;
- SizeType current = kRegexInvalidRange;
- unsigned codepoint;
- while ((codepoint = ds.Take()) != 0) {
- if (isBegin) {
- isBegin = false;
- if (codepoint == '^') {
- negate = true;
- continue;
- }
- }
-
- switch (codepoint) {
- case ']':
- if (start == kRegexInvalidRange)
- return false; // Error: nothing inside []
- if (step == 2) { // Add trailing '-'
- SizeType r = NewRange('-');
- RAPIDJSON_ASSERT(current != kRegexInvalidRange);
- GetRange(current).next = r;
- }
- if (negate)
- GetRange(start).start |= kRangeNegationFlag;
- *range = start;
- return true;
-
- case '\\':
- if (ds.Peek() == 'b') {
- ds.Take();
- codepoint = 0x0008; // Escape backspace character
- }
- else if (!CharacterEscape(ds, &codepoint))
- return false;
- // fall through to default
-
- default:
- switch (step) {
- case 1:
- if (codepoint == '-') {
- step++;
- break;
- }
- // fall through to step 0 for other characters
-
- case 0:
- {
- SizeType r = NewRange(codepoint);
- if (current != kRegexInvalidRange)
- GetRange(current).next = r;
- if (start == kRegexInvalidRange)
- start = r;
- current = r;
- }
- step = 1;
- break;
-
- default:
- RAPIDJSON_ASSERT(step == 2);
- GetRange(current).end = codepoint;
- step = 0;
- }
- }
- }
- return false;
- }
-
- SizeType NewRange(unsigned codepoint) {
- Range* r = ranges_.template Push<Range>();
- r->start = r->end = codepoint;
- r->next = kRegexInvalidRange;
- return rangeCount_++;
- }
-
- template <typename InputStream>
- bool CharacterEscape(DecodedStream<InputStream, Encoding>& ds, unsigned* escapedCodepoint) {
- unsigned codepoint;
- switch (codepoint = ds.Take()) {
- case '^':
- case '$':
- case '|':
- case '(':
- case ')':
- case '?':
- case '*':
- case '+':
- case '.':
- case '[':
- case ']':
- case '{':
- case '}':
- case '\\':
- *escapedCodepoint = codepoint; return true;
- case 'f': *escapedCodepoint = 0x000C; return true;
- case 'n': *escapedCodepoint = 0x000A; return true;
- case 'r': *escapedCodepoint = 0x000D; return true;
- case 't': *escapedCodepoint = 0x0009; return true;
- case 'v': *escapedCodepoint = 0x000B; return true;
- default:
- return false; // Unsupported escape character
- }
- }
-
- Stack<Allocator> states_;
- Stack<Allocator> ranges_;
- SizeType root_;
- SizeType stateCount_;
- SizeType rangeCount_;
-
- static const unsigned kInfinityQuantifier = ~0u;
-
- // For SearchWithAnchoring()
- bool anchorBegin_;
- bool anchorEnd_;
-};
-
-template <typename RegexType, typename Allocator = CrtAllocator>
-class GenericRegexSearch {
-public:
- typedef typename RegexType::EncodingType Encoding;
- typedef typename Encoding::Ch Ch;
-
- GenericRegexSearch(const RegexType& regex, Allocator* allocator = 0) :
- regex_(regex), allocator_(allocator), ownAllocator_(0),
- state0_(allocator, 0), state1_(allocator, 0), stateSet_()
- {
- RAPIDJSON_ASSERT(regex_.IsValid());
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
- stateSet_ = static_cast<unsigned*>(allocator_->Malloc(GetStateSetSize()));
- state0_.template Reserve<SizeType>(regex_.stateCount_);
- state1_.template Reserve<SizeType>(regex_.stateCount_);
- }
-
- ~GenericRegexSearch() {
- Allocator::Free(stateSet_);
- RAPIDJSON_DELETE(ownAllocator_);
- }
-
- template <typename InputStream>
- bool Match(InputStream& is) {
- return SearchWithAnchoring(is, true, true);
- }
-
- bool Match(const Ch* s) {
- GenericStringStream<Encoding> is(s);
- return Match(is);
- }
-
- template <typename InputStream>
- bool Search(InputStream& is) {
- return SearchWithAnchoring(is, regex_.anchorBegin_, regex_.anchorEnd_);
- }
-
- bool Search(const Ch* s) {
- GenericStringStream<Encoding> is(s);
- return Search(is);
- }
-
-private:
- typedef typename RegexType::State State;
- typedef typename RegexType::Range Range;
-
- template <typename InputStream>
- bool SearchWithAnchoring(InputStream& is, bool anchorBegin, bool anchorEnd) {
- DecodedStream<InputStream, Encoding> ds(is);
-
- state0_.Clear();
- Stack<Allocator> *current = &state0_, *next = &state1_;
- const size_t stateSetSize = GetStateSetSize();
- std::memset(stateSet_, 0, stateSetSize);
-
- bool matched = AddState(*current, regex_.root_);
- unsigned codepoint;
- while (!current->Empty() && (codepoint = ds.Take()) != 0) {
- std::memset(stateSet_, 0, stateSetSize);
- next->Clear();
- matched = false;
- for (const SizeType* s = current->template Bottom<SizeType>(); s != current->template End<SizeType>(); ++s) {
- const State& sr = regex_.GetState(*s);
- if (sr.codepoint == codepoint ||
- sr.codepoint == RegexType::kAnyCharacterClass ||
- (sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint)))
- {
- matched = AddState(*next, sr.out) || matched;
- if (!anchorEnd && matched)
- return true;
- }
- if (!anchorBegin)
- AddState(*next, regex_.root_);
- }
- internal::Swap(current, next);
- }
-
- return matched;
- }
-
- size_t GetStateSetSize() const {
- return (regex_.stateCount_ + 31) / 32 * 4;
- }
-
- // Return whether the added states is a match state
- bool AddState(Stack<Allocator>& l, SizeType index) {
- RAPIDJSON_ASSERT(index != kRegexInvalidState);
-
- const State& s = regex_.GetState(index);
- if (s.out1 != kRegexInvalidState) { // Split
- bool matched = AddState(l, s.out);
- return AddState(l, s.out1) || matched;
- }
- else if (!(stateSet_[index >> 5] & (1u << (index & 31)))) {
- stateSet_[index >> 5] |= (1u << (index & 31));
- *l.template PushUnsafe<SizeType>() = index;
- }
- return s.out == kRegexInvalidState; // by using PushUnsafe() above, we can ensure s is not validated due to reallocation.
- }
-
- bool MatchRange(SizeType rangeIndex, unsigned codepoint) const {
- bool yes = (regex_.GetRange(rangeIndex).start & RegexType::kRangeNegationFlag) == 0;
- while (rangeIndex != kRegexInvalidRange) {
- const Range& r = regex_.GetRange(rangeIndex);
- if (codepoint >= (r.start & ~RegexType::kRangeNegationFlag) && codepoint <= r.end)
- return yes;
- rangeIndex = r.next;
- }
- return !yes;
- }
-
- const RegexType& regex_;
- Allocator* allocator_;
- Allocator* ownAllocator_;
- Stack<Allocator> state0_;
- Stack<Allocator> state1_;
- uint32_t* stateSet_;
-};
-
-typedef GenericRegex<UTF8<> > Regex;
-typedef GenericRegexSearch<Regex> RegexSearch;
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_INTERNAL_REGEX_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
deleted file mode 100644
index 5c5398c35..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
+++ /dev/null
@@ -1,231 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_INTERNAL_STACK_H_
-#define RAPIDJSON_INTERNAL_STACK_H_
-
-#include "../allocators.h"
-#include "swap.h"
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-///////////////////////////////////////////////////////////////////////////////
-// Stack
-
-//! A type-unsafe stack for storing different types of data.
-/*! \tparam Allocator Allocator for allocating stack memory.
-*/
-template <typename Allocator>
-class Stack {
-public:
- // Optimization note: Do not allocate memory for stack_ in constructor.
- // Do it lazily when first Push() -> Expand() -> Resize().
- Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- Stack(Stack&& rhs)
- : allocator_(rhs.allocator_),
- ownAllocator_(rhs.ownAllocator_),
- stack_(rhs.stack_),
- stackTop_(rhs.stackTop_),
- stackEnd_(rhs.stackEnd_),
- initialCapacity_(rhs.initialCapacity_)
- {
- rhs.allocator_ = 0;
- rhs.ownAllocator_ = 0;
- rhs.stack_ = 0;
- rhs.stackTop_ = 0;
- rhs.stackEnd_ = 0;
- rhs.initialCapacity_ = 0;
- }
-#endif
-
- ~Stack() {
- Destroy();
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- Stack& operator=(Stack&& rhs) {
- if (&rhs != this)
- {
- Destroy();
-
- allocator_ = rhs.allocator_;
- ownAllocator_ = rhs.ownAllocator_;
- stack_ = rhs.stack_;
- stackTop_ = rhs.stackTop_;
- stackEnd_ = rhs.stackEnd_;
- initialCapacity_ = rhs.initialCapacity_;
-
- rhs.allocator_ = 0;
- rhs.ownAllocator_ = 0;
- rhs.stack_ = 0;
- rhs.stackTop_ = 0;
- rhs.stackEnd_ = 0;
- rhs.initialCapacity_ = 0;
- }
- return *this;
- }
-#endif
-
- void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT {
- internal::Swap(allocator_, rhs.allocator_);
- internal::Swap(ownAllocator_, rhs.ownAllocator_);
- internal::Swap(stack_, rhs.stack_);
- internal::Swap(stackTop_, rhs.stackTop_);
- internal::Swap(stackEnd_, rhs.stackEnd_);
- internal::Swap(initialCapacity_, rhs.initialCapacity_);
- }
-
- void Clear() { stackTop_ = stack_; }
-
- void ShrinkToFit() {
- if (Empty()) {
- // If the stack is empty, completely deallocate the memory.
- Allocator::Free(stack_);
- stack_ = 0;
- stackTop_ = 0;
- stackEnd_ = 0;
- }
- else
- Resize(GetSize());
- }
-
- // Optimization note: try to minimize the size of this function for force inline.
- // Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
- template<typename T>
- RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) {
- // Expand the stack if needed
- if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_))
- Expand<T>(count);
- }
-
- template<typename T>
- RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
- Reserve<T>(count);
- return PushUnsafe<T>(count);
- }
-
- template<typename T>
- RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) {
- RAPIDJSON_ASSERT(stackTop_);
- RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_);
- T* ret = reinterpret_cast<T*>(stackTop_);
- stackTop_ += sizeof(T) * count;
- return ret;
- }
-
- template<typename T>
- T* Pop(size_t count) {
- RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
- stackTop_ -= count * sizeof(T);
- return reinterpret_cast<T*>(stackTop_);
- }
-
- template<typename T>
- T* Top() {
- RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
- return reinterpret_cast<T*>(stackTop_ - sizeof(T));
- }
-
- template<typename T>
- const T* Top() const {
- RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
- return reinterpret_cast<T*>(stackTop_ - sizeof(T));
- }
-
- template<typename T>
- T* End() { return reinterpret_cast<T*>(stackTop_); }
-
- template<typename T>
- const T* End() const { return reinterpret_cast<T*>(stackTop_); }
-
- template<typename T>
- T* Bottom() { return reinterpret_cast<T*>(stack_); }
-
- template<typename T>
- const T* Bottom() const { return reinterpret_cast<T*>(stack_); }
-
- bool HasAllocator() const {
- return allocator_ != 0;
- }
-
- Allocator& GetAllocator() {
- RAPIDJSON_ASSERT(allocator_);
- return *allocator_;
- }
-
- bool Empty() const { return stackTop_ == stack_; }
- size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
- size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }
-
-private:
- template<typename T>
- void Expand(size_t count) {
- // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
- size_t newCapacity;
- if (stack_ == 0) {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
- newCapacity = initialCapacity_;
- } else {
- newCapacity = GetCapacity();
- newCapacity += (newCapacity + 1) / 2;
- }
- size_t newSize = GetSize() + sizeof(T) * count;
- if (newCapacity < newSize)
- newCapacity = newSize;
-
- Resize(newCapacity);
- }
-
- void Resize(size_t newCapacity) {
- const size_t size = GetSize(); // Backup the current size
- stack_ = static_cast<char*>(allocator_->Realloc(stack_, GetCapacity(), newCapacity));
- stackTop_ = stack_ + size;
- stackEnd_ = stack_ + newCapacity;
- }
-
- void Destroy() {
- Allocator::Free(stack_);
- RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack
- }
-
- // Prohibit copy constructor & assignment operator.
- Stack(const Stack&);
- Stack& operator=(const Stack&);
-
- Allocator* allocator_;
- Allocator* ownAllocator_;
- char *stack_;
- char *stackTop_;
- char *stackEnd_;
- size_t initialCapacity_;
-};
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_STACK_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strfunc.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strfunc.h
deleted file mode 100644
index 226439a76..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strfunc.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
-#define RAPIDJSON_INTERNAL_STRFUNC_H_
-
-#include "../stream.h"
-#include <cwchar>
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-//! Custom strlen() which works on different character types.
-/*! \tparam Ch Character type (e.g. char, wchar_t, short)
- \param s Null-terminated input string.
- \return Number of characters in the string.
- \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints.
-*/
-template <typename Ch>
-inline SizeType StrLen(const Ch* s) {
- RAPIDJSON_ASSERT(s != 0);
- const Ch* p = s;
- while (*p) ++p;
- return SizeType(p - s);
-}
-
-template <>
-inline SizeType StrLen(const char* s) {
- return SizeType(std::strlen(s));
-}
-
-template <>
-inline SizeType StrLen(const wchar_t* s) {
- return SizeType(std::wcslen(s));
-}
-
-//! Returns number of code points in a encoded string.
-template<typename Encoding>
-bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
- RAPIDJSON_ASSERT(s != 0);
- RAPIDJSON_ASSERT(outCount != 0);
- GenericStringStream<Encoding> is(s);
- const typename Encoding::Ch* end = s + length;
- SizeType count = 0;
- while (is.src_ < end) {
- unsigned codepoint;
- if (!Encoding::Decode(is, &codepoint))
- return false;
- count++;
- }
- *outCount = count;
- return true;
-}
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_INTERNAL_STRFUNC_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strtod.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strtod.h
deleted file mode 100644
index adf49e349..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/strtod.h
+++ /dev/null
@@ -1,269 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_STRTOD_
-#define RAPIDJSON_STRTOD_
-
-#include "ieee754.h"
-#include "biginteger.h"
-#include "diyfp.h"
-#include "pow10.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-inline double FastPath(double significand, int exp) {
- if (exp < -308)
- return 0.0;
- else if (exp >= 0)
- return significand * internal::Pow10(exp);
- else
- return significand / internal::Pow10(-exp);
-}
-
-inline double StrtodNormalPrecision(double d, int p) {
- if (p < -308) {
- // Prevent expSum < -308, making Pow10(p) = 0
- d = FastPath(d, -308);
- d = FastPath(d, p + 308);
- }
- else
- d = FastPath(d, p);
- return d;
-}
-
-template <typename T>
-inline T Min3(T a, T b, T c) {
- T m = a;
- if (m > b) m = b;
- if (m > c) m = c;
- return m;
-}
-
-inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
- const Double db(b);
- const uint64_t bInt = db.IntegerSignificand();
- const int bExp = db.IntegerExponent();
- const int hExp = bExp - 1;
-
- int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0;
-
- // Adjust for decimal exponent
- if (dExp >= 0) {
- dS_Exp2 += dExp;
- dS_Exp5 += dExp;
- }
- else {
- bS_Exp2 -= dExp;
- bS_Exp5 -= dExp;
- hS_Exp2 -= dExp;
- hS_Exp5 -= dExp;
- }
-
- // Adjust for binary exponent
- if (bExp >= 0)
- bS_Exp2 += bExp;
- else {
- dS_Exp2 -= bExp;
- hS_Exp2 -= bExp;
- }
-
- // Adjust for half ulp exponent
- if (hExp >= 0)
- hS_Exp2 += hExp;
- else {
- dS_Exp2 -= hExp;
- bS_Exp2 -= hExp;
- }
-
- // Remove common power of two factor from all three scaled values
- int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2);
- dS_Exp2 -= common_Exp2;
- bS_Exp2 -= common_Exp2;
- hS_Exp2 -= common_Exp2;
-
- BigInteger dS = d;
- dS.MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<= static_cast<unsigned>(dS_Exp2);
-
- BigInteger bS(bInt);
- bS.MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<= static_cast<unsigned>(bS_Exp2);
-
- BigInteger hS(1);
- hS.MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<= static_cast<unsigned>(hS_Exp2);
-
- BigInteger delta(0);
- dS.Difference(bS, &delta);
-
- return delta.Compare(hS);
-}
-
-inline bool StrtodFast(double d, int p, double* result) {
- // Use fast path for string-to-double conversion if possible
- // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
- if (p > 22 && p < 22 + 16) {
- // Fast Path Cases In Disguise
- d *= internal::Pow10(p - 22);
- p = 22;
- }
-
- if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1
- *result = FastPath(d, p);
- return true;
- }
- else
- return false;
-}
-
-// Compute an approximation and see if it is within 1/2 ULP
-inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosition, int exp, double* result) {
- uint64_t significand = 0;
- size_t i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999
- for (; i < length; i++) {
- if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) ||
- (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5'))
- break;
- significand = significand * 10u + static_cast<unsigned>(decimals[i] - '0');
- }
-
- if (i < length && decimals[i] >= '5') // Rounding
- significand++;
-
- size_t remaining = length - i;
- const int kUlpShift = 3;
- const int kUlp = 1 << kUlpShift;
- int64_t error = (remaining == 0) ? 0 : kUlp / 2;
-
- DiyFp v(significand, 0);
- v = v.Normalize();
- error <<= -v.e;
-
- const int dExp = static_cast<int>(decimalPosition) - static_cast<int>(i) + exp;
-
- int actualExp;
- DiyFp cachedPower = GetCachedPower10(dExp, &actualExp);
- if (actualExp != dExp) {
- static const DiyFp kPow10[] = {
- DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 00000000), -60), // 10^1
- DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 00000000), -57), // 10^2
- DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 00000000), -54), // 10^3
- DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 00000000), -50), // 10^4
- DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 00000000), -47), // 10^5
- DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6
- DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7
- };
- int adjustment = dExp - actualExp - 1;
- RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7);
- v = v * kPow10[adjustment];
- if (length + static_cast<unsigned>(adjustment)> 19u) // has more digits than decimal digits in 64-bit
- error += kUlp / 2;
- }
-
- v = v * cachedPower;
-
- error += kUlp + (error == 0 ? 0 : 1);
-
- const int oldExp = v.e;
- v = v.Normalize();
- error <<= oldExp - v.e;
-
- const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e);
- int precisionSize = 64 - effectiveSignificandSize;
- if (precisionSize + kUlpShift >= 64) {
- int scaleExp = (precisionSize + kUlpShift) - 63;
- v.f >>= scaleExp;
- v.e += scaleExp;
- error = (error >> scaleExp) + 1 + kUlp;
- precisionSize -= scaleExp;
- }
-
- DiyFp rounded(v.f >> precisionSize, v.e + precisionSize);
- const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp;
- const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp;
- if (precisionBits >= halfWay + static_cast<unsigned>(error)) {
- rounded.f++;
- if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340)
- rounded.f >>= 1;
- rounded.e++;
- }
- }
-
- *result = rounded.ToDouble();
-
- return halfWay - static_cast<unsigned>(error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(error);
-}
-
-inline double StrtodBigInteger(double approx, const char* decimals, size_t length, size_t decimalPosition, int exp) {
- const BigInteger dInt(decimals, length);
- const int dExp = static_cast<int>(decimalPosition) - static_cast<int>(length) + exp;
- Double a(approx);
- int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp);
- if (cmp < 0)
- return a.Value(); // within half ULP
- else if (cmp == 0) {
- // Round towards even
- if (a.Significand() & 1)
- return a.NextPositiveDouble();
- else
- return a.Value();
- }
- else // adjustment
- return a.NextPositiveDouble();
-}
-
-inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
- RAPIDJSON_ASSERT(d >= 0.0);
- RAPIDJSON_ASSERT(length >= 1);
-
- double result;
- if (StrtodFast(d, p, &result))
- return result;
-
- // Trim leading zeros
- while (*decimals == '0' && length > 1) {
- length--;
- decimals++;
- decimalPosition--;
- }
-
- // Trim trailing zeros
- while (decimals[length - 1] == '0' && length > 1) {
- length--;
- decimalPosition--;
- exp++;
- }
-
- // Trim right-most digits
- const int kMaxDecimalDigit = 780;
- if (static_cast<int>(length) > kMaxDecimalDigit) {
- int delta = (static_cast<int>(length) - kMaxDecimalDigit);
- exp += delta;
- decimalPosition -= static_cast<unsigned>(delta);
- length = kMaxDecimalDigit;
- }
-
- // If too small, underflow to zero
- if (int(length) + exp < -324)
- return 0.0;
-
- if (StrtodDiyFp(decimals, length, decimalPosition, exp, &result))
- return result;
-
- // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison
- return StrtodBigInteger(result, decimals, length, decimalPosition, exp);
-}
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_STRTOD_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/swap.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/swap.h
deleted file mode 100644
index 666e49f97..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/swap.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_INTERNAL_SWAP_H_
-#define RAPIDJSON_INTERNAL_SWAP_H_
-
-#include "../rapidjson.h"
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-namespace internal {
-
-//! Custom swap() to avoid dependency on C++ <algorithm> header
-/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
- \note This has the same semantics as std::swap().
-*/
-template <typename T>
-inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
- T tmp = a;
- a = b;
- b = tmp;
-}
-
-} // namespace internal
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_INTERNAL_SWAP_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/istreamwrapper.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/istreamwrapper.h
deleted file mode 100644
index 8639c8c3c..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/istreamwrapper.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_ISTREAMWRAPPER_H_
-#define RAPIDJSON_ISTREAMWRAPPER_H_
-
-#include "stream.h"
-#include <iosfwd>
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Wrapper of \c std::basic_istream into RapidJSON's Stream concept.
-/*!
- The classes can be wrapped including but not limited to:
-
- - \c std::istringstream
- - \c std::stringstream
- - \c std::wistringstream
- - \c std::wstringstream
- - \c std::ifstream
- - \c std::fstream
- - \c std::wifstream
- - \c std::wfstream
-
- \tparam StreamType Class derived from \c std::basic_istream.
-*/
-
-template <typename StreamType>
-class BasicIStreamWrapper {
-public:
- typedef typename StreamType::char_type Ch;
- BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {}
-
- Ch Peek() const {
- typename StreamType::int_type c = stream_.peek();
- return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast<Ch>(c) : static_cast<Ch>('\0');
- }
-
- Ch Take() {
- typename StreamType::int_type c = stream_.get();
- if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) {
- count_++;
- return static_cast<Ch>(c);
- }
- else
- return '\0';
- }
-
- // tellg() may return -1 when failed. So we count by ourself.
- size_t Tell() const { return count_; }
-
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
- // For encoding detection only.
- const Ch* Peek4() const {
- RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream.
- int i;
- bool hasError = false;
- for (i = 0; i < 4; ++i) {
- typename StreamType::int_type c = stream_.get();
- if (c == StreamType::traits_type::eof()) {
- hasError = true;
- stream_.clear();
- break;
- }
- peekBuffer_[i] = static_cast<Ch>(c);
- }
- for (--i; i >= 0; --i)
- stream_.putback(peekBuffer_[i]);
- return !hasError ? peekBuffer_ : 0;
- }
-
-private:
- BasicIStreamWrapper(const BasicIStreamWrapper&);
- BasicIStreamWrapper& operator=(const BasicIStreamWrapper&);
-
- StreamType& stream_;
- size_t count_; //!< Number of characters read. Note:
- mutable Ch peekBuffer_[4];
-};
-
-typedef BasicIStreamWrapper<std::istream> IStreamWrapper;
-typedef BasicIStreamWrapper<std::wistream> WIStreamWrapper;
-
-#if defined(__clang__) || defined(_MSC_VER)
-RAPIDJSON_DIAG_POP
-#endif
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_ISTREAMWRAPPER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorybuffer.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorybuffer.h
deleted file mode 100644
index 39bee1dec..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorybuffer.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_MEMORYBUFFER_H_
-#define RAPIDJSON_MEMORYBUFFER_H_
-
-#include "stream.h"
-#include "internal/stack.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Represents an in-memory output byte stream.
-/*!
- This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream.
-
- It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file.
-
- Differences between MemoryBuffer and StringBuffer:
- 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer.
- 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator.
-
- \tparam Allocator type for allocating memory buffer.
- \note implements Stream concept
-*/
-template <typename Allocator = CrtAllocator>
-struct GenericMemoryBuffer {
- typedef char Ch; // byte
-
- GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
-
- void Put(Ch c) { *stack_.template Push<Ch>() = c; }
- void Flush() {}
-
- void Clear() { stack_.Clear(); }
- void ShrinkToFit() { stack_.ShrinkToFit(); }
- Ch* Push(size_t count) { return stack_.template Push<Ch>(count); }
- void Pop(size_t count) { stack_.template Pop<Ch>(count); }
-
- const Ch* GetBuffer() const {
- return stack_.template Bottom<Ch>();
- }
-
- size_t GetSize() const { return stack_.GetSize(); }
-
- static const size_t kDefaultCapacity = 256;
- mutable internal::Stack<Allocator> stack_;
-};
-
-typedef GenericMemoryBuffer<> MemoryBuffer;
-
-//! Implement specialized version of PutN() with memset() for better performance.
-template<>
-inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
- std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
-}
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_MEMORYBUFFER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorystream.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorystream.h
deleted file mode 100644
index 1d71d8a4f..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/memorystream.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_MEMORYSTREAM_H_
-#define RAPIDJSON_MEMORYSTREAM_H_
-
-#include "stream.h"
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(unreachable-code)
-RAPIDJSON_DIAG_OFF(missing-noreturn)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Represents an in-memory input byte stream.
-/*!
- This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream.
-
- It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file.
-
- Differences between MemoryStream and StringStream:
- 1. StringStream has encoding but MemoryStream is a byte stream.
- 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source.
- 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4().
- \note implements Stream concept
-*/
-struct MemoryStream {
- typedef char Ch; // byte
-
- MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {}
-
- Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
- Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }
- size_t Tell() const { return static_cast<size_t>(src_ - begin_); }
-
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
- // For encoding detection only.
- const Ch* Peek4() const {
- return Tell() + 4 <= size_ ? src_ : 0;
- }
-
- const Ch* src_; //!< Current read position.
- const Ch* begin_; //!< Original head of the string.
- const Ch* end_; //!< End of stream.
- size_t size_; //!< Size of the stream.
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_MEMORYBUFFER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/inttypes.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/inttypes.h
deleted file mode 100644
index 18111286b..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/inttypes.h
+++ /dev/null
@@ -1,316 +0,0 @@
-// ISO C9x compliant inttypes.h for Microsoft Visual Studio
-// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-//
-// Copyright (c) 2006-2013 Alexander Chemeris
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the product nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-// The above software in this distribution may have been modified by
-// THL A29 Limited ("Tencent Modifications").
-// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
-
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
-
-#ifndef _MSC_INTTYPES_H_ // [
-#define _MSC_INTTYPES_H_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#include "stdint.h"
-
-// miloyip: VC supports inttypes.h since VC2013
-#if _MSC_VER >= 1800
-#include <inttypes.h>
-#else
-
-// 7.8 Format conversion of integer types
-
-typedef struct {
- intmax_t quot;
- intmax_t rem;
-} imaxdiv_t;
-
-// 7.8.1 Macros for format specifiers
-
-#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
-
-// The fprintf macros for signed integers are:
-#define PRId8 "d"
-#define PRIi8 "i"
-#define PRIdLEAST8 "d"
-#define PRIiLEAST8 "i"
-#define PRIdFAST8 "d"
-#define PRIiFAST8 "i"
-
-#define PRId16 "hd"
-#define PRIi16 "hi"
-#define PRIdLEAST16 "hd"
-#define PRIiLEAST16 "hi"
-#define PRIdFAST16 "hd"
-#define PRIiFAST16 "hi"
-
-#define PRId32 "I32d"
-#define PRIi32 "I32i"
-#define PRIdLEAST32 "I32d"
-#define PRIiLEAST32 "I32i"
-#define PRIdFAST32 "I32d"
-#define PRIiFAST32 "I32i"
-
-#define PRId64 "I64d"
-#define PRIi64 "I64i"
-#define PRIdLEAST64 "I64d"
-#define PRIiLEAST64 "I64i"
-#define PRIdFAST64 "I64d"
-#define PRIiFAST64 "I64i"
-
-#define PRIdMAX "I64d"
-#define PRIiMAX "I64i"
-
-#define PRIdPTR "Id"
-#define PRIiPTR "Ii"
-
-// The fprintf macros for unsigned integers are:
-#define PRIo8 "o"
-#define PRIu8 "u"
-#define PRIx8 "x"
-#define PRIX8 "X"
-#define PRIoLEAST8 "o"
-#define PRIuLEAST8 "u"
-#define PRIxLEAST8 "x"
-#define PRIXLEAST8 "X"
-#define PRIoFAST8 "o"
-#define PRIuFAST8 "u"
-#define PRIxFAST8 "x"
-#define PRIXFAST8 "X"
-
-#define PRIo16 "ho"
-#define PRIu16 "hu"
-#define PRIx16 "hx"
-#define PRIX16 "hX"
-#define PRIoLEAST16 "ho"
-#define PRIuLEAST16 "hu"
-#define PRIxLEAST16 "hx"
-#define PRIXLEAST16 "hX"
-#define PRIoFAST16 "ho"
-#define PRIuFAST16 "hu"
-#define PRIxFAST16 "hx"
-#define PRIXFAST16 "hX"
-
-#define PRIo32 "I32o"
-#define PRIu32 "I32u"
-#define PRIx32 "I32x"
-#define PRIX32 "I32X"
-#define PRIoLEAST32 "I32o"
-#define PRIuLEAST32 "I32u"
-#define PRIxLEAST32 "I32x"
-#define PRIXLEAST32 "I32X"
-#define PRIoFAST32 "I32o"
-#define PRIuFAST32 "I32u"
-#define PRIxFAST32 "I32x"
-#define PRIXFAST32 "I32X"
-
-#define PRIo64 "I64o"
-#define PRIu64 "I64u"
-#define PRIx64 "I64x"
-#define PRIX64 "I64X"
-#define PRIoLEAST64 "I64o"
-#define PRIuLEAST64 "I64u"
-#define PRIxLEAST64 "I64x"
-#define PRIXLEAST64 "I64X"
-#define PRIoFAST64 "I64o"
-#define PRIuFAST64 "I64u"
-#define PRIxFAST64 "I64x"
-#define PRIXFAST64 "I64X"
-
-#define PRIoMAX "I64o"
-#define PRIuMAX "I64u"
-#define PRIxMAX "I64x"
-#define PRIXMAX "I64X"
-
-#define PRIoPTR "Io"
-#define PRIuPTR "Iu"
-#define PRIxPTR "Ix"
-#define PRIXPTR "IX"
-
-// The fscanf macros for signed integers are:
-#define SCNd8 "d"
-#define SCNi8 "i"
-#define SCNdLEAST8 "d"
-#define SCNiLEAST8 "i"
-#define SCNdFAST8 "d"
-#define SCNiFAST8 "i"
-
-#define SCNd16 "hd"
-#define SCNi16 "hi"
-#define SCNdLEAST16 "hd"
-#define SCNiLEAST16 "hi"
-#define SCNdFAST16 "hd"
-#define SCNiFAST16 "hi"
-
-#define SCNd32 "ld"
-#define SCNi32 "li"
-#define SCNdLEAST32 "ld"
-#define SCNiLEAST32 "li"
-#define SCNdFAST32 "ld"
-#define SCNiFAST32 "li"
-
-#define SCNd64 "I64d"
-#define SCNi64 "I64i"
-#define SCNdLEAST64 "I64d"
-#define SCNiLEAST64 "I64i"
-#define SCNdFAST64 "I64d"
-#define SCNiFAST64 "I64i"
-
-#define SCNdMAX "I64d"
-#define SCNiMAX "I64i"
-
-#ifdef _WIN64 // [
-# define SCNdPTR "I64d"
-# define SCNiPTR "I64i"
-#else // _WIN64 ][
-# define SCNdPTR "ld"
-# define SCNiPTR "li"
-#endif // _WIN64 ]
-
-// The fscanf macros for unsigned integers are:
-#define SCNo8 "o"
-#define SCNu8 "u"
-#define SCNx8 "x"
-#define SCNX8 "X"
-#define SCNoLEAST8 "o"
-#define SCNuLEAST8 "u"
-#define SCNxLEAST8 "x"
-#define SCNXLEAST8 "X"
-#define SCNoFAST8 "o"
-#define SCNuFAST8 "u"
-#define SCNxFAST8 "x"
-#define SCNXFAST8 "X"
-
-#define SCNo16 "ho"
-#define SCNu16 "hu"
-#define SCNx16 "hx"
-#define SCNX16 "hX"
-#define SCNoLEAST16 "ho"
-#define SCNuLEAST16 "hu"
-#define SCNxLEAST16 "hx"
-#define SCNXLEAST16 "hX"
-#define SCNoFAST16 "ho"
-#define SCNuFAST16 "hu"
-#define SCNxFAST16 "hx"
-#define SCNXFAST16 "hX"
-
-#define SCNo32 "lo"
-#define SCNu32 "lu"
-#define SCNx32 "lx"
-#define SCNX32 "lX"
-#define SCNoLEAST32 "lo"
-#define SCNuLEAST32 "lu"
-#define SCNxLEAST32 "lx"
-#define SCNXLEAST32 "lX"
-#define SCNoFAST32 "lo"
-#define SCNuFAST32 "lu"
-#define SCNxFAST32 "lx"
-#define SCNXFAST32 "lX"
-
-#define SCNo64 "I64o"
-#define SCNu64 "I64u"
-#define SCNx64 "I64x"
-#define SCNX64 "I64X"
-#define SCNoLEAST64 "I64o"
-#define SCNuLEAST64 "I64u"
-#define SCNxLEAST64 "I64x"
-#define SCNXLEAST64 "I64X"
-#define SCNoFAST64 "I64o"
-#define SCNuFAST64 "I64u"
-#define SCNxFAST64 "I64x"
-#define SCNXFAST64 "I64X"
-
-#define SCNoMAX "I64o"
-#define SCNuMAX "I64u"
-#define SCNxMAX "I64x"
-#define SCNXMAX "I64X"
-
-#ifdef _WIN64 // [
-# define SCNoPTR "I64o"
-# define SCNuPTR "I64u"
-# define SCNxPTR "I64x"
-# define SCNXPTR "I64X"
-#else // _WIN64 ][
-# define SCNoPTR "lo"
-# define SCNuPTR "lu"
-# define SCNxPTR "lx"
-# define SCNXPTR "lX"
-#endif // _WIN64 ]
-
-#endif // __STDC_FORMAT_MACROS ]
-
-// 7.8.2 Functions for greatest-width integer types
-
-// 7.8.2.1 The imaxabs function
-#define imaxabs _abs64
-
-// 7.8.2.2 The imaxdiv function
-
-// This is modified version of div() function from Microsoft's div.c found
-// in %MSVC.NET%\crt\src\div.c
-#ifdef STATIC_IMAXDIV // [
-static
-#else // STATIC_IMAXDIV ][
-_inline
-#endif // STATIC_IMAXDIV ]
-imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
-{
- imaxdiv_t result;
-
- result.quot = numer / denom;
- result.rem = numer % denom;
-
- if (numer < 0 && result.rem > 0) {
- // did division wrong; must fix up
- ++result.quot;
- result.rem -= denom;
- }
-
- return result;
-}
-
-// 7.8.2.3 The strtoimax and strtoumax functions
-#define strtoimax _strtoi64
-#define strtoumax _strtoui64
-
-// 7.8.2.4 The wcstoimax and wcstoumax functions
-#define wcstoimax _wcstoi64
-#define wcstoumax _wcstoui64
-
-#endif // _MSC_VER >= 1800
-
-#endif // _MSC_INTTYPES_H_ ]
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/stdint.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/stdint.h
deleted file mode 100644
index 3d4477b9a..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/msinttypes/stdint.h
+++ /dev/null
@@ -1,300 +0,0 @@
-// ISO C9x compliant stdint.h for Microsoft Visual Studio
-// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-//
-// Copyright (c) 2006-2013 Alexander Chemeris
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the product nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-// The above software in this distribution may have been modified by
-// THL A29 Limited ("Tencent Modifications").
-// All Tencent Modifications are Copyright (C) 2015 THL A29 Limited.
-
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
-
-#ifndef _MSC_STDINT_H_ // [
-#define _MSC_STDINT_H_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-// miloyip: Originally Visual Studio 2010 uses its own stdint.h. However it generates warning with INT64_C(), so change to use this file for vs2010.
-#if _MSC_VER >= 1600 // [
-#include <stdint.h>
-
-#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
-
-#undef INT8_C
-#undef INT16_C
-#undef INT32_C
-#undef INT64_C
-#undef UINT8_C
-#undef UINT16_C
-#undef UINT32_C
-#undef UINT64_C
-
-// 7.18.4.1 Macros for minimum-width integer constants
-
-#define INT8_C(val) val##i8
-#define INT16_C(val) val##i16
-#define INT32_C(val) val##i32
-#define INT64_C(val) val##i64
-
-#define UINT8_C(val) val##ui8
-#define UINT16_C(val) val##ui16
-#define UINT32_C(val) val##ui32
-#define UINT64_C(val) val##ui64
-
-// 7.18.4.2 Macros for greatest-width integer constants
-// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
-// Check out Issue 9 for the details.
-#ifndef INTMAX_C // [
-# define INTMAX_C INT64_C
-#endif // INTMAX_C ]
-#ifndef UINTMAX_C // [
-# define UINTMAX_C UINT64_C
-#endif // UINTMAX_C ]
-
-#endif // __STDC_CONSTANT_MACROS ]
-
-#else // ] _MSC_VER >= 1700 [
-
-#include <limits.h>
-
-// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
-// compiling for ARM we have to wrap <wchar.h> include with 'extern "C++" {}'
-// or compiler would give many errors like this:
-// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
-#if defined(__cplusplus) && !defined(_M_ARM)
-extern "C" {
-#endif
-# include <wchar.h>
-#if defined(__cplusplus) && !defined(_M_ARM)
-}
-#endif
-
-// Define _W64 macros to mark types changing their size, like intptr_t.
-#ifndef _W64
-# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
-# define _W64 __w64
-# else
-# define _W64
-# endif
-#endif
-
-
-// 7.18.1 Integer types
-
-// 7.18.1.1 Exact-width integer types
-
-// Visual Studio 6 and Embedded Visual C++ 4 doesn't
-// realize that, e.g. char has the same size as __int8
-// so we give up on __intX for them.
-#if (_MSC_VER < 1300)
- typedef signed char int8_t;
- typedef signed short int16_t;
- typedef signed int int32_t;
- typedef unsigned char uint8_t;
- typedef unsigned short uint16_t;
- typedef unsigned int uint32_t;
-#else
- typedef signed __int8 int8_t;
- typedef signed __int16 int16_t;
- typedef signed __int32 int32_t;
- typedef unsigned __int8 uint8_t;
- typedef unsigned __int16 uint16_t;
- typedef unsigned __int32 uint32_t;
-#endif
-typedef signed __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-
-
-// 7.18.1.2 Minimum-width integer types
-typedef int8_t int_least8_t;
-typedef int16_t int_least16_t;
-typedef int32_t int_least32_t;
-typedef int64_t int_least64_t;
-typedef uint8_t uint_least8_t;
-typedef uint16_t uint_least16_t;
-typedef uint32_t uint_least32_t;
-typedef uint64_t uint_least64_t;
-
-// 7.18.1.3 Fastest minimum-width integer types
-typedef int8_t int_fast8_t;
-typedef int16_t int_fast16_t;
-typedef int32_t int_fast32_t;
-typedef int64_t int_fast64_t;
-typedef uint8_t uint_fast8_t;
-typedef uint16_t uint_fast16_t;
-typedef uint32_t uint_fast32_t;
-typedef uint64_t uint_fast64_t;
-
-// 7.18.1.4 Integer types capable of holding object pointers
-#ifdef _WIN64 // [
- typedef signed __int64 intptr_t;
- typedef unsigned __int64 uintptr_t;
-#else // _WIN64 ][
- typedef _W64 signed int intptr_t;
- typedef _W64 unsigned int uintptr_t;
-#endif // _WIN64 ]
-
-// 7.18.1.5 Greatest-width integer types
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
-
-
-// 7.18.2 Limits of specified-width integer types
-
-#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
-
-// 7.18.2.1 Limits of exact-width integer types
-#define INT8_MIN ((int8_t)_I8_MIN)
-#define INT8_MAX _I8_MAX
-#define INT16_MIN ((int16_t)_I16_MIN)
-#define INT16_MAX _I16_MAX
-#define INT32_MIN ((int32_t)_I32_MIN)
-#define INT32_MAX _I32_MAX
-#define INT64_MIN ((int64_t)_I64_MIN)
-#define INT64_MAX _I64_MAX
-#define UINT8_MAX _UI8_MAX
-#define UINT16_MAX _UI16_MAX
-#define UINT32_MAX _UI32_MAX
-#define UINT64_MAX _UI64_MAX
-
-// 7.18.2.2 Limits of minimum-width integer types
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-// 7.18.2.3 Limits of fastest minimum-width integer types
-#define INT_FAST8_MIN INT8_MIN
-#define INT_FAST8_MAX INT8_MAX
-#define INT_FAST16_MIN INT16_MIN
-#define INT_FAST16_MAX INT16_MAX
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST8_MAX UINT8_MAX
-#define UINT_FAST16_MAX UINT16_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-// 7.18.2.4 Limits of integer types capable of holding object pointers
-#ifdef _WIN64 // [
-# define INTPTR_MIN INT64_MIN
-# define INTPTR_MAX INT64_MAX
-# define UINTPTR_MAX UINT64_MAX
-#else // _WIN64 ][
-# define INTPTR_MIN INT32_MIN
-# define INTPTR_MAX INT32_MAX
-# define UINTPTR_MAX UINT32_MAX
-#endif // _WIN64 ]
-
-// 7.18.2.5 Limits of greatest-width integer types
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-// 7.18.3 Limits of other integer types
-
-#ifdef _WIN64 // [
-# define PTRDIFF_MIN _I64_MIN
-# define PTRDIFF_MAX _I64_MAX
-#else // _WIN64 ][
-# define PTRDIFF_MIN _I32_MIN
-# define PTRDIFF_MAX _I32_MAX
-#endif // _WIN64 ]
-
-#define SIG_ATOMIC_MIN INT_MIN
-#define SIG_ATOMIC_MAX INT_MAX
-
-#ifndef SIZE_MAX // [
-# ifdef _WIN64 // [
-# define SIZE_MAX _UI64_MAX
-# else // _WIN64 ][
-# define SIZE_MAX _UI32_MAX
-# endif // _WIN64 ]
-#endif // SIZE_MAX ]
-
-// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
-#ifndef WCHAR_MIN // [
-# define WCHAR_MIN 0
-#endif // WCHAR_MIN ]
-#ifndef WCHAR_MAX // [
-# define WCHAR_MAX _UI16_MAX
-#endif // WCHAR_MAX ]
-
-#define WINT_MIN 0
-#define WINT_MAX _UI16_MAX
-
-#endif // __STDC_LIMIT_MACROS ]
-
-
-// 7.18.4 Limits of other integer types
-
-#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
-
-// 7.18.4.1 Macros for minimum-width integer constants
-
-#define INT8_C(val) val##i8
-#define INT16_C(val) val##i16
-#define INT32_C(val) val##i32
-#define INT64_C(val) val##i64
-
-#define UINT8_C(val) val##ui8
-#define UINT16_C(val) val##ui16
-#define UINT32_C(val) val##ui32
-#define UINT64_C(val) val##ui64
-
-// 7.18.4.2 Macros for greatest-width integer constants
-// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
-// Check out Issue 9 for the details.
-#ifndef INTMAX_C // [
-# define INTMAX_C INT64_C
-#endif // INTMAX_C ]
-#ifndef UINTMAX_C // [
-# define UINTMAX_C UINT64_C
-#endif // UINTMAX_C ]
-
-#endif // __STDC_CONSTANT_MACROS ]
-
-#endif // _MSC_VER >= 1600 ]
-
-#endif // _MSC_STDINT_H_ ]
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/ostreamwrapper.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/ostreamwrapper.h
deleted file mode 100644
index 6f4667c08..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/ostreamwrapper.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_OSTREAMWRAPPER_H_
-#define RAPIDJSON_OSTREAMWRAPPER_H_
-
-#include "stream.h"
-#include <iosfwd>
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept.
-/*!
- The classes can be wrapped including but not limited to:
-
- - \c std::ostringstream
- - \c std::stringstream
- - \c std::wpstringstream
- - \c std::wstringstream
- - \c std::ifstream
- - \c std::fstream
- - \c std::wofstream
- - \c std::wfstream
-
- \tparam StreamType Class derived from \c std::basic_ostream.
-*/
-
-template <typename StreamType>
-class BasicOStreamWrapper {
-public:
- typedef typename StreamType::char_type Ch;
- BasicOStreamWrapper(StreamType& stream) : stream_(stream) {}
-
- void Put(Ch c) {
- stream_.put(c);
- }
-
- void Flush() {
- stream_.flush();
- }
-
- // Not implemented
- char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
- char Take() { RAPIDJSON_ASSERT(false); return 0; }
- size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
- char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
-
-private:
- BasicOStreamWrapper(const BasicOStreamWrapper&);
- BasicOStreamWrapper& operator=(const BasicOStreamWrapper&);
-
- StreamType& stream_;
-};
-
-typedef BasicOStreamWrapper<std::ostream> OStreamWrapper;
-typedef BasicOStreamWrapper<std::wostream> WOStreamWrapper;
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_OSTREAMWRAPPER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/pointer.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/pointer.h
deleted file mode 100644
index 0f377efec..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/pointer.h
+++ /dev/null
@@ -1,1358 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_POINTER_H_
-#define RAPIDJSON_POINTER_H_
-
-#include "document.h"
-#include "internal/itoa.h"
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(switch-enum)
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token
-
-//! Error code of parsing.
-/*! \ingroup RAPIDJSON_ERRORS
- \see GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode
-*/
-enum PointerParseErrorCode {
- kPointerParseErrorNone = 0, //!< The parse is successful
-
- kPointerParseErrorTokenMustBeginWithSolidus, //!< A token must begin with a '/'
- kPointerParseErrorInvalidEscape, //!< Invalid escape
- kPointerParseErrorInvalidPercentEncoding, //!< Invalid percent encoding in URI fragment
- kPointerParseErrorCharacterMustPercentEncode //!< A character must percent encoded in URI fragment
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericPointer
-
-//! Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
-/*!
- This class implements RFC 6901 "JavaScript Object Notation (JSON) Pointer"
- (https://tools.ietf.org/html/rfc6901).
-
- A JSON pointer is for identifying a specific value in a JSON document
- (GenericDocument). It can simplify coding of DOM tree manipulation, because it
- can access multiple-level depth of DOM tree with single API call.
-
- After it parses a string representation (e.g. "/foo/0" or URI fragment
- representation (e.g. "#/foo/0") into its internal representation (tokens),
- it can be used to resolve a specific value in multiple documents, or sub-tree
- of documents.
-
- Contrary to GenericValue, Pointer can be copy constructed and copy assigned.
- Apart from assignment, a Pointer cannot be modified after construction.
-
- Although Pointer is very convenient, please aware that constructing Pointer
- involves parsing and dynamic memory allocation. A special constructor with user-
- supplied tokens eliminates these.
-
- GenericPointer depends on GenericDocument and GenericValue.
-
- \tparam ValueType The value type of the DOM tree. E.g. GenericValue<UTF8<> >
- \tparam Allocator The allocator type for allocating memory for internal representation.
-
- \note GenericPointer uses same encoding of ValueType.
- However, Allocator of GenericPointer is independent of Allocator of Value.
-*/
-template <typename ValueType, typename Allocator = CrtAllocator>
-class GenericPointer {
-public:
- typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value
- typedef typename ValueType::Ch Ch; //!< Character type from Value
-
- //! A token is the basic units of internal representation.
- /*!
- A JSON pointer string representation "/foo/123" is parsed to two tokens:
- "foo" and 123. 123 will be represented in both numeric form and string form.
- They are resolved according to the actual value type (object or array).
-
- For token that are not numbers, or the numeric value is out of bound
- (greater than limits of SizeType), they are only treated as string form
- (i.e. the token's index will be equal to kPointerInvalidIndex).
-
- This struct is public so that user can create a Pointer without parsing and
- allocation, using a special constructor.
- */
- struct Token {
- const Ch* name; //!< Name of the token. It has null character at the end but it can contain null character.
- SizeType length; //!< Length of the name.
- SizeType index; //!< A valid array index, if it is not equal to kPointerInvalidIndex.
- };
-
- //!@name Constructors and destructor.
- //@{
-
- //! Default constructor.
- GenericPointer(Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
-
- //! Constructor that parses a string or URI fragment representation.
- /*!
- \param source A null-terminated, string or URI fragment representation of JSON pointer.
- \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
- */
- explicit GenericPointer(const Ch* source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
- Parse(source, internal::StrLen(source));
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Constructor that parses a string or URI fragment representation.
- /*!
- \param source A string or URI fragment representation of JSON pointer.
- \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
- \note Requires the definition of the preprocessor symbol \ref RAPIDJSON_HAS_STDSTRING.
- */
- explicit GenericPointer(const std::basic_string<Ch>& source, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
- Parse(source.c_str(), source.size());
- }
-#endif
-
- //! Constructor that parses a string or URI fragment representation, with length of the source string.
- /*!
- \param source A string or URI fragment representation of JSON pointer.
- \param length Length of source.
- \param allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
- \note Slightly faster than the overload without length.
- */
- GenericPointer(const Ch* source, size_t length, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
- Parse(source, length);
- }
-
- //! Constructor with user-supplied tokens.
- /*!
- This constructor let user supplies const array of tokens.
- This prevents the parsing process and eliminates allocation.
- This is preferred for memory constrained environments.
-
- \param tokens An constant array of tokens representing the JSON pointer.
- \param tokenCount Number of tokens.
-
- \b Example
- \code
- #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
- #define INDEX(i) { #i, sizeof(#i) - 1, i }
-
- static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) };
- static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0]));
- // Equivalent to static const Pointer p("/foo/123");
-
- #undef NAME
- #undef INDEX
- \endcode
- */
- GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
-
- //! Copy constructor.
- GenericPointer(const GenericPointer& rhs, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
- *this = rhs;
- }
-
- //! Destructor.
- ~GenericPointer() {
- if (nameBuffer_) // If user-supplied tokens constructor is used, nameBuffer_ is nullptr and tokens_ are not deallocated.
- Allocator::Free(tokens_);
- RAPIDJSON_DELETE(ownAllocator_);
- }
-
- //! Assignment operator.
- GenericPointer& operator=(const GenericPointer& rhs) {
- if (this != &rhs) {
- // Do not delete ownAllcator
- if (nameBuffer_)
- Allocator::Free(tokens_);
-
- tokenCount_ = rhs.tokenCount_;
- parseErrorOffset_ = rhs.parseErrorOffset_;
- parseErrorCode_ = rhs.parseErrorCode_;
-
- if (rhs.nameBuffer_)
- CopyFromRaw(rhs); // Normally parsed tokens.
- else {
- tokens_ = rhs.tokens_; // User supplied const tokens.
- nameBuffer_ = 0;
- }
- }
- return *this;
- }
-
- //@}
-
- //!@name Append token
- //@{
-
- //! Append a token and return a new Pointer
- /*!
- \param token Token to be appended.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- GenericPointer Append(const Token& token, Allocator* allocator = 0) const {
- GenericPointer r;
- r.allocator_ = allocator;
- Ch *p = r.CopyFromRaw(*this, 1, token.length + 1);
- std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch));
- r.tokens_[tokenCount_].name = p;
- r.tokens_[tokenCount_].length = token.length;
- r.tokens_[tokenCount_].index = token.index;
- return r;
- }
-
- //! Append a name token with length, and return a new Pointer
- /*!
- \param name Name to be appended.
- \param length Length of name.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- GenericPointer Append(const Ch* name, SizeType length, Allocator* allocator = 0) const {
- Token token = { name, length, kPointerInvalidIndex };
- return Append(token, allocator);
- }
-
- //! Append a name token without length, and return a new Pointer
- /*!
- \param name Name (const Ch*) to be appended.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >), (GenericPointer))
- Append(T* name, Allocator* allocator = 0) const {
- return Append(name, internal::StrLen(name), allocator);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Append a name token, and return a new Pointer
- /*!
- \param name Name to be appended.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- GenericPointer Append(const std::basic_string<Ch>& name, Allocator* allocator = 0) const {
- return Append(name.c_str(), static_cast<SizeType>(name.size()), allocator);
- }
-#endif
-
- //! Append a index token, and return a new Pointer
- /*!
- \param index Index to be appended.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- GenericPointer Append(SizeType index, Allocator* allocator = 0) const {
- char buffer[21];
- char* end = sizeof(SizeType) == 4 ? internal::u32toa(index, buffer) : internal::u64toa(index, buffer);
- SizeType length = static_cast<SizeType>(end - buffer);
- buffer[length] = '\0';
-
- if (sizeof(Ch) == 1) {
- Token token = { reinterpret_cast<Ch*>(buffer), length, index };
- return Append(token, allocator);
- }
- else {
- Ch name[21];
- for (size_t i = 0; i <= length; i++)
- name[i] = static_cast<Ch>(buffer[i]);
- Token token = { name, length, index };
- return Append(token, allocator);
- }
- }
-
- //! Append a token by value, and return a new Pointer
- /*!
- \param token token to be appended.
- \param allocator Allocator for the newly return Pointer.
- \return A new Pointer with appended token.
- */
- GenericPointer Append(const ValueType& token, Allocator* allocator = 0) const {
- if (token.IsString())
- return Append(token.GetString(), token.GetStringLength(), allocator);
- else {
- RAPIDJSON_ASSERT(token.IsUint64());
- RAPIDJSON_ASSERT(token.GetUint64() <= SizeType(~0));
- return Append(static_cast<SizeType>(token.GetUint64()), allocator);
- }
- }
-
- //!@name Handling Parse Error
- //@{
-
- //! Check whether this is a valid pointer.
- bool IsValid() const { return parseErrorCode_ == kPointerParseErrorNone; }
-
- //! Get the parsing error offset in code unit.
- size_t GetParseErrorOffset() const { return parseErrorOffset_; }
-
- //! Get the parsing error code.
- PointerParseErrorCode GetParseErrorCode() const { return parseErrorCode_; }
-
- //@}
-
- //! Get the allocator of this pointer.
- Allocator& GetAllocator() { return *allocator_; }
-
- //!@name Tokens
- //@{
-
- //! Get the token array (const version only).
- const Token* GetTokens() const { return tokens_; }
-
- //! Get the number of tokens.
- size_t GetTokenCount() const { return tokenCount_; }
-
- //@}
-
- //!@name Equality/inequality operators
- //@{
-
- //! Equality operator.
- /*!
- \note When any pointers are invalid, always returns false.
- */
- bool operator==(const GenericPointer& rhs) const {
- if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_)
- return false;
-
- for (size_t i = 0; i < tokenCount_; i++) {
- if (tokens_[i].index != rhs.tokens_[i].index ||
- tokens_[i].length != rhs.tokens_[i].length ||
- (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch)* tokens_[i].length) != 0))
- {
- return false;
- }
- }
-
- return true;
- }
-
- //! Inequality operator.
- /*!
- \note When any pointers are invalid, always returns true.
- */
- bool operator!=(const GenericPointer& rhs) const { return !(*this == rhs); }
-
- //@}
-
- //!@name Stringify
- //@{
-
- //! Stringify the pointer into string representation.
- /*!
- \tparam OutputStream Type of output stream.
- \param os The output stream.
- */
- template<typename OutputStream>
- bool Stringify(OutputStream& os) const {
- return Stringify<false, OutputStream>(os);
- }
-
- //! Stringify the pointer into URI fragment representation.
- /*!
- \tparam OutputStream Type of output stream.
- \param os The output stream.
- */
- template<typename OutputStream>
- bool StringifyUriFragment(OutputStream& os) const {
- return Stringify<true, OutputStream>(os);
- }
-
- //@}
-
- //!@name Create value
- //@{
-
- //! Create a value in a subtree.
- /*!
- If the value is not exist, it creates all parent values and a JSON Null value.
- So it always succeed and return the newly created or existing value.
-
- Remind that it may change types of parents according to tokens, so it
- potentially removes previously stored values. For example, if a document
- was an array, and "/foo" is used to create a value, then the document
- will be changed to an object, and all existing array elements are lost.
-
- \param root Root value of a DOM subtree to be resolved. It can be any value other than document root.
- \param allocator Allocator for creating the values if the specified value or its parents are not exist.
- \param alreadyExist If non-null, it stores whether the resolved value is already exist.
- \return The resolved newly created (a JSON Null value), or already exists value.
- */
- ValueType& Create(ValueType& root, typename ValueType::AllocatorType& allocator, bool* alreadyExist = 0) const {
- RAPIDJSON_ASSERT(IsValid());
- ValueType* v = &root;
- bool exist = true;
- for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
- if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
- v->PushBack(ValueType().Move(), allocator);
- v = &((*v)[v->Size() - 1]);
- exist = false;
- }
- else {
- if (t->index == kPointerInvalidIndex) { // must be object name
- if (!v->IsObject())
- v->SetObject(); // Change to Object
- }
- else { // object name or array index
- if (!v->IsArray() && !v->IsObject())
- v->SetArray(); // Change to Array
- }
-
- if (v->IsArray()) {
- if (t->index >= v->Size()) {
- v->Reserve(t->index + 1, allocator);
- while (t->index >= v->Size())
- v->PushBack(ValueType().Move(), allocator);
- exist = false;
- }
- v = &((*v)[t->index]);
- }
- else {
- typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
- if (m == v->MemberEnd()) {
- v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
- v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end
- exist = false;
- }
- else
- v = &m->value;
- }
- }
- }
-
- if (alreadyExist)
- *alreadyExist = exist;
-
- return *v;
- }
-
- //! Creates a value in a document.
- /*!
- \param document A document to be resolved.
- \param alreadyExist If non-null, it stores whether the resolved value is already exist.
- \return The resolved newly created, or already exists value.
- */
- template <typename stackAllocator>
- ValueType& Create(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, bool* alreadyExist = 0) const {
- return Create(document, document.GetAllocator(), alreadyExist);
- }
-
- //@}
-
- //!@name Query value
- //@{
-
- //! Query a value in a subtree.
- /*!
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token.
- \return Pointer to the value if it can be resolved. Otherwise null.
-
- \note
- There are only 3 situations when a value cannot be resolved:
- 1. A value in the path is not an array nor object.
- 2. An object value does not contain the token.
- 3. A token is out of range of an array value.
-
- Use unresolvedTokenIndex to retrieve the token index.
- */
- ValueType* Get(ValueType& root, size_t* unresolvedTokenIndex = 0) const {
- RAPIDJSON_ASSERT(IsValid());
- ValueType* v = &root;
- for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
- switch (v->GetType()) {
- case kObjectType:
- {
- typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
- if (m == v->MemberEnd())
- break;
- v = &m->value;
- }
- continue;
- case kArrayType:
- if (t->index == kPointerInvalidIndex || t->index >= v->Size())
- break;
- v = &((*v)[t->index]);
- continue;
- default:
- break;
- }
-
- // Error: unresolved token
- if (unresolvedTokenIndex)
- *unresolvedTokenIndex = static_cast<size_t>(t - tokens_);
- return 0;
- }
- return v;
- }
-
- //! Query a const value in a const subtree.
- /*!
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \return Pointer to the value if it can be resolved. Otherwise null.
- */
- const ValueType* Get(const ValueType& root, size_t* unresolvedTokenIndex = 0) const {
- return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
- }
-
- //@}
-
- //!@name Query a value with default
- //@{
-
- //! Query a value in a subtree with default value.
- /*!
- Similar to Get(), but if the specified value do not exists, it creates all parents and clone the default value.
- So that this function always succeed.
-
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \param defaultValue Default value to be cloned if the value was not exists.
- \param allocator Allocator for creating the values if the specified value or its parents are not exist.
- \see Create()
- */
- ValueType& GetWithDefault(ValueType& root, const ValueType& defaultValue, typename ValueType::AllocatorType& allocator) const {
- bool alreadyExist;
- Value& v = Create(root, allocator, &alreadyExist);
- return alreadyExist ? v : v.CopyFrom(defaultValue, allocator);
- }
-
- //! Query a value in a subtree with default null-terminated string.
- ValueType& GetWithDefault(ValueType& root, const Ch* defaultValue, typename ValueType::AllocatorType& allocator) const {
- bool alreadyExist;
- Value& v = Create(root, allocator, &alreadyExist);
- return alreadyExist ? v : v.SetString(defaultValue, allocator);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Query a value in a subtree with default std::basic_string.
- ValueType& GetWithDefault(ValueType& root, const std::basic_string<Ch>& defaultValue, typename ValueType::AllocatorType& allocator) const {
- bool alreadyExist;
- Value& v = Create(root, allocator, &alreadyExist);
- return alreadyExist ? v : v.SetString(defaultValue, allocator);
- }
-#endif
-
- //! Query a value in a subtree with default primitive value.
- /*!
- \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
- GetWithDefault(ValueType& root, T defaultValue, typename ValueType::AllocatorType& allocator) const {
- return GetWithDefault(root, ValueType(defaultValue).Move(), allocator);
- }
-
- //! Query a value in a document with default value.
- template <typename stackAllocator>
- ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const ValueType& defaultValue) const {
- return GetWithDefault(document, defaultValue, document.GetAllocator());
- }
-
- //! Query a value in a document with default null-terminated string.
- template <typename stackAllocator>
- ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const Ch* defaultValue) const {
- return GetWithDefault(document, defaultValue, document.GetAllocator());
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Query a value in a document with default std::basic_string.
- template <typename stackAllocator>
- ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const std::basic_string<Ch>& defaultValue) const {
- return GetWithDefault(document, defaultValue, document.GetAllocator());
- }
-#endif
-
- //! Query a value in a document with default primitive value.
- /*!
- \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
- */
- template <typename T, typename stackAllocator>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
- GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T defaultValue) const {
- return GetWithDefault(document, defaultValue, document.GetAllocator());
- }
-
- //@}
-
- //!@name Set a value
- //@{
-
- //! Set a value in a subtree, with move semantics.
- /*!
- It creates all parents if they are not exist or types are different to the tokens.
- So this function always succeeds but potentially remove existing values.
-
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \param value Value to be set.
- \param allocator Allocator for creating the values if the specified value or its parents are not exist.
- \see Create()
- */
- ValueType& Set(ValueType& root, ValueType& value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator) = value;
- }
-
- //! Set a value in a subtree, with copy semantics.
- ValueType& Set(ValueType& root, const ValueType& value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator).CopyFrom(value, allocator);
- }
-
- //! Set a null-terminated string in a subtree.
- ValueType& Set(ValueType& root, const Ch* value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator) = ValueType(value, allocator).Move();
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Set a std::basic_string in a subtree.
- ValueType& Set(ValueType& root, const std::basic_string<Ch>& value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator) = ValueType(value, allocator).Move();
- }
-#endif
-
- //! Set a primitive value in a subtree.
- /*!
- \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
- */
- template <typename T>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
- Set(ValueType& root, T value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator) = ValueType(value).Move();
- }
-
- //! Set a value in a document, with move semantics.
- template <typename stackAllocator>
- ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, ValueType& value) const {
- return Create(document) = value;
- }
-
- //! Set a value in a document, with copy semantics.
- template <typename stackAllocator>
- ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const ValueType& value) const {
- return Create(document).CopyFrom(value, document.GetAllocator());
- }
-
- //! Set a null-terminated string in a document.
- template <typename stackAllocator>
- ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const Ch* value) const {
- return Create(document) = ValueType(value, document.GetAllocator()).Move();
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- //! Sets a std::basic_string in a document.
- template <typename stackAllocator>
- ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, const std::basic_string<Ch>& value) const {
- return Create(document) = ValueType(value, document.GetAllocator()).Move();
- }
-#endif
-
- //! Set a primitive value in a document.
- /*!
- \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
- */
- template <typename T, typename stackAllocator>
- RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
- Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T value) const {
- return Create(document) = value;
- }
-
- //@}
-
- //!@name Swap a value
- //@{
-
- //! Swap a value with a value in a subtree.
- /*!
- It creates all parents if they are not exist or types are different to the tokens.
- So this function always succeeds but potentially remove existing values.
-
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \param value Value to be swapped.
- \param allocator Allocator for creating the values if the specified value or its parents are not exist.
- \see Create()
- */
- ValueType& Swap(ValueType& root, ValueType& value, typename ValueType::AllocatorType& allocator) const {
- return Create(root, allocator).Swap(value);
- }
-
- //! Swap a value with a value in a document.
- template <typename stackAllocator>
- ValueType& Swap(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, ValueType& value) const {
- return Create(document).Swap(value);
- }
-
- //@}
-
- //! Erase a value in a subtree.
- /*!
- \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- \return Whether the resolved value is found and erased.
-
- \note Erasing with an empty pointer \c Pointer(""), i.e. the root, always fail and return false.
- */
- bool Erase(ValueType& root) const {
- RAPIDJSON_ASSERT(IsValid());
- if (tokenCount_ == 0) // Cannot erase the root
- return false;
-
- ValueType* v = &root;
- const Token* last = tokens_ + (tokenCount_ - 1);
- for (const Token *t = tokens_; t != last; ++t) {
- switch (v->GetType()) {
- case kObjectType:
- {
- typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
- if (m == v->MemberEnd())
- return false;
- v = &m->value;
- }
- break;
- case kArrayType:
- if (t->index == kPointerInvalidIndex || t->index >= v->Size())
- return false;
- v = &((*v)[t->index]);
- break;
- default:
- return false;
- }
- }
-
- switch (v->GetType()) {
- case kObjectType:
- return v->EraseMember(GenericStringRef<Ch>(last->name, last->length));
- case kArrayType:
- if (last->index == kPointerInvalidIndex || last->index >= v->Size())
- return false;
- v->Erase(v->Begin() + last->index);
- return true;
- default:
- return false;
- }
- }
-
-private:
- //! Clone the content from rhs to this.
- /*!
- \param rhs Source pointer.
- \param extraToken Extra tokens to be allocated.
- \param extraNameBufferSize Extra name buffer size (in number of Ch) to be allocated.
- \return Start of non-occupied name buffer, for storing extra names.
- */
- Ch* CopyFromRaw(const GenericPointer& rhs, size_t extraToken = 0, size_t extraNameBufferSize = 0) {
- if (!allocator_) // allocator is independently owned.
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
-
- size_t nameBufferSize = rhs.tokenCount_; // null terminators for tokens
- for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t)
- nameBufferSize += t->length;
-
- tokenCount_ = rhs.tokenCount_ + extraToken;
- tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + (nameBufferSize + extraNameBufferSize) * sizeof(Ch)));
- nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
- if (rhs.tokenCount_ > 0) {
- std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ * sizeof(Token));
- }
- if (nameBufferSize > 0) {
- std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize * sizeof(Ch));
- }
-
- // Adjust pointers to name buffer
- std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_;
- for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t)
- t->name += diff;
-
- return nameBuffer_ + nameBufferSize;
- }
-
- //! Check whether a character should be percent-encoded.
- /*!
- According to RFC 3986 2.3 Unreserved Characters.
- \param c The character (code unit) to be tested.
- */
- bool NeedPercentEncode(Ch c) const {
- return !((c >= '0' && c <= '9') || (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '_' || c =='~');
- }
-
- //! Parse a JSON String or its URI fragment representation into tokens.
-#ifndef __clang__ // -Wdocumentation
- /*!
- \param source Either a JSON Pointer string, or its URI fragment representation. Not need to be null terminated.
- \param length Length of the source string.
- \note Source cannot be JSON String Representation of JSON Pointer, e.g. In "/\u0000", \u0000 will not be unescaped.
- */
-#endif
- void Parse(const Ch* source, size_t length) {
- RAPIDJSON_ASSERT(source != NULL);
- RAPIDJSON_ASSERT(nameBuffer_ == 0);
- RAPIDJSON_ASSERT(tokens_ == 0);
-
- // Create own allocator if user did not supply.
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
-
- // Count number of '/' as tokenCount
- tokenCount_ = 0;
- for (const Ch* s = source; s != source + length; s++)
- if (*s == '/')
- tokenCount_++;
-
- Token* token = tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + length * sizeof(Ch)));
- Ch* name = nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
- size_t i = 0;
-
- // Detect if it is a URI fragment
- bool uriFragment = false;
- if (source[i] == '#') {
- uriFragment = true;
- i++;
- }
-
- if (i != length && source[i] != '/') {
- parseErrorCode_ = kPointerParseErrorTokenMustBeginWithSolidus;
- goto error;
- }
-
- while (i < length) {
- RAPIDJSON_ASSERT(source[i] == '/');
- i++; // consumes '/'
-
- token->name = name;
- bool isNumber = true;
-
- while (i < length && source[i] != '/') {
- Ch c = source[i];
- if (uriFragment) {
- // Decoding percent-encoding for URI fragment
- if (c == '%') {
- PercentDecodeStream is(&source[i], source + length);
- GenericInsituStringStream<EncodingType> os(name);
- Ch* begin = os.PutBegin();
- if (!Transcoder<UTF8<>, EncodingType>().Validate(is, os) || !is.IsValid()) {
- parseErrorCode_ = kPointerParseErrorInvalidPercentEncoding;
- goto error;
- }
- size_t len = os.PutEnd(begin);
- i += is.Tell() - 1;
- if (len == 1)
- c = *name;
- else {
- name += len;
- isNumber = false;
- i++;
- continue;
- }
- }
- else if (NeedPercentEncode(c)) {
- parseErrorCode_ = kPointerParseErrorCharacterMustPercentEncode;
- goto error;
- }
- }
-
- i++;
-
- // Escaping "~0" -> '~', "~1" -> '/'
- if (c == '~') {
- if (i < length) {
- c = source[i];
- if (c == '0') c = '~';
- else if (c == '1') c = '/';
- else {
- parseErrorCode_ = kPointerParseErrorInvalidEscape;
- goto error;
- }
- i++;
- }
- else {
- parseErrorCode_ = kPointerParseErrorInvalidEscape;
- goto error;
- }
- }
-
- // First check for index: all of characters are digit
- if (c < '0' || c > '9')
- isNumber = false;
-
- *name++ = c;
- }
- token->length = static_cast<SizeType>(name - token->name);
- if (token->length == 0)
- isNumber = false;
- *name++ = '\0'; // Null terminator
-
- // Second check for index: more than one digit cannot have leading zero
- if (isNumber && token->length > 1 && token->name[0] == '0')
- isNumber = false;
-
- // String to SizeType conversion
- SizeType n = 0;
- if (isNumber) {
- for (size_t j = 0; j < token->length; j++) {
- SizeType m = n * 10 + static_cast<SizeType>(token->name[j] - '0');
- if (m < n) { // overflow detection
- isNumber = false;
- break;
- }
- n = m;
- }
- }
-
- token->index = isNumber ? n : kPointerInvalidIndex;
- token++;
- }
-
- RAPIDJSON_ASSERT(name <= nameBuffer_ + length); // Should not overflow buffer
- parseErrorCode_ = kPointerParseErrorNone;
- return;
-
- error:
- Allocator::Free(tokens_);
- nameBuffer_ = 0;
- tokens_ = 0;
- tokenCount_ = 0;
- parseErrorOffset_ = i;
- return;
- }
-
- //! Stringify to string or URI fragment representation.
- /*!
- \tparam uriFragment True for stringifying to URI fragment representation. False for string representation.
- \tparam OutputStream type of output stream.
- \param os The output stream.
- */
- template<bool uriFragment, typename OutputStream>
- bool Stringify(OutputStream& os) const {
- RAPIDJSON_ASSERT(IsValid());
-
- if (uriFragment)
- os.Put('#');
-
- for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
- os.Put('/');
- for (size_t j = 0; j < t->length; j++) {
- Ch c = t->name[j];
- if (c == '~') {
- os.Put('~');
- os.Put('0');
- }
- else if (c == '/') {
- os.Put('~');
- os.Put('1');
- }
- else if (uriFragment && NeedPercentEncode(c)) {
- // Transcode to UTF8 sequence
- GenericStringStream<typename ValueType::EncodingType> source(&t->name[j]);
- PercentEncodeStream<OutputStream> target(os);
- if (!Transcoder<EncodingType, UTF8<> >().Validate(source, target))
- return false;
- j += source.Tell() - 1;
- }
- else
- os.Put(c);
- }
- }
- return true;
- }
-
- //! A helper stream for decoding a percent-encoded sequence into code unit.
- /*!
- This stream decodes %XY triplet into code unit (0-255).
- If it encounters invalid characters, it sets output code unit as 0 and
- mark invalid, and to be checked by IsValid().
- */
- class PercentDecodeStream {
- public:
- typedef typename ValueType::Ch Ch;
-
- //! Constructor
- /*!
- \param source Start of the stream
- \param end Past-the-end of the stream.
- */
- PercentDecodeStream(const Ch* source, const Ch* end) : src_(source), head_(source), end_(end), valid_(true) {}
-
- Ch Take() {
- if (*src_ != '%' || src_ + 3 > end_) { // %XY triplet
- valid_ = false;
- return 0;
- }
- src_++;
- Ch c = 0;
- for (int j = 0; j < 2; j++) {
- c = static_cast<Ch>(c << 4);
- Ch h = *src_;
- if (h >= '0' && h <= '9') c = static_cast<Ch>(c + h - '0');
- else if (h >= 'A' && h <= 'F') c = static_cast<Ch>(c + h - 'A' + 10);
- else if (h >= 'a' && h <= 'f') c = static_cast<Ch>(c + h - 'a' + 10);
- else {
- valid_ = false;
- return 0;
- }
- src_++;
- }
- return c;
- }
-
- size_t Tell() const { return static_cast<size_t>(src_ - head_); }
- bool IsValid() const { return valid_; }
-
- private:
- const Ch* src_; //!< Current read position.
- const Ch* head_; //!< Original head of the string.
- const Ch* end_; //!< Past-the-end position.
- bool valid_; //!< Whether the parsing is valid.
- };
-
- //! A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence.
- template <typename OutputStream>
- class PercentEncodeStream {
- public:
- PercentEncodeStream(OutputStream& os) : os_(os) {}
- void Put(char c) { // UTF-8 must be byte
- unsigned char u = static_cast<unsigned char>(c);
- static const char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- os_.Put('%');
- os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u >> 4]));
- os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u & 15]));
- }
- private:
- OutputStream& os_;
- };
-
- Allocator* allocator_; //!< The current allocator. It is either user-supplied or equal to ownAllocator_.
- Allocator* ownAllocator_; //!< Allocator owned by this Pointer.
- Ch* nameBuffer_; //!< A buffer containing all names in tokens.
- Token* tokens_; //!< A list of tokens.
- size_t tokenCount_; //!< Number of tokens in tokens_.
- size_t parseErrorOffset_; //!< Offset in code unit when parsing fail.
- PointerParseErrorCode parseErrorCode_; //!< Parsing error code.
-};
-
-//! GenericPointer for Value (UTF-8, default allocator).
-typedef GenericPointer<Value> Pointer;
-
-//!@name Helper functions for GenericPointer
-//@{
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-typename T::ValueType& CreateValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, typename T::AllocatorType& a) {
- return pointer.Create(root, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& CreateValueByPointer(T& root, const CharType(&source)[N], typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Create(root, a);
-}
-
-// No allocator parameter
-
-template <typename DocumentType>
-typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer) {
- return pointer.Create(document);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const CharType(&source)[N]) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Create(document);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-typename T::ValueType* GetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = 0) {
- return pointer.Get(root, unresolvedTokenIndex);
-}
-
-template <typename T>
-const typename T::ValueType* GetValueByPointer(const T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = 0) {
- return pointer.Get(root, unresolvedTokenIndex);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType* GetValueByPointer(T& root, const CharType (&source)[N], size_t* unresolvedTokenIndex = 0) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
-}
-
-template <typename T, typename CharType, size_t N>
-const typename T::ValueType* GetValueByPointer(const T& root, const CharType(&source)[N], size_t* unresolvedTokenIndex = 0) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::ValueType& defaultValue, typename T::AllocatorType& a) {
- return pointer.GetWithDefault(root, defaultValue, a);
-}
-
-template <typename T>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::Ch* defaultValue, typename T::AllocatorType& a) {
- return pointer.GetWithDefault(root, defaultValue, a);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename T>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointer<typename T::ValueType>& pointer, const std::basic_string<typename T::Ch>& defaultValue, typename T::AllocatorType& a) {
- return pointer.GetWithDefault(root, defaultValue, a);
-}
-#endif
-
-template <typename T, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
-GetValueByPointerWithDefault(T& root, const GenericPointer<typename T::ValueType>& pointer, T2 defaultValue, typename T::AllocatorType& a) {
- return pointer.GetWithDefault(root, defaultValue, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::ValueType& defaultValue, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::Ch* defaultValue, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const std::basic_string<typename T::Ch>& defaultValue, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
-}
-#endif
-
-template <typename T, typename CharType, size_t N, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
-GetValueByPointerWithDefault(T& root, const CharType(&source)[N], T2 defaultValue, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
-}
-
-// No allocator parameter
-
-template <typename DocumentType>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const typename DocumentType::ValueType& defaultValue) {
- return pointer.GetWithDefault(document, defaultValue);
-}
-
-template <typename DocumentType>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const typename DocumentType::Ch* defaultValue) {
- return pointer.GetWithDefault(document, defaultValue);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename DocumentType>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const std::basic_string<typename DocumentType::Ch>& defaultValue) {
- return pointer.GetWithDefault(document, defaultValue);
-}
-#endif
-
-template <typename DocumentType, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
-GetValueByPointerWithDefault(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, T2 defaultValue) {
- return pointer.GetWithDefault(document, defaultValue);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& defaultValue) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* defaultValue) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const std::basic_string<typename DocumentType::Ch>& defaultValue) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
-}
-#endif
-
-template <typename DocumentType, typename CharType, size_t N, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
-GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], T2 defaultValue) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, typename T::ValueType& value, typename T::AllocatorType& a) {
- return pointer.Set(root, value, a);
-}
-
-template <typename T>
-typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::ValueType& value, typename T::AllocatorType& a) {
- return pointer.Set(root, value, a);
-}
-
-template <typename T>
-typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::Ch* value, typename T::AllocatorType& a) {
- return pointer.Set(root, value, a);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename T>
-typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const std::basic_string<typename T::Ch>& value, typename T::AllocatorType& a) {
- return pointer.Set(root, value, a);
-}
-#endif
-
-template <typename T, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
-SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, T2 value, typename T::AllocatorType& a) {
- return pointer.Set(root, value, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const std::basic_string<typename T::Ch>& value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
-}
-#endif
-
-template <typename T, typename CharType, size_t N, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
-SetValueByPointer(T& root, const CharType(&source)[N], T2 value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
-}
-
-// No allocator parameter
-
-template <typename DocumentType>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, typename DocumentType::ValueType& value) {
- return pointer.Set(document, value);
-}
-
-template <typename DocumentType>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const typename DocumentType::ValueType& value) {
- return pointer.Set(document, value);
-}
-
-template <typename DocumentType>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const typename DocumentType::Ch* value) {
- return pointer.Set(document, value);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename DocumentType>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, const std::basic_string<typename DocumentType::Ch>& value) {
- return pointer.Set(document, value);
-}
-#endif
-
-template <typename DocumentType, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
-SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, T2 value) {
- return pointer.Set(document, value);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
-}
-
-#if RAPIDJSON_HAS_STDSTRING
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const std::basic_string<typename DocumentType::Ch>& value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
-}
-#endif
-
-template <typename DocumentType, typename CharType, size_t N, typename T2>
-RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
-SetValueByPointer(DocumentType& document, const CharType(&source)[N], T2 value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-typename T::ValueType& SwapValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, typename T::ValueType& value, typename T::AllocatorType& a) {
- return pointer.Swap(root, value, a);
-}
-
-template <typename T, typename CharType, size_t N>
-typename T::ValueType& SwapValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Swap(root, value, a);
-}
-
-template <typename DocumentType>
-typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, typename DocumentType::ValueType& value) {
- return pointer.Swap(document, value);
-}
-
-template <typename DocumentType, typename CharType, size_t N>
-typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) {
- return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Swap(document, value);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-bool EraseValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer) {
- return pointer.Erase(root);
-}
-
-template <typename T, typename CharType, size_t N>
-bool EraseValueByPointer(T& root, const CharType(&source)[N]) {
- return GenericPointer<typename T::ValueType>(source, N - 1).Erase(root);
-}
-
-//@}
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_POINTER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/prettywriter.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/prettywriter.h
deleted file mode 100644
index 98dfb3060..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/prettywriter.h
+++ /dev/null
@@ -1,277 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_PRETTYWRITER_H_
-#define RAPIDJSON_PRETTYWRITER_H_
-
-#include "writer.h"
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Combination of PrettyWriter format flags.
-/*! \see PrettyWriter::SetFormatOptions
- */
-enum PrettyFormatOptions {
- kFormatDefault = 0, //!< Default pretty formatting.
- kFormatSingleLineArray = 1 //!< Format arrays on a single line.
-};
-
-//! Writer with indentation and spacing.
-/*!
- \tparam OutputStream Type of ouptut os.
- \tparam SourceEncoding Encoding of source string.
- \tparam TargetEncoding Encoding of output stream.
- \tparam StackAllocator Type of allocator for allocating memory of stack.
-*/
-template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
-class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
-public:
- typedef Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> Base;
- typedef typename Base::Ch Ch;
-
- //! Constructor
- /*! \param os Output stream.
- \param allocator User supplied allocator. If it is null, it will create a private one.
- \param levelDepth Initial capacity of stack.
- */
- explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
- Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
-
-
- explicit PrettyWriter(StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
- Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- PrettyWriter(PrettyWriter&& rhs) :
- Base(std::forward<PrettyWriter>(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {}
-#endif
-
- //! Set custom indentation.
- /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\\t', '\\n', '\\r').
- \param indentCharCount Number of indent characters for each indentation level.
- \note The default indentation is 4 spaces.
- */
- PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) {
- RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
- indentChar_ = indentChar;
- indentCharCount_ = indentCharCount;
- return *this;
- }
-
- //! Set pretty writer formatting options.
- /*! \param options Formatting options.
- */
- PrettyWriter& SetFormatOptions(PrettyFormatOptions options) {
- formatOptions_ = options;
- return *this;
- }
-
- /*! @name Implementation of Handler
- \see Handler
- */
- //@{
-
- bool Null() { PrettyPrefix(kNullType); return Base::WriteNull(); }
- bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::WriteBool(b); }
- bool Int(int i) { PrettyPrefix(kNumberType); return Base::WriteInt(i); }
- bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::WriteUint(u); }
- bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::WriteInt64(i64); }
- bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::WriteUint64(u64); }
- bool Double(double d) { PrettyPrefix(kNumberType); return Base::WriteDouble(d); }
-
- bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
- RAPIDJSON_ASSERT(str != 0);
- (void)copy;
- PrettyPrefix(kNumberType);
- return Base::WriteString(str, length);
- }
-
- bool String(const Ch* str, SizeType length, bool copy = false) {
- RAPIDJSON_ASSERT(str != 0);
- (void)copy;
- PrettyPrefix(kStringType);
- return Base::WriteString(str, length);
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool String(const std::basic_string<Ch>& str) {
- return String(str.data(), SizeType(str.size()));
- }
-#endif
-
- bool StartObject() {
- PrettyPrefix(kObjectType);
- new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(false);
- return Base::WriteStartObject();
- }
-
- bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool Key(const std::basic_string<Ch>& str) {
- return Key(str.data(), SizeType(str.size()));
- }
-#endif
-
- bool EndObject(SizeType memberCount = 0) {
- (void)memberCount;
- RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); // not inside an Object
- RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray); // currently inside an Array, not Object
- RAPIDJSON_ASSERT(0 == Base::level_stack_.template Top<typename Base::Level>()->valueCount % 2); // Object has a Key without a Value
-
- bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
-
- if (!empty) {
- Base::os_->Put('\n');
- WriteIndent();
- }
- bool ret = Base::WriteEndObject();
- (void)ret;
- RAPIDJSON_ASSERT(ret == true);
- if (Base::level_stack_.Empty()) // end of json text
- Base::Flush();
- return true;
- }
-
- bool StartArray() {
- PrettyPrefix(kArrayType);
- new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(true);
- return Base::WriteStartArray();
- }
-
- bool EndArray(SizeType memberCount = 0) {
- (void)memberCount;
- RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
- RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
- bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
-
- if (!empty && !(formatOptions_ & kFormatSingleLineArray)) {
- Base::os_->Put('\n');
- WriteIndent();
- }
- bool ret = Base::WriteEndArray();
- (void)ret;
- RAPIDJSON_ASSERT(ret == true);
- if (Base::level_stack_.Empty()) // end of json text
- Base::Flush();
- return true;
- }
-
- //@}
-
- /*! @name Convenience extensions */
- //@{
-
- //! Simpler but slower overload.
- bool String(const Ch* str) { return String(str, internal::StrLen(str)); }
- bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); }
-
- //@}
-
- //! Write a raw JSON value.
- /*!
- For user to write a stringified JSON as a value.
-
- \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range.
- \param length Length of the json.
- \param type Type of the root of json.
- \note When using PrettyWriter::RawValue(), the result json may not be indented correctly.
- */
- bool RawValue(const Ch* json, size_t length, Type type) {
- RAPIDJSON_ASSERT(json != 0);
- PrettyPrefix(type);
- return Base::WriteRawValue(json, length);
- }
-
-protected:
- void PrettyPrefix(Type type) {
- (void)type;
- if (Base::level_stack_.GetSize() != 0) { // this value is not at root
- typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
-
- if (level->inArray) {
- if (level->valueCount > 0) {
- Base::os_->Put(','); // add comma if it is not the first element in array
- if (formatOptions_ & kFormatSingleLineArray)
- Base::os_->Put(' ');
- }
-
- if (!(formatOptions_ & kFormatSingleLineArray)) {
- Base::os_->Put('\n');
- WriteIndent();
- }
- }
- else { // in object
- if (level->valueCount > 0) {
- if (level->valueCount % 2 == 0) {
- Base::os_->Put(',');
- Base::os_->Put('\n');
- }
- else {
- Base::os_->Put(':');
- Base::os_->Put(' ');
- }
- }
- else
- Base::os_->Put('\n');
-
- if (level->valueCount % 2 == 0)
- WriteIndent();
- }
- if (!level->inArray && level->valueCount % 2 == 0)
- RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
- level->valueCount++;
- }
- else {
- RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root.
- Base::hasRoot_ = true;
- }
- }
-
- void WriteIndent() {
- size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_;
- PutN(*Base::os_, static_cast<typename OutputStream::Ch>(indentChar_), count);
- }
-
- Ch indentChar_;
- unsigned indentCharCount_;
- PrettyFormatOptions formatOptions_;
-
-private:
- // Prohibit copy constructor & assignment operator.
- PrettyWriter(const PrettyWriter&);
- PrettyWriter& operator=(const PrettyWriter&);
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_RAPIDJSON_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/rapidjson.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/rapidjson.h
deleted file mode 100644
index 5716fdc06..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/rapidjson.h
+++ /dev/null
@@ -1,628 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_RAPIDJSON_H_
-#define RAPIDJSON_RAPIDJSON_H_
-
-/*!\file rapidjson.h
- \brief common definitions and configuration
-
- \see RAPIDJSON_CONFIG
- */
-
-/*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration
- \brief Configuration macros for library features
-
- Some RapidJSON features are configurable to adapt the library to a wide
- variety of platforms, environments and usage scenarios. Most of the
- features can be configured in terms of overriden or predefined
- preprocessor macros at compile-time.
-
- Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs.
-
- \note These macros should be given on the compiler command-line
- (where applicable) to avoid inconsistent values when compiling
- different translation units of a single application.
- */
-
-#include <cstdlib> // malloc(), realloc(), free(), size_t
-#include <cstring> // memset(), memcpy(), memmove(), memcmp()
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_VERSION_STRING
-//
-// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
-//
-
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-// token stringification
-#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
-#define RAPIDJSON_DO_STRINGIFY(x) #x
-
-// token concatenation
-#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
-#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
-#define RAPIDJSON_DO_JOIN2(X, Y) X##Y
-//!@endcond
-
-/*! \def RAPIDJSON_MAJOR_VERSION
- \ingroup RAPIDJSON_CONFIG
- \brief Major version of RapidJSON in integer.
-*/
-/*! \def RAPIDJSON_MINOR_VERSION
- \ingroup RAPIDJSON_CONFIG
- \brief Minor version of RapidJSON in integer.
-*/
-/*! \def RAPIDJSON_PATCH_VERSION
- \ingroup RAPIDJSON_CONFIG
- \brief Patch version of RapidJSON in integer.
-*/
-/*! \def RAPIDJSON_VERSION_STRING
- \ingroup RAPIDJSON_CONFIG
- \brief Version of RapidJSON in "<major>.<minor>.<patch>" string format.
-*/
-#define RAPIDJSON_MAJOR_VERSION 1
-#define RAPIDJSON_MINOR_VERSION 1
-#define RAPIDJSON_PATCH_VERSION 0
-#define RAPIDJSON_VERSION_STRING \
- RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_NAMESPACE_(BEGIN|END)
-/*! \def RAPIDJSON_NAMESPACE
- \ingroup RAPIDJSON_CONFIG
- \brief provide custom rapidjson namespace
-
- In order to avoid symbol clashes and/or "One Definition Rule" errors
- between multiple inclusions of (different versions of) RapidJSON in
- a single binary, users can customize the name of the main RapidJSON
- namespace.
-
- In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE
- to a custom name (e.g. \c MyRapidJSON) is sufficient. If multiple
- levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref
- RAPIDJSON_NAMESPACE_END need to be defined as well:
-
- \code
- // in some .cpp file
- #define RAPIDJSON_NAMESPACE my::rapidjson
- #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
- #define RAPIDJSON_NAMESPACE_END } }
- #include "rapidjson/..."
- \endcode
-
- \see rapidjson
- */
-/*! \def RAPIDJSON_NAMESPACE_BEGIN
- \ingroup RAPIDJSON_CONFIG
- \brief provide custom rapidjson namespace (opening expression)
- \see RAPIDJSON_NAMESPACE
-*/
-/*! \def RAPIDJSON_NAMESPACE_END
- \ingroup RAPIDJSON_CONFIG
- \brief provide custom rapidjson namespace (closing expression)
- \see RAPIDJSON_NAMESPACE
-*/
-#ifndef RAPIDJSON_NAMESPACE
-#define RAPIDJSON_NAMESPACE rapidjson
-#endif
-#ifndef RAPIDJSON_NAMESPACE_BEGIN
-#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
-#endif
-#ifndef RAPIDJSON_NAMESPACE_END
-#define RAPIDJSON_NAMESPACE_END }
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_HAS_STDSTRING
-
-#ifndef RAPIDJSON_HAS_STDSTRING
-#ifdef RAPIDJSON_DOXYGEN_RUNNING
-#define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
-#else
-#define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
-#endif
-/*! \def RAPIDJSON_HAS_STDSTRING
- \ingroup RAPIDJSON_CONFIG
- \brief Enable RapidJSON support for \c std::string
-
- By defining this preprocessor symbol to \c 1, several convenience functions for using
- \ref rapidjson::GenericValue with \c std::string are enabled, especially
- for construction and comparison.
-
- \hideinitializer
-*/
-#endif // !defined(RAPIDJSON_HAS_STDSTRING)
-
-#if RAPIDJSON_HAS_STDSTRING
-#include <string>
-#endif // RAPIDJSON_HAS_STDSTRING
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_NO_INT64DEFINE
-
-/*! \def RAPIDJSON_NO_INT64DEFINE
- \ingroup RAPIDJSON_CONFIG
- \brief Use external 64-bit integer types.
-
- RapidJSON requires the 64-bit integer types \c int64_t and \c uint64_t types
- to be available at global scope.
-
- If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to
- prevent RapidJSON from defining its own types.
-*/
-#ifndef RAPIDJSON_NO_INT64DEFINE
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013
-#include "msinttypes/stdint.h"
-#include "msinttypes/inttypes.h"
-#else
-// Other compilers should have this.
-#include <stdint.h>
-#include <inttypes.h>
-#endif
-//!@endcond
-#ifdef RAPIDJSON_DOXYGEN_RUNNING
-#define RAPIDJSON_NO_INT64DEFINE
-#endif
-#endif // RAPIDJSON_NO_INT64TYPEDEF
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_FORCEINLINE
-
-#ifndef RAPIDJSON_FORCEINLINE
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#if defined(_MSC_VER) && defined(NDEBUG)
-#define RAPIDJSON_FORCEINLINE __forceinline
-#elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
-#define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
-#else
-#define RAPIDJSON_FORCEINLINE
-#endif
-//!@endcond
-#endif // RAPIDJSON_FORCEINLINE
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_ENDIAN
-#define RAPIDJSON_LITTLEENDIAN 0 //!< Little endian machine
-#define RAPIDJSON_BIGENDIAN 1 //!< Big endian machine
-
-//! Endianness of the machine.
-/*!
- \def RAPIDJSON_ENDIAN
- \ingroup RAPIDJSON_CONFIG
-
- GCC 4.6 provided macro for detecting endianness of the target machine. But other
- compilers may not have this. User can define RAPIDJSON_ENDIAN to either
- \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN.
-
- Default detection implemented with reference to
- \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html
- \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp
-*/
-#ifndef RAPIDJSON_ENDIAN
-// Detect with GCC 4.6's macro
-# ifdef __BYTE_ORDER__
-# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
-# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
-# else
-# error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
-# endif // __BYTE_ORDER__
-// Detect with GLIBC's endian.h
-# elif defined(__GLIBC__)
-# include <endian.h>
-# if (__BYTE_ORDER == __LITTLE_ENDIAN)
-# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
-# elif (__BYTE_ORDER == __BIG_ENDIAN)
-# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
-# else
-# error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
-# endif // __GLIBC__
-// Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
-# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
-# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
-# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
-# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
-// Detect with architecture macros
-# elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
-# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
-# elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__)
-# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
-# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
-# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
-# elif defined(RAPIDJSON_DOXYGEN_RUNNING)
-# define RAPIDJSON_ENDIAN
-# else
-# error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
-# endif
-#endif // RAPIDJSON_ENDIAN
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_64BIT
-
-//! Whether using 64-bit architecture
-#ifndef RAPIDJSON_64BIT
-#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
-#define RAPIDJSON_64BIT 1
-#else
-#define RAPIDJSON_64BIT 0
-#endif
-#endif // RAPIDJSON_64BIT
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_ALIGN
-
-//! Data alignment of the machine.
-/*! \ingroup RAPIDJSON_CONFIG
- \param x pointer to align
-
- Some machines require strict data alignment. Currently the default uses 4 bytes
- alignment on 32-bit platforms and 8 bytes alignment for 64-bit platforms.
- User can customize by defining the RAPIDJSON_ALIGN function macro.
-*/
-#ifndef RAPIDJSON_ALIGN
-#if RAPIDJSON_64BIT == 1
-#define RAPIDJSON_ALIGN(x) (((x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u))
-#else
-#define RAPIDJSON_ALIGN(x) (((x) + 3u) & ~3u)
-#endif
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_UINT64_C2
-
-//! Construct a 64-bit literal by a pair of 32-bit integer.
-/*!
- 64-bit literal with or without ULL suffix is prone to compiler warnings.
- UINT64_C() is C macro which cause compilation problems.
- Use this macro to define 64-bit constants by a pair of 32-bit integer.
-*/
-#ifndef RAPIDJSON_UINT64_C2
-#define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_48BITPOINTER_OPTIMIZATION
-
-//! Use only lower 48-bit address for some pointers.
-/*!
- \ingroup RAPIDJSON_CONFIG
-
- This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address.
- The higher 16-bit can be used for storing other data.
- \c GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.
-*/
-#ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
-#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
-#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
-#else
-#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
-#endif
-#endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
-
-#if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
-#if RAPIDJSON_64BIT != 1
-#error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
-#endif
-#define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast<type *>((reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast<uintptr_t>(reinterpret_cast<const void*>(x))))
-#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
-#else
-#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
-#define RAPIDJSON_GETPOINTER(type, p) (p)
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD
-
-/*! \def RAPIDJSON_SIMD
- \ingroup RAPIDJSON_CONFIG
- \brief Enable SSE2/SSE4.2/Neon optimization.
-
- RapidJSON supports optimized implementations for some parsing operations
- based on the SSE2, SSE4.2 or NEon SIMD extensions on modern Intel
- or ARM compatible processors.
-
- To enable these optimizations, three different symbols can be defined;
- \code
- // Enable SSE2 optimization.
- #define RAPIDJSON_SSE2
-
- // Enable SSE4.2 optimization.
- #define RAPIDJSON_SSE42
- \endcode
-
- // Enable ARM Neon optimization.
- #define RAPIDJSON_NEON
- \endcode
-
- \c RAPIDJSON_SSE42 takes precedence over SSE2, if both are defined.
-
- If any of these symbols is defined, RapidJSON defines the macro
- \c RAPIDJSON_SIMD to indicate the availability of the optimized code.
-*/
-#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
- || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
-#define RAPIDJSON_SIMD
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_NO_SIZETYPEDEFINE
-
-#ifndef RAPIDJSON_NO_SIZETYPEDEFINE
-/*! \def RAPIDJSON_NO_SIZETYPEDEFINE
- \ingroup RAPIDJSON_CONFIG
- \brief User-provided \c SizeType definition.
-
- In order to avoid using 32-bit size types for indexing strings and arrays,
- define this preprocessor symbol and provide the type rapidjson::SizeType
- before including RapidJSON:
- \code
- #define RAPIDJSON_NO_SIZETYPEDEFINE
- namespace rapidjson { typedef ::std::size_t SizeType; }
- #include "rapidjson/..."
- \endcode
-
- \see rapidjson::SizeType
-*/
-#ifdef RAPIDJSON_DOXYGEN_RUNNING
-#define RAPIDJSON_NO_SIZETYPEDEFINE
-#endif
-RAPIDJSON_NAMESPACE_BEGIN
-//! Size type (for string lengths, array sizes, etc.)
-/*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
- instead of using \c size_t. Users may override the SizeType by defining
- \ref RAPIDJSON_NO_SIZETYPEDEFINE.
-*/
-typedef unsigned SizeType;
-RAPIDJSON_NAMESPACE_END
-#endif
-
-// always import std::size_t to rapidjson namespace
-RAPIDJSON_NAMESPACE_BEGIN
-using std::size_t;
-RAPIDJSON_NAMESPACE_END
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_ASSERT
-
-//! Assertion.
-/*! \ingroup RAPIDJSON_CONFIG
- By default, rapidjson uses C \c assert() for internal assertions.
- User can override it by defining RAPIDJSON_ASSERT(x) macro.
-
- \note Parsing errors are handled and can be customized by the
- \ref RAPIDJSON_ERRORS APIs.
-*/
-#ifndef RAPIDJSON_ASSERT
-#include <cassert>
-#define RAPIDJSON_ASSERT(x) assert(x)
-#endif // RAPIDJSON_ASSERT
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_STATIC_ASSERT
-
-// Prefer C++11 static_assert, if available
-#ifndef RAPIDJSON_STATIC_ASSERT
-#if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
-#define RAPIDJSON_STATIC_ASSERT(x) \
- static_assert(x, RAPIDJSON_STRINGIFY(x))
-#endif // C++11
-#endif // RAPIDJSON_STATIC_ASSERT
-
-// Adopt C++03 implementation from boost
-#ifndef RAPIDJSON_STATIC_ASSERT
-#ifndef __clang__
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#endif
-RAPIDJSON_NAMESPACE_BEGIN
-template <bool x> struct STATIC_ASSERTION_FAILURE;
-template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
-template <size_t x> struct StaticAssertTest {};
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__GNUC__)
-#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
-#else
-#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
-#endif
-#ifndef __clang__
-//!@endcond
-#endif
-
-/*! \def RAPIDJSON_STATIC_ASSERT
- \brief (Internal) macro to check for conditions at compile-time
- \param x compile-time condition
- \hideinitializer
- */
-#define RAPIDJSON_STATIC_ASSERT(x) \
- typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
- sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
- RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
-#endif // RAPIDJSON_STATIC_ASSERT
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
-
-//! Compiler branching hint for expression with high probability to be true.
-/*!
- \ingroup RAPIDJSON_CONFIG
- \param x Boolean expression likely to be true.
-*/
-#ifndef RAPIDJSON_LIKELY
-#if defined(__GNUC__) || defined(__clang__)
-#define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
-#else
-#define RAPIDJSON_LIKELY(x) (x)
-#endif
-#endif
-
-//! Compiler branching hint for expression with low probability to be true.
-/*!
- \ingroup RAPIDJSON_CONFIG
- \param x Boolean expression unlikely to be true.
-*/
-#ifndef RAPIDJSON_UNLIKELY
-#if defined(__GNUC__) || defined(__clang__)
-#define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
-#else
-#define RAPIDJSON_UNLIKELY(x) (x)
-#endif
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// Helpers
-
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-
-#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
-#define RAPIDJSON_MULTILINEMACRO_END \
-} while((void)0, 0)
-
-// adopted from Boost
-#define RAPIDJSON_VERSION_CODE(x,y,z) \
- (((x)*100000) + ((y)*100) + (z))
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
-
-#if defined(__GNUC__)
-#define RAPIDJSON_GNUC \
- RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
-#endif
-
-#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
-
-#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
-#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
-#define RAPIDJSON_DIAG_OFF(x) \
- RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
-
-// push/pop support in Clang and GCC>=4.6
-#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
-#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
-#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
-#else // GCC >= 4.2, < 4.6
-#define RAPIDJSON_DIAG_PUSH /* ignored */
-#define RAPIDJSON_DIAG_POP /* ignored */
-#endif
-
-#elif defined(_MSC_VER)
-
-// pragma (MSVC specific)
-#define RAPIDJSON_PRAGMA(x) __pragma(x)
-#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
-
-#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
-#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
-#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
-
-#else
-
-#define RAPIDJSON_DIAG_OFF(x) /* ignored */
-#define RAPIDJSON_DIAG_PUSH /* ignored */
-#define RAPIDJSON_DIAG_POP /* ignored */
-
-#endif // RAPIDJSON_DIAG_*
-
-///////////////////////////////////////////////////////////////////////////////
-// C++11 features
-
-#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
-#if defined(__clang__)
-#if __has_feature(cxx_rvalue_references) && \
- (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
-#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
-#else
-#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
-#endif
-#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
- (defined(_MSC_VER) && _MSC_VER >= 1600)
-
-#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
-#else
-#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
-#endif
-#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
-
-#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
-#if defined(__clang__)
-#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
-#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
-// (defined(_MSC_VER) && _MSC_VER >= ????) // not yet supported
-#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
-#else
-#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
-#endif
-#endif
-#if RAPIDJSON_HAS_CXX11_NOEXCEPT
-#define RAPIDJSON_NOEXCEPT noexcept
-#else
-#define RAPIDJSON_NOEXCEPT /* noexcept */
-#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
-
-// no automatic detection, yet
-#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
-#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
-#endif
-
-#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
-#if defined(__clang__)
-#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
-#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
- (defined(_MSC_VER) && _MSC_VER >= 1700)
-#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
-#else
-#define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
-#endif
-#endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
-
-//!@endcond
-
-///////////////////////////////////////////////////////////////////////////////
-// new/delete
-
-#ifndef RAPIDJSON_NEW
-///! customization point for global \c new
-#define RAPIDJSON_NEW(TypeName) new TypeName
-#endif
-#ifndef RAPIDJSON_DELETE
-///! customization point for global \c delete
-#define RAPIDJSON_DELETE(x) delete x
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// Type
-
-/*! \namespace rapidjson
- \brief main RapidJSON namespace
- \see RAPIDJSON_NAMESPACE
-*/
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Type of JSON value
-enum Type {
- kNullType = 0, //!< null
- kFalseType = 1, //!< false
- kTrueType = 2, //!< true
- kObjectType = 3, //!< object
- kArrayType = 4, //!< array
- kStringType = 5, //!< string
- kNumberType = 6 //!< number
-};
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_RAPIDJSON_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/reader.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/reader.h
deleted file mode 100644
index 120c31115..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/reader.h
+++ /dev/null
@@ -1,2221 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_READER_H_
-#define RAPIDJSON_READER_H_
-
-/*! \file reader.h */
-
-#include "allocators.h"
-#include "stream.h"
-#include "encodedstream.h"
-#include "internal/meta.h"
-#include "internal/stack.h"
-#include "internal/strtod.h"
-#include <limits>
-
-#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER)
-#include <intrin.h>
-#pragma intrinsic(_BitScanForward)
-#endif
-#ifdef RAPIDJSON_SSE42
-#include <nmmintrin.h>
-#elif defined(RAPIDJSON_SSE2)
-#include <emmintrin.h>
-#elif defined(RAPIDJSON_NEON)
-#include <arm_neon.h>
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
-RAPIDJSON_DIAG_OFF(4702) // unreachable code
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(old-style-cast)
-RAPIDJSON_DIAG_OFF(padded)
-RAPIDJSON_DIAG_OFF(switch-enum)
-#endif
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#define RAPIDJSON_NOTHING /* deliberately empty */
-#ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN
-#define RAPIDJSON_PARSE_ERROR_EARLY_RETURN(value) \
- RAPIDJSON_MULTILINEMACRO_BEGIN \
- if (RAPIDJSON_UNLIKELY(HasParseError())) { return value; } \
- RAPIDJSON_MULTILINEMACRO_END
-#endif
-#define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(RAPIDJSON_NOTHING)
-//!@endcond
-
-/*! \def RAPIDJSON_PARSE_ERROR_NORETURN
- \ingroup RAPIDJSON_ERRORS
- \brief Macro to indicate a parse error.
- \param parseErrorCode \ref rapidjson::ParseErrorCode of the error
- \param offset position of the error in JSON input (\c size_t)
-
- This macros can be used as a customization point for the internal
- error handling mechanism of RapidJSON.
-
- A common usage model is to throw an exception instead of requiring the
- caller to explicitly check the \ref rapidjson::GenericReader::Parse's
- return value:
-
- \code
- #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \
- throw ParseException(parseErrorCode, #parseErrorCode, offset)
-
- #include <stdexcept> // std::runtime_error
- #include "rapidjson/error/error.h" // rapidjson::ParseResult
-
- struct ParseException : std::runtime_error, rapidjson::ParseResult {
- ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset)
- : std::runtime_error(msg), ParseResult(code, offset) {}
- };
-
- #include "rapidjson/reader.h"
- \endcode
-
- \see RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse
- */
-#ifndef RAPIDJSON_PARSE_ERROR_NORETURN
-#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \
- RAPIDJSON_MULTILINEMACRO_BEGIN \
- RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */ \
- SetParseError(parseErrorCode, offset); \
- RAPIDJSON_MULTILINEMACRO_END
-#endif
-
-/*! \def RAPIDJSON_PARSE_ERROR
- \ingroup RAPIDJSON_ERRORS
- \brief (Internal) macro to indicate and handle a parse error.
- \param parseErrorCode \ref rapidjson::ParseErrorCode of the error
- \param offset position of the error in JSON input (\c size_t)
-
- Invokes RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing.
-
- \see RAPIDJSON_PARSE_ERROR_NORETURN
- \hideinitializer
- */
-#ifndef RAPIDJSON_PARSE_ERROR
-#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \
- RAPIDJSON_MULTILINEMACRO_BEGIN \
- RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \
- RAPIDJSON_MULTILINEMACRO_END
-#endif
-
-#include "error/error.h" // ParseErrorCode, ParseResult
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// ParseFlag
-
-/*! \def RAPIDJSON_PARSE_DEFAULT_FLAGS
- \ingroup RAPIDJSON_CONFIG
- \brief User-defined kParseDefaultFlags definition.
-
- User can define this as any \c ParseFlag combinations.
-*/
-#ifndef RAPIDJSON_PARSE_DEFAULT_FLAGS
-#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags
-#endif
-
-//! Combination of parseFlags
-/*! \see Reader::Parse, Document::Parse, Document::ParseInsitu, Document::ParseStream
- */
-enum ParseFlag {
- kParseNoFlags = 0, //!< No flags are set.
- kParseInsituFlag = 1, //!< In-situ(destructive) parsing.
- kParseValidateEncodingFlag = 2, //!< Validate encoding of JSON strings.
- kParseIterativeFlag = 4, //!< Iterative(constant complexity in terms of function call stack size) parsing.
- kParseStopWhenDoneFlag = 8, //!< After parsing a complete JSON root from stream, stop further processing the rest of stream. When this flag is used, parser will not generate kParseErrorDocumentRootNotSingular error.
- kParseFullPrecisionFlag = 16, //!< Parse number in full precision (but slower).
- kParseCommentsFlag = 32, //!< Allow one-line (//) and multi-line (/**/) comments.
- kParseNumbersAsStringsFlag = 64, //!< Parse all numbers (ints/doubles) as strings.
- kParseTrailingCommasFlag = 128, //!< Allow trailing commas at the end of objects and arrays.
- kParseNanAndInfFlag = 256, //!< Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
- kParseDefaultFlags = RAPIDJSON_PARSE_DEFAULT_FLAGS //!< Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Handler
-
-/*! \class rapidjson::Handler
- \brief Concept for receiving events from GenericReader upon parsing.
- The functions return true if no error occurs. If they return false,
- the event publisher should terminate the process.
-\code
-concept Handler {
- typename Ch;
-
- bool Null();
- bool Bool(bool b);
- bool Int(int i);
- bool Uint(unsigned i);
- bool Int64(int64_t i);
- bool Uint64(uint64_t i);
- bool Double(double d);
- /// enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length)
- bool RawNumber(const Ch* str, SizeType length, bool copy);
- bool String(const Ch* str, SizeType length, bool copy);
- bool StartObject();
- bool Key(const Ch* str, SizeType length, bool copy);
- bool EndObject(SizeType memberCount);
- bool StartArray();
- bool EndArray(SizeType elementCount);
-};
-\endcode
-*/
-///////////////////////////////////////////////////////////////////////////////
-// BaseReaderHandler
-
-//! Default implementation of Handler.
-/*! This can be used as base class of any reader handler.
- \note implements Handler concept
-*/
-template<typename Encoding = UTF8<>, typename Derived = void>
-struct BaseReaderHandler {
- typedef typename Encoding::Ch Ch;
-
- typedef typename internal::SelectIf<internal::IsSame<Derived, void>, BaseReaderHandler, Derived>::Type Override;
-
- bool Default() { return true; }
- bool Null() { return static_cast<Override&>(*this).Default(); }
- bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
- bool Int(int) { return static_cast<Override&>(*this).Default(); }
- bool Uint(unsigned) { return static_cast<Override&>(*this).Default(); }
- bool Int64(int64_t) { return static_cast<Override&>(*this).Default(); }
- bool Uint64(uint64_t) { return static_cast<Override&>(*this).Default(); }
- bool Double(double) { return static_cast<Override&>(*this).Default(); }
- /// enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length)
- bool RawNumber(const Ch* str, SizeType len, bool copy) { return static_cast<Override&>(*this).String(str, len, copy); }
- bool String(const Ch*, SizeType, bool) { return static_cast<Override&>(*this).Default(); }
- bool StartObject() { return static_cast<Override&>(*this).Default(); }
- bool Key(const Ch* str, SizeType len, bool copy) { return static_cast<Override&>(*this).String(str, len, copy); }
- bool EndObject(SizeType) { return static_cast<Override&>(*this).Default(); }
- bool StartArray() { return static_cast<Override&>(*this).Default(); }
- bool EndArray(SizeType) { return static_cast<Override&>(*this).Default(); }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// StreamLocalCopy
-
-namespace internal {
-
-template<typename Stream, int = StreamTraits<Stream>::copyOptimization>
-class StreamLocalCopy;
-
-//! Do copy optimization.
-template<typename Stream>
-class StreamLocalCopy<Stream, 1> {
-public:
- StreamLocalCopy(Stream& original) : s(original), original_(original) {}
- ~StreamLocalCopy() { original_ = s; }
-
- Stream s;
-
-private:
- StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
-
- Stream& original_;
-};
-
-//! Keep reference.
-template<typename Stream>
-class StreamLocalCopy<Stream, 0> {
-public:
- StreamLocalCopy(Stream& original) : s(original) {}
-
- Stream& s;
-
-private:
- StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
-};
-
-} // namespace internal
-
-///////////////////////////////////////////////////////////////////////////////
-// SkipWhitespace
-
-//! Skip the JSON white spaces in a stream.
-/*! \param is A input stream for skipping white spaces.
- \note This function has SSE2/SSE4.2 specialization.
-*/
-template<typename InputStream>
-void SkipWhitespace(InputStream& is) {
- internal::StreamLocalCopy<InputStream> copy(is);
- InputStream& s(copy.s);
-
- typename InputStream::Ch c;
- while ((c = s.Peek()) == ' ' || c == '\n' || c == '\r' || c == '\t')
- s.Take();
-}
-
-inline const char* SkipWhitespace(const char* p, const char* end) {
- while (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
- ++p;
- return p;
-}
-
-#ifdef RAPIDJSON_SSE42
-//! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once.
-inline const char *SkipWhitespace_SIMD(const char* p) {
- // Fast return for single non-whitespace
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- // 16-byte align to the next boundary
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- // The rest of string using SIMD
- static const char whitespace[16] = " \n\r\t";
- const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
-
- for (;; p += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
- if (r != 16) // some of characters is non-whitespace
- return p + r;
- }
-}
-
-inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
- // Fast return for single non-whitespace
- if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
- ++p;
- else
- return p;
-
- // The middle of string using SIMD
- static const char whitespace[16] = " \n\r\t";
- const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
-
- for (; p <= end - 16; p += 16) {
- const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
- const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
- if (r != 16) // some of characters is non-whitespace
- return p + r;
- }
-
- return SkipWhitespace(p, end);
-}
-
-#elif defined(RAPIDJSON_SSE2)
-
-//! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once.
-inline const char *SkipWhitespace_SIMD(const char* p) {
- // Fast return for single non-whitespace
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- // 16-byte align to the next boundary
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- // The rest of string
- #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
- static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') };
- #undef C16
-
- const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
- const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
- const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
- const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
-
- for (;; p += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- __m128i x = _mm_cmpeq_epi8(s, w0);
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
- unsigned short r = static_cast<unsigned short>(~_mm_movemask_epi8(x));
- if (r != 0) { // some of characters may be non-whitespace
-#ifdef _MSC_VER // Find the index of first non-whitespace
- unsigned long offset;
- _BitScanForward(&offset, r);
- return p + offset;
-#else
- return p + __builtin_ffs(r) - 1;
-#endif
- }
- }
-}
-
-inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
- // Fast return for single non-whitespace
- if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
- ++p;
- else
- return p;
-
- // The rest of string
- #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
- static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') };
- #undef C16
-
- const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
- const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
- const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
- const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
-
- for (; p <= end - 16; p += 16) {
- const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
- __m128i x = _mm_cmpeq_epi8(s, w0);
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
- x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
- unsigned short r = static_cast<unsigned short>(~_mm_movemask_epi8(x));
- if (r != 0) { // some of characters may be non-whitespace
-#ifdef _MSC_VER // Find the index of first non-whitespace
- unsigned long offset;
- _BitScanForward(&offset, r);
- return p + offset;
-#else
- return p + __builtin_ffs(r) - 1;
-#endif
- }
- }
-
- return SkipWhitespace(p, end);
-}
-
-#elif defined(RAPIDJSON_NEON)
-
-//! Skip whitespace with ARM Neon instructions, testing 16 8-byte characters at once.
-inline const char *SkipWhitespace_SIMD(const char* p) {
- // Fast return for single non-whitespace
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- // 16-byte align to the next boundary
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
- ++p;
- else
- return p;
-
- const uint8x16_t w0 = vmovq_n_u8(' ');
- const uint8x16_t w1 = vmovq_n_u8('\n');
- const uint8x16_t w2 = vmovq_n_u8('\r');
- const uint8x16_t w3 = vmovq_n_u8('\t');
-
- for (;; p += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, w0);
- x = vorrq_u8(x, vceqq_u8(s, w1));
- x = vorrq_u8(x, vceqq_u8(s, w2));
- x = vorrq_u8(x, vceqq_u8(s, w3));
-
- x = vmvnq_u8(x); // Negate
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- if (low == 0) {
- if (high != 0) {
- int lz =__builtin_clzll(high);;
- return p + 8 + (lz >> 3);
- }
- } else {
- int lz = __builtin_clzll(low);;
- return p + (lz >> 3);
- }
- }
-}
-
-inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
- // Fast return for single non-whitespace
- if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
- ++p;
- else
- return p;
-
- const uint8x16_t w0 = vmovq_n_u8(' ');
- const uint8x16_t w1 = vmovq_n_u8('\n');
- const uint8x16_t w2 = vmovq_n_u8('\r');
- const uint8x16_t w3 = vmovq_n_u8('\t');
-
- for (; p <= end - 16; p += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, w0);
- x = vorrq_u8(x, vceqq_u8(s, w1));
- x = vorrq_u8(x, vceqq_u8(s, w2));
- x = vorrq_u8(x, vceqq_u8(s, w3));
-
- x = vmvnq_u8(x); // Negate
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- if (low == 0) {
- if (high != 0) {
- int lz = __builtin_clzll(high);
- return p + 8 + (lz >> 3);
- }
- } else {
- int lz = __builtin_clzll(low);
- return p + (lz >> 3);
- }
- }
-
- return SkipWhitespace(p, end);
-}
-
-#endif // RAPIDJSON_NEON
-
-#ifdef RAPIDJSON_SIMD
-//! Template function specialization for InsituStringStream
-template<> inline void SkipWhitespace(InsituStringStream& is) {
- is.src_ = const_cast<char*>(SkipWhitespace_SIMD(is.src_));
-}
-
-//! Template function specialization for StringStream
-template<> inline void SkipWhitespace(StringStream& is) {
- is.src_ = SkipWhitespace_SIMD(is.src_);
-}
-
-template<> inline void SkipWhitespace(EncodedInputStream<UTF8<>, MemoryStream>& is) {
- is.is_.src_ = SkipWhitespace_SIMD(is.is_.src_, is.is_.end_);
-}
-#endif // RAPIDJSON_SIMD
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericReader
-
-//! SAX-style JSON parser. Use \ref Reader for UTF8 encoding and default allocator.
-/*! GenericReader parses JSON text from a stream, and send events synchronously to an
- object implementing Handler concept.
-
- It needs to allocate a stack for storing a single decoded string during
- non-destructive parsing.
-
- For in-situ parsing, the decoded string is directly written to the source
- text string, no temporary buffer is required.
-
- A GenericReader object can be reused for parsing multiple JSON text.
-
- \tparam SourceEncoding Encoding of the input stream.
- \tparam TargetEncoding Encoding of the parse output.
- \tparam StackAllocator Allocator type for stack.
-*/
-template <typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
-class GenericReader {
-public:
- typedef typename SourceEncoding::Ch Ch; //!< SourceEncoding character type
-
- //! Constructor.
- /*! \param stackAllocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing)
- \param stackCapacity stack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing)
- */
- GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(stackAllocator, stackCapacity), parseResult_() {}
-
- //! Parse JSON text.
- /*! \tparam parseFlags Combination of \ref ParseFlag.
- \tparam InputStream Type of input stream, implementing Stream concept.
- \tparam Handler Type of handler, implementing Handler concept.
- \param is Input stream to be parsed.
- \param handler The handler to receive events.
- \return Whether the parsing is successful.
- */
- template <unsigned parseFlags, typename InputStream, typename Handler>
- ParseResult Parse(InputStream& is, Handler& handler) {
- if (parseFlags & kParseIterativeFlag)
- return IterativeParse<parseFlags>(is, handler);
-
- parseResult_.Clear();
-
- ClearStackOnExit scope(*this);
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
-
- if (RAPIDJSON_UNLIKELY(is.Peek() == '\0')) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentEmpty, is.Tell());
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
- }
- else {
- ParseValue<parseFlags>(is, handler);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
-
- if (!(parseFlags & kParseStopWhenDoneFlag)) {
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
-
- if (RAPIDJSON_UNLIKELY(is.Peek() != '\0')) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorDocumentRootNotSingular, is.Tell());
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
- }
- }
- }
-
- return parseResult_;
- }
-
- //! Parse JSON text (with \ref kParseDefaultFlags)
- /*! \tparam InputStream Type of input stream, implementing Stream concept
- \tparam Handler Type of handler, implementing Handler concept.
- \param is Input stream to be parsed.
- \param handler The handler to receive events.
- \return Whether the parsing is successful.
- */
- template <typename InputStream, typename Handler>
- ParseResult Parse(InputStream& is, Handler& handler) {
- return Parse<kParseDefaultFlags>(is, handler);
- }
-
- //! Initialize JSON text token-by-token parsing
- /*!
- */
- void IterativeParseInit() {
- parseResult_.Clear();
- state_ = IterativeParsingStartState;
- }
-
- //! Parse one token from JSON text
- /*! \tparam InputStream Type of input stream, implementing Stream concept
- \tparam Handler Type of handler, implementing Handler concept.
- \param is Input stream to be parsed.
- \param handler The handler to receive events.
- \return Whether the parsing is successful.
- */
- template <unsigned parseFlags, typename InputStream, typename Handler>
- bool IterativeParseNext(InputStream& is, Handler& handler) {
- while (RAPIDJSON_LIKELY(is.Peek() != '\0')) {
- SkipWhitespaceAndComments<parseFlags>(is);
-
- Token t = Tokenize(is.Peek());
- IterativeParsingState n = Predict(state_, t);
- IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler);
-
- // If we've finished or hit an error...
- if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) {
- // Report errors.
- if (d == IterativeParsingErrorState) {
- HandleError(state_, is);
- return false;
- }
-
- // Transition to the finish state.
- RAPIDJSON_ASSERT(d == IterativeParsingFinishState);
- state_ = d;
-
- // If StopWhenDone is not set...
- if (!(parseFlags & kParseStopWhenDoneFlag)) {
- // ... and extra non-whitespace data is found...
- SkipWhitespaceAndComments<parseFlags>(is);
- if (is.Peek() != '\0') {
- // ... this is considered an error.
- HandleError(state_, is);
- return false;
- }
- }
-
- // Success! We are done!
- return true;
- }
-
- // Transition to the new state.
- state_ = d;
-
- // If we parsed anything other than a delimiter, we invoked the handler, so we can return true now.
- if (!IsIterativeParsingDelimiterState(n))
- return true;
- }
-
- // We reached the end of file.
- stack_.Clear();
-
- if (state_ != IterativeParsingFinishState) {
- HandleError(state_, is);
- return false;
- }
-
- return true;
- }
-
- //! Check if token-by-token parsing JSON text is complete
- /*! \return Whether the JSON has been fully decoded.
- */
- RAPIDJSON_FORCEINLINE bool IterativeParseComplete() {
- return IsIterativeParsingCompleteState(state_);
- }
-
- //! Whether a parse error has occured in the last parsing.
- bool HasParseError() const { return parseResult_.IsError(); }
-
- //! Get the \ref ParseErrorCode of last parsing.
- ParseErrorCode GetParseErrorCode() const { return parseResult_.Code(); }
-
- //! Get the position of last parsing error in input, 0 otherwise.
- size_t GetErrorOffset() const { return parseResult_.Offset(); }
-
-protected:
- void SetParseError(ParseErrorCode code, size_t offset) { parseResult_.Set(code, offset); }
-
-private:
- // Prohibit copy constructor & assignment operator.
- GenericReader(const GenericReader&);
- GenericReader& operator=(const GenericReader&);
-
- void ClearStack() { stack_.Clear(); }
-
- // clear stack on any exit from ParseStream, e.g. due to exception
- struct ClearStackOnExit {
- explicit ClearStackOnExit(GenericReader& r) : r_(r) {}
- ~ClearStackOnExit() { r_.ClearStack(); }
- private:
- GenericReader& r_;
- ClearStackOnExit(const ClearStackOnExit&);
- ClearStackOnExit& operator=(const ClearStackOnExit&);
- };
-
- template<unsigned parseFlags, typename InputStream>
- void SkipWhitespaceAndComments(InputStream& is) {
- SkipWhitespace(is);
-
- if (parseFlags & kParseCommentsFlag) {
- while (RAPIDJSON_UNLIKELY(Consume(is, '/'))) {
- if (Consume(is, '*')) {
- while (true) {
- if (RAPIDJSON_UNLIKELY(is.Peek() == '\0'))
- RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell());
- else if (Consume(is, '*')) {
- if (Consume(is, '/'))
- break;
- }
- else
- is.Take();
- }
- }
- else if (RAPIDJSON_LIKELY(Consume(is, '/')))
- while (is.Peek() != '\0' && is.Take() != '\n') {}
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell());
-
- SkipWhitespace(is);
- }
- }
- }
-
- // Parse object: { string : value, ... }
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseObject(InputStream& is, Handler& handler) {
- RAPIDJSON_ASSERT(is.Peek() == '{');
- is.Take(); // Skip '{'
-
- if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- if (Consume(is, '}')) {
- if (RAPIDJSON_UNLIKELY(!handler.EndObject(0))) // empty object
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- return;
- }
-
- for (SizeType memberCount = 0;;) {
- if (RAPIDJSON_UNLIKELY(is.Peek() != '"'))
- RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell());
-
- ParseString<parseFlags>(is, handler, true);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- if (RAPIDJSON_UNLIKELY(!Consume(is, ':')))
- RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell());
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- ParseValue<parseFlags>(is, handler);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- ++memberCount;
-
- switch (is.Peek()) {
- case ',':
- is.Take();
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- break;
- case '}':
- is.Take();
- if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- return;
- default:
- RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); break; // This useless break is only for making warning and coverage happy
- }
-
- if (parseFlags & kParseTrailingCommasFlag) {
- if (is.Peek() == '}') {
- if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- is.Take();
- return;
- }
- }
- }
- }
-
- // Parse array: [ value, ... ]
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseArray(InputStream& is, Handler& handler) {
- RAPIDJSON_ASSERT(is.Peek() == '[');
- is.Take(); // Skip '['
-
- if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- if (Consume(is, ']')) {
- if (RAPIDJSON_UNLIKELY(!handler.EndArray(0))) // empty array
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- return;
- }
-
- for (SizeType elementCount = 0;;) {
- ParseValue<parseFlags>(is, handler);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- ++elementCount;
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
-
- if (Consume(is, ',')) {
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- }
- else if (Consume(is, ']')) {
- if (RAPIDJSON_UNLIKELY(!handler.EndArray(elementCount)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- return;
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell());
-
- if (parseFlags & kParseTrailingCommasFlag) {
- if (is.Peek() == ']') {
- if (RAPIDJSON_UNLIKELY(!handler.EndArray(elementCount)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- is.Take();
- return;
- }
- }
- }
- }
-
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseNull(InputStream& is, Handler& handler) {
- RAPIDJSON_ASSERT(is.Peek() == 'n');
- is.Take();
-
- if (RAPIDJSON_LIKELY(Consume(is, 'u') && Consume(is, 'l') && Consume(is, 'l'))) {
- if (RAPIDJSON_UNLIKELY(!handler.Null()))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
- }
-
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseTrue(InputStream& is, Handler& handler) {
- RAPIDJSON_ASSERT(is.Peek() == 't');
- is.Take();
-
- if (RAPIDJSON_LIKELY(Consume(is, 'r') && Consume(is, 'u') && Consume(is, 'e'))) {
- if (RAPIDJSON_UNLIKELY(!handler.Bool(true)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
- }
-
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseFalse(InputStream& is, Handler& handler) {
- RAPIDJSON_ASSERT(is.Peek() == 'f');
- is.Take();
-
- if (RAPIDJSON_LIKELY(Consume(is, 'a') && Consume(is, 'l') && Consume(is, 's') && Consume(is, 'e'))) {
- if (RAPIDJSON_UNLIKELY(!handler.Bool(false)))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
- }
-
- template<typename InputStream>
- RAPIDJSON_FORCEINLINE static bool Consume(InputStream& is, typename InputStream::Ch expect) {
- if (RAPIDJSON_LIKELY(is.Peek() == expect)) {
- is.Take();
- return true;
- }
- else
- return false;
- }
-
- // Helper function to parse four hexidecimal digits in \uXXXX in ParseString().
- template<typename InputStream>
- unsigned ParseHex4(InputStream& is, size_t escapeOffset) {
- unsigned codepoint = 0;
- for (int i = 0; i < 4; i++) {
- Ch c = is.Peek();
- codepoint <<= 4;
- codepoint += static_cast<unsigned>(c);
- if (c >= '0' && c <= '9')
- codepoint -= '0';
- else if (c >= 'A' && c <= 'F')
- codepoint -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- codepoint -= 'a' - 10;
- else {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorStringUnicodeEscapeInvalidHex, escapeOffset);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
- }
- is.Take();
- }
- return codepoint;
- }
-
- template <typename CharType>
- class StackStream {
- public:
- typedef CharType Ch;
-
- StackStream(internal::Stack<StackAllocator>& stack) : stack_(stack), length_(0) {}
- RAPIDJSON_FORCEINLINE void Put(Ch c) {
- *stack_.template Push<Ch>() = c;
- ++length_;
- }
-
- RAPIDJSON_FORCEINLINE void* Push(SizeType count) {
- length_ += count;
- return stack_.template Push<Ch>(count);
- }
-
- size_t Length() const { return length_; }
-
- Ch* Pop() {
- return stack_.template Pop<Ch>(length_);
- }
-
- private:
- StackStream(const StackStream&);
- StackStream& operator=(const StackStream&);
-
- internal::Stack<StackAllocator>& stack_;
- SizeType length_;
- };
-
- // Parse string and generate String event. Different code paths for kParseInsituFlag.
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseString(InputStream& is, Handler& handler, bool isKey = false) {
- internal::StreamLocalCopy<InputStream> copy(is);
- InputStream& s(copy.s);
-
- RAPIDJSON_ASSERT(s.Peek() == '\"');
- s.Take(); // Skip '\"'
-
- bool success = false;
- if (parseFlags & kParseInsituFlag) {
- typename InputStream::Ch *head = s.PutBegin();
- ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- size_t length = s.PutEnd(head) - 1;
- RAPIDJSON_ASSERT(length <= 0xFFFFFFFF);
- const typename TargetEncoding::Ch* const str = reinterpret_cast<typename TargetEncoding::Ch*>(head);
- success = (isKey ? handler.Key(str, SizeType(length), false) : handler.String(str, SizeType(length), false));
- }
- else {
- StackStream<typename TargetEncoding::Ch> stackStream(stack_);
- ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(s, stackStream);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- SizeType length = static_cast<SizeType>(stackStream.Length()) - 1;
- const typename TargetEncoding::Ch* const str = stackStream.Pop();
- success = (isKey ? handler.Key(str, length, true) : handler.String(str, length, true));
- }
- if (RAPIDJSON_UNLIKELY(!success))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, s.Tell());
- }
-
- // Parse string to an output is
- // This function handles the prefix/suffix double quotes, escaping, and optional encoding validation.
- template<unsigned parseFlags, typename SEncoding, typename TEncoding, typename InputStream, typename OutputStream>
- RAPIDJSON_FORCEINLINE void ParseStringToStream(InputStream& is, OutputStream& os) {
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- static const char escape[256] = {
- Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/',
- Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0,
- 0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0,
- 0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16
- };
-#undef Z16
-//!@endcond
-
- for (;;) {
- // Scan and copy string before "\\\"" or < 0x20. This is an optional optimzation.
- if (!(parseFlags & kParseValidateEncodingFlag))
- ScanCopyUnescapedString(is, os);
-
- Ch c = is.Peek();
- if (RAPIDJSON_UNLIKELY(c == '\\')) { // Escape
- size_t escapeOffset = is.Tell(); // For invalid escaping, report the inital '\\' as error offset
- is.Take();
- Ch e = is.Peek();
- if ((sizeof(Ch) == 1 || unsigned(e) < 256) && RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)])) {
- is.Take();
- os.Put(static_cast<typename TEncoding::Ch>(escape[static_cast<unsigned char>(e)]));
- }
- else if (RAPIDJSON_LIKELY(e == 'u')) { // Unicode
- is.Take();
- unsigned codepoint = ParseHex4(is, escapeOffset);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- if (RAPIDJSON_UNLIKELY(codepoint >= 0xD800 && codepoint <= 0xDBFF)) {
- // Handle UTF-16 surrogate pair
- if (RAPIDJSON_UNLIKELY(!Consume(is, '\\') || !Consume(is, 'u')))
- RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset);
- unsigned codepoint2 = ParseHex4(is, escapeOffset);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
- if (RAPIDJSON_UNLIKELY(codepoint2 < 0xDC00 || codepoint2 > 0xDFFF))
- RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset);
- codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
- }
- TEncoding::Encode(os, codepoint);
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorStringEscapeInvalid, escapeOffset);
- }
- else if (RAPIDJSON_UNLIKELY(c == '"')) { // Closing double quote
- is.Take();
- os.Put('\0'); // null-terminate the string
- return;
- }
- else if (RAPIDJSON_UNLIKELY(static_cast<unsigned>(c) < 0x20)) { // RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
- if (c == '\0')
- RAPIDJSON_PARSE_ERROR(kParseErrorStringMissQuotationMark, is.Tell());
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, is.Tell());
- }
- else {
- size_t offset = is.Tell();
- if (RAPIDJSON_UNLIKELY((parseFlags & kParseValidateEncodingFlag ?
- !Transcoder<SEncoding, TEncoding>::Validate(is, os) :
- !Transcoder<SEncoding, TEncoding>::Transcode(is, os))))
- RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, offset);
- }
- }
- }
-
- template<typename InputStream, typename OutputStream>
- static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream&, OutputStream&) {
- // Do nothing for generic version
- }
-
-#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
- // StringStream -> StackStream<char>
- static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(StringStream& is, StackStream<char>& os) {
- const char* p = is.src_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = p;
- return;
- }
- else
- os.Put(*p++);
-
- // The rest of string using SIMD
- static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
- static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
- static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
- const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
- const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
- const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
-
- for (;; p += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- const __m128i t1 = _mm_cmpeq_epi8(s, dq);
- const __m128i t2 = _mm_cmpeq_epi8(s, bs);
- const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
- const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
- unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
- if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
- SizeType length;
- #ifdef _MSC_VER // Find the index of first escaped
- unsigned long offset;
- _BitScanForward(&offset, r);
- length = offset;
- #else
- length = static_cast<SizeType>(__builtin_ffs(r) - 1);
- #endif
- if (length != 0) {
- char* q = reinterpret_cast<char*>(os.Push(length));
- for (size_t i = 0; i < length; i++)
- q[i] = p[i];
-
- p += length;
- }
- break;
- }
- _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);
- }
-
- is.src_ = p;
- }
-
- // InsituStringStream -> InsituStringStream
- static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InsituStringStream& is, InsituStringStream& os) {
- RAPIDJSON_ASSERT(&is == &os);
- (void)os;
-
- if (is.src_ == is.dst_) {
- SkipUnescapedString(is);
- return;
- }
-
- char* p = is.src_;
- char *q = is.dst_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = p;
- is.dst_ = q;
- return;
- }
- else
- *q++ = *p++;
-
- // The rest of string using SIMD
- static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
- static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
- static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
- const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
- const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
- const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
-
- for (;; p += 16, q += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- const __m128i t1 = _mm_cmpeq_epi8(s, dq);
- const __m128i t2 = _mm_cmpeq_epi8(s, bs);
- const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
- const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
- unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
- if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
- size_t length;
-#ifdef _MSC_VER // Find the index of first escaped
- unsigned long offset;
- _BitScanForward(&offset, r);
- length = offset;
-#else
- length = static_cast<size_t>(__builtin_ffs(r) - 1);
-#endif
- for (const char* pend = p + length; p != pend; )
- *q++ = *p++;
- break;
- }
- _mm_storeu_si128(reinterpret_cast<__m128i *>(q), s);
- }
-
- is.src_ = p;
- is.dst_ = q;
- }
-
- // When read/write pointers are the same for insitu stream, just skip unescaped characters
- static RAPIDJSON_FORCEINLINE void SkipUnescapedString(InsituStringStream& is) {
- RAPIDJSON_ASSERT(is.src_ == is.dst_);
- char* p = is.src_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- for (; p != nextAligned; p++)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = is.dst_ = p;
- return;
- }
-
- // The rest of string using SIMD
- static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
- static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
- static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
- const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
- const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
- const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
-
- for (;; p += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- const __m128i t1 = _mm_cmpeq_epi8(s, dq);
- const __m128i t2 = _mm_cmpeq_epi8(s, bs);
- const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
- const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
- unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
- if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
- size_t length;
-#ifdef _MSC_VER // Find the index of first escaped
- unsigned long offset;
- _BitScanForward(&offset, r);
- length = offset;
-#else
- length = static_cast<size_t>(__builtin_ffs(r) - 1);
-#endif
- p += length;
- break;
- }
- }
-
- is.src_ = is.dst_ = p;
- }
-#elif defined(RAPIDJSON_NEON)
- // StringStream -> StackStream<char>
- static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(StringStream& is, StackStream<char>& os) {
- const char* p = is.src_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = p;
- return;
- }
- else
- os.Put(*p++);
-
- // The rest of string using SIMD
- const uint8x16_t s0 = vmovq_n_u8('"');
- const uint8x16_t s1 = vmovq_n_u8('\\');
- const uint8x16_t s2 = vmovq_n_u8('\b');
- const uint8x16_t s3 = vmovq_n_u8(32);
-
- for (;; p += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, s0);
- x = vorrq_u8(x, vceqq_u8(s, s1));
- x = vorrq_u8(x, vceqq_u8(s, s2));
- x = vorrq_u8(x, vcltq_u8(s, s3));
-
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- SizeType length = 0;
- bool escaped = false;
- if (low == 0) {
- if (high != 0) {
- unsigned lz = (unsigned)__builtin_clzll(high);;
- length = 8 + (lz >> 3);
- escaped = true;
- }
- } else {
- unsigned lz = (unsigned)__builtin_clzll(low);;
- length = lz >> 3;
- escaped = true;
- }
- if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
- if (length != 0) {
- char* q = reinterpret_cast<char*>(os.Push(length));
- for (size_t i = 0; i < length; i++)
- q[i] = p[i];
-
- p += length;
- }
- break;
- }
- vst1q_u8(reinterpret_cast<uint8_t *>(os.Push(16)), s);
- }
-
- is.src_ = p;
- }
-
- // InsituStringStream -> InsituStringStream
- static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InsituStringStream& is, InsituStringStream& os) {
- RAPIDJSON_ASSERT(&is == &os);
- (void)os;
-
- if (is.src_ == is.dst_) {
- SkipUnescapedString(is);
- return;
- }
-
- char* p = is.src_;
- char *q = is.dst_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- while (p != nextAligned)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = p;
- is.dst_ = q;
- return;
- }
- else
- *q++ = *p++;
-
- // The rest of string using SIMD
- const uint8x16_t s0 = vmovq_n_u8('"');
- const uint8x16_t s1 = vmovq_n_u8('\\');
- const uint8x16_t s2 = vmovq_n_u8('\b');
- const uint8x16_t s3 = vmovq_n_u8(32);
-
- for (;; p += 16, q += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, s0);
- x = vorrq_u8(x, vceqq_u8(s, s1));
- x = vorrq_u8(x, vceqq_u8(s, s2));
- x = vorrq_u8(x, vcltq_u8(s, s3));
-
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- SizeType length = 0;
- bool escaped = false;
- if (low == 0) {
- if (high != 0) {
- unsigned lz = (unsigned)__builtin_clzll(high);
- length = 8 + (lz >> 3);
- escaped = true;
- }
- } else {
- unsigned lz = (unsigned)__builtin_clzll(low);
- length = lz >> 3;
- escaped = true;
- }
- if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
- for (const char* pend = p + length; p != pend; ) {
- *q++ = *p++;
- }
- break;
- }
- vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
- }
-
- is.src_ = p;
- is.dst_ = q;
- }
-
- // When read/write pointers are the same for insitu stream, just skip unescaped characters
- static RAPIDJSON_FORCEINLINE void SkipUnescapedString(InsituStringStream& is) {
- RAPIDJSON_ASSERT(is.src_ == is.dst_);
- char* p = is.src_;
-
- // Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- for (; p != nextAligned; p++)
- if (RAPIDJSON_UNLIKELY(*p == '\"') || RAPIDJSON_UNLIKELY(*p == '\\') || RAPIDJSON_UNLIKELY(static_cast<unsigned>(*p) < 0x20)) {
- is.src_ = is.dst_ = p;
- return;
- }
-
- // The rest of string using SIMD
- const uint8x16_t s0 = vmovq_n_u8('"');
- const uint8x16_t s1 = vmovq_n_u8('\\');
- const uint8x16_t s2 = vmovq_n_u8('\b');
- const uint8x16_t s3 = vmovq_n_u8(32);
-
- for (;; p += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, s0);
- x = vorrq_u8(x, vceqq_u8(s, s1));
- x = vorrq_u8(x, vceqq_u8(s, s2));
- x = vorrq_u8(x, vcltq_u8(s, s3));
-
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- if (low == 0) {
- if (high != 0) {
- int lz = __builtin_clzll(high);
- p += 8 + (lz >> 3);
- break;
- }
- } else {
- int lz = __builtin_clzll(low);
- p += lz >> 3;
- break;
- }
- }
-
- is.src_ = is.dst_ = p;
- }
-#endif // RAPIDJSON_NEON
-
- template<typename InputStream, bool backup, bool pushOnTake>
- class NumberStream;
-
- template<typename InputStream>
- class NumberStream<InputStream, false, false> {
- public:
- typedef typename InputStream::Ch Ch;
-
- NumberStream(GenericReader& reader, InputStream& s) : is(s) { (void)reader; }
-
- RAPIDJSON_FORCEINLINE Ch Peek() const { return is.Peek(); }
- RAPIDJSON_FORCEINLINE Ch TakePush() { return is.Take(); }
- RAPIDJSON_FORCEINLINE Ch Take() { return is.Take(); }
- RAPIDJSON_FORCEINLINE void Push(char) {}
-
- size_t Tell() { return is.Tell(); }
- size_t Length() { return 0; }
- const char* Pop() { return 0; }
-
- protected:
- NumberStream& operator=(const NumberStream&);
-
- InputStream& is;
- };
-
- template<typename InputStream>
- class NumberStream<InputStream, true, false> : public NumberStream<InputStream, false, false> {
- typedef NumberStream<InputStream, false, false> Base;
- public:
- NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is), stackStream(reader.stack_) {}
-
- RAPIDJSON_FORCEINLINE Ch TakePush() {
- stackStream.Put(static_cast<char>(Base::is.Peek()));
- return Base::is.Take();
- }
-
- RAPIDJSON_FORCEINLINE void Push(char c) {
- stackStream.Put(c);
- }
-
- size_t Length() { return stackStream.Length(); }
-
- const char* Pop() {
- stackStream.Put('\0');
- return stackStream.Pop();
- }
-
- private:
- StackStream<char> stackStream;
- };
-
- template<typename InputStream>
- class NumberStream<InputStream, true, true> : public NumberStream<InputStream, true, false> {
- typedef NumberStream<InputStream, true, false> Base;
- public:
- NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is) {}
-
- RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); }
- };
-
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseNumber(InputStream& is, Handler& handler) {
- internal::StreamLocalCopy<InputStream> copy(is);
- NumberStream<InputStream,
- ((parseFlags & kParseNumbersAsStringsFlag) != 0) ?
- ((parseFlags & kParseInsituFlag) == 0) :
- ((parseFlags & kParseFullPrecisionFlag) != 0),
- (parseFlags & kParseNumbersAsStringsFlag) != 0 &&
- (parseFlags & kParseInsituFlag) == 0> s(*this, copy.s);
-
- size_t startOffset = s.Tell();
- double d = 0.0;
- bool useNanOrInf = false;
-
- // Parse minus
- bool minus = Consume(s, '-');
-
- // Parse int: zero / ( digit1-9 *DIGIT )
- unsigned i = 0;
- uint64_t i64 = 0;
- bool use64bit = false;
- int significandDigit = 0;
- if (RAPIDJSON_UNLIKELY(s.Peek() == '0')) {
- i = 0;
- s.TakePush();
- }
- else if (RAPIDJSON_LIKELY(s.Peek() >= '1' && s.Peek() <= '9')) {
- i = static_cast<unsigned>(s.TakePush() - '0');
-
- if (minus)
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (RAPIDJSON_UNLIKELY(i >= 214748364)) { // 2^31 = 2147483648
- if (RAPIDJSON_LIKELY(i != 214748364 || s.Peek() > '8')) {
- i64 = i;
- use64bit = true;
- break;
- }
- }
- i = i * 10 + static_cast<unsigned>(s.TakePush() - '0');
- significandDigit++;
- }
- else
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (RAPIDJSON_UNLIKELY(i >= 429496729)) { // 2^32 - 1 = 4294967295
- if (RAPIDJSON_LIKELY(i != 429496729 || s.Peek() > '5')) {
- i64 = i;
- use64bit = true;
- break;
- }
- }
- i = i * 10 + static_cast<unsigned>(s.TakePush() - '0');
- significandDigit++;
- }
- }
- // Parse NaN or Infinity here
- else if ((parseFlags & kParseNanAndInfFlag) && RAPIDJSON_LIKELY((s.Peek() == 'I' || s.Peek() == 'N'))) {
- if (Consume(s, 'N')) {
- if (Consume(s, 'a') && Consume(s, 'N')) {
- d = std::numeric_limits<double>::quiet_NaN();
- useNanOrInf = true;
- }
- }
- else if (RAPIDJSON_LIKELY(Consume(s, 'I'))) {
- if (Consume(s, 'n') && Consume(s, 'f')) {
- d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
- useNanOrInf = true;
-
- if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n')
- && Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y')))) {
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
- }
- }
- }
-
- if (RAPIDJSON_UNLIKELY(!useNanOrInf)) {
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
- }
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
-
- // Parse 64bit int
- bool useDouble = false;
- if (use64bit) {
- if (minus)
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (RAPIDJSON_UNLIKELY(i64 >= RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC))) // 2^63 = 9223372036854775808
- if (RAPIDJSON_LIKELY(i64 != RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC) || s.Peek() > '8')) {
- d = static_cast<double>(i64);
- useDouble = true;
- break;
- }
- i64 = i64 * 10 + static_cast<unsigned>(s.TakePush() - '0');
- significandDigit++;
- }
- else
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (RAPIDJSON_UNLIKELY(i64 >= RAPIDJSON_UINT64_C2(0x19999999, 0x99999999))) // 2^64 - 1 = 18446744073709551615
- if (RAPIDJSON_LIKELY(i64 != RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || s.Peek() > '5')) {
- d = static_cast<double>(i64);
- useDouble = true;
- break;
- }
- i64 = i64 * 10 + static_cast<unsigned>(s.TakePush() - '0');
- significandDigit++;
- }
- }
-
- // Force double for big integer
- if (useDouble) {
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (RAPIDJSON_UNLIKELY(d >= 1.7976931348623157e307)) // DBL_MAX / 10.0
- RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
- d = d * 10 + (s.TakePush() - '0');
- }
- }
-
- // Parse frac = decimal-point 1*DIGIT
- int expFrac = 0;
- size_t decimalPosition;
- if (Consume(s, '.')) {
- decimalPosition = s.Length();
-
- if (RAPIDJSON_UNLIKELY(!(s.Peek() >= '0' && s.Peek() <= '9')))
- RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissFraction, s.Tell());
-
- if (!useDouble) {
-#if RAPIDJSON_64BIT
- // Use i64 to store significand in 64-bit architecture
- if (!use64bit)
- i64 = i;
-
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (i64 > RAPIDJSON_UINT64_C2(0x1FFFFF, 0xFFFFFFFF)) // 2^53 - 1 for fast path
- break;
- else {
- i64 = i64 * 10 + static_cast<unsigned>(s.TakePush() - '0');
- --expFrac;
- if (i64 != 0)
- significandDigit++;
- }
- }
-
- d = static_cast<double>(i64);
-#else
- // Use double to store significand in 32-bit architecture
- d = static_cast<double>(use64bit ? i64 : i);
-#endif
- useDouble = true;
- }
-
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- if (significandDigit < 17) {
- d = d * 10.0 + (s.TakePush() - '0');
- --expFrac;
- if (RAPIDJSON_LIKELY(d > 0.0))
- significandDigit++;
- }
- else
- s.TakePush();
- }
- }
- else
- decimalPosition = s.Length(); // decimal position at the end of integer.
-
- // Parse exp = e [ minus / plus ] 1*DIGIT
- int exp = 0;
- if (Consume(s, 'e') || Consume(s, 'E')) {
- if (!useDouble) {
- d = static_cast<double>(use64bit ? i64 : i);
- useDouble = true;
- }
-
- bool expMinus = false;
- if (Consume(s, '+'))
- ;
- else if (Consume(s, '-'))
- expMinus = true;
-
- if (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- exp = static_cast<int>(s.Take() - '0');
- if (expMinus) {
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- exp = exp * 10 + static_cast<int>(s.Take() - '0');
- if (exp >= 214748364) { // Issue #313: prevent overflow exponent
- while (RAPIDJSON_UNLIKELY(s.Peek() >= '0' && s.Peek() <= '9')) // Consume the rest of exponent
- s.Take();
- }
- }
- }
- else { // positive exp
- int maxExp = 308 - expFrac;
- while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
- exp = exp * 10 + static_cast<int>(s.Take() - '0');
- if (RAPIDJSON_UNLIKELY(exp > maxExp))
- RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
- }
- }
- }
- else
- RAPIDJSON_PARSE_ERROR(kParseErrorNumberMissExponent, s.Tell());
-
- if (expMinus)
- exp = -exp;
- }
-
- // Finish parsing, call event according to the type of number.
- bool cont = true;
-
- if (parseFlags & kParseNumbersAsStringsFlag) {
- if (parseFlags & kParseInsituFlag) {
- s.Pop(); // Pop stack no matter if it will be used or not.
- typename InputStream::Ch* head = is.PutBegin();
- const size_t length = s.Tell() - startOffset;
- RAPIDJSON_ASSERT(length <= 0xFFFFFFFF);
- // unable to insert the \0 character here, it will erase the comma after this number
- const typename TargetEncoding::Ch* const str = reinterpret_cast<typename TargetEncoding::Ch*>(head);
- cont = handler.RawNumber(str, SizeType(length), false);
- }
- else {
- SizeType numCharsToCopy = static_cast<SizeType>(s.Length());
- StringStream srcStream(s.Pop());
- StackStream<typename TargetEncoding::Ch> dstStream(stack_);
- while (numCharsToCopy--) {
- Transcoder<UTF8<>, TargetEncoding>::Transcode(srcStream, dstStream);
- }
- dstStream.Put('\0');
- const typename TargetEncoding::Ch* str = dstStream.Pop();
- const SizeType length = static_cast<SizeType>(dstStream.Length()) - 1;
- cont = handler.RawNumber(str, SizeType(length), true);
- }
- }
- else {
- size_t length = s.Length();
- const char* decimal = s.Pop(); // Pop stack no matter if it will be used or not.
-
- if (useDouble) {
- int p = exp + expFrac;
- if (parseFlags & kParseFullPrecisionFlag)
- d = internal::StrtodFullPrecision(d, p, decimal, length, decimalPosition, exp);
- else
- d = internal::StrtodNormalPrecision(d, p);
-
- cont = handler.Double(minus ? -d : d);
- }
- else if (useNanOrInf) {
- cont = handler.Double(d);
- }
- else {
- if (use64bit) {
- if (minus)
- cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
- else
- cont = handler.Uint64(i64);
- }
- else {
- if (minus)
- cont = handler.Int(static_cast<int32_t>(~i + 1));
- else
- cont = handler.Uint(i);
- }
- }
- }
- if (RAPIDJSON_UNLIKELY(!cont))
- RAPIDJSON_PARSE_ERROR(kParseErrorTermination, startOffset);
- }
-
- // Parse any JSON value
- template<unsigned parseFlags, typename InputStream, typename Handler>
- void ParseValue(InputStream& is, Handler& handler) {
- switch (is.Peek()) {
- case 'n': ParseNull <parseFlags>(is, handler); break;
- case 't': ParseTrue <parseFlags>(is, handler); break;
- case 'f': ParseFalse <parseFlags>(is, handler); break;
- case '"': ParseString<parseFlags>(is, handler); break;
- case '{': ParseObject<parseFlags>(is, handler); break;
- case '[': ParseArray <parseFlags>(is, handler); break;
- default :
- ParseNumber<parseFlags>(is, handler);
- break;
-
- }
- }
-
- // Iterative Parsing
-
- // States
- enum IterativeParsingState {
- IterativeParsingFinishState = 0, // sink states at top
- IterativeParsingErrorState, // sink states at top
- IterativeParsingStartState,
-
- // Object states
- IterativeParsingObjectInitialState,
- IterativeParsingMemberKeyState,
- IterativeParsingMemberValueState,
- IterativeParsingObjectFinishState,
-
- // Array states
- IterativeParsingArrayInitialState,
- IterativeParsingElementState,
- IterativeParsingArrayFinishState,
-
- // Single value state
- IterativeParsingValueState,
-
- // Delimiter states (at bottom)
- IterativeParsingElementDelimiterState,
- IterativeParsingMemberDelimiterState,
- IterativeParsingKeyValueDelimiterState,
-
- cIterativeParsingStateCount
- };
-
- // Tokens
- enum Token {
- LeftBracketToken = 0,
- RightBracketToken,
-
- LeftCurlyBracketToken,
- RightCurlyBracketToken,
-
- CommaToken,
- ColonToken,
-
- StringToken,
- FalseToken,
- TrueToken,
- NullToken,
- NumberToken,
-
- kTokenCount
- };
-
- RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) {
-
-//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
-#define N NumberToken
-#define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N
- // Maps from ASCII to Token
- static const unsigned char tokenMap[256] = {
- N16, // 00~0F
- N16, // 10~1F
- N, N, StringToken, N, N, N, N, N, N, N, N, N, CommaToken, N, N, N, // 20~2F
- N, N, N, N, N, N, N, N, N, N, ColonToken, N, N, N, N, N, // 30~3F
- N16, // 40~4F
- N, N, N, N, N, N, N, N, N, N, N, LeftBracketToken, N, RightBracketToken, N, N, // 50~5F
- N, N, N, N, N, N, FalseToken, N, N, N, N, N, N, N, NullToken, N, // 60~6F
- N, N, N, N, TrueToken, N, N, N, N, N, N, LeftCurlyBracketToken, N, RightCurlyBracketToken, N, N, // 70~7F
- N16, N16, N16, N16, N16, N16, N16, N16 // 80~FF
- };
-#undef N
-#undef N16
-//!@endcond
-
- if (sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
- return static_cast<Token>(tokenMap[static_cast<unsigned char>(c)]);
- else
- return NumberToken;
- }
-
- RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) {
- // current state x one lookahead token -> new state
- static const char G[cIterativeParsingStateCount][kTokenCount] = {
- // Finish(sink state)
- {
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState
- },
- // Error(sink state)
- {
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState
- },
- // Start
- {
- IterativeParsingArrayInitialState, // Left bracket
- IterativeParsingErrorState, // Right bracket
- IterativeParsingObjectInitialState, // Left curly bracket
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingValueState, // String
- IterativeParsingValueState, // False
- IterativeParsingValueState, // True
- IterativeParsingValueState, // Null
- IterativeParsingValueState // Number
- },
- // ObjectInitial
- {
- IterativeParsingErrorState, // Left bracket
- IterativeParsingErrorState, // Right bracket
- IterativeParsingErrorState, // Left curly bracket
- IterativeParsingObjectFinishState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingMemberKeyState, // String
- IterativeParsingErrorState, // False
- IterativeParsingErrorState, // True
- IterativeParsingErrorState, // Null
- IterativeParsingErrorState // Number
- },
- // MemberKey
- {
- IterativeParsingErrorState, // Left bracket
- IterativeParsingErrorState, // Right bracket
- IterativeParsingErrorState, // Left curly bracket
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingKeyValueDelimiterState, // Colon
- IterativeParsingErrorState, // String
- IterativeParsingErrorState, // False
- IterativeParsingErrorState, // True
- IterativeParsingErrorState, // Null
- IterativeParsingErrorState // Number
- },
- // MemberValue
- {
- IterativeParsingErrorState, // Left bracket
- IterativeParsingErrorState, // Right bracket
- IterativeParsingErrorState, // Left curly bracket
- IterativeParsingObjectFinishState, // Right curly bracket
- IterativeParsingMemberDelimiterState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingErrorState, // String
- IterativeParsingErrorState, // False
- IterativeParsingErrorState, // True
- IterativeParsingErrorState, // Null
- IterativeParsingErrorState // Number
- },
- // ObjectFinish(sink state)
- {
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState
- },
- // ArrayInitial
- {
- IterativeParsingArrayInitialState, // Left bracket(push Element state)
- IterativeParsingArrayFinishState, // Right bracket
- IterativeParsingObjectInitialState, // Left curly bracket(push Element state)
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingElementState, // String
- IterativeParsingElementState, // False
- IterativeParsingElementState, // True
- IterativeParsingElementState, // Null
- IterativeParsingElementState // Number
- },
- // Element
- {
- IterativeParsingErrorState, // Left bracket
- IterativeParsingArrayFinishState, // Right bracket
- IterativeParsingErrorState, // Left curly bracket
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingElementDelimiterState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingErrorState, // String
- IterativeParsingErrorState, // False
- IterativeParsingErrorState, // True
- IterativeParsingErrorState, // Null
- IterativeParsingErrorState // Number
- },
- // ArrayFinish(sink state)
- {
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState
- },
- // Single Value (sink state)
- {
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
- IterativeParsingErrorState
- },
- // ElementDelimiter
- {
- IterativeParsingArrayInitialState, // Left bracket(push Element state)
- IterativeParsingArrayFinishState, // Right bracket
- IterativeParsingObjectInitialState, // Left curly bracket(push Element state)
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingElementState, // String
- IterativeParsingElementState, // False
- IterativeParsingElementState, // True
- IterativeParsingElementState, // Null
- IterativeParsingElementState // Number
- },
- // MemberDelimiter
- {
- IterativeParsingErrorState, // Left bracket
- IterativeParsingErrorState, // Right bracket
- IterativeParsingErrorState, // Left curly bracket
- IterativeParsingObjectFinishState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingMemberKeyState, // String
- IterativeParsingErrorState, // False
- IterativeParsingErrorState, // True
- IterativeParsingErrorState, // Null
- IterativeParsingErrorState // Number
- },
- // KeyValueDelimiter
- {
- IterativeParsingArrayInitialState, // Left bracket(push MemberValue state)
- IterativeParsingErrorState, // Right bracket
- IterativeParsingObjectInitialState, // Left curly bracket(push MemberValue state)
- IterativeParsingErrorState, // Right curly bracket
- IterativeParsingErrorState, // Comma
- IterativeParsingErrorState, // Colon
- IterativeParsingMemberValueState, // String
- IterativeParsingMemberValueState, // False
- IterativeParsingMemberValueState, // True
- IterativeParsingMemberValueState, // Null
- IterativeParsingMemberValueState // Number
- },
- }; // End of G
-
- return static_cast<IterativeParsingState>(G[state][token]);
- }
-
- // Make an advance in the token stream and state based on the candidate destination state which was returned by Transit().
- // May return a new state on state pop.
- template <unsigned parseFlags, typename InputStream, typename Handler>
- RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream& is, Handler& handler) {
- (void)token;
-
- switch (dst) {
- case IterativeParsingErrorState:
- return dst;
-
- case IterativeParsingObjectInitialState:
- case IterativeParsingArrayInitialState:
- {
- // Push the state(Element or MemeberValue) if we are nested in another array or value of member.
- // In this way we can get the correct state on ObjectFinish or ArrayFinish by frame pop.
- IterativeParsingState n = src;
- if (src == IterativeParsingArrayInitialState || src == IterativeParsingElementDelimiterState)
- n = IterativeParsingElementState;
- else if (src == IterativeParsingKeyValueDelimiterState)
- n = IterativeParsingMemberValueState;
- // Push current state.
- *stack_.template Push<SizeType>(1) = n;
- // Initialize and push the member/element count.
- *stack_.template Push<SizeType>(1) = 0;
- // Call handler
- bool hr = (dst == IterativeParsingObjectInitialState) ? handler.StartObject() : handler.StartArray();
- // On handler short circuits the parsing.
- if (!hr) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell());
- return IterativeParsingErrorState;
- }
- else {
- is.Take();
- return dst;
- }
- }
-
- case IterativeParsingMemberKeyState:
- ParseString<parseFlags>(is, handler, true);
- if (HasParseError())
- return IterativeParsingErrorState;
- else
- return dst;
-
- case IterativeParsingKeyValueDelimiterState:
- RAPIDJSON_ASSERT(token == ColonToken);
- is.Take();
- return dst;
-
- case IterativeParsingMemberValueState:
- // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
- ParseValue<parseFlags>(is, handler);
- if (HasParseError()) {
- return IterativeParsingErrorState;
- }
- return dst;
-
- case IterativeParsingElementState:
- // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
- ParseValue<parseFlags>(is, handler);
- if (HasParseError()) {
- return IterativeParsingErrorState;
- }
- return dst;
-
- case IterativeParsingMemberDelimiterState:
- case IterativeParsingElementDelimiterState:
- is.Take();
- // Update member/element count.
- *stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
- return dst;
-
- case IterativeParsingObjectFinishState:
- {
- // Transit from delimiter is only allowed when trailing commas are enabled
- if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingMemberDelimiterState) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorObjectMissName, is.Tell());
- return IterativeParsingErrorState;
- }
- // Get member count.
- SizeType c = *stack_.template Pop<SizeType>(1);
- // If the object is not empty, count the last member.
- if (src == IterativeParsingMemberValueState)
- ++c;
- // Restore the state.
- IterativeParsingState n = static_cast<IterativeParsingState>(*stack_.template Pop<SizeType>(1));
- // Transit to Finish state if this is the topmost scope.
- if (n == IterativeParsingStartState)
- n = IterativeParsingFinishState;
- // Call handler
- bool hr = handler.EndObject(c);
- // On handler short circuits the parsing.
- if (!hr) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell());
- return IterativeParsingErrorState;
- }
- else {
- is.Take();
- return n;
- }
- }
-
- case IterativeParsingArrayFinishState:
- {
- // Transit from delimiter is only allowed when trailing commas are enabled
- if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingElementDelimiterState) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorValueInvalid, is.Tell());
- return IterativeParsingErrorState;
- }
- // Get element count.
- SizeType c = *stack_.template Pop<SizeType>(1);
- // If the array is not empty, count the last element.
- if (src == IterativeParsingElementState)
- ++c;
- // Restore the state.
- IterativeParsingState n = static_cast<IterativeParsingState>(*stack_.template Pop<SizeType>(1));
- // Transit to Finish state if this is the topmost scope.
- if (n == IterativeParsingStartState)
- n = IterativeParsingFinishState;
- // Call handler
- bool hr = handler.EndArray(c);
- // On handler short circuits the parsing.
- if (!hr) {
- RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorTermination, is.Tell());
- return IterativeParsingErrorState;
- }
- else {
- is.Take();
- return n;
- }
- }
-
- default:
- // This branch is for IterativeParsingValueState actually.
- // Use `default:` rather than
- // `case IterativeParsingValueState:` is for code coverage.
-
- // The IterativeParsingStartState is not enumerated in this switch-case.
- // It is impossible for that case. And it can be caught by following assertion.
-
- // The IterativeParsingFinishState is not enumerated in this switch-case either.
- // It is a "derivative" state which cannot triggered from Predict() directly.
- // Therefore it cannot happen here. And it can be caught by following assertion.
- RAPIDJSON_ASSERT(dst == IterativeParsingValueState);
-
- // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
- ParseValue<parseFlags>(is, handler);
- if (HasParseError()) {
- return IterativeParsingErrorState;
- }
- return IterativeParsingFinishState;
- }
- }
-
- template <typename InputStream>
- void HandleError(IterativeParsingState src, InputStream& is) {
- if (HasParseError()) {
- // Error flag has been set.
- return;
- }
-
- switch (src) {
- case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell()); return;
- case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell()); return;
- case IterativeParsingObjectInitialState:
- case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); return;
- case IterativeParsingMemberKeyState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); return;
- case IterativeParsingMemberValueState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); return;
- case IterativeParsingKeyValueDelimiterState:
- case IterativeParsingArrayInitialState:
- case IterativeParsingElementDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); return;
- default: RAPIDJSON_ASSERT(src == IterativeParsingElementState); RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); return;
- }
- }
-
- RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) {
- return s >= IterativeParsingElementDelimiterState;
- }
-
- RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) {
- return s <= IterativeParsingErrorState;
- }
-
- template <unsigned parseFlags, typename InputStream, typename Handler>
- ParseResult IterativeParse(InputStream& is, Handler& handler) {
- parseResult_.Clear();
- ClearStackOnExit scope(*this);
- IterativeParsingState state = IterativeParsingStartState;
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
- while (is.Peek() != '\0') {
- Token t = Tokenize(is.Peek());
- IterativeParsingState n = Predict(state, t);
- IterativeParsingState d = Transit<parseFlags>(state, t, n, is, handler);
-
- if (d == IterativeParsingErrorState) {
- HandleError(state, is);
- break;
- }
-
- state = d;
-
- // Do not further consume streams if a root JSON has been parsed.
- if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState)
- break;
-
- SkipWhitespaceAndComments<parseFlags>(is);
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
- }
-
- // Handle the end of file.
- if (state != IterativeParsingFinishState)
- HandleError(state, is);
-
- return parseResult_;
- }
-
- static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string.
- internal::Stack<StackAllocator> stack_; //!< A stack for storing decoded string temporarily during non-destructive parsing.
- ParseResult parseResult_;
- IterativeParsingState state_;
-}; // class GenericReader
-
-//! Reader with UTF8 encoding and default allocator.
-typedef GenericReader<UTF8<>, UTF8<> > Reader;
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-
-#ifdef __GNUC__
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_READER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/schema.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/schema.h
deleted file mode 100644
index abcf1a102..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/schema.h
+++ /dev/null
@@ -1,2016 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available->
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip-> All rights reserved->
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License-> You may obtain a copy of the License at
-//
-// http://opensource->org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied-> See the License for the
-// specific language governing permissions and limitations under the License->
-
-#ifndef RAPIDJSON_SCHEMA_H_
-#define RAPIDJSON_SCHEMA_H_
-
-#include "document.h"
-#include "pointer.h"
-#include <cmath> // abs, floor
-
-#if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX)
-#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1
-#else
-#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0
-#endif
-
-#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
-#define RAPIDJSON_SCHEMA_USE_STDREGEX 1
-#else
-#define RAPIDJSON_SCHEMA_USE_STDREGEX 0
-#endif
-
-#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
-#include "internal/regex.h"
-#elif RAPIDJSON_SCHEMA_USE_STDREGEX
-#include <regex>
-#endif
-
-#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX || RAPIDJSON_SCHEMA_USE_STDREGEX
-#define RAPIDJSON_SCHEMA_HAS_REGEX 1
-#else
-#define RAPIDJSON_SCHEMA_HAS_REGEX 0
-#endif
-
-#ifndef RAPIDJSON_SCHEMA_VERBOSE
-#define RAPIDJSON_SCHEMA_VERBOSE 0
-#endif
-
-#if RAPIDJSON_SCHEMA_VERBOSE
-#include "stringbuffer.h"
-#endif
-
-RAPIDJSON_DIAG_PUSH
-
-#if defined(__GNUC__)
-RAPIDJSON_DIAG_OFF(effc++)
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_OFF(weak-vtables)
-RAPIDJSON_DIAG_OFF(exit-time-destructors)
-RAPIDJSON_DIAG_OFF(c++98-compat-pedantic)
-RAPIDJSON_DIAG_OFF(variadic-macros)
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// Verbose Utilities
-
-#if RAPIDJSON_SCHEMA_VERBOSE
-
-namespace internal {
-
-inline void PrintInvalidKeyword(const char* keyword) {
- printf("Fail keyword: %s\n", keyword);
-}
-
-inline void PrintInvalidKeyword(const wchar_t* keyword) {
- wprintf(L"Fail keyword: %ls\n", keyword);
-}
-
-inline void PrintInvalidDocument(const char* document) {
- printf("Fail document: %s\n\n", document);
-}
-
-inline void PrintInvalidDocument(const wchar_t* document) {
- wprintf(L"Fail document: %ls\n\n", document);
-}
-
-inline void PrintValidatorPointers(unsigned depth, const char* s, const char* d) {
- printf("S: %*s%s\nD: %*s%s\n\n", depth * 4, " ", s, depth * 4, " ", d);
-}
-
-inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar_t* d) {
- wprintf(L"S: %*ls%ls\nD: %*ls%ls\n\n", depth * 4, L" ", s, depth * 4, L" ", d);
-}
-
-} // namespace internal
-
-#endif // RAPIDJSON_SCHEMA_VERBOSE
-
-///////////////////////////////////////////////////////////////////////////////
-// RAPIDJSON_INVALID_KEYWORD_RETURN
-
-#if RAPIDJSON_SCHEMA_VERBOSE
-#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) internal::PrintInvalidKeyword(keyword)
-#else
-#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword)
-#endif
-
-#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)\
-RAPIDJSON_MULTILINEMACRO_BEGIN\
- context.invalidKeyword = keyword.GetString();\
- RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword.GetString());\
- return false;\
-RAPIDJSON_MULTILINEMACRO_END
-
-///////////////////////////////////////////////////////////////////////////////
-// Forward declarations
-
-template <typename ValueType, typename Allocator>
-class GenericSchemaDocument;
-
-namespace internal {
-
-template <typename SchemaDocumentType>
-class Schema;
-
-///////////////////////////////////////////////////////////////////////////////
-// ISchemaValidator
-
-class ISchemaValidator {
-public:
- virtual ~ISchemaValidator() {}
- virtual bool IsValid() const = 0;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// ISchemaStateFactory
-
-template <typename SchemaType>
-class ISchemaStateFactory {
-public:
- virtual ~ISchemaStateFactory() {}
- virtual ISchemaValidator* CreateSchemaValidator(const SchemaType&) = 0;
- virtual void DestroySchemaValidator(ISchemaValidator* validator) = 0;
- virtual void* CreateHasher() = 0;
- virtual uint64_t GetHashCode(void* hasher) = 0;
- virtual void DestroryHasher(void* hasher) = 0;
- virtual void* MallocState(size_t size) = 0;
- virtual void FreeState(void* p) = 0;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Hasher
-
-// For comparison of compound value
-template<typename Encoding, typename Allocator>
-class Hasher {
-public:
- typedef typename Encoding::Ch Ch;
-
- Hasher(Allocator* allocator = 0, size_t stackCapacity = kDefaultSize) : stack_(allocator, stackCapacity) {}
-
- bool Null() { return WriteType(kNullType); }
- bool Bool(bool b) { return WriteType(b ? kTrueType : kFalseType); }
- bool Int(int i) { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
- bool Uint(unsigned u) { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
- bool Int64(int64_t i) { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
- bool Uint64(uint64_t u) { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
- bool Double(double d) {
- Number n;
- if (d < 0) n.u.i = static_cast<int64_t>(d);
- else n.u.u = static_cast<uint64_t>(d);
- n.d = d;
- return WriteNumber(n);
- }
-
- bool RawNumber(const Ch* str, SizeType len, bool) {
- WriteBuffer(kNumberType, str, len * sizeof(Ch));
- return true;
- }
-
- bool String(const Ch* str, SizeType len, bool) {
- WriteBuffer(kStringType, str, len * sizeof(Ch));
- return true;
- }
-
- bool StartObject() { return true; }
- bool Key(const Ch* str, SizeType len, bool copy) { return String(str, len, copy); }
- bool EndObject(SizeType memberCount) {
- uint64_t h = Hash(0, kObjectType);
- uint64_t* kv = stack_.template Pop<uint64_t>(memberCount * 2);
- for (SizeType i = 0; i < memberCount; i++)
- h ^= Hash(kv[i * 2], kv[i * 2 + 1]); // Use xor to achieve member order insensitive
- *stack_.template Push<uint64_t>() = h;
- return true;
- }
-
- bool StartArray() { return true; }
- bool EndArray(SizeType elementCount) {
- uint64_t h = Hash(0, kArrayType);
- uint64_t* e = stack_.template Pop<uint64_t>(elementCount);
- for (SizeType i = 0; i < elementCount; i++)
- h = Hash(h, e[i]); // Use hash to achieve element order sensitive
- *stack_.template Push<uint64_t>() = h;
- return true;
- }
-
- bool IsValid() const { return stack_.GetSize() == sizeof(uint64_t); }
-
- uint64_t GetHashCode() const {
- RAPIDJSON_ASSERT(IsValid());
- return *stack_.template Top<uint64_t>();
- }
-
-private:
- static const size_t kDefaultSize = 256;
- struct Number {
- union U {
- uint64_t u;
- int64_t i;
- }u;
- double d;
- };
-
- bool WriteType(Type type) { return WriteBuffer(type, 0, 0); }
-
- bool WriteNumber(const Number& n) { return WriteBuffer(kNumberType, &n, sizeof(n)); }
-
- bool WriteBuffer(Type type, const void* data, size_t len) {
- // FNV-1a from http://isthe.com/chongo/tech/comp/fnv/
- uint64_t h = Hash(RAPIDJSON_UINT64_C2(0x84222325, 0xcbf29ce4), type);
- const unsigned char* d = static_cast<const unsigned char*>(data);
- for (size_t i = 0; i < len; i++)
- h = Hash(h, d[i]);
- *stack_.template Push<uint64_t>() = h;
- return true;
- }
-
- static uint64_t Hash(uint64_t h, uint64_t d) {
- static const uint64_t kPrime = RAPIDJSON_UINT64_C2(0x00000100, 0x000001b3);
- h ^= d;
- h *= kPrime;
- return h;
- }
-
- Stack<Allocator> stack_;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// SchemaValidationContext
-
-template <typename SchemaDocumentType>
-struct SchemaValidationContext {
- typedef Schema<SchemaDocumentType> SchemaType;
- typedef ISchemaStateFactory<SchemaType> SchemaValidatorFactoryType;
- typedef typename SchemaType::ValueType ValueType;
- typedef typename ValueType::Ch Ch;
-
- enum PatternValidatorType {
- kPatternValidatorOnly,
- kPatternValidatorWithProperty,
- kPatternValidatorWithAdditionalProperty
- };
-
- SchemaValidationContext(SchemaValidatorFactoryType& f, const SchemaType* s) :
- factory(f),
- schema(s),
- valueSchema(),
- invalidKeyword(),
- hasher(),
- arrayElementHashCodes(),
- validators(),
- validatorCount(),
- patternPropertiesValidators(),
- patternPropertiesValidatorCount(),
- patternPropertiesSchemas(),
- patternPropertiesSchemaCount(),
- valuePatternValidatorType(kPatternValidatorOnly),
- propertyExist(),
- inArray(false),
- valueUniqueness(false),
- arrayUniqueness(false)
- {
- }
-
- ~SchemaValidationContext() {
- if (hasher)
- factory.DestroryHasher(hasher);
- if (validators) {
- for (SizeType i = 0; i < validatorCount; i++)
- factory.DestroySchemaValidator(validators[i]);
- factory.FreeState(validators);
- }
- if (patternPropertiesValidators) {
- for (SizeType i = 0; i < patternPropertiesValidatorCount; i++)
- factory.DestroySchemaValidator(patternPropertiesValidators[i]);
- factory.FreeState(patternPropertiesValidators);
- }
- if (patternPropertiesSchemas)
- factory.FreeState(patternPropertiesSchemas);
- if (propertyExist)
- factory.FreeState(propertyExist);
- }
-
- SchemaValidatorFactoryType& factory;
- const SchemaType* schema;
- const SchemaType* valueSchema;
- const Ch* invalidKeyword;
- void* hasher; // Only validator access
- void* arrayElementHashCodes; // Only validator access this
- ISchemaValidator** validators;
- SizeType validatorCount;
- ISchemaValidator** patternPropertiesValidators;
- SizeType patternPropertiesValidatorCount;
- const SchemaType** patternPropertiesSchemas;
- SizeType patternPropertiesSchemaCount;
- PatternValidatorType valuePatternValidatorType;
- PatternValidatorType objectPatternValidatorType;
- SizeType arrayElementIndex;
- bool* propertyExist;
- bool inArray;
- bool valueUniqueness;
- bool arrayUniqueness;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Schema
-
-template <typename SchemaDocumentType>
-class Schema {
-public:
- typedef typename SchemaDocumentType::ValueType ValueType;
- typedef typename SchemaDocumentType::AllocatorType AllocatorType;
- typedef typename SchemaDocumentType::PointerType PointerType;
- typedef typename ValueType::EncodingType EncodingType;
- typedef typename EncodingType::Ch Ch;
- typedef SchemaValidationContext<SchemaDocumentType> Context;
- typedef Schema<SchemaDocumentType> SchemaType;
- typedef GenericValue<EncodingType, AllocatorType> SValue;
- friend class GenericSchemaDocument<ValueType, AllocatorType>;
-
- Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) :
- allocator_(allocator),
- typeless_(schemaDocument->GetTypeless()),
- enum_(),
- enumCount_(),
- not_(),
- type_((1 << kTotalSchemaType) - 1), // typeless
- validatorCount_(),
- properties_(),
- additionalPropertiesSchema_(),
- patternProperties_(),
- patternPropertyCount_(),
- propertyCount_(),
- minProperties_(),
- maxProperties_(SizeType(~0)),
- additionalProperties_(true),
- hasDependencies_(),
- hasRequired_(),
- hasSchemaDependencies_(),
- additionalItemsSchema_(),
- itemsList_(),
- itemsTuple_(),
- itemsTupleCount_(),
- minItems_(),
- maxItems_(SizeType(~0)),
- additionalItems_(true),
- uniqueItems_(false),
- pattern_(),
- minLength_(0),
- maxLength_(~SizeType(0)),
- exclusiveMinimum_(false),
- exclusiveMaximum_(false)
- {
- typedef typename SchemaDocumentType::ValueType ValueType;
- typedef typename ValueType::ConstValueIterator ConstValueIterator;
- typedef typename ValueType::ConstMemberIterator ConstMemberIterator;
-
- if (!value.IsObject())
- return;
-
- if (const ValueType* v = GetMember(value, GetTypeString())) {
- type_ = 0;
- if (v->IsString())
- AddType(*v);
- else if (v->IsArray())
- for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr)
- AddType(*itr);
- }
-
- if (const ValueType* v = GetMember(value, GetEnumString()))
- if (v->IsArray() && v->Size() > 0) {
- enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
- for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
- typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
- char buffer[256 + 24];
- MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
- EnumHasherType h(&hasherAllocator, 256);
- itr->Accept(h);
- enum_[enumCount_++] = h.GetHashCode();
- }
- }
-
- if (schemaDocument) {
- AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document);
- AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document);
- AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document);
- }
-
- if (const ValueType* v = GetMember(value, GetNotString())) {
- schemaDocument->CreateSchema(&not_, p.Append(GetNotString(), allocator_), *v, document);
- notValidatorIndex_ = validatorCount_;
- validatorCount_++;
- }
-
- // Object
-
- const ValueType* properties = GetMember(value, GetPropertiesString());
- const ValueType* required = GetMember(value, GetRequiredString());
- const ValueType* dependencies = GetMember(value, GetDependenciesString());
- {
- // Gather properties from properties/required/dependencies
- SValue allProperties(kArrayType);
-
- if (properties && properties->IsObject())
- for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr)
- AddUniqueElement(allProperties, itr->name);
-
- if (required && required->IsArray())
- for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
- if (itr->IsString())
- AddUniqueElement(allProperties, *itr);
-
- if (dependencies && dependencies->IsObject())
- for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) {
- AddUniqueElement(allProperties, itr->name);
- if (itr->value.IsArray())
- for (ConstValueIterator i = itr->value.Begin(); i != itr->value.End(); ++i)
- if (i->IsString())
- AddUniqueElement(allProperties, *i);
- }
-
- if (allProperties.Size() > 0) {
- propertyCount_ = allProperties.Size();
- properties_ = static_cast<Property*>(allocator_->Malloc(sizeof(Property) * propertyCount_));
- for (SizeType i = 0; i < propertyCount_; i++) {
- new (&properties_[i]) Property();
- properties_[i].name = allProperties[i];
- properties_[i].schema = typeless_;
- }
- }
- }
-
- if (properties && properties->IsObject()) {
- PointerType q = p.Append(GetPropertiesString(), allocator_);
- for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) {
- SizeType index;
- if (FindPropertyIndex(itr->name, &index))
- schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document);
- }
- }
-
- if (const ValueType* v = GetMember(value, GetPatternPropertiesString())) {
- PointerType q = p.Append(GetPatternPropertiesString(), allocator_);
- patternProperties_ = static_cast<PatternProperty*>(allocator_->Malloc(sizeof(PatternProperty) * v->MemberCount()));
- patternPropertyCount_ = 0;
-
- for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) {
- new (&patternProperties_[patternPropertyCount_]) PatternProperty();
- patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name);
- schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, q.Append(itr->name, allocator_), itr->value, document);
- patternPropertyCount_++;
- }
- }
-
- if (required && required->IsArray())
- for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
- if (itr->IsString()) {
- SizeType index;
- if (FindPropertyIndex(*itr, &index)) {
- properties_[index].required = true;
- hasRequired_ = true;
- }
- }
-
- if (dependencies && dependencies->IsObject()) {
- PointerType q = p.Append(GetDependenciesString(), allocator_);
- hasDependencies_ = true;
- for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) {
- SizeType sourceIndex;
- if (FindPropertyIndex(itr->name, &sourceIndex)) {
- if (itr->value.IsArray()) {
- properties_[sourceIndex].dependencies = static_cast<bool*>(allocator_->Malloc(sizeof(bool) * propertyCount_));
- std::memset(properties_[sourceIndex].dependencies, 0, sizeof(bool)* propertyCount_);
- for (ConstValueIterator targetItr = itr->value.Begin(); targetItr != itr->value.End(); ++targetItr) {
- SizeType targetIndex;
- if (FindPropertyIndex(*targetItr, &targetIndex))
- properties_[sourceIndex].dependencies[targetIndex] = true;
- }
- }
- else if (itr->value.IsObject()) {
- hasSchemaDependencies_ = true;
- schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document);
- properties_[sourceIndex].dependenciesValidatorIndex = validatorCount_;
- validatorCount_++;
- }
- }
- }
- }
-
- if (const ValueType* v = GetMember(value, GetAdditionalPropertiesString())) {
- if (v->IsBool())
- additionalProperties_ = v->GetBool();
- else if (v->IsObject())
- schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document);
- }
-
- AssignIfExist(minProperties_, value, GetMinPropertiesString());
- AssignIfExist(maxProperties_, value, GetMaxPropertiesString());
-
- // Array
- if (const ValueType* v = GetMember(value, GetItemsString())) {
- PointerType q = p.Append(GetItemsString(), allocator_);
- if (v->IsObject()) // List validation
- schemaDocument->CreateSchema(&itemsList_, q, *v, document);
- else if (v->IsArray()) { // Tuple validation
- itemsTuple_ = static_cast<const Schema**>(allocator_->Malloc(sizeof(const Schema*) * v->Size()));
- SizeType index = 0;
- for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr, index++)
- schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document);
- }
- }
-
- AssignIfExist(minItems_, value, GetMinItemsString());
- AssignIfExist(maxItems_, value, GetMaxItemsString());
-
- if (const ValueType* v = GetMember(value, GetAdditionalItemsString())) {
- if (v->IsBool())
- additionalItems_ = v->GetBool();
- else if (v->IsObject())
- schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document);
- }
-
- AssignIfExist(uniqueItems_, value, GetUniqueItemsString());
-
- // String
- AssignIfExist(minLength_, value, GetMinLengthString());
- AssignIfExist(maxLength_, value, GetMaxLengthString());
-
- if (const ValueType* v = GetMember(value, GetPatternString()))
- pattern_ = CreatePattern(*v);
-
- // Number
- if (const ValueType* v = GetMember(value, GetMinimumString()))
- if (v->IsNumber())
- minimum_.CopyFrom(*v, *allocator_);
-
- if (const ValueType* v = GetMember(value, GetMaximumString()))
- if (v->IsNumber())
- maximum_.CopyFrom(*v, *allocator_);
-
- AssignIfExist(exclusiveMinimum_, value, GetExclusiveMinimumString());
- AssignIfExist(exclusiveMaximum_, value, GetExclusiveMaximumString());
-
- if (const ValueType* v = GetMember(value, GetMultipleOfString()))
- if (v->IsNumber() && v->GetDouble() > 0.0)
- multipleOf_.CopyFrom(*v, *allocator_);
- }
-
- ~Schema() {
- AllocatorType::Free(enum_);
- if (properties_) {
- for (SizeType i = 0; i < propertyCount_; i++)
- properties_[i].~Property();
- AllocatorType::Free(properties_);
- }
- if (patternProperties_) {
- for (SizeType i = 0; i < patternPropertyCount_; i++)
- patternProperties_[i].~PatternProperty();
- AllocatorType::Free(patternProperties_);
- }
- AllocatorType::Free(itemsTuple_);
-#if RAPIDJSON_SCHEMA_HAS_REGEX
- if (pattern_) {
- pattern_->~RegexType();
- AllocatorType::Free(pattern_);
- }
-#endif
- }
-
- bool BeginValue(Context& context) const {
- if (context.inArray) {
- if (uniqueItems_)
- context.valueUniqueness = true;
-
- if (itemsList_)
- context.valueSchema = itemsList_;
- else if (itemsTuple_) {
- if (context.arrayElementIndex < itemsTupleCount_)
- context.valueSchema = itemsTuple_[context.arrayElementIndex];
- else if (additionalItemsSchema_)
- context.valueSchema = additionalItemsSchema_;
- else if (additionalItems_)
- context.valueSchema = typeless_;
- else
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetItemsString());
- }
- else
- context.valueSchema = typeless_;
-
- context.arrayElementIndex++;
- }
- return true;
- }
-
- RAPIDJSON_FORCEINLINE bool EndValue(Context& context) const {
- if (context.patternPropertiesValidatorCount > 0) {
- bool otherValid = false;
- SizeType count = context.patternPropertiesValidatorCount;
- if (context.objectPatternValidatorType != Context::kPatternValidatorOnly)
- otherValid = context.patternPropertiesValidators[--count]->IsValid();
-
- bool patternValid = true;
- for (SizeType i = 0; i < count; i++)
- if (!context.patternPropertiesValidators[i]->IsValid()) {
- patternValid = false;
- break;
- }
-
- if (context.objectPatternValidatorType == Context::kPatternValidatorOnly) {
- if (!patternValid)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
- }
- else if (context.objectPatternValidatorType == Context::kPatternValidatorWithProperty) {
- if (!patternValid || !otherValid)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
- }
- else if (!patternValid && !otherValid) // kPatternValidatorWithAdditionalProperty)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
- }
-
- if (enum_) {
- const uint64_t h = context.factory.GetHashCode(context.hasher);
- for (SizeType i = 0; i < enumCount_; i++)
- if (enum_[i] == h)
- goto foundEnum;
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetEnumString());
- foundEnum:;
- }
-
- if (allOf_.schemas)
- for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++)
- if (!context.validators[i]->IsValid())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetAllOfString());
-
- if (anyOf_.schemas) {
- for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++)
- if (context.validators[i]->IsValid())
- goto foundAny;
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetAnyOfString());
- foundAny:;
- }
-
- if (oneOf_.schemas) {
- bool oneValid = false;
- for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++)
- if (context.validators[i]->IsValid()) {
- if (oneValid)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString());
- else
- oneValid = true;
- }
- if (!oneValid)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString());
- }
-
- if (not_ && context.validators[notValidatorIndex_]->IsValid())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetNotString());
-
- return true;
- }
-
- bool Null(Context& context) const {
- if (!(type_ & (1 << kNullSchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
- return CreateParallelValidator(context);
- }
-
- bool Bool(Context& context, bool) const {
- if (!(type_ & (1 << kBooleanSchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
- return CreateParallelValidator(context);
- }
-
- bool Int(Context& context, int i) const {
- if (!CheckInt(context, i))
- return false;
- return CreateParallelValidator(context);
- }
-
- bool Uint(Context& context, unsigned u) const {
- if (!CheckUint(context, u))
- return false;
- return CreateParallelValidator(context);
- }
-
- bool Int64(Context& context, int64_t i) const {
- if (!CheckInt(context, i))
- return false;
- return CreateParallelValidator(context);
- }
-
- bool Uint64(Context& context, uint64_t u) const {
- if (!CheckUint(context, u))
- return false;
- return CreateParallelValidator(context);
- }
-
- bool Double(Context& context, double d) const {
- if (!(type_ & (1 << kNumberSchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- if (!minimum_.IsNull() && !CheckDoubleMinimum(context, d))
- return false;
-
- if (!maximum_.IsNull() && !CheckDoubleMaximum(context, d))
- return false;
-
- if (!multipleOf_.IsNull() && !CheckDoubleMultipleOf(context, d))
- return false;
-
- return CreateParallelValidator(context);
- }
-
- bool String(Context& context, const Ch* str, SizeType length, bool) const {
- if (!(type_ & (1 << kStringSchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- if (minLength_ != 0 || maxLength_ != SizeType(~0)) {
- SizeType count;
- if (internal::CountStringCodePoint<EncodingType>(str, length, &count)) {
- if (count < minLength_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinLengthString());
- if (count > maxLength_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxLengthString());
- }
- }
-
- if (pattern_ && !IsPatternMatch(pattern_, str, length))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternString());
-
- return CreateParallelValidator(context);
- }
-
- bool StartObject(Context& context) const {
- if (!(type_ & (1 << kObjectSchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- if (hasDependencies_ || hasRequired_) {
- context.propertyExist = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
- std::memset(context.propertyExist, 0, sizeof(bool) * propertyCount_);
- }
-
- if (patternProperties_) { // pre-allocate schema array
- SizeType count = patternPropertyCount_ + 1; // extra for valuePatternValidatorType
- context.patternPropertiesSchemas = static_cast<const SchemaType**>(context.factory.MallocState(sizeof(const SchemaType*) * count));
- context.patternPropertiesSchemaCount = 0;
- std::memset(context.patternPropertiesSchemas, 0, sizeof(SchemaType*) * count);
- }
-
- return CreateParallelValidator(context);
- }
-
- bool Key(Context& context, const Ch* str, SizeType len, bool) const {
- if (patternProperties_) {
- context.patternPropertiesSchemaCount = 0;
- for (SizeType i = 0; i < patternPropertyCount_; i++)
- if (patternProperties_[i].pattern && IsPatternMatch(patternProperties_[i].pattern, str, len)) {
- context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = patternProperties_[i].schema;
- context.valueSchema = typeless_;
- }
- }
-
- SizeType index;
- if (FindPropertyIndex(ValueType(str, len).Move(), &index)) {
- if (context.patternPropertiesSchemaCount > 0) {
- context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = properties_[index].schema;
- context.valueSchema = typeless_;
- context.valuePatternValidatorType = Context::kPatternValidatorWithProperty;
- }
- else
- context.valueSchema = properties_[index].schema;
-
- if (context.propertyExist)
- context.propertyExist[index] = true;
-
- return true;
- }
-
- if (additionalPropertiesSchema_) {
- if (additionalPropertiesSchema_ && context.patternPropertiesSchemaCount > 0) {
- context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = additionalPropertiesSchema_;
- context.valueSchema = typeless_;
- context.valuePatternValidatorType = Context::kPatternValidatorWithAdditionalProperty;
- }
- else
- context.valueSchema = additionalPropertiesSchema_;
- return true;
- }
- else if (additionalProperties_) {
- context.valueSchema = typeless_;
- return true;
- }
-
- if (context.patternPropertiesSchemaCount == 0) // patternProperties are not additional properties
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetAdditionalPropertiesString());
-
- return true;
- }
-
- bool EndObject(Context& context, SizeType memberCount) const {
- if (hasRequired_)
- for (SizeType index = 0; index < propertyCount_; index++)
- if (properties_[index].required)
- if (!context.propertyExist[index])
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
-
- if (memberCount < minProperties_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
-
- if (memberCount > maxProperties_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxPropertiesString());
-
- if (hasDependencies_) {
- for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++)
- if (context.propertyExist[sourceIndex]) {
- if (properties_[sourceIndex].dependencies) {
- for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++)
- if (properties_[sourceIndex].dependencies[targetIndex] && !context.propertyExist[targetIndex])
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
- }
- else if (properties_[sourceIndex].dependenciesSchema)
- if (!context.validators[properties_[sourceIndex].dependenciesValidatorIndex]->IsValid())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
- }
- }
-
- return true;
- }
-
- bool StartArray(Context& context) const {
- if (!(type_ & (1 << kArraySchemaType)))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- context.arrayElementIndex = 0;
- context.inArray = true;
-
- return CreateParallelValidator(context);
- }
-
- bool EndArray(Context& context, SizeType elementCount) const {
- context.inArray = false;
-
- if (elementCount < minItems_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinItemsString());
-
- if (elementCount > maxItems_)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxItemsString());
-
- return true;
- }
-
- // Generate functions for string literal according to Ch
-#define RAPIDJSON_STRING_(name, ...) \
- static const ValueType& Get##name##String() {\
- static const Ch s[] = { __VA_ARGS__, '\0' };\
- static const ValueType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1));\
- return v;\
- }
-
- RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l')
- RAPIDJSON_STRING_(Boolean, 'b', 'o', 'o', 'l', 'e', 'a', 'n')
- RAPIDJSON_STRING_(Object, 'o', 'b', 'j', 'e', 'c', 't')
- RAPIDJSON_STRING_(Array, 'a', 'r', 'r', 'a', 'y')
- RAPIDJSON_STRING_(String, 's', 't', 'r', 'i', 'n', 'g')
- RAPIDJSON_STRING_(Number, 'n', 'u', 'm', 'b', 'e', 'r')
- RAPIDJSON_STRING_(Integer, 'i', 'n', 't', 'e', 'g', 'e', 'r')
- RAPIDJSON_STRING_(Type, 't', 'y', 'p', 'e')
- RAPIDJSON_STRING_(Enum, 'e', 'n', 'u', 'm')
- RAPIDJSON_STRING_(AllOf, 'a', 'l', 'l', 'O', 'f')
- RAPIDJSON_STRING_(AnyOf, 'a', 'n', 'y', 'O', 'f')
- RAPIDJSON_STRING_(OneOf, 'o', 'n', 'e', 'O', 'f')
- RAPIDJSON_STRING_(Not, 'n', 'o', 't')
- RAPIDJSON_STRING_(Properties, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's')
- RAPIDJSON_STRING_(Required, 'r', 'e', 'q', 'u', 'i', 'r', 'e', 'd')
- RAPIDJSON_STRING_(Dependencies, 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'i', 'e', 's')
- RAPIDJSON_STRING_(PatternProperties, 'p', 'a', 't', 't', 'e', 'r', 'n', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's')
- RAPIDJSON_STRING_(AdditionalProperties, 'a', 'd', 'd', 'i', 't', 'i', 'o', 'n', 'a', 'l', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's')
- RAPIDJSON_STRING_(MinProperties, 'm', 'i', 'n', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's')
- RAPIDJSON_STRING_(MaxProperties, 'm', 'a', 'x', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's')
- RAPIDJSON_STRING_(Items, 'i', 't', 'e', 'm', 's')
- RAPIDJSON_STRING_(MinItems, 'm', 'i', 'n', 'I', 't', 'e', 'm', 's')
- RAPIDJSON_STRING_(MaxItems, 'm', 'a', 'x', 'I', 't', 'e', 'm', 's')
- RAPIDJSON_STRING_(AdditionalItems, 'a', 'd', 'd', 'i', 't', 'i', 'o', 'n', 'a', 'l', 'I', 't', 'e', 'm', 's')
- RAPIDJSON_STRING_(UniqueItems, 'u', 'n', 'i', 'q', 'u', 'e', 'I', 't', 'e', 'm', 's')
- RAPIDJSON_STRING_(MinLength, 'm', 'i', 'n', 'L', 'e', 'n', 'g', 't', 'h')
- RAPIDJSON_STRING_(MaxLength, 'm', 'a', 'x', 'L', 'e', 'n', 'g', 't', 'h')
- RAPIDJSON_STRING_(Pattern, 'p', 'a', 't', 't', 'e', 'r', 'n')
- RAPIDJSON_STRING_(Minimum, 'm', 'i', 'n', 'i', 'm', 'u', 'm')
- RAPIDJSON_STRING_(Maximum, 'm', 'a', 'x', 'i', 'm', 'u', 'm')
- RAPIDJSON_STRING_(ExclusiveMinimum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'i', 'n', 'i', 'm', 'u', 'm')
- RAPIDJSON_STRING_(ExclusiveMaximum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'a', 'x', 'i', 'm', 'u', 'm')
- RAPIDJSON_STRING_(MultipleOf, 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'O', 'f')
-
-#undef RAPIDJSON_STRING_
-
-private:
- enum SchemaValueType {
- kNullSchemaType,
- kBooleanSchemaType,
- kObjectSchemaType,
- kArraySchemaType,
- kStringSchemaType,
- kNumberSchemaType,
- kIntegerSchemaType,
- kTotalSchemaType
- };
-
-#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
- typedef internal::GenericRegex<EncodingType> RegexType;
-#elif RAPIDJSON_SCHEMA_USE_STDREGEX
- typedef std::basic_regex<Ch> RegexType;
-#else
- typedef char RegexType;
-#endif
-
- struct SchemaArray {
- SchemaArray() : schemas(), count() {}
- ~SchemaArray() { AllocatorType::Free(schemas); }
- const SchemaType** schemas;
- SizeType begin; // begin index of context.validators
- SizeType count;
- };
-
- template <typename V1, typename V2>
- void AddUniqueElement(V1& a, const V2& v) {
- for (typename V1::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
- if (*itr == v)
- return;
- V1 c(v, *allocator_);
- a.PushBack(c, *allocator_);
- }
-
- static const ValueType* GetMember(const ValueType& value, const ValueType& name) {
- typename ValueType::ConstMemberIterator itr = value.FindMember(name);
- return itr != value.MemberEnd() ? &(itr->value) : 0;
- }
-
- static void AssignIfExist(bool& out, const ValueType& value, const ValueType& name) {
- if (const ValueType* v = GetMember(value, name))
- if (v->IsBool())
- out = v->GetBool();
- }
-
- static void AssignIfExist(SizeType& out, const ValueType& value, const ValueType& name) {
- if (const ValueType* v = GetMember(value, name))
- if (v->IsUint64() && v->GetUint64() <= SizeType(~0))
- out = static_cast<SizeType>(v->GetUint64());
- }
-
- void AssignIfExist(SchemaArray& out, SchemaDocumentType& schemaDocument, const PointerType& p, const ValueType& value, const ValueType& name, const ValueType& document) {
- if (const ValueType* v = GetMember(value, name)) {
- if (v->IsArray() && v->Size() > 0) {
- PointerType q = p.Append(name, allocator_);
- out.count = v->Size();
- out.schemas = static_cast<const Schema**>(allocator_->Malloc(out.count * sizeof(const Schema*)));
- memset(out.schemas, 0, sizeof(Schema*)* out.count);
- for (SizeType i = 0; i < out.count; i++)
- schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document);
- out.begin = validatorCount_;
- validatorCount_ += out.count;
- }
- }
- }
-
-#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
- template <typename ValueType>
- RegexType* CreatePattern(const ValueType& value) {
- if (value.IsString()) {
- RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString());
- if (!r->IsValid()) {
- r->~RegexType();
- AllocatorType::Free(r);
- r = 0;
- }
- return r;
- }
- return 0;
- }
-
- static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType) {
- GenericRegexSearch<RegexType> rs(*pattern);
- return rs.Search(str);
- }
-#elif RAPIDJSON_SCHEMA_USE_STDREGEX
- template <typename ValueType>
- RegexType* CreatePattern(const ValueType& value) {
- if (value.IsString())
- try {
- return new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
- }
- catch (const std::regex_error&) {
- }
- return 0;
- }
-
- static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType length) {
- std::match_results<const Ch*> r;
- return std::regex_search(str, str + length, r, *pattern);
- }
-#else
- template <typename ValueType>
- RegexType* CreatePattern(const ValueType&) { return 0; }
-
- static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; }
-#endif // RAPIDJSON_SCHEMA_USE_STDREGEX
-
- void AddType(const ValueType& type) {
- if (type == GetNullString() ) type_ |= 1 << kNullSchemaType;
- else if (type == GetBooleanString()) type_ |= 1 << kBooleanSchemaType;
- else if (type == GetObjectString() ) type_ |= 1 << kObjectSchemaType;
- else if (type == GetArrayString() ) type_ |= 1 << kArraySchemaType;
- else if (type == GetStringString() ) type_ |= 1 << kStringSchemaType;
- else if (type == GetIntegerString()) type_ |= 1 << kIntegerSchemaType;
- else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType);
- }
-
- bool CreateParallelValidator(Context& context) const {
- if (enum_ || context.arrayUniqueness)
- context.hasher = context.factory.CreateHasher();
-
- if (validatorCount_) {
- RAPIDJSON_ASSERT(context.validators == 0);
- context.validators = static_cast<ISchemaValidator**>(context.factory.MallocState(sizeof(ISchemaValidator*) * validatorCount_));
- context.validatorCount = validatorCount_;
-
- if (allOf_.schemas)
- CreateSchemaValidators(context, allOf_);
-
- if (anyOf_.schemas)
- CreateSchemaValidators(context, anyOf_);
-
- if (oneOf_.schemas)
- CreateSchemaValidators(context, oneOf_);
-
- if (not_)
- context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_);
-
- if (hasSchemaDependencies_) {
- for (SizeType i = 0; i < propertyCount_; i++)
- if (properties_[i].dependenciesSchema)
- context.validators[properties_[i].dependenciesValidatorIndex] = context.factory.CreateSchemaValidator(*properties_[i].dependenciesSchema);
- }
- }
-
- return true;
- }
-
- void CreateSchemaValidators(Context& context, const SchemaArray& schemas) const {
- for (SizeType i = 0; i < schemas.count; i++)
- context.validators[schemas.begin + i] = context.factory.CreateSchemaValidator(*schemas.schemas[i]);
- }
-
- // O(n)
- bool FindPropertyIndex(const ValueType& name, SizeType* outIndex) const {
- SizeType len = name.GetStringLength();
- const Ch* str = name.GetString();
- for (SizeType index = 0; index < propertyCount_; index++)
- if (properties_[index].name.GetStringLength() == len &&
- (std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0))
- {
- *outIndex = index;
- return true;
- }
- return false;
- }
-
- bool CheckInt(Context& context, int64_t i) const {
- if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType))))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- if (!minimum_.IsNull()) {
- if (minimum_.IsInt64()) {
- if (exclusiveMinimum_ ? i <= minimum_.GetInt64() : i < minimum_.GetInt64())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
- }
- else if (minimum_.IsUint64()) {
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); // i <= max(int64_t) < minimum.GetUint64()
- }
- else if (!CheckDoubleMinimum(context, static_cast<double>(i)))
- return false;
- }
-
- if (!maximum_.IsNull()) {
- if (maximum_.IsInt64()) {
- if (exclusiveMaximum_ ? i >= maximum_.GetInt64() : i > maximum_.GetInt64())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
- }
- else if (maximum_.IsUint64()) { }
- /* do nothing */ // i <= max(int64_t) < maximum_.GetUint64()
- else if (!CheckDoubleMaximum(context, static_cast<double>(i)))
- return false;
- }
-
- if (!multipleOf_.IsNull()) {
- if (multipleOf_.IsUint64()) {
- if (static_cast<uint64_t>(i >= 0 ? i : -i) % multipleOf_.GetUint64() != 0)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
- }
- else if (!CheckDoubleMultipleOf(context, static_cast<double>(i)))
- return false;
- }
-
- return true;
- }
-
- bool CheckUint(Context& context, uint64_t i) const {
- if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType))))
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
-
- if (!minimum_.IsNull()) {
- if (minimum_.IsUint64()) {
- if (exclusiveMinimum_ ? i <= minimum_.GetUint64() : i < minimum_.GetUint64())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
- }
- else if (minimum_.IsInt64())
- /* do nothing */; // i >= 0 > minimum.Getint64()
- else if (!CheckDoubleMinimum(context, static_cast<double>(i)))
- return false;
- }
-
- if (!maximum_.IsNull()) {
- if (maximum_.IsUint64()) {
- if (exclusiveMaximum_ ? i >= maximum_.GetUint64() : i > maximum_.GetUint64())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
- }
- else if (maximum_.IsInt64())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); // i >= 0 > maximum_
- else if (!CheckDoubleMaximum(context, static_cast<double>(i)))
- return false;
- }
-
- if (!multipleOf_.IsNull()) {
- if (multipleOf_.IsUint64()) {
- if (i % multipleOf_.GetUint64() != 0)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
- }
- else if (!CheckDoubleMultipleOf(context, static_cast<double>(i)))
- return false;
- }
-
- return true;
- }
-
- bool CheckDoubleMinimum(Context& context, double d) const {
- if (exclusiveMinimum_ ? d <= minimum_.GetDouble() : d < minimum_.GetDouble())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
- return true;
- }
-
- bool CheckDoubleMaximum(Context& context, double d) const {
- if (exclusiveMaximum_ ? d >= maximum_.GetDouble() : d > maximum_.GetDouble())
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
- return true;
- }
-
- bool CheckDoubleMultipleOf(Context& context, double d) const {
- double a = std::abs(d), b = std::abs(multipleOf_.GetDouble());
- double q = std::floor(a / b);
- double r = a - q * b;
- if (r > 0.0)
- RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
- return true;
- }
-
- struct Property {
- Property() : schema(), dependenciesSchema(), dependenciesValidatorIndex(), dependencies(), required(false) {}
- ~Property() { AllocatorType::Free(dependencies); }
- SValue name;
- const SchemaType* schema;
- const SchemaType* dependenciesSchema;
- SizeType dependenciesValidatorIndex;
- bool* dependencies;
- bool required;
- };
-
- struct PatternProperty {
- PatternProperty() : schema(), pattern() {}
- ~PatternProperty() {
- if (pattern) {
- pattern->~RegexType();
- AllocatorType::Free(pattern);
- }
- }
- const SchemaType* schema;
- RegexType* pattern;
- };
-
- AllocatorType* allocator_;
- const SchemaType* typeless_;
- uint64_t* enum_;
- SizeType enumCount_;
- SchemaArray allOf_;
- SchemaArray anyOf_;
- SchemaArray oneOf_;
- const SchemaType* not_;
- unsigned type_; // bitmask of kSchemaType
- SizeType validatorCount_;
- SizeType notValidatorIndex_;
-
- Property* properties_;
- const SchemaType* additionalPropertiesSchema_;
- PatternProperty* patternProperties_;
- SizeType patternPropertyCount_;
- SizeType propertyCount_;
- SizeType minProperties_;
- SizeType maxProperties_;
- bool additionalProperties_;
- bool hasDependencies_;
- bool hasRequired_;
- bool hasSchemaDependencies_;
-
- const SchemaType* additionalItemsSchema_;
- const SchemaType* itemsList_;
- const SchemaType** itemsTuple_;
- SizeType itemsTupleCount_;
- SizeType minItems_;
- SizeType maxItems_;
- bool additionalItems_;
- bool uniqueItems_;
-
- RegexType* pattern_;
- SizeType minLength_;
- SizeType maxLength_;
-
- SValue minimum_;
- SValue maximum_;
- SValue multipleOf_;
- bool exclusiveMinimum_;
- bool exclusiveMaximum_;
-};
-
-template<typename Stack, typename Ch>
-struct TokenHelper {
- RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) {
- *documentStack.template Push<Ch>() = '/';
- char buffer[21];
- size_t length = static_cast<size_t>((sizeof(SizeType) == 4 ? u32toa(index, buffer) : u64toa(index, buffer)) - buffer);
- for (size_t i = 0; i < length; i++)
- *documentStack.template Push<Ch>() = static_cast<Ch>(buffer[i]);
- }
-};
-
-// Partial specialized version for char to prevent buffer copying.
-template <typename Stack>
-struct TokenHelper<Stack, char> {
- RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) {
- if (sizeof(SizeType) == 4) {
- char *buffer = documentStack.template Push<char>(1 + 10); // '/' + uint
- *buffer++ = '/';
- const char* end = internal::u32toa(index, buffer);
- documentStack.template Pop<char>(static_cast<size_t>(10 - (end - buffer)));
- }
- else {
- char *buffer = documentStack.template Push<char>(1 + 20); // '/' + uint64
- *buffer++ = '/';
- const char* end = internal::u64toa(index, buffer);
- documentStack.template Pop<char>(static_cast<size_t>(20 - (end - buffer)));
- }
- }
-};
-
-} // namespace internal
-
-///////////////////////////////////////////////////////////////////////////////
-// IGenericRemoteSchemaDocumentProvider
-
-template <typename SchemaDocumentType>
-class IGenericRemoteSchemaDocumentProvider {
-public:
- typedef typename SchemaDocumentType::Ch Ch;
-
- virtual ~IGenericRemoteSchemaDocumentProvider() {}
- virtual const SchemaDocumentType* GetRemoteDocument(const Ch* uri, SizeType length) = 0;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericSchemaDocument
-
-//! JSON schema document.
-/*!
- A JSON schema document is a compiled version of a JSON schema.
- It is basically a tree of internal::Schema.
-
- \note This is an immutable class (i.e. its instance cannot be modified after construction).
- \tparam ValueT Type of JSON value (e.g. \c Value ), which also determine the encoding.
- \tparam Allocator Allocator type for allocating memory of this document.
-*/
-template <typename ValueT, typename Allocator = CrtAllocator>
-class GenericSchemaDocument {
-public:
- typedef ValueT ValueType;
- typedef IGenericRemoteSchemaDocumentProvider<GenericSchemaDocument> IRemoteSchemaDocumentProviderType;
- typedef Allocator AllocatorType;
- typedef typename ValueType::EncodingType EncodingType;
- typedef typename EncodingType::Ch Ch;
- typedef internal::Schema<GenericSchemaDocument> SchemaType;
- typedef GenericPointer<ValueType, Allocator> PointerType;
- friend class internal::Schema<GenericSchemaDocument>;
- template <typename, typename, typename>
- friend class GenericSchemaValidator;
-
- //! Constructor.
- /*!
- Compile a JSON document into schema document.
-
- \param document A JSON document as source.
- \param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null.
- \param allocator An optional allocator instance for allocating memory. Can be null.
- */
- explicit GenericSchemaDocument(const ValueType& document, IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) :
- remoteProvider_(remoteProvider),
- allocator_(allocator),
- ownAllocator_(),
- root_(),
- typeless_(),
- schemaMap_(allocator, kInitialSchemaMapSize),
- schemaRef_(allocator, kInitialSchemaRefSize)
- {
- if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
-
- typeless_ = static_cast<SchemaType*>(allocator_->Malloc(sizeof(SchemaType)));
- new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), 0);
-
- // Generate root schema, it will call CreateSchema() to create sub-schemas,
- // And call AddRefSchema() if there are $ref.
- CreateSchemaRecursive(&root_, PointerType(), document, document);
-
- // Resolve $ref
- while (!schemaRef_.Empty()) {
- SchemaRefEntry* refEntry = schemaRef_.template Pop<SchemaRefEntry>(1);
- if (const SchemaType* s = GetSchema(refEntry->target)) {
- if (refEntry->schema)
- *refEntry->schema = s;
-
- // Create entry in map if not exist
- if (!GetSchema(refEntry->source)) {
- new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(refEntry->source, const_cast<SchemaType*>(s), false, allocator_);
- }
- }
- else if (refEntry->schema)
- *refEntry->schema = typeless_;
-
- refEntry->~SchemaRefEntry();
- }
-
- RAPIDJSON_ASSERT(root_ != 0);
-
- schemaRef_.ShrinkToFit(); // Deallocate all memory for ref
- }
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- //! Move constructor in C++11
- GenericSchemaDocument(GenericSchemaDocument&& rhs) RAPIDJSON_NOEXCEPT :
- remoteProvider_(rhs.remoteProvider_),
- allocator_(rhs.allocator_),
- ownAllocator_(rhs.ownAllocator_),
- root_(rhs.root_),
- typeless_(rhs.typeless_),
- schemaMap_(std::move(rhs.schemaMap_)),
- schemaRef_(std::move(rhs.schemaRef_))
- {
- rhs.remoteProvider_ = 0;
- rhs.allocator_ = 0;
- rhs.ownAllocator_ = 0;
- rhs.typeless_ = 0;
- }
-#endif
-
- //! Destructor
- ~GenericSchemaDocument() {
- while (!schemaMap_.Empty())
- schemaMap_.template Pop<SchemaEntry>(1)->~SchemaEntry();
-
- if (typeless_) {
- typeless_->~SchemaType();
- Allocator::Free(typeless_);
- }
-
- RAPIDJSON_DELETE(ownAllocator_);
- }
-
- //! Get the root schema.
- const SchemaType& GetRoot() const { return *root_; }
-
-private:
- //! Prohibit copying
- GenericSchemaDocument(const GenericSchemaDocument&);
- //! Prohibit assignment
- GenericSchemaDocument& operator=(const GenericSchemaDocument&);
-
- struct SchemaRefEntry {
- SchemaRefEntry(const PointerType& s, const PointerType& t, const SchemaType** outSchema, Allocator *allocator) : source(s, allocator), target(t, allocator), schema(outSchema) {}
- PointerType source;
- PointerType target;
- const SchemaType** schema;
- };
-
- struct SchemaEntry {
- SchemaEntry(const PointerType& p, SchemaType* s, bool o, Allocator* allocator) : pointer(p, allocator), schema(s), owned(o) {}
- ~SchemaEntry() {
- if (owned) {
- schema->~SchemaType();
- Allocator::Free(schema);
- }
- }
- PointerType pointer;
- SchemaType* schema;
- bool owned;
- };
-
- void CreateSchemaRecursive(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) {
- if (schema)
- *schema = typeless_;
-
- if (v.GetType() == kObjectType) {
- const SchemaType* s = GetSchema(pointer);
- if (!s)
- CreateSchema(schema, pointer, v, document);
-
- for (typename ValueType::ConstMemberIterator itr = v.MemberBegin(); itr != v.MemberEnd(); ++itr)
- CreateSchemaRecursive(0, pointer.Append(itr->name, allocator_), itr->value, document);
- }
- else if (v.GetType() == kArrayType)
- for (SizeType i = 0; i < v.Size(); i++)
- CreateSchemaRecursive(0, pointer.Append(i, allocator_), v[i], document);
- }
-
- void CreateSchema(const SchemaType** schema, const PointerType& pointer, const ValueType& v, const ValueType& document) {
- RAPIDJSON_ASSERT(pointer.IsValid());
- if (v.IsObject()) {
- if (!HandleRefSchema(pointer, schema, v, document)) {
- SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, document, allocator_);
- new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(pointer, s, true, allocator_);
- if (schema)
- *schema = s;
- }
- }
- }
-
- bool HandleRefSchema(const PointerType& source, const SchemaType** schema, const ValueType& v, const ValueType& document) {
- static const Ch kRefString[] = { '$', 'r', 'e', 'f', '\0' };
- static const ValueType kRefValue(kRefString, 4);
-
- typename ValueType::ConstMemberIterator itr = v.FindMember(kRefValue);
- if (itr == v.MemberEnd())
- return false;
-
- if (itr->value.IsString()) {
- SizeType len = itr->value.GetStringLength();
- if (len > 0) {
- const Ch* s = itr->value.GetString();
- SizeType i = 0;
- while (i < len && s[i] != '#') // Find the first #
- i++;
-
- if (i > 0) { // Remote reference, resolve immediately
- if (remoteProvider_) {
- if (const GenericSchemaDocument* remoteDocument = remoteProvider_->GetRemoteDocument(s, i)) {
- PointerType pointer(&s[i], len - i, allocator_);
- if (pointer.IsValid()) {
- if (const SchemaType* sc = remoteDocument->GetSchema(pointer)) {
- if (schema)
- *schema = sc;
- return true;
- }
- }
- }
- }
- }
- else if (s[i] == '#') { // Local reference, defer resolution
- PointerType pointer(&s[i], len - i, allocator_);
- if (pointer.IsValid()) {
- if (const ValueType* nv = pointer.Get(document))
- if (HandleRefSchema(source, schema, *nv, document))
- return true;
-
- new (schemaRef_.template Push<SchemaRefEntry>()) SchemaRefEntry(source, pointer, schema, allocator_);
- return true;
- }
- }
- }
- }
- return false;
- }
-
- const SchemaType* GetSchema(const PointerType& pointer) const {
- for (const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>(); target != schemaMap_.template End<SchemaEntry>(); ++target)
- if (pointer == target->pointer)
- return target->schema;
- return 0;
- }
-
- PointerType GetPointer(const SchemaType* schema) const {
- for (const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>(); target != schemaMap_.template End<SchemaEntry>(); ++target)
- if (schema == target->schema)
- return target->pointer;
- return PointerType();
- }
-
- const SchemaType* GetTypeless() const { return typeless_; }
-
- static const size_t kInitialSchemaMapSize = 64;
- static const size_t kInitialSchemaRefSize = 64;
-
- IRemoteSchemaDocumentProviderType* remoteProvider_;
- Allocator *allocator_;
- Allocator *ownAllocator_;
- const SchemaType* root_; //!< Root schema.
- SchemaType* typeless_;
- internal::Stack<Allocator> schemaMap_; // Stores created Pointer -> Schemas
- internal::Stack<Allocator> schemaRef_; // Stores Pointer from $ref and schema which holds the $ref
-};
-
-//! GenericSchemaDocument using Value type.
-typedef GenericSchemaDocument<Value> SchemaDocument;
-//! IGenericRemoteSchemaDocumentProvider using SchemaDocument.
-typedef IGenericRemoteSchemaDocumentProvider<SchemaDocument> IRemoteSchemaDocumentProvider;
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericSchemaValidator
-
-//! JSON Schema Validator.
-/*!
- A SAX style JSON schema validator.
- It uses a \c GenericSchemaDocument to validate SAX events.
- It delegates the incoming SAX events to an output handler.
- The default output handler does nothing.
- It can be reused multiple times by calling \c Reset().
-
- \tparam SchemaDocumentType Type of schema document.
- \tparam OutputHandler Type of output handler. Default handler does nothing.
- \tparam StateAllocator Allocator for storing the internal validation states.
-*/
-template <
- typename SchemaDocumentType,
- typename OutputHandler = BaseReaderHandler<typename SchemaDocumentType::SchemaType::EncodingType>,
- typename StateAllocator = CrtAllocator>
-class GenericSchemaValidator :
- public internal::ISchemaStateFactory<typename SchemaDocumentType::SchemaType>,
- public internal::ISchemaValidator
-{
-public:
- typedef typename SchemaDocumentType::SchemaType SchemaType;
- typedef typename SchemaDocumentType::PointerType PointerType;
- typedef typename SchemaType::EncodingType EncodingType;
- typedef typename EncodingType::Ch Ch;
-
- //! Constructor without output handler.
- /*!
- \param schemaDocument The schema document to conform to.
- \param allocator Optional allocator for storing internal validation states.
- \param schemaStackCapacity Optional initial capacity of schema path stack.
- \param documentStackCapacity Optional initial capacity of document path stack.
- */
- GenericSchemaValidator(
- const SchemaDocumentType& schemaDocument,
- StateAllocator* allocator = 0,
- size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
- size_t documentStackCapacity = kDefaultDocumentStackCapacity)
- :
- schemaDocument_(&schemaDocument),
- root_(schemaDocument.GetRoot()),
- stateAllocator_(allocator),
- ownStateAllocator_(0),
- schemaStack_(allocator, schemaStackCapacity),
- documentStack_(allocator, documentStackCapacity),
- outputHandler_(0),
- valid_(true)
-#if RAPIDJSON_SCHEMA_VERBOSE
- , depth_(0)
-#endif
- {
- }
-
- //! Constructor with output handler.
- /*!
- \param schemaDocument The schema document to conform to.
- \param allocator Optional allocator for storing internal validation states.
- \param schemaStackCapacity Optional initial capacity of schema path stack.
- \param documentStackCapacity Optional initial capacity of document path stack.
- */
- GenericSchemaValidator(
- const SchemaDocumentType& schemaDocument,
- OutputHandler& outputHandler,
- StateAllocator* allocator = 0,
- size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
- size_t documentStackCapacity = kDefaultDocumentStackCapacity)
- :
- schemaDocument_(&schemaDocument),
- root_(schemaDocument.GetRoot()),
- stateAllocator_(allocator),
- ownStateAllocator_(0),
- schemaStack_(allocator, schemaStackCapacity),
- documentStack_(allocator, documentStackCapacity),
- outputHandler_(&outputHandler),
- valid_(true)
-#if RAPIDJSON_SCHEMA_VERBOSE
- , depth_(0)
-#endif
- {
- }
-
- //! Destructor.
- ~GenericSchemaValidator() {
- Reset();
- RAPIDJSON_DELETE(ownStateAllocator_);
- }
-
- //! Reset the internal states.
- void Reset() {
- while (!schemaStack_.Empty())
- PopSchema();
- documentStack_.Clear();
- valid_ = true;
- }
-
- //! Checks whether the current state is valid.
- // Implementation of ISchemaValidator
- virtual bool IsValid() const { return valid_; }
-
- //! Gets the JSON pointer pointed to the invalid schema.
- PointerType GetInvalidSchemaPointer() const {
- return schemaStack_.Empty() ? PointerType() : schemaDocument_->GetPointer(&CurrentSchema());
- }
-
- //! Gets the keyword of invalid schema.
- const Ch* GetInvalidSchemaKeyword() const {
- return schemaStack_.Empty() ? 0 : CurrentContext().invalidKeyword;
- }
-
- //! Gets the JSON pointer pointed to the invalid value.
- PointerType GetInvalidDocumentPointer() const {
- return documentStack_.Empty() ? PointerType() : PointerType(documentStack_.template Bottom<Ch>(), documentStack_.GetSize() / sizeof(Ch));
- }
-
-#if RAPIDJSON_SCHEMA_VERBOSE
-#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() \
-RAPIDJSON_MULTILINEMACRO_BEGIN\
- *documentStack_.template Push<Ch>() = '\0';\
- documentStack_.template Pop<Ch>(1);\
- internal::PrintInvalidDocument(documentStack_.template Bottom<Ch>());\
-RAPIDJSON_MULTILINEMACRO_END
-#else
-#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_()
-#endif
-
-#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\
- if (!valid_) return false; \
- if (!BeginValue() || !CurrentSchema().method arg1) {\
- RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\
- return valid_ = false;\
- }
-
-#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\
- for (Context* context = schemaStack_.template Bottom<Context>(); context != schemaStack_.template End<Context>(); context++) {\
- if (context->hasher)\
- static_cast<HasherType*>(context->hasher)->method arg2;\
- if (context->validators)\
- for (SizeType i_ = 0; i_ < context->validatorCount; i_++)\
- static_cast<GenericSchemaValidator*>(context->validators[i_])->method arg2;\
- if (context->patternPropertiesValidators)\
- for (SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++)\
- static_cast<GenericSchemaValidator*>(context->patternPropertiesValidators[i_])->method arg2;\
- }
-
-#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)\
- return valid_ = EndValue() && (!outputHandler_ || outputHandler_->method arg2)
-
-#define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \
- RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);\
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2);\
- RAPIDJSON_SCHEMA_HANDLE_END_ (method, arg2)
-
- bool Null() { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Null, (CurrentContext() ), ( )); }
- bool Bool(bool b) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Bool, (CurrentContext(), b), (b)); }
- bool Int(int i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int, (CurrentContext(), i), (i)); }
- bool Uint(unsigned u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint, (CurrentContext(), u), (u)); }
- bool Int64(int64_t i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int64, (CurrentContext(), i), (i)); }
- bool Uint64(uint64_t u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint64, (CurrentContext(), u), (u)); }
- bool Double(double d) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Double, (CurrentContext(), d), (d)); }
- bool RawNumber(const Ch* str, SizeType length, bool copy)
- { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
- bool String(const Ch* str, SizeType length, bool copy)
- { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
-
- bool StartObject() {
- RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext()));
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartObject, ());
- return valid_ = !outputHandler_ || outputHandler_->StartObject();
- }
-
- bool Key(const Ch* str, SizeType len, bool copy) {
- if (!valid_) return false;
- AppendToken(str, len);
- if (!CurrentSchema().Key(CurrentContext(), str, len, copy)) return valid_ = false;
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(Key, (str, len, copy));
- return valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy);
- }
-
- bool EndObject(SizeType memberCount) {
- if (!valid_) return false;
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndObject, (memberCount));
- if (!CurrentSchema().EndObject(CurrentContext(), memberCount)) return valid_ = false;
- RAPIDJSON_SCHEMA_HANDLE_END_(EndObject, (memberCount));
- }
-
- bool StartArray() {
- RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartArray, (CurrentContext()));
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartArray, ());
- return valid_ = !outputHandler_ || outputHandler_->StartArray();
- }
-
- bool EndArray(SizeType elementCount) {
- if (!valid_) return false;
- RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndArray, (elementCount));
- if (!CurrentSchema().EndArray(CurrentContext(), elementCount)) return valid_ = false;
- RAPIDJSON_SCHEMA_HANDLE_END_(EndArray, (elementCount));
- }
-
-#undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_
-#undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_
-#undef RAPIDJSON_SCHEMA_HANDLE_PARALLEL_
-#undef RAPIDJSON_SCHEMA_HANDLE_VALUE_
-
- // Implementation of ISchemaStateFactory<SchemaType>
- virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root) {
- return new (GetStateAllocator().Malloc(sizeof(GenericSchemaValidator))) GenericSchemaValidator(*schemaDocument_, root,
-#if RAPIDJSON_SCHEMA_VERBOSE
- depth_ + 1,
-#endif
- &GetStateAllocator());
- }
-
- virtual void DestroySchemaValidator(ISchemaValidator* validator) {
- GenericSchemaValidator* v = static_cast<GenericSchemaValidator*>(validator);
- v->~GenericSchemaValidator();
- StateAllocator::Free(v);
- }
-
- virtual void* CreateHasher() {
- return new (GetStateAllocator().Malloc(sizeof(HasherType))) HasherType(&GetStateAllocator());
- }
-
- virtual uint64_t GetHashCode(void* hasher) {
- return static_cast<HasherType*>(hasher)->GetHashCode();
- }
-
- virtual void DestroryHasher(void* hasher) {
- HasherType* h = static_cast<HasherType*>(hasher);
- h->~HasherType();
- StateAllocator::Free(h);
- }
-
- virtual void* MallocState(size_t size) {
- return GetStateAllocator().Malloc(size);
- }
-
- virtual void FreeState(void* p) {
- StateAllocator::Free(p);
- }
-
-private:
- typedef typename SchemaType::Context Context;
- typedef GenericValue<UTF8<>, StateAllocator> HashCodeArray;
- typedef internal::Hasher<EncodingType, StateAllocator> HasherType;
-
- GenericSchemaValidator(
- const SchemaDocumentType& schemaDocument,
- const SchemaType& root,
-#if RAPIDJSON_SCHEMA_VERBOSE
- unsigned depth,
-#endif
- StateAllocator* allocator = 0,
- size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
- size_t documentStackCapacity = kDefaultDocumentStackCapacity)
- :
- schemaDocument_(&schemaDocument),
- root_(root),
- stateAllocator_(allocator),
- ownStateAllocator_(0),
- schemaStack_(allocator, schemaStackCapacity),
- documentStack_(allocator, documentStackCapacity),
- outputHandler_(0),
- valid_(true)
-#if RAPIDJSON_SCHEMA_VERBOSE
- , depth_(depth)
-#endif
- {
- }
-
- StateAllocator& GetStateAllocator() {
- if (!stateAllocator_)
- stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator)();
- return *stateAllocator_;
- }
-
- bool BeginValue() {
- if (schemaStack_.Empty())
- PushSchema(root_);
- else {
- if (CurrentContext().inArray)
- internal::TokenHelper<internal::Stack<StateAllocator>, Ch>::AppendIndexToken(documentStack_, CurrentContext().arrayElementIndex);
-
- if (!CurrentSchema().BeginValue(CurrentContext()))
- return false;
-
- SizeType count = CurrentContext().patternPropertiesSchemaCount;
- const SchemaType** sa = CurrentContext().patternPropertiesSchemas;
- typename Context::PatternValidatorType patternValidatorType = CurrentContext().valuePatternValidatorType;
- bool valueUniqueness = CurrentContext().valueUniqueness;
- RAPIDJSON_ASSERT(CurrentContext().valueSchema);
- PushSchema(*CurrentContext().valueSchema);
-
- if (count > 0) {
- CurrentContext().objectPatternValidatorType = patternValidatorType;
- ISchemaValidator**& va = CurrentContext().patternPropertiesValidators;
- SizeType& validatorCount = CurrentContext().patternPropertiesValidatorCount;
- va = static_cast<ISchemaValidator**>(MallocState(sizeof(ISchemaValidator*) * count));
- for (SizeType i = 0; i < count; i++)
- va[validatorCount++] = CreateSchemaValidator(*sa[i]);
- }
-
- CurrentContext().arrayUniqueness = valueUniqueness;
- }
- return true;
- }
-
- bool EndValue() {
- if (!CurrentSchema().EndValue(CurrentContext()))
- return false;
-
-#if RAPIDJSON_SCHEMA_VERBOSE
- GenericStringBuffer<EncodingType> sb;
- schemaDocument_->GetPointer(&CurrentSchema()).Stringify(sb);
-
- *documentStack_.template Push<Ch>() = '\0';
- documentStack_.template Pop<Ch>(1);
- internal::PrintValidatorPointers(depth_, sb.GetString(), documentStack_.template Bottom<Ch>());
-#endif
-
- uint64_t h = CurrentContext().arrayUniqueness ? static_cast<HasherType*>(CurrentContext().hasher)->GetHashCode() : 0;
-
- PopSchema();
-
- if (!schemaStack_.Empty()) {
- Context& context = CurrentContext();
- if (context.valueUniqueness) {
- HashCodeArray* a = static_cast<HashCodeArray*>(context.arrayElementHashCodes);
- if (!a)
- CurrentContext().arrayElementHashCodes = a = new (GetStateAllocator().Malloc(sizeof(HashCodeArray))) HashCodeArray(kArrayType);
- for (typename HashCodeArray::ConstValueIterator itr = a->Begin(); itr != a->End(); ++itr)
- if (itr->GetUint64() == h)
- RAPIDJSON_INVALID_KEYWORD_RETURN(SchemaType::GetUniqueItemsString());
- a->PushBack(h, GetStateAllocator());
- }
- }
-
- // Remove the last token of document pointer
- while (!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) != '/')
- ;
-
- return true;
- }
-
- void AppendToken(const Ch* str, SizeType len) {
- documentStack_.template Reserve<Ch>(1 + len * 2); // worst case all characters are escaped as two characters
- *documentStack_.template PushUnsafe<Ch>() = '/';
- for (SizeType i = 0; i < len; i++) {
- if (str[i] == '~') {
- *documentStack_.template PushUnsafe<Ch>() = '~';
- *documentStack_.template PushUnsafe<Ch>() = '0';
- }
- else if (str[i] == '/') {
- *documentStack_.template PushUnsafe<Ch>() = '~';
- *documentStack_.template PushUnsafe<Ch>() = '1';
- }
- else
- *documentStack_.template PushUnsafe<Ch>() = str[i];
- }
- }
-
- RAPIDJSON_FORCEINLINE void PushSchema(const SchemaType& schema) { new (schemaStack_.template Push<Context>()) Context(*this, &schema); }
-
- RAPIDJSON_FORCEINLINE void PopSchema() {
- Context* c = schemaStack_.template Pop<Context>(1);
- if (HashCodeArray* a = static_cast<HashCodeArray*>(c->arrayElementHashCodes)) {
- a->~HashCodeArray();
- StateAllocator::Free(a);
- }
- c->~Context();
- }
-
- const SchemaType& CurrentSchema() const { return *schemaStack_.template Top<Context>()->schema; }
- Context& CurrentContext() { return *schemaStack_.template Top<Context>(); }
- const Context& CurrentContext() const { return *schemaStack_.template Top<Context>(); }
-
- static const size_t kDefaultSchemaStackCapacity = 1024;
- static const size_t kDefaultDocumentStackCapacity = 256;
- const SchemaDocumentType* schemaDocument_;
- const SchemaType& root_;
- StateAllocator* stateAllocator_;
- StateAllocator* ownStateAllocator_;
- internal::Stack<StateAllocator> schemaStack_; //!< stack to store the current path of schema (BaseSchemaType *)
- internal::Stack<StateAllocator> documentStack_; //!< stack to store the current path of validating document (Ch)
- OutputHandler* outputHandler_;
- bool valid_;
-#if RAPIDJSON_SCHEMA_VERBOSE
- unsigned depth_;
-#endif
-};
-
-typedef GenericSchemaValidator<SchemaDocument> SchemaValidator;
-
-///////////////////////////////////////////////////////////////////////////////
-// SchemaValidatingReader
-
-//! A helper class for parsing with validation.
-/*!
- This helper class is a functor, designed as a parameter of \ref GenericDocument::Populate().
-
- \tparam parseFlags Combination of \ref ParseFlag.
- \tparam InputStream Type of input stream, implementing Stream concept.
- \tparam SourceEncoding Encoding of the input stream.
- \tparam SchemaDocumentType Type of schema document.
- \tparam StackAllocator Allocator type for stack.
-*/
-template <
- unsigned parseFlags,
- typename InputStream,
- typename SourceEncoding,
- typename SchemaDocumentType = SchemaDocument,
- typename StackAllocator = CrtAllocator>
-class SchemaValidatingReader {
-public:
- typedef typename SchemaDocumentType::PointerType PointerType;
- typedef typename InputStream::Ch Ch;
-
- //! Constructor
- /*!
- \param is Input stream.
- \param sd Schema document.
- */
- SchemaValidatingReader(InputStream& is, const SchemaDocumentType& sd) : is_(is), sd_(sd), invalidSchemaKeyword_(), isValid_(true) {}
-
- template <typename Handler>
- bool operator()(Handler& handler) {
- GenericReader<SourceEncoding, typename SchemaDocumentType::EncodingType, StackAllocator> reader;
- GenericSchemaValidator<SchemaDocumentType, Handler> validator(sd_, handler);
- parseResult_ = reader.template Parse<parseFlags>(is_, validator);
-
- isValid_ = validator.IsValid();
- if (isValid_) {
- invalidSchemaPointer_ = PointerType();
- invalidSchemaKeyword_ = 0;
- invalidDocumentPointer_ = PointerType();
- }
- else {
- invalidSchemaPointer_ = validator.GetInvalidSchemaPointer();
- invalidSchemaKeyword_ = validator.GetInvalidSchemaKeyword();
- invalidDocumentPointer_ = validator.GetInvalidDocumentPointer();
- }
-
- return parseResult_;
- }
-
- const ParseResult& GetParseResult() const { return parseResult_; }
- bool IsValid() const { return isValid_; }
- const PointerType& GetInvalidSchemaPointer() const { return invalidSchemaPointer_; }
- const Ch* GetInvalidSchemaKeyword() const { return invalidSchemaKeyword_; }
- const PointerType& GetInvalidDocumentPointer() const { return invalidDocumentPointer_; }
-
-private:
- InputStream& is_;
- const SchemaDocumentType& sd_;
-
- ParseResult parseResult_;
- PointerType invalidSchemaPointer_;
- const Ch* invalidSchemaKeyword_;
- PointerType invalidDocumentPointer_;
- bool isValid_;
-};
-
-RAPIDJSON_NAMESPACE_END
-RAPIDJSON_DIAG_POP
-
-#endif // RAPIDJSON_SCHEMA_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stream.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stream.h
deleted file mode 100644
index fef82c252..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stream.h
+++ /dev/null
@@ -1,179 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#include "rapidjson.h"
-
-#ifndef RAPIDJSON_STREAM_H_
-#define RAPIDJSON_STREAM_H_
-
-#include "encodings.h"
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// Stream
-
-/*! \class rapidjson::Stream
- \brief Concept for reading and writing characters.
-
- For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd().
-
- For write-only stream, only need to implement Put() and Flush().
-
-\code
-concept Stream {
- typename Ch; //!< Character type of the stream.
-
- //! Read the current character from stream without moving the read cursor.
- Ch Peek() const;
-
- //! Read the current character from stream and moving the read cursor to next character.
- Ch Take();
-
- //! Get the current read cursor.
- //! \return Number of characters read from start.
- size_t Tell();
-
- //! Begin writing operation at the current read pointer.
- //! \return The begin writer pointer.
- Ch* PutBegin();
-
- //! Write a character.
- void Put(Ch c);
-
- //! Flush the buffer.
- void Flush();
-
- //! End the writing operation.
- //! \param begin The begin write pointer returned by PutBegin().
- //! \return Number of characters written.
- size_t PutEnd(Ch* begin);
-}
-\endcode
-*/
-
-//! Provides additional information for stream.
-/*!
- By using traits pattern, this type provides a default configuration for stream.
- For custom stream, this type can be specialized for other configuration.
- See TEST(Reader, CustomStringStream) in readertest.cpp for example.
-*/
-template<typename Stream>
-struct StreamTraits {
- //! Whether to make local copy of stream for optimization during parsing.
- /*!
- By default, for safety, streams do not use local copy optimization.
- Stream that can be copied fast should specialize this, like StreamTraits<StringStream>.
- */
- enum { copyOptimization = 0 };
-};
-
-//! Reserve n characters for writing to a stream.
-template<typename Stream>
-inline void PutReserve(Stream& stream, size_t count) {
- (void)stream;
- (void)count;
-}
-
-//! Write character to a stream, presuming buffer is reserved.
-template<typename Stream>
-inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
- stream.Put(c);
-}
-
-//! Put N copies of a character to a stream.
-template<typename Stream, typename Ch>
-inline void PutN(Stream& stream, Ch c, size_t n) {
- PutReserve(stream, n);
- for (size_t i = 0; i < n; i++)
- PutUnsafe(stream, c);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// StringStream
-
-//! Read-only string stream.
-/*! \note implements Stream concept
-*/
-template <typename Encoding>
-struct GenericStringStream {
- typedef typename Encoding::Ch Ch;
-
- GenericStringStream(const Ch *src) : src_(src), head_(src) {}
-
- Ch Peek() const { return *src_; }
- Ch Take() { return *src_++; }
- size_t Tell() const { return static_cast<size_t>(src_ - head_); }
-
- Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
- void Put(Ch) { RAPIDJSON_ASSERT(false); }
- void Flush() { RAPIDJSON_ASSERT(false); }
- size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
-
- const Ch* src_; //!< Current read position.
- const Ch* head_; //!< Original head of the string.
-};
-
-template <typename Encoding>
-struct StreamTraits<GenericStringStream<Encoding> > {
- enum { copyOptimization = 1 };
-};
-
-//! String stream with UTF8 encoding.
-typedef GenericStringStream<UTF8<> > StringStream;
-
-///////////////////////////////////////////////////////////////////////////////
-// InsituStringStream
-
-//! A read-write string stream.
-/*! This string stream is particularly designed for in-situ parsing.
- \note implements Stream concept
-*/
-template <typename Encoding>
-struct GenericInsituStringStream {
- typedef typename Encoding::Ch Ch;
-
- GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {}
-
- // Read
- Ch Peek() { return *src_; }
- Ch Take() { return *src_++; }
- size_t Tell() { return static_cast<size_t>(src_ - head_); }
-
- // Write
- void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
-
- Ch* PutBegin() { return dst_ = src_; }
- size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
- void Flush() {}
-
- Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
- void Pop(size_t count) { dst_ -= count; }
-
- Ch* src_;
- Ch* dst_;
- Ch* head_;
-};
-
-template <typename Encoding>
-struct StreamTraits<GenericInsituStringStream<Encoding> > {
- enum { copyOptimization = 1 };
-};
-
-//! Insitu string stream with UTF8 encoding.
-typedef GenericInsituStringStream<UTF8<> > InsituStringStream;
-
-RAPIDJSON_NAMESPACE_END
-
-#endif // RAPIDJSON_STREAM_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stringbuffer.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stringbuffer.h
deleted file mode 100644
index 4e38b82c3..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/stringbuffer.h
+++ /dev/null
@@ -1,121 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_STRINGBUFFER_H_
-#define RAPIDJSON_STRINGBUFFER_H_
-
-#include "stream.h"
-#include "internal/stack.h"
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
-#include <utility> // std::move
-#endif
-
-#include "internal/stack.h"
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-//! Represents an in-memory output stream.
-/*!
- \tparam Encoding Encoding of the stream.
- \tparam Allocator type for allocating memory buffer.
- \note implements Stream concept
-*/
-template <typename Encoding, typename Allocator = CrtAllocator>
-class GenericStringBuffer {
-public:
- typedef typename Encoding::Ch Ch;
-
- GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {}
- GenericStringBuffer& operator=(GenericStringBuffer&& rhs) {
- if (&rhs != this)
- stack_ = std::move(rhs.stack_);
- return *this;
- }
-#endif
-
- void Put(Ch c) { *stack_.template Push<Ch>() = c; }
- void PutUnsafe(Ch c) { *stack_.template PushUnsafe<Ch>() = c; }
- void Flush() {}
-
- void Clear() { stack_.Clear(); }
- void ShrinkToFit() {
- // Push and pop a null terminator. This is safe.
- *stack_.template Push<Ch>() = '\0';
- stack_.ShrinkToFit();
- stack_.template Pop<Ch>(1);
- }
-
- void Reserve(size_t count) { stack_.template Reserve<Ch>(count); }
- Ch* Push(size_t count) { return stack_.template Push<Ch>(count); }
- Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe<Ch>(count); }
- void Pop(size_t count) { stack_.template Pop<Ch>(count); }
-
- const Ch* GetString() const {
- // Push and pop a null terminator. This is safe.
- *stack_.template Push<Ch>() = '\0';
- stack_.template Pop<Ch>(1);
-
- return stack_.template Bottom<Ch>();
- }
-
- //! Get the size of string in bytes in the string buffer.
- size_t GetSize() const { return stack_.GetSize(); }
-
- //! Get the length of string in Ch in the string buffer.
- size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); }
-
- static const size_t kDefaultCapacity = 256;
- mutable internal::Stack<Allocator> stack_;
-
-private:
- // Prohibit copy constructor & assignment operator.
- GenericStringBuffer(const GenericStringBuffer&);
- GenericStringBuffer& operator=(const GenericStringBuffer&);
-};
-
-//! String buffer with UTF8 encoding
-typedef GenericStringBuffer<UTF8<> > StringBuffer;
-
-template<typename Encoding, typename Allocator>
-inline void PutReserve(GenericStringBuffer<Encoding, Allocator>& stream, size_t count) {
- stream.Reserve(count);
-}
-
-template<typename Encoding, typename Allocator>
-inline void PutUnsafe(GenericStringBuffer<Encoding, Allocator>& stream, typename Encoding::Ch c) {
- stream.PutUnsafe(c);
-}
-
-//! Implement specialized version of PutN() with memset() for better performance.
-template<>
-inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
- std::memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
-}
-
-RAPIDJSON_NAMESPACE_END
-
-#if defined(__clang__)
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_STRINGBUFFER_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/writer.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/writer.h
deleted file mode 100644
index e610ebb60..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/writer.h
+++ /dev/null
@@ -1,711 +0,0 @@
-// Tencent is pleased to support the open source community by making RapidJSON available.
-//
-// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-//
-// Licensed under the MIT License (the "License"); you may not use this file except
-// in compliance with the License. You may obtain a copy of the License at
-//
-// http://opensource.org/licenses/MIT
-//
-// Unless required by applicable law or agreed to in writing, software distributed
-// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-// CONDITIONS OF ANY KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations under the License.
-
-#ifndef RAPIDJSON_WRITER_H_
-#define RAPIDJSON_WRITER_H_
-
-#include "stream.h"
-#include "internal/meta.h"
-#include "internal/stack.h"
-#include "internal/strfunc.h"
-#include "internal/dtoa.h"
-#include "internal/itoa.h"
-#include "stringbuffer.h"
-#include <new> // placement new
-
-#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER)
-#include <intrin.h>
-#pragma intrinsic(_BitScanForward)
-#endif
-#ifdef RAPIDJSON_SSE42
-#include <nmmintrin.h>
-#elif defined(RAPIDJSON_SSE2)
-#include <emmintrin.h>
-#elif defined(RAPIDJSON_NEON)
-#include <arm_neon.h>
-#endif
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_PUSH
-RAPIDJSON_DIAG_OFF(padded)
-RAPIDJSON_DIAG_OFF(unreachable-code)
-RAPIDJSON_DIAG_OFF(c++98-compat)
-#endif
-
-RAPIDJSON_NAMESPACE_BEGIN
-
-///////////////////////////////////////////////////////////////////////////////
-// WriteFlag
-
-/*! \def RAPIDJSON_WRITE_DEFAULT_FLAGS
- \ingroup RAPIDJSON_CONFIG
- \brief User-defined kWriteDefaultFlags definition.
-
- User can define this as any \c WriteFlag combinations.
-*/
-#ifndef RAPIDJSON_WRITE_DEFAULT_FLAGS
-#define RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNoFlags
-#endif
-
-//! Combination of writeFlags
-enum WriteFlag {
- kWriteNoFlags = 0, //!< No flags are set.
- kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings.
- kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN.
- kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS
-};
-
-//! JSON writer
-/*! Writer implements the concept Handler.
- It generates JSON text by events to an output os.
-
- User may programmatically calls the functions of a writer to generate JSON text.
-
- On the other side, a writer can also be passed to objects that generates events,
-
- for example Reader::Parse() and Document::Accept().
-
- \tparam OutputStream Type of output stream.
- \tparam SourceEncoding Encoding of source string.
- \tparam TargetEncoding Encoding of output stream.
- \tparam StackAllocator Type of allocator for allocating memory of stack.
- \note implements Handler concept
-*/
-template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
-class Writer {
-public:
- typedef typename SourceEncoding::Ch Ch;
-
- static const int kDefaultMaxDecimalPlaces = 324;
-
- //! Constructor
- /*! \param os Output stream.
- \param stackAllocator User supplied allocator. If it is null, it will create a private one.
- \param levelDepth Initial capacity of stack.
- */
- explicit
- Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = kDefaultLevelDepth) :
- os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
-
- explicit
- Writer(StackAllocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
- os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
-
-#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
- Writer(Writer&& rhs) :
- os_(rhs.os_), level_stack_(std::move(rhs.level_stack_)), maxDecimalPlaces_(rhs.maxDecimalPlaces_), hasRoot_(rhs.hasRoot_) {
- rhs.os_ = 0;
- }
-#endif
-
- //! Reset the writer with a new stream.
- /*!
- This function reset the writer with a new stream and default settings,
- in order to make a Writer object reusable for output multiple JSONs.
-
- \param os New output stream.
- \code
- Writer<OutputStream> writer(os1);
- writer.StartObject();
- // ...
- writer.EndObject();
-
- writer.Reset(os2);
- writer.StartObject();
- // ...
- writer.EndObject();
- \endcode
- */
- void Reset(OutputStream& os) {
- os_ = &os;
- hasRoot_ = false;
- level_stack_.Clear();
- }
-
- //! Checks whether the output is a complete JSON.
- /*!
- A complete JSON has a complete root object or array.
- */
- bool IsComplete() const {
- return hasRoot_ && level_stack_.Empty();
- }
-
- int GetMaxDecimalPlaces() const {
- return maxDecimalPlaces_;
- }
-
- //! Sets the maximum number of decimal places for double output.
- /*!
- This setting truncates the output with specified number of decimal places.
-
- For example,
-
- \code
- writer.SetMaxDecimalPlaces(3);
- writer.StartArray();
- writer.Double(0.12345); // "0.123"
- writer.Double(0.0001); // "0.0"
- writer.Double(1.234567890123456e30); // "1.234567890123456e30" (do not truncate significand for positive exponent)
- writer.Double(1.23e-4); // "0.0" (do truncate significand for negative exponent)
- writer.EndArray();
- \endcode
-
- The default setting does not truncate any decimal places. You can restore to this setting by calling
- \code
- writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces);
- \endcode
- */
- void SetMaxDecimalPlaces(int maxDecimalPlaces) {
- maxDecimalPlaces_ = maxDecimalPlaces;
- }
-
- /*!@name Implementation of Handler
- \see Handler
- */
- //@{
-
- bool Null() { Prefix(kNullType); return EndValue(WriteNull()); }
- bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); }
- bool Int(int i) { Prefix(kNumberType); return EndValue(WriteInt(i)); }
- bool Uint(unsigned u) { Prefix(kNumberType); return EndValue(WriteUint(u)); }
- bool Int64(int64_t i64) { Prefix(kNumberType); return EndValue(WriteInt64(i64)); }
- bool Uint64(uint64_t u64) { Prefix(kNumberType); return EndValue(WriteUint64(u64)); }
-
- //! Writes the given \c double value to the stream
- /*!
- \param d The value to be written.
- \return Whether it is succeed.
- */
- bool Double(double d) { Prefix(kNumberType); return EndValue(WriteDouble(d)); }
-
- bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
- RAPIDJSON_ASSERT(str != 0);
- (void)copy;
- Prefix(kNumberType);
- return EndValue(WriteString(str, length));
- }
-
- bool String(const Ch* str, SizeType length, bool copy = false) {
- RAPIDJSON_ASSERT(str != 0);
- (void)copy;
- Prefix(kStringType);
- return EndValue(WriteString(str, length));
- }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool String(const std::basic_string<Ch>& str) {
- return String(str.data(), SizeType(str.size()));
- }
-#endif
-
- bool StartObject() {
- Prefix(kObjectType);
- new (level_stack_.template Push<Level>()) Level(false);
- return WriteStartObject();
- }
-
- bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
-
-#if RAPIDJSON_HAS_STDSTRING
- bool Key(const std::basic_string<Ch>& str)
- {
- return Key(str.data(), SizeType(str.size()));
- }
-#endif
-
- bool EndObject(SizeType memberCount = 0) {
- (void)memberCount;
- RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object
- RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray); // currently inside an Array, not Object
- RAPIDJSON_ASSERT(0 == level_stack_.template Top<Level>()->valueCount % 2); // Object has a Key without a Value
- level_stack_.template Pop<Level>(1);
- return EndValue(WriteEndObject());
- }
-
- bool StartArray() {
- Prefix(kArrayType);
- new (level_stack_.template Push<Level>()) Level(true);
- return WriteStartArray();
- }
-
- bool EndArray(SizeType elementCount = 0) {
- (void)elementCount;
- RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
- RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
- level_stack_.template Pop<Level>(1);
- return EndValue(WriteEndArray());
- }
- //@}
-
- /*! @name Convenience extensions */
- //@{
-
- //! Simpler but slower overload.
- bool String(const Ch* const& str) { return String(str, internal::StrLen(str)); }
- bool Key(const Ch* const& str) { return Key(str, internal::StrLen(str)); }
-
- //@}
-
- //! Write a raw JSON value.
- /*!
- For user to write a stringified JSON as a value.
-
- \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range.
- \param length Length of the json.
- \param type Type of the root of json.
- */
- bool RawValue(const Ch* json, size_t length, Type type) {
- RAPIDJSON_ASSERT(json != 0);
- Prefix(type);
- return EndValue(WriteRawValue(json, length));
- }
-
- //! Flush the output stream.
- /*!
- Allows the user to flush the output stream immediately.
- */
- void Flush() {
- os_->Flush();
- }
-
-protected:
- //! Information for each nested level
- struct Level {
- Level(bool inArray_) : valueCount(0), inArray(inArray_) {}
- size_t valueCount; //!< number of values in this level
- bool inArray; //!< true if in array, otherwise in object
- };
-
- static const size_t kDefaultLevelDepth = 32;
-
- bool WriteNull() {
- PutReserve(*os_, 4);
- PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true;
- }
-
- bool WriteBool(bool b) {
- if (b) {
- PutReserve(*os_, 4);
- PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'r'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'e');
- }
- else {
- PutReserve(*os_, 5);
- PutUnsafe(*os_, 'f'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 's'); PutUnsafe(*os_, 'e');
- }
- return true;
- }
-
- bool WriteInt(int i) {
- char buffer[11];
- const char* end = internal::i32toa(i, buffer);
- PutReserve(*os_, static_cast<size_t>(end - buffer));
- for (const char* p = buffer; p != end; ++p)
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
- return true;
- }
-
- bool WriteUint(unsigned u) {
- char buffer[10];
- const char* end = internal::u32toa(u, buffer);
- PutReserve(*os_, static_cast<size_t>(end - buffer));
- for (const char* p = buffer; p != end; ++p)
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
- return true;
- }
-
- bool WriteInt64(int64_t i64) {
- char buffer[21];
- const char* end = internal::i64toa(i64, buffer);
- PutReserve(*os_, static_cast<size_t>(end - buffer));
- for (const char* p = buffer; p != end; ++p)
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
- return true;
- }
-
- bool WriteUint64(uint64_t u64) {
- char buffer[20];
- char* end = internal::u64toa(u64, buffer);
- PutReserve(*os_, static_cast<size_t>(end - buffer));
- for (char* p = buffer; p != end; ++p)
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
- return true;
- }
-
- bool WriteDouble(double d) {
- if (internal::Double(d).IsNanOrInf()) {
- if (!(writeFlags & kWriteNanAndInfFlag))
- return false;
- if (internal::Double(d).IsNan()) {
- PutReserve(*os_, 3);
- PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
- return true;
- }
- if (internal::Double(d).Sign()) {
- PutReserve(*os_, 9);
- PutUnsafe(*os_, '-');
- }
- else
- PutReserve(*os_, 8);
- PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
- PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
- return true;
- }
-
- char buffer[25];
- char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
- PutReserve(*os_, static_cast<size_t>(end - buffer));
- for (char* p = buffer; p != end; ++p)
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
- return true;
- }
-
- bool WriteString(const Ch* str, SizeType length) {
- static const typename OutputStream::Ch hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- static const char escape[256] = {
-#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- //0 1 2 3 4 5 6 7 8 9 A B C D E F
- 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
- 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
- 0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
- Z16, Z16, // 30~4F
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
- Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
-#undef Z16
- };
-
- if (TargetEncoding::supportUnicode)
- PutReserve(*os_, 2 + length * 6); // "\uxxxx..."
- else
- PutReserve(*os_, 2 + length * 12); // "\uxxxx\uyyyy..."
-
- PutUnsafe(*os_, '\"');
- GenericStringStream<SourceEncoding> is(str);
- while (ScanWriteUnescapedString(is, length)) {
- const Ch c = is.Peek();
- if (!TargetEncoding::supportUnicode && static_cast<unsigned>(c) >= 0x80) {
- // Unicode escaping
- unsigned codepoint;
- if (RAPIDJSON_UNLIKELY(!SourceEncoding::Decode(is, &codepoint)))
- return false;
- PutUnsafe(*os_, '\\');
- PutUnsafe(*os_, 'u');
- if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) {
- PutUnsafe(*os_, hexDigits[(codepoint >> 12) & 15]);
- PutUnsafe(*os_, hexDigits[(codepoint >> 8) & 15]);
- PutUnsafe(*os_, hexDigits[(codepoint >> 4) & 15]);
- PutUnsafe(*os_, hexDigits[(codepoint ) & 15]);
- }
- else {
- RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF);
- // Surrogate pair
- unsigned s = codepoint - 0x010000;
- unsigned lead = (s >> 10) + 0xD800;
- unsigned trail = (s & 0x3FF) + 0xDC00;
- PutUnsafe(*os_, hexDigits[(lead >> 12) & 15]);
- PutUnsafe(*os_, hexDigits[(lead >> 8) & 15]);
- PutUnsafe(*os_, hexDigits[(lead >> 4) & 15]);
- PutUnsafe(*os_, hexDigits[(lead ) & 15]);
- PutUnsafe(*os_, '\\');
- PutUnsafe(*os_, 'u');
- PutUnsafe(*os_, hexDigits[(trail >> 12) & 15]);
- PutUnsafe(*os_, hexDigits[(trail >> 8) & 15]);
- PutUnsafe(*os_, hexDigits[(trail >> 4) & 15]);
- PutUnsafe(*os_, hexDigits[(trail ) & 15]);
- }
- }
- else if ((sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256) && RAPIDJSON_UNLIKELY(escape[static_cast<unsigned char>(c)])) {
- is.Take();
- PutUnsafe(*os_, '\\');
- PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(escape[static_cast<unsigned char>(c)]));
- if (escape[static_cast<unsigned char>(c)] == 'u') {
- PutUnsafe(*os_, '0');
- PutUnsafe(*os_, '0');
- PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) >> 4]);
- PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) & 0xF]);
- }
- }
- else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
- Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) :
- Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
- return false;
- }
- PutUnsafe(*os_, '\"');
- return true;
- }
-
- bool ScanWriteUnescapedString(GenericStringStream<SourceEncoding>& is, size_t length) {
- return RAPIDJSON_LIKELY(is.Tell() < length);
- }
-
- bool WriteStartObject() { os_->Put('{'); return true; }
- bool WriteEndObject() { os_->Put('}'); return true; }
- bool WriteStartArray() { os_->Put('['); return true; }
- bool WriteEndArray() { os_->Put(']'); return true; }
-
- bool WriteRawValue(const Ch* json, size_t length) {
- PutReserve(*os_, length);
- for (size_t i = 0; i < length; i++) {
- RAPIDJSON_ASSERT(json[i] != '\0');
- PutUnsafe(*os_, json[i]);
- }
- return true;
- }
-
- void Prefix(Type type) {
- (void)type;
- if (RAPIDJSON_LIKELY(level_stack_.GetSize() != 0)) { // this value is not at root
- Level* level = level_stack_.template Top<Level>();
- if (level->valueCount > 0) {
- if (level->inArray)
- os_->Put(','); // add comma if it is not the first element in array
- else // in object
- os_->Put((level->valueCount % 2 == 0) ? ',' : ':');
- }
- if (!level->inArray && level->valueCount % 2 == 0)
- RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
- level->valueCount++;
- }
- else {
- RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
- hasRoot_ = true;
- }
- }
-
- // Flush the value if it is the top level one.
- bool EndValue(bool ret) {
- if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
- Flush();
- return ret;
- }
-
- OutputStream* os_;
- internal::Stack<StackAllocator> level_stack_;
- int maxDecimalPlaces_;
- bool hasRoot_;
-
-private:
- // Prohibit copy constructor & assignment operator.
- Writer(const Writer&);
- Writer& operator=(const Writer&);
-};
-
-// Full specialization for StringStream to prevent memory copying
-
-template<>
-inline bool Writer<StringBuffer>::WriteInt(int i) {
- char *buffer = os_->Push(11);
- const char* end = internal::i32toa(i, buffer);
- os_->Pop(static_cast<size_t>(11 - (end - buffer)));
- return true;
-}
-
-template<>
-inline bool Writer<StringBuffer>::WriteUint(unsigned u) {
- char *buffer = os_->Push(10);
- const char* end = internal::u32toa(u, buffer);
- os_->Pop(static_cast<size_t>(10 - (end - buffer)));
- return true;
-}
-
-template<>
-inline bool Writer<StringBuffer>::WriteInt64(int64_t i64) {
- char *buffer = os_->Push(21);
- const char* end = internal::i64toa(i64, buffer);
- os_->Pop(static_cast<size_t>(21 - (end - buffer)));
- return true;
-}
-
-template<>
-inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
- char *buffer = os_->Push(20);
- const char* end = internal::u64toa(u, buffer);
- os_->Pop(static_cast<size_t>(20 - (end - buffer)));
- return true;
-}
-
-template<>
-inline bool Writer<StringBuffer>::WriteDouble(double d) {
- if (internal::Double(d).IsNanOrInf()) {
- // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
- if (!(kWriteDefaultFlags & kWriteNanAndInfFlag))
- return false;
- if (internal::Double(d).IsNan()) {
- PutReserve(*os_, 3);
- PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
- return true;
- }
- if (internal::Double(d).Sign()) {
- PutReserve(*os_, 9);
- PutUnsafe(*os_, '-');
- }
- else
- PutReserve(*os_, 8);
- PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
- PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
- return true;
- }
-
- char *buffer = os_->Push(25);
- char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
- os_->Pop(static_cast<size_t>(25 - (end - buffer)));
- return true;
-}
-
-#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
-template<>
-inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
- if (length < 16)
- return RAPIDJSON_LIKELY(is.Tell() < length);
-
- if (!RAPIDJSON_LIKELY(is.Tell() < length))
- return false;
-
- const char* p = is.src_;
- const char* end = is.head_ + length;
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- const char* endAligned = reinterpret_cast<const char*>(reinterpret_cast<size_t>(end) & static_cast<size_t>(~15));
- if (nextAligned > end)
- return true;
-
- while (p != nextAligned)
- if (*p < 0x20 || *p == '\"' || *p == '\\') {
- is.src_ = p;
- return RAPIDJSON_LIKELY(is.Tell() < length);
- }
- else
- os_->PutUnsafe(*p++);
-
- // The rest of string using SIMD
- static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
- static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
- static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
- const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
- const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
- const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
-
- for (; p != endAligned; p += 16) {
- const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
- const __m128i t1 = _mm_cmpeq_epi8(s, dq);
- const __m128i t2 = _mm_cmpeq_epi8(s, bs);
- const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
- const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
- unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
- if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
- SizeType len;
-#ifdef _MSC_VER // Find the index of first escaped
- unsigned long offset;
- _BitScanForward(&offset, r);
- len = offset;
-#else
- len = static_cast<SizeType>(__builtin_ffs(r) - 1);
-#endif
- char* q = reinterpret_cast<char*>(os_->PushUnsafe(len));
- for (size_t i = 0; i < len; i++)
- q[i] = p[i];
-
- p += len;
- break;
- }
- _mm_storeu_si128(reinterpret_cast<__m128i *>(os_->PushUnsafe(16)), s);
- }
-
- is.src_ = p;
- return RAPIDJSON_LIKELY(is.Tell() < length);
-}
-#elif defined(RAPIDJSON_NEON)
-template<>
-inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
- if (length < 16)
- return RAPIDJSON_LIKELY(is.Tell() < length);
-
- if (!RAPIDJSON_LIKELY(is.Tell() < length))
- return false;
-
- const char* p = is.src_;
- const char* end = is.head_ + length;
- const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
- const char* endAligned = reinterpret_cast<const char*>(reinterpret_cast<size_t>(end) & static_cast<size_t>(~15));
- if (nextAligned > end)
- return true;
-
- while (p != nextAligned)
- if (*p < 0x20 || *p == '\"' || *p == '\\') {
- is.src_ = p;
- return RAPIDJSON_LIKELY(is.Tell() < length);
- }
- else
- os_->PutUnsafe(*p++);
-
- // The rest of string using SIMD
- const uint8x16_t s0 = vmovq_n_u8('"');
- const uint8x16_t s1 = vmovq_n_u8('\\');
- const uint8x16_t s2 = vmovq_n_u8('\b');
- const uint8x16_t s3 = vmovq_n_u8(32);
-
- for (; p != endAligned; p += 16) {
- const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
- uint8x16_t x = vceqq_u8(s, s0);
- x = vorrq_u8(x, vceqq_u8(s, s1));
- x = vorrq_u8(x, vceqq_u8(s, s2));
- x = vorrq_u8(x, vcltq_u8(s, s3));
-
- x = vrev64q_u8(x); // Rev in 64
- uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
- uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
-
- SizeType len = 0;
- bool escaped = false;
- if (low == 0) {
- if (high != 0) {
- unsigned lz = (unsigned)__builtin_clzll(high);
- len = 8 + (lz >> 3);
- escaped = true;
- }
- } else {
- unsigned lz = (unsigned)__builtin_clzll(low);
- len = lz >> 3;
- escaped = true;
- }
- if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
- char* q = reinterpret_cast<char*>(os_->PushUnsafe(len));
- for (size_t i = 0; i < len; i++)
- q[i] = p[i];
-
- p += len;
- break;
- }
- vst1q_u8(reinterpret_cast<uint8_t *>(os_->PushUnsafe(16)), s);
- }
-
- is.src_ = p;
- return RAPIDJSON_LIKELY(is.Tell() < length);
-}
-#endif // RAPIDJSON_NEON
-
-RAPIDJSON_NAMESPACE_END
-
-#ifdef _MSC_VER
-RAPIDJSON_DIAG_POP
-#endif
-
-#ifdef __clang__
-RAPIDJSON_DIAG_POP
-#endif
-
-#endif // RAPIDJSON_RAPIDJSON_H_
diff --git a/src/3rdparty/assimp/contrib/rapidjson/license.txt b/src/3rdparty/assimp/contrib/rapidjson/license.txt
deleted file mode 100644
index 7ccc161c8..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/license.txt
+++ /dev/null
@@ -1,57 +0,0 @@
-Tencent is pleased to support the open source community by making RapidJSON available.
-
-Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-
-If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License.
-If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license.
-A copy of the MIT License is included in this file.
-
-Other dependencies and licenses:
-
-Open Source Software Licensed Under the BSD License:
---------------------------------------------------------------------
-
-The msinttypes r29
-Copyright (c) 2006-2013 Alexander Chemeris
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-* Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Open Source Software Licensed Under the JSON License:
---------------------------------------------------------------------
-
-json.org
-Copyright (c) 2002 JSON.org
-All Rights Reserved.
-
-JSON_checker
-Copyright (c) 2002 JSON.org
-All Rights Reserved.
-
-
-Terms of the JSON License:
----------------------------------------------------
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-Terms of the MIT License:
---------------------------------------------------------------------
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/3rdparty/assimp/contrib/rapidjson/readme.md b/src/3rdparty/assimp/contrib/rapidjson/readme.md
deleted file mode 100644
index b833a98e8..000000000
--- a/src/3rdparty/assimp/contrib/rapidjson/readme.md
+++ /dev/null
@@ -1,160 +0,0 @@
-![RapidJSON logo](doc/logo/rapidjson.png)
-
-![Release version](https://img.shields.io/badge/release-v1.1.0-blue.svg)
-
-## A fast JSON parser/generator for C++ with both SAX/DOM style API
-
-Tencent is pleased to support the open source community by making RapidJSON available.
-
-Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
-
-* [RapidJSON GitHub](https://github.com/Tencent/rapidjson/)
-* RapidJSON Documentation
- * [English](http://rapidjson.org/)
- * [简体中文](http://rapidjson.org/zh-cn/)
- * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/) with downloadable PDF/EPUB/MOBI, without API reference.
-
-## Build status
-
-| [Linux][lin-link] | [Windows][win-link] | [Coveralls][cov-link] |
-| :---------------: | :-----------------: | :-------------------: |
-| ![lin-badge] | ![win-badge] | ![cov-badge] |
-
-[lin-badge]: https://travis-ci.org/Tencent/rapidjson.svg?branch=master "Travis build status"
-[lin-link]: https://travis-ci.org/Tencent/rapidjson "Travis build status"
-[win-badge]: https://ci.appveyor.com/api/projects/status/l6qulgqahcayidrf/branch/master?svg=true "AppVeyor build status"
-[win-link]: https://ci.appveyor.com/project/miloyip/rapidjson-0fdqj/branch/master "AppVeyor build status"
-[cov-badge]: https://coveralls.io/repos/Tencent/rapidjson/badge.svg?branch=master "Coveralls coverage"
-[cov-link]: https://coveralls.io/r/Tencent/rapidjson?branch=master "Coveralls coverage"
-
-## Introduction
-
-RapidJSON is a JSON parser and generator for C++. It was inspired by [RapidXml](http://rapidxml.sourceforge.net/).
-
-* RapidJSON is **small** but **complete**. It supports both SAX and DOM style API. The SAX parser is only a half thousand lines of code.
-
-* RapidJSON is **fast**. Its performance can be comparable to `strlen()`. It also optionally supports SSE2/SSE4.2 for acceleration.
-
-* RapidJSON is **self-contained** and **header-only**. It does not depend on external libraries such as BOOST. It even does not depend on STL.
-
-* RapidJSON is **memory-friendly**. Each JSON value occupies exactly 16 bytes for most 32/64-bit machines (excluding text string). By default it uses a fast memory allocator, and the parser allocates memory compactly during parsing.
-
-* RapidJSON is **Unicode-friendly**. It supports UTF-8, UTF-16, UTF-32 (LE & BE), and their detection, validation and transcoding internally. For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM. It also supports surrogates and "\u0000" (null character).
-
-More features can be read [here](doc/features.md).
-
-JSON(JavaScript Object Notation) is a light-weight data exchange format. RapidJSON should be in fully compliance with RFC7159/ECMA-404, with optional support of relaxed syntax. More information about JSON can be obtained at
-* [Introducing JSON](http://json.org/)
-* [RFC7159: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc7159)
-* [Standard ECMA-404: The JSON Data Interchange Format](https://www.ecma-international.org/publications/standards/Ecma-404.htm)
-
-## Highlights in v1.1 (2016-8-25)
-
-* Added [JSON Pointer](doc/pointer.md)
-* Added [JSON Schema](doc/schema.md)
-* Added [relaxed JSON syntax](doc/dom.md) (comment, trailing comma, NaN/Infinity)
-* Iterating array/object with [C++11 Range-based for loop](doc/tutorial.md)
-* Reduce memory overhead of each `Value` from 24 bytes to 16 bytes in x86-64 architecture.
-
-For other changes please refer to [change log](CHANGELOG.md).
-
-## Compatibility
-
-RapidJSON is cross-platform. Some platform/compiler combinations which have been tested are shown as follows.
-* Visual C++ 2008/2010/2013 on Windows (32/64-bit)
-* GNU C++ 3.8.x on Cygwin
-* Clang 3.4 on Mac OS X (32/64-bit) and iOS
-* Clang 3.4 on Android NDK
-
-Users can build and run the unit tests on their platform/compiler.
-
-## Installation
-
-RapidJSON is a header-only C++ library. Just copy the `include/rapidjson` folder to system or project's include path.
-
-RapidJSON uses following software as its dependencies:
-* [CMake](https://cmake.org/) as a general build tool
-* (optional) [Doxygen](http://www.doxygen.org) to build documentation
-* (optional) [googletest](https://github.com/google/googletest) for unit and performance testing
-
-To generate user documentation and run tests please proceed with the steps below:
-
-1. Execute `git submodule update --init` to get the files of thirdparty submodules (google test).
-2. Create directory called `build` in rapidjson source directory.
-3. Change to `build` directory and run `cmake ..` command to configure your build. Windows users can do the same with cmake-gui application.
-4. On Windows, build the solution found in the build directory. On Linux, run `make` from the build directory.
-
-On successful build you will find compiled test and example binaries in `bin`
-directory. The generated documentation will be available in `doc/html`
-directory of the build tree. To run tests after finished build please run `make
-test` or `ctest` from your build tree. You can get detailed output using `ctest
--V` command.
-
-It is possible to install library system-wide by running `make install` command
-from the build tree with administrative privileges. This will install all files
-according to system preferences. Once RapidJSON is installed, it is possible
-to use it from other CMake projects by adding `find_package(RapidJSON)` line to
-your CMakeLists.txt.
-
-## Usage at a glance
-
-This simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.
-
-~~~~~~~~~~cpp
-// rapidjson/example/simpledom/simpledom.cpp`
-#include "rapidjson/document.h"
-#include "rapidjson/writer.h"
-#include "rapidjson/stringbuffer.h"
-#include <iostream>
-
-using namespace rapidjson;
-
-int main() {
- // 1. Parse a JSON string into DOM.
- const char* json = "{\"project\":\"rapidjson\",\"stars\":10}";
- Document d;
- d.Parse(json);
-
- // 2. Modify it by DOM.
- Value& s = d["stars"];
- s.SetInt(s.GetInt() + 1);
-
- // 3. Stringify the DOM
- StringBuffer buffer;
- Writer<StringBuffer> writer(buffer);
- d.Accept(writer);
-
- // Output {"project":"rapidjson","stars":11}
- std::cout << buffer.GetString() << std::endl;
- return 0;
-}
-~~~~~~~~~~
-
-Note that this example did not handle potential errors.
-
-The following diagram shows the process.
-
-![simpledom](doc/diagram/simpledom.png)
-
-More [examples](https://github.com/Tencent/rapidjson/tree/master/example) are available:
-
-* DOM API
- * [tutorial](https://github.com/Tencent/rapidjson/blob/master/example/tutorial/tutorial.cpp): Basic usage of DOM API.
-
-* SAX API
- * [simplereader](https://github.com/Tencent/rapidjson/blob/master/example/simplereader/simplereader.cpp): Dumps all SAX events while parsing a JSON by `Reader`.
- * [condense](https://github.com/Tencent/rapidjson/blob/master/example/condense/condense.cpp): A command line tool to rewrite a JSON, with all whitespaces removed.
- * [pretty](https://github.com/Tencent/rapidjson/blob/master/example/pretty/pretty.cpp): A command line tool to rewrite a JSON with indents and newlines by `PrettyWriter`.
- * [capitalize](https://github.com/Tencent/rapidjson/blob/master/example/capitalize/capitalize.cpp): A command line tool to capitalize strings in JSON.
- * [messagereader](https://github.com/Tencent/rapidjson/blob/master/example/messagereader/messagereader.cpp): Parse a JSON message with SAX API.
- * [serialize](https://github.com/Tencent/rapidjson/blob/master/example/serialize/serialize.cpp): Serialize a C++ object into JSON with SAX API.
- * [jsonx](https://github.com/Tencent/rapidjson/blob/master/example/jsonx/jsonx.cpp): Implements a `JsonxWriter` which stringify SAX events into [JSONx](https://www-01.ibm.com/support/knowledgecenter/SS9H2Y_7.1.0/com.ibm.dp.doc/json_jsonx.html) (a kind of XML) format. The example is a command line tool which converts input JSON into JSONx format.
-
-* Schema
- * [schemavalidator](https://github.com/Tencent/rapidjson/blob/master/example/schemavalidator/schemavalidator.cpp) : A command line tool to validate a JSON with a JSON schema.
-
-* Advanced
- * [prettyauto](https://github.com/Tencent/rapidjson/blob/master/example/prettyauto/prettyauto.cpp): A modified version of [pretty](https://github.com/Tencent/rapidjson/blob/master/example/pretty/pretty.cpp) to automatically handle JSON with any UTF encodings.
- * [parsebyparts](https://github.com/Tencent/rapidjson/blob/master/example/parsebyparts/parsebyparts.cpp): Implements an `AsyncDocumentParser` which can parse JSON in parts, using C++11 thread.
- * [filterkey](https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp): A command line tool to remove all values with user-specified key.
- * [filterkeydom](https://github.com/Tencent/rapidjson/blob/master/example/filterkeydom/filterkeydom.cpp): Same tool as above, but it demonstrates how to use a generator to populate a `Document`.
diff --git a/src/3rdparty/assimp/contrib/unzip/crypt.h b/src/3rdparty/assimp/contrib/unzip/crypt.h
deleted file mode 100644
index 2aa99c284..000000000
--- a/src/3rdparty/assimp/contrib/unzip/crypt.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/* crypt.h -- base code for crypt/uncrypt ZIPfile
-
-
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-
- This code is a modified version of crypting code in Infozip distribution
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
-
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
-
- If you don't need crypting in your application, just define symbols
- NOCRYPT and NOUNCRYPT.
-
- This code support the "Traditional PKWARE Encryption".
-
- The new AES encryption added on Zip format by Winzip (see the page
- http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
- Encryption is not supported.
-*/
-
-#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
-
-/***********************************************************************
- * Return the next byte in the pseudo-random sequence
- */
-static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
-{
- unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
- * unpredictable manner on 16-bit systems; not a problem
- * with any known compiler so far, though */
-
- temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
- return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
-}
-
-/***********************************************************************
- * Update the encryption keys with the next byte of plain text
- */
-static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
-{
- (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
- (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
- (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
- {
- register int keyshift = (int)((*(pkeys+1)) >> 24);
- (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
- }
- return c;
-}
-
-
-/***********************************************************************
- * Initialize the encryption keys and the random header according to
- * the given password.
- */
-static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
-{
- *(pkeys+0) = 305419896L;
- *(pkeys+1) = 591751049L;
- *(pkeys+2) = 878082192L;
- while (*passwd != '\0') {
- update_keys(pkeys,pcrc_32_tab,(int)*passwd);
- passwd++;
- }
-}
-
-#define zdecode(pkeys,pcrc_32_tab,c) \
- (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
-
-#define zencode(pkeys,pcrc_32_tab,c,t) \
- (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
-
-#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-
-#define RAND_HEAD_LEN 12
- /* "last resort" source for second part of crypt seed pattern */
-# ifndef ZCR_SEED2
-# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
-# endif
-
-static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
- const char *passwd; /* password string */
- unsigned char *buf; /* where to write header */
- int bufSize;
- unsigned long* pkeys;
- const unsigned long* pcrc_32_tab;
- unsigned long crcForCrypting;
-{
- int n; /* index in random header */
- int t; /* temporary */
- int c; /* random byte */
- unsigned char header[RAND_HEAD_LEN-2]; /* random header */
- static unsigned calls = 0; /* ensure different random header each time */
-
- if (bufSize<RAND_HEAD_LEN)
- return 0;
-
- /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
- * output of rand() to get less predictability, since rand() is
- * often poorly implemented.
- */
- if (++calls == 1)
- {
- srand((unsigned)(time(NULL) ^ ZCR_SEED2));
- }
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- c = (rand() >> 7) & 0xff;
- header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
- }
- /* Encrypt random header (last two bytes is high word of crc) */
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
- }
- buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
- buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
- return n;
-}
-
-#endif
diff --git a/src/3rdparty/assimp/contrib/unzip/ioapi.c b/src/3rdparty/assimp/contrib/unzip/ioapi.c
deleted file mode 100644
index f1bee23e6..000000000
--- a/src/3rdparty/assimp/contrib/unzip/ioapi.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* ioapi.c -- IO base function header for compress/uncompress .zip
- files using zlib + zip or unzip API
-
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "zlib.h"
-#include "ioapi.h"
-
-
-
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-
-voidpf ZCALLBACK fopen_file_func OF((
- voidpf opaque,
- const char* filename,
- int mode));
-
-uLong ZCALLBACK fread_file_func OF((
- voidpf opaque,
- voidpf stream,
- void* buf,
- uLong size));
-
-uLong ZCALLBACK fwrite_file_func OF((
- voidpf opaque,
- voidpf stream,
- const void* buf,
- uLong size));
-
-long ZCALLBACK ftell_file_func OF((
- voidpf opaque,
- voidpf stream));
-
-long ZCALLBACK fseek_file_func OF((
- voidpf opaque,
- voidpf stream,
- uLong offset,
- int origin));
-
-int ZCALLBACK fclose_file_func OF((
- voidpf opaque,
- voidpf stream));
-
-int ZCALLBACK ferror_file_func OF((
- voidpf opaque,
- voidpf stream));
-
-
-voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
- voidpf opaque;
- const char* filename;
- int mode;
-{
- FILE* file = NULL;
- const char* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = "rb";
- else
- if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = "r+b";
- else
- if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = "wb";
-
- if ((filename!=NULL) && (mode_fopen != NULL))
- file = fopen(filename, mode_fopen);
- return file;
-}
-
-
-uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
- voidpf opaque;
- voidpf stream;
- void* buf;
- uLong size;
-{
- uLong ret;
- ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-
-uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
- voidpf opaque;
- voidpf stream;
- const void* buf;
- uLong size;
-{
- uLong ret;
- ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-long ZCALLBACK ftell_file_func (opaque, stream)
- voidpf opaque;
- voidpf stream;
-{
- long ret;
- ret = ftell((FILE *)stream);
- return ret;
-}
-
-long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
- voidpf opaque;
- voidpf stream;
- uLong offset;
- int origin;
-{
- int fseek_origin=0;
- long ret;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- fseek_origin = SEEK_CUR;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- fseek_origin = SEEK_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- fseek_origin = SEEK_SET;
- break;
- default: return -1;
- }
- ret = 0;
- fseek((FILE *)stream, offset, fseek_origin);
- return ret;
-}
-
-int ZCALLBACK fclose_file_func (opaque, stream)
- voidpf opaque;
- voidpf stream;
-{
- int ret;
- ret = fclose((FILE *)stream);
- return ret;
-}
-
-int ZCALLBACK ferror_file_func (opaque, stream)
- voidpf opaque;
- voidpf stream;
-{
- int ret;
- ret = ferror((FILE *)stream);
- return ret;
-}
-
-void fill_fopen_filefunc (pzlib_filefunc_def)
- zlib_filefunc_def* pzlib_filefunc_def;
-{
- pzlib_filefunc_def->zopen_file = fopen_file_func;
- pzlib_filefunc_def->zread_file = fread_file_func;
- pzlib_filefunc_def->zwrite_file = fwrite_file_func;
- pzlib_filefunc_def->ztell_file = ftell_file_func;
- pzlib_filefunc_def->zseek_file = fseek_file_func;
- pzlib_filefunc_def->zclose_file = fclose_file_func;
- pzlib_filefunc_def->zerror_file = ferror_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/src/3rdparty/assimp/contrib/unzip/ioapi.h b/src/3rdparty/assimp/contrib/unzip/ioapi.h
deleted file mode 100644
index 7d457baab..000000000
--- a/src/3rdparty/assimp/contrib/unzip/ioapi.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
- files using zlib + zip or unzip API
-
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-*/
-
-#ifndef _ZLIBIOAPI_H
-#define _ZLIBIOAPI_H
-
-
-#define ZLIB_FILEFUNC_SEEK_CUR (1)
-#define ZLIB_FILEFUNC_SEEK_END (2)
-#define ZLIB_FILEFUNC_SEEK_SET (0)
-
-#define ZLIB_FILEFUNC_MODE_READ (1)
-#define ZLIB_FILEFUNC_MODE_WRITE (2)
-#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
-
-#define ZLIB_FILEFUNC_MODE_EXISTING (4)
-#define ZLIB_FILEFUNC_MODE_CREATE (8)
-
-
-#ifndef ZCALLBACK
-
-#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
-#define ZCALLBACK CALLBACK
-#else
-#define ZCALLBACK
-#endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
-typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
-typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
-typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
-typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
-
-typedef struct zlib_filefunc_def_s
-{
- open_file_func zopen_file;
- read_file_func zread_file;
- write_file_func zwrite_file;
- tell_file_func ztell_file;
- seek_file_func zseek_file;
- close_file_func zclose_file;
- testerror_file_func zerror_file;
- voidpf opaque;
-} zlib_filefunc_def;
-
-
-
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
-#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
-#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
-#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
-#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
-#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/3rdparty/assimp/contrib/unzip/unzip.c b/src/3rdparty/assimp/contrib/unzip/unzip.c
deleted file mode 100644
index e8b62e763..000000000
--- a/src/3rdparty/assimp/contrib/unzip/unzip.c
+++ /dev/null
@@ -1,1611 +0,0 @@
-/* unzip.c -- IO for uncompress .zip files using zlib
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-
- Read unzip.h for more info
-*/
-
-/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
-compatibility with older software. The following is from the original crypt.c. Code
-woven in by Terry Thorsen 1/2003.
-*/
-/*
- Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
-
- See the accompanying file LICENSE, version 2000-Apr-09 or later
- (the contents of which are also included in zip.h) for terms of use.
- If, for some reason, all these files are missing, the Info-ZIP license
- also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
-*/
-/*
- crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
- */
-
-/*
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "zlib.h"
-#include "unzip.h"
-
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
-#else
-# include <errno.h>
-#endif
-
-
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-
-#ifndef CASESENSITIVITYDEFAULT_NO
-# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
-# define CASESENSITIVITYDEFAULT_NO
-# endif
-#endif
-
-
-#ifndef UNZ_BUFSIZE
-#define UNZ_BUFSIZE (16384)
-#endif
-
-#ifndef UNZ_MAXFILENAMEINZIP
-#define UNZ_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-
-
-
-
-const char unz_copyright[] =
- " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info_internal_s
-{
- uLong offset_curfile;/* relative offset of local header 4 bytes */
-} unz_file_info_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
- when reading and decompress it */
-typedef struct
-{
- char *read_buffer; /* internal buffer for compressed data */
- z_stream stream; /* zLib stream structure for inflate */
-
- uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
- uLong stream_initialised; /* flag set if stream structure is initialised*/
-
- uLong offset_local_extrafield;/* offset of the local extra field */
- uInt size_local_extrafield;/* size of the local extra field */
- uLong pos_local_extrafield; /* position in the local extra field in read*/
-
- uLong crc32; /* crc32 of all data uncompressed */
- uLong crc32_wait; /* crc32 we must obtain after decompress all */
- uLong rest_read_compressed; /* number of byte to be decompressed */
- uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
- zlib_filefunc_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- uLong compression_method; /* compression method (0==store) */
- uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- int raw;
-} file_in_zip_read_info_s;
-
-
-/* unz_s contain internal information about the zipfile
-*/
-typedef struct
-{
- zlib_filefunc_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- unz_global_info gi; /* public global information */
- uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- uLong num_file; /* number of the current file in the zipfile*/
- uLong pos_in_central_dir; /* pos of the current file in the central dir*/
- uLong current_file_ok; /* flag about the usability of the current file*/
- uLong central_pos; /* position of the beginning of the central dir*/
-
- uLong size_central_dir; /* size of the central directory */
- uLong offset_central_dir; /* offset of start of central directory with
- respect to the starting disk number */
-
- unz_file_info cur_file_info; /* public info about the current file in zip*/
- unz_file_info_internal cur_file_info_internal; /* private info about it*/
- file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
- file if we are decompressing it */
- int encrypted;
-# ifndef NOUNCRYPT
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
- const z_crc_t* pcrc_32_tab;
-# endif
-} unz_s;
-
-
-#ifndef NOUNCRYPT
-#include "crypt.h"
-#endif
-
-/* ===========================================================================
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF
- for end of file.
- IN assertion: the stream s has been sucessfully opened for reading.
-*/
-
-
-local int unzlocal_getByte OF((
- const zlib_filefunc_def* pzlib_filefunc_def,
- voidpf filestream,
- int *pi));
-
-local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
- const zlib_filefunc_def* pzlib_filefunc_def;
- voidpf filestream;
- int *pi;
-{
- unsigned char c;
- int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
- if (err==1)
- {
- *pi = (int)c;
- return UNZ_OK;
- }
- else
- {
- if (ZERROR(*pzlib_filefunc_def,filestream))
- return UNZ_ERRNO;
- else
- return UNZ_EOF;
- }
-}
-
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int unzlocal_getShort OF((
- const zlib_filefunc_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
- const zlib_filefunc_def* pzlib_filefunc_def;
- voidpf filestream;
- uLong *pX;
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int unzlocal_getLong OF((
- const zlib_filefunc_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
- const zlib_filefunc_def* pzlib_filefunc_def;
- voidpf filestream;
- uLong *pX;
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<16;
-
- if (err==UNZ_OK)
- err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<24;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (fileName1,fileName2)
- const char* fileName1;
- const char* fileName2;
-{
- for (;;)
- {
- char c1=*(fileName1++);
- char c2=*(fileName2++);
- if ((c1>='a') && (c1<='z'))
- c1 -= 0x20;
- if ((c2>='a') && (c2<='z'))
- c2 -= 0x20;
- if (c1=='\0')
- return ((c2=='\0') ? 0 : -1);
- if (c2=='\0')
- return 1;
- if (c1<c2)
- return -1;
- if (c1>c2)
- return 1;
- }
-}
-
-
-#ifdef CASESENSITIVITYDEFAULT_NO
-#define CASESENSITIVITYDEFAULTVALUE 2
-#else
-#define CASESENSITIVITYDEFAULTVALUE 1
-#endif
-
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-
-*/
-extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
- const char* fileName1;
- const char* fileName2;
- int iCaseSensitivity;
-{
- if (iCaseSensitivity==0)
- iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
-
- if (iCaseSensitivity==1)
- return strcmp(fileName1,fileName2);
-
- return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-
-/*
- Locate the Central directory of a zipfile (at the end, just before
- the global comment)
-*/
-local uLong unzlocal_SearchCentralDir OF((
- const zlib_filefunc_def* pzlib_filefunc_def,
- voidpf filestream));
-
-local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
- const zlib_filefunc_def* pzlib_filefunc_def;
- voidpf filestream;
-{
- unsigned char* buf;
- uLong uSizeFile;
- uLong uBackRead;
- uLong uMaxBack=0xffff; /* maximum size of global comment */
- uLong uPosFound=0;
-
- if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize,uReadPos ;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
- if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- return uPosFound;
-}
-
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
- "zlib/zlib114.zip".
- If the zipfile cannot be opened (file doesn't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
- const char *path;
- zlib_filefunc_def* pzlib_filefunc_def;
-{
- unz_s us;
- unz_s *s;
- uLong central_pos,uL;
-
- uLong number_disk; /* number of the current dist, used for
- spaning ZIP, unsupported, always 0*/
- uLong number_disk_with_CD; /* number the the disk with central dir, used
- for spaning ZIP, unsupported, always 0*/
- uLong number_entry_CD; /* total number of entries in
- the central dir
- (same than number_entry on nospan) */
-
- int err=UNZ_OK;
-
- if (unz_copyright[0]!=' ')
- return NULL;
-
- if (pzlib_filefunc_def==NULL)
- fill_fopen_filefunc(&us.z_filefunc);
- else
- us.z_filefunc = *pzlib_filefunc_def;
-
- us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
- path,
- ZLIB_FILEFUNC_MODE_READ |
- ZLIB_FILEFUNC_MODE_EXISTING);
- if (us.filestream==NULL)
- return NULL;
-
- central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
- if (central_pos==0)
- err=UNZ_ERRNO;
-
- if (ZSEEK(us.z_filefunc, us.filestream,
- central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
- /* the signature, already checked */
- if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of this disk */
- if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central dir on this disk */
- if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central dir */
- if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- if ((number_entry_CD!=us.gi.number_entry) ||
- (number_disk_with_CD!=0) ||
- (number_disk!=0))
- err=UNZ_BADZIPFILE;
-
- /* size of the central directory */
- if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* zipfile comment length */
- if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
- (err==UNZ_OK))
- err=UNZ_BADZIPFILE;
-
- if (err!=UNZ_OK)
- {
- ZCLOSE(us.z_filefunc, us.filestream);
- return NULL;
- }
-
- us.byte_before_the_zipfile = central_pos -
- (us.offset_central_dir+us.size_central_dir);
- us.central_pos = central_pos;
- us.pfile_in_zip_read = NULL;
- us.encrypted = 0;
-
-
- s=(unz_s*)ALLOC(sizeof(unz_s));
- *s=us;
- unzGoToFirstFile((unzFile)s);
- return (unzFile)s;
-}
-
-
-extern unzFile ZEXPORT unzOpen (path)
- const char *path;
-{
- return unzOpen2(path, NULL);
-}
-
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (file)
- unzFile file;
-{
- unz_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
-
- if (s->pfile_in_zip_read!=NULL)
- unzCloseCurrentFile(file);
-
- ZCLOSE(s->z_filefunc, s->filestream);
- TRYFREE(s);
- return UNZ_OK;
-}
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
- unzFile file;
- unz_global_info *pglobal_info;
-{
- unz_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- *pglobal_info=s->gi;
- return UNZ_OK;
-}
-
-
-/*
- Translate date/time from Dos format to tm_unz (readable more easilty)
-*/
-local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
- uLong ulDosDate;
- tm_unz* ptm;
-{
- uLong uDate;
- uDate = (uLong)(ulDosDate>>16);
- ptm->tm_mday = (uInt)(uDate&0x1f) ;
- ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
- ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
-
- ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
- ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
- ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
-}
-
-/*
- Get Info about the current file in the zipfile, with internal only info
-*/
-local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
- unz_file_info *pfile_info,
- unz_file_info_internal
- *pfile_info_internal,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-
-local int unzlocal_GetCurrentFileInfoInternal (file,
- pfile_info,
- pfile_info_internal,
- szFileName, fileNameBufferSize,
- extraField, extraFieldBufferSize,
- szComment, commentBufferSize)
- unzFile file;
- unz_file_info *pfile_info;
- unz_file_info_internal *pfile_info_internal;
- char *szFileName;
- uLong fileNameBufferSize;
- void *extraField;
- uLong extraFieldBufferSize;
- char *szComment;
- uLong commentBufferSize;
-{
- unz_s* s;
- unz_file_info file_info;
- unz_file_info_internal file_info_internal;
- int err=UNZ_OK;
- uLong uMagic;
- long lSeek=0;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- if (ZSEEK(s->z_filefunc, s->filestream,
- s->pos_in_central_dir+s->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
-
- /* we check the magic */
- if (err==UNZ_OK)
- {
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- {
- err=UNZ_ERRNO;
- }
- else if (uMagic!=0x02014b50)
- {
- err=UNZ_BADZIPFILE;
- }
- }
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
- err=UNZ_ERRNO;
-
- unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
- err=UNZ_ERRNO;
-
- lSeek+=file_info.size_filename;
- if ((err==UNZ_OK) && (szFileName!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_filename<fileNameBufferSize)
- {
- *(szFileName+file_info.size_filename)='\0';
- uSizeRead = file_info.size_filename;
- }
- else
- uSizeRead = fileNameBufferSize;
-
- if ((file_info.size_filename>0) && (fileNameBufferSize>0))
- if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek -= uSizeRead;
- }
-
-
- if ((err==UNZ_OK) && (extraField!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_file_extra<extraFieldBufferSize)
- uSizeRead = file_info.size_file_extra;
- else
- uSizeRead = extraFieldBufferSize;
-
- if (lSeek!=0)
- {
- if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
- if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
- if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek += file_info.size_file_extra - uSizeRead;
- }
- else
- {
- lSeek+=file_info.size_file_extra;
- }
-
- if ((err==UNZ_OK) && (szComment!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_file_comment<commentBufferSize)
- {
- *(szComment+file_info.size_file_comment)='\0';
- uSizeRead = file_info.size_file_comment;
- }
- else
- {
- uSizeRead = commentBufferSize;
- }
-
- if (lSeek!=0)
- {
- if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)!=0)
- err=UNZ_ERRNO;
- }
- if ((file_info.size_file_comment>0) && (commentBufferSize>0))
- if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- }
- else
- {
- }
-
- if ((err==UNZ_OK) && (pfile_info!=NULL))
- *pfile_info=file_info;
-
- if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
- *pfile_info_internal=file_info_internal;
-
- return err;
-}
-
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem.
-*/
-extern int ZEXPORT unzGetCurrentFileInfo (file,
- pfile_info,
- szFileName, fileNameBufferSize,
- extraField, extraFieldBufferSize,
- szComment, commentBufferSize)
- unzFile file;
- unz_file_info *pfile_info;
- char *szFileName;
- uLong fileNameBufferSize;
- void *extraField;
- uLong extraFieldBufferSize;
- char *szComment;
- uLong commentBufferSize;
-{
- return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
- szFileName,fileNameBufferSize,
- extraField,extraFieldBufferSize,
- szComment,commentBufferSize);
-}
-
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-extern int ZEXPORT unzGoToFirstFile (file)
- unzFile file;
-{
- int err=UNZ_OK;
- unz_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- s->pos_in_central_dir=s->offset_central_dir;
- s->num_file=0;
- err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-extern int ZEXPORT unzGoToNextFile (file)
- unzFile file;
-{
- unz_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
- if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
- if (s->num_file+1==s->gi.number_entry)
- return UNZ_END_OF_LIST_OF_FILE;
-
- s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
- s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
- s->num_file++;
- err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzipStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
- unzFile file;
- const char *szFileName;
- int iCaseSensitivity;
-{
- unz_s* s;
- int err;
-
- /* We remember the 'current' position in the file so that we can jump
- * back there if we fail.
- */
- unz_file_info cur_file_infoSaved;
- unz_file_info_internal cur_file_info_internalSaved;
- uLong num_fileSaved;
- uLong pos_in_central_dirSaved;
-
-
- if (file==NULL)
- return UNZ_PARAMERROR;
-
- if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
- return UNZ_PARAMERROR;
-
- s=(unz_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- /* Save the current state */
- num_fileSaved = s->num_file;
- pos_in_central_dirSaved = s->pos_in_central_dir;
- cur_file_infoSaved = s->cur_file_info;
- cur_file_info_internalSaved = s->cur_file_info_internal;
-
- err = unzGoToFirstFile(file);
-
- while (err == UNZ_OK)
- {
- char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
- err = unzGetCurrentFileInfo(file,NULL,
- szCurrentFileName,sizeof(szCurrentFileName)-1,
- NULL,0,NULL,0);
- if (err == UNZ_OK)
- {
- if (unzStringFileNameCompare(szCurrentFileName,
- szFileName,iCaseSensitivity)==0)
- return UNZ_OK;
- err = unzGoToNextFile(file);
- }
- }
-
- /* We failed, so restore the state of the 'current file' to where we
- * were.
- */
- s->num_file = num_fileSaved ;
- s->pos_in_central_dir = pos_in_central_dirSaved ;
- s->cur_file_info = cur_file_infoSaved;
- s->cur_file_info_internal = cur_file_info_internalSaved;
- return err;
-}
-
-
-/*
-///////////////////////////////////////////
-// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
-// I need random access
-//
-// Further optimization could be realized by adding an ability
-// to cache the directory in memory. The goal being a single
-// comprehensive file read to put the file I need in a memory.
-*/
-
-/*
-typedef struct unz_file_pos_s
-{
- uLong pos_in_zip_directory; // offset in file
- uLong num_of_file; // # of file
-} unz_file_pos;
-*/
-
-extern int ZEXPORT unzGetFilePos(file, file_pos)
- unzFile file;
- unz_file_pos* file_pos;
-{
- unz_s* s;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- file_pos->pos_in_zip_directory = s->pos_in_central_dir;
- file_pos->num_of_file = s->num_file;
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzGoToFilePos(file, file_pos)
- unzFile file;
- unz_file_pos* file_pos;
-{
- unz_s* s;
- int err;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
-
- /* jump to the right spot */
- s->pos_in_central_dir = file_pos->pos_in_zip_directory;
- s->num_file = file_pos->num_of_file;
-
- /* set the current file */
- err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- /* return results */
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-/*
-// Unzip Helper Functions - should be here?
-///////////////////////////////////////////
-*/
-
-/*
- Read the local header of the current zipfile
- Check the coherency of the local header and info in the end of central
- directory about this file
- store in *piSizeVar the size of extra info in local header
- (filename and size of extra field data)
-*/
-local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
- poffset_local_extrafield,
- psize_local_extrafield)
- unz_s* s;
- uInt* piSizeVar;
- uLong *poffset_local_extrafield;
- uInt *psize_local_extrafield;
-{
- uLong uMagic,uData,uFlags;
- uLong size_filename;
- uLong size_extra_field;
- int err=UNZ_OK;
-
- *piSizeVar = 0;
- *poffset_local_extrafield = 0;
- *psize_local_extrafield = 0;
-
- if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
- s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
-
- if (err==UNZ_OK)
- {
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- err=UNZ_ERRNO;
- else if (uMagic!=0x04034b50)
- err=UNZ_BADZIPFILE;
- }
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
-/*
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
- err=UNZ_BADZIPFILE;
-*/
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
- err=UNZ_BADZIPFILE;
-
- if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
- (s->cur_file_info.compression_method!=Z_DEFLATED))
- err=UNZ_BADZIPFILE;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
- err=UNZ_ERRNO;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
- ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
- ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
- ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
- err=UNZ_BADZIPFILE;
-
- *piSizeVar += (uInt)size_filename;
-
- if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
- err=UNZ_ERRNO;
- *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
- SIZEZIPLOCALHEADER + size_filename;
- *psize_local_extrafield = (uInt)size_extra_field;
-
- *piSizeVar += (uInt)size_extra_field;
-
- return err;
-}
-
-/*
- Open for reading data the current file in the zipfile.
- If there is no error and the file is opened, the return value is UNZ_OK.
-*/
-extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
- unzFile file;
- int* method;
- int* level;
- int raw;
- const char* password;
-{
- int err=UNZ_OK;
- uInt iSizeVar;
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- uLong offset_local_extrafield; /* offset of the local extra field */
- uInt size_local_extrafield; /* size of the local extra field */
-# ifndef NOUNCRYPT
- char source[12];
-# else
- if (password != NULL)
- return UNZ_PARAMERROR;
-# endif
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- if (!s->current_file_ok)
- return UNZ_PARAMERROR;
-
- if (s->pfile_in_zip_read != NULL)
- unzCloseCurrentFile(file);
-
- if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
- &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
- return UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info = (file_in_zip_read_info_s*)
- ALLOC(sizeof(file_in_zip_read_info_s));
- if (pfile_in_zip_read_info==NULL)
- return UNZ_INTERNALERROR;
-
- pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
- pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
- pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
- pfile_in_zip_read_info->pos_local_extrafield=0;
- pfile_in_zip_read_info->raw=raw;
-
- if (pfile_in_zip_read_info->read_buffer==NULL)
- {
- TRYFREE(pfile_in_zip_read_info);
- return UNZ_INTERNALERROR;
- }
-
- pfile_in_zip_read_info->stream_initialised=0;
-
- if (method!=NULL)
- *method = (int)s->cur_file_info.compression_method;
-
- if (level!=NULL)
- {
- *level = 6;
- switch (s->cur_file_info.flag & 0x06)
- {
- case 6 : *level = 1; break;
- case 4 : *level = 2; break;
- case 2 : *level = 9; break;
- }
- }
-
- if ((s->cur_file_info.compression_method!=0) &&
- (s->cur_file_info.compression_method!=Z_DEFLATED))
- return UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
- pfile_in_zip_read_info->crc32=0;
- pfile_in_zip_read_info->compression_method =
- s->cur_file_info.compression_method;
- pfile_in_zip_read_info->filestream=s->filestream;
- pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
- pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
-
- pfile_in_zip_read_info->stream.total_out = 0;
-
- if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
- (!raw))
- {
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
- pfile_in_zip_read_info->stream.zfree = (free_func)0;
- pfile_in_zip_read_info->stream.opaque = (voidpf)0;
- pfile_in_zip_read_info->stream.next_in = (voidpf)0;
- pfile_in_zip_read_info->stream.avail_in = 0;
-
- err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
- if (err == Z_OK)
- pfile_in_zip_read_info->stream_initialised=1;
- else
- {
- TRYFREE(pfile_in_zip_read_info);
- return err;
- }
- /* windowBits is passed < 0 to tell that there is no zlib header.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END.
- * In unzip, i don't wait absolutely Z_STREAM_END because I known the
- * size of both compressed and uncompressed data
- */
- }
- pfile_in_zip_read_info->rest_read_compressed =
- s->cur_file_info.compressed_size ;
- pfile_in_zip_read_info->rest_read_uncompressed =
- s->cur_file_info.uncompressed_size ;
-
-
- pfile_in_zip_read_info->pos_in_zipfile =
- s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
- iSizeVar;
-
- pfile_in_zip_read_info->stream.avail_in = (uInt)0;
-
- s->pfile_in_zip_read = pfile_in_zip_read_info;
-
-# ifndef NOUNCRYPT
- if (password != NULL)
- {
- int i;
- s->pcrc_32_tab = get_crc_table();
- init_keys(password,s->keys,s->pcrc_32_tab);
- if (ZSEEK(s->z_filefunc, s->filestream,
- s->pfile_in_zip_read->pos_in_zipfile +
- s->pfile_in_zip_read->byte_before_the_zipfile,
- SEEK_SET)!=0)
- return UNZ_INTERNALERROR;
- if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
- return UNZ_INTERNALERROR;
-
- for (i = 0; i<12; i++)
- zdecode(s->keys,s->pcrc_32_tab,source[i]);
-
- s->pfile_in_zip_read->pos_in_zipfile+=12;
- s->encrypted=1;
- }
-# endif
-
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzOpenCurrentFile (file)
- unzFile file;
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
-}
-
-extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
- unzFile file;
- const char* password;
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
-}
-
-extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
- unzFile file;
- int* method;
- int* level;
- int raw;
-{
- return unzOpenCurrentFile3(file, method, level, raw, NULL);
-}
-
-/*
- Read bytes from the current file.
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-extern int ZEXPORT unzReadCurrentFile (file, buf, len)
- unzFile file;
- voidp buf;
- unsigned len;
-{
- int err=UNZ_OK;
- uInt iRead = 0;
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if (pfile_in_zip_read_info->read_buffer == NULL)
- return UNZ_END_OF_LIST_OF_FILE;
- if (len==0)
- return 0;
-
- pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
-
- pfile_in_zip_read_info->stream.avail_out = (uInt)len;
-
- if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
- (!(pfile_in_zip_read_info->raw)))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
-
- if ((len>pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in) &&
- (pfile_in_zip_read_info->raw))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in;
-
- while (pfile_in_zip_read_info->stream.avail_out>0)
- {
- if ((pfile_in_zip_read_info->stream.avail_in==0) &&
- (pfile_in_zip_read_info->rest_read_compressed>0))
- {
- uInt uReadThis = UNZ_BUFSIZE;
- if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
- uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
- if (uReadThis == 0)
- return UNZ_EOF;
- if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->pos_in_zipfile +
- pfile_in_zip_read_info->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
- if (ZREAD(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->read_buffer,
- uReadThis)!=uReadThis)
- return UNZ_ERRNO;
-
-
-# ifndef NOUNCRYPT
- if(s->encrypted)
- {
- uInt i;
- for(i=0;i<uReadThis;i++)
- pfile_in_zip_read_info->read_buffer[i] =
- zdecode(s->keys,s->pcrc_32_tab,
- pfile_in_zip_read_info->read_buffer[i]);
- }
-# endif
-
-
- pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
-
- pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
-
- pfile_in_zip_read_info->stream.next_in =
- (Bytef*)pfile_in_zip_read_info->read_buffer;
- pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
- }
-
- if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
- {
- uInt uDoCopy,i ;
-
- if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- return (iRead==0) ? UNZ_EOF : iRead;
-
- if (pfile_in_zip_read_info->stream.avail_out <
- pfile_in_zip_read_info->stream.avail_in)
- uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
- else
- uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
-
- for (i=0;i<uDoCopy;i++)
- *(pfile_in_zip_read_info->stream.next_out+i) =
- *(pfile_in_zip_read_info->stream.next_in+i);
-
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
- pfile_in_zip_read_info->stream.next_out,
- uDoCopy);
- pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
- pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
- pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
- pfile_in_zip_read_info->stream.next_out += uDoCopy;
- pfile_in_zip_read_info->stream.next_in += uDoCopy;
- pfile_in_zip_read_info->stream.total_out += uDoCopy;
- iRead += uDoCopy;
- }
- else
- {
- uLong uTotalOutBefore,uTotalOutAfter;
- const Bytef *bufBefore;
- uLong uOutThis;
- int flush=Z_SYNC_FLUSH;
-
- uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
- bufBefore = pfile_in_zip_read_info->stream.next_out;
-
- /*
- if ((pfile_in_zip_read_info->rest_read_uncompressed ==
- pfile_in_zip_read_info->stream.avail_out) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- flush = Z_FINISH;
- */
- err=inflate(&pfile_in_zip_read_info->stream,flush);
-
- if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
- err = Z_DATA_ERROR;
-
- uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
-
- pfile_in_zip_read_info->crc32 =
- crc32(pfile_in_zip_read_info->crc32,bufBefore,
- (uInt)(uOutThis));
-
- pfile_in_zip_read_info->rest_read_uncompressed -=
- uOutThis;
-
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
- if (err==Z_STREAM_END)
- return (iRead==0) ? UNZ_EOF : iRead;
- if (err!=Z_OK)
- break;
- }
- }
-
- if (err==Z_OK)
- return iRead;
- return err;
-}
-
-
-/*
- Give the current position in uncompressed data
-*/
-extern z_off_t ZEXPORT unztell (file)
- unzFile file;
-{
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- return (z_off_t)pfile_in_zip_read_info->stream.total_out;
-}
-
-
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-extern int ZEXPORT unzeof (file)
- unzFile file;
-{
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
- return 1;
- else
- return 0;
-}
-
-
-
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field that can be read
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
- unzFile file;
- voidp buf;
- unsigned len;
-{
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- uInt read_now;
- uLong size_to_read;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
- pfile_in_zip_read_info->pos_local_extrafield);
-
- if (buf==NULL)
- return (int)size_to_read;
-
- if (len>size_to_read)
- read_now = (uInt)size_to_read;
- else
- read_now = (uInt)len ;
-
- if (read_now==0)
- return 0;
-
- if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->offset_local_extrafield +
- pfile_in_zip_read_info->pos_local_extrafield,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (ZREAD(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- buf,read_now)!=read_now)
- return UNZ_ERRNO;
-
- return (int)read_now;
-}
-
-/*
- Close the file in zip opened with unzipOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-extern int ZEXPORT unzCloseCurrentFile (file)
- unzFile file;
-{
- int err=UNZ_OK;
-
- unz_s* s;
- file_in_zip_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
- (!pfile_in_zip_read_info->raw))
- {
- if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
- err=UNZ_CRCERROR;
- }
-
-
- TRYFREE(pfile_in_zip_read_info->read_buffer);
- pfile_in_zip_read_info->read_buffer = NULL;
- if (pfile_in_zip_read_info->stream_initialised)
- inflateEnd(&pfile_in_zip_read_info->stream);
-
- pfile_in_zip_read_info->stream_initialised = 0;
- TRYFREE(pfile_in_zip_read_info);
-
- s->pfile_in_zip_read=NULL;
-
- return err;
-}
-
-
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
- unzFile file;
- char *szComment;
- uLong uSizeBuf;
-{
- int err=UNZ_OK;
- unz_s* s;
- uLong uReadThis ;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
-
- uReadThis = uSizeBuf;
- if (uReadThis>s->gi.size_comment)
- uReadThis = s->gi.size_comment;
-
- if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (uReadThis>0)
- {
- *szComment='\0';
- if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
- return UNZ_ERRNO;
- }
-
- if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
- *(szComment+s->gi.size_comment)='\0';
- return (int)uReadThis;
-}
-
-/* Additions by RX '2004 */
-extern uLong ZEXPORT unzGetOffset (file)
- unzFile file;
-{
- unz_s* s;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
- if (!s->current_file_ok)
- return 0;
- if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
- if (s->num_file==s->gi.number_entry)
- return 0;
- return s->pos_in_central_dir;
-}
-
-extern int ZEXPORT unzSetOffset (file, pos)
- unzFile file;
- uLong pos;
-{
- unz_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz_s*)file;
-
- s->pos_in_central_dir = pos;
- s->num_file = s->gi.number_entry; /* hack */
- err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
diff --git a/src/3rdparty/assimp/contrib/unzip/unzip.h b/src/3rdparty/assimp/contrib/unzip/unzip.h
deleted file mode 100644
index b247937c8..000000000
--- a/src/3rdparty/assimp/contrib/unzip/unzip.h
+++ /dev/null
@@ -1,354 +0,0 @@
-/* unzip.h -- IO for uncompress .zip files using zlib
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-
- This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
- WinZip, InfoZip tools and compatible.
-
- Multi volume ZipFile (span) are not supported.
- Encryption compatible with pkzip 2.04g only supported
- Old compressions used by old PKZip 1.x are not supported
-
-
- I WAIT FEEDBACK at mail info@winimage.com
- Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
-
-*/
-
-/* for more info about .ZIP format, see
- http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
- http://www.info-zip.org/pub/infozip/doc/
- PkWare has also a specification at :
- ftp://ftp.pkware.com/probdesc.zip
-*/
-
-#ifndef _unz_H
-#define _unz_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK (0)
-#define UNZ_END_OF_LIST_OF_FILE (-100)
-#define UNZ_ERRNO (Z_ERRNO)
-#define UNZ_EOF (0)
-#define UNZ_PARAMERROR (-102)
-#define UNZ_BADZIPFILE (-103)
-#define UNZ_INTERNALERROR (-104)
-#define UNZ_CRCERROR (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
- These data comes from the end of central dir */
-typedef struct unz_global_info_s
-{
- uLong number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info;
-
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- uLong compressed_size; /* compressed size 4 bytes */
- uLong uncompressed_size; /* uncompressed size 4 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity));
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
- "zlib/zlib113.zip".
- If the zipfile cannot be opened (file don't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
- zlib_filefunc_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unzOpen, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
- unz_global_info *pglobal_info));
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
- char *szComment,
- uLong uSizeBuf));
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
- const char *szFileName,
- int iCaseSensitivity));
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
- uLong pos_in_zip_directory; /* offset in zip file directory */
- uLong num_of_file; /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
- unz_file_info *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-/*
- Get Info about the current file
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
- the current file
- if szFileName!=NULL, the filemane string will be copied in szFileName
- (fileNameBufferSize is the size of the buffer)
- if extraField!=NULL, the extra field information will be copied in extraField
- (extraFieldBufferSize is the size of the buffer).
- This is the Central-header version of the extra field
- if szComment!=NULL, the comment string of the file will be copied in szComment
- (commentBufferSize is the size of the buffer)
-*/
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
- from it, and close it (you can close it before reading all the file)
- */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
- Open for reading data the current file in the zipfile.
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
- const char* password));
-/*
- Open for reading data the current file in the zipfile.
- password is a crypting password
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
- int* method,
- int* level,
- int raw));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
- int* method,
- int* level,
- int raw,
- const char* password));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read bytes from the current file (opened by unzOpenCurrentFile)
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-/*
- Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-
-/***************************************************************************/
-
-/* Get the current file offset */
-extern uLong ZEXPORT unzGetOffset (unzFile file);
-
-/* Set the current file offset */
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz_H */
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/doc/ReleaseNotes b/src/3rdparty/assimp/contrib/utf8cpp/doc/ReleaseNotes
deleted file mode 100644
index 364411a23..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/doc/ReleaseNotes
+++ /dev/null
@@ -1,12 +0,0 @@
-utf8 cpp library
-Release 2.3.4
-
-A minor bug fix release. Thanks to all who reported bugs.
-
-Note: Version 2.3.3 contained a regression, and therefore was removed.
-
-Changes from version 2.3.2
-- Bug fix [39]: checked.h Line 273 and unchecked.h Line 182 have an extra ';'
-- Bug fix [36]: replace_invalid() only works with back_inserter
-
-Files included in the release: utf8.h, core.h, checked.h, unchecked.h, utf8cpp.html, ReleaseNotes
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/doc/utf8cpp.html b/src/3rdparty/assimp/contrib/utf8cpp/doc/utf8cpp.html
deleted file mode 100644
index 6f2aacbe7..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/doc/utf8cpp.html
+++ /dev/null
@@ -1,1789 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
- <head>
- <meta name="generator" content=
- "HTML Tidy for Linux/x86 (vers 1st November 2002), see www.w3.org">
- <meta name="description" content=
- "A simple, portable and lightweigt C++ library for easy handling of UTF-8 encoded strings">
- <meta name="keywords" content="UTF-8 C++ portable utf8 unicode generic templates">
- <meta name="author" content="Nemanja Trifunovic">
- <title>
- UTF8-CPP: UTF-8 with C++ in a Portable Way
- </title>
- <style type="text/css">
- <!--
- span.return_value {
- color: brown;
- }
- span.keyword {
- color: blue;
- }
- span.preprocessor {
- color: navy;
- }
- span.literal {
- color: olive;
- }
- span.comment {
- color: green;
- }
- code {
- font-weight: bold;
- }
- ul.toc {
- list-style-type: none;
- }
- p.version {
- font-size: small;
- font-style: italic;
- }
- -->
- </style>
- </head>
- <body>
- <h1>
- UTF8-CPP: UTF-8 with C++ in a Portable Way
- </h1>
- <p>
- <a href="https://sourceforge.net/projects/utfcpp">The Sourceforge project page</a>
- </p>
- <div id="toc">
- <h2>
- Table of Contents
- </h2>
- <ul class="toc">
- <li>
- <a href="#introduction">Introduction</a>
- </li>
- <li>
- <a href="#examples">Examples of Use</a>
- <ul class="toc">
- <li>
- <a href=#introsample>Introductionary Sample </a>
- </li>
- <li>
- <a href=#validfile>Checking if a file contains valid UTF-8 text</a>
- </li>
- <li>
- <a href=#fixinvalid>Ensure that a string contains valid UTF-8 text</a>
- </li>
- </ul>
- <li>
- <a href="#reference">Reference</a>
- <ul class="toc">
- <li>
- <a href="#funutf8">Functions From utf8 Namespace </a>
- </li>
- <li>
- <a href="#typesutf8">Types From utf8 Namespace </a>
- </li>
- <li>
- <a href="#fununchecked">Functions From utf8::unchecked Namespace </a>
- </li>
- <li>
- <a href="#typesunchecked">Types From utf8::unchecked Namespace </a>
- </li>
- </ul>
- </li>
- <li>
- <a href="#points">Points of Interest</a>
- </li>
- <li>
- <a href="#links">Links</a>
- </li>
- </ul>
- </div>
- <h2 id="introduction">
- Introduction
- </h2>
- <p>
- Many C++ developers miss an easy and portable way of handling Unicode encoded
- strings. The original C++ Standard (known as C++98 or C++03) is Unicode agnostic.
- C++11 provides some support for Unicode on core language and library level:
- u8, u, and U character and string literals, char16_t and char32_t character types,
- u16string and u32string library classes, and codecvt support for conversions
- between Unicode encoding forms.
- In the meantime, developers use third party libraries like ICU, OS specific capabilities, or simply
- roll out their own solutions.
- </p>
- <p>
- In order to easily handle UTF-8 encoded Unicode strings, I came up with a small
- generic library. For anybody used to work with STL algorithms and iterators, it should be
- easy and natural to use. The code is freely available for any purpose - check out
- the license at the beginning of the utf8.h file. If you run into
- bugs or performance issues, please let me know and I'll do my best to address them.
- </p>
- <p>
- The purpose of this article is not to offer an introduction to Unicode in general,
- and UTF-8 in particular. If you are not familiar with Unicode, be sure to check out
- <a href="http://www.unicode.org/">Unicode Home Page</a> or some other source of
- information for Unicode. Also, it is not my aim to advocate the use of UTF-8
- encoded strings in C++ programs; if you want to handle UTF-8 encoded strings from
- C++, I am sure you have good reasons for it.
- </p>
- <h2 id="examples">
- Examples of use
- </h2>
- <h3 id="introsample">
- Introductionary Sample
- </h3>
- <p>
- To illustrate the use of the library, let's start with a small but complete program
- that opens a file containing UTF-8 encoded text, reads it line by line, checks each line
- for invalid UTF-8 byte sequences, and converts it to UTF-16 encoding and back to UTF-8:
- </p>
-<pre>
-<span class="preprocessor">#include &lt;fstream&gt;</span>
-<span class="preprocessor">#include &lt;iostream&gt;</span>
-<span class="preprocessor">#include &lt;string&gt;</span>
-<span class="preprocessor">#include &lt;vector&gt;</span>
-<span class="preprocessor">#include "utf8.h"</span>
-<span class="keyword">using namespace</span> std;
-<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">char</span>** argv)
-{
- <span class="keyword">if</span> (argc != <span class="literal">2</span>) {
- cout &lt;&lt; <span class="literal">"\nUsage: docsample filename\n"</span>;
- <span class="keyword">return</span> <span class="literal">0</span>;
- }
-
- <span class="keyword">const char</span>* test_file_path = argv[1];
- <span class="comment">// Open the test file (contains UTF-8 encoded text)</span>
- ifstream fs8(test_file_path);
- <span class="keyword">if</span> (!fs8.is_open()) {
- cout &lt;&lt; <span class=
-"literal">"Could not open "</span> &lt;&lt; test_file_path &lt;&lt; endl;
- <span class="keyword">return</span> <span class="literal">0</span>;
- }
-
- <span class="keyword">unsigned</span> line_count = <span class="literal">1</span>;
- string line;
- <span class="comment">// Play with all the lines in the file</span>
- <span class="keyword">while</span> (getline(fs8, line)) {
- <span class="comment">// check for invalid utf-8 (for a simple yes/no check, there is also utf8::is_valid function)</span>
- string::iterator end_it = utf8::find_invalid(line.begin(), line.end());
- <span class="keyword">if</span> (end_it != line.end()) {
- cout &lt;&lt; <span class=
-"literal">"Invalid UTF-8 encoding detected at line "</span> &lt;&lt; line_count &lt;&lt; <span
- class="literal">"\n"</span>;
- cout &lt;&lt; <span class=
-"literal">"This part is fine: "</span> &lt;&lt; string(line.begin(), end_it) &lt;&lt; <span
- class="literal">"\n"</span>;
- }
-
- <span class="comment">// Get the line length (at least for the valid part)</span>
- <span class="keyword">int</span> length = utf8::distance(line.begin(), end_it);
- cout &lt;&lt; <span class=
-"literal">"Length of line "</span> &lt;&lt; line_count &lt;&lt; <span class=
-"literal">" is "</span> &lt;&lt; length &lt;&lt; <span class="literal">"\n"</span>;
-
- <span class="comment">// Convert it to utf-16</span>
- vector&lt;unsigned short&gt; utf16line;
- utf8::utf8to16(line.begin(), end_it, back_inserter(utf16line));
-
- <span class="comment">// And back to utf-8</span>
- string utf8line;
- utf8::utf16to8(utf16line.begin(), utf16line.end(), back_inserter(utf8line));
-
- <span class="comment">// Confirm that the conversion went OK:</span>
- <span class="keyword">if</span> (utf8line != string(line.begin(), end_it))
- cout &lt;&lt; <span class=
-"literal">"Error in UTF-16 conversion at line: "</span> &lt;&lt; line_count &lt;&lt; <span
- class="literal">"\n"</span>;
-
- line_count++;
- }
- <span class="keyword">return</span> <span class="literal">0</span>;
-}
-</pre>
- <p>
- In the previous code sample, for each line we performed
- a detection of invalid UTF-8 sequences with <code>find_invalid</code>; the number
- of characters (more precisely - the number of Unicode code points, including the end
- of line and even BOM if there is one) in each line was
- determined with a use of <code>utf8::distance</code>; finally, we have converted
- each line to UTF-16 encoding with <code>utf8to16</code> and back to UTF-8 with
- <code>utf16to8</code>.
- </p>
- <h3 id="validfile">Checking if a file contains valid UTF-8 text</h3>
-<p>
-Here is a function that checks whether the content of a file is valid UTF-8 encoded text without
-reading the content into the memory:
-</p>
-<pre>
-<span class="keyword">bool</span> valid_utf8_file(i<span class="keyword">const char</span>* file_name)
-{
- ifstream ifs(file_name);
- <span class="keyword">if</span> (!ifs)
- <span class="keyword">return false</span>; <span class="comment">// even better, throw here</span>
-
- istreambuf_iterator&lt;<span class="keyword">char</span>&gt; it(ifs.rdbuf());
- istreambuf_iterator&lt;<span class="keyword">char</span>&gt; eos;
-
- <span class="keyword">return</span> utf8::is_valid(it, eos);
-}
-</pre>
-<p>
-Because the function <code>utf8::is_valid()</code> works with input iterators, we were able
-to pass an <code>istreambuf_iterator</code> to it and read the content of the file directly
-without loading it to the memory first.</p>
-<p>
-Note that other functions that take input iterator arguments can be used in a similar way. For
-instance, to read the content of a UTF-8 encoded text file and convert the text to UTF-16, just
-do something like:
-</p>
-<pre>
- utf8::utf8to16(it, eos, back_inserter(u16string));
-</pre>
- <h3 id="fixinvalid">Ensure that a string contains valid UTF-8 text</h3>
-<p>
-If we have some text that "probably" contains UTF-8 encoded text and we want to
-replace any invalid UTF-8 sequence with a replacement character, something like
-the following function may be used:
-</p>
-<pre>
-<span class="keyword">void</span> fix_utf8_string(std::string&amp; str)
-{
- std::string temp;
- utf8::replace_invalid(str.begin(), str.end(), back_inserter(temp));
- str = temp;
-}
-</pre>
-<p>The function will replace any invalid UTF-8 sequence with a Unicode replacement character.
-There is an overloaded function that enables the caller to supply their own replacement character.
-</p>
- <h2 id="reference">
- Reference
- </h2>
- <h3 id="funutf8">
- Functions From utf8 Namespace
- </h3>
- <h4>
- utf8::append
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Encodes a 32 bit code point as a UTF-8 sequence of octets and appends the sequence
- to a UTF-8 string.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-octet_iterator append(uint32_t cp, octet_iterator result);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an output iterator.<br>
- <code>cp</code>: a 32 bit integer representing a code point to append to the
- sequence.<br>
- <code>result</code>: an output iterator to the place in the sequence where to
- append the code point.<br>
- <span class="return_value">Return value</span>: an iterator pointing to the place
- after the newly appended sequence.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned char</span> u[<span class="literal">5</span>] = {<span
-class="literal">0</span>,<span class="literal">0</span>,<span class=
-"literal">0</span>,<span class="literal">0</span>,<span class="literal">0</span>};
-<span class="keyword">unsigned char</span>* end = append(<span class=
-"literal">0x0448</span>, u);
-assert (u[<span class="literal">0</span>] == <span class=
-"literal">0xd1</span> &amp;&amp; u[<span class="literal">1</span>] == <span class=
-"literal">0x88</span> &amp;&amp; u[<span class="literal">2</span>] == <span class=
-"literal">0</span> &amp;&amp; u[<span class="literal">3</span>] == <span class=
-"literal">0</span> &amp;&amp; u[<span class="literal">4</span>] == <span class=
-"literal">0</span>);
-</pre>
- <p>
- Note that <code>append</code> does not allocate any memory - it is the burden of
- the caller to make sure there is enough memory allocated for the operation. To make
- things more interesting, <code>append</code> can add anywhere between 1 and 4
- octets to the sequence. In practice, you would most often want to use
- <code>std::back_inserter</code> to ensure that the necessary memory is allocated.
- </p>
- <p>
- In case of an invalid code point, a <code>utf8::invalid_code_point</code> exception
- is thrown.
- </p>
- <h4>
- utf8::next
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Given the iterator to the beginning of the UTF-8 sequence, it returns the code
- point and moves the iterator to the next position.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t next(octet_iterator&amp; it, octet_iterator end);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>it</code>: a reference to an iterator pointing to the beginning of an UTF-8
- encoded code point. After the function returns, it is incremented to point to the
- beginning of the next code point.<br>
- <code>end</code>: end of the UTF-8 sequence to be processed. If <code>it</code>
- gets equal to <code>end</code> during the extraction of a code point, an
- <code>utf8::not_enough_room</code> exception is thrown.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- processed UTF-8 code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars;
-<span class="keyword">int</span> cp = next(w, twochars + <span class="literal">6</span>);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars + <span class="literal">3</span>);
-</pre>
- <p>
- This function is typically used to iterate through a UTF-8 encoded string.
- </p>
- <p>
- In case of an invalid UTF-8 seqence, a <code>utf8::invalid_utf8</code> exception is
- thrown.
- </p>
- <h4>
- utf8::peek_next
- </h4>
- <p class="version">
- Available in version 2.1 and later.
- </p>
- <p>
- Given the iterator to the beginning of the UTF-8 sequence, it returns the code
- point for the following sequence without changing the value of the iterator.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t peek_next(octet_iterator it, octet_iterator end);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>it</code>: an iterator pointing to the beginning of an UTF-8
- encoded code point.<br>
- <code>end</code>: end of the UTF-8 sequence to be processed. If <code>it</code>
- gets equal to <code>end</code> during the extraction of a code point, an
- <code>utf8::not_enough_room</code> exception is thrown.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- processed UTF-8 code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars;
-<span class="keyword">int</span> cp = peek_next(w, twochars + <span class="literal">6</span>);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- In case of an invalid UTF-8 seqence, a <code>utf8::invalid_utf8</code> exception is
- thrown.
- </p>
- <h4>
- utf8::prior
- </h4>
- <p class="version">
- Available in version 1.02 and later.
- </p>
- <p>
- Given a reference to an iterator pointing to an octet in a UTF-8 sequence, it
- decreases the iterator until it hits the beginning of the previous UTF-8 encoded
- code point and returns the 32 bits representation of the code point.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t prior(octet_iterator&amp; it, octet_iterator start);
-
-</pre>
- <p>
- <code>octet_iterator</code>: a bidirectional iterator.<br>
- <code>it</code>: a reference pointing to an octet within a UTF-8 encoded string.
- After the function returns, it is decremented to point to the beginning of the
- previous code point.<br>
- <code>start</code>: an iterator to the beginning of the sequence where the search
- for the beginning of a code point is performed. It is a
- safety measure to prevent passing the beginning of the string in the search for a
- UTF-8 lead octet.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- previous code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">unsigned char</span>* w = twochars + <span class=
-"literal">3</span>;
-<span class="keyword">int</span> cp = prior (w, twochars);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- This function has two purposes: one is two iterate backwards through a UTF-8
- encoded string. Note that it is usually a better idea to iterate forward instead,
- since <code>utf8::next</code> is faster. The second purpose is to find a beginning
- of a UTF-8 sequence if we have a random position within a string. Note that in that
- case <code>utf8::prior</code> may not detect an invalid UTF-8 sequence in some scenarios:
- for instance if there are superfluous trail octets, it will just skip them.
- </p>
- <p>
- <code>it</code> will typically point to the beginning of
- a code point, and <code>start</code> will point to the
- beginning of the string to ensure we don't go backwards too far. <code>it</code> is
- decreased until it points to a lead UTF-8 octet, and then the UTF-8 sequence
- beginning with that octet is decoded to a 32 bit representation and returned.
- </p>
- <p>
- In case <code>start</code> is reached before a UTF-8 lead octet is hit, or if an
- invalid UTF-8 sequence is started by the lead octet, an <code>invalid_utf8</code>
- exception is thrown.
- </p>
- <p>In case <code>start</code> equals <code>it</code>, a <code>not_enough_room</code>
- exception is thrown.
- <h4>
- utf8::previous
- </h4>
- <p class="version">
- Deprecated in version 1.02 and later.
- </p>
- <p>
- Given a reference to an iterator pointing to an octet in a UTF-8 seqence, it
- decreases the iterator until it hits the beginning of the previous UTF-8 encoded
- code point and returns the 32 bits representation of the code point.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t previous(octet_iterator&amp; it, octet_iterator pass_start);
-
-</pre>
- <p>
- <code>octet_iterator</code>: a random access iterator.<br>
- <code>it</code>: a reference pointing to an octet within a UTF-8 encoded string.
- After the function returns, it is decremented to point to the beginning of the
- previous code point.<br>
- <code>pass_start</code>: an iterator to the point in the sequence where the search
- for the beginning of a code point is aborted if no result was reached. It is a
- safety measure to prevent passing the beginning of the string in the search for a
- UTF-8 lead octet.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- previous code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">unsigned char</span>* w = twochars + <span class=
-"literal">3</span>;
-<span class="keyword">int</span> cp = previous (w, twochars - <span class=
-"literal">1</span>);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- <code>utf8::previous</code> is deprecated, and <code>utf8::prior</code> should
- be used instead, although the existing code can continue using this function.
- The problem is the parameter <code>pass_start</code> that points to the position
- just before the beginning of the sequence. Standard containers don't have the
- concept of "pass start" and the function can not be used with their iterators.
- </p>
- <p>
- <code>it</code> will typically point to the beginning of
- a code point, and <code>pass_start</code> will point to the octet just before the
- beginning of the string to ensure we don't go backwards too far. <code>it</code> is
- decreased until it points to a lead UTF-8 octet, and then the UTF-8 sequence
- beginning with that octet is decoded to a 32 bit representation and returned.
- </p>
- <p>
- In case <code>pass_start</code> is reached before a UTF-8 lead octet is hit, or if an
- invalid UTF-8 sequence is started by the lead octet, an <code>invalid_utf8</code>
- exception is thrown
- </p>
- <h4>
- utf8::advance
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Advances an iterator by the specified number of code points within an UTF-8
- sequence.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, typename distance_type&gt;
-<span class=
-"keyword">void</span> advance (octet_iterator&amp; it, distance_type n, octet_iterator end);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>distance_type</code>: an integral type convertible to <code>octet_iterator</code>'s difference type.<br>
- <code>it</code>: a reference to an iterator pointing to the beginning of an UTF-8
- encoded code point. After the function returns, it is incremented to point to the
- nth following code point.<br>
- <code>n</code>: a positive integer that shows how many code points we want to
- advance.<br>
- <code>end</code>: end of the UTF-8 sequence to be processed. If <code>it</code>
- gets equal to <code>end</code> during the extraction of a code point, an
- <code>utf8::not_enough_room</code> exception is thrown.<br>
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">unsigned char</span>* w = twochars;
-advance (w, <span class="literal">2</span>, twochars + <span class="literal">6</span>);
-assert (w == twochars + <span class="literal">5</span>);
-</pre>
- <p>
- This function works only "forward". In case of a negative <code>n</code>, there is
- no effect.
- </p>
- <p>
- In case of an invalid code point, a <code>utf8::invalid_code_point</code> exception
- is thrown.
- </p>
- <h4>
- utf8::distance
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Given the iterators to two UTF-8 encoded code points in a seqence, returns the
- number of code points between them.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-<span class=
-"keyword">typename</span> std::iterator_traits&lt;octet_iterator&gt;::difference_type distance (octet_iterator first, octet_iterator last);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>first</code>: an iterator to a beginning of a UTF-8 encoded code point.<br>
- <code>last</code>: an iterator to a "post-end" of the last UTF-8 encoded code
- point in the sequence we are trying to determine the length. It can be the
- beginning of a new code point, or not.<br>
- <span class="return_value">Return value</span> the distance between the iterators,
- in code points.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-size_t dist = utf8::distance(twochars, twochars + <span class="literal">5</span>);
-assert (dist == <span class="literal">2</span>);
-</pre>
- <p>
- This function is used to find the length (in code points) of a UTF-8 encoded
- string. The reason it is called <em>distance</em>, rather than, say,
- <em>length</em> is mainly because developers are used that <em>length</em> is an
- O(1) function. Computing the length of an UTF-8 string is a linear operation, and
- it looked better to model it after <code>std::distance</code> algorithm.
- </p>
- <p>
- In case of an invalid UTF-8 seqence, a <code>utf8::invalid_utf8</code> exception is
- thrown. If <code>last</code> does not point to the past-of-end of a UTF-8 seqence,
- a <code>utf8::not_enough_room</code> exception is thrown.
- </p>
- <h4>
- utf8::utf16to8
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-16 encoded string to UTF-8.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> u16bit_iterator, <span class=
-"keyword">typename</span> octet_iterator&gt;
-octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result);
-
-</pre>
- <p>
- <code>u16bit_iterator</code>: an input iterator.<br>
- <code>octet_iterator</code>: an output iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-16 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-16 encoded
- string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-8 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-8 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned short</span> utf16string[] = {<span class=
-"literal">0x41</span>, <span class="literal">0x0448</span>, <span class=
-"literal">0x65e5</span>, <span class="literal">0xd834</span>, <span class=
-"literal">0xdd1e</span>};
-vector&lt;<span class="keyword">unsigned char</span>&gt; utf8result;
-utf16to8(utf16string, utf16string + <span class=
-"literal">5</span>, back_inserter(utf8result));
-assert (utf8result.size() == <span class="literal">10</span>);
-</pre>
- <p>
- In case of invalid UTF-16 sequence, a <code>utf8::invalid_utf16</code> exception is
- thrown.
- </p>
- <h4>
- utf8::utf8to16
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts an UTF-8 encoded string to UTF-16
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> u16bit_iterator, typename octet_iterator&gt;
-u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>u16bit_iterator</code>: an output iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 encoded
- string to convert. &lt; br /&gt; <code>end</code>: an iterator pointing to
- pass-the-end of the UTF-8 encoded string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-16 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-16 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span> utf8_with_surrogates[] = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88\xf0\x9d\x84\x9e"</span>;
-vector &lt;<span class="keyword">unsigned short</span>&gt; utf16result;
-utf8to16(utf8_with_surrogates, utf8_with_surrogates + <span class=
-"literal">9</span>, back_inserter(utf16result));
-assert (utf16result.size() == <span class="literal">4</span>);
-assert (utf16result[<span class="literal">2</span>] == <span class=
-"literal">0xd834</span>);
-assert (utf16result[<span class="literal">3</span>] == <span class=
-"literal">0xdd1e</span>);
-</pre>
- <p>
- In case of an invalid UTF-8 seqence, a <code>utf8::invalid_utf8</code> exception is
- thrown. If <code>end</code> does not point to the past-of-end of a UTF-8 seqence, a
- <code>utf8::not_enough_room</code> exception is thrown.
- </p>
- <h4>
- utf8::utf32to8
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-32 encoded string to UTF-8.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, typename u32bit_iterator&gt;
-octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an output iterator.<br>
- <code>u32bit_iterator</code>: an input iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-32 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-32 encoded
- string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-8 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-8 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">int</span> utf32string[] = {<span class=
-"literal">0x448</span>, <span class="literal">0x65E5</span>, <span class=
-"literal">0x10346</span>, <span class="literal">0</span>};
-vector&lt;<span class="keyword">unsigned char</span>&gt; utf8result;
-utf32to8(utf32string, utf32string + <span class=
-"literal">3</span>, back_inserter(utf8result));
-assert (utf8result.size() == <span class="literal">9</span>);
-</pre>
- <p>
- In case of invalid UTF-32 string, a <code>utf8::invalid_code_point</code> exception
- is thrown.
- </p>
- <h4>
- utf8::utf8to32
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-8 encoded string to UTF-32.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, <span class=
-"keyword">typename</span> u32bit_iterator&gt;
-u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>u32bit_iterator</code>: an output iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-8 encoded string
- to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-32 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-32 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-vector&lt;<span class="keyword">int</span>&gt; utf32result;
-utf8to32(twochars, twochars + <span class=
-"literal">5</span>, back_inserter(utf32result));
-assert (utf32result.size() == <span class="literal">2</span>);
-</pre>
- <p>
- In case of an invalid UTF-8 seqence, a <code>utf8::invalid_utf8</code> exception is
- thrown. If <code>end</code> does not point to the past-of-end of a UTF-8 seqence, a
- <code>utf8::not_enough_room</code> exception is thrown.
- </p>
- <h4>
- utf8::find_invalid
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Detects an invalid sequence within a UTF-8 string.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-octet_iterator find_invalid(octet_iterator start, octet_iterator end);
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 string to
- test for validity.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-8 string to test
- for validity.<br>
- <span class="return_value">Return value</span>: an iterator pointing to the first
- invalid octet in the UTF-8 string. In case none were found, equals
- <code>end</code>.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span> utf_invalid[] = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88\xfa"</span>;
-<span class=
-"keyword">char</span>* invalid = find_invalid(utf_invalid, utf_invalid + <span class=
-"literal">6</span>);
-assert (invalid == utf_invalid + <span class="literal">5</span>);
-</pre>
- <p>
- This function is typically used to make sure a UTF-8 string is valid before
- processing it with other functions. It is especially important to call it if before
- doing any of the <em>unchecked</em> operations on it.
- </p>
- <h4>
- utf8::is_valid
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Checks whether a sequence of octets is a valid UTF-8 string.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-<span class="keyword">bool</span> is_valid(octet_iterator start, octet_iterator end);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 string to
- test for validity.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-8 string to test
- for validity.<br>
- <span class="return_value">Return value</span>: <code>true</code> if the sequence
- is a valid UTF-8 string; <code>false</code> if not.
- </p>
- Example of use:
-<pre>
-<span class="keyword">char</span> utf_invalid[] = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88\xfa"</span>;
-<span class="keyword">bool</span> bvalid = is_valid(utf_invalid, utf_invalid + <span
-class="literal">6</span>);
-assert (bvalid == false);
-</pre>
- <p>
- <code>is_valid</code> is a shorthand for <code>find_invalid(start, end) ==
- end;</code>. You may want to use it to make sure that a byte seqence is a valid
- UTF-8 string without the need to know where it fails if it is not valid.
- </p>
- <h4>
- utf8::replace_invalid
- </h4>
- <p class="version">
- Available in version 2.0 and later.
- </p>
- <p>
- Replaces all invalid UTF-8 sequences within a string with a replacement marker.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, <span class=
-"keyword">typename</span> output_iterator&gt;
-output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement);
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, <span class=
-"keyword">typename</span> output_iterator&gt;
-output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out);
-
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>output_iterator</code>: an output iterator.<br>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 string to
- look for invalid UTF-8 sequences.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-8 string to look
- for invalid UTF-8 sequences.<br>
- <code>out</code>: An output iterator to the range where the result of replacement
- is stored.<br>
- <code>replacement</code>: A Unicode code point for the replacement marker. The
- version without this parameter assumes the value <code>0xfffd</code><br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the UTF-8 string with replaced invalid sequences.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span> invalid_sequence[] = <span class=
-"literal">"a\x80\xe0\xa0\xc0\xaf\xed\xa0\x80z"</span>;
-vector&lt;<span class="keyword">char</span>&gt; replace_invalid_result;
-replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), back_inserter(replace_invalid_result), <span
- class="literal">'?'</span>);
-bvalid = is_valid(replace_invalid_result.begin(), replace_invalid_result.end());
-assert (bvalid);
-<span class="keyword">char</span>* fixed_invalid_sequence = <span class=
-"literal">"a????z"</span>;
-assert (std::equal(replace_invalid_result.begin(), replace_invalid_result.end(), fixed_invalid_sequence));
-</pre>
- <p>
- <code>replace_invalid</code> does not perform in-place replacement of invalid
- sequences. Rather, it produces a copy of the original string with the invalid
- sequences replaced with a replacement marker. Therefore, <code>out</code> must not
- be in the <code>[start, end]</code> range.
- </p>
- <p>
- If <code>end</code> does not point to the past-of-end of a UTF-8 sequence, a
- <code>utf8::not_enough_room</code> exception is thrown.
- </p>
- <h4>
- utf8::starts_with_bom
- </h4>
- <p class="version">
- Available in version 2.3 and later. Relaces deprecated <code>is_bom()</code> function.
- </p>
- <p>
- Checks whether an octet sequence starts with a UTF-8 byte order mark (BOM)
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-<span class="keyword">bool</span> starts_with_bom (octet_iterator it, octet_iterator end);
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>it</code>: beginning of the octet sequence to check<br>
- <code>end</code>: pass-end of the sequence to check<br>
- <span class="return_value">Return value</span>: <code>true</code> if the sequence
- starts with a UTF-8 byte order mark; <code>false</code> if not.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned char</span> byte_order_mark[] = {<span class=
-"literal">0xef</span>, <span class="literal">0xbb</span>, <span class=
-"literal">0xbf</span>};
-<span class="keyword">bool</span> bbom = starts_with_bom(byte_order_mark, byte_order_mark + <span class="keyword">sizeof</span>(byte_order_mark));
-assert (bbom == <span class="literal">true</span>);
-</pre>
- <p>
- The typical use of this function is to check the first three bytes of a file. If
- they form the UTF-8 BOM, we want to skip them before processing the actual UTF-8
- encoded text.
- </p>
- <h4>
- utf8::is_bom
- </h4>
- <p class="version">
- Available in version 1.0 and later. Deprecated in version 2.3. <code>starts_with_bom()</code> should be used
- instead.
- </p>
- <p>
- Checks whether a sequence of three octets is a UTF-8 byte order mark (BOM)
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-<span class="keyword">bool</span> is_bom (octet_iterator it); <span class="comment"> // Deprecated</span>
-</pre>
- <p>
- <code>octet_iterator</code>: an input iterator.<br>
- <code>it</code>: beginning of the 3-octet sequence to check<br>
- <span class="return_value">Return value</span>: <code>true</code> if the sequence
- is UTF-8 byte order mark; <code>false</code> if not.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned char</span> byte_order_mark[] = {<span class=
-"literal">0xef</span>, <span class="literal">0xbb</span>, <span class=
-"literal">0xbf</span>};
-<span class="keyword">bool</span> bbom = is_bom(byte_order_mark);
-assert (bbom == <span class="literal">true</span>);
-</pre>
- <p>
- The typical use of this function is to check the first three bytes of a file. If
- they form the UTF-8 BOM, we want to skip them before processing the actual UTF-8
- encoded text.
- </p>
- <p>
- If a sequence is
- shorter than three bytes, an invalid iterator will be dereferenced. Therefore, this function is deprecated
- in favor of <code>starts_with_bom()</code>that takes the end of sequence as an argument.
- </p>
- <h3 id="typesutf8">
- Types From utf8 Namespace
- </h3>
- <h4>utf8::exception
- </h4>
- <p class="version">
- Available in version 2.3 and later.
- </p>
- <p>
- Base class for the exceptions thrown by UTF CPP library functions.
- </p>
-<pre>
-<span class="keyword">class</span> exception : <span class="keyword">public</span> std::exception {};
-</pre>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">try</span> {
- code_that_uses_utf_cpp_library();
-}
-<span class="keyword">catch</span>(<span class="keyword">const</span> utf8::exception&amp; utfcpp_ex) {
- cerr &lt;&lt; utfcpp_ex.what();
-}
-</pre>
-
- <h4>utf8::invalid_code_point
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Thrown by UTF8 CPP functions such as <code>advance</code> and <code>next</code> if an UTF-8 sequence represents and invalid code point.
- </p>
-
-<pre>
-<span class="keyword">class</span> invalid_code_point : <span class="keyword">public</span> exception {
-<span class="keyword">public</span>:
- uint32_t code_point() <span class="keyword">const</span>;
-};
-
-</pre>
- <p>
- Member function <code>code_point()</code> can be used to determine the invalid code point that
- caused the exception to be thrown.
- </p>
- <h4>utf8::invalid_utf8
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Thrown by UTF8 CPP functions such as <code>next</code> and <code>prior</code> if an invalid UTF-8 sequence
- is detected during decoding.
- </p>
-
-<pre>
-<span class="keyword">class</span> invalid_utf8 : <span class="keyword">public</span> exception {
-<span class="keyword">public</span>:
- uint8_t utf8_octet() <span class="keyword">const</span>;
-};
-</pre>
-
- <p>
- Member function <code>utf8_octet()</code> can be used to determine the beginning of the byte
- sequence that caused the exception to be thrown.
- </p>
-</pre>
- <h4>utf8::invalid_utf16
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Thrown by UTF8 CPP function <code>utf16to8</code> if an invalid UTF-16 sequence
- is detected during decoding.
- </p>
-
-<pre>
-<span class="keyword">class</span> invalid_utf16 : <span class="keyword">public</span> exception {
-<span class="keyword">public</span>:
- uint16_t utf16_word() <span class="keyword">const</span>;
-};
-</pre>
-
- <p>
- Member function <code>utf16_word()</code> can be used to determine the UTF-16 code unit
- that caused the exception to be thrown.
- </p>
- <h4>utf8::not_enough_room
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Thrown by UTF8 CPP functions such as <code>next</code> if the end of the decoded UTF-8 sequence
- was reached before the code point was decoded.
- </p>
-
-<pre>
-<span class="keyword">class</span> not_enough_room : <span class="keyword">public</span> exception {};
-</pre>
- <h4>
- utf8::iterator
- </h4>
- <p class="version">
- Available in version 2.0 and later.
- </p>
- <p>
- Adapts the underlying octet iterator to iterate over the sequence of code points,
- rather than raw octets.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class="keyword">typename</span> octet_iterator&gt;
-<span class="keyword">class</span> iterator;
-</pre>
-
- <h5>Member functions</h5>
- <dl>
- <dt><code>iterator();</code> <dd> the deafult constructor; the underlying <code>octet_iterator</code> is
- constructed with its default constructor.
- <dt><code><span class="keyword">explicit</span> iterator (const octet_iterator&amp; octet_it,
- const octet_iterator&amp; range_start,
- const octet_iterator&amp; range_end);</code> <dd> a constructor
- that initializes the underlying <code>octet_iterator</code> with <code>octet_it</code>
- and sets the range in which the iterator is considered valid.
- <dt><code>octet_iterator base () <span class="keyword">const</span>;</code> <dd> returns the
- underlying <code>octet_iterator</code>.
- <dt><code>uint32_t operator * () <span class="keyword">const</span>;</code> <dd> decodes the utf-8 sequence
- the underlying <code>octet_iterator</code> is pointing to and returns the code point.
- <dt><code><span class="keyword">bool operator</span> == (const iterator&amp; rhs)
- <span class="keyword">const</span>;</code> <dd> returns <span class="keyword">true</span>
- if the two underlaying iterators are equal.
- <dt><code><span class="keyword">bool operator</span> != (const iterator&amp; rhs)
- <span class="keyword">const</span>;</code> <dd> returns <span class="keyword">true</span>
- if the two underlaying iterators are not equal.
- <dt><code>iterator&amp; <span class="keyword">operator</span> ++ (); </code> <dd> the prefix increment - moves
- the iterator to the next UTF-8 encoded code point.
- <dt><code>iterator <span class="keyword">operator</span> ++ (<span class="keyword">int</span>); </code> <dd>
- the postfix increment - moves the iterator to the next UTF-8 encoded code point and returns the current one.
- <dt><code>iterator&amp; <span class="keyword">operator</span> -- (); </code> <dd> the prefix decrement - moves
- the iterator to the previous UTF-8 encoded code point.
- <dt><code>iterator <span class="keyword">operator</span> -- (<span class="keyword">int</span>); </code> <dd>
- the postfix decrement - moves the iterator to the previous UTF-8 encoded code point and returns the current one.
- </dl>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* threechars = <span class="literal">"\xf0\x90\x8d\x86\xe6\x97\xa5\xd1\x88"</span>;
-utf8::iterator&lt;<span class="keyword">char</span>*&gt; it(threechars, threechars, threechars + <span class="literal">9</span>);
-utf8::iterator&lt;<span class="keyword">char</span>*&gt; it2 = it;
-assert (it2 == it);
-assert (*it == <span class="literal">0x10346</span>);
-assert (*(++it) == <span class="literal">0x65e5</span>);
-assert ((*it++) == <span class="literal">0x65e5</span>);
-assert (*it == <span class="literal">0x0448</span>);
-assert (it != it2);
-utf8::iterator&lt;<span class="keyword">char</span>*&gt; endit (threechars + <span class="literal">9</span>, threechars, threechars + <span class="literal">9</span>);
-assert (++it == endit);
-assert (*(--it) == <span class="literal">0x0448</span>);
-assert ((*it--) == <span class="literal">0x0448</span>);
-assert (*it == <span class="literal">0x65e5</span>);
-assert (--it == utf8::iterator&lt;<span class="keyword">char</span>*&gt;(threechars, threechars, threechars + <span class="literal">9</span>));
-assert (*it == <span class="literal">0x10346</span>);
-</pre>
- <p>
- The purpose of <code>utf8::iterator</code> adapter is to enable easy iteration as well as the use of STL
- algorithms with UTF-8 encoded strings. Increment and decrement operators are implemented in terms of
- <code>utf8::next()</code> and <code>utf8::prior()</code> functions.
- </p>
- <p>
- Note that <code>utf8::iterator</code> adapter is a checked iterator. It operates on the range specified in
- the constructor; any attempt to go out of that range will result in an exception. Even the comparison operators
- require both iterator object to be constructed against the same range - otherwise an exception is thrown. Typically,
- the range will be determined by sequence container functions <code>begin</code> and <code>end</code>, i.e.:
- </p>
-<pre>
-std::string s = <span class="literal">"example"</span>;
-utf8::iterator i (s.begin(), s.begin(), s.end());
-</pre>
- <h3 id="fununchecked">
- Functions From utf8::unchecked Namespace
- </h3>
- <h4>
- utf8::unchecked::append
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Encodes a 32 bit code point as a UTF-8 sequence of octets and appends the sequence
- to a UTF-8 string.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-octet_iterator append(uint32_t cp, octet_iterator result);
-
-</pre>
- <p>
- <code>cp</code>: A 32 bit integer representing a code point to append to the
- sequence.<br>
- <code>result</code>: An output iterator to the place in the sequence where to
- append the code point.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the newly appended sequence.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned char</span> u[<span class="literal">5</span>] = {<span
-class="literal">0</span>,<span class="literal">0</span>,<span class=
-"literal">0</span>,<span class="literal">0</span>,<span class="literal">0</span>};
-<span class="keyword">unsigned char</span>* end = unchecked::append(<span class=
-"literal">0x0448</span>, u);
-assert (u[<span class="literal">0</span>] == <span class=
-"literal">0xd1</span> &amp;&amp; u[<span class="literal">1</span>] == <span class=
-"literal">0x88</span> &amp;&amp; u[<span class="literal">2</span>] == <span class=
-"literal">0</span> &amp;&amp; u[<span class="literal">3</span>] == <span class=
-"literal">0</span> &amp;&amp; u[<span class="literal">4</span>] == <span class=
-"literal">0</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::append</code>. It does not
- check for validity of the supplied code point, and may produce an invalid UTF-8
- sequence.
- </p>
- <h4>
- utf8::unchecked::next
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Given the iterator to the beginning of a UTF-8 sequence, it returns the code point
- and moves the iterator to the next position.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t next(octet_iterator&amp; it);
-
-</pre>
- <p>
- <code>it</code>: a reference to an iterator pointing to the beginning of an UTF-8
- encoded code point. After the function returns, it is incremented to point to the
- beginning of the next code point.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- processed UTF-8 code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars;
-<span class="keyword">int</span> cp = unchecked::next(w);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars + <span class="literal">3</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::next</code>. It does not
- check for validity of the supplied UTF-8 sequence.
- </p>
- <h4>
- utf8::unchecked::peek_next
- </h4>
- <p class="version">
- Available in version 2.1 and later.
- </p>
- <p>
- Given the iterator to the beginning of a UTF-8 sequence, it returns the code point.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t peek_next(octet_iterator it);
-
-</pre>
- <p>
- <code>it</code>: an iterator pointing to the beginning of an UTF-8
- encoded code point.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- processed UTF-8 code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars;
-<span class="keyword">int</span> cp = unchecked::peek_next(w);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::peek_next</code>. It does not
- check for validity of the supplied UTF-8 sequence.
- </p>
- <h4>
- utf8::unchecked::prior
- </h4>
- <p class="version">
- Available in version 1.02 and later.
- </p>
- <p>
- Given a reference to an iterator pointing to an octet in a UTF-8 seqence, it
- decreases the iterator until it hits the beginning of the previous UTF-8 encoded
- code point and returns the 32 bits representation of the code point.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t prior(octet_iterator&amp; it);
-
-</pre>
- <p>
- <code>it</code>: a reference pointing to an octet within a UTF-8 encoded string.
- After the function returns, it is decremented to point to the beginning of the
- previous code point.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- previous code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars + <span class="literal">3</span>;
-<span class="keyword">int</span> cp = unchecked::prior (w);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::prior</code>. It does not
- check for validity of the supplied UTF-8 sequence and offers no boundary checking.
- </p>
- <h4>
- utf8::unchecked::previous (deprecated, see utf8::unchecked::prior)
- </h4>
- <p class="version">
- Deprecated in version 1.02 and later.
- </p>
- <p>
- Given a reference to an iterator pointing to an octet in a UTF-8 seqence, it
- decreases the iterator until it hits the beginning of the previous UTF-8 encoded
- code point and returns the 32 bits representation of the code point.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-uint32_t previous(octet_iterator&amp; it);
-
-</pre>
- <p>
- <code>it</code>: a reference pointing to an octet within a UTF-8 encoded string.
- After the function returns, it is decremented to point to the beginning of the
- previous code point.<br>
- <span class="return_value">Return value</span>: the 32 bit representation of the
- previous code point.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars + <span class="literal">3</span>;
-<span class="keyword">int</span> cp = unchecked::previous (w);
-assert (cp == <span class="literal">0x65e5</span>);
-assert (w == twochars);
-</pre>
- <p>
- The reason this function is deprecated is just the consistency with the "checked"
- versions, where <code>prior</code> should be used instead of <code>previous</code>.
- In fact, <code>unchecked::previous</code> behaves exactly the same as <code>
- unchecked::prior</code>
- </p>
- <p>
- This is a faster but less safe version of <code>utf8::previous</code>. It does not
- check for validity of the supplied UTF-8 sequence and offers no boundary checking.
- </p>
- <h4>
- utf8::unchecked::advance
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Advances an iterator by the specified number of code points within an UTF-8
- sequence.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, typename distance_type&gt;
-<span class="keyword">void</span> advance (octet_iterator&amp; it, distance_type n);
-
-</pre>
- <p>
- <code>it</code>: a reference to an iterator pointing to the beginning of an UTF-8
- encoded code point. After the function returns, it is incremented to point to the
- nth following code point.<br>
- <code>n</code>: a positive integer that shows how many code points we want to
- advance.<br>
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-<span class="keyword">char</span>* w = twochars;
-unchecked::advance (w, <span class="literal">2</span>);
-assert (w == twochars + <span class="literal">5</span>);
-</pre>
- <p>
- This function works only "forward". In case of a negative <code>n</code>, there is
- no effect.
- </p>
- <p>
- This is a faster but less safe version of <code>utf8::advance</code>. It does not
- check for validity of the supplied UTF-8 sequence and offers no boundary checking.
- </p>
- <h4>
- utf8::unchecked::distance
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Given the iterators to two UTF-8 encoded code points in a seqence, returns the
- number of code points between them.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator&gt;
-<span class=
-"keyword">typename</span> std::iterator_traits&lt;octet_iterator&gt;::difference_type distance (octet_iterator first, octet_iterator last);
-</pre>
- <p>
- <code>first</code>: an iterator to a beginning of a UTF-8 encoded code point.<br>
- <code>last</code>: an iterator to a "post-end" of the last UTF-8 encoded code
- point in the sequence we are trying to determine the length. It can be the
- beginning of a new code point, or not.<br>
- <span class="return_value">Return value</span> the distance between the iterators,
- in code points.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-size_t dist = utf8::unchecked::distance(twochars, twochars + <span class=
-"literal">5</span>);
-assert (dist == <span class="literal">2</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::distance</code>. It does not
- check for validity of the supplied UTF-8 sequence.
- </p>
- <h4>
- utf8::unchecked::utf16to8
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-16 encoded string to UTF-8.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> u16bit_iterator, <span class=
-"keyword">typename</span> octet_iterator&gt;
-octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result);
-
-</pre>
- <p>
- <code>start</code>: an iterator pointing to the beginning of the UTF-16 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-16 encoded
- string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-8 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-8 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">unsigned short</span> utf16string[] = {<span class=
-"literal">0x41</span>, <span class="literal">0x0448</span>, <span class=
-"literal">0x65e5</span>, <span class="literal">0xd834</span>, <span class=
-"literal">0xdd1e</span>};
-vector&lt;<span class="keyword">unsigned char</span>&gt; utf8result;
-unchecked::utf16to8(utf16string, utf16string + <span class=
-"literal">5</span>, back_inserter(utf8result));
-assert (utf8result.size() == <span class="literal">10</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::utf16to8</code>. It does not
- check for validity of the supplied UTF-16 sequence.
- </p>
- <h4>
- utf8::unchecked::utf8to16
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts an UTF-8 encoded string to UTF-16
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> u16bit_iterator, typename octet_iterator&gt;
-u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result);
-
-</pre>
- <p>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 encoded
- string to convert. &lt; br /&gt; <code>end</code>: an iterator pointing to
- pass-the-end of the UTF-8 encoded string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-16 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-16 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span> utf8_with_surrogates[] = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88\xf0\x9d\x84\x9e"</span>;
-vector &lt;<span class="keyword">unsigned short</span>&gt; utf16result;
-unchecked::utf8to16(utf8_with_surrogates, utf8_with_surrogates + <span class=
-"literal">9</span>, back_inserter(utf16result));
-assert (utf16result.size() == <span class="literal">4</span>);
-assert (utf16result[<span class="literal">2</span>] == <span class=
-"literal">0xd834</span>);
-assert (utf16result[<span class="literal">3</span>] == <span class=
-"literal">0xdd1e</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::utf8to16</code>. It does not
- check for validity of the supplied UTF-8 sequence.
- </p>
- <h4>
- utf8::unchecked::utf32to8
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-32 encoded string to UTF-8.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, <span class=
-"keyword">typename</span> u32bit_iterator&gt;
-octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result);
-
-</pre>
- <p>
- <code>start</code>: an iterator pointing to the beginning of the UTF-32 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-32 encoded
- string to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-8 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-8 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">int</span> utf32string[] = {<span class=
-"literal">0x448</span>, <span class="literal">0x65e5</span>, <span class=
-"literal">0x10346</span>, <span class="literal">0</span>};
-vector&lt;<span class="keyword">unsigned char</span>&gt; utf8result;
-utf32to8(utf32string, utf32string + <span class=
-"literal">3</span>, back_inserter(utf8result));
-assert (utf8result.size() == <span class="literal">9</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::utf32to8</code>. It does not
- check for validity of the supplied UTF-32 sequence.
- </p>
- <h4>
- utf8::unchecked::utf8to32
- </h4>
- <p class="version">
- Available in version 1.0 and later.
- </p>
- <p>
- Converts a UTF-8 encoded string to UTF-32.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class=
-"keyword">typename</span> octet_iterator, typename u32bit_iterator&gt;
-u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result);
-
-</pre>
- <p>
- <code>start</code>: an iterator pointing to the beginning of the UTF-8 encoded
- string to convert.<br>
- <code>end</code>: an iterator pointing to pass-the-end of the UTF-8 encoded string
- to convert.<br>
- <code>result</code>: an output iterator to the place in the UTF-32 string where to
- append the result of conversion.<br>
- <span class="return_value">Return value</span>: An iterator pointing to the place
- after the appended UTF-32 string.
- </p>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* twochars = <span class=
-"literal">"\xe6\x97\xa5\xd1\x88"</span>;
-vector&lt;<span class="keyword">int</span>&gt; utf32result;
-unchecked::utf8to32(twochars, twochars + <span class=
-"literal">5</span>, back_inserter(utf32result));
-assert (utf32result.size() == <span class="literal">2</span>);
-</pre>
- <p>
- This is a faster but less safe version of <code>utf8::utf8to32</code>. It does not
- check for validity of the supplied UTF-8 sequence.
- </p>
- <h3 id="typesunchecked">
- Types From utf8::unchecked Namespace
- </h3>
- <h4>
- utf8::iterator
- </h4>
- <p class="version">
- Available in version 2.0 and later.
- </p>
- <p>
- Adapts the underlying octet iterator to iterate over the sequence of code points,
- rather than raw octets.
- </p>
-<pre>
-<span class="keyword">template</span> &lt;<span class="keyword">typename</span> octet_iterator&gt;
-<span class="keyword">class</span> iterator;
-</pre>
-
- <h5>Member functions</h5>
- <dl>
- <dt><code>iterator();</code> <dd> the deafult constructor; the underlying <code>octet_iterator</code> is
- constructed with its default constructor.
- <dt><code><span class="keyword">explicit</span> iterator (const octet_iterator&amp; octet_it);
- </code> <dd> a constructor
- that initializes the underlying <code>octet_iterator</code> with <code>octet_it</code>
- <dt><code>octet_iterator base () <span class="keyword">const</span>;</code> <dd> returns the
- underlying <code>octet_iterator</code>.
- <dt><code>uint32_t operator * () <span class="keyword">const</span>;</code> <dd> decodes the utf-8 sequence
- the underlying <code>octet_iterator</code> is pointing to and returns the code point.
- <dt><code><span class="keyword">bool operator</span> == (const iterator&amp; rhs)
- <span class="keyword">const</span>;</code> <dd> returns <span class="keyword">true</span>
- if the two underlaying iterators are equal.
- <dt><code><span class="keyword">bool operator</span> != (const iterator&amp; rhs)
- <span class="keyword">const</span>;</code> <dd> returns <span class="keyword">true</span>
- if the two underlaying iterators are not equal.
- <dt><code>iterator&amp; <span class="keyword">operator</span> ++ (); </code> <dd> the prefix increment - moves
- the iterator to the next UTF-8 encoded code point.
- <dt><code>iterator <span class="keyword">operator</span> ++ (<span class="keyword">int</span>); </code> <dd>
- the postfix increment - moves the iterator to the next UTF-8 encoded code point and returns the current one.
- <dt><code>iterator&amp; <span class="keyword">operator</span> -- (); </code> <dd> the prefix decrement - moves
- the iterator to the previous UTF-8 encoded code point.
- <dt><code>iterator <span class="keyword">operator</span> -- (<span class="keyword">int</span>); </code> <dd>
- the postfix decrement - moves the iterator to the previous UTF-8 encoded code point and returns the current one.
- </dl>
- <p>
- Example of use:
- </p>
-<pre>
-<span class="keyword">char</span>* threechars = <span class="literal">"\xf0\x90\x8d\x86\xe6\x97\xa5\xd1\x88"</span>;
-utf8::unchecked::iterator&lt;<span class="keyword">char</span>*&gt; un_it(threechars);
-utf8::unchecked::iterator&lt;<span class="keyword">char</span>*&gt; un_it2 = un_it;
-assert (un_it2 == un_it);
-assert (*un_it == <span class="literal">0x10346</span>);
-assert (*(++un_it) == <span class="literal">0x65e5</span>);
-assert ((*un_it++) == <span class="literal">0x65e5</span>);
-assert (*un_it == <span class="literal">0x0448</span>);
-assert (un_it != un_it2);
-utf8::::unchecked::iterator&lt;<span class="keyword">char</span>*&gt; un_endit (threechars + <span class="literal">9</span>);
-assert (++un_it == un_endit);
-assert (*(--un_it) == <span class="literal">0x0448</span>);
-assert ((*un_it--) == <span class="literal">0x0448</span>);
-assert (*un_it == <span class="literal">0x65e5</span>);
-assert (--un_it == utf8::unchecked::iterator&lt;<span class="keyword">char</span>*&gt;(threechars));
-assert (*un_it == <span class="literal">0x10346</span>);
-</pre>
- <p>
- This is an unchecked version of <code>utf8::iterator</code>. It is faster in many cases, but offers
- no validity or range checks.
- </p>
- <h2 id="points">
- Points of interest
- </h2>
- <h4>
- Design goals and decisions
- </h4>
- <p>
- The library was designed to be:
- </p>
- <ol>
- <li>
- Generic: for better or worse, there are many C++ string classes out there, and
- the library should work with as many of them as possible.
- </li>
- <li>
- Portable: the library should be portable both accross different platforms and
- compilers. The only non-portable code is a small section that declares unsigned
- integers of different sizes: three typedefs. They can be changed by the users of
- the library if they don't match their platform. The default setting should work
- for Windows (both 32 and 64 bit), and most 32 bit and 64 bit Unix derivatives.
- </li>
- <li>
- Lightweight: follow the "pay only for what you use" guideline.
- </li>
- <li>
- Unintrusive: avoid forcing any particular design or even programming style on the
- user. This is a library, not a framework.
- </li>
- </ol>
- <h4>
- Alternatives
- </h4>
- <p>
- In case you want to look into other means of working with UTF-8 strings from C++,
- here is the list of solutions I am aware of:
- </p>
- <ol>
- <li>
- <a href="http://icu.sourceforge.net/">ICU Library</a>. It is very powerful,
- complete, feature-rich, mature, and widely used. Also big, intrusive,
- non-generic, and doesn't play well with the Standard Library. I definitelly
- recommend looking at ICU even if you don't plan to use it.
- </li>
- <li>
- C++11 language and library features. Still far from complete, and not widely
- supported by compiler vendors.
- </li>
- <li>
- <a href=
- "http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch03s04.html">Glib::ustring</a>.
- A class specifically made to work with UTF-8 strings, and also feel like
- <code>std::string</code>. If you prefer to have yet another string class in your
- code, it may be worth a look. Be aware of the licensing issues, though.
- </li>
- <li>
- Platform dependent solutions: Windows and POSIX have functions to convert strings
- from one encoding to another. That is only a subset of what my library offers,
- but if that is all you need it may be good enough.
- </li>
- </ol>
- <h2 id="links">
- Links
- </h2>
- <ol>
- <li>
- <a href="http://www.unicode.org/">The Unicode Consortium</a>.
- </li>
- <li>
- <a href="http://icu.sourceforge.net/">ICU Library</a>.
- </li>
- <li>
- <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8 at Wikipedia</a>
- </li>
- <li>
- <a href="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ for
- Unix/Linux</a>
- </li>
- </ol>
- </body>
-</html>
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8.h b/src/3rdparty/assimp/contrib/utf8cpp/source/utf8.h
deleted file mode 100644
index 82b13f59f..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2006 Nemanja Trifunovic
-
-/*
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-
-#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
-#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
-
-#include "utf8/checked.h"
-#include "utf8/unchecked.h"
-
-#endif // header guard
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/checked.h b/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/checked.h
deleted file mode 100644
index 133115513..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/checked.h
+++ /dev/null
@@ -1,327 +0,0 @@
-// Copyright 2006 Nemanja Trifunovic
-
-/*
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-
-#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-
-#include "core.h"
-#include <stdexcept>
-
-namespace utf8
-{
- // Base for the exceptions that may be thrown from the library
- class exception : public ::std::exception {
- };
-
- // Exceptions that may be thrown from the library functions.
- class invalid_code_point : public exception {
- uint32_t cp;
- public:
- invalid_code_point(uint32_t cp) : cp(cp) {}
- virtual const char* what() const throw() { return "Invalid code point"; }
- uint32_t code_point() const {return cp;}
- };
-
- class invalid_utf8 : public exception {
- uint8_t u8;
- public:
- invalid_utf8 (uint8_t u) : u8(u) {}
- virtual const char* what() const throw() { return "Invalid UTF-8"; }
- uint8_t utf8_octet() const {return u8;}
- };
-
- class invalid_utf16 : public exception {
- uint16_t u16;
- public:
- invalid_utf16 (uint16_t u) : u16(u) {}
- virtual const char* what() const throw() { return "Invalid UTF-16"; }
- uint16_t utf16_word() const {return u16;}
- };
-
- class not_enough_room : public exception {
- public:
- virtual const char* what() const throw() { return "Not enough space"; }
- };
-
- /// The library API - functions intended to be called by the users
-
- template <typename octet_iterator>
- octet_iterator append(uint32_t cp, octet_iterator result)
- {
- if (!utf8::internal::is_code_point_valid(cp))
- throw invalid_code_point(cp);
-
- if (cp < 0x80) // one octet
- *(result++) = static_cast<uint8_t>(cp);
- else if (cp < 0x800) { // two octets
- *(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else if (cp < 0x10000) { // three octets
- *(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else { // four octets
- *(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
- *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- return result;
- }
-
- template <typename octet_iterator, typename output_iterator>
- output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
- {
- while (start != end) {
- octet_iterator sequence_start = start;
- internal::utf_error err_code = utf8::internal::validate_next(start, end);
- switch (err_code) {
- case internal::UTF8_OK :
- for (octet_iterator it = sequence_start; it != start; ++it)
- *out++ = *it;
- break;
- case internal::NOT_ENOUGH_ROOM:
- throw not_enough_room();
- case internal::INVALID_LEAD:
- out = utf8::append (replacement, out);
- ++start;
- break;
- case internal::INCOMPLETE_SEQUENCE:
- case internal::OVERLONG_SEQUENCE:
- case internal::INVALID_CODE_POINT:
- out = utf8::append (replacement, out);
- ++start;
- // just one replacement mark for the sequence
- while (start != end && utf8::internal::is_trail(*start))
- ++start;
- break;
- }
- }
- return out;
- }
-
- template <typename octet_iterator, typename output_iterator>
- inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
- {
- static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
- return utf8::replace_invalid(start, end, out, replacement_marker);
- }
-
- template <typename octet_iterator>
- uint32_t next(octet_iterator& it, octet_iterator end)
- {
- uint32_t cp = 0;
- internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);
- switch (err_code) {
- case internal::UTF8_OK :
- break;
- case internal::NOT_ENOUGH_ROOM :
- throw not_enough_room();
- case internal::INVALID_LEAD :
- case internal::INCOMPLETE_SEQUENCE :
- case internal::OVERLONG_SEQUENCE :
- throw invalid_utf8(*it);
- case internal::INVALID_CODE_POINT :
- throw invalid_code_point(cp);
- }
- return cp;
- }
-
- template <typename octet_iterator>
- uint32_t peek_next(octet_iterator it, octet_iterator end)
- {
- return utf8::next(it, end);
- }
-
- template <typename octet_iterator>
- uint32_t prior(octet_iterator& it, octet_iterator start)
- {
- // can't do much if it == start
- if (it == start)
- throw not_enough_room();
-
- octet_iterator end = it;
- // Go back until we hit either a lead octet or start
- while (utf8::internal::is_trail(*(--it)))
- if (it == start)
- throw invalid_utf8(*it); // error - no lead byte in the sequence
- return utf8::peek_next(it, end);
- }
-
- /// Deprecated in versions that include "prior"
- template <typename octet_iterator>
- uint32_t previous(octet_iterator& it, octet_iterator pass_start)
- {
- octet_iterator end = it;
- while (utf8::internal::is_trail(*(--it)))
- if (it == pass_start)
- throw invalid_utf8(*it); // error - no lead byte in the sequence
- octet_iterator temp = it;
- return utf8::next(temp, end);
- }
-
- template <typename octet_iterator, typename distance_type>
- void advance (octet_iterator& it, distance_type n, octet_iterator end)
- {
- for (distance_type i = 0; i < n; ++i)
- utf8::next(it, end);
- }
-
- template <typename octet_iterator>
- typename std::iterator_traits<octet_iterator>::difference_type
- distance (octet_iterator first, octet_iterator last)
- {
- typename std::iterator_traits<octet_iterator>::difference_type dist;
- for (dist = 0; first < last; ++dist)
- utf8::next(first, last);
- return dist;
- }
-
- template <typename u16bit_iterator, typename octet_iterator>
- octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
- {
- while (start != end) {
- uint32_t cp = utf8::internal::mask16(*start++);
- // Take care of surrogate pairs first
- if (utf8::internal::is_lead_surrogate(cp)) {
- if (start != end) {
- uint32_t trail_surrogate = utf8::internal::mask16(*start++);
- if (utf8::internal::is_trail_surrogate(trail_surrogate))
- cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
- else
- throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
- }
- else
- throw invalid_utf16(static_cast<uint16_t>(cp));
-
- }
- // Lone trail surrogate
- else if (utf8::internal::is_trail_surrogate(cp))
- throw invalid_utf16(static_cast<uint16_t>(cp));
-
- result = utf8::append(cp, result);
- }
- return result;
- }
-
- template <typename u16bit_iterator, typename octet_iterator>
- u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
- {
- while (start != end) {
- uint32_t cp = utf8::next(start, end);
- if (cp > 0xffff) { //make a surrogate pair
- *result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
- *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
- }
- else
- *result++ = static_cast<uint16_t>(cp);
- }
- return result;
- }
-
- template <typename octet_iterator, typename u32bit_iterator>
- octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
- {
- while (start != end)
- result = utf8::append(*(start++), result);
-
- return result;
- }
-
- template <typename octet_iterator, typename u32bit_iterator>
- u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
- {
- while (start != end)
- (*result++) = utf8::next(start, end);
-
- return result;
- }
-
- // The iterator class
- template <typename octet_iterator>
- class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
- octet_iterator it;
- octet_iterator range_start;
- octet_iterator range_end;
- public:
- iterator () {}
- explicit iterator (const octet_iterator& octet_it,
- const octet_iterator& range_start,
- const octet_iterator& range_end) :
- it(octet_it), range_start(range_start), range_end(range_end)
- {
- if (it < range_start || it > range_end)
- throw std::out_of_range("Invalid utf-8 iterator position");
- }
- // the default "big three" are OK
- octet_iterator base () const { return it; }
- uint32_t operator * () const
- {
- octet_iterator temp = it;
- return utf8::next(temp, range_end);
- }
- bool operator == (const iterator& rhs) const
- {
- if (range_start != rhs.range_start || range_end != rhs.range_end)
- throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
- return (it == rhs.it);
- }
- bool operator != (const iterator& rhs) const
- {
- return !(operator == (rhs));
- }
- iterator& operator ++ ()
- {
- utf8::next(it, range_end);
- return *this;
- }
- iterator operator ++ (int)
- {
- iterator temp = *this;
- utf8::next(it, range_end);
- return temp;
- }
- iterator& operator -- ()
- {
- utf8::prior(it, range_start);
- return *this;
- }
- iterator operator -- (int)
- {
- iterator temp = *this;
- utf8::prior(it, range_start);
- return temp;
- }
- }; // class iterator
-
-} // namespace utf8
-
-#endif //header guard
-
-
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/core.h b/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/core.h
deleted file mode 100644
index 693d388c0..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/core.h
+++ /dev/null
@@ -1,329 +0,0 @@
-// Copyright 2006 Nemanja Trifunovic
-
-/*
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-
-#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-
-#include <iterator>
-
-namespace utf8
-{
- // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers
- // You may need to change them to match your system.
- // These typedefs have the same names as ones from cstdint, or boost/cstdint
- typedef unsigned char uint8_t;
- typedef unsigned short uint16_t;
- typedef unsigned int uint32_t;
-
-// Helper code - not intended to be directly called by the library users. May be changed at any time
-namespace internal
-{
- // Unicode constants
- // Leading (high) surrogates: 0xd800 - 0xdbff
- // Trailing (low) surrogates: 0xdc00 - 0xdfff
- const uint16_t LEAD_SURROGATE_MIN = 0xd800u;
- const uint16_t LEAD_SURROGATE_MAX = 0xdbffu;
- const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u;
- const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu;
- const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10);
- const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN;
-
- // Maximum valid value for a Unicode code point
- const uint32_t CODE_POINT_MAX = 0x0010ffffu;
-
- template<typename octet_type>
- inline uint8_t mask8(octet_type oc)
- {
- return static_cast<uint8_t>(0xff & oc);
- }
- template<typename u16_type>
- inline uint16_t mask16(u16_type oc)
- {
- return static_cast<uint16_t>(0xffff & oc);
- }
- template<typename octet_type>
- inline bool is_trail(octet_type oc)
- {
- return ((utf8::internal::mask8(oc) >> 6) == 0x2);
- }
-
- template <typename u16>
- inline bool is_lead_surrogate(u16 cp)
- {
- return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX);
- }
-
- template <typename u16>
- inline bool is_trail_surrogate(u16 cp)
- {
- return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
- }
-
- template <typename u16>
- inline bool is_surrogate(u16 cp)
- {
- return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
- }
-
- template <typename u32>
- inline bool is_code_point_valid(u32 cp)
- {
- return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));
- }
-
- template <typename octet_iterator>
- inline typename std::iterator_traits<octet_iterator>::difference_type
- sequence_length(octet_iterator lead_it)
- {
- uint8_t lead = utf8::internal::mask8(*lead_it);
- if (lead < 0x80)
- return 1;
- else if ((lead >> 5) == 0x6)
- return 2;
- else if ((lead >> 4) == 0xe)
- return 3;
- else if ((lead >> 3) == 0x1e)
- return 4;
- else
- return 0;
- }
-
- template <typename octet_difference_type>
- inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length)
- {
- if (cp < 0x80) {
- if (length != 1)
- return true;
- }
- else if (cp < 0x800) {
- if (length != 2)
- return true;
- }
- else if (cp < 0x10000) {
- if (length != 3)
- return true;
- }
-
- return false;
- }
-
- enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
-
- /// Helper for get_sequence_x
- template <typename octet_iterator>
- utf_error increase_safely(octet_iterator& it, octet_iterator end)
- {
- if (++it == end)
- return NOT_ENOUGH_ROOM;
-
- if (!utf8::internal::is_trail(*it))
- return INCOMPLETE_SEQUENCE;
-
- return UTF8_OK;
- }
-
- #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}
-
- /// get_sequence_x functions decode utf-8 sequences of the length x
- template <typename octet_iterator>
- utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point)
- {
- if (it == end)
- return NOT_ENOUGH_ROOM;
-
- code_point = utf8::internal::mask8(*it);
-
- return UTF8_OK;
- }
-
- template <typename octet_iterator>
- utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point)
- {
- if (it == end)
- return NOT_ENOUGH_ROOM;
-
- code_point = utf8::internal::mask8(*it);
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
-
- return UTF8_OK;
- }
-
- template <typename octet_iterator>
- utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point)
- {
- if (it == end)
- return NOT_ENOUGH_ROOM;
-
- code_point = utf8::internal::mask8(*it);
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point += (*it) & 0x3f;
-
- return UTF8_OK;
- }
-
- template <typename octet_iterator>
- utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point)
- {
- if (it == end)
- return NOT_ENOUGH_ROOM;
-
- code_point = utf8::internal::mask8(*it);
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
-
- UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
-
- code_point += (*it) & 0x3f;
-
- return UTF8_OK;
- }
-
- #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
-
- template <typename octet_iterator>
- utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
- {
- // Save the original value of it so we can go back in case of failure
- // Of course, it does not make much sense with i.e. stream iterators
- octet_iterator original_it = it;
-
- uint32_t cp = 0;
- // Determine the sequence length based on the lead octet
- typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
- const octet_difference_type length = utf8::internal::sequence_length(it);
-
- // Get trail octets and calculate the code point
- utf_error err = UTF8_OK;
- switch (length) {
- case 0:
- return INVALID_LEAD;
- case 1:
- err = utf8::internal::get_sequence_1(it, end, cp);
- break;
- case 2:
- err = utf8::internal::get_sequence_2(it, end, cp);
- break;
- case 3:
- err = utf8::internal::get_sequence_3(it, end, cp);
- break;
- case 4:
- err = utf8::internal::get_sequence_4(it, end, cp);
- break;
- }
-
- if (err == UTF8_OK) {
- // Decoding succeeded. Now, security checks...
- if (utf8::internal::is_code_point_valid(cp)) {
- if (!utf8::internal::is_overlong_sequence(cp, length)){
- // Passed! Return here.
- code_point = cp;
- ++it;
- return UTF8_OK;
- }
- else
- err = OVERLONG_SEQUENCE;
- }
- else
- err = INVALID_CODE_POINT;
- }
-
- // Failure branch - restore the original value of the iterator
- it = original_it;
- return err;
- }
-
- template <typename octet_iterator>
- inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
- uint32_t ignored;
- return utf8::internal::validate_next(it, end, ignored);
- }
-
-} // namespace internal
-
- /// The library API - functions intended to be called by the users
-
- // Byte order mark
- const uint8_t bom[] = {0xef, 0xbb, 0xbf};
-
- template <typename octet_iterator>
- octet_iterator find_invalid(octet_iterator start, octet_iterator end)
- {
- octet_iterator result = start;
- while (result != end) {
- utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);
- if (err_code != internal::UTF8_OK)
- return result;
- }
- return result;
- }
-
- template <typename octet_iterator>
- inline bool is_valid(octet_iterator start, octet_iterator end)
- {
- return (utf8::find_invalid(start, end) == end);
- }
-
- template <typename octet_iterator>
- inline bool starts_with_bom (octet_iterator it, octet_iterator end)
- {
- return (
- ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&
- ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&
- ((it != end) && (utf8::internal::mask8(*it)) == bom[2])
- );
- }
-
- //Deprecated in release 2.3
- template <typename octet_iterator>
- inline bool is_bom (octet_iterator it)
- {
- return (
- (utf8::internal::mask8(*it++)) == bom[0] &&
- (utf8::internal::mask8(*it++)) == bom[1] &&
- (utf8::internal::mask8(*it)) == bom[2]
- );
- }
-} // namespace utf8
-
-#endif // header guard
-
-
diff --git a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/unchecked.h b/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/unchecked.h
deleted file mode 100644
index cb2427166..000000000
--- a/src/3rdparty/assimp/contrib/utf8cpp/source/utf8/unchecked.h
+++ /dev/null
@@ -1,228 +0,0 @@
-// Copyright 2006 Nemanja Trifunovic
-
-/*
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-*/
-
-
-#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
-
-#include "core.h"
-
-namespace utf8
-{
- namespace unchecked
- {
- template <typename octet_iterator>
- octet_iterator append(uint32_t cp, octet_iterator result)
- {
- if (cp < 0x80) // one octet
- *(result++) = static_cast<uint8_t>(cp);
- else if (cp < 0x800) { // two octets
- *(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else if (cp < 0x10000) { // three octets
- *(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else { // four octets
- *(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
- *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f)| 0x80);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- return result;
- }
-
- template <typename octet_iterator>
- uint32_t next(octet_iterator& it)
- {
- uint32_t cp = utf8::internal::mask8(*it);
- typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
- switch (length) {
- case 1:
- break;
- case 2:
- it++;
- cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
- break;
- case 3:
- ++it;
- cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
- ++it;
- cp += (*it) & 0x3f;
- break;
- case 4:
- ++it;
- cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
- ++it;
- cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
- ++it;
- cp += (*it) & 0x3f;
- break;
- }
- ++it;
- return cp;
- }
-
- template <typename octet_iterator>
- uint32_t peek_next(octet_iterator it)
- {
- return utf8::unchecked::next(it);
- }
-
- template <typename octet_iterator>
- uint32_t prior(octet_iterator& it)
- {
- while (utf8::internal::is_trail(*(--it))) ;
- octet_iterator temp = it;
- return utf8::unchecked::next(temp);
- }
-
- // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous)
- template <typename octet_iterator>
- inline uint32_t previous(octet_iterator& it)
- {
- return utf8::unchecked::prior(it);
- }
-
- template <typename octet_iterator, typename distance_type>
- void advance (octet_iterator& it, distance_type n)
- {
- for (distance_type i = 0; i < n; ++i)
- utf8::unchecked::next(it);
- }
-
- template <typename octet_iterator>
- typename std::iterator_traits<octet_iterator>::difference_type
- distance (octet_iterator first, octet_iterator last)
- {
- typename std::iterator_traits<octet_iterator>::difference_type dist;
- for (dist = 0; first < last; ++dist)
- utf8::unchecked::next(first);
- return dist;
- }
-
- template <typename u16bit_iterator, typename octet_iterator>
- octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
- {
- while (start != end) {
- uint32_t cp = utf8::internal::mask16(*start++);
- // Take care of surrogate pairs first
- if (utf8::internal::is_lead_surrogate(cp)) {
- uint32_t trail_surrogate = utf8::internal::mask16(*start++);
- cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
- }
- result = utf8::unchecked::append(cp, result);
- }
- return result;
- }
-
- template <typename u16bit_iterator, typename octet_iterator>
- u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
- {
- while (start < end) {
- uint32_t cp = utf8::unchecked::next(start);
- if (cp > 0xffff) { //make a surrogate pair
- *result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
- *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
- }
- else
- *result++ = static_cast<uint16_t>(cp);
- }
- return result;
- }
-
- template <typename octet_iterator, typename u32bit_iterator>
- octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
- {
- while (start != end)
- result = utf8::unchecked::append(*(start++), result);
-
- return result;
- }
-
- template <typename octet_iterator, typename u32bit_iterator>
- u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
- {
- while (start < end)
- (*result++) = utf8::unchecked::next(start);
-
- return result;
- }
-
- // The iterator class
- template <typename octet_iterator>
- class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
- octet_iterator it;
- public:
- iterator () {}
- explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
- // the default "big three" are OK
- octet_iterator base () const { return it; }
- uint32_t operator * () const
- {
- octet_iterator temp = it;
- return utf8::unchecked::next(temp);
- }
- bool operator == (const iterator& rhs) const
- {
- return (it == rhs.it);
- }
- bool operator != (const iterator& rhs) const
- {
- return !(operator == (rhs));
- }
- iterator& operator ++ ()
- {
- ::std::advance(it, utf8::internal::sequence_length(it));
- return *this;
- }
- iterator operator ++ (int)
- {
- iterator temp = *this;
- ::std::advance(it, utf8::internal::sequence_length(it));
- return temp;
- }
- iterator& operator -- ()
- {
- utf8::unchecked::prior(it);
- return *this;
- }
- iterator operator -- (int)
- {
- iterator temp = *this;
- utf8::unchecked::prior(it);
- return temp;
- }
- }; // class iterator
-
- } // namespace utf8::unchecked
-} // namespace utf8
-
-
-#endif // header guard
-
diff --git a/src/3rdparty/assimp/contrib/zip/README.md b/src/3rdparty/assimp/contrib/zip/README.md
deleted file mode 100644
index 24de5e61a..000000000
--- a/src/3rdparty/assimp/contrib/zip/README.md
+++ /dev/null
@@ -1,139 +0,0 @@
-### A portable (OSX/Linux/Windows), simple zip library written in C
-This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API.
-
-[![Windows][win-badge]][win-link] [![OS X][osx-linux-badge]][osx-linux-link]
-
-[win-badge]: https://img.shields.io/appveyor/ci/kuba--/zip/master.svg?label=windows "AppVeyor build status"
-[win-link]: https://ci.appveyor.com/project/kuba--/zip "AppVeyor build status"
-[osx-linux-badge]: https://img.shields.io/travis/kuba--/zip/master.svg?label=linux/osx "Travis CI build status"
-[osx-linux-link]: https://travis-ci.org/kuba--/zip "Travis CI build status"
-
-# The Idea
-<img src="zip.png" name="zip" />
-... Some day, I was looking for zip library written in C for my project, but I could not find anything simple enough and lightweight.
-Everything what I tried required 'crazy mental gymnastics' to integrate or had some limitations or was too heavy.
-I hate frameworks, factories and adding new dependencies. If I must to install all those dependencies and link new library, I'm getting almost sick.
-I wanted something powerfull and small enough, so I could add just a few files and compile them into my project.
-And finally I found miniz.
-Miniz is a lossless, high performance data compression library in a single source file. I only needed simple interface to append buffers or files to the current zip-entry. Thanks to this feature I'm able to merge many files/buffers and compress them on-the-fly.
-
-It was the reason, why I decided to write zip module on top of the miniz. It required a little bit hacking and wrapping some functions, but I kept simplicity. So, you can grab these 3 files and compile them into your project. I hope that interface is also extremely simple, so you will not have any problems to understand it.
-
-# Examples
-
-* Create a new zip archive with default compression level.
-```c
- struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
- {
- zip_entry_open(zip, "foo-1.txt");
- {
- char *buf = "Some data here...";
- zip_entry_write(zip, buf, strlen(buf));
- }
- zip_entry_close(zip);
-
- zip_entry_open(zip, "foo-2.txt");
- {
- // merge 3 files into one entry and compress them on-the-fly.
- zip_entry_fwrite(zip, "foo-2.1.txt");
- zip_entry_fwrite(zip, "foo-2.2.txt");
- zip_entry_fwrite(zip, "foo-2.3.txt");
- }
- zip_entry_close(zip);
- }
- zip_close(zip);
-```
-
-* Append to the existing zip archive.
-```c
- struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'a');
- {
- zip_entry_open(zip, "foo-3.txt");
- {
- char *buf = "Append some data here...";
- zip_entry_write(zip, buf, strlen(buf));
- }
- zip_entry_close(zip);
- }
- zip_close(zip);
-```
-
-* Extract a zip archive into a folder.
-```c
- int on_extract_entry(const char *filename, void *arg) {
- static int i = 0;
- int n = *(int *)arg;
- printf("Extracted: %s (%d of %d)\n", filename, ++i, n);
-
- return 0;
- }
-
- int arg = 2;
- zip_extract("foo.zip", "/tmp", on_extract_entry, &arg);
-```
-
-* Extract a zip entry into memory.
-```c
- void *buf = NULL;
- size_t bufsize;
-
- struct zip_t *zip = zip_open("foo.zip", 0, 'r');
- {
- zip_entry_open(zip, "foo-1.txt");
- {
- zip_entry_read(zip, &buf, &bufsize);
- }
- zip_entry_close(zip);
- }
- zip_close(zip);
-
- free(buf);
-```
-
-* Extract a zip entry into memory using callback.
-```c
- struct buffer_t {
- char *data;
- size_t size;
- };
-
- static size_t on_extract(void *arg, unsigned long long offset, const void *data, size_t size) {
- struct buffer_t *buf = (struct buffer_t *)arg;
- buf->data = realloc(buf->data, buf->size + size + 1);
- assert(NULL != buf->data);
-
- memcpy(&(buf->data[buf->size]), data, size);
- buf->size += size;
- buf->data[buf->size] = 0;
-
- return size;
- }
-
- struct buffer_t buf = {0};
- struct zip_t *zip = zip_open("foo.zip", 0, 'r');
- {
- zip_entry_open(zip, "foo-1.txt");
- {
- zip_entry_extract(zip, on_extract, &buf);
- }
- zip_entry_close(zip);
- }
- zip_close(zip);
-
- free(buf.data);
-```
-
-
-* Extract a zip entry into a file.
-```c
- struct zip_t *zip = zip_open("foo.zip", 0, 'r');
- {
- zip_entry_open(zip, "foo-2.txt");
- {
- zip_entry_fread(zip, "foo-2.txt");
- }
- zip_entry_close(zip);
- }
- zip_close(zip);
-```
-
diff --git a/src/3rdparty/assimp/contrib/zip/UNLICENSE b/src/3rdparty/assimp/contrib/zip/UNLICENSE
deleted file mode 100644
index ed7cccdf2..000000000
--- a/src/3rdparty/assimp/contrib/zip/UNLICENSE
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- This is free and unencumbered software released into the public domain.
-
- Anyone is free to copy, modify, publish, use, compile, sell, or
- distribute this software, either in source code form or as a compiled
- binary, for any purpose, commercial or non-commercial, and by any
- means.
-
- In jurisdictions that recognize copyright laws, the author or authors
- of this software dedicate any and all copyright interest in the
- software to the public domain. We make this dedication for the benefit
- of the public at large and to the detriment of our heirs and
- successors. We intend this dedication to be an overt act of
- relinquishment in perpetuity of all present and future rights to this
- software under copyright law.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
- For more information, please refer to <http://unlicense.org/>
-*/
diff --git a/src/3rdparty/assimp/contrib/zip/src/miniz.h b/src/3rdparty/assimp/contrib/zip/src/miniz.h
deleted file mode 100644
index 2e4e223da..000000000
--- a/src/3rdparty/assimp/contrib/zip/src/miniz.h
+++ /dev/null
@@ -1,4928 +0,0 @@
-/*
- miniz.c v1.15 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
- See "unlicense" statement at the end of this file.
- Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
- Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
-
- Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
- MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
-
- * Change History
- 10/13/13 v1.15 r4 - Interim bugfix release while I work on the next major release with Zip64 support (almost there!):
- - Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug
- would only have occured in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place()
- (which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag).
- - Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size
- - Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries.
- Hopefully this fix won't cause any issues on weird zip archives, because it assumes the low 16-bits of zip external attributes are DOS attributes (which I believe they always are in practice).
- - Fixing mz_zip_reader_is_file_a_directory() so it doesn't check the internal attributes, just the filename and external attributes
- - mz_zip_reader_init_file() - missing MZ_FCLOSE() call if the seek failed
- - Added cmake support for Linux builds which builds all the examples, tested with clang v3.3 and gcc v4.6.
- - Clang fix for tdefl_write_image_to_png_file_in_memory() from toffaletti
- - Merged MZ_FORCEINLINE fix from hdeanclark
- - Fix <time.h> include before config #ifdef, thanks emil.brink
- - Added tdefl_write_image_to_png_file_in_memory_ex(): supports Y flipping (super useful for OpenGL apps), and explicit control over the compression level (so you can
- set it to 1 for real-time compression).
- - Merged in some compiler fixes from paulharris's github repro.
- - Retested this build under Windows (VS 2010, including static analysis), tcc 0.9.26, gcc v4.6 and clang v3.3.
- - Added example6.c, which dumps an image of the mandelbrot set to a PNG file.
- - Modified example2 to help test the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY flag more.
- - In r3: Bugfix to mz_zip_writer_add_file() found during merge: Fix possible src file fclose() leak if alignment bytes+local header file write faiiled
-  - In r4: Minor bugfix to mz_zip_writer_add_from_zip_reader(): Was pushing the wrong central dir header offset, appears harmless in this release, but it became a problem in the zip64 branch
- 5/20/12 v1.14 - MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include <time.h> (thanks fermtect).
- 5/19/12 v1.13 - From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit.
- - Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files.
- - Eliminated a bunch of warnings when compiling with GCC 32-bit/64.
- - Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly
- "Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning).
- - Created 32-bit and 64-bit Codeblocks projects/workspace. Built and tested Linux executables. The codeblocks workspace is compatible with Linux+Win32/x64.
- - Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test.
- - Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives.
- - Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.)
- - Fix ftell() usage in examples so they exit with an error on files which are too large (a limitation of the examples, not miniz itself).
- 4/12/12 v1.12 - More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's.
- level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson <bruced@valvesoftware.com> for the feedback/bug report.
- 5/28/11 v1.11 - Added statement from unlicense.org
- 5/27/11 v1.10 - Substantial compressor optimizations:
- - Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a
- - Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86).
- - Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types.
- - Refactored the compression code for better readability and maintainability.
- - Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large
- drop in throughput on some files).
- 5/15/11 v1.09 - Initial stable release.
-
- * Low-level Deflate/Inflate implementation notes:
-
- Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or
- greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses
- approximately as well as zlib.
-
- Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function
- coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory
- block large enough to hold the entire file.
-
- The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation.
-
- * zlib-style API notes:
-
- miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in
- zlib replacement in many apps:
- The z_stream struct, optional memory allocation callbacks
- deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
- inflateInit/inflateInit2/inflate/inflateEnd
- compress, compress2, compressBound, uncompress
- CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
- Supports raw deflate streams or standard zlib streams with adler-32 checking.
-
- Limitations:
- The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries.
- I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but
- there are no guarantees that miniz.c pulls this off perfectly.
-
- * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by
- Alex Evans. Supports 1-4 bytes/pixel images.
-
- * ZIP archive API notes:
-
- The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to
- get the job done with minimal fuss. There are simple API's to retrieve file information, read files from
- existing archives, create new archives, append new files to existing archives, or clone archive data from
- one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h),
- or you can specify custom file read/write callbacks.
-
- - Archive reading: Just call this function to read a single file from a disk archive:
-
- void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name,
- size_t *pSize, mz_uint zip_flags);
-
- For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central
- directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files.
-
- - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file:
-
- int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
-
- The locate operation can optionally check file comments too, which (as one example) can be used to identify
- multiple versions of the same file in an archive. This function uses a simple linear search through the central
- directory, so it's not very fast.
-
- Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and
- retrieve detailed info on each file by calling mz_zip_reader_file_stat().
-
- - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data
- to disk and builds an exact image of the central directory in memory. The central directory image is written
- all at once at the end of the archive file when the archive is finalized.
-
- The archive writer can optionally align each file's local header and file data to any power of 2 alignment,
- which can be useful when the archive will be read from optical media. Also, the writer supports placing
- arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still
- readable by any ZIP tool.
-
- - Archive appending: The simple way to add a single file to an archive is to call this function:
-
- mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name,
- const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
-
- The archive will be created if it doesn't already exist, otherwise it'll be appended to.
- Note the appending is done in-place and is not an atomic operation, so if something goes wrong
- during the operation it's possible the archive could be left without a central directory (although the local
- file headers and file data will be fine, so the archive will be recoverable).
-
- For more complex archive modification scenarios:
- 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to
- preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the
- compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and
- you're done. This is safe but requires a bunch of temporary disk space or heap memory.
-
- 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(),
- append new files as needed, then finalize the archive which will write an updated central directory to the
- original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a
- possibility that the archive's central directory could be lost with this method if anything goes wrong, though.
-
- - ZIP archive support limitations:
- No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
- Requires streams capable of seeking.
-
- * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the
- below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it.
-
- * Important: For best perf. be sure to customize the below macros for your target platform:
- #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
- #define MINIZ_LITTLE_ENDIAN 1
- #define MINIZ_HAS_64BIT_REGISTERS 1
-
- * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz
- uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files
- (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes).
-*/
-
-#ifndef MINIZ_HEADER_INCLUDED
-#define MINIZ_HEADER_INCLUDED
-
-#include <stdlib.h>
-
-// Defines to completely disable specific portions of miniz.c:
-// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
-
-// Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
-//#define MINIZ_NO_STDIO
-
-// If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
-// get/set file times, and the C run-time funcs that get/set times won't be called.
-// The current downside is the times written to your archives will be from 1979.
-//#define MINIZ_NO_TIME
-
-// Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
-//#define MINIZ_NO_ARCHIVE_APIS
-
-// Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
-//#define MINIZ_NO_ARCHIVE_WRITING_APIS
-
-// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
-//#define MINIZ_NO_ZLIB_APIS
-
-// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
-//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
-
-// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
-// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
-// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
-// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
-//#define MINIZ_NO_MALLOC
-
-#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
- // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
- #define MINIZ_NO_TIME
-#endif
-
-#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
- #include <time.h>
-#endif
-
-#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
-// MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
-#define MINIZ_X86_OR_X64_CPU 1
-#endif
-
-#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
-// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
-#define MINIZ_LITTLE_ENDIAN 1
-#endif
-
-#if MINIZ_X86_OR_X64_CPU
-// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
-#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
-#endif
-
-#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
-// Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
-#define MINIZ_HAS_64BIT_REGISTERS 1
-#endif
-
-#ifdef __APPLE__
-#define ftello64 ftello
-#define fseeko64 fseeko
-#define fopen64 fopen
-#define freopen64 freopen
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// ------------------- zlib-style API Definitions.
-
-// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
-typedef unsigned long mz_ulong;
-
-// mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
-void mz_free(void *p);
-
-#define MZ_ADLER32_INIT (1)
-// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
-mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
-
-#define MZ_CRC32_INIT (0)
-// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
-mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
-
-// Compression strategies.
-enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
-
-// Method
-#define MZ_DEFLATED 8
-
-#ifndef MINIZ_NO_ZLIB_APIS
-
-// Heap allocation callbacks.
-// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
-typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
-typedef void (*mz_free_func)(void *opaque, void *address);
-typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
-
-#define MZ_VERSION "9.1.15"
-#define MZ_VERNUM 0x91F0
-#define MZ_VER_MAJOR 9
-#define MZ_VER_MINOR 1
-#define MZ_VER_REVISION 15
-#define MZ_VER_SUBREVISION 0
-
-// Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
-enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
-
-// Return status codes. MZ_PARAM_ERROR is non-standard.
-enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
-
-// Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
-enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
-
-// Window bits
-#define MZ_DEFAULT_WINDOW_BITS 15
-
-struct mz_internal_state;
-
-// Compression/decompression stream struct.
-typedef struct mz_stream_s
-{
- const unsigned char *next_in; // pointer to next byte to read
- unsigned int avail_in; // number of bytes available at next_in
- mz_ulong total_in; // total number of bytes consumed so far
-
- unsigned char *next_out; // pointer to next byte to write
- unsigned int avail_out; // number of bytes that can be written to next_out
- mz_ulong total_out; // total number of bytes produced so far
-
- char *msg; // error msg (unused)
- struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
-
- mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
- mz_free_func zfree; // optional heap free function (defaults to free)
- void *opaque; // heap alloc function user pointer
-
- int data_type; // data_type (unused)
- mz_ulong adler; // adler32 of the source or uncompressed data
- mz_ulong reserved; // not used
-} mz_stream;
-
-typedef mz_stream *mz_streamp;
-
-// Returns the version string of miniz.c.
-const char *mz_version(void);
-
-// mz_deflateInit() initializes a compressor with default options:
-// Parameters:
-// pStream must point to an initialized mz_stream struct.
-// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
-// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
-// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
-// Return values:
-// MZ_OK on success.
-// MZ_STREAM_ERROR if the stream is bogus.
-// MZ_PARAM_ERROR if the input parameters are bogus.
-// MZ_MEM_ERROR on out of memory.
-int mz_deflateInit(mz_streamp pStream, int level);
-
-// mz_deflateInit2() is like mz_deflate(), except with more control:
-// Additional parameters:
-// method must be MZ_DEFLATED
-// window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
-// mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
-int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
-
-// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
-int mz_deflateReset(mz_streamp pStream);
-
-// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
-// Parameters:
-// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
-// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
-// Return values:
-// MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
-// MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
-// MZ_STREAM_ERROR if the stream is bogus.
-// MZ_PARAM_ERROR if one of the parameters is invalid.
-// MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
-int mz_deflate(mz_streamp pStream, int flush);
-
-// mz_deflateEnd() deinitializes a compressor:
-// Return values:
-// MZ_OK on success.
-// MZ_STREAM_ERROR if the stream is bogus.
-int mz_deflateEnd(mz_streamp pStream);
-
-// mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
-mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
-
-// Single-call compression functions mz_compress() and mz_compress2():
-// Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
-int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
-int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
-
-// mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
-mz_ulong mz_compressBound(mz_ulong source_len);
-
-// Initializes a decompressor.
-int mz_inflateInit(mz_streamp pStream);
-
-// mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
-// window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
-int mz_inflateInit2(mz_streamp pStream, int window_bits);
-
-// Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
-// Parameters:
-// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
-// flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
-// On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
-// MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
-// Return values:
-// MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
-// MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
-// MZ_STREAM_ERROR if the stream is bogus.
-// MZ_DATA_ERROR if the deflate stream is invalid.
-// MZ_PARAM_ERROR if one of the parameters is invalid.
-// MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again
-// with more input data, or with more room in the output buffer (except when using single call decompression, described above).
-int mz_inflate(mz_streamp pStream, int flush);
-
-// Deinitializes a decompressor.
-int mz_inflateEnd(mz_streamp pStream);
-
-// Single-call decompression.
-// Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
-int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
-
-// Returns a string description of the specified error code, or NULL if the error code is invalid.
-const char *mz_error(int err);
-
-// Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports.
-// Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
-#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
- typedef unsigned char Byte;
- typedef unsigned int uInt;
- typedef mz_ulong uLong;
- typedef Byte Bytef;
- typedef uInt uIntf;
- typedef char charf;
- typedef int intf;
- typedef void *voidpf;
- typedef uLong uLongf;
- typedef void *voidp;
- typedef void *const voidpc;
- #define Z_NULL 0
- #define Z_NO_FLUSH MZ_NO_FLUSH
- #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
- #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
- #define Z_FULL_FLUSH MZ_FULL_FLUSH
- #define Z_FINISH MZ_FINISH
- #define Z_BLOCK MZ_BLOCK
- #define Z_OK MZ_OK
- #define Z_STREAM_END MZ_STREAM_END
- #define Z_NEED_DICT MZ_NEED_DICT
- #define Z_ERRNO MZ_ERRNO
- #define Z_STREAM_ERROR MZ_STREAM_ERROR
- #define Z_DATA_ERROR MZ_DATA_ERROR
- #define Z_MEM_ERROR MZ_MEM_ERROR
- #define Z_BUF_ERROR MZ_BUF_ERROR
- #define Z_VERSION_ERROR MZ_VERSION_ERROR
- #define Z_PARAM_ERROR MZ_PARAM_ERROR
- #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
- #define Z_BEST_SPEED MZ_BEST_SPEED
- #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
- #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
- #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
- #define Z_FILTERED MZ_FILTERED
- #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
- #define Z_RLE MZ_RLE
- #define Z_FIXED MZ_FIXED
- #define Z_DEFLATED MZ_DEFLATED
- #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
- #define alloc_func mz_alloc_func
- #define free_func mz_free_func
- #define internal_state mz_internal_state
- #define z_stream mz_stream
- #define deflateInit mz_deflateInit
- #define deflateInit2 mz_deflateInit2
- #define deflateReset mz_deflateReset
- #define deflate mz_deflate
- #define deflateEnd mz_deflateEnd
- #define deflateBound mz_deflateBound
- #define compress mz_compress
- #define compress2 mz_compress2
- #define compressBound mz_compressBound
- #define inflateInit mz_inflateInit
- #define inflateInit2 mz_inflateInit2
- #define inflate mz_inflate
- #define inflateEnd mz_inflateEnd
- #define uncompress mz_uncompress
- #define crc32 mz_crc32
- #define adler32 mz_adler32
- #define MAX_WBITS 15
- #define MAX_MEM_LEVEL 9
- #define zError mz_error
- #define ZLIB_VERSION MZ_VERSION
- #define ZLIB_VERNUM MZ_VERNUM
- #define ZLIB_VER_MAJOR MZ_VER_MAJOR
- #define ZLIB_VER_MINOR MZ_VER_MINOR
- #define ZLIB_VER_REVISION MZ_VER_REVISION
- #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
- #define zlibVersion mz_version
- #define zlib_version mz_version()
-#endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
-
-#endif // MINIZ_NO_ZLIB_APIS
-
-// ------------------- Types and macros
-
-typedef unsigned char mz_uint8;
-typedef signed short mz_int16;
-typedef unsigned short mz_uint16;
-typedef unsigned int mz_uint32;
-typedef unsigned int mz_uint;
-typedef long long mz_int64;
-typedef unsigned long long mz_uint64;
-typedef int mz_bool;
-
-#define MZ_FALSE (0)
-#define MZ_TRUE (1)
-
-// An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
-#ifdef _MSC_VER
- #define MZ_MACRO_END while (0, 0)
-#else
- #define MZ_MACRO_END while (0)
-#endif
-
-// ------------------- ZIP archive reading/writing
-
-#ifndef MINIZ_NO_ARCHIVE_APIS
-
-enum
-{
- MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
- MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
- MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
-};
-
-typedef struct
-{
- mz_uint32 m_file_index;
- mz_uint32 m_central_dir_ofs;
- mz_uint16 m_version_made_by;
- mz_uint16 m_version_needed;
- mz_uint16 m_bit_flag;
- mz_uint16 m_method;
-#ifndef MINIZ_NO_TIME
- time_t m_time;
-#endif
- mz_uint32 m_crc32;
- mz_uint64 m_comp_size;
- mz_uint64 m_uncomp_size;
- mz_uint16 m_internal_attr;
- mz_uint32 m_external_attr;
- mz_uint64 m_local_header_ofs;
- mz_uint32 m_comment_size;
- char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
- char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
-} mz_zip_archive_file_stat;
-
-typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
-typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
-
-struct mz_zip_internal_state_tag;
-typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
-
-typedef enum
-{
- MZ_ZIP_MODE_INVALID = 0,
- MZ_ZIP_MODE_READING = 1,
- MZ_ZIP_MODE_WRITING = 2,
- MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
-} mz_zip_mode;
-
-typedef struct mz_zip_archive_tag
-{
- mz_uint64 m_archive_size;
- mz_uint64 m_central_directory_file_ofs;
- mz_uint m_total_files;
- mz_zip_mode m_zip_mode;
-
- mz_uint m_file_offset_alignment;
-
- mz_alloc_func m_pAlloc;
- mz_free_func m_pFree;
- mz_realloc_func m_pRealloc;
- void *m_pAlloc_opaque;
-
- mz_file_read_func m_pRead;
- mz_file_write_func m_pWrite;
- void *m_pIO_opaque;
-
- mz_zip_internal_state *m_pState;
-
-} mz_zip_archive;
-
-typedef enum
-{
- MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
- MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
- MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
- MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
-} mz_zip_flags;
-
-// ZIP archive reading
-
-// Inits a ZIP archive reader.
-// These functions read and validate the archive's central directory.
-mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
-mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
-
-#ifndef MINIZ_NO_STDIO
-mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
-#endif
-
-// Returns the total number of files in the archive.
-mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
-
-// Returns detailed information about an archive file entry.
-mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
-
-// Determines if an archive file entry is a directory entry.
-mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
-mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
-
-// Retrieves the filename of an archive file entry.
-// Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
-mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
-
-// Attempts to locates a file in the archive's central directory.
-// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
-// Returns -1 if the file cannot be found.
-int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
-
-// Extracts a archive file to a memory buffer using no memory allocation.
-mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
-mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
-
-// Extracts a archive file to a memory buffer.
-mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
-mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
-
-// Extracts a archive file to a dynamically allocated heap buffer.
-void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
-void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
-
-// Extracts a archive file using a callback function to output the file's data.
-mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
-mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
-
-#ifndef MINIZ_NO_STDIO
-// Extracts a archive file to a disk file and sets its last accessed and modified times.
-// This function only extracts files, not archive directory records.
-mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
-mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
-#endif
-
-// Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
-mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
-
-// ZIP archive writing
-
-#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
-
-// Inits a ZIP archive writer.
-mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
-mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
-
-#ifndef MINIZ_NO_STDIO
-mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
-#endif
-
-// Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
-// For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called.
-// For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it).
-// Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
-// Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
-// the archive is finalized the file's central directory will be hosed.
-mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
-
-// Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
-// To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
-// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
-mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
-mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
-
-#ifndef MINIZ_NO_STDIO
-// Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
-// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
-mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
-#endif
-
-// Adds a file to an archive by fully cloning the data from another archive.
-// This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
-mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
-
-// Finalizes the archive by writing the central directory records followed by the end of central directory record.
-// After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
-// An archive must be manually finalized by calling this function for it to be valid.
-mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
-mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
-
-// Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
-// Note for the archive to be valid, it must have been finalized before ending.
-mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
-
-// Misc. high-level helper functions:
-
-// mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
-// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
-mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
-
-// Reads a single file from an archive into a heap block.
-// Returns NULL on failure.
-void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
-
-#endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
-
-#endif // #ifndef MINIZ_NO_ARCHIVE_APIS
-
-// ------------------- Low-level Decompression API Definitions
-
-// Decompression flags used by tinfl_decompress().
-// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
-// TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input.
-// TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB).
-// TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
-enum
-{
- TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
- TINFL_FLAG_HAS_MORE_INPUT = 2,
- TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
- TINFL_FLAG_COMPUTE_ADLER32 = 8
-};
-
-// High level decompression functions:
-// tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
-// On entry:
-// pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
-// On return:
-// Function returns a pointer to the decompressed data, or NULL on failure.
-// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
-// The caller must call mz_free() on the returned block when it's no longer needed.
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
-
-// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
-// Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
-#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
-size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
-
-// tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer.
-// Returns 1 on success or 0 on failure.
-typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
-int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
-
-struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
-
-// Max size of LZ dictionary.
-#define TINFL_LZ_DICT_SIZE 32768
-
-// Return status.
-typedef enum
-{
- TINFL_STATUS_BAD_PARAM = -3,
- TINFL_STATUS_ADLER32_MISMATCH = -2,
- TINFL_STATUS_FAILED = -1,
- TINFL_STATUS_DONE = 0,
- TINFL_STATUS_NEEDS_MORE_INPUT = 1,
- TINFL_STATUS_HAS_MORE_OUTPUT = 2
-} tinfl_status;
-
-// Initializes the decompressor to its initial state.
-#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
-#define tinfl_get_adler32(r) (r)->m_check_adler32
-
-// Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability.
-// This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output.
-tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
-
-// Internal/private bits follow.
-enum
-{
- TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
- TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
-};
-
-typedef struct
-{
- mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
- mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
-} tinfl_huff_table;
-
-#if MINIZ_HAS_64BIT_REGISTERS
- #define TINFL_USE_64BIT_BITBUF 1
-#endif
-
-#if TINFL_USE_64BIT_BITBUF
- typedef mz_uint64 tinfl_bit_buf_t;
- #define TINFL_BITBUF_SIZE (64)
-#else
- typedef mz_uint32 tinfl_bit_buf_t;
- #define TINFL_BITBUF_SIZE (32)
-#endif
-
-struct tinfl_decompressor_tag
-{
- mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
- tinfl_bit_buf_t m_bit_buf;
- size_t m_dist_from_out_buf_start;
- tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
- mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
-};
-
-// ------------------- Low-level Compression API Definitions
-
-// Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
-#define TDEFL_LESS_MEMORY 0
-
-// tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
-// TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression).
-enum
-{
- TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
-};
-
-// TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data.
-// TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
-// TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
-// TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory).
-// TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
-// TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
-// TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
-// TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
-// The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
-enum
-{
- TDEFL_WRITE_ZLIB_HEADER = 0x01000,
- TDEFL_COMPUTE_ADLER32 = 0x02000,
- TDEFL_GREEDY_PARSING_FLAG = 0x04000,
- TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
- TDEFL_RLE_MATCHES = 0x10000,
- TDEFL_FILTER_MATCHES = 0x20000,
- TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
- TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
-};
-
-// High level compression functions:
-// tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
-// On entry:
-// pSrc_buf, src_buf_len: Pointer and size of source block to compress.
-// flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
-// On return:
-// Function returns a pointer to the compressed data, or NULL on failure.
-// *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
-// The caller must free() the returned block when it's no longer needed.
-void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
-
-// tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
-// Returns 0 on failure.
-size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
-
-// Compresses an image to a compressed PNG file in memory.
-// On entry:
-// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
-// The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
-// level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL
-// If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
-// On return:
-// Function returns a pointer to the compressed data, or NULL on failure.
-// *pLen_out will be set to the size of the PNG image file.
-// The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
-void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
-void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
-
-// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
-typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
-
-// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
-mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
-
-enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
-
-// TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
-#if TDEFL_LESS_MEMORY
-enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
-#else
-enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
-#endif
-
-// The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions.
-typedef enum
-{
- TDEFL_STATUS_BAD_PARAM = -2,
- TDEFL_STATUS_PUT_BUF_FAILED = -1,
- TDEFL_STATUS_OKAY = 0,
- TDEFL_STATUS_DONE = 1,
-} tdefl_status;
-
-// Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
-typedef enum
-{
- TDEFL_NO_FLUSH = 0,
- TDEFL_SYNC_FLUSH = 2,
- TDEFL_FULL_FLUSH = 3,
- TDEFL_FINISH = 4
-} tdefl_flush;
-
-// tdefl's compression state structure.
-typedef struct
-{
- tdefl_put_buf_func_ptr m_pPut_buf_func;
- void *m_pPut_buf_user;
- mz_uint m_flags, m_max_probes[2];
- int m_greedy_parsing;
- mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
- mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
- mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
- mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
- tdefl_status m_prev_return_status;
- const void *m_pIn_buf;
- void *m_pOut_buf;
- size_t *m_pIn_buf_size, *m_pOut_buf_size;
- tdefl_flush m_flush;
- const mz_uint8 *m_pSrc;
- size_t m_src_buf_left, m_out_buf_ofs;
- mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
- mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
- mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
- mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
- mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
- mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
- mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
- mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
-} tdefl_compressor;
-
-// Initializes the compressor.
-// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
-// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression.
-// If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
-// flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
-tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
-
-// Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible.
-tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush);
-
-// tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
-// tdefl_compress_buffer() always consumes the entire input buffer.
-tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
-
-tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
-mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
-
-// Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
-#ifndef MINIZ_NO_ZLIB_APIS
-// Create tdefl_compress() flags given zlib-style compression parameters.
-// level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
-// window_bits may be -15 (raw deflate) or 15 (zlib)
-// strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
-mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
-#endif // #ifndef MINIZ_NO_ZLIB_APIS
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // MINIZ_HEADER_INCLUDED
-
-// ------------------- End of Header: Implementation follows. (If you only want the header, define MINIZ_HEADER_FILE_ONLY.)
-
-#ifndef MINIZ_HEADER_FILE_ONLY
-
-typedef unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 : -1];
-typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 : -1];
-typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1];
-
-#include <string.h>
-#include <assert.h>
-
-#define MZ_ASSERT(x) assert(x)
-
-#ifdef MINIZ_NO_MALLOC
- #define MZ_MALLOC(x) NULL
- #define MZ_FREE(x) (void)x, ((void)0)
- #define MZ_REALLOC(p, x) NULL
-#else
- #define MZ_MALLOC(x) malloc(x)
- #define MZ_FREE(x) free(x)
- #define MZ_REALLOC(p, x) realloc(p, x)
-#endif
-
-#define MZ_MAX(a,b) (((a)>(b))?(a):(b))
-#define MZ_MIN(a,b) (((a)<(b))?(a):(b))
-#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
-
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
- #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
- #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
-#else
- #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
- #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
-#endif
-
-#ifdef _MSC_VER
- #define MZ_FORCEINLINE __forceinline
-#elif defined(__GNUC__)
- #define MZ_FORCEINLINE inline __attribute__((__always_inline__))
-#else
- #define MZ_FORCEINLINE inline
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-// ------------------- zlib-style API's
-
-mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
-{
- mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552;
- if (!ptr) return MZ_ADLER32_INIT;
- while (buf_len) {
- for (i = 0; i + 7 < block_len; i += 8, ptr += 8) {
- s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
- s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
- }
- for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
- s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
- }
- return (s2 << 16) + s1;
-}
-
-// Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed": http://www.geocities.com/malbrain/
-mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
-{
- static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
- 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
- mz_uint32 crcu32 = (mz_uint32)crc;
- if (!ptr) return MZ_CRC32_INIT;
- crcu32 = ~crcu32; while (buf_len--) { mz_uint8 b = *ptr++; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; }
- return ~crcu32;
-}
-
-void mz_free(void *p)
-{
- MZ_FREE(p);
-}
-
-#ifndef MINIZ_NO_ZLIB_APIS
-
-static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque, (void)items, (void)size; return MZ_MALLOC(items * size); }
-static void def_free_func(void *opaque, void *address) { (void)opaque, (void)address; MZ_FREE(address); }
-static void *def_realloc_func(void *opaque, void *address, size_t items, size_t size) { (void)opaque, (void)address, (void)items, (void)size; return MZ_REALLOC(address, items * size); }
-
-const char *mz_version(void)
-{
- return MZ_VERSION;
-}
-
-int mz_deflateInit(mz_streamp pStream, int level)
-{
- return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
-}
-
-int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
-{
- tdefl_compressor *pComp;
- mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy);
-
- if (!pStream) return MZ_STREAM_ERROR;
- if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))) return MZ_PARAM_ERROR;
-
- pStream->data_type = 0;
- pStream->adler = MZ_ADLER32_INIT;
- pStream->msg = NULL;
- pStream->reserved = 0;
- pStream->total_in = 0;
- pStream->total_out = 0;
- if (!pStream->zalloc) pStream->zalloc = def_alloc_func;
- if (!pStream->zfree) pStream->zfree = def_free_func;
-
- pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor));
- if (!pComp)
- return MZ_MEM_ERROR;
-
- pStream->state = (struct mz_internal_state *)pComp;
-
- if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
- {
- mz_deflateEnd(pStream);
- return MZ_PARAM_ERROR;
- }
-
- return MZ_OK;
-}
-
-int mz_deflateReset(mz_streamp pStream)
-{
- if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree)) return MZ_STREAM_ERROR;
- pStream->total_in = pStream->total_out = 0;
- tdefl_init((tdefl_compressor*)pStream->state, NULL, NULL, ((tdefl_compressor*)pStream->state)->m_flags);
- return MZ_OK;
-}
-
-int mz_deflate(mz_streamp pStream, int flush)
-{
- size_t in_bytes, out_bytes;
- mz_ulong orig_total_in, orig_total_out;
- int mz_status = MZ_OK;
-
- if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out)) return MZ_STREAM_ERROR;
- if (!pStream->avail_out) return MZ_BUF_ERROR;
-
- if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH;
-
- if (((tdefl_compressor*)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE)
- return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR;
-
- orig_total_in = pStream->total_in; orig_total_out = pStream->total_out;
- for ( ; ; )
- {
- tdefl_status defl_status;
- in_bytes = pStream->avail_in; out_bytes = pStream->avail_out;
-
- defl_status = tdefl_compress((tdefl_compressor*)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush);
- pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes;
- pStream->total_in += (mz_uint)in_bytes; pStream->adler = tdefl_get_adler32((tdefl_compressor*)pStream->state);
-
- pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes;
- pStream->total_out += (mz_uint)out_bytes;
-
- if (defl_status < 0)
- {
- mz_status = MZ_STREAM_ERROR;
- break;
- }
- else if (defl_status == TDEFL_STATUS_DONE)
- {
- mz_status = MZ_STREAM_END;
- break;
- }
- else if (!pStream->avail_out)
- break;
- else if ((!pStream->avail_in) && (flush != MZ_FINISH))
- {
- if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out))
- break;
- return MZ_BUF_ERROR; // Can't make forward progress without some input.
- }
- }
- return mz_status;
-}
-
-int mz_deflateEnd(mz_streamp pStream)
-{
- if (!pStream) return MZ_STREAM_ERROR;
- if (pStream->state)
- {
- pStream->zfree(pStream->opaque, pStream->state);
- pStream->state = NULL;
- }
- return MZ_OK;
-}
-
-mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
-{
- (void)pStream;
- // This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.)
- return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
-}
-
-int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
-{
- int status;
- mz_stream stream;
- memset(&stream, 0, sizeof(stream));
-
- // In case mz_ulong is 64-bits (argh I hate longs).
- if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
-
- stream.next_in = pSource;
- stream.avail_in = (mz_uint32)source_len;
- stream.next_out = pDest;
- stream.avail_out = (mz_uint32)*pDest_len;
-
- status = mz_deflateInit(&stream, level);
- if (status != MZ_OK) return status;
-
- status = mz_deflate(&stream, MZ_FINISH);
- if (status != MZ_STREAM_END)
- {
- mz_deflateEnd(&stream);
- return (status == MZ_OK) ? MZ_BUF_ERROR : status;
- }
-
- *pDest_len = stream.total_out;
- return mz_deflateEnd(&stream);
-}
-
-int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
-{
- return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION);
-}
-
-mz_ulong mz_compressBound(mz_ulong source_len)
-{
- return mz_deflateBound(NULL, source_len);
-}
-
-typedef struct
-{
- tinfl_decompressor m_decomp;
- mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; int m_window_bits;
- mz_uint8 m_dict[TINFL_LZ_DICT_SIZE];
- tinfl_status m_last_status;
-} inflate_state;
-
-int mz_inflateInit2(mz_streamp pStream, int window_bits)
-{
- inflate_state *pDecomp;
- if (!pStream) return MZ_STREAM_ERROR;
- if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) return MZ_PARAM_ERROR;
-
- pStream->data_type = 0;
- pStream->adler = 0;
- pStream->msg = NULL;
- pStream->total_in = 0;
- pStream->total_out = 0;
- pStream->reserved = 0;
- if (!pStream->zalloc) pStream->zalloc = def_alloc_func;
- if (!pStream->zfree) pStream->zfree = def_free_func;
-
- pDecomp = (inflate_state*)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));
- if (!pDecomp) return MZ_MEM_ERROR;
-
- pStream->state = (struct mz_internal_state *)pDecomp;
-
- tinfl_init(&pDecomp->m_decomp);
- pDecomp->m_dict_ofs = 0;
- pDecomp->m_dict_avail = 0;
- pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
- pDecomp->m_first_call = 1;
- pDecomp->m_has_flushed = 0;
- pDecomp->m_window_bits = window_bits;
-
- return MZ_OK;
-}
-
-int mz_inflateInit(mz_streamp pStream)
-{
- return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
-}
-
-int mz_inflate(mz_streamp pStream, int flush)
-{
- inflate_state* pState;
- mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
- size_t in_bytes, out_bytes, orig_avail_in;
- tinfl_status status;
-
- if ((!pStream) || (!pStream->state)) return MZ_STREAM_ERROR;
- if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH;
- if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
-
- pState = (inflate_state*)pStream->state;
- if (pState->m_window_bits > 0) decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
- orig_avail_in = pStream->avail_in;
-
- first_call = pState->m_first_call; pState->m_first_call = 0;
- if (pState->m_last_status < 0) return MZ_DATA_ERROR;
-
- if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR;
- pState->m_has_flushed |= (flush == MZ_FINISH);
-
- if ((flush == MZ_FINISH) && (first_call))
- {
- // MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file.
- decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
- in_bytes = pStream->avail_in; out_bytes = pStream->avail_out;
- status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
- pState->m_last_status = status;
- pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes;
- pStream->adler = tinfl_get_adler32(&pState->m_decomp);
- pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes;
-
- if (status < 0)
- return MZ_DATA_ERROR;
- else if (status != TINFL_STATUS_DONE)
- {
- pState->m_last_status = TINFL_STATUS_FAILED;
- return MZ_BUF_ERROR;
- }
- return MZ_STREAM_END;
- }
- // flush != MZ_FINISH then we must assume there's more input.
- if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
-
- if (pState->m_dict_avail)
- {
- n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
- memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
- pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
- pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
- return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
- }
-
- for ( ; ; )
- {
- in_bytes = pStream->avail_in;
- out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
-
- status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
- pState->m_last_status = status;
-
- pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes;
- pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp);
-
- pState->m_dict_avail = (mz_uint)out_bytes;
-
- n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
- memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
- pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n;
- pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
-
- if (status < 0)
- return MZ_DATA_ERROR; // Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well).
- else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
- return MZ_BUF_ERROR; // Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH.
- else if (flush == MZ_FINISH)
- {
- // The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH.
- if (status == TINFL_STATUS_DONE)
- return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
- // status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong.
- else if (!pStream->avail_out)
- return MZ_BUF_ERROR;
- }
- else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
- break;
- }
-
- return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
-}
-
-int mz_inflateEnd(mz_streamp pStream)
-{
- if (!pStream)
- return MZ_STREAM_ERROR;
- if (pStream->state)
- {
- pStream->zfree(pStream->opaque, pStream->state);
- pStream->state = NULL;
- }
- return MZ_OK;
-}
-
-int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
-{
- mz_stream stream;
- int status;
- memset(&stream, 0, sizeof(stream));
-
- // In case mz_ulong is 64-bits (argh I hate longs).
- if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
-
- stream.next_in = pSource;
- stream.avail_in = (mz_uint32)source_len;
- stream.next_out = pDest;
- stream.avail_out = (mz_uint32)*pDest_len;
-
- status = mz_inflateInit(&stream);
- if (status != MZ_OK)
- return status;
-
- status = mz_inflate(&stream, MZ_FINISH);
- if (status != MZ_STREAM_END)
- {
- mz_inflateEnd(&stream);
- return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
- }
- *pDest_len = stream.total_out;
-
- return mz_inflateEnd(&stream);
-}
-
-const char *mz_error(int err)
-{
- static struct { int m_err; const char *m_pDesc; } s_error_descs[] =
- {
- { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" },
- { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
- };
- mz_uint i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc;
- return NULL;
-}
-
-#endif //MINIZ_NO_ZLIB_APIS
-
-// ------------------- Low-level Decompression (completely independent from all compression API's)
-
-#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
-#define TINFL_MEMSET(p, c, l) memset(p, c, l)
-
-#define TINFL_CR_BEGIN switch(r->m_state) { case 0:
-#define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
-#define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
-#define TINFL_CR_FINISH }
-
-// TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never
-// reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario.
-#define TINFL_GET_BYTE(state_index, c) do { \
- if (pIn_buf_cur >= pIn_buf_end) { \
- for ( ; ; ) { \
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
- TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
- if (pIn_buf_cur < pIn_buf_end) { \
- c = *pIn_buf_cur++; \
- break; \
- } \
- } else { \
- c = 0; \
- break; \
- } \
- } \
- } else c = *pIn_buf_cur++; } MZ_MACRO_END
-
-#define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n))
-#define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
-#define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END
-
-// TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2.
-// It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a
-// Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the
-// bit buffer contains >=15 bits (deflate's max. Huffman code size).
-#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
- do { \
- temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
- if (temp >= 0) { \
- code_len = temp >> 9; \
- if ((code_len) && (num_bits >= code_len)) \
- break; \
- } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
- code_len = TINFL_FAST_LOOKUP_BITS; \
- do { \
- temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
- } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
- } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
- } while (num_bits < 15);
-
-// TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read
-// beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully
-// decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32.
-// The slow path is only executed at the very end of the input buffer.
-#define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
- int temp; mz_uint code_len, c; \
- if (num_bits < 15) { \
- if ((pIn_buf_end - pIn_buf_cur) < 2) { \
- TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
- } else { \
- bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \
- } \
- } \
- if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
- code_len = temp >> 9, temp &= 511; \
- else { \
- code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
- } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
-
-tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
-{
- static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 };
- static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 };
- static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0};
- static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
- static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
- static const int s_min_table_sizes[3] = { 257, 1, 4 };
-
- tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf;
- const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
- mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
- size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
-
- // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter).
- if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; }
-
- num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start;
- TINFL_CR_BEGIN
-
- bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1;
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
- {
- TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1);
- counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
- if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
- if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
- }
-
- do
- {
- TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1;
- if (r->m_type == 0)
- {
- TINFL_SKIP_BITS(5, num_bits & 7);
- for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); }
- if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); }
- while ((counter) && (num_bits))
- {
- TINFL_GET_BITS(51, dist, 8);
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); }
- *pOut_buf_cur++ = (mz_uint8)dist;
- counter--;
- }
- while (counter)
- {
- size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); }
- while (pIn_buf_cur >= pIn_buf_end)
- {
- if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT)
- {
- TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT);
- }
- else
- {
- TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED);
- }
- }
- n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
- TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n;
- }
- }
- else if (r->m_type == 3)
- {
- TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
- }
- else
- {
- if (r->m_type == 1)
- {
- mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i;
- r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
- for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
- }
- else
- {
- for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; }
- MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; }
- r->m_table_sizes[2] = 19;
- }
- for ( ; (int)r->m_type >= 0; r->m_type--)
- {
- int tree_next, tree_cur; tinfl_huff_table *pTable;
- mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree);
- for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
- used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
- for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
- if ((65536 != total) && (used_syms > 1))
- {
- TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
- }
- for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
- {
- mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue;
- cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
- if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; }
- if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
- rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
- for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
- {
- tree_cur -= ((rev_code >>= 1) & 1);
- if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1];
- }
- tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
- }
- if (r->m_type == 2)
- {
- for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); )
- {
- mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; }
- if ((dist == 16) && (!counter))
- {
- TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
- }
- num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16];
- TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s;
- }
- if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
- {
- TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
- }
- TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
- }
- }
- for ( ; ; )
- {
- mz_uint8 *pSrc;
- for ( ; ; )
- {
- if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
- {
- TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
- if (counter >= 256)
- break;
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); }
- *pOut_buf_cur++ = (mz_uint8)counter;
- }
- else
- {
- int sym2; mz_uint code_len;
-#if TINFL_USE_64BIT_BITBUF
- if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; }
-#else
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
-#endif
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
- code_len = sym2 >> 9;
- else
- {
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
- }
- counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
- if (counter & 256)
- break;
-
-#if !TINFL_USE_64BIT_BITBUF
- if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; }
-#endif
- if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
- code_len = sym2 >> 9;
- else
- {
- code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0);
- }
- bit_buf >>= code_len; num_bits -= code_len;
-
- pOut_buf_cur[0] = (mz_uint8)counter;
- if (sym2 & 256)
- {
- pOut_buf_cur++;
- counter = sym2;
- break;
- }
- pOut_buf_cur[1] = (mz_uint8)sym2;
- pOut_buf_cur += 2;
- }
- }
- if ((counter &= 511) == 256) break;
-
- num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
-
- TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
- num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
- if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
-
- dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
- if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
- {
- TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
- }
-
- pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
-
- if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
- {
- while (counter--)
- {
- while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); }
- *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
- }
- continue;
- }
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
- else if ((counter >= 9) && (counter <= dist))
- {
- const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
- do
- {
- ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
- ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
- pOut_buf_cur += 8;
- } while ((pSrc += 8) < pSrc_end);
- if ((counter &= 7) < 3)
- {
- if (counter)
- {
- pOut_buf_cur[0] = pSrc[0];
- if (counter > 1)
- pOut_buf_cur[1] = pSrc[1];
- pOut_buf_cur += counter;
- }
- continue;
- }
- }
-#endif
- do
- {
- pOut_buf_cur[0] = pSrc[0];
- pOut_buf_cur[1] = pSrc[1];
- pOut_buf_cur[2] = pSrc[2];
- pOut_buf_cur += 3; pSrc += 3;
- } while ((int)(counter -= 3) > 2);
- if ((int)counter > 0)
- {
- pOut_buf_cur[0] = pSrc[0];
- if ((int)counter > 1)
- pOut_buf_cur[1] = pSrc[1];
- pOut_buf_cur += counter;
- }
- }
- }
- } while (!(r->m_final & 1));
- if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
- {
- TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; }
- }
- TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
- TINFL_CR_FINISH
-
-common_exit:
- r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start;
- *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
- if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
- {
- const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size;
- mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552;
- while (buf_len)
- {
- for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
- {
- s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
- s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
- }
- for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1;
- s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
- }
- r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH;
- }
- return status;
-}
-
-// Higher level helper functions.
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
-{
- tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0;
- *pOut_len = 0;
- tinfl_init(&decomp);
- for ( ; ; )
- {
- size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
- (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
- if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
- {
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
- }
- src_buf_ofs += src_buf_size;
- *pOut_len += dst_buf_size;
- if (status == TINFL_STATUS_DONE) break;
- new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
- pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
- if (!pNew_buf)
- {
- MZ_FREE(pBuf); *pOut_len = 0; return NULL;
- }
- pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
- }
- return pBuf;
-}
-
-size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
-{
- tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp);
- status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
- return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
-}
-
-int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
-{
- int result = 0;
- tinfl_decompressor decomp;
- mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0;
- if (!pDict)
- return TINFL_STATUS_FAILED;
- tinfl_init(&decomp);
- for ( ; ; )
- {
- size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
- tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
- (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
- in_buf_ofs += in_buf_size;
- if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
- break;
- if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
- {
- result = (status == TINFL_STATUS_DONE);
- break;
- }
- dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
- }
- MZ_FREE(pDict);
- *pIn_buf_size = in_buf_ofs;
- return result;
-}
-
-// ------------------- Low-level Compression (independent from all decompression API's)
-
-// Purposely making these tables static for faster init and thread safety.
-static const mz_uint16 s_tdefl_len_sym[256] = {
- 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
- 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
- 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
- 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
- 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
- 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
- 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
- 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
-
-static const mz_uint8 s_tdefl_len_extra[256] = {
- 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
-
-static const mz_uint8 s_tdefl_small_dist_sym[512] = {
- 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
- 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
- 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
- 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
- 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
- 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
-
-static const mz_uint8 s_tdefl_small_dist_extra[512] = {
- 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7 };
-
-static const mz_uint8 s_tdefl_large_dist_sym[128] = {
- 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
- 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
- 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
-
-static const mz_uint8 s_tdefl_large_dist_extra[128] = {
- 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
- 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
-
-// Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values.
-typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq;
-static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1)
-{
- mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
- for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
- while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
- for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
- {
- const mz_uint32* pHist = &hist[pass << 8];
- mz_uint offsets[256], cur_ofs = 0;
- for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
- for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
- { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
- }
- return pCur_syms;
-}
-
-// tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, alistair@cs.mu.oz.au, Jyrki Katajainen, jyrki@diku.dk, November 1996.
-static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
-{
- int root, leaf, next, avbl, used, dpth;
- if (n==0) return; else if (n==1) { A[0].m_key = 1; return; }
- A[0].m_key += A[1].m_key; root = 0; leaf = 2;
- for (next=1; next < n-1; next++)
- {
- if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key;
- if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
- }
- A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
- avbl = 1; used = dpth = 0; root = n-2; next = n-1;
- while (avbl>0)
- {
- while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; }
- while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; }
- avbl = 2*used; dpth++; used = 0;
- }
-}
-
-// Limits canonical Huffman code table's max code size.
-enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 };
-static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
-{
- int i; mz_uint32 total = 0; if (code_list_len <= 1) return;
- for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i];
- for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
- while (total != (1UL << max_code_size))
- {
- pNum_codes[max_code_size]--;
- for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; }
- total--;
- }
-}
-
-static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
-{
- int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes);
- if (static_table)
- {
- for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
- }
- else
- {
- tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
- int num_used_syms = 0;
- const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
- for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; }
-
- pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
-
- for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++;
-
- tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
-
- MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
- for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
- for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
- }
-
- next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
-
- for (i = 0; i < table_len; i++)
- {
- mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue;
- code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
- d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
- }
-}
-
-#define TDEFL_PUT_BITS(b, l) do { \
- mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
- d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
- while (d->m_bits_in >= 8) { \
- if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
- *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
- d->m_bit_buffer >>= 8; \
- d->m_bits_in -= 8; \
- } \
-} MZ_MACRO_END
-
-#define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
- if (rle_repeat_count < 3) { \
- d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
- while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
- } else { \
- d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
-} rle_repeat_count = 0; } }
-
-#define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
- if (rle_z_count < 3) { \
- d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
- } else if (rle_z_count <= 10) { \
- d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
- } else { \
- d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
-} rle_z_count = 0; } }
-
-static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
-
-static void tdefl_start_dynamic_block(tdefl_compressor *d)
-{
- int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
- mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF;
-
- d->m_huff_count[0][256] = 1;
-
- tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE);
- tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE);
-
- for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) if (d->m_huff_code_sizes[0][num_lit_codes - 1]) break;
- for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) if (d->m_huff_code_sizes[1][num_dist_codes - 1]) break;
-
- memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
- memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
- total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0;
-
- memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
- for (i = 0; i < total_code_sizes_to_pack; i++)
- {
- mz_uint8 code_size = code_sizes_to_pack[i];
- if (!code_size)
- {
- TDEFL_RLE_PREV_CODE_SIZE();
- if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); }
- }
- else
- {
- TDEFL_RLE_ZERO_CODE_SIZE();
- if (code_size != prev_code_size)
- {
- TDEFL_RLE_PREV_CODE_SIZE();
- d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size;
- }
- else if (++rle_repeat_count == 6)
- {
- TDEFL_RLE_PREV_CODE_SIZE();
- }
- }
- prev_code_size = code_size;
- }
- if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); } else { TDEFL_RLE_ZERO_CODE_SIZE(); }
-
- tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE);
-
- TDEFL_PUT_BITS(2, 2);
-
- TDEFL_PUT_BITS(num_lit_codes - 257, 5);
- TDEFL_PUT_BITS(num_dist_codes - 1, 5);
-
- for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) break;
- num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4);
- for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
-
- for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; )
- {
- mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
- TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
- if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
- }
-}
-
-static void tdefl_start_static_block(tdefl_compressor *d)
-{
- mz_uint i;
- mz_uint8 *p = &d->m_huff_code_sizes[0][0];
-
- for (i = 0; i <= 143; ++i) *p++ = 8;
- for ( ; i <= 255; ++i) *p++ = 9;
- for ( ; i <= 279; ++i) *p++ = 7;
- for ( ; i <= 287; ++i) *p++ = 8;
-
- memset(d->m_huff_code_sizes[1], 5, 32);
-
- tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
- tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
-
- TDEFL_PUT_BITS(1, 2);
-}
-
-static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
-
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
-{
- mz_uint flags;
- mz_uint8 *pLZ_codes;
- mz_uint8 *pOutput_buf = d->m_pOutput_buf;
- mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
- mz_uint64 bit_buffer = d->m_bit_buffer;
- mz_uint bits_in = d->m_bits_in;
-
-#define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
-
- flags = 1;
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
- {
- if (flags == 1)
- flags = *pLZ_codes++ | 0x100;
-
- if (flags & 1)
- {
- mz_uint s0, s1, n0, n1, sym, num_extra_bits;
- mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
-
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
- TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
-
- // This sequence coaxes MSVC into using cmov's vs. jmp's.
- s0 = s_tdefl_small_dist_sym[match_dist & 511];
- n0 = s_tdefl_small_dist_extra[match_dist & 511];
- s1 = s_tdefl_large_dist_sym[match_dist >> 8];
- n1 = s_tdefl_large_dist_extra[match_dist >> 8];
- sym = (match_dist < 512) ? s0 : s1;
- num_extra_bits = (match_dist < 512) ? n0 : n1;
-
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
- TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
- }
- else
- {
- mz_uint lit = *pLZ_codes++;
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
-
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
- {
- flags >>= 1;
- lit = *pLZ_codes++;
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
-
- if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
- {
- flags >>= 1;
- lit = *pLZ_codes++;
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
- TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
- }
- }
- }
-
- if (pOutput_buf >= d->m_pOutput_buf_end)
- return MZ_FALSE;
-
- *(mz_uint64*)pOutput_buf = bit_buffer;
- pOutput_buf += (bits_in >> 3);
- bit_buffer >>= (bits_in & ~7);
- bits_in &= 7;
- }
-
-#undef TDEFL_PUT_BITS_FAST
-
- d->m_pOutput_buf = pOutput_buf;
- d->m_bits_in = 0;
- d->m_bit_buffer = 0;
-
- while (bits_in)
- {
- mz_uint32 n = MZ_MIN(bits_in, 16);
- TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
- bit_buffer >>= n;
- bits_in -= n;
- }
-
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
-
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
-}
-#else
-static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
-{
- mz_uint flags;
- mz_uint8 *pLZ_codes;
-
- flags = 1;
- for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
- {
- if (flags == 1)
- flags = *pLZ_codes++ | 0x100;
- if (flags & 1)
- {
- mz_uint sym, num_extra_bits;
- mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
-
- MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
- TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
- TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
-
- if (match_dist < 512)
- {
- sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist];
- }
- else
- {
- sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
- }
- MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
- TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
- TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
- }
- else
- {
- mz_uint lit = *pLZ_codes++;
- MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
- TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
- }
- }
-
- TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
-
- return (d->m_pOutput_buf < d->m_pOutput_buf_end);
-}
-#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
-
-static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
-{
- if (static_block)
- tdefl_start_static_block(d);
- else
- tdefl_start_dynamic_block(d);
- return tdefl_compress_lz_codes(d);
-}
-
-static int tdefl_flush_block(tdefl_compressor *d, int flush)
-{
- mz_uint saved_bit_buf, saved_bits_in;
- mz_uint8 *pSaved_output_buf;
- mz_bool comp_block_succeeded = MZ_FALSE;
- int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
- mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
-
- d->m_pOutput_buf = pOutput_buf_start;
- d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
-
- MZ_ASSERT(!d->m_output_flush_remaining);
- d->m_output_flush_ofs = 0;
- d->m_output_flush_remaining = 0;
-
- *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
- d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
-
- if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
- {
- TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
- }
-
- TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
-
- pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
-
- if (!use_raw_block)
- comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
-
- // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead.
- if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
- ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) )
- {
- mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
- TDEFL_PUT_BITS(0, 2);
- if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
- for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
- {
- TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
- }
- for (i = 0; i < d->m_total_lz_bytes; ++i)
- {
- TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
- }
- }
- // Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes.
- else if (!comp_block_succeeded)
- {
- d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
- tdefl_compress_block(d, MZ_TRUE);
- }
-
- if (flush)
- {
- if (flush == TDEFL_FINISH)
- {
- if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
- if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) { mz_uint i, a = d->m_adler32; for (i = 0; i < 4; i++) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } }
- }
- else
- {
- mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); }
- }
- }
-
- MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
-
- memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
- memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
-
- d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++;
-
- if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
- {
- if (d->m_pPut_buf_func)
- {
- *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
- if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
- return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
- }
- else if (pOutput_buf_start == d->m_output_buf)
- {
- int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
- memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
- d->m_out_buf_ofs += bytes_to_copy;
- if ((n -= bytes_to_copy) != 0)
- {
- d->m_output_flush_ofs = bytes_to_copy;
- d->m_output_flush_remaining = n;
- }
- }
- else
- {
- d->m_out_buf_ofs += n;
- }
- }
-
- return d->m_output_flush_remaining;
-}
-
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
-#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
-static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
-{
- mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
- mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
- const mz_uint16 *s = (const mz_uint16*)(d->m_dict + pos), *p, *q;
- mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
- MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
- for ( ; ; )
- {
- for ( ; ; )
- {
- if (--num_probes_left == 0) return;
- #define TDEFL_PROBE \
- next_probe_pos = d->m_next[probe_pos]; \
- if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
- probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
- if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
- TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
- }
- if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
- do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
- (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
- if (!probe_len)
- {
- *pMatch_dist = dist; *pMatch_len = MZ_MIN(max_match_len, TDEFL_MAX_MATCH_LEN); break;
- }
- else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8*)p == *(const mz_uint8*)q)) > match_len)
- {
- *pMatch_dist = dist; if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) break;
- c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]);
- }
- }
-}
-#else
-static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
-{
- mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
- mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
- const mz_uint8 *s = d->m_dict + pos, *p, *q;
- mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
- MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return;
- for ( ; ; )
- {
- for ( ; ; )
- {
- if (--num_probes_left == 0) return;
- #define TDEFL_PROBE \
- next_probe_pos = d->m_next[probe_pos]; \
- if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
- probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
- if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break;
- TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
- }
- if (!dist) break; p = s; q = d->m_dict + probe_pos; for (probe_len = 0; probe_len < max_match_len; probe_len++) if (*p++ != *q++) break;
- if (probe_len > match_len)
- {
- *pMatch_dist = dist; if ((*pMatch_len = match_len = probe_len) == max_match_len) return;
- c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1];
- }
- }
-}
-#endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
-
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
-static mz_bool tdefl_compress_fast(tdefl_compressor *d)
-{
- // Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio.
- mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left;
- mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
- mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
-
- while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size)))
- {
- const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
- mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
- mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
- d->m_src_buf_left -= num_bytes_to_process;
- lookahead_size += num_bytes_to_process;
-
- while (num_bytes_to_process)
- {
- mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process);
- memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
- if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
- memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos));
- d->m_pSrc += n;
- dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK;
- num_bytes_to_process -= n;
- }
-
- dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size);
- if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) break;
-
- while (lookahead_size >= 4)
- {
- mz_uint cur_match_dist, cur_match_len = 1;
- mz_uint8 *pCur_dict = d->m_dict + cur_pos;
- mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF;
- mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
- mz_uint probe_pos = d->m_hash[hash];
- d->m_hash[hash] = (mz_uint16)lookahead_pos;
-
- if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
- {
- const mz_uint16 *p = (const mz_uint16 *)pCur_dict;
- const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos);
- mz_uint32 probe_len = 32;
- do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
- (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) );
- cur_match_len = ((mz_uint)(p - (const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(const mz_uint8 *)p == *(const mz_uint8 *)q);
- if (!probe_len)
- cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0;
-
- if ((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U)))
- {
- cur_match_len = 1;
- *pLZ_code_buf++ = (mz_uint8)first_trigram;
- *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
- d->m_huff_count[0][(mz_uint8)first_trigram]++;
- }
- else
- {
- mz_uint32 s0, s1;
- cur_match_len = MZ_MIN(cur_match_len, lookahead_size);
-
- MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE));
-
- cur_match_dist--;
-
- pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
- *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
- pLZ_code_buf += 3;
- *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80);
-
- s0 = s_tdefl_small_dist_sym[cur_match_dist & 511];
- s1 = s_tdefl_large_dist_sym[cur_match_dist >> 8];
- d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++;
-
- d->m_huff_count[0][s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++;
- }
- }
- else
- {
- *pLZ_code_buf++ = (mz_uint8)first_trigram;
- *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
- d->m_huff_count[0][(mz_uint8)first_trigram]++;
- }
-
- if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
-
- total_lz_bytes += cur_match_len;
- lookahead_pos += cur_match_len;
- dict_size = MZ_MIN(dict_size + cur_match_len, TDEFL_LZ_DICT_SIZE);
- cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK;
- MZ_ASSERT(lookahead_size >= cur_match_len);
- lookahead_size -= cur_match_len;
-
- if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
- {
- int n;
- d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
- d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
- if ((n = tdefl_flush_block(d, 0)) != 0)
- return (n < 0) ? MZ_FALSE : MZ_TRUE;
- total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left;
- }
- }
-
- while (lookahead_size)
- {
- mz_uint8 lit = d->m_dict[cur_pos];
-
- total_lz_bytes++;
- *pLZ_code_buf++ = lit;
- *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
- if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
-
- d->m_huff_count[0][lit]++;
-
- lookahead_pos++;
- dict_size = MZ_MIN(dict_size + 1, TDEFL_LZ_DICT_SIZE);
- cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
- lookahead_size--;
-
- if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
- {
- int n;
- d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
- d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
- if ((n = tdefl_flush_block(d, 0)) != 0)
- return (n < 0) ? MZ_FALSE : MZ_TRUE;
- total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left;
- }
- }
- }
-
- d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
- d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
- return MZ_TRUE;
-}
-#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
-
-static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit)
-{
- d->m_total_lz_bytes++;
- *d->m_pLZ_code_buf++ = lit;
- *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
- d->m_huff_count[0][lit]++;
-}
-
-static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
-{
- mz_uint32 s0, s1;
-
- MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE));
-
- d->m_total_lz_bytes += match_len;
-
- d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN);
-
- match_dist -= 1;
- d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF);
- d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8); d->m_pLZ_code_buf += 3;
-
- *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
-
- s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127];
- d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
-
- if (match_len >= TDEFL_MIN_MATCH_LEN) d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
-}
-
-static mz_bool tdefl_compress_normal(tdefl_compressor *d)
-{
- const mz_uint8 *pSrc = d->m_pSrc; size_t src_buf_left = d->m_src_buf_left;
- tdefl_flush flush = d->m_flush;
-
- while ((src_buf_left) || ((flush) && (d->m_lookahead_size)))
- {
- mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
- // Update dictionary and hash chains. Keeps the lookahead size equal to TDEFL_MAX_MATCH_LEN.
- if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1))
- {
- mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2;
- mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK];
- mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size);
- const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process;
- src_buf_left -= num_bytes_to_process;
- d->m_lookahead_size += num_bytes_to_process;
- while (pSrc != pSrc_end)
- {
- mz_uint8 c = *pSrc++; d->m_dict[dst_pos] = c; if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
- hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
- d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos);
- dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; ins_pos++;
- }
- }
- else
- {
- while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
- {
- mz_uint8 c = *pSrc++;
- mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
- src_buf_left--;
- d->m_dict[dst_pos] = c;
- if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
- d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
- if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN)
- {
- mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2;
- mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
- d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos);
- }
- }
- }
- d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size);
- if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
- break;
-
- // Simple lazy/greedy parsing state machine.
- len_to_move = 1; cur_match_dist = 0; cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1); cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
- if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS))
- {
- if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS)))
- {
- mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK];
- cur_match_len = 0; while (cur_match_len < d->m_lookahead_size) { if (d->m_dict[cur_pos + cur_match_len] != c) break; cur_match_len++; }
- if (cur_match_len < TDEFL_MIN_MATCH_LEN) cur_match_len = 0; else cur_match_dist = 1;
- }
- }
- else
- {
- tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len);
- }
- if (((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5)))
- {
- cur_match_dist = cur_match_len = 0;
- }
- if (d->m_saved_match_len)
- {
- if (cur_match_len > d->m_saved_match_len)
- {
- tdefl_record_literal(d, (mz_uint8)d->m_saved_lit);
- if (cur_match_len >= 128)
- {
- tdefl_record_match(d, cur_match_len, cur_match_dist);
- d->m_saved_match_len = 0; len_to_move = cur_match_len;
- }
- else
- {
- d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
- }
- }
- else
- {
- tdefl_record_match(d, d->m_saved_match_len, d->m_saved_match_dist);
- len_to_move = d->m_saved_match_len - 1; d->m_saved_match_len = 0;
- }
- }
- else if (!cur_match_dist)
- tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]);
- else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
- {
- tdefl_record_match(d, cur_match_len, cur_match_dist);
- len_to_move = cur_match_len;
- }
- else
- {
- d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
- }
- // Move the lookahead forward by len_to_move bytes.
- d->m_lookahead_pos += len_to_move;
- MZ_ASSERT(d->m_lookahead_size >= len_to_move);
- d->m_lookahead_size -= len_to_move;
- d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, TDEFL_LZ_DICT_SIZE);
- // Check if it's time to flush the current LZ codes to the internal output buffer.
- if ( (d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) ||
- ( (d->m_total_lz_bytes > 31*1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) )
- {
- int n;
- d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left;
- if ((n = tdefl_flush_block(d, 0)) != 0)
- return (n < 0) ? MZ_FALSE : MZ_TRUE;
- }
- }
-
- d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left;
- return MZ_TRUE;
-}
-
-static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d)
-{
- if (d->m_pIn_buf_size)
- {
- *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
- }
-
- if (d->m_pOut_buf_size)
- {
- size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining);
- memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n);
- d->m_output_flush_ofs += (mz_uint)n;
- d->m_output_flush_remaining -= (mz_uint)n;
- d->m_out_buf_ofs += n;
-
- *d->m_pOut_buf_size = d->m_out_buf_ofs;
- }
-
- return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY;
-}
-
-tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush)
-{
- if (!d)
- {
- if (pIn_buf_size) *pIn_buf_size = 0;
- if (pOut_buf_size) *pOut_buf_size = 0;
- return TDEFL_STATUS_BAD_PARAM;
- }
-
- d->m_pIn_buf = pIn_buf; d->m_pIn_buf_size = pIn_buf_size;
- d->m_pOut_buf = pOut_buf; d->m_pOut_buf_size = pOut_buf_size;
- d->m_pSrc = (const mz_uint8 *)(pIn_buf); d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0;
- d->m_out_buf_ofs = 0;
- d->m_flush = flush;
-
- if ( ((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) ||
- (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf) )
- {
- if (pIn_buf_size) *pIn_buf_size = 0;
- if (pOut_buf_size) *pOut_buf_size = 0;
- return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM);
- }
- d->m_wants_to_finish |= (flush == TDEFL_FINISH);
-
- if ((d->m_output_flush_remaining) || (d->m_finished))
- return (d->m_prev_return_status = tdefl_flush_output_buffer(d));
-
-#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
- if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) &&
- ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) &&
- ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0))
- {
- if (!tdefl_compress_fast(d))
- return d->m_prev_return_status;
- }
- else
-#endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
- {
- if (!tdefl_compress_normal(d))
- return d->m_prev_return_status;
- }
-
- if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf))
- d->m_adler32 = (mz_uint32)mz_adler32(d->m_adler32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf);
-
- if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining))
- {
- if (tdefl_flush_block(d, flush) < 0)
- return d->m_prev_return_status;
- d->m_finished = (flush == TDEFL_FINISH);
- if (flush == TDEFL_FULL_FLUSH) { MZ_CLEAR_OBJ(d->m_hash); MZ_CLEAR_OBJ(d->m_next); d->m_dict_size = 0; }
- }
-
- return (d->m_prev_return_status = tdefl_flush_output_buffer(d));
-}
-
-tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush)
-{
- MZ_ASSERT(d->m_pPut_buf_func); return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush);
-}
-
-tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
-{
- d->m_pPut_buf_func = pPut_buf_func; d->m_pPut_buf_user = pPut_buf_user;
- d->m_flags = (mz_uint)(flags); d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3; d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0;
- d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
- if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_OBJ(d->m_hash);
- d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0;
- d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0;
- d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8;
- d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf; d->m_prev_return_status = TDEFL_STATUS_OKAY;
- d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0; d->m_adler32 = 1;
- d->m_pIn_buf = NULL; d->m_pOut_buf = NULL;
- d->m_pIn_buf_size = NULL; d->m_pOut_buf_size = NULL;
- d->m_flush = TDEFL_NO_FLUSH; d->m_pSrc = NULL; d->m_src_buf_left = 0; d->m_out_buf_ofs = 0;
- memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
- memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
- return TDEFL_STATUS_OKAY;
-}
-
-tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d)
-{
- return d->m_prev_return_status;
-}
-
-mz_uint32 tdefl_get_adler32(tdefl_compressor *d)
-{
- return d->m_adler32;
-}
-
-mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
-{
- tdefl_compressor *pComp; mz_bool succeeded; if (((buf_len) && (!pBuf)) || (!pPut_buf_func)) return MZ_FALSE;
- pComp = (tdefl_compressor*)MZ_MALLOC(sizeof(tdefl_compressor)); if (!pComp) return MZ_FALSE;
- succeeded = (tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY);
- succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE);
- MZ_FREE(pComp); return succeeded;
-}
-
-typedef struct
-{
- size_t m_size, m_capacity;
- mz_uint8 *m_pBuf;
- mz_bool m_expandable;
-} tdefl_output_buffer;
-
-static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser)
-{
- tdefl_output_buffer *p = (tdefl_output_buffer *)pUser;
- size_t new_size = p->m_size + len;
- if (new_size > p->m_capacity)
- {
- size_t new_capacity = p->m_capacity; mz_uint8 *pNew_buf; if (!p->m_expandable) return MZ_FALSE;
- do { new_capacity = MZ_MAX(128U, new_capacity << 1U); } while (new_size > new_capacity);
- pNew_buf = (mz_uint8*)MZ_REALLOC(p->m_pBuf, new_capacity); if (!pNew_buf) return MZ_FALSE;
- p->m_pBuf = pNew_buf; p->m_capacity = new_capacity;
- }
- memcpy((mz_uint8*)p->m_pBuf + p->m_size, pBuf, len); p->m_size = new_size;
- return MZ_TRUE;
-}
-
-void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
-{
- tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf);
- if (!pOut_len) return MZ_FALSE; else *pOut_len = 0;
- out_buf.m_expandable = MZ_TRUE;
- if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return NULL;
- *pOut_len = out_buf.m_size; return out_buf.m_pBuf;
-}
-
-size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
-{
- tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf);
- if (!pOut_buf) return 0;
- out_buf.m_pBuf = (mz_uint8*)pOut_buf; out_buf.m_capacity = out_buf_len;
- if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return 0;
- return out_buf.m_size;
-}
-
-#ifndef MINIZ_NO_ZLIB_APIS
-static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
-
-// level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files).
-mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy)
-{
- mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
- if (window_bits > 0) comp_flags |= TDEFL_WRITE_ZLIB_HEADER;
-
- if (!level) comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
- else if (strategy == MZ_FILTERED) comp_flags |= TDEFL_FILTER_MATCHES;
- else if (strategy == MZ_HUFFMAN_ONLY) comp_flags &= ~TDEFL_MAX_PROBES_MASK;
- else if (strategy == MZ_FIXED) comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS;
- else if (strategy == MZ_RLE) comp_flags |= TDEFL_RLE_MATCHES;
-
- return comp_flags;
-}
-#endif //MINIZ_NO_ZLIB_APIS
-
-#ifdef _MSC_VER
-#pragma warning (push)
-#pragma warning (disable:4204) // nonstandard extension used : non-constant aggregate initializer (also supported by GNU C and C99, so no big deal)
-#endif
-
-// Simple PNG writer function by Alex Evans, 2011. Released into the public domain: https://gist.github.com/908299, more context at
-// http://altdevblogaday.org/2011/04/06/a-smaller-jpg-encoder/.
-// This is actually a modification of Alex's original code so PNG files generated by this function pass pngcheck.
-void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip)
-{
- // Using a local copy of this array here in case MINIZ_NO_ZLIB_APIS was defined.
- static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
- tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); tdefl_output_buffer out_buf; int i, bpl = w * num_chans, y, z; mz_uint32 c; *pLen_out = 0;
- if (!pComp) return NULL;
- MZ_CLEAR_OBJ(out_buf); out_buf.m_expandable = MZ_TRUE; out_buf.m_capacity = 57+MZ_MAX(64, (1+bpl)*h); if (NULL == (out_buf.m_pBuf = (mz_uint8*)MZ_MALLOC(out_buf.m_capacity))) { MZ_FREE(pComp); return NULL; }
- // write dummy header
- for (z = 41; z; --z) tdefl_output_buffer_putter(&z, 1, &out_buf);
- // compress image data
- tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, s_tdefl_png_num_probes[MZ_MIN(10, level)] | TDEFL_WRITE_ZLIB_HEADER);
- for (y = 0; y < h; ++y) { tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, (mz_uint8*)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); }
- if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) { MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; }
- // write real header
- *pLen_out = out_buf.m_size-41;
- {
- static const mz_uint8 chans[] = {0x00, 0x00, 0x04, 0x02, 0x06};
- mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
- 0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8,chans[num_chans],0,0,0,0,0,0,0,
- (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54};
- c=(mz_uint32)mz_crc32(MZ_CRC32_INIT,pnghdr+12,17); for (i=0; i<4; ++i, c<<=8) ((mz_uint8*)(pnghdr+29))[i]=(mz_uint8)(c>>24);
- memcpy(out_buf.m_pBuf, pnghdr, 41);
- }
- // write footer (IDAT CRC-32, followed by IEND chunk)
- if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) { *pLen_out = 0; MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; }
- c = (mz_uint32)mz_crc32(MZ_CRC32_INIT,out_buf.m_pBuf+41-4, *pLen_out+4); for (i=0; i<4; ++i, c<<=8) (out_buf.m_pBuf+out_buf.m_size-16)[i] = (mz_uint8)(c >> 24);
- // compute final size of file, grab compressed data buffer and return
- *pLen_out += 57; MZ_FREE(pComp); return out_buf.m_pBuf;
-}
-void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
-{
- // Level 6 corresponds to TDEFL_DEFAULT_MAX_PROBES or MZ_DEFAULT_LEVEL (but we can't depend on MZ_DEFAULT_LEVEL being available in case the zlib API's where #defined out)
- return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE);
-}
-
-#ifdef _MSC_VER
-#pragma warning (pop)
-#endif
-
-// ------------------- .ZIP archive reading
-
-#ifndef MINIZ_NO_ARCHIVE_APIS
-
-#ifdef MINIZ_NO_STDIO
- #define MZ_FILE void *
-#else
- #include <stdio.h>
- #include <sys/stat.h>
-
- #if defined(_MSC_VER) || defined(__MINGW64__)
- static FILE *mz_fopen(const char *pFilename, const char *pMode)
- {
- FILE* pFile = NULL;
- fopen_s(&pFile, pFilename, pMode);
- return pFile;
- }
- static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
- {
- FILE* pFile = NULL;
- if (freopen_s(&pFile, pPath, pMode, pStream))
- return NULL;
- return pFile;
- }
- #ifndef MINIZ_NO_TIME
- #include <sys/utime.h>
- #endif
- #define MZ_FILE FILE
- #define MZ_FOPEN mz_fopen
- #define MZ_FCLOSE fclose
- #define MZ_FREAD fread
- #define MZ_FWRITE fwrite
- #define MZ_FTELL64 _ftelli64
- #define MZ_FSEEK64 _fseeki64
- #define MZ_FILE_STAT_STRUCT _stat
- #define MZ_FILE_STAT _stat
- #define MZ_FFLUSH fflush
- #define MZ_FREOPEN mz_freopen
- #define MZ_DELETE_FILE remove
- #elif defined(__MINGW32__)
- #ifndef MINIZ_NO_TIME
- #include <sys/utime.h>
- #endif
- #define MZ_FILE FILE
- #define MZ_FOPEN(f, m) fopen(f, m)
- #define MZ_FCLOSE fclose
- #define MZ_FREAD fread
- #define MZ_FWRITE fwrite
- #define MZ_FTELL64 ftello64
- #define MZ_FSEEK64 fseeko64
- #define MZ_FILE_STAT_STRUCT _stat
- #define MZ_FILE_STAT _stat
- #define MZ_FFLUSH fflush
- #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
- #define MZ_DELETE_FILE remove
- #elif defined(__TINYC__)
- #ifndef MINIZ_NO_TIME
- #include <sys/utime.h>
- #endif
- #define MZ_FILE FILE
- #define MZ_FOPEN(f, m) fopen(f, m)
- #define MZ_FCLOSE fclose
- #define MZ_FREAD fread
- #define MZ_FWRITE fwrite
- #define MZ_FTELL64 ftell
- #define MZ_FSEEK64 fseek
- #define MZ_FILE_STAT_STRUCT stat
- #define MZ_FILE_STAT stat
- #define MZ_FFLUSH fflush
- #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
- #define MZ_DELETE_FILE remove
- #elif defined(__GNUC__) && _LARGEFILE64_SOURCE
- #ifndef MINIZ_NO_TIME
- #include <utime.h>
- #endif
- #define MZ_FILE FILE
- #define MZ_FOPEN(f, m) fopen64(f, m)
- #define MZ_FCLOSE fclose
- #define MZ_FREAD fread
- #define MZ_FWRITE fwrite
- #define MZ_FTELL64 ftello64
- #define MZ_FSEEK64 fseeko64
- #define MZ_FILE_STAT_STRUCT stat64
- #define MZ_FILE_STAT stat64
- #define MZ_FFLUSH fflush
- #define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
- #define MZ_DELETE_FILE remove
- #else
- #ifndef MINIZ_NO_TIME
- #include <utime.h>
- #endif
- #define MZ_FILE FILE
- #define MZ_FOPEN(f, m) fopen(f, m)
- #define MZ_FCLOSE fclose
- #define MZ_FREAD fread
- #define MZ_FWRITE fwrite
- #define MZ_FTELL64 ftello
- #define MZ_FSEEK64 fseeko
- #define MZ_FILE_STAT_STRUCT stat
- #define MZ_FILE_STAT stat
- #define MZ_FFLUSH fflush
- #define MZ_FREOPEN(f, m, s) freopen(f, m, s)
- #define MZ_DELETE_FILE remove
- #endif // #ifdef _MSC_VER
-#endif // #ifdef MINIZ_NO_STDIO
-
-#define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))
-
-// Various ZIP archive enums. To completely avoid cross platform compiler alignment and platform endian issues, miniz.c doesn't use structs for any of this stuff.
-enum
-{
- // ZIP archive identifiers and record sizes
- MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06054b50, MZ_ZIP_CENTRAL_DIR_HEADER_SIG = 0x02014b50, MZ_ZIP_LOCAL_DIR_HEADER_SIG = 0x04034b50,
- MZ_ZIP_LOCAL_DIR_HEADER_SIZE = 30, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE = 46, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE = 22,
- // Central directory header record offsets
- MZ_ZIP_CDH_SIG_OFS = 0, MZ_ZIP_CDH_VERSION_MADE_BY_OFS = 4, MZ_ZIP_CDH_VERSION_NEEDED_OFS = 6, MZ_ZIP_CDH_BIT_FLAG_OFS = 8,
- MZ_ZIP_CDH_METHOD_OFS = 10, MZ_ZIP_CDH_FILE_TIME_OFS = 12, MZ_ZIP_CDH_FILE_DATE_OFS = 14, MZ_ZIP_CDH_CRC32_OFS = 16,
- MZ_ZIP_CDH_COMPRESSED_SIZE_OFS = 20, MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS = 24, MZ_ZIP_CDH_FILENAME_LEN_OFS = 28, MZ_ZIP_CDH_EXTRA_LEN_OFS = 30,
- MZ_ZIP_CDH_COMMENT_LEN_OFS = 32, MZ_ZIP_CDH_DISK_START_OFS = 34, MZ_ZIP_CDH_INTERNAL_ATTR_OFS = 36, MZ_ZIP_CDH_EXTERNAL_ATTR_OFS = 38, MZ_ZIP_CDH_LOCAL_HEADER_OFS = 42,
- // Local directory header offsets
- MZ_ZIP_LDH_SIG_OFS = 0, MZ_ZIP_LDH_VERSION_NEEDED_OFS = 4, MZ_ZIP_LDH_BIT_FLAG_OFS = 6, MZ_ZIP_LDH_METHOD_OFS = 8, MZ_ZIP_LDH_FILE_TIME_OFS = 10,
- MZ_ZIP_LDH_FILE_DATE_OFS = 12, MZ_ZIP_LDH_CRC32_OFS = 14, MZ_ZIP_LDH_COMPRESSED_SIZE_OFS = 18, MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22,
- MZ_ZIP_LDH_FILENAME_LEN_OFS = 26, MZ_ZIP_LDH_EXTRA_LEN_OFS = 28,
- // End of central directory offsets
- MZ_ZIP_ECDH_SIG_OFS = 0, MZ_ZIP_ECDH_NUM_THIS_DISK_OFS = 4, MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS = 6, MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 8,
- MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS = 10, MZ_ZIP_ECDH_CDIR_SIZE_OFS = 12, MZ_ZIP_ECDH_CDIR_OFS_OFS = 16, MZ_ZIP_ECDH_COMMENT_SIZE_OFS = 20,
-};
-
-typedef struct
-{
- void *m_p;
- size_t m_size, m_capacity;
- mz_uint m_element_size;
-} mz_zip_array;
-
-struct mz_zip_internal_state_tag
-{
- mz_zip_array m_central_dir;
- mz_zip_array m_central_dir_offsets;
- mz_zip_array m_sorted_central_dir_offsets;
- MZ_FILE *m_pFile;
- void *m_pMem;
- size_t m_mem_size;
- size_t m_mem_capacity;
-};
-
-#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
-#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
-
-static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray)
-{
- pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p);
- memset(pArray, 0, sizeof(mz_zip_array));
-}
-
-static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array *pArray, size_t min_new_capacity, mz_uint growing)
-{
- void *pNew_p; size_t new_capacity = min_new_capacity; MZ_ASSERT(pArray->m_element_size); if (pArray->m_capacity >= min_new_capacity) return MZ_TRUE;
- if (growing) { new_capacity = MZ_MAX(1, pArray->m_capacity); while (new_capacity < min_new_capacity) new_capacity *= 2; }
- if (NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->m_p, pArray->m_element_size, new_capacity))) return MZ_FALSE;
- pArray->m_p = pNew_p; pArray->m_capacity = new_capacity;
- return MZ_TRUE;
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing)
-{
- if (new_capacity > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) return MZ_FALSE; }
- return MZ_TRUE;
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing)
-{
- if (new_size > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) return MZ_FALSE; }
- pArray->m_size = new_size;
- return MZ_TRUE;
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n)
-{
- return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE);
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n)
-{
- if (n==0) return MZ_TRUE;
- assert(NULL!=pElements);
- size_t orig_size = pArray->m_size; if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) return MZ_FALSE;
- memcpy((mz_uint8*)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_TIME
-static time_t mz_zip_dos_to_time_t(int dos_time, int dos_date)
-{
- struct tm tm;
- memset(&tm, 0, sizeof(tm)); tm.tm_isdst = -1;
- tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900; tm.tm_mon = ((dos_date >> 5) & 15) - 1; tm.tm_mday = dos_date & 31;
- tm.tm_hour = (dos_time >> 11) & 31; tm.tm_min = (dos_time >> 5) & 63; tm.tm_sec = (dos_time << 1) & 62;
- return mktime(&tm);
-}
-
-static void mz_zip_time_to_dos_time(time_t time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
-{
-#ifdef _MSC_VER
- struct tm tm_struct;
- struct tm *tm = &tm_struct;
- errno_t err = localtime_s(tm, &time);
- if (err)
- {
- *pDOS_date = 0; *pDOS_time = 0;
- return;
- }
-#else
- struct tm *tm = localtime(&time);
-#endif
- *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
- *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
-}
-#endif
-
-#ifndef MINIZ_NO_STDIO
-static mz_bool mz_zip_get_file_modified_time(const char *pFilename, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
-{
-#ifdef MINIZ_NO_TIME
- (void)pFilename; *pDOS_date = *pDOS_time = 0;
-#else
- struct MZ_FILE_STAT_STRUCT file_stat;
- // On Linux with x86 glibc, this call will fail on large files (>= 0x80000000 bytes) unless you compiled with _LARGEFILE64_SOURCE. Argh.
- if (MZ_FILE_STAT(pFilename, &file_stat) != 0)
- return MZ_FALSE;
- mz_zip_time_to_dos_time(file_stat.st_mtime, pDOS_time, pDOS_date);
-#endif // #ifdef MINIZ_NO_TIME
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_TIME
-static mz_bool mz_zip_set_file_times(const char *pFilename, time_t access_time, time_t modified_time)
-{
- struct utimbuf t; t.actime = access_time; t.modtime = modified_time;
- return !utime(pFilename, &t);
-}
-#endif // #ifndef MINIZ_NO_TIME
-#endif // #ifndef MINIZ_NO_STDIO
-
-static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint32 flags)
-{
- (void)flags;
- if ((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
- return MZ_FALSE;
-
- if (!pZip->m_pAlloc) pZip->m_pAlloc = def_alloc_func;
- if (!pZip->m_pFree) pZip->m_pFree = def_free_func;
- if (!pZip->m_pRealloc) pZip->m_pRealloc = def_realloc_func;
-
- pZip->m_zip_mode = MZ_ZIP_MODE_READING;
- pZip->m_archive_size = 0;
- pZip->m_central_directory_file_ofs = 0;
- pZip->m_total_files = 0;
-
- if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state))))
- return MZ_FALSE;
- memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32));
- return MZ_TRUE;
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index)
-{
- const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
- const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index));
- mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS), r_len = MZ_READ_LE16(pR + MZ_ZIP_CDH_FILENAME_LEN_OFS);
- mz_uint8 l = 0, r = 0;
- pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; pR += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
- pE = pL + MZ_MIN(l_len, r_len);
- while (pL < pE)
- {
- if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR)))
- break;
- pL++; pR++;
- }
- return (pL == pE) ? (l_len < r_len) : (l < r);
-}
-
-#define MZ_SWAP_UINT32(a, b) do { mz_uint32 t = a; a = b; b = t; } MZ_MACRO_END
-
-// Heap sort of lowercased filenames, used to help accelerate plain central directory searches by mz_zip_reader_locate_file(). (Could also use qsort(), but it could allocate memory.)
-static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip)
-{
- mz_zip_internal_state *pState = pZip->m_pState;
- const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
- const mz_zip_array *pCentral_dir = &pState->m_central_dir;
- mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
- const int size = pZip->m_total_files;
- int start = (size - 2) >> 1, end;
- while (start >= 0)
- {
- int child, root = start;
- for ( ; ; )
- {
- if ((child = (root << 1) + 1) >= size)
- break;
- child += (((child + 1) < size) && (mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1])));
- if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child]))
- break;
- MZ_SWAP_UINT32(pIndices[root], pIndices[child]); root = child;
- }
- start--;
- }
-
- end = size - 1;
- while (end > 0)
- {
- int child, root = 0;
- MZ_SWAP_UINT32(pIndices[end], pIndices[0]);
- for ( ; ; )
- {
- if ((child = (root << 1) + 1) >= end)
- break;
- child += (((child + 1) < end) && mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1]));
- if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child]))
- break;
- MZ_SWAP_UINT32(pIndices[root], pIndices[child]); root = child;
- }
- end--;
- }
-}
-
-static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 flags)
-{
- mz_uint cdir_size, num_this_disk, cdir_disk_index;
- mz_uint64 cdir_ofs;
- mz_int64 cur_file_ofs;
- const mz_uint8 *p;
- mz_uint32 buf_u32[4096 / sizeof(mz_uint32)]; mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
- mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0);
- // Basic sanity checks - reject files which are too small, and check the first 4 bytes of the file to make sure a local header is there.
- if (pZip->m_archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- // Find the end of central directory record by scanning the file from the end towards the beginning.
- cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)sizeof(buf_u32), 0);
- for ( ; ; )
- {
- int i, n = (int)MZ_MIN(sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs);
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n)
- return MZ_FALSE;
- for (i = n - 4; i >= 0; --i)
- if (MZ_READ_LE32(pBuf + i) == MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG)
- break;
- if (i >= 0)
- {
- cur_file_ofs += i;
- break;
- }
- if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (0xFFFF + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
- return MZ_FALSE;
- cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0);
- }
- // Read and verify the end of central directory record.
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- if ((MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_SIG_OFS) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG) ||
- ((pZip->m_total_files = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS)) != MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS)))
- return MZ_FALSE;
-
- num_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS);
- cdir_disk_index = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS);
- if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
- return MZ_FALSE;
-
- if ((cdir_size = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_SIZE_OFS)) < pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
-
- cdir_ofs = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_OFS_OFS);
- if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
- return MZ_FALSE;
-
- pZip->m_central_directory_file_ofs = cdir_ofs;
-
- if (pZip->m_total_files)
- {
- mz_uint i, n;
-
- // Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and another to hold the sorted indices.
- if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) ||
- (!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)))
- return MZ_FALSE;
-
- if (sort_central_dir)
- {
- if (!mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE))
- return MZ_FALSE;
- }
-
- if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size)
- return MZ_FALSE;
-
- // Now create an index into the central directory file records, do some basic sanity checking on each record, and check for zip64 entries (which are not yet supported).
- p = (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p;
- for (n = cdir_size, i = 0; i < pZip->m_total_files; ++i)
- {
- mz_uint total_header_size, comp_size, decomp_size, disk_index;
- if ((n < MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) || (MZ_READ_LE32(p) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG))
- return MZ_FALSE;
- MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, i) = (mz_uint32)(p - (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p);
- if (sort_central_dir)
- MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_sorted_central_dir_offsets, mz_uint32, i) = i;
- comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
- decomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
- if (((!MZ_READ_LE32(p + MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size) || (decomp_size == 0xFFFFFFFF) || (comp_size == 0xFFFFFFFF))
- return MZ_FALSE;
- disk_index = MZ_READ_LE16(p + MZ_ZIP_CDH_DISK_START_OFS);
- if ((disk_index != num_this_disk) && (disk_index != 1))
- return MZ_FALSE;
- if (((mz_uint64)MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS) + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + comp_size) > pZip->m_archive_size)
- return MZ_FALSE;
- if ((total_header_size = MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS)) > n)
- return MZ_FALSE;
- n -= total_header_size; p += total_header_size;
- }
- }
-
- if (sort_central_dir)
- mz_zip_reader_sort_central_dir_offsets_by_filename(pZip);
-
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags)
-{
- if ((!pZip) || (!pZip->m_pRead))
- return MZ_FALSE;
- if (!mz_zip_reader_init_internal(pZip, flags))
- return MZ_FALSE;
- pZip->m_archive_size = size;
- if (!mz_zip_reader_read_central_dir(pZip, flags))
- {
- mz_zip_reader_end(pZip);
- return MZ_FALSE;
- }
- return MZ_TRUE;
-}
-
-static size_t mz_zip_mem_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
-{
- mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
- size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n);
- memcpy(pBuf, (const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s);
- return s;
-}
-
-mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags)
-{
- if (!mz_zip_reader_init_internal(pZip, flags))
- return MZ_FALSE;
- pZip->m_archive_size = size;
- pZip->m_pRead = mz_zip_mem_read_func;
- pZip->m_pIO_opaque = pZip;
-#ifdef __cplusplus
- pZip->m_pState->m_pMem = const_cast<void *>(pMem);
-#else
- pZip->m_pState->m_pMem = (void *)pMem;
-#endif
- pZip->m_pState->m_mem_size = size;
- if (!mz_zip_reader_read_central_dir(pZip, flags))
- {
- mz_zip_reader_end(pZip);
- return MZ_FALSE;
- }
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_STDIO
-static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
-{
- mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
- mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile);
- if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET))))
- return 0;
- return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile);
-}
-
-mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags)
-{
- mz_uint64 file_size;
- MZ_FILE *pFile = MZ_FOPEN(pFilename, "rb");
- if (!pFile)
- return MZ_FALSE;
- if (MZ_FSEEK64(pFile, 0, SEEK_END))
- {
- MZ_FCLOSE(pFile);
- return MZ_FALSE;
- }
- file_size = MZ_FTELL64(pFile);
- if (!mz_zip_reader_init_internal(pZip, flags))
- {
- MZ_FCLOSE(pFile);
- return MZ_FALSE;
- }
- pZip->m_pRead = mz_zip_file_read_func;
- pZip->m_pIO_opaque = pZip;
- pZip->m_pState->m_pFile = pFile;
- pZip->m_archive_size = file_size;
- if (!mz_zip_reader_read_central_dir(pZip, flags))
- {
- mz_zip_reader_end(pZip);
- return MZ_FALSE;
- }
- return MZ_TRUE;
-}
-#endif // #ifndef MINIZ_NO_STDIO
-
-mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip)
-{
- return pZip ? pZip->m_total_files : 0;
-}
-
-static MZ_FORCEINLINE const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
-{
- if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
- return NULL;
- return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index));
-}
-
-mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index)
-{
- mz_uint m_bit_flag;
- const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index);
- if (!p)
- return MZ_FALSE;
- m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
- return (m_bit_flag & 1);
-}
-
-mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index)
-{
- mz_uint filename_len, external_attr;
- const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index);
- if (!p)
- return MZ_FALSE;
-
- // First see if the filename ends with a '/' character.
- filename_len = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
- if (filename_len)
- {
- if (*(p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_len - 1) == '/')
- return MZ_TRUE;
- }
-
- // Bugfix: This code was also checking if the internal attribute was non-zero, which wasn't correct.
- // Most/all zip writers (hopefully) set DOS file/directory attributes in the low 16-bits, so check for the DOS directory flag and ignore the source OS ID in the created by field.
- // FIXME: Remove this check? Is it necessary - we already check the filename.
- external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS);
- if ((external_attr & 0x10) != 0)
- return MZ_TRUE;
-
- return MZ_FALSE;
-}
-
-mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat)
-{
- mz_uint n;
- const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index);
- if ((!p) || (!pStat))
- return MZ_FALSE;
-
- // Unpack the central directory record.
- pStat->m_file_index = file_index;
- pStat->m_central_dir_ofs = MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index);
- pStat->m_version_made_by = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS);
- pStat->m_version_needed = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_NEEDED_OFS);
- pStat->m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
- pStat->m_method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS);
-#ifndef MINIZ_NO_TIME
- pStat->m_time = mz_zip_dos_to_time_t(MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_TIME_OFS), MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_DATE_OFS));
-#endif
- pStat->m_crc32 = MZ_READ_LE32(p + MZ_ZIP_CDH_CRC32_OFS);
- pStat->m_comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
- pStat->m_uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
- pStat->m_internal_attr = MZ_READ_LE16(p + MZ_ZIP_CDH_INTERNAL_ATTR_OFS);
- pStat->m_external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS);
- pStat->m_local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS);
-
- // Copy as much of the filename and comment as possible.
- n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1);
- memcpy(pStat->m_filename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n); pStat->m_filename[n] = '\0';
-
- n = MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS); n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1);
- pStat->m_comment_size = n;
- memcpy(pStat->m_comment, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS), n); pStat->m_comment[n] = '\0';
-
- return MZ_TRUE;
-}
-
-mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size)
-{
- mz_uint n;
- const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index);
- if (!p) { if (filename_buf_size) pFilename[0] = '\0'; return 0; }
- n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
- if (filename_buf_size)
- {
- n = MZ_MIN(n, filename_buf_size - 1);
- memcpy(pFilename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n);
- pFilename[n] = '\0';
- }
- return n + 1;
-}
-
-static MZ_FORCEINLINE mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags)
-{
- mz_uint i;
- if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
- return 0 == memcmp(pA, pB, len);
- for (i = 0; i < len; ++i)
- if (MZ_TOLOWER(pA[i]) != MZ_TOLOWER(pB[i]))
- return MZ_FALSE;
- return MZ_TRUE;
-}
-
-static MZ_FORCEINLINE int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len)
-{
- const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
- mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS);
- mz_uint8 l = 0, r = 0;
- pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
- pE = pL + MZ_MIN(l_len, r_len);
- while (pL < pE)
- {
- if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR)))
- break;
- pL++; pR++;
- }
- return (pL == pE) ? (int)(l_len - r_len) : (l - r);
-}
-
-static int mz_zip_reader_locate_file_binary_search(mz_zip_archive *pZip, const char *pFilename)
-{
- mz_zip_internal_state *pState = pZip->m_pState;
- const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
- const mz_zip_array *pCentral_dir = &pState->m_central_dir;
- mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
- const int size = pZip->m_total_files;
- const mz_uint filename_len = (mz_uint)strlen(pFilename);
- int l = 0, h = size - 1;
- while (l <= h)
- {
- int m = (l + h) >> 1, file_index = pIndices[m], comp = mz_zip_reader_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len);
- if (!comp)
- return file_index;
- else if (comp < 0)
- l = m + 1;
- else
- h = m - 1;
- }
- return -1;
-}
-
-int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags)
-{
- mz_uint file_index; size_t name_len, comment_len;
- if ((!pZip) || (!pZip->m_pState) || (!pName) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
- return -1;
- if (((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size))
- return mz_zip_reader_locate_file_binary_search(pZip, pName);
- name_len = strlen(pName); if (name_len > 0xFFFF) return -1;
- comment_len = pComment ? strlen(pComment) : 0; if (comment_len > 0xFFFF) return -1;
- for (file_index = 0; file_index < pZip->m_total_files; file_index++)
- {
- const mz_uint8 *pHeader = &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index));
- mz_uint filename_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_FILENAME_LEN_OFS);
- const char *pFilename = (const char *)pHeader + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
- if (filename_len < name_len)
- continue;
- if (comment_len)
- {
- mz_uint file_extra_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_EXTRA_LEN_OFS), file_comment_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_COMMENT_LEN_OFS);
- const char *pFile_comment = pFilename + filename_len + file_extra_len;
- if ((file_comment_len != comment_len) || (!mz_zip_reader_string_equal(pComment, pFile_comment, file_comment_len, flags)))
- continue;
- }
- if ((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len))
- {
- int ofs = filename_len - 1;
- do
- {
- if ((pFilename[ofs] == '/') || (pFilename[ofs] == '\\') || (pFilename[ofs] == ':'))
- break;
- } while (--ofs >= 0);
- ofs++;
- pFilename += ofs; filename_len -= ofs;
- }
- if ((filename_len == name_len) && (mz_zip_reader_string_equal(pName, pFilename, filename_len, flags)))
- return file_index;
- }
- return -1;
-}
-
-mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
-{
- int status = TINFL_STATUS_DONE;
- mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
- mz_zip_archive_file_stat file_stat;
- void *pRead_buf;
- mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
- tinfl_decompressor inflator;
-
- if ((buf_size) && (!pBuf))
- return MZ_FALSE;
-
- if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
- return MZ_FALSE;
-
- // Empty file, or a directory (but not always a directory - I've seen odd zips with directories that have compressed data which inflates to 0 bytes)
- if (!file_stat.m_comp_size)
- return MZ_TRUE;
-
- // Entry is a subdirectory (I've seen old zips with dir entries which have compressed deflate data which inflates to 0 bytes, but these entries claim to uncompress to 512 bytes in the headers).
- // I'm torn how to handle this case - should it fail instead?
- if (mz_zip_reader_is_file_a_directory(pZip, file_index))
- return MZ_TRUE;
-
- // Encryption and patch files are not supported.
- if (file_stat.m_bit_flag & (1 | 32))
- return MZ_FALSE;
-
- // This function only supports stored and deflate.
- if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
- return MZ_FALSE;
-
- // Ensure supplied output buffer is large enough.
- needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
- if (buf_size < needed_size)
- return MZ_FALSE;
-
- // Read and parse the local directory entry.
- cur_file_ofs = file_stat.m_local_header_ofs;
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
- return MZ_FALSE;
-
- cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
- if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
- return MZ_FALSE;
-
- if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
- {
- // The file is stored or the caller has requested the compressed data.
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size)
- return MZ_FALSE;
- return ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) != 0) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) == file_stat.m_crc32);
- }
-
- // Decompress the file either directly from memory or from a file input buffer.
- tinfl_init(&inflator);
-
- if (pZip->m_pState->m_pMem)
- {
- // Read directly from the archive in memory.
- pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
- read_buf_size = read_buf_avail = file_stat.m_comp_size;
- comp_remaining = 0;
- }
- else if (pUser_read_buf)
- {
- // Use a user provided read buffer.
- if (!user_read_buf_size)
- return MZ_FALSE;
- pRead_buf = (mz_uint8 *)pUser_read_buf;
- read_buf_size = user_read_buf_size;
- read_buf_avail = 0;
- comp_remaining = file_stat.m_comp_size;
- }
- else
- {
- // Temporarily allocate a read buffer.
- read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
-#ifdef _MSC_VER
- if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
-#else
- if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
-#endif
- return MZ_FALSE;
- if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
- return MZ_FALSE;
- read_buf_avail = 0;
- comp_remaining = file_stat.m_comp_size;
- }
-
- do
- {
- size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs);
- if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
- {
- read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
- cur_file_ofs += read_buf_avail;
- comp_remaining -= read_buf_avail;
- read_buf_ofs = 0;
- }
- in_buf_size = (size_t)read_buf_avail;
- status = tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0));
- read_buf_avail -= in_buf_size;
- read_buf_ofs += in_buf_size;
- out_buf_ofs += out_buf_size;
- } while (status == TINFL_STATUS_NEEDS_MORE_INPUT);
-
- if (status == TINFL_STATUS_DONE)
- {
- // Make sure the entire file was decompressed, and check its CRC.
- if ((out_buf_ofs != file_stat.m_uncomp_size) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32))
- status = TINFL_STATUS_FAILED;
- }
-
- if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf))
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
-
- return status == TINFL_STATUS_DONE;
-}
-
-mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
-{
- int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags);
- if (file_index < 0)
- return MZ_FALSE;
- return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size);
-}
-
-mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags)
-{
- return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0);
-}
-
-mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags)
-{
- return mz_zip_reader_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0);
-}
-
-void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags)
-{
- mz_uint64 comp_size, uncomp_size, alloc_size;
- const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index);
- void *pBuf;
-
- if (pSize)
- *pSize = 0;
- if (!p)
- return NULL;
-
- comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
- uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
-
- alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
-#ifdef _MSC_VER
- if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
-#else
- if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
-#endif
- return NULL;
- if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size)))
- return NULL;
-
- if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags))
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
- return NULL;
- }
-
- if (pSize) *pSize = (size_t)alloc_size;
- return pBuf;
-}
-
-void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags)
-{
- int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags);
- if (file_index < 0)
- {
- if (pSize) *pSize = 0;
- return MZ_FALSE;
- }
- return mz_zip_reader_extract_to_heap(pZip, file_index, pSize, flags);
-}
-
-mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
-{
- int status = TINFL_STATUS_DONE; mz_uint file_crc32 = MZ_CRC32_INIT;
- mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
- mz_zip_archive_file_stat file_stat;
- void *pRead_buf = NULL; void *pWrite_buf = NULL;
- mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
-
- if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
- return MZ_FALSE;
-
- // Empty file, or a directory (but not always a directory - I've seen odd zips with directories that have compressed data which inflates to 0 bytes)
- if (!file_stat.m_comp_size)
- return MZ_TRUE;
-
- // Entry is a subdirectory (I've seen old zips with dir entries which have compressed deflate data which inflates to 0 bytes, but these entries claim to uncompress to 512 bytes in the headers).
- // I'm torn how to handle this case - should it fail instead?
- if (mz_zip_reader_is_file_a_directory(pZip, file_index))
- return MZ_TRUE;
-
- // Encryption and patch files are not supported.
- if (file_stat.m_bit_flag & (1 | 32))
- return MZ_FALSE;
-
- // This function only supports stored and deflate.
- if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
- return MZ_FALSE;
-
- // Read and parse the local directory entry.
- cur_file_ofs = file_stat.m_local_header_ofs;
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
- return MZ_FALSE;
-
- cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
- if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
- return MZ_FALSE;
-
- // Decompress the file either directly from memory or from a file input buffer.
- if (pZip->m_pState->m_pMem)
- {
- pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
- read_buf_size = read_buf_avail = file_stat.m_comp_size;
- comp_remaining = 0;
- }
- else
- {
- read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
- if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
- return MZ_FALSE;
- read_buf_avail = 0;
- comp_remaining = file_stat.m_comp_size;
- }
-
- if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
- {
- // The file is stored or the caller has requested the compressed data.
- if (pZip->m_pState->m_pMem)
- {
-#ifdef _MSC_VER
- if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF))
-#else
- if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF))
-#endif
- return MZ_FALSE;
- if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
- status = TINFL_STATUS_FAILED;
- else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
- file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size);
- out_buf_ofs += file_stat.m_comp_size;
- }
- else
- {
- while (comp_remaining)
- {
- read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
-
- if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
- file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)read_buf_avail);
-
- if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
- cur_file_ofs += read_buf_avail;
- out_buf_ofs += read_buf_avail;
- comp_remaining -= read_buf_avail;
- }
- }
- }
- else
- {
- tinfl_decompressor inflator;
- tinfl_init(&inflator);
-
- if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
- status = TINFL_STATUS_FAILED;
- else
- {
- do
- {
- mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
- size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
- if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
- {
- read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
- if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
- cur_file_ofs += read_buf_avail;
- comp_remaining -= read_buf_avail;
- read_buf_ofs = 0;
- }
-
- in_buf_size = (size_t)read_buf_avail;
- status = tinfl_decompress(&inflator, (const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
- read_buf_avail -= in_buf_size;
- read_buf_ofs += in_buf_size;
-
- if (out_buf_size)
- {
- if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
- file_crc32 = (mz_uint32)mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size);
- if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size)
- {
- status = TINFL_STATUS_FAILED;
- break;
- }
- }
- } while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT));
- }
- }
-
- if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
- {
- // Make sure the entire file was decompressed, and check its CRC.
- if ((out_buf_ofs != file_stat.m_uncomp_size) || (file_crc32 != file_stat.m_crc32))
- status = TINFL_STATUS_FAILED;
- }
-
- if (!pZip->m_pState->m_pMem)
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- if (pWrite_buf)
- pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf);
-
- return status == TINFL_STATUS_DONE;
-}
-
-mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
-{
- int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags);
- if (file_index < 0)
- return MZ_FALSE;
- return mz_zip_reader_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags);
-}
-
-#ifndef MINIZ_NO_STDIO
-static size_t mz_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n)
-{
- (void)ofs; return MZ_FWRITE(pBuf, 1, n, (MZ_FILE*)pOpaque);
-}
-
-mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags)
-{
- mz_bool status;
- mz_zip_archive_file_stat file_stat;
- MZ_FILE *pFile;
- if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
- return MZ_FALSE;
- pFile = MZ_FOPEN(pDst_filename, "wb");
- if (!pFile)
- return MZ_FALSE;
- status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
- if (MZ_FCLOSE(pFile) == EOF)
- return MZ_FALSE;
-#ifndef MINIZ_NO_TIME
- if (status)
- mz_zip_set_file_times(pDst_filename, file_stat.m_time, file_stat.m_time);
-#endif
- return status;
-}
-#endif // #ifndef MINIZ_NO_STDIO
-
-mz_bool mz_zip_reader_end(mz_zip_archive *pZip)
-{
- if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
- return MZ_FALSE;
-
- if (pZip->m_pState)
- {
- mz_zip_internal_state *pState = pZip->m_pState; pZip->m_pState = NULL;
- mz_zip_array_clear(pZip, &pState->m_central_dir);
- mz_zip_array_clear(pZip, &pState->m_central_dir_offsets);
- mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets);
-
-#ifndef MINIZ_NO_STDIO
- if (pState->m_pFile)
- {
- MZ_FCLOSE(pState->m_pFile);
- pState->m_pFile = NULL;
- }
-#endif // #ifndef MINIZ_NO_STDIO
-
- pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
- }
- pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
-
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_STDIO
-mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
-{
- int file_index = mz_zip_reader_locate_file(pZip, pArchive_filename, NULL, flags);
- if (file_index < 0)
- return MZ_FALSE;
- return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags);
-}
-#endif
-
-// ------------------- .ZIP archive writing
-
-#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
-
-static void mz_write_le16(mz_uint8 *p, mz_uint16 v) { p[0] = (mz_uint8)v; p[1] = (mz_uint8)(v >> 8); }
-static void mz_write_le32(mz_uint8 *p, mz_uint32 v) { p[0] = (mz_uint8)v; p[1] = (mz_uint8)(v >> 8); p[2] = (mz_uint8)(v >> 16); p[3] = (mz_uint8)(v >> 24); }
-#define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v))
-#define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v))
-
-mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size)
-{
- if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
- return MZ_FALSE;
-
- if (pZip->m_file_offset_alignment)
- {
- // Ensure user specified file offset alignment is a power of 2.
- if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1))
- return MZ_FALSE;
- }
-
- if (!pZip->m_pAlloc) pZip->m_pAlloc = def_alloc_func;
- if (!pZip->m_pFree) pZip->m_pFree = def_free_func;
- if (!pZip->m_pRealloc) pZip->m_pRealloc = def_realloc_func;
-
- pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
- pZip->m_archive_size = existing_size;
- pZip->m_central_directory_file_ofs = 0;
- pZip->m_total_files = 0;
-
- if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state))))
- return MZ_FALSE;
- memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32));
- MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32));
- return MZ_TRUE;
-}
-
-static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
-{
- mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
- mz_zip_internal_state *pState = pZip->m_pState;
- mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
-#ifdef _MSC_VER
- if ((!n) || ((0, sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)))
-#else
- if ((!n) || ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)))
-#endif
- return 0;
- if (new_size > pState->m_mem_capacity)
- {
- void *pNew_block;
- size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity); while (new_capacity < new_size) new_capacity *= 2;
- if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity)))
- return 0;
- pState->m_pMem = pNew_block; pState->m_mem_capacity = new_capacity;
- }
- memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n);
- pState->m_mem_size = (size_t)new_size;
- return n;
-}
-
-mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size)
-{
- pZip->m_pWrite = mz_zip_heap_write_func;
- pZip->m_pIO_opaque = pZip;
- if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning))
- return MZ_FALSE;
- if (0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning)))
- {
- if (NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size)))
- {
- mz_zip_writer_end(pZip);
- return MZ_FALSE;
- }
- pZip->m_pState->m_mem_capacity = initial_allocation_size;
- }
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_STDIO
-static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
-{
- mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
- mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile);
- if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET))))
- return 0;
- return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile);
-}
-
-mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning)
-{
- MZ_FILE *pFile;
- pZip->m_pWrite = mz_zip_file_write_func;
- pZip->m_pIO_opaque = pZip;
- if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning))
- return MZ_FALSE;
- if (NULL == (pFile = MZ_FOPEN(pFilename, "wb")))
- {
- mz_zip_writer_end(pZip);
- return MZ_FALSE;
- }
- pZip->m_pState->m_pFile = pFile;
- if (size_to_reserve_at_beginning)
- {
- mz_uint64 cur_ofs = 0; char buf[4096]; MZ_CLEAR_OBJ(buf);
- do
- {
- size_t n = (size_t)MZ_MIN(sizeof(buf), size_to_reserve_at_beginning);
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs, buf, n) != n)
- {
- mz_zip_writer_end(pZip);
- return MZ_FALSE;
- }
- cur_ofs += n; size_to_reserve_at_beginning -= n;
- } while (size_to_reserve_at_beginning);
- }
- return MZ_TRUE;
-}
-#endif // #ifndef MINIZ_NO_STDIO
-
-mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename)
-{
- mz_zip_internal_state *pState;
- if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
- return MZ_FALSE;
- // No sense in trying to write to an archive that's already at the support max size
- if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP_LOCAL_DIR_HEADER_SIZE) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- pState = pZip->m_pState;
-
- if (pState->m_pFile)
- {
-#ifdef MINIZ_NO_STDIO
- pFilename; return MZ_FALSE;
-#else
- // Archive is being read from stdio - try to reopen as writable.
- if (pZip->m_pIO_opaque != pZip)
- return MZ_FALSE;
- if (!pFilename)
- return MZ_FALSE;
- pZip->m_pWrite = mz_zip_file_write_func;
- if (NULL == (pState->m_pFile = MZ_FREOPEN(pFilename, "r+b", pState->m_pFile)))
- {
- // The mz_zip_archive is now in a bogus state because pState->m_pFile is NULL, so just close it.
- mz_zip_reader_end(pZip);
- return MZ_FALSE;
- }
-#endif // #ifdef MINIZ_NO_STDIO
- }
- else if (pState->m_pMem)
- {
- // Archive lives in a memory block. Assume it's from the heap that we can resize using the realloc callback.
- if (pZip->m_pIO_opaque != pZip)
- return MZ_FALSE;
- pState->m_mem_capacity = pState->m_mem_size;
- pZip->m_pWrite = mz_zip_heap_write_func;
- }
- // Archive is being read via a user provided read function - make sure the user has specified a write function too.
- else if (!pZip->m_pWrite)
- return MZ_FALSE;
-
- // Start writing new files at the archive's current central directory location.
- pZip->m_archive_size = pZip->m_central_directory_file_ofs;
- pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
- pZip->m_central_directory_file_ofs = 0;
-
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags)
-{
- return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0);
-}
-
-typedef struct
-{
- mz_zip_archive *m_pZip;
- mz_uint64 m_cur_archive_file_ofs;
- mz_uint64 m_comp_size;
-} mz_zip_writer_add_state;
-
-static mz_bool mz_zip_writer_add_put_buf_callback(const void* pBuf, int len, void *pUser)
-{
- mz_zip_writer_add_state *pState = (mz_zip_writer_add_state *)pUser;
- if ((int)pState->m_pZip->m_pWrite(pState->m_pZip->m_pIO_opaque, pState->m_cur_archive_file_ofs, pBuf, len) != len)
- return MZ_FALSE;
- pState->m_cur_archive_file_ofs += len;
- pState->m_comp_size += len;
- return MZ_TRUE;
-}
-
-static mz_bool mz_zip_writer_create_local_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date)
-{
- (void)pZip;
- memset(pDst, 0, MZ_ZIP_LOCAL_DIR_HEADER_SIZE);
- MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_SIG_OFS, MZ_ZIP_LOCAL_DIR_HEADER_SIG);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_VERSION_NEEDED_OFS, method ? 20 : 0);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_BIT_FLAG_OFS, bit_flags);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_METHOD_OFS, method);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_TIME_OFS, dos_time);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_DATE_OFS, dos_date);
- MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_CRC32_OFS, uncomp_crc32);
- MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS, comp_size);
- MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS, uncomp_size);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILENAME_LEN_OFS, filename_size);
- MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_EXTRA_LEN_OFS, extra_size);
- return MZ_TRUE;
-}
-
-static mz_bool mz_zip_writer_create_central_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
-{
- (void)pZip;
- memset(pDst, 0, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_SIG_OFS, MZ_ZIP_CENTRAL_DIR_HEADER_SIG);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_NEEDED_OFS, method ? 20 : 0);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_BIT_FLAG_OFS, bit_flags);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_METHOD_OFS, method);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_TIME_OFS, dos_time);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_DATE_OFS, dos_date);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_CRC32_OFS, uncomp_crc32);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, comp_size);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, uncomp_size);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILENAME_LEN_OFS, filename_size);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_EXTRA_LEN_OFS, extra_size);
- MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_COMMENT_LEN_OFS, comment_size);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, ext_attributes);
- MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_header_ofs);
- return MZ_TRUE;
-}
-
-static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char *pFilename, mz_uint16 filename_size, const void *pExtra, mz_uint16 extra_size, const void *pComment, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
-{
- mz_zip_internal_state *pState = pZip->m_pState;
- mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size;
- size_t orig_central_dir_size = pState->m_central_dir.m_size;
- mz_uint8 central_dir_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE];
-
- // No zip64 support yet
- if ((local_header_ofs > 0xFFFFFFFF) || (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + comment_size) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes))
- return MZ_FALSE;
-
- if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) ||
- (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pFilename, filename_size)) ||
- (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pExtra, extra_size)) ||
- (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pComment, comment_size)) ||
- (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &central_dir_ofs, 1)))
- {
- // Try to push the central directory array back into its original state.
- mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
- return MZ_FALSE;
- }
-
- return MZ_TRUE;
-}
-
-static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name)
-{
- // Basic ZIP archive filename validity checks: Valid filenames cannot start with a forward slash, cannot contain a drive letter, and cannot use DOS-style backward slashes.
- if (*pArchive_name == '/')
- return MZ_FALSE;
- while (*pArchive_name)
- {
- if ((*pArchive_name == '\\') || (*pArchive_name == ':'))
- return MZ_FALSE;
- pArchive_name++;
- }
- return MZ_TRUE;
-}
-
-static mz_uint mz_zip_writer_compute_padding_needed_for_file_alignment(mz_zip_archive *pZip)
-{
- mz_uint32 n;
- if (!pZip->m_file_offset_alignment)
- return 0;
- n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1));
- return (pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1);
-}
-
-static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_file_ofs, mz_uint32 n)
-{
- char buf[4096];
- memset(buf, 0, MZ_MIN(sizeof(buf), n));
- while (n)
- {
- mz_uint32 s = MZ_MIN(sizeof(buf), n);
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs, buf, s) != s)
- return MZ_FALSE;
- cur_file_ofs += s; n -= s;
- }
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
-{
- mz_uint16 method = 0, dos_time = 0, dos_date = 0;
- mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
- mz_uint64 local_dir_header_ofs, cur_archive_file_ofs, comp_size = 0;
- size_t archive_name_size;
- mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
- tdefl_compressor *pComp = NULL;
- mz_bool store_data_uncompressed;
- mz_zip_internal_state *pState;
-
- if ((int)level_and_flags < 0)
- level_and_flags = MZ_DEFAULT_LEVEL;
- level = level_and_flags & 0xF;
- store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA));
-
- if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (pZip->m_total_files == 0xFFFF) || (level > MZ_UBER_COMPRESSION))
- return MZ_FALSE;
-
- local_dir_header_ofs = cur_archive_file_ofs = pZip->m_archive_size;
- pState = pZip->m_pState;
-
- if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size))
- return MZ_FALSE;
- // No zip64 support yet
- if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF))
- return MZ_FALSE;
- if (!mz_zip_writer_validate_archive_name(pArchive_name))
- return MZ_FALSE;
-
-#ifndef MINIZ_NO_TIME
- {
- time_t cur_time; time(&cur_time);
- mz_zip_time_to_dos_time(cur_time, &dos_time, &dos_date);
- }
-#endif // #ifndef MINIZ_NO_TIME
-
- archive_name_size = strlen(pArchive_name);
- if (archive_name_size > 0xFFFF)
- return MZ_FALSE;
-
- num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip);
-
- // no zip64 support yet
- if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + comment_size + archive_name_size) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- if ((archive_name_size) && (pArchive_name[archive_name_size - 1] == '/'))
- {
- // Set DOS Subdirectory attribute bit.
- ext_attributes |= 0x10;
- // Subdirectories cannot contain data.
- if ((buf_size) || (uncomp_size))
- return MZ_FALSE;
- }
-
- // Try to do any allocations before writing to the archive, so if an allocation fails the file remains unmodified. (A good idea if we're doing an in-place modification.)
- if ((!mz_zip_array_ensure_room(pZip, &pState->m_central_dir, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size)) || (!mz_zip_array_ensure_room(pZip, &pState->m_central_dir_offsets, 1)))
- return MZ_FALSE;
-
- if ((!store_data_uncompressed) && (buf_size))
- {
- if (NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor))))
- return MZ_FALSE;
- }
-
- if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header)))
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- return MZ_FALSE;
- }
- local_dir_header_ofs += num_alignment_padding_bytes;
- if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); }
- cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header);
-
- MZ_CLEAR_OBJ(local_dir_header);
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- return MZ_FALSE;
- }
- cur_archive_file_ofs += archive_name_size;
-
- if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
- {
- uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8*)pBuf, buf_size);
- uncomp_size = buf_size;
- if (uncomp_size <= 3)
- {
- level = 0;
- store_data_uncompressed = MZ_TRUE;
- }
- }
-
- if (store_data_uncompressed)
- {
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- return MZ_FALSE;
- }
-
- cur_archive_file_ofs += buf_size;
- comp_size = buf_size;
-
- if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)
- method = MZ_DEFLATED;
- }
- else if (buf_size)
- {
- mz_zip_writer_add_state state;
-
- state.m_pZip = pZip;
- state.m_cur_archive_file_ofs = cur_archive_file_ofs;
- state.m_comp_size = 0;
-
- if ((tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) ||
- (tdefl_compress_buffer(pComp, pBuf, buf_size, TDEFL_FINISH) != TDEFL_STATUS_DONE))
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- return MZ_FALSE;
- }
-
- comp_size = state.m_comp_size;
- cur_archive_file_ofs = state.m_cur_archive_file_ofs;
-
- method = MZ_DEFLATED;
- }
-
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- pComp = NULL;
-
- // no zip64 support yet
- if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF))
- return MZ_FALSE;
-
- if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date))
- return MZ_FALSE;
-
- if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
- return MZ_FALSE;
-
- if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes))
- return MZ_FALSE;
-
- pZip->m_total_files++;
- pZip->m_archive_size = cur_archive_file_ofs;
-
- return MZ_TRUE;
-}
-
-#ifndef MINIZ_NO_STDIO
-mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
-{
- mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes;
- mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
- mz_uint64 local_dir_header_ofs, cur_archive_file_ofs, uncomp_size = 0, comp_size = 0;
- size_t archive_name_size;
- mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
- MZ_FILE *pSrc_file = NULL;
-
- if ((int)level_and_flags < 0)
- level_and_flags = MZ_DEFAULT_LEVEL;
- level = level_and_flags & 0xF;
-
- if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION))
- return MZ_FALSE;
-
- local_dir_header_ofs = cur_archive_file_ofs = pZip->m_archive_size;
-
-
- if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)
- return MZ_FALSE;
- if (!mz_zip_writer_validate_archive_name(pArchive_name))
- return MZ_FALSE;
-
- archive_name_size = strlen(pArchive_name);
- if (archive_name_size > 0xFFFF)
- return MZ_FALSE;
-
- num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip);
-
- // no zip64 support yet
- if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + comment_size + archive_name_size) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- if (!mz_zip_get_file_modified_time(pSrc_filename, &dos_time, &dos_date))
- return MZ_FALSE;
-
- pSrc_file = MZ_FOPEN(pSrc_filename, "rb");
- if (!pSrc_file)
- return MZ_FALSE;
- MZ_FSEEK64(pSrc_file, 0, SEEK_END);
- uncomp_size = MZ_FTELL64(pSrc_file);
- MZ_FSEEK64(pSrc_file, 0, SEEK_SET);
-
- if (uncomp_size > 0xFFFFFFFF)
- {
- // No zip64 support yet
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
- if (uncomp_size <= 3)
- level = 0;
-
- if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header)))
- {
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
- local_dir_header_ofs += num_alignment_padding_bytes;
- if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); }
- cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header);
-
- MZ_CLEAR_OBJ(local_dir_header);
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
- {
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
- cur_archive_file_ofs += archive_name_size;
-
- if (uncomp_size)
- {
- mz_uint64 uncomp_remaining = uncomp_size;
- void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE);
- if (!pRead_buf)
- {
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
-
- if (!level)
- {
- while (uncomp_remaining)
- {
- mz_uint n = (mz_uint)MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining);
- if ((MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n))
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
- uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n);
- uncomp_remaining -= n;
- cur_archive_file_ofs += n;
- }
- comp_size = uncomp_size;
- }
- else
- {
- mz_bool result = MZ_FALSE;
- mz_zip_writer_add_state state;
- tdefl_compressor *pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor));
- if (!pComp)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
-
- state.m_pZip = pZip;
- state.m_cur_archive_file_ofs = cur_archive_file_ofs;
- state.m_comp_size = 0;
-
- if (tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
-
- for ( ; ; )
- {
- size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, MZ_ZIP_MAX_IO_BUF_SIZE);
- tdefl_status status;
-
- if (MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size)
- break;
-
- uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size);
- uncomp_remaining -= in_buf_size;
-
- status = tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
- if (status == TDEFL_STATUS_DONE)
- {
- result = MZ_TRUE;
- break;
- }
- else if (status != TDEFL_STATUS_OKAY)
- break;
- }
-
- pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
-
- if (!result)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- MZ_FCLOSE(pSrc_file);
- return MZ_FALSE;
- }
-
- comp_size = state.m_comp_size;
- cur_archive_file_ofs = state.m_cur_archive_file_ofs;
-
- method = MZ_DEFLATED;
- }
-
- pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
- }
-
- MZ_FCLOSE(pSrc_file); pSrc_file = NULL;
-
- // no zip64 support yet
- if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF))
- return MZ_FALSE;
-
- if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date))
- return MZ_FALSE;
-
- if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
- return MZ_FALSE;
-
- if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes))
- return MZ_FALSE;
-
- pZip->m_total_files++;
- pZip->m_archive_size = cur_archive_file_ofs;
-
- return MZ_TRUE;
-}
-#endif // #ifndef MINIZ_NO_STDIO
-
-mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index)
-{
- mz_uint n, bit_flags, num_alignment_padding_bytes;
- mz_uint64 comp_bytes_remaining, local_dir_header_ofs;
- mz_uint64 cur_src_file_ofs, cur_dst_file_ofs;
- mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
- mz_uint8 central_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE];
- size_t orig_central_dir_size;
- mz_zip_internal_state *pState;
- void *pBuf; const mz_uint8 *pSrc_central_header;
-
- if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
- return MZ_FALSE;
- if (NULL == (pSrc_central_header = mz_zip_reader_get_cdh(pSource_zip, file_index)))
- return MZ_FALSE;
- pState = pZip->m_pState;
-
- num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip);
-
- // no zip64 support yet
- if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- cur_src_file_ofs = MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS);
- cur_dst_file_ofs = pZip->m_archive_size;
-
- if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
- return MZ_FALSE;
- cur_src_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE;
-
- if (!mz_zip_writer_write_zeros(pZip, cur_dst_file_ofs, num_alignment_padding_bytes))
- return MZ_FALSE;
- cur_dst_file_ofs += num_alignment_padding_bytes;
- local_dir_header_ofs = cur_dst_file_ofs;
- if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); }
-
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
- return MZ_FALSE;
- cur_dst_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE;
-
- n = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
- comp_bytes_remaining = n + MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
-
- if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)MZ_MAX(sizeof(mz_uint32) * 4, MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, comp_bytes_remaining)))))
- return MZ_FALSE;
-
- while (comp_bytes_remaining)
- {
- n = (mz_uint)MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, comp_bytes_remaining);
- if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
- return MZ_FALSE;
- }
- cur_src_file_ofs += n;
-
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
- return MZ_FALSE;
- }
- cur_dst_file_ofs += n;
-
- comp_bytes_remaining -= n;
- }
-
- bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS);
- if (bit_flags & 8)
- {
- // Copy data descriptor
- if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, sizeof(mz_uint32) * 4) != sizeof(mz_uint32) * 4)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
- return MZ_FALSE;
- }
-
- n = sizeof(mz_uint32) * ((MZ_READ_LE32(pBuf) == 0x08074b50) ? 4 : 3);
- if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
- return MZ_FALSE;
- }
-
- cur_dst_file_ofs += n;
- }
- pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
-
- // no zip64 support yet
- if (cur_dst_file_ofs > 0xFFFFFFFF)
- return MZ_FALSE;
-
- orig_central_dir_size = pState->m_central_dir.m_size;
-
- memcpy(central_header, pSrc_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE);
- MZ_WRITE_LE32(central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_dir_header_ofs);
- if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE))
- return MZ_FALSE;
-
- n = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_COMMENT_LEN_OFS);
- if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n))
- {
- mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
- return MZ_FALSE;
- }
-
- if (pState->m_central_dir.m_size > 0xFFFFFFFF)
- return MZ_FALSE;
- n = (mz_uint32)orig_central_dir_size;
- if (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &n, 1))
- {
- mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
- return MZ_FALSE;
- }
-
- pZip->m_total_files++;
- pZip->m_archive_size = cur_dst_file_ofs;
-
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip)
-{
- mz_zip_internal_state *pState;
- mz_uint64 central_dir_ofs, central_dir_size;
- mz_uint8 hdr[MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE];
-
- if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
- return MZ_FALSE;
-
- pState = pZip->m_pState;
-
- // no zip64 support yet
- if ((pZip->m_total_files > 0xFFFF) || ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > 0xFFFFFFFF))
- return MZ_FALSE;
-
- central_dir_ofs = 0;
- central_dir_size = 0;
- if (pZip->m_total_files)
- {
- // Write central directory
- central_dir_ofs = pZip->m_archive_size;
- central_dir_size = pState->m_central_dir.m_size;
- pZip->m_central_directory_file_ofs = central_dir_ofs;
- if (pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (size_t)central_dir_size) != central_dir_size)
- return MZ_FALSE;
- pZip->m_archive_size += central_dir_size;
- }
-
- // Write end of central directory record
- MZ_CLEAR_OBJ(hdr);
- MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG);
- MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, pZip->m_total_files);
- MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, pZip->m_total_files);
- MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_SIZE_OFS, central_dir_size);
- MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_OFS_OFS, central_dir_ofs);
-
- if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, sizeof(hdr)) != sizeof(hdr))
- return MZ_FALSE;
-#ifndef MINIZ_NO_STDIO
- if ((pState->m_pFile) && (MZ_FFLUSH(pState->m_pFile) == EOF))
- return MZ_FALSE;
-#endif // #ifndef MINIZ_NO_STDIO
-
- pZip->m_archive_size += sizeof(hdr);
-
- pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED;
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize)
-{
- if ((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pSize))
- return MZ_FALSE;
- if (pZip->m_pWrite != mz_zip_heap_write_func)
- return MZ_FALSE;
- if (!mz_zip_writer_finalize_archive(pZip))
- return MZ_FALSE;
-
- *pBuf = pZip->m_pState->m_pMem;
- *pSize = pZip->m_pState->m_mem_size;
- pZip->m_pState->m_pMem = NULL;
- pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0;
- return MZ_TRUE;
-}
-
-mz_bool mz_zip_writer_end(mz_zip_archive *pZip)
-{
- mz_zip_internal_state *pState;
- mz_bool status = MZ_TRUE;
- if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || ((pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) && (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)))
- return MZ_FALSE;
-
- pState = pZip->m_pState;
- pZip->m_pState = NULL;
- mz_zip_array_clear(pZip, &pState->m_central_dir);
- mz_zip_array_clear(pZip, &pState->m_central_dir_offsets);
- mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets);
-
-#ifndef MINIZ_NO_STDIO
- if (pState->m_pFile)
- {
- MZ_FCLOSE(pState->m_pFile);
- pState->m_pFile = NULL;
- }
-#endif // #ifndef MINIZ_NO_STDIO
-
- if ((pZip->m_pWrite == mz_zip_heap_write_func) && (pState->m_pMem))
- {
- pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem);
- pState->m_pMem = NULL;
- }
-
- pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
- pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
- return status;
-}
-
-#ifndef MINIZ_NO_STDIO
-mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
-{
- mz_bool status, created_new_archive = MZ_FALSE;
- mz_zip_archive zip_archive;
- struct MZ_FILE_STAT_STRUCT file_stat;
- MZ_CLEAR_OBJ(zip_archive);
- if ((int)level_and_flags < 0)
- level_and_flags = MZ_DEFAULT_LEVEL;
- if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > MZ_UBER_COMPRESSION))
- return MZ_FALSE;
- if (!mz_zip_writer_validate_archive_name(pArchive_name))
- return MZ_FALSE;
- if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0)
- {
- // Create a new archive.
- if (!mz_zip_writer_init_file(&zip_archive, pZip_filename, 0))
- return MZ_FALSE;
- created_new_archive = MZ_TRUE;
- }
- else
- {
- // Append to an existing archive.
- if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY))
- return MZ_FALSE;
- if (!mz_zip_writer_init_from_reader(&zip_archive, pZip_filename))
- {
- mz_zip_reader_end(&zip_archive);
- return MZ_FALSE;
- }
- }
- status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
- // Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.)
- if (!mz_zip_writer_finalize_archive(&zip_archive))
- status = MZ_FALSE;
- if (!mz_zip_writer_end(&zip_archive))
- status = MZ_FALSE;
- if ((!status) && (created_new_archive))
- {
- // It's a new archive and something went wrong, so just delete it.
- int ignoredStatus = MZ_DELETE_FILE(pZip_filename);
- (void)ignoredStatus;
- }
- return status;
-}
-
-void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags)
-{
- int file_index;
- mz_zip_archive zip_archive;
- void *p = NULL;
-
- if (pSize)
- *pSize = 0;
-
- if ((!pZip_filename) || (!pArchive_name))
- return NULL;
-
- MZ_CLEAR_OBJ(zip_archive);
- if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY))
- return NULL;
-
- if ((file_index = mz_zip_reader_locate_file(&zip_archive, pArchive_name, NULL, flags)) >= 0)
- p = mz_zip_reader_extract_to_heap(&zip_archive, file_index, pSize, flags);
-
- mz_zip_reader_end(&zip_archive);
- return p;
-}
-
-#endif // #ifndef MINIZ_NO_STDIO
-
-#endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
-
-#endif // #ifndef MINIZ_NO_ARCHIVE_APIS
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // MINIZ_HEADER_FILE_ONLY
-
-/*
- This is free and unencumbered software released into the public domain.
-
- Anyone is free to copy, modify, publish, use, compile, sell, or
- distribute this software, either in source code form or as a compiled
- binary, for any purpose, commercial or non-commercial, and by any
- means.
-
- In jurisdictions that recognize copyright laws, the author or authors
- of this software dedicate any and all copyright interest in the
- software to the public domain. We make this dedication for the benefit
- of the public at large and to the detriment of our heirs and
- successors. We intend this dedication to be an overt act of
- relinquishment in perpetuity of all present and future rights to this
- software under copyright law.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
- For more information, please refer to <http://unlicense.org/>
-*/
diff --git a/src/3rdparty/assimp/contrib/zip/src/zip.c b/src/3rdparty/assimp/contrib/zip/src/zip.c
deleted file mode 100644
index 80573096b..000000000
--- a/src/3rdparty/assimp/contrib/zip/src/zip.c
+++ /dev/null
@@ -1,640 +0,0 @@
-/*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "zip.h"
-#include "miniz.h"
-
-#include <errno.h>
-#include <sys/stat.h>
-#include <time.h>
-
-#if defined _WIN32 || defined __WIN32__
-/* Win32, DOS */
-#include <direct.h>
-
-#define MKDIR(DIRNAME) _mkdir(DIRNAME)
-#define STRCLONE(STR) ((STR) ? _strdup(STR) : NULL)
-#define HAS_DEVICE(P) \
- ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) && \
- (P)[1] == ':')
-#define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE(P) ? 2 : 0)
-#define ISSLASH(C) ((C) == '/' || (C) == '\\')
-
-#else
-#define MKDIR(DIRNAME) mkdir(DIRNAME, 0755)
-#define STRCLONE(STR) ((STR) ? strdup(STR) : NULL)
-#endif
-
-#ifndef FILESYSTEM_PREFIX_LEN
-#define FILESYSTEM_PREFIX_LEN(P) 0
-#endif
-
-#ifndef ISSLASH
-#define ISSLASH(C) ((C) == '/')
-#endif
-
-#define CLEANUP(ptr) \
- do { \
- if (ptr) { \
- free((void *)ptr); \
- ptr = NULL; \
- } \
- } while (0)
-
-static char *basename(const char *name) {
- char const *p;
- char const *base = name += FILESYSTEM_PREFIX_LEN(name);
- int all_slashes = 1;
-
- for (p = name; *p; p++) {
- if (ISSLASH(*p))
- base = p + 1;
- else
- all_slashes = 0;
- }
-
- /* If NAME is all slashes, arrange to return `/'. */
- if (*base == '\0' && ISSLASH(*name) && all_slashes) --base;
-
- return (char *)base;
-}
-
-static int mkpath(const char *path) {
- char const *p;
- char npath[MAX_PATH + 1] = {0};
- int len = 0;
-
- for (p = path; *p && len < MAX_PATH; p++) {
- if (ISSLASH(*p) && len > 0) {
- if (MKDIR(npath) == -1)
- if (errno != EEXIST) return -1;
- }
- npath[len++] = *p;
- }
-
- return 0;
-}
-
-static char *strrpl(const char *str, char oldchar, char newchar) {
- char *rpl = (char *)malloc(sizeof(char) * (1 + strlen(str)));
- char *begin = rpl;
- char c;
- while((c = *str++)) {
- if (c == oldchar) {
- c = newchar;
- }
- *rpl++ = c;
- }
- *rpl = '\0';
-
- return begin;
-}
-
-struct zip_entry_t {
- int index;
- const char *name;
- mz_uint64 uncomp_size;
- mz_uint64 comp_size;
- mz_uint32 uncomp_crc32;
- mz_uint64 offset;
- mz_uint8 header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
- mz_uint64 header_offset;
- mz_uint16 method;
- mz_zip_writer_add_state state;
- tdefl_compressor comp;
-};
-
-struct zip_t {
- mz_zip_archive archive;
- mz_uint level;
- struct zip_entry_t entry;
- char mode;
-};
-
-struct zip_t *zip_open(const char *zipname, int level, char mode) {
- struct zip_t *zip = NULL;
-
- if (!zipname || strlen(zipname) < 1) {
- // zip_t archive name is empty or NULL
- goto cleanup;
- }
-
- if (level < 0) level = MZ_DEFAULT_LEVEL;
- if ((level & 0xF) > MZ_UBER_COMPRESSION) {
- // Wrong compression level
- goto cleanup;
- }
-
- zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t));
- if (!zip) goto cleanup;
-
- zip->level = level;
- zip->mode = mode;
- switch (mode) {
- case 'w':
- // Create a new archive.
- if (!mz_zip_writer_init_file(&(zip->archive), zipname, 0)) {
- // Cannot initialize zip_archive writer
- goto cleanup;
- }
- break;
-
- case 'r':
- case 'a':
- if (!mz_zip_reader_init_file(
- &(zip->archive), zipname,
- level | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY)) {
- // An archive file does not exist or cannot initialize
- // zip_archive reader
- goto cleanup;
- }
-
- if (mode == 'a' &&
- !mz_zip_writer_init_from_reader(&(zip->archive), zipname)) {
- mz_zip_reader_end(&(zip->archive));
- goto cleanup;
- }
-
- break;
-
- default:
- goto cleanup;
- }
-
- return zip;
-
-cleanup:
- CLEANUP(zip);
- return NULL;
-}
-
-void zip_close(struct zip_t *zip) {
- if (zip) {
- // Always finalize, even if adding failed for some reason, so we have a
- // valid central directory.
- mz_zip_writer_finalize_archive(&(zip->archive));
-
- mz_zip_writer_end(&(zip->archive));
- mz_zip_reader_end(&(zip->archive));
-
- CLEANUP(zip);
- }
-}
-
-int zip_entry_open(struct zip_t *zip, const char *entryname) {
- char *locname = NULL;
- size_t entrylen = 0;
- mz_zip_archive *pzip = NULL;
- mz_uint num_alignment_padding_bytes, level;
-
- if (!zip || !entryname) {
- return -1;
- }
-
- entrylen = strlen(entryname);
- if (entrylen < 1) {
- return -1;
- }
-
- pzip = &(zip->archive);
- /*
- .ZIP File Format Specification Version: 6.3.3
-
- 4.4.17.1 The name of the file, with optional relative path.
- The path stored MUST not contain a drive or
- device letter, or a leading slash. All slashes
- MUST be forward slashes '/' as opposed to
- backwards slashes '\' for compatibility with Amiga
- and UNIX file systems etc. If input came from standard
- input, there is no file name field.
- */
- locname = strrpl(entryname, '\\', '/');
-
- if (zip->mode == 'r') {
- zip->entry.index = mz_zip_reader_locate_file(pzip, locname, NULL, 0);
- CLEANUP(locname);
- return (zip->entry.index < 0) ? -1 : 0;
- }
-
- zip->entry.index = zip->archive.m_total_files;
- zip->entry.name = locname;
- if (!zip->entry.name) {
- // Cannot parse zip entry name
- return -1;
- }
-
- zip->entry.comp_size = 0;
- zip->entry.uncomp_size = 0;
- zip->entry.uncomp_crc32 = MZ_CRC32_INIT;
- zip->entry.offset = zip->archive.m_archive_size;
- zip->entry.header_offset = zip->archive.m_archive_size;
- memset(zip->entry.header, 0,
- MZ_ZIP_LOCAL_DIR_HEADER_SIZE * sizeof(mz_uint8));
- zip->entry.method = 0;
-
- num_alignment_padding_bytes =
- mz_zip_writer_compute_padding_needed_for_file_alignment(pzip);
-
- if (!pzip->m_pState || (pzip->m_zip_mode != MZ_ZIP_MODE_WRITING)) {
- // Wrong zip mode
- return -1;
- }
- if (zip->level & MZ_ZIP_FLAG_COMPRESSED_DATA) {
- // Wrong zip compression level
- return -1;
- }
- // no zip64 support yet
- if ((pzip->m_total_files == 0xFFFF) ||
- ((pzip->m_archive_size + num_alignment_padding_bytes +
- MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE +
- entrylen) > 0xFFFFFFFF)) {
- // No zip64 support yet
- return -1;
- }
- if (!mz_zip_writer_write_zeros(
- pzip, zip->entry.offset,
- num_alignment_padding_bytes + sizeof(zip->entry.header))) {
- // Cannot memset zip entry header
- return -1;
- }
-
- zip->entry.header_offset += num_alignment_padding_bytes;
- if (pzip->m_file_offset_alignment) {
- MZ_ASSERT((zip->entry.header_offset &
- (pzip->m_file_offset_alignment - 1)) == 0);
- }
- zip->entry.offset +=
- num_alignment_padding_bytes + sizeof(zip->entry.header);
-
- if (pzip->m_pWrite(pzip->m_pIO_opaque, zip->entry.offset, zip->entry.name,
- entrylen) != entrylen) {
- // Cannot write data to zip entry
- return -1;
- }
-
- zip->entry.offset += entrylen;
- level = zip->level & 0xF;
- if (level) {
- zip->entry.state.m_pZip = pzip;
- zip->entry.state.m_cur_archive_file_ofs = zip->entry.offset;
- zip->entry.state.m_comp_size = 0;
-
- if (tdefl_init(&(zip->entry.comp), mz_zip_writer_add_put_buf_callback,
- &(zip->entry.state),
- tdefl_create_comp_flags_from_zip_params(
- level, -15, MZ_DEFAULT_STRATEGY)) !=
- TDEFL_STATUS_OKAY) {
- // Cannot initialize the zip compressor
- return -1;
- }
- }
-
- return 0;
-}
-
-int zip_entry_close(struct zip_t *zip) {
- mz_zip_archive *pzip = NULL;
- mz_uint level;
- tdefl_status done;
- mz_uint16 entrylen;
- time_t t;
- struct tm *tm;
- mz_uint16 dos_time, dos_date;
- int status = -1;
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- if (zip->mode == 'r') {
- return 0;
- }
-
- pzip = &(zip->archive);
- level = zip->level & 0xF;
- if (level) {
- done = tdefl_compress_buffer(&(zip->entry.comp), "", 0, TDEFL_FINISH);
- if (done != TDEFL_STATUS_DONE && done != TDEFL_STATUS_OKAY) {
- // Cannot flush compressed buffer
- goto cleanup;
- }
- zip->entry.comp_size = zip->entry.state.m_comp_size;
- zip->entry.offset = zip->entry.state.m_cur_archive_file_ofs;
- zip->entry.method = MZ_DEFLATED;
- }
-
- entrylen = (mz_uint16)strlen(zip->entry.name);
- t = time(NULL);
- tm = localtime(&t);
- dos_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) +
- ((tm->tm_sec) >> 1));
- dos_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) +
- ((tm->tm_mon + 1) << 5) + tm->tm_mday);
-
- // no zip64 support yet
- if ((zip->entry.comp_size > 0xFFFFFFFF) ||
- (zip->entry.offset > 0xFFFFFFFF)) {
- // No zip64 support, yet
- goto cleanup;
- }
-
- if (!mz_zip_writer_create_local_dir_header(
- pzip, zip->entry.header, entrylen, 0, zip->entry.uncomp_size,
- zip->entry.comp_size, zip->entry.uncomp_crc32, zip->entry.method, 0,
- dos_time, dos_date)) {
- // Cannot create zip entry header
- goto cleanup;
- }
-
- if (pzip->m_pWrite(pzip->m_pIO_opaque, zip->entry.header_offset,
- zip->entry.header, sizeof(zip->entry.header)) !=
- sizeof(zip->entry.header)) {
- // Cannot write zip entry header
- goto cleanup;
- }
-
- if (!mz_zip_writer_add_to_central_dir(
- pzip, zip->entry.name, entrylen, NULL, 0, "", 0,
- zip->entry.uncomp_size, zip->entry.comp_size,
- zip->entry.uncomp_crc32, zip->entry.method, 0, dos_time, dos_date,
- zip->entry.header_offset, 0)) {
- // Cannot write to zip central dir
- goto cleanup;
- }
-
- pzip->m_total_files++;
- pzip->m_archive_size = zip->entry.offset;
- status = 0;
-
-cleanup:
- CLEANUP(zip->entry.name);
- return status;
-}
-
-int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize) {
- mz_uint level;
- mz_zip_archive *pzip = NULL;
- tdefl_status status;
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- pzip = &(zip->archive);
- if (buf && bufsize > 0) {
- zip->entry.uncomp_size += bufsize;
- zip->entry.uncomp_crc32 = (mz_uint32)mz_crc32(
- zip->entry.uncomp_crc32, (const mz_uint8 *)buf, bufsize);
-
- level = zip->level & 0xF;
- if (!level) {
- if ((pzip->m_pWrite(pzip->m_pIO_opaque, zip->entry.offset, buf,
- bufsize) != bufsize)) {
- // Cannot write buffer
- return -1;
- }
- zip->entry.offset += bufsize;
- zip->entry.comp_size += bufsize;
- } else {
- status = tdefl_compress_buffer(&(zip->entry.comp), buf, bufsize,
- TDEFL_NO_FLUSH);
- if (status != TDEFL_STATUS_DONE && status != TDEFL_STATUS_OKAY) {
- // Cannot compress buffer
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-int zip_entry_fwrite(struct zip_t *zip, const char *filename) {
- int status = 0;
- size_t n = 0;
- FILE *stream = NULL;
- mz_uint8 buf[MZ_ZIP_MAX_IO_BUF_SIZE] = {0};
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- stream = fopen(filename, "rb");
- if (!stream) {
- // Cannot open filename
- return -1;
- }
-
- while ((n = fread(buf, sizeof(mz_uint8), MZ_ZIP_MAX_IO_BUF_SIZE, stream)) >
- 0) {
- if (zip_entry_write(zip, buf, n) < 0) {
- status = -1;
- break;
- }
- }
- fclose(stream);
-
- return status;
-}
-
-int zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize) {
- mz_zip_archive *pzip = NULL;
- mz_uint idx;
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- if (zip->mode != 'r' || zip->entry.index < 0) {
- // the entry is not found or we do not have read access
- return -1;
- }
-
- pzip = &(zip->archive);
- idx = (mz_uint)zip->entry.index;
- if (mz_zip_reader_is_file_a_directory(pzip, idx)) {
- // the entry is a directory
- return -1;
- }
-
- *buf = mz_zip_reader_extract_to_heap(pzip, idx, bufsize, 0);
- return (*buf) ? 0 : -1;
-}
-
-int zip_entry_fread(struct zip_t *zip, const char *filename) {
- mz_zip_archive *pzip = NULL;
- mz_uint idx;
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- if (zip->mode != 'r' || zip->entry.index < 0) {
- // the entry is not found or we do not have read access
- return -1;
- }
-
- pzip = &(zip->archive);
- idx = (mz_uint)zip->entry.index;
- if (mz_zip_reader_is_file_a_directory(pzip, idx)) {
- // the entry is a directory
- return -1;
- }
-
- return (mz_zip_reader_extract_to_file(pzip, idx, filename, 0)) ? 0 : -1;
-}
-
-int zip_entry_extract(struct zip_t *zip,
- size_t (*on_extract)(void *arg, unsigned long long offset,
- const void *buf, size_t bufsize),
- void *arg) {
- mz_zip_archive *pzip = NULL;
- mz_uint idx;
-
- if (!zip) {
- // zip_t handler is not initialized
- return -1;
- }
-
- if (zip->mode != 'r' || zip->entry.index < 0) {
- // the entry is not found or we do not have read access
- return -1;
- }
-
- pzip = &(zip->archive);
- idx = (mz_uint)zip->entry.index;
-
- return (mz_zip_reader_extract_to_callback(pzip, idx, on_extract, arg, 0))
- ? 0
- : -1;
-}
-
-int zip_create(const char *zipname, const char *filenames[], size_t len) {
- int status = 0;
- size_t i;
- mz_zip_archive zip_archive;
-
- if (!zipname || strlen(zipname) < 1) {
- // zip_t archive name is empty or NULL
- return -1;
- }
-
- // Create a new archive.
- if (!memset(&(zip_archive), 0, sizeof(zip_archive))) {
- // Cannot memset zip archive
- return -1;
- }
-
- if (!mz_zip_writer_init_file(&zip_archive, zipname, 0)) {
- // Cannot initialize zip_archive writer
- return -1;
- }
-
- for (i = 0; i < len; ++i) {
- const char *name = filenames[i];
- if (!name) {
- status = -1;
- break;
- }
-
- if (!mz_zip_writer_add_file(&zip_archive, basename(name), name, "", 0,
- ZIP_DEFAULT_COMPRESSION_LEVEL)) {
- // Cannot add file to zip_archive
- status = -1;
- break;
- }
- }
-
- mz_zip_writer_finalize_archive(&zip_archive);
- mz_zip_writer_end(&zip_archive);
- return status;
-}
-
-int zip_extract(const char *zipname, const char *dir,
- int (*on_extract)(const char *filename, void *arg), void *arg) {
- int status = -1;
- mz_uint i, n;
- char path[MAX_PATH + 1] = {0};
- mz_zip_archive zip_archive;
- mz_zip_archive_file_stat info;
- size_t dirlen = 0;
-
- if (!memset(&(zip_archive), 0, sizeof(zip_archive))) {
- // Cannot memset zip archive
- return -1;
- }
-
- if (!zipname || !dir) {
- // Cannot parse zip archive name
- return -1;
- }
-
- dirlen = strlen(dir);
- if (dirlen + 1 > MAX_PATH) {
- return -1;
- }
-
- // Now try to open the archive.
- if (!mz_zip_reader_init_file(&zip_archive, zipname, 0)) {
- // Cannot initialize zip_archive reader
- return -1;
- }
-
- strcpy(path, dir);
- if (!ISSLASH(path[dirlen - 1])) {
-#if defined _WIN32 || defined __WIN32__
- path[dirlen] = '\\';
-#else
- path[dirlen] = '/';
-#endif
- ++dirlen;
- }
-
- // Get and print information about each file in the archive.
- n = mz_zip_reader_get_num_files(&zip_archive);
- for (i = 0; i < n; ++i) {
- if (!mz_zip_reader_file_stat(&zip_archive, i, &info)) {
- // Cannot get information about zip archive;
- goto out;
- }
- strncpy(&path[dirlen], info.m_filename, MAX_PATH - dirlen);
- if (mkpath(path) < 0) {
- // Cannot make a path
- goto out;
- }
-
- if (!mz_zip_reader_is_file_a_directory(&zip_archive, i)) {
- if (!mz_zip_reader_extract_to_file(&zip_archive, i, path, 0)) {
- // Cannot extract zip archive to file
- goto out;
- }
- }
-
- if (on_extract) {
- if (on_extract(path, arg) < 0) {
- goto out;
- }
- }
- }
- status = 0;
-
-out:
- // Close the archive, freeing any resources it was using
- if (!mz_zip_reader_end(&zip_archive)) {
- // Cannot end zip reader
- status = -1;
- }
-
- return status;
-}
diff --git a/src/3rdparty/assimp/contrib/zip/src/zip.h b/src/3rdparty/assimp/contrib/zip/src/zip.h
deleted file mode 100644
index 1611b5417..000000000
--- a/src/3rdparty/assimp/contrib/zip/src/zip.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-#ifndef ZIP_H
-#define ZIP_H
-
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef MAX_PATH
-#define MAX_PATH 32767 /* # chars in a path name including NULL */
-#endif
-
-#define ZIP_DEFAULT_COMPRESSION_LEVEL 6
-
-/*
- This data structure is used throughout the library to represent zip archive
- - forward declaration.
-*/
-struct zip_t;
-
-/*
- Opens zip archive with compression level using the given mode.
-
- Args:
- zipname: zip archive file name.
- level: compression level (0-9 are the standard zlib-style levels).
- mode: file access mode.
- 'r': opens a file for reading/extracting (the file must exists).
- 'w': creates an empty file for writing.
- 'a': appends to an existing archive.
-
- Returns:
- The zip archive handler or NULL on error
-*/
-extern struct zip_t *zip_open(const char *zipname, int level, char mode);
-
-/*
- Closes zip archive, releases resources - always finalize.
-
- Args:
- zip: zip archive handler.
-*/
-extern void zip_close(struct zip_t *zip);
-
-/*
- Opens a new entry for writing in a zip archive.
-
- Args:
- zip: zip archive handler.
- entryname: an entry name in local dictionary.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_open(struct zip_t *zip, const char *entryname);
-
-/*
- Closes a zip entry, flushes buffer and releases resources.
-
- Args:
- zip: zip archive handler.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_close(struct zip_t *zip);
-
-/*
- Compresses an input buffer for the current zip entry.
-
- Args:
- zip: zip archive handler.
- buf: input buffer.
- bufsize: input buffer size (in bytes).
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize);
-
-/*
- Compresses a file for the current zip entry.
-
- Args:
- zip: zip archive handler.
- filename: input file.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_fwrite(struct zip_t *zip, const char *filename);
-
-/*
- Extracts the current zip entry into output buffer.
- The function allocates sufficient memory for a output buffer.
-
- Args:
- zip: zip archive handler.
- buf: output buffer.
- bufsize: output buffer size (in bytes).
-
- Note:
- - remember to release memory allocated for a output buffer.
- - for large entries, please take a look at zip_entry_extract function.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize);
-
-/*
- Extracts the current zip entry into output file.
-
- Args:
- zip: zip archive handler.
- filename: output file.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_entry_fread(struct zip_t *zip, const char *filename);
-
-/*
- Extract the current zip entry using a callback function (on_extract).
-
- Args:
- zip: zip archive handler.
- on_extract: callback function.
- arg: opaque pointer (optional argument,
- which you can pass to the on_extract callback)
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
- */
-extern int zip_entry_extract(struct zip_t *zip,
- size_t (*on_extract)(void *arg,
- unsigned long long offset,
- const void *data,
- size_t size),
- void *arg);
-
-/*
- Creates a new archive and puts files into a single zip archive.
-
- Args:
- zipname: zip archive file.
- filenames: input files.
- len: number of input files.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_create(const char *zipname, const char *filenames[], size_t len);
-
-/*
- Extracts a zip archive file into directory.
-
- If on_extract_entry is not NULL, the callback will be called after
- successfully extracted each zip entry.
- Returning a negative value from the callback will cause abort and return an
- error. The last argument (void *arg) is optional, which you can use to pass
- data to the on_extract_entry callback.
-
- Args:
- zipname: zip archive file.
- dir: output directory.
- on_extract_entry: on extract callback.
- arg: opaque pointer.
-
- Returns:
- The return code - 0 on success, negative number (< 0) on error.
-*/
-extern int zip_extract(const char *zipname, const char *dir,
- int (*on_extract_entry)(const char *filename, void *arg),
- void *arg);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif