-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTAG_String.h
More file actions
49 lines (42 loc) · 806 Bytes
/
Copy pathTAG_String.h
File metadata and controls
49 lines (42 loc) · 806 Bytes
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
#pragma once
#include "ITAG.h"
class cTAG_String : public ITAG
{
private:
short size;
char *buf;
public:
cTAG_String() : ITAG(eTAG_String), size(0),buf(NULL) {}
cTAG_String(int _size, char *_buf) : ITAG(eTAG_String), size(_size)
{
buf = new char[size];
memcpy(buf,_buf,size);
}
cTAG_String(const char *_buf) : ITAG(eTAG_String)
{
size = strlen(_buf);
buf = new char[size];
memcpy(buf,_buf,size);
}
~cTAG_String()
{
delete[] buf;
}
void WriteStream(std::ostream &out)
{
int temp = htons(size);
out.write((char*)&temp,2);
if(buf != NULL && size != 0)
out.write(buf,size);
}
void ReadStream(std::istream &in)
{
if(buf != NULL)
delete[] buf;
in.read((char*)&size,2);
size = ntohs(size);
buf = new char[size+1];
in.read(buf,size);
buf[size] = 0;
}
};