[Remove] No idea why we would need these conversion routines. :S
This commit is contained in:
parent
f74878719d
commit
1244888130
@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef INCLUDED_CASSERT
|
||||
#define INCLUSED_CASSERT
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
struct ConvertBase {
|
||||
enum { charCount = sizeof(T) };
|
||||
union Values {
|
||||
unsigned char c[charCount];
|
||||
T t;
|
||||
};
|
||||
|
||||
Values value;
|
||||
|
||||
int GetSize(void) const { return charCount; }
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct ConvertFrom: private ConvertBase<T> {
|
||||
explicit ConvertFrom(const T& t) {
|
||||
this->value.t = t;
|
||||
}
|
||||
using ConvertBase<T>::GetSize;
|
||||
|
||||
unsigned char GetByte(int index) const {
|
||||
assert((index >= 0) && (index < GetSize()));
|
||||
return this->value.c[index];
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct ConvertTo: private ConvertBase<T> {
|
||||
using ConvertBase<T>::GetSize;
|
||||
|
||||
void SetByte(int index, unsigned char c) {
|
||||
assert((index >= 0) && (index < GetSize()));
|
||||
this->value.c[index] = c;
|
||||
}
|
||||
|
||||
const T& GetValue(void) const {
|
||||
return this->value.t;
|
||||
}
|
||||
};
|
||||
|
||||
typedef unsigned short uint16_t;
|
@ -1,113 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "str2int.h"
|
||||
|
||||
char convert_strbuf[16];
|
||||
|
||||
// I'm presuming 32 bit int..
|
||||
|
||||
int _last_str2int_errno = 0;
|
||||
|
||||
char* int2str(int value) {
|
||||
int tmp;
|
||||
int expv;
|
||||
int strpos = 0;
|
||||
|
||||
if(value < 0) {
|
||||
convert_strbuf[0] = '-';
|
||||
strpos++;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
for(expv = 1000000000; expv > 1; expv /= 10) {
|
||||
if((value / expv) != 0) break;
|
||||
}
|
||||
|
||||
for( ; expv > 0; expv /= 10) {
|
||||
tmp = (value/expv);
|
||||
value -= tmp * expv;
|
||||
convert_strbuf[strpos] = (char)('0' + tmp);
|
||||
strpos++;
|
||||
}
|
||||
convert_strbuf[strpos] = '\0';
|
||||
return convert_strbuf;
|
||||
}
|
||||
|
||||
// Does not check for possible overflow..
|
||||
int str2int(const char* string) {
|
||||
int i;
|
||||
int len = strlen(string);
|
||||
int value = 0;
|
||||
int exp = 1;
|
||||
|
||||
if(len > 11) {
|
||||
_last_str2int_errno = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = len - 1; i >= 0; i--) {
|
||||
if(string[i] >= '0' && string[i] <= '9') {
|
||||
value+=(string[i] - '0') * exp;
|
||||
exp *= 10;
|
||||
} else {
|
||||
if(i == 0) {
|
||||
if(string[0] == '-') {
|
||||
_last_str2int_errno = 0;
|
||||
return -value;
|
||||
}
|
||||
}
|
||||
_last_str2int_errno = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
_last_str2int_errno = 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
int str2int_errno(void) {
|
||||
return _last_str2int_errno;
|
||||
}
|
||||
|
||||
char* time2str(int secs) {
|
||||
if(secs < 0) {
|
||||
return "00:00:00";
|
||||
}
|
||||
int max_secs = 99 + 99*60 + 99*60*60;
|
||||
if(secs > max_secs) {
|
||||
secs = max_secs;
|
||||
}
|
||||
|
||||
// Fill.
|
||||
int hours = secs / 3600;
|
||||
int mins = (secs - hours * 3600) / 60;
|
||||
int sex = (secs - hours * 3600 - mins * 60);
|
||||
int timeVal[3] = {hours, mins, sex};
|
||||
|
||||
int tmp;
|
||||
int strpos = 0;
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int value = timeVal[i];
|
||||
if(value > 100) value = 99;
|
||||
|
||||
int expv = 10;
|
||||
if((value / expv) == 0) {
|
||||
expv = 1;
|
||||
// Zero padding.
|
||||
convert_strbuf[strpos] = '0';
|
||||
strpos++;
|
||||
}
|
||||
for( ; expv > 0; expv /= 10) {
|
||||
tmp = (value / expv);
|
||||
value -= tmp * expv;
|
||||
convert_strbuf[strpos] = (char)('0' + tmp);
|
||||
strpos++;
|
||||
}
|
||||
if(i < 2) {
|
||||
convert_strbuf[strpos] = ':';
|
||||
strpos++;
|
||||
}
|
||||
}
|
||||
convert_strbuf[strpos] = '\0';
|
||||
return convert_strbuf;
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
extern char* int2str(int value);
|
||||
extern int str2int(const char* string);
|
||||
extern int str2int_errno(void);
|
||||
extern char* time2str(int secs); // hh:mm::ss.
|
||||
|
Loading…
Reference in New Issue
Block a user