diff --git a/ChangeLog b/ChangeLog index 08321def23cbfb87d76a9fcf217b58aa5d75fcf2..b1f1173a009d8f390a12baf6f148fa9cdca8ce18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-08-28 bulgarelli + + * include/ByteStream.h (ByteStream): renamed swap() in swapWord() + * include/ByteStream.h (ByteStream): void swapWordIfStreamIsLittleEndian(); + * include/ByteStream.h (ByteStream): void swapWordIfStreamIsBigEndian(); + 25 July 2003 v2.0.3 on git @@ -63,11 +69,11 @@ TAG CVS: PACKETLIB_1_3_9 7 December 2005 TAG CVS: PACKETLIB_1_3_8 -+ added the management of number of blocks *2 per rblocks in the SDFRBBlock (symbol * in the line of sub from nblocks) ++ added the management of number of blocks *2 per rblocks in the SDFRBBlock (symbol '*' in the line of sub from nblocks) 21 October 2005 TAG CVS: PACKETLIB_1_3_7 -+ added the management of number of blocks /2 per rblocks in the SDFRBBlock (symbol / in the line of sub from nblocks) ++ added the management of number of blocks /2 per rblocks in the SDFRBBlock (symbol '/' in the line of sub from nblocks) + added include 24 August 2005 @@ -256,3 +262,4 @@ socket 9 Maggio 2002 Prima versione 1.0.4. Tag CVS: START + diff --git a/Makefile b/Makefile index 6f946bf7a1b3b765431b0935816d133a64649e35..5692e3316d642dddcacca6a730e1312065e621e5 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ CC = gcc CXX = g++ #Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user #- g3 -CFLAGS = -O2 -O0 -m64 -fPIC -g +CFLAGS = -O2 -O0 -m64 -fPIC #-O2 -O0 -g3 #Set INCPATH to add the inclusion paths INCPATH = -I ./include diff --git a/include/ByteStream.h b/include/ByteStream.h index 078698fd83a9bf54640a1fa58a465c9b1ed28a84..294c0a3f18bf070b471917f640c6c36444137edf 100644 --- a/include/ByteStream.h +++ b/include/ByteStream.h @@ -106,8 +106,14 @@ public: bool isBigendian() const; - /// Swap of the stream if the architecture is little endian - void swap(); + /// Swap the stream if it is little endian (for big endian architectures, e.g. Motorola) + void swapWordIfStreamIsLittleEndian(); + + /// Swap the stream if it is big endian (for little endian architectures, e.g. Intel) + void swapWordIfStreamIsBigEndian(); + + /// Swap the stream of words + void swapWord(); /// Pointer to the stream byte* stream; diff --git a/src/ByteStream.cpp b/src/ByteStream.cpp index 6b4e117784427b266c2fdaa2b1cf1c06f73e628f..a979098cc6874aa28d912f8a5bca5384e2434b43 100644 --- a/src/ByteStream.cpp +++ b/src/ByteStream.cpp @@ -69,7 +69,7 @@ PacketLib::ByteStream::ByteStream(byte* stream, dword dim, bool bigendian, bool this->stream = stream; this->bigendian = bigendian; if(!memory_sharing) - swap(); + swapWordIfStreamIsLittleEndian(); /// \remarks memory_sharing == false means that the object is responsible for the memory setMemoryAllocated(!memory_sharing); mem_allocation_constructor = false; @@ -234,7 +234,7 @@ byte* PacketLib::ByteStream::getStream() byte* PacketLib::ByteStream::getOutputStream() { - swap(); + swapWordIfStreamIsLittleEndian(); return stream; } @@ -242,7 +242,7 @@ byte* PacketLib::ByteStream::getOutputStream() void PacketLib::ByteStream::endOutputStream() { - swap(); + swapWordIfStreamIsLittleEndian(); } @@ -267,7 +267,7 @@ void PacketLib::ByteStream::setStreamCopy(byte* b, dword dim) stream = (byte*) new byte[dim]; for(dword i=0; ibigendian = bigendian; this->stream = b; - if(!memory_sharing) swap(); + if(!memory_sharing) swapWordIfStreamIsLittleEndian(); setMemoryAllocated(!memory_sharing); return true; } @@ -358,21 +358,19 @@ bool PacketLib::ByteStream::setWord(dword start, word value) } -void PacketLib::ByteStream::swap() +void PacketLib::ByteStream::swapWordIfStreamIsLittleEndian() { if(!bigendian) { - dword dim = byteInTheStream; - for(dword i = 0; i< dim; i+=2) - { - /// For odd dimensions - if((dim - i) != 1) - { - byte btemp = stream[i]; - stream[i] = stream[i+1]; - stream[i+1] = btemp; - } - } + swapWord(); + } +} + +void PacketLib::ByteStream::swapWordIfStreamIsBigEndian() +{ + if(bigendian) + { + swapWord(); } } @@ -422,3 +420,17 @@ void PacketLib::ByteStream::deleteStreamMemory() if(!mem_allocation_constructor && mem_allocation) delete[] stream; } + +void PacketLib::ByteStream::swapWord() { + dword dim = byteInTheStream; + for(dword i = 0; i< dim; i+=2) + { + /// For odd dimensions + if((dim - i) != 1) + { + byte btemp = stream[i]; + stream[i] = stream[i+1]; + stream[i+1] = btemp; + } + } +}