-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclUTF.h
142 lines (135 loc) · 5.17 KB
/
clUTF.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
//--------------------------------------------------
// インクルード
//--------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdio.h>
//--------------------------------------------------
// UTFクラス
//--------------------------------------------------
class clUTF{
public:
class clElement{
public:
enum TYPE{
TYPE_NULL, // 空要素
TYPE_CHAR, // char
TYPE_UCHAR, // unsigned char
TYPE_SHORT, // short
TYPE_USHORT, // unsigned short
TYPE_INT, // int
TYPE_UINT, // unsigned int
TYPE_LONGLONG, // long long
TYPE_ULONGLONG, // unsigned long long
TYPE_FLOAT, // float
TYPE_STRING, // char *
TYPE_DATA, // void *
};
public:
clElement():_prev(NULL),_next(NULL),_name(NULL),_type(TYPE_NULL),_valueLongLong(0){}
bool IsNULL(void){return _type==TYPE_NULL;}
clElement *GetPrev(void){return _prev;}
clElement *GetNext(void){return _next;}
const char *GetName(void){return _name;}
TYPE GetType(void){return _type;}
char GetValueChar(void){return _valueChar;}
unsigned char GetValueUChar(void){return _valueUChar;}
short GetValueShort(void){return _valueShort;}
unsigned short GetValueUShort(void){return _valueUShort;}
int GetValueInt(void){return _valueInt;}
unsigned int GetValueUInt(void){return _valueUInt;}
long long GetValueLongLong(void){return _valueLongLong;}
unsigned long long GetValueULongLong(void){return _valueULongLong;}
float GetValueFloat(void){return _valueFloat;}
char *GetValueString(void){return _valueString;}
void *GetData(void){return _valueData.data;}
unsigned int GetDataSize(void){return _valueData.size;}
void SetName(const char *name){_name=name;}
void SetValueChar(char vaule){_valueChar=vaule;_type=TYPE_CHAR;}
void SetValueUChar(unsigned char vaule){_valueUChar=vaule;_type=TYPE_UCHAR;}
void SetValueShort(short vaule){_valueShort=vaule;_type=TYPE_SHORT;}
void SetValueUShort(unsigned short vaule){_valueUShort=vaule;_type=TYPE_USHORT;}
void SetValueInt(int vaule){_valueInt=vaule;_type=TYPE_INT;}
void SetValueUInt(unsigned int vaule){_valueUInt=vaule;_type=TYPE_UINT;}
void SetValueLongLong(long long vaule){_valueLongLong=vaule;_type=TYPE_LONGLONG;}
void SetValueULongLong(unsigned long long vaule){_valueULongLong=vaule;_type=TYPE_ULONGLONG;}
void SetValueFloat(float vaule){_valueFloat=vaule;_type=TYPE_FLOAT;}
void SetValueString(char *vaule){_valueString=vaule;_type=TYPE_STRING;}
void SetValueData(void *data,unsigned int size){_valueData.data=data;_valueData.size=size;_type=TYPE_DATA;}
private:
clElement *_prev;
clElement *_next;
const char *_name;
TYPE _type;
union{
char _valueChar;
unsigned char _valueUChar;
short _valueShort;
unsigned short _valueUShort;
int _valueInt;
unsigned int _valueUInt;
long long _valueLongLong;
unsigned long long _valueULongLong;
float _valueFloat;
char *_valueString;
struct{
void *data;
unsigned int size;
}_valueData;
};
friend clUTF;
};
public:
clUTF();
~clUTF();
// ロード
static bool CheckFile(void *data,unsigned int size);
bool LoadFile(const char *filename);
bool LoadData(void *data);
//bool SaveFile(const char *filename);
bool SaveFileINI(const char *filename,bool subUTF=false);
bool SaveFileINI(FILE *fp,bool subUTF=false,int tab=0);
void Release(void);
// 要素
clElement *Add(unsigned int pageIndex,const char *name,char value);
clElement *Add(unsigned int pageIndex,const char *name,unsigned char value);
clElement *Add(unsigned int pageIndex,const char *name,short value);
clElement *Add(unsigned int pageIndex,const char *name,unsigned short value);
clElement *Add(unsigned int pageIndex,const char *name,int value);
clElement *Add(unsigned int pageIndex,const char *name,unsigned int value);
clElement *Add(unsigned int pageIndex,const char *name,long long value);
clElement *Add(unsigned int pageIndex,const char *name,unsigned long long value);
clElement *Add(unsigned int pageIndex,const char *name,float value);
clElement *Add(unsigned int pageIndex,const char *name,char *value);
clElement *Add(unsigned int pageIndex,const char *name,void *data,unsigned int size);
// 取得
const char *GetName(void){return _name;}
unsigned int GetPageCount(void){return _pageCount;}
clElement *GetElement(unsigned int pageIndex); // ※見つからない場合、TYPE_NULLの要素が返る
clElement *GetElement(unsigned int pageIndex,const char *name); // ※見つからない場合、TYPE_NULLの要素が返る
private:
struct stHeader{
unsigned int signature;
unsigned int dataSize;
};
struct stInfo{
unsigned int valueOffset;
unsigned int stringOffset;
unsigned int dataOffset;
unsigned int nameOffset;
unsigned short elementCount;
unsigned short valueSize;
unsigned int valueCount;
};
struct stPage{
clElement *first;
clElement *last;
};
char *_string;
unsigned char *_data;
char *_name;
unsigned int _pageCount;
stPage *_page;
clElement *Add(stPage *parent,const char *name);
};