string functions::asString(const unsigned long number)
throw() {
- return asString((Unsigned64)number);
+ return asString((U64)number);
}
-string functions::asString(const Integer64 number)
+string functions::asString(const S64 number)
throw() {
char aux [24];
sprintf(aux, "%lld", number);
return string(aux);
}
-string functions::asString(const Unsigned64 number)
+string functions::asString(const U64 number)
throw() {
char aux [16];
sprintf(aux, "%llu", number);
string functions::asHexString(const long number)
throw() {
- return asHexString((Integer64)number);
+ return asHexString((S64)number);
}
-string functions::asHexString(const Integer64 number)
+string functions::asHexString(const S64 number)
throw() {
char aux [32];
sprintf(aux, "0x%llx", number);
// from a version by Allen Holub (see Andrew Binstock, "Hashing Revisited"
// Dr. Dobb's Journal, April 1996)
-Integer64 functions::hash(const char* p)
+S64 functions::hash(const char* p)
throw() {
- static const int long_bits = sizeof(Integer64) << 3;
+ static const int long_bits = sizeof(S64) << 3;
static const int one_eighth = long_bits >> 3;
static const int three_fourths = long_bits * 3 / 4;
- static const Integer64 high_bits = ((Integer64)(~0L)) << (long_bits - one_eighth);
- Integer64 result = 0;
- Integer64 temp;
+ static const S64 high_bits = ((S64)(~0L)) << (long_bits - one_eighth);
+ S64 result = 0;
+ S64 temp;
while(*p != 0) {
result = (result << one_eighth) + *p ++;
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
-Integer64 functions::asInteger64(const char* str)
+S64 functions::asInteger64(const char* str)
throw() {
- Integer64 number = 0;
+ S64 number = 0;
sscanf(str, "%lld", &number);
/*
#ifdef __anna64__
}
/*static*/
-Integer64 functions::merge(const char* whatis, const int n1, const int n2, const int bitShift)
+S64 functions::merge(const char* whatis, const int n1, const int n2, const int bitShift)
throw(RuntimeException) {
if(bitShift > intBitSize) {
string msg(functions::asString("%s | N1: 0x%x | N2: 0x%x | bitShift: %d | bitShift must be less than %d", whatis, n1, n2, bitShift, intBitSize));
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
- Integer64 result = n1;
+ S64 result = n1;
result <<= bitShift;
result |= n2;
return result;
}
+bool functions::littleEndian()
+throw() {
+ int i = 1;
+ char *p = (char *) &i;
+ if (p[0] == 1) return true;
+ return false;
+}
+
+const char* functions::codeInteger(char* result, const int n)
+throw() {
+ int aux(htonl(n));
+ register char* w((char*) &aux);
+ *result = *w;
+ *(result + 1) = *(w + 1);
+ *(result + 2) = *(w + 2);
+ *(result + 3) = *(w + 3);
+ return result;
+}
+
+const char* functions::codeShort(char* result, const short int n)
+throw() {
+ short int aux(htons(n));
+ register char* w((char*) &aux);
+ *result = *w;
+ *(result + 1) = *(w + 1);
+ return result;
+}
+
+const char* functions::codeInteger64(char* result, const S64 n)
+throw() {
+ S64 aux(0xffffffff);
+ int n2;
+ aux <<= 32;
+ aux &= n;
+ n2 = (aux >> 32) & 0xffffffff;
+ codeInteger(result, n2);
+ n2 = n & 0xffffffff;
+ codeInteger(result + sizeof(int), n2);
+ return result;
+}
+
+/*static*/
+const char* functions::codeFloat(char* result, const float n)
+throw() {
+ int ii;
+ anna_memcpy(&ii, &n, sizeof(n));
+ return functions::codeInteger(result, ii);
+}
+
+/*static*/
+const char* functions::codeDouble(char* result, const double n)
+throw() {
+ S64 ii;
+ anna_memcpy(&ii, &n, sizeof(n));
+ return functions::codeInteger64(result, ii);
+}
+
+int functions::decodeInteger(const char* data)
+throw() {
+ int result;
+ register char* w((char*) &result);
+ *w = *data;
+ *(w + 1) = *(data + 1);
+ *(w + 2) = *(data + 2);
+ *(w + 3) = *(data + 3);
+ return ntohl(result);
+}
+
+short int functions::decodeShort(const char* data)
+throw() {
+ short int result;
+ register char* w((char*) &result);
+ *w = *data;
+ *(w + 1) = *(data + 1);
+ return ntohs(result);
+}
+
+S64 functions::decodeInteger64(const char* data)
+throw() {
+ S64 result(decodeInteger(data));
+ result <<= 32;
+ return result |= (decodeInteger(data + sizeof(int)) & 0xffffffff);
+}
+
+/*static*/
+float functions::decodeFloat(const char* data)
+throw() {
+ float result;
+ int ii = functions::decodeInteger(data);
+ anna_memcpy(&result, &ii, sizeof(result));
+ return result;
+}
+
+/*static*/
+double functions::decodeDouble(const char* data)
+throw() {
+ double result;
+ S64 ii = functions::decodeInteger64(data);
+ anna_memcpy(&result, &ii, sizeof(result));
+ return result;
+}
+
+
void functions::decodeIsupNumber(const char *buffer, int length, isup_number_t & isupNumber, bool calledOrCalling) throw(anna::RuntimeException) {
#define DECODE2BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 8) & 0xFF00) + ((value_type)buffer[indx+1] & 0x00FF))