Commit b24abc3c authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

ByteStream swap* methods

parent cdefa544
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
2013-08-28  bulgarelli  <bulgarelli@tesp28.local>

	* 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 <unistd.h>

24 August 2005
@@ -256,3 +262,4 @@ socket
9 Maggio 2002
Prima versione 1.0.4.
Tag CVS: START
	 
+1 −1
Original line number Diff line number Diff line
@@ -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
+8 −2
Original line number Diff line number Diff line
@@ -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;
+29 −17
Original line number Diff line number Diff line
@@ -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; i<dim; i++)
        stream[i] = b[i];
    swap();
    swapWordIfStreamIsLittleEndian();
    setMemoryAllocated(true);
}

@@ -281,7 +281,7 @@ bool PacketLib::ByteStream::setStream(byte* b, dword dim, bool bigendian, bool m
    this->bigendian = 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;
		}
	}
}