libc++: adapt to core libc

This commit is contained in:
Hugues Delorme 2013-01-24 11:31:38 +01:00
parent 867cdc0098
commit ff8a6fe6e5
10 changed files with 55 additions and 66 deletions

View File

@ -9,7 +9,8 @@ message($$PREFIX_DIR)
TEMPLATE = lib TEMPLATE = lib
TARGET = fougstl-c++$$TARGET_SUFFIX TARGET = fougstl-c++$$TARGET_SUFFIX
DESTDIR = $$PREFIX_DIR/lib DESTDIR = $$PREFIX_DIR/lib
CONFIG *= dll
DEFINES *= FOUG_USE_STDINT_H
dll { dll {
DEFINES *= FOUG_STL_DLL FOUG_STL_MAKE_DLL DEFINES *= FOUG_STL_DLL FOUG_STL_MAKE_DLL
@ -40,13 +41,13 @@ SOURCES += \
../../../src/c++/libstl/stlb.cpp \ ../../../src/c++/libstl/stlb.cpp \
../../../src/c++/libstl/stla.cpp ../../../src/c++/libstl/stla.cpp
global_inc.path = $$PREFIX_DIR/include global_inc.path = $$PREFIX_DIR/include/dataex
global_inc.files = ../../../src/*.h 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_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_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 cpp_libstl_inc.files = ../../../src/c++/libstl/*.h
INSTALLS += global_inc cpp_global_inc cpp_streams_inc cpp_libstl_inc INSTALLS += global_inc cpp_global_inc cpp_streams_inc cpp_libstl_inc

View File

@ -14,9 +14,9 @@ public:
virtual bool isReadable() const = 0; virtual bool isReadable() const = 0;
virtual bool isSequential() const = 0; virtual bool isSequential() const = 0;
virtual bool seek(foug::Int64 pos) = 0; virtual bool seek(int64_t pos) = 0;
virtual Int64 read(char* data, Int64 maxSize) = 0; virtual int64_t read(char* data, int64_t maxSize) = 0;
virtual Int64 write(const char* data, Int64 maxSize) = 0; virtual int64_t write(const char* data, int64_t maxSize) = 0;
}; };
} // namespace foug } // namespace foug

View File

@ -1,24 +1,12 @@
#ifndef FOUG_CPP_GLOBAL_H #ifndef FOUG_CPP_GLOBAL_H
#define FOUG_CPP_GLOBAL_H #define FOUG_CPP_GLOBAL_H
#include "../c/foug_global.h" #include "../c/global.h"
namespace foug { namespace foug {
typedef foug_int8 Int8; typedef foug_real32_t Real32;
typedef foug_uint8 UInt8; typedef foug_real64_t Real64;
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;
} // namespace foug } // namespace foug

View File

@ -30,8 +30,8 @@ typedef Triangle<Coords> Triangle;
class FOUG_STL_EXPORT AbstractGeometry class FOUG_STL_EXPORT AbstractGeometry
{ {
public: public:
virtual UInt32 triangleCount() const = 0; virtual uint32_t triangleCount() const = 0;
virtual void getTriangle(UInt32 index, Triangle* triangle) const = 0; virtual void getTriangle(uint32_t index, Triangle* triangle) const = 0;
}; };
} // namespace stl } // namespace stl

View File

@ -6,7 +6,7 @@
namespace foug { namespace foug {
namespace stla { namespace stla {
bool Io::read(AbstractGeometryBuilder* builder, Int64 streamSize) bool Io::read(AbstractGeometryBuilder* builder, int64_t streamSize)
{ {
return false; return false;
} }

View File

@ -22,7 +22,7 @@ class FOUG_STL_EXPORT Io : public IoBase
public: public:
Io(AbstractStream* stream = 0); 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); bool write(const stl::AbstractGeometry& geom, const std::string& solidName);
}; };

View File

@ -7,46 +7,46 @@
// Read tools // Read tools
template<typename NUMERIC> template<typename NUMERIC>
NUMERIC fromLittleEndian(const foug::UInt8* bytes) NUMERIC fromLittleEndian(const uint8_t* bytes)
{ {
return 0; return 0;
} }
template<> template<>
foug::UInt16 fromLittleEndian<foug::UInt16>(const foug::UInt8* bytes) uint16_t fromLittleEndian<uint16_t>(const uint8_t* bytes)
{ {
// |BB|AA| -> 0xAABB // |BB|AA| -> 0xAABB
return (bytes[1] << 8) | bytes[0]; return (bytes[1] << 8) | bytes[0];
} }
template<> template<>
foug::UInt32 fromLittleEndian<foug::UInt32>(const foug::UInt8* bytes) uint32_t fromLittleEndian<uint32_t>(const uint8_t* bytes)
{ {
// |DD|CC|BB|AA| -> 0xAABBCCDD // |DD|CC|BB|AA| -> 0xAABBCCDD
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
} }
template<> template<>
foug::Real32 fromLittleEndian<foug::Real32>(const foug::UInt8* bytes) foug::Real32 fromLittleEndian<foug::Real32>(const uint8_t* bytes)
{ {
union union
{ {
foug::UInt32 asInteger; uint32_t asInteger;
foug::Real32 asFloat; foug::Real32 asFloat;
} helper; } helper;
helper.asInteger = fromLittleEndian<foug::UInt32>(bytes); helper.asInteger = fromLittleEndian<uint32_t>(bytes);
return helper.asFloat; return helper.asFloat;
} }
// Write tools // Write tools
template<typename NUMERIC> template<typename NUMERIC>
void toLittleEndian(NUMERIC n, foug::UInt8* bytes) void toLittleEndian(NUMERIC n, uint8_t* bytes)
{ {
union { union {
NUMERIC asNumeric; NUMERIC asNumeric;
foug::UInt8 asBytes[sizeof(NUMERIC)]; uint8_t asBytes[sizeof(NUMERIC)];
} helper; } helper;
helper.asNumeric = n; helper.asNumeric = n;
// std::copy(helper.asBytes, helper.asBytes + sizeof(NUMERIC), bytes); // std::copy(helper.asBytes, helper.asBytes + sizeof(NUMERIC), bytes);
@ -59,13 +59,13 @@ namespace stlb {
static const int stlFacetSize = 50; static const int stlFacetSize = 50;
static const int stlMinFileSize = 284; 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::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(); AbstractStream* istream = this->stream();
AbstractTaskProgress* progress = this->taskProgress(); 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<char*>(buffer); char* charBuffer = reinterpret_cast<char*>(buffer);
// Read header // Read header
@ -107,9 +107,9 @@ bool Io::read(AbstractGeometryBuilder* builder)
builder->processHeader(headerData); builder->processHeader(headerData);
// Read facet count // Read facet count
if (istream->read(charBuffer, sizeof(UInt32)) != sizeof(UInt32)) if (istream->read(charBuffer, sizeof(uint32_t)) != sizeof(uint32_t))
return false; return false;
const UInt32 facetCount = ::fromLittleEndian<UInt32>(buffer); const uint32_t facetCount = ::fromLittleEndian<uint32_t>(buffer);
builder->beginTriangles(facetCount); builder->beginTriangles(facetCount);
if (progress != 0) { if (progress != 0) {
@ -118,16 +118,16 @@ bool Io::read(AbstractGeometryBuilder* builder)
} }
// Read triangles // Read triangles
const UInt64 totalFacetSize = stlTriangleDataSize * facetCount; const uint64_t totalFacetSize = stlTriangleDataSize * facetCount;
UInt64 amountReadSize = 0; uint64_t amountReadSize = 0;
stl::Triangle triangle; stl::Triangle triangle;
bool streamError = false; bool streamError = false;
while (amountReadSize < totalFacetSize && !streamError) { 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)) { if (iReadSize > 0 && (iReadSize % stlTriangleDataSize == 0)) {
const UInt32 iFacetCount = iReadSize / stlTriangleDataSize; const uint32_t iFacetCount = iReadSize / stlTriangleDataSize;
UInt32 bufferOffset = 0; uint32_t bufferOffset = 0;
for (UInt32 i = 0; i < iFacetCount; ++i) { for (uint32_t i = 0; i < iFacetCount; ++i) {
// Read normal // Read normal
triangle.normal.x = ::fromLittleEndian<Real32>(buffer + bufferOffset); triangle.normal.x = ::fromLittleEndian<Real32>(buffer + bufferOffset);
triangle.normal.y = ::fromLittleEndian<Real32>(buffer + 1*sizeof(Real32) + bufferOffset); triangle.normal.y = ::fromLittleEndian<Real32>(buffer + 1*sizeof(Real32) + bufferOffset);
@ -149,8 +149,8 @@ bool Io::read(AbstractGeometryBuilder* builder)
triangle.v3.z = ::fromLittleEndian<Real32>(buffer + 11*sizeof(Real32) + bufferOffset); triangle.v3.z = ::fromLittleEndian<Real32>(buffer + 11*sizeof(Real32) + bufferOffset);
// Attribute byte count // Attribute byte count
const UInt16 attributeByteCount = const uint16_t attributeByteCount =
::fromLittleEndian<UInt16>(buffer + 12*sizeof(Real32) + bufferOffset); ::fromLittleEndian<uint16_t>(buffer + 12*sizeof(Real32) + bufferOffset);
// Add triangle // Add triangle
builder->processNextTriangle(triangle, attributeByteCount); builder->processNextTriangle(triangle, attributeByteCount);
@ -189,7 +189,7 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat
AbstractStream* ostream = this->stream(); AbstractStream* ostream = this->stream();
AbstractTaskProgress* progress = this->taskProgress(); AbstractTaskProgress* progress = this->taskProgress();
UInt8 buffer[128]; uint8_t buffer[128];
// Write header // Write header
Header headerData; Header headerData;
@ -202,9 +202,9 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat
return false; return false;
// Write facet count // Write facet count
const UInt32 facetCount = geom.triangleCount(); const uint32_t facetCount = geom.triangleCount();
::toLittleEndian<UInt32>(facetCount, buffer); ::toLittleEndian<uint32_t>(facetCount, buffer);
if (ostream->write(reinterpret_cast<char*>(&buffer), sizeof(UInt32)) != sizeof(UInt32)) if (ostream->write(reinterpret_cast<char*>(&buffer), sizeof(uint32_t)) != sizeof(uint32_t))
return false; return false;
if (progress != 0) { if (progress != 0) {
@ -214,7 +214,7 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat
// Write triangles // Write triangles
stl::Triangle triangle; stl::Triangle triangle;
for (UInt32 facet = 0; facet < facetCount; ++facet) { for (uint32_t facet = 0; facet < facetCount; ++facet) {
geom.getTriangle(facet, &triangle); geom.getTriangle(facet, &triangle);
// Write normal // Write normal
@ -238,8 +238,8 @@ bool Io::write(const stl::AbstractGeometry& geom, const AbstractGeometryExtraDat
::toLittleEndian<Real32>(triangle.v3.z, buffer + 11*sizeof(Real32)); ::toLittleEndian<Real32>(triangle.v3.z, buffer + 11*sizeof(Real32));
// Attribute byte count // Attribute byte count
const UInt16 attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0; const uint16_t attrByteCount = extraData != 0 ? extraData->attributeByteCount(facet) : 0;
::toLittleEndian<UInt16>(attrByteCount, buffer + 12*sizeof(Real32)); ::toLittleEndian<uint16_t>(attrByteCount, buffer + 12*sizeof(Real32));
// Write to stream // Write to stream
if (ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize) if (ostream->write(reinterpret_cast<const char*>(buffer), stlTriangleDataSize)

View File

@ -10,14 +10,14 @@ namespace foug {
namespace stlb { namespace stlb {
enum { HeaderSize = 80 }; enum { HeaderSize = 80 };
typedef UInt8 Header[HeaderSize]; typedef uint8_t Header[HeaderSize];
class FOUG_STL_EXPORT AbstractGeometryBuilder class FOUG_STL_EXPORT AbstractGeometryBuilder
{ {
public: public:
virtual void processHeader(const Header& data); virtual void processHeader(const Header& data);
virtual void beginTriangles(UInt32 count); virtual void beginTriangles(uint32_t count);
virtual void processNextTriangle(const stl::Triangle& triangle, UInt16 attributeByteCount) = 0; virtual void processNextTriangle(const stl::Triangle& triangle, uint16_t attributeByteCount) = 0;
virtual void endTriangles(); virtual void endTriangles();
}; };
@ -25,7 +25,7 @@ class FOUG_STL_EXPORT AbstractGeometryExtraData
{ {
public: public:
virtual void getHeader(Header& data) const = 0; 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 class FOUG_STL_EXPORT Io : public IoBase

View File

@ -30,17 +30,17 @@ bool Qt4Stream::isSequential() const
return m_device != 0 ? m_device->isSequential() : false; return m_device != 0 ? m_device->isSequential() : false;
} }
bool Qt4Stream::seek(Int64 pos) bool Qt4Stream::seek(int64_t pos)
{ {
return m_device->seek(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); 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); return m_device->write(data, maxSize);
} }

View File

@ -17,9 +17,9 @@ public:
bool isReadable() const; bool isReadable() const;
bool isSequential() const; bool isSequential() const;
bool seek(foug::Int64 pos); bool seek(int64_t pos);
Int64 read(char* data, Int64 maxSize); int64_t read(char* data, int64_t maxSize);
Int64 write(const char* data, Int64 maxSize); int64_t write(const char* data, int64_t maxSize);
private: private:
QIODevice* m_device; QIODevice* m_device;