13 #ifndef G3D_BinaryOutput_h
14 #define G3D_BinaryOutput_h
20 #include <sys/types.h>
34 # pragma warning (push)
36 # pragma warning (disable : 4127)
105 m_bufferLen =
max(m_bufferLen, (
size_t)(m_pos + bytes));
106 if (m_bufferLen > m_maxBufferLen) {
129 const std::string& filename,
180 void commit(
bool flush =
true);
217 throw "Cannot resize huge files to be shorter.";
220 if (n < (
int64)m_bufferLen) {
223 if (n > (
int64)m_bufferLen) {
247 if (p > (
int64)m_bufferLen) {
252 throw "Cannot seek more than 10 MB backwards on huge files.";
340 const int pad = len - ((int)s.length() + 1);
343 for (
int i = 0; i <
pad; ++i) {
388 if (m_pos + n > (
int64)m_bufferLen) {
415 # define DECLARE_WRITER(ucase, lcase)\
416 void write##ucase(const lcase* out, int n);\
417 void write##ucase(const std::vector<lcase>& out, int n);\
418 void write##ucase(const Array<lcase>& out, int n);
431 # undef DECLARE_WRITER
438 # pragma warning (pop)
unorm8
Definition: unorm8.h:33
void setLength(int64 n)
Definition: BinaryOutput.h:213
void writeVector4(const Vector4 &v)
Definition: BinaryOutput.cpp:475
BinaryOutput()
Definition: BinaryOutput.cpp:201
void writeColor4(const Color4 &v)
Definition: BinaryOutput.cpp:496
void writeInt32(int32 i)
Definition: BinaryOutput.h:301
int8_t int8
Definition: Define.h:148
void skip(int n)
Definition: BinaryOutput.h:387
int16_t int16
Definition: g3dmath.h:165
void setEndian(G3DEndian fileEndian)
Definition: BinaryOutput.cpp:265
static void memcpy(void *dst, const void *src, size_t numBytes)
Definition: System.cpp:643
bool m_committed
Definition: BinaryOutput.h:56
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
size_t m_bufferLen
Definition: BinaryOutput.h:77
int64_t int64
Definition: Define.h:145
void writeColor3(const Color3 &v)
Definition: BinaryOutput.cpp:504
int m_beginEndBits
Definition: BinaryOutput.h:59
std::string getFilename() const
Definition: BinaryOutput.h:163
void writeString32(const char *s)
Definition: BinaryOutput.cpp:463
void setPosition(int64 p)
Definition: BinaryOutput.h:244
void compress(int level=9)
Definition: BinaryOutput.cpp:276
void writeInt64(int64 i)
Definition: BinaryOutput.h:308
void writeUInt16(uint16 u)
Definition: BinaryOutput.cpp:379
double float64
Definition: g3dmath.h:173
int8_t int8
Definition: g3dmath.h:163
#define DECLARE_WRITER(ucase, lcase)
Definition: BinaryOutput.h:415
int64 size() const
Definition: BinaryOutput.h:200
int64 position() const
Definition: BinaryOutput.h:232
void writeString(const std::string &s)
Definition: BinaryOutput.h:334
void writeInt16(int16 i)
Definition: BinaryOutput.h:295
void writeUInt8(uint8 i)
Definition: BinaryOutput.h:283
size_t m_maxBufferLen
Definition: BinaryOutput.h:80
const uint8 * getCArray() const
Definition: BinaryOutput.h:153
bool m_swapBytes
Definition: BinaryOutput.h:70
void writeString(const std::string &s, int len)
Definition: BinaryOutput.h:339
uint64_t uint64
Definition: g3dmath.h:170
void reset()
Definition: BinaryOutput.cpp:240
G3DEndian m_fileEndian
Definition: BinaryOutput.h:72
uint16_t uint16
Definition: g3dmath.h:166
bool m_ok
Definition: BinaryOutput.h:91
short Int16
Definition: bzlib_private.h:46
int64 m_pos
Definition: BinaryOutput.h:83
T max(const T &x, const T &y)
Definition: g3dmath.h:320
void writeUInt64(uint64 u)
Definition: BinaryOutput.cpp:415
void writeFloat64(float64 f)
Definition: BinaryOutput.h:322
void reserveBytesWhenOutOfMemory(size_t bytes)
Definition: BinaryOutput.cpp:145
#define debugAssert(exp)
Definition: debugAssert.h:160
float float32
Definition: g3dmath.h:172
bool operator==(const BinaryOutput &)
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
unsigned int UInt32
Definition: bzlib_private.h:45
uint64_t uint64
Definition: Define.h:149
uint16_t uint16
Definition: Define.h:151
int64 m_alreadyWritten
Definition: BinaryOutput.h:89
void endBits()
Definition: BinaryOutput.cpp:539
G3DEndian
The order in which the bytes of an integer are stored on a machine.
Definition: System.h:48
int m_bitPos
Definition: BinaryOutput.h:67
void writeBytes(const void *b, size_t count)
Definition: BinaryOutput.h:260
int64_t int64
Definition: g3dmath.h:169
void commit(bool flush=true)
Definition: BinaryOutput.cpp:322
std::string m_filename
Definition: BinaryOutput.h:54
uint8_t uint8
Definition: g3dmath.h:164
int Int32
Definition: bzlib_private.h:44
void writeBits(uint32 bitString, int numBits)
Definition: BinaryOutput.cpp:519
void reallocBuffer(size_t bytes, size_t oldBufferLen)
Definition: BinaryOutput.cpp:113
void writeStringEven(const std::string &s)
Definition: BinaryOutput.h:358
BinaryOutput & operator=(const BinaryOutput &)
Definition: BinaryOutput.h:52
int8 m_bitString
Definition: BinaryOutput.h:64
void writeVector2(const Vector2 &v)
Definition: BinaryOutput.cpp:490
~BinaryOutput()
Definition: BinaryOutput.cpp:256
int32_t int32
Definition: g3dmath.h:167
void reserveBytes(size_t bytes)
Definition: BinaryOutput.h:101
uint8_t uint8
Definition: Define.h:152
void writeFloat32(float32 f)
Definition: BinaryOutput.h:312
int16_t int16
Definition: Define.h:147
void writeUInt32(uint32 u)
Definition: BinaryOutput.cpp:395
uint32_t uint32
Definition: g3dmath.h:168
bool ok() const
Definition: BinaryOutput.cpp:271
void beginBits()
Definition: BinaryOutput.cpp:511
unsigned short UInt16
Definition: bzlib_private.h:47
G3DEndian endian() const
Definition: BinaryOutput.h:159
bool m_init
Definition: BinaryOutput.h:86
void writeVector3(const Vector3 &v)
Definition: BinaryOutput.cpp:483
void writeString32(const std::string &s)
Definition: BinaryOutput.h:370
void writeInt8(int8 i)
Definition: BinaryOutput.h:273
uint8 * m_buffer
Definition: BinaryOutput.h:74
void writeUNorm8(unorm8 i)
Definition: BinaryOutput.h:289
void writeBool8(bool b)
Definition: BinaryOutput.h:279
int64 length() const
Definition: BinaryOutput.h:196