| 1 |
#include "../System/SystemDefine.h"
|
| 2 |
#include "BinaryTools.h"
|
| 3 |
|
| 4 |
|
| 5 |
BinaryTools::BinaryTools(){}
|
| 6 |
BinaryTools::~BinaryTools(){}
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 11 |
//compare two Strings against each other, without the null in the end of the Strings
|
| 12 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 13 |
|
| 14 |
bool BinaryTools::compareIntArray(int *source, int *source2, int sizeSource, int size2Source)
|
| 15 |
{
|
| 16 |
bool statement=true;
|
| 17 |
|
| 18 |
if( sizeSource == size2Source )
|
| 19 |
{
|
| 20 |
for ( int s=0; s<sizeSource ; s++ )
|
| 21 |
{
|
| 22 |
if ( source[s] != source2[s] )
|
| 23 |
{
|
| 24 |
statement=false;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
}
|
| 28 |
else
|
| 29 |
{
|
| 30 |
statement=false;
|
| 31 |
}
|
| 32 |
|
| 33 |
return statement;
|
| 34 |
}
|
| 35 |
|
| 36 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 37 |
//copy a String to another destination includes the null in the of the String
|
| 38 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 39 |
|
| 40 |
void BinaryTools::copyIntArray(char *source, char *dest, int sourceSize)
|
| 41 |
{
|
| 42 |
for ( int s=0; s<sourceSize ; s++ )
|
| 43 |
{
|
| 44 |
dest[s]=source[s];
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 49 |
//add two Strings together and returns a new String
|
| 50 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 51 |
|
| 52 |
int *BinaryTools::addIntArrayToIntArray(int *source, int *source2, int sourceSize, int source2Size)
|
| 53 |
{
|
| 54 |
int forward=0;
|
| 55 |
|
| 56 |
int *buffer=(int*)malloc((sourceSize+source2Size)*sizeof(int));
|
| 57 |
|
| 58 |
for ( int s=0 ; s<sourceSize ; s++ )
|
| 59 |
{
|
| 60 |
buffer[forward]=source[s];
|
| 61 |
forward++;
|
| 62 |
}
|
| 63 |
|
| 64 |
for ( int s2=0 ; s2<source2Size ; s2++ )
|
| 65 |
{
|
| 66 |
buffer[forward]=source2[s2];
|
| 67 |
forward++;
|
| 68 |
}
|
| 69 |
|
| 70 |
return buffer;
|
| 71 |
}
|
| 72 |
|
| 73 |
|
| 74 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 75 |
//
|
| 76 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 77 |
|
| 78 |
int *BinaryTools::addIntValueToArray(int *source, int sourceSize, int value)
|
| 79 |
{
|
| 80 |
int forward=0;
|
| 81 |
|
| 82 |
int *buffer=(int*)malloc(sourceSize+sizeof(int)+sizeof(int));
|
| 83 |
|
| 84 |
for ( int s=0 ; s<sourceSize ; s++ )
|
| 85 |
{
|
| 86 |
buffer[forward]=source[s];
|
| 87 |
forward++;
|
| 88 |
}
|
| 89 |
|
| 90 |
buffer[forward]=value;
|
| 91 |
|
| 92 |
|
| 93 |
return buffer;
|
| 94 |
}
|
| 95 |
|
| 96 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 97 |
//
|
| 98 |
//////////////////////////////////////////////////////////////////////////////////////
|
| 99 |
|
| 100 |
float *BinaryTools::addFloatValueToArray(float *source, int sourceSize, float value)
|
| 101 |
{
|
| 102 |
int forward=0;
|
| 103 |
|
| 104 |
float *buffer=(float*)malloc(sourceSize+sizeof(float)+sizeof(float));
|
| 105 |
|
| 106 |
for ( int s=0 ; s<sourceSize ; s++ )
|
| 107 |
{
|
| 108 |
buffer[forward]=source[s];
|
| 109 |
forward++;
|
| 110 |
}
|
| 111 |
|
| 112 |
buffer[forward]=value;
|
| 113 |
|
| 114 |
|
| 115 |
return buffer;
|
| 116 |
}
|