From ff8a6fe6e582cc0a7152e86f34d38ae6a8f1b7c8 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 24 Jan 2013 11:31:38 +0100 Subject: [PATCH] libc++: adapt to core libc --- qmake.build/c++/libstl/libstl.pro | 11 +++--- src/c++/abstract_stream.h | 6 ++-- src/c++/foug_global.h | 18 ++-------- src/c++/libstl/abstract_geometry.h | 4 +-- src/c++/libstl/stla.cpp | 2 +- src/c++/libstl/stla.h | 2 +- src/c++/libstl/stlb.cpp | 58 +++++++++++++++--------------- src/c++/libstl/stlb.h | 8 ++--- src/c++/streams/qt4_stream.cpp | 6 ++-- src/c++/streams/qt4_stream.h | 6 ++-- 10 files changed, 55 insertions(+), 66 deletions(-) diff --git a/qmake.build/c++/libstl/libstl.pro b/qmake.build/c++/libstl/libstl.pro index eb34e44..90e3c93 100644 --- a/qmake.build/c++/libstl/libstl.pro +++ b/qmake.build/c++/libstl/libstl.pro @@ -9,7 +9,8 @@ message($$PREFIX_DIR) TEMPLATE = lib TARGET = fougstl-c++$$TARGET_SUFFIX DESTDIR = $$PREFIX_DIR/lib -CONFIG *= dll + +DEFINES *= FOUG_USE_STDINT_H dll { DEFINES *= FOUG_STL_DLL FOUG_STL_MAKE_DLL @@ -40,13 +41,13 @@ SOURCES += \ ../../../src/c++/libstl/stlb.cpp \ ../../../src/c++/libstl/stla.cpp -global_inc.path = $$PREFIX_DIR/include +global_inc.path = $$PREFIX_DIR/include/dataex global_inc.files = ../../../src/*.h -cpp_global_inc.path = $$PREFIX_DIR/include/c++ +cpp_global_inc.path = $$PREFIX_DIR/include/dataex/c++ cpp_global_inc.files = ../../../src/c++/*.h -cpp_streams_inc.path = $$PREFIX_DIR/include/c++/streams +cpp_streams_inc.path = $$PREFIX_DIR/include/dataex/c++/streams cpp_streams_inc.files = ../../../src/c++/streams/*.h -cpp_libstl_inc.path = $$PREFIX_DIR/include/c++/libstl +cpp_libstl_inc.path = $$PREFIX_DIR/include/dataex/c++/libstl cpp_libstl_inc.files = ../../../src/c++/libstl/*.h INSTALLS += global_inc cpp_global_inc cpp_streams_inc cpp_libstl_inc diff --git a/src/c++/abstract_stream.h b/src/c++/abstract_stream.h index 168d377..bcb3a0d 100644 --- a/src/c++/abstract_stream.h +++ b/src/c++/abstract_stream.h @@ -14,9 +14,9 @@ public: virtual bool isReadable() const = 0; virtual bool isSequential() const = 0; - virtual bool seek(foug::Int64 pos) = 0; - virtual Int64 read(char* data, Int64 maxSize) = 0; - virtual Int64 write(const char* data, Int64 maxSize) = 0; + virtual bool seek(int64_t pos) = 0; + virtual int64_t read(char* data, int64_t maxSize) = 0; + virtual int64_t write(const char* data, int64_t maxSize) = 0; }; } // namespace foug diff --git a/src/c++/foug_global.h b/src/c++/foug_global.h index 193c9d7..6313580 100644 --- a/src/c++/foug_global.h +++ b/src/c++/foug_global.h @@ -1,24 +1,12 @@ #ifndef FOUG_CPP_GLOBAL_H #define FOUG_CPP_GLOBAL_H -#include "../c/foug_global.h" +#include "../c/global.h" namespace foug { -typedef foug_int8 Int8; -typedef foug_uint8 UInt8; - -typedef foug_int16 Int16; -typedef foug_uint16 UInt16; - -typedef foug_int32 Int32; -typedef foug_uint32 UInt32; - -typedef foug_int64 Int64; -typedef foug_uint64 UInt64; - -typedef foug_real32 Real32; -typedef foug_real64 Real64; +typedef foug_real32_t Real32; +typedef foug_real64_t Real64; } // namespace foug diff --git a/src/c++/libstl/abstract_geometry.h b/src/c++/libstl/abstract_geometry.h index 8ec5eeb..1174353 100644 --- a/src/c++/libstl/abstract_geometry.h +++ b/src/c++/libstl/abstract_geometry.h @@ -30,8 +30,8 @@ typedef Triangle Triangle; class FOUG_STL_EXPORT AbstractGeometry { public: - virtual UInt32 triangleCount() const = 0; - virtual void getTriangle(UInt32 index, Triangle* triangle) const = 0; + virtual uint32_t triangleCount() const = 0; + virtual void getTriangle(uint32_t index, Triangle* triangle) const = 0; }; } // namespace stl diff --git a/src/c++/libstl/stla.cpp b/src/c++/libstl/stla.cpp index c695423..3f687e9 100644 --- a/src/c++/libstl/stla.cpp +++ b/src/c++/libstl/stla.cpp @@ -6,7 +6,7 @@ namespace foug { namespace stla { -bool Io::read(AbstractGeometryBuilder* builder, Int64 streamSize) +bool Io::read(AbstractGeometryBuilder* builder, int64_t streamSize) { return false; } diff --git a/src/c++/libstl/stla.h b/src/c++/libstl/stla.h index a074b83..081d882 100644 --- a/src/c++/libstl/stla.h +++ b/src/c++/libstl/stla.h @@ -22,7 +22,7 @@ class FOUG_STL_EXPORT Io : public IoBase public: Io(AbstractStream* stream = 0); - bool read(AbstractGeometryBuilder* builder, Int64 streamSize = -1); + bool read(AbstractGeometryBuilder* builder, int64_t streamSize = -1); bool write(const stl::AbstractGeometry& geom, const std::string& solidName); }; diff --git a/src/c++/libstl/stlb.cpp b/src/c++/libstl/stlb.cpp index 56f2c70..8e6bee9 100644 --- a/src/c++/libstl/stlb.cpp +++ b/src/c++/libstl/stlb.cpp @@ -7,46 +7,46 @@ // Read tools template -NUMERIC fromLittleEndian(const foug::UInt8* bytes) +NUMERIC fromLittleEndian(const uint8_t* bytes) { return 0; } template<> -foug::UInt16 fromLittleEndian(const foug::UInt8* bytes) +uint16_t fromLittleEndian(const uint8_t* bytes) { // |BB|AA| -> 0xAABB return (bytes[1] << 8) | bytes[0]; } template<> -foug::UInt32 fromLittleEndian(const foug::UInt8* bytes) +uint32_t fromLittleEndian(const uint8_t* bytes) { // |DD|CC|BB|AA| -> 0xAABBCCDD return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); } template<> -foug::Real32 fromLittleEndian(const foug::UInt8* bytes) +foug::Real32 fromLittleEndian(const uint8_t* bytes) { union { - foug::UInt32 asInteger; + uint32_t asInteger; foug::Real32 asFloat; } helper; - helper.asInteger = fromLittleEndian(bytes); + helper.asInteger = fromLittleEndian(bytes); return helper.asFloat; } // Write tools template -void toLittleEndian(NUMERIC n, foug::UInt8* bytes) +void toLittleEndian(NUMERIC n, uint8_t* bytes) { union { NUMERIC asNumeric; - foug::UInt8 asBytes[sizeof(NUMERIC)]; + uint8_t asBytes[sizeof(NUMERIC)]; } helper; helper.asNumeric = n; // std::copy(helper.asBytes, helper.asBytes + sizeof(NUMERIC), bytes); @@ -59,13 +59,13 @@ namespace stlb { static const int stlFacetSize = 50; static const int stlMinFileSize = 284; -static const int stlTriangleDataSize = (4 * 3) * sizeof(foug::Real32) + sizeof(foug::UInt16); +static const int stlTriangleDataSize = (4 * 3) * sizeof(foug::Real32) + sizeof(uint16_t); void AbstractGeometryBuilder::processHeader(const Header& /*data*/) { } -void AbstractGeometryBuilder::beginTriangles(UInt32 /*count*/) +void AbstractGeometryBuilder::beginTriangles(uint32_t /*count*/) { } @@ -95,9 +95,9 @@ bool Io::read(AbstractGeometryBuilder* builder) AbstractStream* istream = this->stream(); AbstractTaskProgress* progress = this->taskProgress(); - const UInt32 chunkSize = stlTriangleDataSize * 163; + const uint32_t chunkSize = stlTriangleDataSize * 163; - UInt8 buffer[8192]; + uint8_t buffer[8192]; char* charBuffer = reinterpret_cast(buffer); // Read header @@ -107,9 +107,9 @@ bool Io::read(AbstractGeometryBuilder* builder) builder->processHeader(headerData); // Read facet count - if (istream->read(charBuffer, sizeof(UInt32)) != sizeof(UInt32)) + if (istream->read(charBuffer, sizeof(uint32_t)) != sizeof(uint32_t)) return false; - const UInt32 facetCount = ::fromLittleEndian(buffer); + const uint32_t facetCount = ::fromLittleEndian(buffer); builder->beginTriangles(facetCount); if (progress != 0) { @@ -118,16 +118,16 @@ bool Io::read(AbstractGeometryBuilder* builder) } // Read triangles - const UInt64 totalFacetSize = stlTriangleDataSize * facetCount; - UInt64 amountReadSize = 0; + const uint64_t totalFacetSize = stlTriangleDataSize * facetCount; + uint64_t amountReadSize = 0; stl::Triangle triangle; bool streamError = false; while (amountReadSize < totalFacetSize && !streamError) { - const Int64 iReadSize = istream->read(charBuffer, chunkSize); + const int64_t iReadSize = istream->read(charBuffer, chunkSize); if (iReadSize > 0 && (iReadSize % stlTriangleDataSize == 0)) { - const UInt32 iFacetCount = iReadSize / stlTriangleDataSize; - UInt32 bufferOffset = 0; - for (UInt32 i = 0; i < iFacetCount; ++i) { + const uint32_t iFacetCount = iReadSize / stlTriangleDataSize; + uint32_t bufferOffset = 0; + for (uint32_t i = 0; i < iFacetCount; ++i) { // Read normal triangle.normal.x = ::fromLittleEndian(buffer + bufferOffset); triangle.normal.y = ::fromLittleEndian(buffer + 1*sizeof(Real32) + bufferOffset); @@ -149,8 +149,8 @@ bool Io::read(AbstractGeometryBuilder* builder) triangle.v3.z = ::fromLittleEndian(buffer + 11*sizeof(Real32) + bufferOffset); // Attribute byte count - const UInt16 attributeByteCount = - ::fromLittleEndian(buffer + 12*sizeof(Real32) + bufferOffset); + const uint16_t attributeByteCount = + ::fromLittleEndian(buffer + 12*sizeof(Real32) + bufferOffset); // Add triangle builder->processNextTriangle(triangle, attributeByteCount); @@ -189,7 +189,7 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat AbstractStream* ostream = this->stream(); AbstractTaskProgress* progress = this->taskProgress(); - UInt8 buffer[128]; + uint8_t buffer[128]; // Write header Header headerData; @@ -202,9 +202,9 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat return false; // Write facet count - const UInt32 facetCount = geom.triangleCount(); - ::toLittleEndian(facetCount, buffer); - if (ostream->write(reinterpret_cast(&buffer), sizeof(UInt32)) != sizeof(UInt32)) + const uint32_t facetCount = geom.triangleCount(); + ::toLittleEndian(facetCount, buffer); + if (ostream->write(reinterpret_cast(&buffer), sizeof(uint32_t)) != sizeof(uint32_t)) return false; if (progress != 0) { @@ -214,7 +214,7 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat // Write triangles stl::Triangle triangle; - for (UInt32 facet = 0; facet < facetCount; ++facet) { + for (uint32_t facet = 0; facet < facetCount; ++facet) { geom.getTriangle(facet, &triangle); // Write normal @@ -238,8 +238,8 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat ::toLittleEndian(triangle.v3.z, buffer + 11*sizeof(Real32)); // Attribute byte count - const UInt16 attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0; - ::toLittleEndian(attrByteCount, buffer + 12*sizeof(Real32)); + const uint16_t attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0; + ::toLittleEndian(attrByteCount, buffer + 12*sizeof(Real32)); // Write to stream if (ostream->write(reinterpret_cast(buffer), stlTriangleDataSize) diff --git a/src/c++/libstl/stlb.h b/src/c++/libstl/stlb.h index a470f54..a42c98e 100644 --- a/src/c++/libstl/stlb.h +++ b/src/c++/libstl/stlb.h @@ -10,14 +10,14 @@ namespace foug { namespace stlb { enum { HeaderSize = 80 }; -typedef UInt8 Header[HeaderSize]; +typedef uint8_t Header[HeaderSize]; class FOUG_STL_EXPORT AbstractGeometryBuilder { public: virtual void processHeader(const Header& data); - virtual void beginTriangles(UInt32 count); - virtual void processNextTriangle(const stl::Triangle& triangle, UInt16 attributeByteCount) = 0; + virtual void beginTriangles(uint32_t count); + virtual void processNextTriangle(const stl::Triangle& triangle, uint16_t attributeByteCount) = 0; virtual void endTriangles(); }; @@ -25,7 +25,7 @@ class FOUG_STL_EXPORT AbstractGeometryExtraData { public: virtual void getHeader(Header& data) const = 0; - virtual UInt16 attributeByteCount(UInt32 triangleIndex) const = 0; + virtual uint16_t attributeByteCount(uint32_t triangleIndex) const = 0; }; class FOUG_STL_EXPORT Io : public IoBase diff --git a/src/c++/streams/qt4_stream.cpp b/src/c++/streams/qt4_stream.cpp index 862363e..ad40d81 100644 --- a/src/c++/streams/qt4_stream.cpp +++ b/src/c++/streams/qt4_stream.cpp @@ -30,17 +30,17 @@ bool Qt4Stream::isSequential() const return m_device != 0 ? m_device->isSequential() : false; } -bool Qt4Stream::seek(Int64 pos) +bool Qt4Stream::seek(int64_t pos) { return m_device->seek(pos); } -Int64 Qt4Stream::read(char *data, Int64 maxSize) +int64_t Qt4Stream::read(char *data, int64_t maxSize) { return m_device->read(data, maxSize); } -Int64 Qt4Stream::write(const char *data, Int64 maxSize) +int64_t Qt4Stream::write(const char *data, int64_t maxSize) { return m_device->write(data, maxSize); } diff --git a/src/c++/streams/qt4_stream.h b/src/c++/streams/qt4_stream.h index d54129d..2eb5257 100644 --- a/src/c++/streams/qt4_stream.h +++ b/src/c++/streams/qt4_stream.h @@ -17,9 +17,9 @@ public: bool isReadable() const; bool isSequential() const; - bool seek(foug::Int64 pos); - Int64 read(char* data, Int64 maxSize); - Int64 write(const char* data, Int64 maxSize); + bool seek(int64_t pos); + int64_t read(char* data, int64_t maxSize); + int64_t write(const char* data, int64_t maxSize); private: QIODevice* m_device;