forked from KengoSawa2/RapidCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.h
107 lines (91 loc) · 3.29 KB
/
utility.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
/* static char *utility_id =
"@(#)Copyright (C) 2004-2012 H.Shirouzu utility.h Ver2.10"; */
/* ========================================================================
Project Name : Utility
Create : 2004-09-15(Wed)
Update : 2012-06-17(Sun)
port update : 2016-02-28
Copyright : H.Shirouzu, Kengo Sawatsu
Reference :
======================================================================== */
#ifndef UTILITY_H
#define UTILITY_H
#include "tlib.h"
#include "osl.h"
class PathArray : public THashTbl {
protected:
struct PathObj : THashObj {
void *path;
int len;
PathObj(const void *_path, int len=-1) { Set(_path, len); }
~PathObj() { if (path) free(path); }
BOOL Set(const void *_path, int len=-1);
};
int num;
PathObj **pathArray;
DWORD flags;
BOOL SetPath(int idx, const void *path, int len=-1);
virtual BOOL IsSameVal(THashObj *obj, const void *val) {
return lstrcmpiV(((PathObj *)obj)->path, val) == 0;
}
public:
enum { ALLOW_SAME=1, NO_REMOVE_QUOTE=2 };
PathArray(void);
PathArray(const PathArray &);
~PathArray();
void Init(void);
void SetMode(DWORD _flags) { flags = _flags; }
int RegisterMultiPath(const void *_multi_path, void *separator=UNICODE_PARAGRAPH);
int GetMultiPath(void *multi_path, int max_len, const void *separator=UNICODE_PARAGRAPH,
const void *escape_char=NULL);
int GetMultiPathLen(const void *separator=UNICODE_PARAGRAPH,
const void *escape_char=NULL);
PathArray& operator=(const PathArray& init);
void *Path(int idx) const { return idx < num ? pathArray[idx]->path : NULL; }
int Num(void) const { return num; }
BOOL RegisterPath(const void *path);
BOOL ReplacePath(int idx, void *new_path);
u_int MakeHashId(const void *data, int len=-1) {
return MakeHash(data, (len >= 0 ? len : strlenV(data)) * CHAR_LEN_V);
}
u_int MakeHashId(const PathObj *obj) { return MakeHash(obj->path, obj->len * CHAR_LEN_V); }
};
class DataList {
public:
struct Head {
Head *prior;
Head *next;
int alloc_size;
int data_size;
BYTE data[1]; // opaque
};
protected:
VBuf buf;
Head *top;
Head *end;
int num;
int grow_size;
int min_margin;
Condition cv;
public:
DataList(int size=0, int max_size=0, int _grow_size=0, VBuf *_borrowBuf=NULL, int _min_margin=65536);
~DataList();
BOOL Init(int size, int max_size, int _grow_size, VBuf *_borrowBuf=NULL, int _min_margin=65536);
void UnInit();
void Lock() { cv.Lock(); }
void UnLock() { cv.UnLock(); }
BOOL Wait(DWORD timeout=-1) { return cv.Wait(timeout); }
BOOL IsWait() { return cv.WaitThreads() ? TRUE : FALSE; }
void Notify() { cv.Notify(); }
Head *Alloc(void *data, int copy_size, int need_size);
Head *Get();
Head *Fetch(Head *prior=NULL);
void Clear();
int Num() { return num; }
int RemainSize();
int MaxSize() { return buf.MaxSize(); }
int Size() { return buf.Size(); }
int Grow(int grow_size) { return buf.Grow(grow_size); }
int MinMargin() { return min_margin; }
};
#endif