-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.h
57 lines (51 loc) · 1.2 KB
/
convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef __CONVERTER__H_
#define __CONVERTER__H_
#include <string.h>
#include <memory.h>
#include "exeption.h"
#include <string>
using namespace std;
typedef unsigned char byte;
class IConverter
{
};
template <int countToCovert, typename Type1, typename Type2>
class LightConverter : public IConverter
{
public:
static int ConvertCharStringArrayTobyte(byte** byteArr, char **str, int cnt)
{
int countBytes = 0;
for (int i = 0; i < cnt; i++)
countBytes += strlen(str[i]);
int pos = 0;
byte* buf = new byte[countBytes];
if (!buf) ThrowException("Cant alloc memory for buf");
for (int i = 0; i < cnt; i++)
{
int len = strlen(str[i]);
memcpy(buf + pos, str[i], len);//str[i]));
pos += len;
}
*byteArr = buf;
return countBytes;
}
static int ConvertStringArrayTobyte(byte** byteArr, string *str, int cnt)
{
int countBytes = 0;
for (int i = 0; i < cnt; i++)
countBytes += str[i].length();
int pos = 0;
byte* buf = new byte[countBytes];
if (!buf) ThrowException("Cant alloc memory for buf");
for (int i = 0; i < cnt; i++)
{
int len = str[i].length();
memcpy(buf + pos, str[i].c_str(), len);//str[i]));
pos += len;
}
*byteArr = buf;
return countBytes;
}
};
#endif