Nebula
Loading...
Searching...
No Matches
binarywriter.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
15#include "io/streamwriter.h"
16#include "util/blob.h"
17#include "util/guid.h"
18#include "system/byteorder.h"
19#if !__OSX__
20#include "math/vec2.h"
21#endif
22
23//------------------------------------------------------------------------------
24namespace IO
25{
27{
29public:
33 virtual ~BinaryWriter();
35 void SetMemoryMappingEnabled(bool b);
37 bool IsMemoryMappingEnabled() const;
43 virtual bool Open();
45 virtual void Close();
47 void WriteChar(char c);
49 void WriteUChar(unsigned char c);
51 void WriteShort(short s);
53 void WriteUShort(unsigned short s);
55 void WriteInt(int i);
57 void WriteUInt(unsigned int i);
59 void WriteInt64(int64_t i);
61 void WriteUInt64(uint64_t i);
63 void WriteFloat(float f);
65 void WriteFloatAsNormalizedUByte2(float f);
69 void WriteDouble(double d);
71 void WriteBool(bool b);
73 void WriteString(const Util::String& s);
74 #if !__OSX__
76 void WriteVec2(Math::vec2 f);
78 void WriteVec3(const Math::vec3& v);
80 void WriteVec4(const Math::vec4& v);
82 void WriteMat4(const Math::mat4& m);
83 #endif
85 void WriteFloatArray(const Util::Array<float>& arr);
87 void WriteIntArray(const Util::Array<int>& arr);
89 void WriteUIntArray(const Util::Array<uint>& arr);
91 void WriteBoolArray(const Util::Array<bool>& arr);
93 void WriteGuid(const Util::Guid& guid);
95 void WriteBlob(const Util::Blob& blob);
97 void WriteRawData(const void* ptr, SizeT numBytes);
98
99public:
103 unsigned char* mapCursor;
104 unsigned char* mapEnd;
105};
106
107//------------------------------------------------------------------------------
110inline
111void
116
117//------------------------------------------------------------------------------
120inline
121bool
123{
124 return this->enableMapping;
125}
126
127//------------------------------------------------------------------------------
130inline void
135
136//------------------------------------------------------------------------------
141{
142 return this->byteOrder.GetToByteOrder();
143}
144
145} // namespace IO
146//------------------------------------------------------------------------------
A friendly interface for writing binary data to a stream.
Definition binarywriter.h:27
void WriteMat4(const Math::mat4 &m)
write a mat4 to the stream
Definition binarywriter.cc:442
bool isMapped
Definition binarywriter.h:101
void WriteGuid(const Util::Guid &guid)
write a guid
Definition binarywriter.cc:363
virtual bool Open()
begin reading from the stream
Definition binarywriter.cc:47
void WriteUInt64(uint64_t i)
write an 64-bit unsigned int to the stream
Definition binarywriter.cc:218
void WriteFloat(float f)
write a float value to the stream
Definition binarywriter.cc:238
void WriteDouble(double d)
write a double value to the stream
Definition binarywriter.cc:280
System::ByteOrder::Type GetStreamByteOrder() const
get the stream byte order
Definition binarywriter.h:140
void WriteBool(bool b)
write a boolean value to the stream
Definition binarywriter.cc:300
virtual ~BinaryWriter()
destructor
Definition binarywriter.cc:35
void WriteChar(char c)
write an 8-bit char to the stream
Definition binarywriter.cc:84
void WriteFloatArray(const Util::Array< float > &arr)
write a float array to the stream
Definition binarywriter.cc:464
virtual void Close()
end reading from the stream
Definition binarywriter.cc:72
BinaryWriter()
constructor
Definition binarywriter.cc:23
void WriteIntArray(const Util::Array< int > &arr)
write a int array to the stream
Definition binarywriter.cc:496
void WriteUChar(unsigned char c)
write an 8-bit unsigned char to the stream
Definition binarywriter.cc:101
void SetMemoryMappingEnabled(bool b)
call before Open() to enable memory mapping (if stream supports mapping)
Definition binarywriter.h:112
System::ByteOrder byteOrder
Definition binarywriter.h:102
unsigned char * mapEnd
Definition binarywriter.h:104
void SetStreamByteOrder(System::ByteOrder::Type byteOrder)
set the stream byte order (default is host byte order)
Definition binarywriter.h:131
void WriteUInt(unsigned int i)
write an 32-bit unsigned int to the stream
Definition binarywriter.cc:178
void WriteBoolArray(const Util::Array< bool > &arr)
write a bool array to the stream
Definition binarywriter.cc:561
bool enableMapping
Definition binarywriter.h:100
__DeclareClass(BinaryWriter)
void WriteVec3(const Math::vec3 &v)
write a vec4 to the stream
Definition binarywriter.cc:397
void WriteInt64(int64_t i)
write an 64-bit signed int to the stream
Definition binarywriter.cc:198
void WriteUShort(unsigned short s)
write an 16-bit unsigned short to the stream
Definition binarywriter.cc:138
void WriteShort(short s)
write an 16-bit short to the stream
Definition binarywriter.cc:118
void WriteVec4(const Math::vec4 &v)
write a vec4 to the stream
Definition binarywriter.cc:421
void WriteUIntArray(const Util::Array< uint > &arr)
write a unsigned int array to the stream
Definition binarywriter.cc:528
void WriteFloatAsNormalizedUByte2(float f)
write a compressed float value to the stream, lossy and needed to be in the range of -1....
Definition binarywriter.cc:258
void WriteRawData(const void *ptr, SizeT numBytes)
write raw data
Definition binarywriter.cc:593
void WriteString(const Util::String &s)
write a string to the stream
Definition binarywriter.cc:321
void WriteVec2(Math::vec2 f)
write a float value to the stream
Definition binarywriter.cc:376
void WriteFloatAsUnsignedNormalizedUByte2(float f)
write a compressed float value to the stream, lossy and needed to be in the range of 0....
Definition binarywriter.cc:269
void WriteBlob(const Util::Blob &blob)
write a blob of data
Definition binarywriter.cc:344
void WriteInt(int i)
write an 32-bit int to the stream
Definition binarywriter.cc:158
unsigned char * mapCursor
Definition binarywriter.h:103
bool IsMemoryMappingEnabled() const
return true if memory mapping is enabled
Definition binarywriter.h:122
Stream writer classes provide a specialized write-interface for a stream.
Definition streamwriter.h:22
Provides information and methods to help with byte ordering issues.
Definition darwinbyteorder.h:18
Type GetToByteOrder() const
get to-byte-order
Definition byteorder.h:140
Type
Definition byteorder.h:37
void SetToByteOrder(Type toByteOrder)
set to-byte-order
Definition byteorder.h:131
Nebula's dynamic array class.
Definition array.h:60
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
Implements a GUID.
Instances of wrapped stream classes.
Definition orientation.cc:10
A 4x4 single point precision float matrix.
Definition mat4.h:47
A 2-component float vector class.
Definition vec2.h:21
A 3D vector.
Definition vec3.h:39
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
int SizeT
Definition types.h:49