Well, after reading the topic "Force stream << >> to interpret as binary"I am trying to develop a BinaryStream class (for my fun, during free time).
-> the topic was that one:
http://www.cplusplus.com/forum/general/97851/
The basic idea is simple (and probably a little dumb)... a class that can manage an already open stream in order to have a "pure" class that can have its own overloads of << and >> (the logic is similar to the QT class QDataStream).
This work probably is not hard itself, but I soonly figured that, if I want to provide a BinaryStream, possibly platform independent, you should provide manage binaries in an uniform way.
This mean... manage and check endianness and care of basic data size.
If I limit my work to "little" or "big" endian the endiannes check would be easy... (making a pre-configure-program that checks endiannes and creates a subheader file that will specify endiannes type in a #define macro)...
The big problem comes in data types, becouse I readed that you cannot be sure of the actual size for basic data (it can happen, for example, that some system "short" can have the same size of "char").
But, if I think well, when you write BINARY FILES (where endiannes and data size truely needed to check correctly to be correctly readed) I think that a byte would be always 8bit long (or I hope).
Surely... the pre-configure-program could check the actual size for all basic data types (with sizeof) but then the management could be impossible to implement for my limited skills.
Checking QT I see that QT 4.6.x simply consider int8 = char, int16=short, int32=long, int64=long long so probably I am caring of a false problem.
What do you think about? any hints?
----------------
Question 2: indirectly related to the first one.
I am thinking about also creating a sort of ByteArray class (similar to the QByteArray on qt).... is it possible to create a derived class of std::string specialized to manage char arrays but not for intendent as TEXTUAL but as BINARY (without "/0" termination).
Thank a lot