forked from KengoSawa2/RapidCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmisc.h
151 lines (124 loc) · 4.07 KB
/
tmisc.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
143
144
145
146
147
148
149
150
151
/* @(#)Copyright (C) 1996-2011 H.Shirouzu tlib.h Ver0.99 */
/* ========================================================================
Project Name : Win32 Lightweight Class Library Test
Module Name : Main Header
Create : 1996-06-01(Sat)
Update : 2011-05-23(Mon)
port update : 2016-02-28
Copyright : H.Shirouzu, Kengo Sawatsu
Reference :
======================================================================== */
#ifndef TLIBMISC_H
#define TLIBMISC_H
#include <sys/types.h>
#include "osl.h"
#include <QString>
#include <QHash>
#include <QThread>
#include <QMutex>
class THashTbl;
class THashObj {
public:
THashObj *priorHash;
THashObj *nextHash;
u_int hashId;
public:
THashObj() { priorHash = nextHash = NULL; hashId = 0; }
virtual ~THashObj() { if (priorHash && priorHash != this) UnlinkHash(); }
virtual bool LinkHash(THashObj *top);
virtual bool UnlinkHash();
friend class THashTbl;
};
class THashTbl {
protected:
THashObj *hashTbl;
int hashNum;
int registerNum;
bool isDeleteObj;
virtual bool IsSameVal(THashObj *, const void *val) = 0;
public:
THashTbl(int _hashNum=0, bool _isDeleteObj=true);
virtual ~THashTbl();
virtual bool Init(int _hashNum);
virtual void UnInit();
virtual void Register(THashObj *obj, u_int hash_id);
virtual void UnRegister(THashObj *obj);
virtual THashObj *Search(const void *data, u_int hash_id);
virtual int GetRegisterNum() { return registerNum; }
// virtual u_int MakeHashId(const void *data) = 0;
};
struct TResHashObj : THashObj {
void *val;
TResHashObj(UINT _resId, void *_val) { hashId = _resId; val = _val; }
~TResHashObj() { free(val); }
};
class TResHash : public THashTbl {
protected:
virtual bool IsSameVal(THashObj *obj, const void *val) {
return obj->hashId == *(u_int *)val;
}
public:
TResHash(int _hashNum) : THashTbl(_hashNum) {}
TResHashObj *Search(UINT resId) { return (TResHashObj *)THashTbl::Search(&resId, resId); }
void Register(TResHashObj *obj) { THashTbl::Register(obj, obj->hashId); }
};
class Condition {
protected:
enum WaitEvent { CLEAR_EVENT=0, DONE_EVENT, WAIT_EVENT };
QMutex cs;
QMutex *hEvents;
WaitEvent *waitEvents;
int max_threads;
int waitCnt;
public:
Condition(void);
~Condition();
bool Initialize(int _max_threads);
void UnInitialize(void);
void Lock(void) { cs.lock();}
void UnLock(void) { cs.unlock();}
// ロックを取得してから利用すること
int WaitThreads() { return waitCnt; }
int IsWait() { return waitCnt ? true : FALSE; }
void DetachThread() { max_threads--; }
int MaxThreads() { return max_threads; }
bool Wait(DWORD);
void Notify(void);
};
#define PAGE_SIZE (4 * 1024)
class VBuf {
protected:
BYTE *buf;
VBuf *borrowBuf;
int size;
int usedSize;
int maxSize;
void Init();
public:
VBuf(int _size=0, int _max_size=0, VBuf *_borrowBuf=NULL);
~VBuf();
bool AllocBuf(int _size, int _max_size=0, VBuf *_borrowBuf=NULL);
bool LockBuf();
void FreeBuf();
bool Grow(int grow_size);
operator BYTE *() { return buf; }
BYTE *Buf() { return buf; }
WCHAR *WBuf() { return (WCHAR *)buf; }
int Size() { return size; }
int MaxSize() { return maxSize; }
int UsedSize() { return usedSize; }
void SetUsedSize(int _used_size) { usedSize = _used_size; }
int AddUsedSize(int _used_size) { return usedSize += _used_size; }
int RemainSize(void) { return size - usedSize; }
};
char* GetLoadStrA(UINT resId);
// WindowsのLoadString()の代替固定文字列構造体
// LoadStringをだますために使う
struct StringTable {
UINT resId;
QString str;
};
int MakePath(char *dest, const char *dir, const char *file);
WCHAR lGetCharIncA(const char **str);
int bin2hexstr(const BYTE *bindata, int len, char *buf);
#endif