Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/GikoDB.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Oct 9 15:08:43 2004 UTC (19 years, 5 months ago) by yoffy
Branch: MAIN
CVS Tags: v1_59_0_771, v1_59_0_770, v1_59_0_773, v1_59_0_772, v1_59_0_775, v1_59_0_774, v1_59_0_777, v1_59_0_776, v1_56_0_715, v1_59_0_778, v1_63_1_819, v1_57_0_737, v1_62_0_812, v1_57_0_735, v1_57_0_734, v1_57_0_733, v1_57_0_732, v1_57_0_731, v1_57_0_730, v1_50_2_606, v1_51_0_612, v1_50_0_581, v1_50_0_580, v1_50_0_587, v1_50_0_586, v1_57_0_739, v1_57_0_738, v1_59_1_765, v1_51_1_639, v1_53_0_671, v1_50_0_595, v1_60_0_788, v1_60_0_789, v1_54_0_677, v1_54_0_676, v1_50_0_572, v1_58_0_748, marged-Bb50, v1_58_0_745, v1_60_0_781, v1_60_0_782, v1_58_0_746, v1_60_0_784, v1_54_0_678, v1_60_0_786, v1_60_0_787, v1_56_0_707, v1_59_0_767, v1_56_0_705, v1_56_0_704, v1_56_0_703, v1_56_0_702, v1_56_0_701, v1_56_0_700, v1_59_1_778, v1_51_0_626, v1_57_0_723, b51, v1_52_1_658, v1_51_0_622, v1_59_0_768, v1_59_0_769, v1_50_0_598, v1_57_0_725, v1_57_0_726, v1_57_0_727, v1_57_0_720, v1_57_0_722, v1_57_1_744, v1_50_0_590, bv1_49_0_564, v1_50_0_593, v1_57_0_728, v1_57_0_729, v1_50_0_596, bv1_49_0_563, v1_52_0_646, v1_50_0_557, v1_57_0_736, v1_50_0_585, v1_51_0_611, v1_51_0_620, v1_52_0_644, v1_58_0_752, v1_58_0_750, v1_58_0_751, v1_58_0_756, v1_58_0_757, v1_58_0_754, v1_58_0_755, v1_58_0_759, v1_52_0_643, v1_57_0_719, v1_57_0_718, v1_56_0_716, v1_54_0_687, v1_56_0_710, v1_56_0_711, v1_56_1_717, v1_56_1_716, v1_51_0_634, v1_51_0_635, v1_51_0_636, v1_51_0_637, v1_54_0_688, v1_54_0_689, v1_51_0_632, v1_51_0_633, v1_50_0_603, v1_54_0_684, v1_50_0_582, v1_54_0_685, v1_53_0_664, v1_61_0_796, v1_61_0_797, v1_61_0_795, v1_52_0_647, v1_61_0_798, v1_61_0_799, v1_50_0_604, v1_51_0_638, v1_52_0_648, v1_53_0_661, v1_53_0_663, v1_53_0_662, v1_53_0_665, v1_53_0_667, v1_53_0_666, v1_53_0_669, v1_53_0_668, v1_55_0_692, v1_55_0_693, v1_55_0_696, v1_55_0_697, v1_55_0_694, v1_55_0_695, merged-remodeling, v1_50_0_577, v1_52_0_645, v1_52_0_651, v1_54_1_691, v1_52_0_650, v1_56_2_724, v1_50_0_606, v1_56_2_722, v1_50_0_588, v1_52_0_652, v1_55_1_697, v1_52_0_642, v1_52_0_654, v1_51_0_616, v1_56_0_714, v1_51_0_614, v1_51_0_615, v1_53_0_672, v1_51_0_613, v1_53_0_670, v1_63_0_818, v1_63_0_817, v1_63_0_816, v1_63_0_815, v1_51_1_640, v1_54_0_686, v1_51_0_618, v1_51_0_619, bv1_49_0_565, v1_54_0_680, v1_54_0_681, v1_62_0_805, v1_62_0_804, v1_62_0_807, v1_62_0_806, b50, v1_56_0_712, v1_62_0_803, v1_62_0_802, v1_56_0_713, v1_62_0_809, v1_50_0_574, v1_54_0_682, v1_50_0_584, v_step1, v1_56_0_721, v1_50_0_573, v1_50_0_600, v1_51_0_630, v1_50_0_571, v1_54_0_683, v1_51_0_631, v1_60_0_780, v1_60_0_779, v1_62_0_810, v1_62_0_811, v1_58_0_747, v1_60_0_783, root-of-draw, v1_50_0_576, v1_54_0_679, v1_59_2_785, marged_bRESPOPUP, v1_50_2_604, v1_50_0_578, v1_54_0_675, v1_51_0_628, v1_50_0_579, v1_51_0_617, root-of-Bb50, root-of-Bb51, v1_56_0_706, root-of-remodel, root-of-Bb53, v1_50_0_594, v1_52_1_657, v1_54_0_674, v1_52_0_660, v1_60_1_793, v1_50_0_602, v1_51_0_629, v1_54_0_690, v1_51_0_627, v1_50_0_601, v1_58_0_763, v1_58_0_762, v1_58_0_761, v1_58_0_760, v1_51_0_625, v1_62_1_813, v1_51_0_623, v1_57_2_749, v1_50_0_605, v1_57_0_742, v1_57_0_743, v1_57_0_740, v1_57_0_741, v1_52_0_655, v1_56_0_709, v1_57_0_744, v1_52_0_656, v1_56_0_708, v1_52_0_649, v1_61_0_800, v1_53_1_673, v1_50_0_599, v1_56_0_699, v1_56_0_698, v1_50_0_561, v1_51_0_624, v1_51_1_641, v1_51_0_621, v1_60_0_793, v1_60_0_792, v1_60_0_791, v1_60_0_790, v1_60_2_794, v1_61_1_801, HEAD
Branch point for: Bb57, Bb56, Bb55, Bb53, Bb52, Bb51, Bb62, Bb63, Bb60, Bb61, remodeling, Bb59, Bb58, Bb50, bRESPOPUP, bListSU, Bb54, Bdraw
File MIME type: text/x-pascal
データベースユニットの追加(作成中)。
※まだ脳内コードを吐き出しただけなので稼動経験無し

1 unit GikoDB;
2
3 (*!
4 \file GikoDB.pas
5 \brief 膂≧?????若?帥???若??/span>
6
7 $Id$
8
9
10 <h2>???若?帥???若?鴻?????若?????? 0.0d1</h2>
11 <p>
12 ??2 罨≦?????鴻?????????激?若???ф?????????
13 ?????? 1 ???潟?若???????????????潟?若?????????????c???????宴???????<br>
14 ???????ゃ?????????? (膃 1 ??????) ??????????若?????ゃ?????????????違??????????
15 </p>
16
17 <hr>
18 <h3>???<?ゃ???ゃ?<?若??lt;/h3>
19 <table border="1" style="text-align:center">
20 <tr><td><a href="#header">??????</a></td></tr>
21 <tr><td><a href="#info">?ゃ?潟?????<?若?激?с?潟?祉???激?с??lt;/a></td></tr>
22 <tr><td><a href="#cols">?????????鴻???祉???激?с??lt;/a></td></tr>
23 <tr><td><a href="#atlb">?≪???宴?若?激?с?潟???若?????祉???激?с??lt;/a></td></tr>
24 <tr><td><a href="#idex">?ゃ?潟???????鴻?祉???激?с??lt;/a></td></tr>
25 <tr><td><a href="#sect">?祉???帥?祉???激?с??lt;/a></td></tr>
26 <tr><td>??lt;/td></tr>
27 <tr><td><a href="#idex">?ゃ?潟???????鴻?祉???激?с??lt;/a></td></tr>
28 <tr><td><a href="#sect">?祉???帥?祉???激?с??lt;/a></td></tr>
29 </table>
30 <p>
31 <b>网?荀?</b><br>
32 ??FAT ???<?ゃ???激?鴻??????罔<????罕????????c????????
33 </p>
34
35 <hr>
36 <a name="header"></a>
37 <h3>??????</h3>
38 <table border="1" style="text-align:center">
39 <tr><td>?激?違??????lt;/td><td>4 byte</td></tr>
40 <tr><td>?<?吾?c?若???若?吾?с??lt;/td><td>1 byte</td></tr>
41 <tr><td>???ゃ???若???若?吾?с??lt;/td><td>1 byte</td></tr>
42 <tr><td>?????若?号?????</td><td>1 byte</td></tr>
43 <tr><td>?????吾?с?潟???潟????lt;/td><td>1 byte</td></tr>
44 </table>
45 <p>
46 <b>?激?違??????lt;/b><br>
47 ??'gkdb' ??????膤祉???????????潟???c?≪?潟?ф?主???????<br>
48 ?????????潟???c?≪?潟?с?????潟?若?????主????????????ゃ?????潟???c?≪?潟??羆冴?障????
49 </p>
50 <p>
51 <b>?<?吾?c?若???若?吾?с??lt;/b><br>
52 ?????<?ゃ???????若?????????<?吾?c?若???若?吾?с?潟??
53 </p>
54 <p>
55 <b>???ゃ???若???若?吾?с??lt;/b><br>
56 ?????<?ゃ???????若???????????ゃ???若???若?吾?с?潟??
57 </p>
58 <p>
59 <b>?????若?号?????</b><br>
60 ???????若?鴻????????ゃ?????宴??????
61 綽??????ゃ???ゃ??ぇ絨?????若?吾?с?潟??ぇ絨???????莠??с????篋???<br />
62 ??篁ヤ???????ゃ??
63 </p>
64 <table border="1">
65 <tr><td>???????????????若??lt;/td><td>0</td></tr>
66 <tr><td>?≪?????<?????若??lt;/td><td>1</td></tr>
67 <tr><td>???若?帥?????若??lt;/td><td>2</td></tr>
68 <tr><td>Release Candidate</td><td>3</td></tr>
69 <tr><td>???????ャ?若?????若??lt;/td><td>4</td></tr>
70 <tr><td>???<?ゃ???????鴻???????若??lt;/td><td>5</td></tr>
71 </table>
72 <p>
73 <b>?????吾?с?潟???潟????lt;/b><br>
74 ???????若?合??垩??????
75 </p>
76 <p>
77
78 <hr>
79 <a name="section"></a>
80 <h3>?祉???激?с??lt;/h3>
81 <table border="1" style="text-align:center">
82 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
83 <tr><td>?祉???激?с?潟?帥?ゃ??</td><td>4 chars</td></tr>
84 <tr><td>?祉???激?с?喝??絎?lt;/td><td>???</td></tr>
85 </table>
86 <p>
87 <b>?祉???激?с?潟?泣?ゃ??lt;/b><br>
88 ???祉???激?с?喝??????泣?ゃ?冴??
89 ?上?????≪?????鴻???祉???激?с?潟?泣?ゃ?冴????膊?????篋??ф????祉???激?с?潟????????
90 ?ゃ?障?????祉???激?с?潟?泣?ゃ?冴????昆?????????泣?ゃ?冴?????障??????<br>
91 ??緇?膓????祉???激?с?潟???????翫??? 0 ????????
92 </p>
93 <p>
94 <b>?祉???激?с?潟?帥?ゃ??</b><br>
95 ???祉???激?с?潟??┏蕁???茵??? 4 byte ????絖?????<br>
96 ??篏帥?????????c??腥冴???祉???激?с?潟? 0 ?????≪????????
97 </p>
98
99 <hr>
100 <a name="info"></a>
101 <h3>?ゃ?潟?????<?若?激?с?潟?祉???激?с??lt;/h3>
102 <table border="1" style="text-align:center">
103 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
104 <tr><td>'info'</td><td>4 chars</td></tr>
105 <tr><td>?祉???帥?泣?ゃ??lt;/td><td>4 byte</td></tr>
106 <tr><td>???潟?若????lt;/td><td>4 byte</td></tr>
107 </table>
108 <p>
109 <b>?祉???帥?泣?ゃ??lt;/b><br>
110 ??<a href="#sect">?祉???帥?祉???激?с??lt;/a>? 1 ?祉???帥??????? byte ?違????
111 </p>
112 <p>
113 <b>???潟?若????lt;/b><br>
114 ?????若?帥???若?劫????????潟?若???違????
115 </p>
116
117 <hr>
118 <a name="cols"></a>
119 <h3>?????????鴻???祉???激?с??lt;/h3>
120 <table border="1" style="text-align:center">
121 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
122 <tr><td>'cols'</td><td>4 chars</td></tr>
123 <tr><td>????????lt;/td><td>4 byte</td></tr>
124 <tr><td>????????0</td><td>pascal string</td></tr>
125 <tr><td>???若?帥?帥?ゃ??0</td><td>4 chars</td></tr>
126 <tr><td>??lt;/td><td></td></tr>
127 <tr><td>????????n</td><td>pascal string</td></tr>
128 <tr><td>???若?帥?帥?ゃ??n</td><td>4 chars</td></tr>
129 </table>
130 <p>
131 <b>?狗??</b><br>
132 ??茲??違???祉???激?с?潟???障?????c???菴違????篋????堺?ャ?障??????
133 </p>
134 <p>
135 <b>????????lt;/b><br>
136 ??緇?膓????????????????違??
137 </p>
138 <p>
139 <b>????????</b><br>
140 ??絎??????≪???祉?鴻????????????????????????腱違??<br>
141 ??腟?腴??障???????ゃ???????障?上??罕?膀????????????????????????絖????????c????????
142 </p>
143 <p>
144 <b>???若?帥?帥?ゃ??</b><br>
145 ???主??????????????若?帥???帥?ゃ????<br>
146 ???祉???激?с?潟?泣?ゃ?冴??????????障?丞?篋??????翫????
147 ??荅括完??札筝?????????
148 </p>
149 <p>
150 ??茫????ゃ? 1 byte 羔?莢祉??????<br>
151 ???医?ゃ??腓冴?????若?帥?帥?ゃ???????? 2 罅????医?? byte ?違??茵???????????<br>
152 ??pascal string ? 1 byte ????絖????激????????????絖?????
153 data ? 4 byte ?????若?翠?激?????????????若?帥??<br>
154 ?????????????????????????????祉???激?с?潟?泣?ゃ?冴????????
155 ???若?翠?激??腓冴???ゃ???激???????障????????????
156 ?ゃ?障????罨<?????若?帥???????????????若?翠? + 4 byte?????膊???綽?荀?????????<br>
157 ??unix time ????膊?腱???茵????? 8 byte integer ?с??UTC ????エ????????
158 </p>
159 <table border="1">
160 <tr><td>茫?????lt;/td><td>'bool'</td></tr>
161 <tr><td rowspan="4">膃?垬????贋??lt;/td><td>'si01'</td></tr>
162 <tr><td>'si02'</td></tr>
163 <tr><td>'si04'</td></tr>
164 <tr><td>'si08'</td></tr>
165 <tr><td rowspan="4">膃?埇?<???贋??lt;/td><td>'ui01'</td></tr>
166 <tr><td>'ui02'</td></tr>
167 <tr><td>'ui04'</td></tr>
168 <tr><td>'ui08'</td></tr>
169 <tr><td rowspan="2">羌???絨??lt;/td><td>'fp04'</td></tr>
170 <tr><td>'fp08'</td></tr>
171 <tr><td>pascal string</td><td>'pstr'</td></tr>
172 <tr><td>data (long string)</td><td>'data'</td></tr>
173 <tr><td>unix time</td><td>'time'</td></tr>
174 </table>
175
176 <hr>
177 <a name="atlb"></a>
178 <h3>?≪???宴?若?激?с?潟???若?????祉???激?с??lt;/h3>
179 <table border="1" style="text-align:center">
180 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
181 <tr><td>'atlb'</td><td>4 chars</td></tr>
182 <tr><td>膓?膓????若????lt;/td><td>4 byte</td></tr>
183 <tr><td>??lt;/td><td></td></tr>
184 <tr><td>膓?膓????若????lt;/td><td>4 byte</td></tr>
185 </table>
186 <p>
187 <b>网?荀?</b><br>
188 ?????????若???????ゃ?潟???????鴻??/span>
189 <a href="#sect">?祉????lt;/a>???ゃ?潟???????鴻??絲障?????c????????
190 </p>
191 <p>
192 <b>?狗??</b><br>
193 ??茲??違???祉???激?с?潟???障?????c???菴違????篋????堺?ャ?障??????
194 </p>
195 <p>
196 <b>膓?膓????若????lt;/b><br>
197 ??0 ????紮??障????膓?膓??????≪???宴?若?激?с?潟???若?????ゃ?潟???????鴻??
198 膓?膓????????翫??? 0xffffffff??
199 </p>
200
201 <hr>
202 <a name="idex"></a>
203 <h3>?純?若??羝??帥?ゃ?潟???????鴻?祉???激?с??lt;/h3>
204 <table border="1" style="text-align:center">
205 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
206 <tr><td>'idex'</td><td>4 chars</td></tr>
207 <tr><td>?????????lt;/td><td>2 byte</td></tr>
208 <tr><td>??????????lt;/td><td>2 byte</td></tr>
209 <tr><td>???若???????lt;/td><td>4 byte</td></tr>
210 <tr><td>??lt;/td><td>4 byte</td></tr>
211 <tr><td>??lt;/td><td></td></tr>
212 <tr><td>???若???????lt;/td><td>4 byte</td></tr>
213 <tr><td>??lt;/td><td>4 byte</td></tr>
214 </table>
215 <p>
216 <b>网?荀?</b><br>
217 ?????潟?若?????劫??????????с?純?若???????ゃ?潟???????鴻??<br>
218 ??絨?????????????ゃ????????????????ゃ?潟???????鴻???????????????????????
219 </p>
220 <p>
221 <b>?狗??</b><br>
222 ??茲??違???祉???激?с?潟???障?????c???菴違????篋????堺?ャ?障??????
223 </p>
224 <p>
225 <b>?????????lt;/b><br>
226 ??0 ?????違?????????????ゃ?潟???????鴻????????????????????ゃ?潟???????鴻????茵?????
227 </p>
228 <p>
229 <b>??????????lt;/b><br>
230 ???? bit ???????ゃ?潟???????鴻???≪?????????????c??篆?????????<br>
231 ???????????c???荀с??札筝?????????
232 </p>
233 <table border="1">
234 <tr><td>0bit</td><td>?純?若?????若???若??0...????, 1...????</td></tr>
235 </table>
236 <p>
237 <b>???若???????lt;/b><br>
238 ??0 ????紮??障??<a href="#atlb">?≪???宴?若?激?с?潟???若????lt;/a>???ゃ?潟???????鴻??<br>
239 </p>
240 <p>
241 <b>??lt;/b><br>
242 ?????潟?若?????主????????????ゃ??<br>
243 ?????潟?若???????ゃ???主?????????????????
244 ?ゃ?潟???????鴻?????ゃ??????????茲??????ゃ???主?????????篋?????????
245 ?ゃ??紊??眼????????????????????紊??眼???????????????????<br>
246 ??4 byte ??莇????????若?帥?帥?ゃ??????????????????激?ュ?ゃ???主???????
247 </p>
248
249 <hr>
250 <a name="sect"></a>
251 <h3>?祉???帥?祉???激?с??lt;/h3>
252 <table border="1" style="text-align:center">
253 <tr><td>?祉???激?с?潟?泣?ゃ??lt;/td><td>4 byte</td></tr>
254 <tr><td>'sect'</td><td>4 chars</td></tr>
255 <tr><td>?祉???激?с?括???lt;/td><td>4 byte</td></tr>
256 <tr><td>?祉????</td><td></td></tr>
257 <tr><td>??lt;/td><td></td></tr>
258 <tr><td>?祉????</td><td></td></tr>
259 </table>
260 <p>
261 <b>?祉???激?с?括???lt;/b><br>
262 ???祉???激?с?潟??研?潟??茘??ャ????????????垩?с????<br>
263 ???祉???帥?祉???激?с?潟??茲??違?????翫?????祉???激?с?括??垩???????????/span>
264 ?祉???睡??垩???蚊??綵????????障????
265 </p>
266 <p>
267 <b>?祉????lt;/b><br>
268 ?????????????ゃ???????主?????????
269 </p>
270 *)
271 interface
272
273 //==================================================
274 uses
275 //==================================================
276
277 Classes, SysUtils, IniFiles,
278 Windows,
279 YofUtils;
280
281
282 //==================================================
283 type
284 //==================================================
285
286 TGikoDB = class;
287
288 {!***********************************************************
289 \brief ?祉???激?с??/span>
290 ************************************************************}
291 TSection = class( TObject )
292 private
293 FMemory : Pointer; //!< ?祉???激?с?潟?≪??????/span>
294 FParent : TGikoDB;
295
296 function GetSize : Longword;
297 procedure SetSize( newSize : Longword );
298 function GetType : Longword;
299 procedure SetType( newType : Longword );
300 function GetNext : Pointer;
301 function GetContents : Pointer;
302
303 public
304 constructor Create( parent : TGikoDB; const address : Pointer );
305
306 property Memory : Pointer read FMemory;
307 property Size : Longword read GetSize;
308 property SectionType : Longword read GetType;
309 property Next : Pointer read GetNext;
310 end;
311
312 {!***********************************************************
313 \brief ?祉???帥?祉???激?с??/span>
314 ************************************************************}
315 TSector = class( TSection )
316 private
317 FSectionNo : Longword; //!< ?祉???激?с?括???/span>
318 FCount : Integer; //!< ?祉???炊??/span>
319
320 function GetContents : Pointer;
321 function GetSector( index : Integer ) : Pointer;
322
323 public
324 constructor Create( parent : TGikoDB; const address : Pointer );
325
326 property Count : Integer read FCount;
327 property Sector[ index : Integer ] : Pointer read GetSector; default;
328 end;
329
330 {!***********************************************************
331 \brief ?純?若??羝??帥?ゃ?潟???????号???篏?
332 ************************************************************}
333 RSortIndex = record
334 FATIndex : Word; //!< ?≪???宴?若?激?с?潟???若?????ゃ?潟????????/span>
335 FValue : Longword; //!< ??/span>
336 end;
337
338 PSortIndex = ^RSortIndex;
339
340 {!***********************************************************
341 \brief ?純?若??羝??帥?ゃ?潟????????/span>
342 ************************************************************}
343 TSortIndex = class( TSection )
344 private
345 FColumnIndex : Word; //!< ???????ゃ?潟????????/span>
346 FColumnProperty : Word; //!< ?ゃ?潟???????鴻??????????/span>
347
348 function GetContents : Pointer;
349 function GetCount : Integer;
350 function GetItem( index : Integer ) : PSortIndex;
351
352 public
353 constructor Create( parent : TGikoDB; const address : Pointer );
354
355 property Count : Integer read GetCount;
356 property Items[ index : Integer ] : PSortIndex read GetItem; default;
357 property ColumnIndex : Word read FColumnIndex;
358 property ColumnProperty : Word read FColumnProperty;
359 end;
360
361 {!***********************************************************
362 \brief ?≪???宴?若?激?с?潟???若????/span>
363 ************************************************************}
364 TAllocationTable = class( TSection )
365 private
366 function GetTable( index : Integer ) : Longword;
367
368 public
369 constructor Create( parent : TGikoDB; const address : Pointer );
370
371 property Table[ index : Integer ] : Longword read GetTable; default;
372 end;
373
374 {!***********************************************************
375 \brief ??????
376 ************************************************************}
377 TColumn = class( TObject )
378 private
379 FIndex : Word; //!< ???????ゃ?潟????????/span>
380 FType : Longword; //!< ???若?帥?帥?ゃ??
381
382 public
383 constructor Create( colIndex : Word; colType : Longword );
384
385 property ColumnIndex : Word read FIndex;
386 property ColumnType : Longword read FType;
387 end;
388
389 {!***********************************************************
390 \brief ?????????鴻??
391 ************************************************************}
392 TColumnList = class( TSection )
393 private
394 FList : THashedStringList; //!< ?????????鴻?????
395 FColumnEnd : PChar; //!< 罨<????????菴遵??篏?臀?/span>
396
397 function GetContents : Pointer;
398 function GetColumnCount : Longword;
399 procedure SetColumnCount( n : Longword );
400
401 function GetItemFromIndex( index : Integer ) : TColumn;
402 function GetItemFromColumnIndex( index : Integer ) : TColumn;
403 function GetItemFromName( const columnName : string ) : TColumn;
404 procedure WriteBack;
405
406 public
407 //! \todo ???ゃ????????????篁ラ??? index ???ゃ????????
408 constructor Create( parent : TGikoDB; const address : Pointer );
409 destructor Destroy; override;
410
411 {!
412 \warning ??綺???絎??с??????綺????荀????翫????/span>
413 ObjectsFromColumnIndex ??篏睡?????????????
414 }
415 property Objects[ index : Integer ] : TColumn read GetItemFromIndex;
416 {!
417 \warning ?????????冴???????純?с????? Objects ??篏睡?????????????????????????
418 }
419 property ObjectsFromColumnIndex[ index : Integer ] : TColumn
420 read GetItemFromColumnIndex;
421 property Items[ const columnName : string ] : TColumn read GetItemFromName; default;
422
423 {!
424 \brief ????????????/span>
425 \param columnName ???ゃ????????????
426 \todo ???ゃ????????????篁ラ??? index ???ゃ????????
427
428 columnName ??絖??????????翫???????????∴???????篋???篆?荐若?????????障????
429 }
430 procedure Delete( const columnName : string );
431
432 {!
433 \brief ????????申??
434 \param columnName 菴遵??????????????
435 \param columnType 菴遵?????????????????若?帥?帥?ゃ??
436
437 columnName ???≪??????????翫???????????∴???????篋???篆?荐若?????????障????
438 }
439 procedure Add( const columnName : string; columnType : Longword );
440 end;
441
442 {!***********************************************************
443 \brief ?ゃ?潟?????<?若?激?с?潟?祉???激?с??/span>
444 ************************************************************}
445 TInfomation = class( TSection )
446 private
447 function GetSectorSize : Longword;
448 function GetRecordCount : Longword;
449
450 public
451 constructor Create( parent : TGikoDB; const address : Pointer );
452
453 property SectorSize : Longword read GetSectorSize;
454 property RecordCount : Longword read GetRecordCount;
455 end;
456
457 {!***********************************************************
458 \brief ???潟?若??
459 ************************************************************}
460 TRecord = class( TObject )
461 private
462 FParent : TGikoDB;
463 FSectorNo : Longword; //!< ?祉???睡???/span>
464
465 //! \todo 篏???筝?/span>
466 function GetStringByName( const columnName : string ) : string;
467 //! \todo 篏???筝?/span>
468 procedure SetStringByName(
469 const columnName : string;
470 const value : string );
471 //! \todo 篏???筝?/span>
472 function GetStringByIndex( index : Longword ) : string;
473 //! \todo 篏???筝?/span>
474 function GetIntegerByName( const columnName : string ) : Integer;
475 //! \todo 篏???筝?/span>
476 procedure SetIntegerByName(
477 const columnName : string;
478 const value : Integer );
479 //! \todo 篏???筝?/span>
480 function GetIntegerByIndex( index : Longword ) : Integer;
481
482 public
483 constructor Create( parent : TGikoDB; sectorNo : Longword );
484
485 //! \brief ?ゃ????絖????у??鐚頥??
486 property StringValue[ const columnName : string ] : string
487 read GetStringByName write SetStringByName;
488
489 //! \brief ?ゃ???医?ゃ?у??鐚頥??
490 property IntegerValue[ const columnName : string ] : Integer
491 read GetIntegerByName write SetIntegerByName;
492 end;
493
494 {!***********************************************************
495 \brief ?泣???若?????????????????若?帥???若?鴻?????若??????
496 ************************************************************}
497 EGikoDBUnssuportedFormatError = class( Exception );
498
499 {!***********************************************************
500 \brief 膂≧?????若?帥???若??/span>
501 ************************************************************}
502 TGikoDB = class( TObject )
503 private
504 FFilePath : string; //!< ?????????<?ゃ????????/span>
505 FFile : TMappedFile; //!< ???若?帥???若?鴻??篆??????????<?ゃ??/span>
506 FPageSize : Longword; //!< ???若?吾?泣?ゃ??/span>
507 FSectorSize : Integer; //!< ?祉???帥?泣?ゃ??/span>
508 FSections : TList; //!< ?祉???激?с?潟???鴻??
509 FChanged : Boolean; //!< FSections ????罕?膀???綽?荀???
510
511 FInfomation : TInfomation;
512 FColumnList : TColumnList;
513 FSectors : TList;
514 FIndexes : TList;
515 FAllocationTable : TAllocationTable;
516
517 procedure CreateInitialSections;
518 procedure ReadSections;
519 procedure ReadSection0_0d1( const address : PChar );
520
521 {!
522 \brief ?祉???激?с?潟?????
523 \warning 緇??у??? Changed ??絎?茵??????????????
524 \warning sectionSize ??????篏?????∈篆???????篋????????障????
525 }
526 function CreateSection(
527 sectionSize : Longword;
528 sectionType : Longword
529 ) : Pointer;
530
531 {!
532 \brief ?祉???激?с?潟???≦宍?紫軒絨?span>
533 \warning 緇??у??? Changed ??絎?茵??????????????
534 \warning 紊?????翫?????祉???激?с?潟???≪?????鴻??紊?????障????
535 \warning section ??????祉???激?с?潟????絎?????篋????堺?ャ?障??????
536 腥冴???祉???激?с?潟??腆坂???????? CreateSection ??篏睡???????????????
537 }
538 procedure ReallocateSection(
539 section : TSection;
540 sectionSize : Longword );
541
542 {!
543 \brief ?祉???激?с?恰???宴??茯??睡?眼????TGikoDB ?????鴻????罕?膀?????
544 \param force 茯??睡?眼????筝?綽?荀????ゆ?????????翫????綣桁?句??????睡?眼???障????
545 \warning ?祉???激?с?潟???吾??紊?????緇??у???絎?茵??????????????
546 \warning ???????祉???激?с?潟?????鴻??В?障?????障????
547 }
548 procedure Changed( force : Boolean = False );
549
550 {!
551 \brief ???祉???帥?????劫????????????ゃ???≪???冴??
552 \param founds 荀??ゃ???c???ゃ????????????
553 \param value ?≪???冴????/span>
554 \param columnIndex ???????ゃ?潟????????/span>
555 \return 1 ?や札筝?荀??ゃ???c???翫??? True
556 \warning ????激???ゃ???障??? 4 byte ??莇??????ゃ??????激?ュ?ゃ??羝<?????????????
557 \warning 絎??????ゃ?????c????????激?ュ?ゃ???????翫?????????????????????????障????
558 }
559 function SelectValue(
560 founds : TList;
561 value : Longword;
562 columnIndex : Word = 0
563 ) : Boolean;
564
565 {!
566 \brief ???潟?若??????緇?
567 \param primalyValue ???潟?若????/span>
568 \return ???潟?若???ゃ????眼???????潟?若??
569 \warning ?????ゃ?????????????医?ゃ?с???????絖??????翫?????????∽?違??け?????障????
570 }
571 function GetRecordByInteger( primalyValue : Integer ) : TRecord;
572
573 {!
574 \brief ???潟?若??????緇?
575 \param primalyValue ???潟?若????
576 \return ???潟?若????????眼???????潟?若??
577 \warning ?????ゃ??????????????絖????с??????医?ゃ???翫?????????∽?違??け?????障????
578 }
579 function GetRecordByString( const primalyValue : string ) : TRecord;
580
581 {!
582 \brief ?祉???帥?????ゃ?潟?帥????緇?
583 \param sectorNo ?祉???睡???/span>
584 \return ?祉???帥???臀??????????ゃ?潟??/span>
585 \todo 篏???筝?/span>
586 }
587 function GetSector( sectorNo : Integer ) : Pointer;
588
589 public
590 {!
591 \brief ???若?帥???若?鴻?????若????/span>
592 \param filePath ??????<?ゃ????????/span>
593 \param mode fmOpenRead (??????????) ?障??? fmOpenReadWrite
594 \warning ?上???????若?吾?с?潟???????? 2GB ?障?с?????宴???障??????
595 絎?????????≪?????合??????????眼???????????障????
596 ?泣?ゃ?冴???≪???????с?????????????????ф絵??????????????
597 \todo MapViewOfFile ? 64bit 腥咲?????≪???祉?鴻?с???????????≦宍??????
598
599 filePath ??絖?????????mode ? fmOpenReadWrite ????絎????????翫????/span>
600 ?域??????若?帥???若?鴻??篏????????障????
601 }
602 constructor Create(
603 const filePath : string;
604 mode : Longword = fmOpenRead );
605 destructor Destroy; override;
606
607 {!
608 \brief ??絎鴻???????鴻?????<?ゃ???????潟??
609 \param filePath 篆?絖????????<?ゃ????????/span>
610 \todo 篏???筝?/span>
611 }
612 procedure Dump(
613 const filePath : string );
614
615 {!
616 \brief ???潟?若??????緇?
617 \param primalyValue ???潟?若????/span>
618 \return ???潟?若???ゃ????眼???????潟?若??
619 \warning ?????ゃ?????????????医?ゃ?с???????絖??????翫?????????∽?違??け?????障????
620 }
621 property RecordByInteger[ primalyValue : Integer ] : TRecord
622 read GetRecordByInteger;
623
624 {!
625 \brief ???潟?若??????緇?
626 \param primalyValue ???潟?若????
627 \return ???潟?若????????眼???????潟?若??
628 \warning ?????ゃ??????????????絖????с??????医?ゃ???翫?????????∽?違??け?????障????
629 }
630 property RecordByString[ const primalyValue : string ] : TRecord
631 read GetRecordByString;
632 end;
633
634 //==================================================
635 implementation
636 //==================================================
637
638 uses
639 Math;
640
641 const
642 MINIMUM_PAGE_SIZE = $10000; //!< ??絨?????若?吾?泣?ゃ? ( 64KB )
643 SECTOR_SIZE = $40; //!< ?祉???帥?泣?ゃ? ( 64Byte )
644 SIGNATURE_LITTLE_ENDIAN
645 = $676b6462; //!< 'bdkg' ???若?帥???若?鴻?激?違??????/span>
646 DATABASE_VERSION = $01000000; //!< ???若?吾?с?潟???潟??? ( 0.0d1 )
647
648 NULL_SECTION = $00000000; //!< ??戎???祉???激?с??/span>
649 INFOMATION_SECTION = $6f666e69; //!< 'info' ?ゃ?潟?????<?若?激?с?潟?祉???激?с??/span>
650 COLUMN_LIST_SECTION = $736c6f63; //!< 'cols' ?????????鴻???祉???激?с??/span>
651 ALLOCATION_TABLE_SECTION
652 = $626c7461; //!< 'atlb' ?≪???宴?若?激?с?潟???若?????祉???激?с??/span>
653 INDEX_SECTION = $78656469; //!< 'idex' ?ゃ?潟???????鴻?祉???激?с??/span>
654 SECTOR_SECTION = $74636573; //!< 'sect' ?祉???帥?祉???激?с??/span>
655 NULL_SECTOR_NO = $ffffffff; //!< 腟?腴???茵????祉???睡???/span>
656
657 TYPE_BOOL = $6c6f6f62; //!< 'bool' 茫?????/span>
658 TYPE_INT8 = $31306973; //!< 'si01' signed int 1 byte
659 TYPE_INT16 = $32306973; //!< 'si02'
660 TYPE_INT32 = $34306973; //!< 'si04'
661 TYPE_INT64 = $38306973; //!< 'si08'
662 TYPE_UINT8 = $31306975; //!< 'ui01' unsigned int 1 byte
663 TYPE_UINT16 = $32306975; //!< 'ui02'
664 TYPE_UINT32 = $34306975; //!< 'ui04'
665 TYPE_UINT64 = $38306975; //!< 'ui08'
666 TYPE_FLOAT32 = $34306c66; //!< 'fp04' floating point 4 byte
667 TYPE_FLOAT64 = $38306c66; //!< 'fp08'
668 TYPE_PSTR = $72747370; //!< 'pstr' pascal string
669 TYPE_DATA = $61746164; //!< 'data' data (long string)
670
671 COLUMN_DELETED = '_.-*+/DELETED+*./_-'; //!< ???ゃ??????????????
672
673
674
675 //************************************************************
676 // misc
677 //************************************************************
678
679 //==============================
680 // SortSectionsByPtr
681 //==============================
682 function SortSectionsByPtr( Item1, Item2 : Pointer ) : Integer;
683 begin
684
685 Result := PChar( TSection( Item1 ).Memory ) -
686 PChar( TSection( Item2 ).Memory );
687
688 end;
689
690 //==============================
691 // SortSectorSections
692 //==============================
693 function SortSectorSections( Item1, Item2 : Pointer ) : Integer;
694 begin
695
696 Result := PChar( TSector( Item1 ).FSectionNo ) -
697 PChar( TSector( Item2 ).FSectionNo );
698
699 end;
700
701
702
703 //************************************************************
704 // TSection class
705 //************************************************************
706
707 //==============================
708 // Create
709 //==============================
710 constructor TSection.Create( parent : TGikoDB; const address : Pointer );
711 begin
712
713 FParent := parent;
714 FMemory := address;
715
716 end;
717
718 //==============================
719 // GetSize
720 //==============================
721 function TSection.GetSize : Longword;
722 begin
723
724 Result := PDword( FMemory )^;
725
726 end;
727
728 //==============================
729 // SetSize
730 //==============================
731 procedure TSection.SetSize( newSize : Longword );
732 begin
733
734 PDword( FMemory )^ := newSize;
735
736 end;
737
738 //==============================
739 // GetType
740 //==============================
741 function TSection.GetType : Longword;
742 begin
743
744 Result := PDword( PChar( FMemory ) + 4 )^;
745
746 end;
747
748 //==============================
749 // SetType
750 //==============================
751 procedure TSection.SetType( newType : Longword );
752 begin
753
754 PDword( PChar( FMemory ) + 4 )^ := newType;
755
756 end;
757
758 //==============================
759 // GetNext
760 //==============================
761 function TSection.GetNext : Pointer;
762 begin
763
764 Result := PChar( FMemory ) + Size;
765
766 end;
767
768 //==============================
769 // GetContents
770 //==============================
771 function TSection.GetContents : Pointer;
772 begin
773
774 Result := PChar( FMemory ) + 8;
775
776 end;
777
778
779
780 //************************************************************
781 // TSector class
782 //************************************************************
783
784 //==============================
785 // Create
786 //==============================
787 constructor TSector.Create( parent : TGikoDB; const address : Pointer );
788 begin
789
790 inherited;
791 FSectionNo := PDWord( PChar( Memory ) + 8 )^;
792 FCount := Size - Longword( 12 ) div SECTOR_SIZE;
793
794 end;
795
796 //==============================
797 // GetContents
798 //==============================
799 function TSector.GetContents : Pointer;
800 begin
801
802 Result := PChar( FMemory ) + 12;
803
804 end;
805
806 //==============================
807 // GetSector
808 //==============================
809 function TSector.GetSector( index : Integer ) : Pointer;
810 begin
811
812 Assert( (index > 0) and (index <= FCount) );
813 // 8 = sizeof(section size) + sizeof(section type) + sizeof(section no) -
814 // 1 base * sizeof(Longword)
815 Result := PChar( GetContents ) + Longword( index ) * SECTOR_SIZE;
816
817 end;
818
819
820
821 //************************************************************
822 // TSortIndex class
823 //************************************************************
824
825 //==============================
826 // Create
827 //==============================
828 constructor TSortIndex.Create( parent : TGikoDB; const address : Pointer );
829 begin
830
831 inherited;
832 FColumnIndex := PWORD( PChar( Memory ) + 4 )^;
833 FColumnProperty := PWORD( PChar( Memory ) + 6 )^;
834
835 end;
836
837 //==============================
838 // GetContents
839 //==============================
840 function TSortIndex.GetContents : Pointer;
841 begin
842
843 Result := PChar( FMemory ) + 12;
844
845 end;
846
847 //==============================
848 // GetCount
849 //==============================
850 function TSortIndex.GetCount : Integer;
851 begin
852
853 Result := FParent.FInfomation.RecordCount;
854
855 end;
856
857 //==============================
858 // GetItem
859 //==============================
860 function TSortIndex.GetItem( index : Integer ) : PSortIndex;
861 begin
862
863 Result := PSortIndex( PChar( GetContents ) + index * SizeOf( RSortIndex ) );
864
865 end;
866
867
868
869 //************************************************************
870 // TAllocationTable class
871 //************************************************************
872
873 //==============================
874 // Create
875 //==============================
876 constructor TAllocationTable.Create( parent : TGikoDB; const address : Pointer );
877 begin
878
879 inherited;
880
881 end;
882
883 function TAllocationTable.GetTable( index : Integer ) : Longword;
884 begin
885
886 Result := PDword( PChar( GetContents ) + index * SizeOf( DWORD ) )^
887
888 end;
889
890
891
892 //************************************************************
893 // TColumn class
894 //************************************************************
895
896 //==============================
897 // Create
898 //==============================
899 constructor TColumn.Create( colIndex : Word; colType : Longword );
900 begin
901
902 FIndex := colIndex;
903 FType := colType;
904
905 end;
906
907
908
909 //************************************************************
910 // TColumnList class
911 //************************************************************
912
913 //==============================
914 // Create
915 //==============================
916 constructor TColumnList.Create( parent : TGikoDB; const address : Pointer );
917 var
918 i, j : Word;
919 p, p2, tail : PChar;
920 l : Integer;
921 columnCount : Longword;
922 col : TColumn;
923 colType : Longword;
924 colName : string;
925 begin
926
927 inherited;
928 FList := THashedStringList.Create;
929 FList.Sorted := True;
930 FList.Duplicates := dupError;
931 columnCount := GetColumnCount;
932 p := PChar( GetContents );
933 tail := Next;
934
935 j := Random( MaxInt );
936 for i := 0 to columnCount - 1 do begin
937 p2 := p; // Break ??? FColumnEnd ??襲?帥????????????
938
939 if p2 >= tail then Break;
940 l := PByte( p2 )^; Inc( p2 );
941 if p2 + l + SizeOf( Dword ) >= tail then Break;
942 colName := Copy( p2, 0, l ); p2 := p2 + l;
943 colType := PDword( p2 )^; p2 := p2 + SizeOf( colType );
944
945 p := p2;
946
947 if l = 0 then begin
948 // ???ゃ?????????????????????ч???????茲?????????????篁?????
949 while true do begin
950 Inc( j );
951 colName := COLUMN_DELETED + IntToStr( j );
952 if FList.IndexOf( colName ) < 0 then
953 Break;
954 end;
955 end;
956 col := TColumn.Create( i, colType );
957 FList.AddObject( colName, col );
958 end;
959
960 FColumnEnd := p;
961
962 end;
963
964 //==============================
965 // Destroy
966 //==============================
967 destructor TColumnList.Destroy;
968 var
969 i : Integer;
970 begin
971
972 for i := FList.Count - 1 downto 0 do
973 FList.Objects[ i ].Free;
974 FList.Free;
975
976 end;
977
978 //==============================
979 // GetContents
980 //==============================
981 function TColumnList.GetContents : Pointer;
982 begin
983
984 Result := PChar( FMemory ) + 12;
985
986 end;
987
988 //==============================
989 // GetColumnCount
990 //==============================
991 function TColumnList.GetColumnCount : Longword;
992 begin
993
994 Result := PDword( PChar( Memory ) + 8 )^;
995
996 end;
997
998 //==============================
999 // SetColumnCount
1000 //==============================
1001 procedure TColumnList.SetColumnCount( n : Longword );
1002 begin
1003
1004 PDword( PChar( Memory ) + 8 )^ := n;
1005
1006 end;
1007
1008 //==============================
1009 // GetItemFromIndex
1010 //==============================
1011 function TColumnList.GetItemFromIndex( index : Integer ) : TColumn;
1012 begin
1013
1014 Result := TColumn( FList.Objects[ index ] );
1015
1016 end;
1017
1018 //==============================
1019 // GetItemFromColumnIndex
1020 //==============================
1021 function TColumnList.GetItemFromColumnIndex( index : Integer ) : TColumn;
1022 var
1023 i : Integer;
1024 col : TColumn;
1025 begin
1026
1027 Result := nil;
1028 for i := 0 to FList.Count - 1 do begin
1029 col := Objects[ i ];
1030 if col.ColumnIndex = index then begin
1031 Result := col;
1032 Break;
1033 end;
1034 end;
1035
1036 end;
1037
1038 //==============================
1039 // GetItemFromName
1040 //==============================
1041 function TColumnList.GetItemFromName( const columnName : string ) : TColumn;
1042 var
1043 i : Integer;
1044 begin
1045
1046 i := FList.IndexOf( columnName );
1047 if i >= 0 then
1048 Result := Objects[ i ]
1049 else
1050 Result := nil;
1051
1052 end;
1053
1054 //==============================
1055 // Delete
1056 //==============================
1057 procedure TColumnList.Delete( const columnName : string );
1058 var
1059 i, j : Integer;
1060 s : string;
1061 begin
1062
1063 i := FList.IndexOf( columnName );
1064 if i >= 0 then begin
1065 j := Random( MaxInt );
1066 while true do begin
1067 Inc( j );
1068 s := COLUMN_DELETED + IntToStr( j );
1069 if FList.IndexOf( s ) < 0 then begin
1070 FList[ i ] := s;
1071 Break;
1072 end;
1073 end;
1074
1075 WriteBack;
1076 end;
1077
1078 end;
1079
1080 //==============================
1081 // Add
1082 //==============================
1083 procedure TColumnList.Add( const columnName : string; columnType : Longword );
1084 var
1085 i, l : Integer;
1086 col : TColumn;
1087 p : PChar;
1088 begin
1089
1090 i := FList.IndexOf( columnName );
1091 if i >= 0 then begin
1092 col := TColumn.Create( FList.Count, columnType );
1093 FList.AddObject( columnName, col );
1094 p := FColumnEnd;
1095 l := Length( columnName );
1096 Assert( l <= 255 );
1097 if 255 < l then
1098 Exit;
1099 if p + l + 5 <= Next then begin
1100 // ?祉???激?с?潟??????????????ц申荐?????
1101 PByte( p )^ := l; Inc( p );
1102 Move( PChar( columnName )^, p^, l ); p := p + l;
1103 PDword( p )^ := columnType; p := p + SizeOf( columnType );
1104
1105 FColumnEnd := p;
1106 SetColumnCount( FList.Count );
1107 end else begin
1108 // ?祉???激?с?潟???ャ????????????? WriteBack ??算????
1109 WriteBack;
1110 end;
1111 end;
1112
1113 end;
1114
1115 //==============================
1116 // WriteBack
1117 //==============================
1118 procedure TColumnList.WriteBack;
1119 var
1120 p, tail : PChar;
1121 i, j : Integer;
1122 idx, l : Integer;
1123 col : TColumn;
1124 begin
1125
1126 // 綽?荀????祉???激?с?潟?泣?ゃ?冴??荐?膊?????
1127 p := PChar( GetContents );
1128 for i := 0 to FList.Count - 1 do begin
1129 p := p + 5;
1130 if AnsiPos( COLUMN_DELETED, FList[ i ] ) <> 1 then
1131 p := p + Length( FList[ i ] );
1132 end;
1133
1134 if p > Next then
1135 // ?祉???激?с?潟?泣?ゃ?冴??莇潟?????????ф?≦宍
1136 FParent.ReallocateSection( Self, p - Memory );
1137
1138 p := PChar( GetContents );
1139 for i := 0 to FList.Count - 1 do begin
1140 // FList ???????????с?純?若????????????????/span>
1141 // ColumnIndex ?т研?鴻???????膣≪?????????????????
1142 idx := -1;
1143 col := nil;
1144 for j := 0 to FList.Count - 1 do begin
1145 col := TColumn( FList.Objects[ j ] );
1146 if col.ColumnIndex = i then begin
1147 idx := j;
1148 Break;
1149 end;
1150 end;
1151 Assert( idx <> -1 );
1152
1153 if AnsiPos( COLUMN_DELETED, FList[ idx ] ) = 1 then
1154 l := 0
1155 else
1156 l := Length( FList[ idx ] );
1157 PByte( p )^ := l; Inc( p );
1158 Move( PChar( FList[ idx ] )^, p^, l ); p := p + l;
1159 PDWord( p )^ := col.ColumnType; p := p + SizeOf( DWORD );
1160 Assert( p <= Next );
1161 end;
1162
1163 FColumnEnd := p;
1164 SetColumnCount( FList.Count );
1165
1166 FParent.Changed;
1167
1168 end;
1169
1170
1171
1172 //************************************************************
1173 // TInfomation class
1174 //************************************************************
1175
1176 //==============================
1177 // Create
1178 //==============================
1179 constructor TInfomation.Create( parent : TGikoDB; const address : Pointer );
1180 begin
1181
1182 inherited;
1183
1184 end;
1185
1186 //==============================
1187 // GetSectorSize
1188 //==============================
1189 function TInfomation.GetSectorSize : Longword;
1190 begin
1191
1192 Result := PDword( PChar( GetContents ) )^;
1193
1194 end;
1195
1196 //==============================
1197 // GetRecordCount
1198 //==============================
1199 function TInfomation.GetRecordCount : Longword;
1200 begin
1201
1202 Result := PDword( PChar( GetContents ) + 4 )^;
1203 end;
1204
1205
1206
1207 //************************************************************
1208 // TRecord class
1209 //************************************************************
1210
1211 //==============================
1212 // Create
1213 //==============================
1214 constructor TRecord.Create( parent : TGikoDB; sectorNo : Longword );
1215 begin
1216
1217 inherited Create;
1218 FParent := parent;
1219 FSectorNo := sectorNo;
1220
1221 end;
1222
1223 //==============================
1224 // GetStringByName
1225 //==============================
1226 function TRecord.GetStringByName( const columnName : string ) : string;
1227 begin
1228 //!!!!! 篏???筝 !!!!!
1229 end;
1230
1231 //==============================
1232 // SetStringByName
1233 //==============================
1234 procedure TRecord.SetStringByName(
1235 const columnName : string;
1236 const value : string );
1237 begin
1238 //!!!!! 篏???筝 !!!!!
1239 end;
1240
1241 //==============================
1242 // GetStringByIndex
1243 //==============================
1244 function TRecord.GetStringByIndex( index : Longword ) : string;
1245 begin
1246 //!!!!! 篏???筝 !!!!!
1247 end;
1248
1249 //==============================
1250 // GetIntegerByName
1251 //==============================
1252 function TRecord.GetIntegerByName( const columnName : string ) : Integer;
1253 begin
1254 //!!!!! 篏???筝 !!!!!
1255 end;
1256
1257 //==============================
1258 // SetIntegerByName
1259 //==============================
1260 procedure TRecord.SetIntegerByName(
1261 const columnName : string;
1262 const value : Integer );
1263 var
1264 col, c : TColumn;
1265 sectorNo : Integer;
1266 offset : Longword;
1267 i : Integer;
1268 begin
1269
1270 col := FParent.FColumnList[ columnName ];
1271 if col = nil then
1272 Exit;
1273 sectorNo := FSectorNo;
1274 offset := 0;
1275
1276 for i := 0 to col.ColumnIndex - 1 do begin
1277 c := FParent.FColumnList.GetItemFromColumnIndex( i );
1278 case c.ColumnType of
1279 TYPE_BOOL, TYPE_INT8, TYPE_UINT8: Inc( offset );
1280 TYPE_INT16, TYPE_UINT16: offset := offset + 2;
1281 TYPE_INT32, TYPE_UINT32, TYPE_FLOAT32: offset := offset + 4;
1282 TYPE_INT64, TYPE_UINT64, TYPE_FLOAT64: offset := offset + 8;
1283
1284 TYPE_PSTR:
1285 begin
1286 //!!!!! 篏???筝 !!!!!
1287 offset := PByte( PChar( FParent.GetSector( sectorNo ) ) + offset )^;
1288 while offset >= FParent.FSectorSize do begin
1289 sectorNo := FParent.FAllocationTable[ sectorNo ];
1290 if sectorNo = NULL_SECTOR_NO then
1291 Exit;
1292 offset := offset - FParent.FSectorSize;
1293 end;
1294 end;
1295
1296 TYPE_DATA:
1297 begin
1298 //!!!!! 篏???筝 !!!!!
1299 end;
1300 end;
1301 end;
1302
1303 //!!!!! 篏???筝 !!!!!
1304
1305 end;
1306
1307 //==============================
1308 // GetIntegerByIndex
1309 //==============================
1310 function TRecord.GetIntegerByIndex( index : Longword ) : Integer;
1311 begin
1312 //!!!!! 篏???筝 !!!!!
1313 end;
1314
1315
1316
1317 //************************************************************
1318 // TGikoDB class
1319 //************************************************************
1320
1321 //==============================
1322 // Create
1323 //==============================
1324 constructor TGikoDB.Create(
1325 const filePath : string;
1326 mode : Longword = fmOpenRead );
1327 var
1328 info : _SYSTEM_INFO;
1329 maximumSize : Integer;
1330 begin
1331
1332 Randomize;
1333 FFilePath := ExpandUNCFileName( filePath );
1334 FChanged := False;
1335
1336 GetSystemInfo( info );
1337 FPageSize := Max( info.dwPageSize, MINIMUM_PAGE_SIZE );
1338 if FileExists( filePath ) then begin
1339 maximumSize := 0;
1340 FFile := TMappedFile.Create( FFilePath, mode, maximumSize );
1341 ReadSections;
1342 end else begin
1343 maximumSize := FPageSize;
1344 FFile := TMappedFile.Create( FFilePath, mode, maximumSize );
1345 CreateInitialSections;
1346 ReadSections;
1347 end;
1348
1349 end;
1350
1351 //==============================
1352 // Destroy
1353 //==============================
1354 destructor TGikoDB.Destroy;
1355 var
1356 i : Integer;
1357 begin
1358
1359 FFile.Free;
1360 for i := FSections.Count - 1 downto 0 do
1361 TObject( FSections[ i ] ).Free;
1362 FSections.Free;
1363
1364 end;
1365
1366 //==============================
1367 // CreateInitialSections
1368 //==============================
1369 procedure TGikoDB.CreateInitialSections;
1370 var
1371 i : Integer;
1372 p, p2 : PChar;
1373 emptySize : Longword;
1374 sectionCount : Longword;
1375 begin
1376
1377 FSections := TList.Create;
1378 p := PChar( FFile.Memory );
1379
1380 //===== ??????
1381 // ?激?違??????/span>
1382 PDword( p )^ := SIGNATURE_LITTLE_ENDIAN; p := p + SizeOf( DWORD );
1383 // ???若?吾?с??/span>
1384 PDword( p )^ := DATABASE_VERSION; p := p + SizeOf( DWORD );
1385
1386 //===== ?ゃ?潟?????<?若?激?с?潟?祉???激?с??/span>
1387 p2 := p;
1388 // ?祉???激?с?潟?泣?ゃ??/span>
1389 PDword( p2 )^ := 16; p2 := p2 + SizeOf( DWORD );
1390 // ?祉???激?с?潟?帥?ゃ??
1391 PDword( p2 )^ := INFOMATION_SECTION; p2 := p2 + SizeOf( DWORD );
1392 // ?祉???帥?泣?ゃ??/span>
1393 PDword( p2 )^ := SECTOR_SIZE; p2 := p2 + SizeOf( DWORD );
1394 // ???潟?若????/span>
1395 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1396 p := p + PDword( p )^;
1397
1398 //===== ?????????鴻???祉???激?с??/span>
1399 // 1 ?祉???帥? SECTOR_SIZE / SizeOf( DWORD ) ?????????????ャ??????????
1400 // 1 ??????? 12 byte(11 ??絖?) + 4 byte ???若?帥?帥?ゃ?? = 16 byte 羔?莢祉??????皿絎?
1401 p2 := p;
1402 // ?祉???激?с?潟?泣?ゃ??/span>
1403 PDword( p2 )^ := 8 + (SECTOR_SIZE div SizeOf( DWORD )) * 16;
1404 p2 := p2 + SizeOf( DWORD );
1405 // ?祉???激?с?潟?帥?ゃ??
1406 PDword( p2 )^ := COLUMN_LIST_SECTION; p2 := p2 + SizeOf( DWORD );
1407 // ????????/span>
1408 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1409 p := p + PDword( p )^;
1410
1411 //===== ?≪???宴?若?激?с?潟???若?????祉???激?с??/span>
1412 // - 8 = allocation table section
1413 // -12 = index section + column no + property
1414 // -12 = sector section + section no
1415 p2 := p;
1416 emptySize := p2 - PChar( FFile.Memory ) - 8 - 12 - 12;
1417 // emptySize = sectionCount *
1418 // (SECTOR_SIZE + allocation table + table no + value)
1419 // sectionCount = emptySize / (SECTOR_SIZE + 12)
1420 sectionCount := emptySize div (SECTOR_SIZE + 12);
1421 // ?祉???激?с?潟?泣?ゃ??/span>
1422 PDword( p2 )^ := 8 + sectionCount * SizeOf( DWORD );
1423 p2 := p2 + SizeOf( DWORD );
1424 // ?祉???激?с?潟?帥?ゃ??
1425 PDword( p2 )^ := ALLOCATION_TABLE_SECTION;
1426 p2 := p2 + SizeOf( DWORD );
1427 // ???若????/span>
1428 for i := 1 to sectionCount do begin
1429 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1430 end;
1431 p := p + PDword( p )^;
1432
1433 //===== ?ゃ?潟???????鴻?祉???激?с??/span>
1434 p2 := p;
1435 // ?祉???激?с?潟?泣?ゃ??/span>
1436 PDword( p2 )^ := 12 + sectionCount * SizeOf( DWORD ) * 2;
1437 p2 := p2 + SizeOf( DWORD );
1438 // ?祉???激?с?潟?帥?ゃ??
1439 PDword( p2 )^ := INDEX_SECTION; p2 := p2 + SizeOf( DWORD );
1440 // ???????? ( 2 byte ) + ????????? ( 2 byte )
1441 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1442 // ???若?????? + ??/span>
1443 for i := 1 to sectionCount * 2 do begin
1444 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1445 end;
1446 p := p + PDword( p )^;
1447
1448 //===== ?祉???帥?祉???激?с??/span>
1449 p2 := p;
1450 // ?祉???激?с?潟?泣?ゃ??/span>
1451 PDword( p2 )^ := 8 + sectionCount * SECTOR_SIZE;
1452 p2 := p2 + SizeOf( DWORD );
1453 // ?祉???激?с?潟?帥?ゃ??
1454 PDword( p2 )^ := SECTOR_SECTION; p2 := p2 + SizeOf( DWORD );
1455 // ?祉???激?с?括???/span>
1456 PDword( p2 )^ := 0; p2 := p2 + SizeOf( DWORD );
1457 p := p + PDword( p )^;
1458
1459 if p + 8 <= PChar( FFile.Memory ) + FFile.Size then begin
1460 // 腟?腴????/span>
1461 PDWord( p )^ := 0;
1462 PDWord( p + 4 )^ := NULL_SECTION;
1463 end;
1464
1465 end;
1466
1467 //==============================
1468 // ReadSections
1469 //==============================
1470 procedure TGikoDB.ReadSections;
1471 var
1472 p : PChar;
1473 dbVersion : Longword;
1474 begin
1475
1476 FSections := TList.Create;
1477 p := FFile.Memory;
1478 // ?激?違?????c?????с??? (?上?????????????潟???c?≪?潟????
1479 if PDword( p )^ <> SIGNATURE_LITTLE_ENDIAN then
1480 raise EGikoDBUnssuportedFormatError.Create(
1481 '???若?帥???若?鴻???????若????????筝????с????' );
1482 p := p + SizeOf( DWORD );
1483
1484 dbVersion := PDword( p )^; p := p + SizeOf( DWORD );
1485 case dbVersion of
1486 DATABASE_VERSION:
1487 ReadSection0_0d1( p );
1488 else
1489 raise EGikoDBUnssuportedFormatError.Create(
1490 '?泣???若???????????????????若???????с????' );
1491 end;
1492
1493 end;
1494
1495 //==============================
1496 // ReadSection0_0d1
1497 //==============================
1498 procedure TGikoDB.ReadSection0_0d1( const address : PChar );
1499 var
1500 p, tail : PChar;
1501 sectionSize : Longword;
1502 sectionType : Longword;
1503 section : TSection;
1504 begin
1505
1506 p := address;
1507 tail := PChar( FFile.Memory ) + FFile.Size - 8;
1508 while p < tail do begin
1509 sectionSize := PDword( p )^;
1510 sectionType := PDword( p + 4 )^;
1511 if sectionSize = 0 then
1512 Break;
1513
1514 case sectionType of
1515 NULL_SECTION:
1516 FSections.Add( TSection.Create( Self, p ) );
1517
1518 INFOMATION_SECTION:
1519 begin
1520 FInfomation := TInfomation.Create( Self, p );
1521 FSections.Add( FInfomation );
1522 end;
1523
1524 COLUMN_LIST_SECTION:
1525 begin
1526 FColumnList := TColumnList.Create( Self, p );
1527 FSections.Add( FColumnList );
1528 end;
1529
1530 ALLOCATION_TABLE_SECTION:
1531 begin
1532 FAllocationTable := TAllocationTable.Create( Self, p );
1533 FSections.Add( FAllocationTable );
1534 end;
1535
1536 INDEX_SECTION:
1537 begin
1538 section := TSortIndex.Create( Self, p );
1539 FIndexes.Add( section );
1540 FSections.Add( section );
1541 end;
1542
1543 SECTOR_SECTION:
1544 begin
1545 section := TSector.Create( Self, p );
1546 FSectors.Add( section );
1547 FSections.Add( section );
1548 end;
1549
1550 else
1551 FSections.Add( TSection.Create( Self, p ) )
1552 end;
1553 p := p + sectionSize;
1554 end;
1555
1556 end;
1557
1558 //==============================
1559 // CreateSection
1560 //==============================
1561 function TGikoDB.CreateSection(
1562 sectionSize : Longword;
1563 sectionType : Longword
1564 ) : Pointer;
1565 var
1566 i, j : Integer;
1567 section : TSection;
1568 emptySection : TSection;
1569 emptySize : Longword;
1570 emptyIndex : Integer;
1571 fileSize : Longword;
1572 oldBegin : PChar;
1573 p : PChar;
1574 begin
1575
1576 // ?障????????祉???激?с?潟???≪??
1577 emptySection := nil;
1578 section := nil;
1579 emptyIndex := 0;
1580 // ?g?????腥冴???????? FSection ??兄??絖??с??
1581 // ?g??????????????違???????????с?純?若??
1582 FSections.Sort( SortSectionsByPtr );
1583
1584 for i := 0 to FSections.Count - 1 do begin
1585 section := TSection( FSections[ i ] );
1586 if (section.SectionType = NULL_SECTION) then begin
1587 // emptySection ???g?????腥冴??????????????????
1588 if emptySection = nil then begin
1589 emptySection := section;
1590 emptyIndex := i;
1591 end;
1592
1593 emptySize := PChar( section.Memory ) + section.Size -
1594 PChar( emptySection.Memory );
1595 if sectionSize <= emptySize then begin
1596 // 腥冴???祉???激?с?括?肴?
1597 Result := emptySection.Memory;
1598 PDword( Result )^ := emptySize;
1599 PDword( PChar( Result ) + 4 )^ := sectionType;
1600 // 腥冴???祉???激?с?潟??????/span>
1601 for j := i downto emptyIndex do begin
1602 TSection( FSections[ j ] ).Free;
1603 FSections.Delete( j );
1604 end;
1605 Exit; // ?紫????祉???激?с?潟?????ゃ????????????? for i ???茵?筝?????/span>
1606 end;
1607 end else begin
1608 emptySection := nil;
1609 end;
1610 end;
1611
1612 // ???<?ゃ??????鮎???????????????????
1613 oldBegin := FFile.Memory;
1614 if PChar( section.Next ) + sectionSize <= oldBegin + FFile.Size then begin
1615 // 腥冴???????肴?
1616 Result := section.Next;
1617 PDword( Result )^ := sectionSize;
1618 PDword( PChar( Result ) + 4 )^ := sectionType;
1619 Exit;
1620 end;
1621
1622 // sectionSize ??羣??????????????????с???<?ゃ?????≦宍
1623 FChanged := True;
1624
1625 // ?≦宍?????泣?ゃ?冴???膊?
1626 fileSize := (sectionSize div FPageSize + 1) * FPageSize;
1627
1628 // ?≦宍???????<?ゃ??????????????
1629 FFile.Free;
1630 FFile := TMappedFile.Create( FFilePath, fmOpenReadWrite, fileSize );
1631
1632 // ??鮎??申??
1633 Result := PChar( FFile.Memory ) + (PChar( section.Next ) - oldBegin);
1634 PDword( Result )^ := sectionSize;
1635 PDword( PChar( Result ) + 4 )^ := sectionType;
1636
1637 p := PChar( Result ) + sectionSize;
1638 if p + 8 <= PChar( FFile.Memory ) + FFile.Size then begin
1639 // 腟?腴????/span>
1640 PDword( p )^ := 0; p := p + SizeOf( DWORD );
1641 PDword( p )^ := NULL_SECTION;
1642 end;
1643
1644 end;
1645
1646 //==============================
1647 // ReallocateSection
1648 //==============================
1649 procedure TGikoDB.ReallocateSection(
1650 section : TSection;
1651 sectionSize : Longword );
1652 var
1653 nextSection : PChar;
1654 fileEnd : PChar;
1655 p : PChar;
1656 size : Longword;
1657 sectionType : Longword;
1658 begin
1659
1660 FChanged := True;
1661 fileEnd := PChar( FFile.Memory ) + FFile.Size;
1662
1663 if sectionSize <= section.Size then begin
1664
1665 // 膰??
1666 nextSection := PChar( section.Next );
1667 section.SetSize( sectionSize );
1668 if 8 >= fileEnd - PChar( nextSection ) then
1669 // ????????緇????祉???激?с??/span>
1670 nextSection := fileEnd;
1671
1672 if 16 >= nextSection - PChar( section.Next ) then begin
1673 // 緇?膓?????腥冴????絨??????? section ???g?????
1674 section.SetSize( nextSection - PChar( section.Memory ) );
1675 end else begin
1676 // 緇?膓?????腥冴????紊с???????х??祉???激?с?潟??????
1677 p := section.Next;
1678 if PDword( nextSection )^ = 0 then
1679 // 腥冴???祉???激?с?潟????腟??祉???激?с??/span>
1680 PDword( p )^ := 0
1681 else
1682 // ??????????腥冴???祉???激?с??/span>
1683 PDword( p )^ := nextSection - p;
1684 PDword( p + 4 )^ := NULL_SECTION;
1685 end;
1686
1687 end else begin
1688
1689 // ?≦宍
1690 size := section.Size;
1691 p := PChar( section.Next );
1692
1693 // section ??????緇????g?????腥冴?????≪??
1694 while (8 < fileEnd - p) and (size < sectionSize) do begin
1695 if PDword( p )^ = 0 then begin
1696 size := size + Longword( fileEnd - p );
1697 Break;
1698 end else if PDword( p + 4 )^ = 0 then begin
1699 size := size + PDword( p )^;
1700 p := p + PDword( p )^;
1701 end else begin
1702 Break;
1703 end;
1704 end;
1705
1706 if size >= sectionSize then begin
1707 // ?g?????腥冴???祉???激?с?潟?ц?????
1708 section.SetSize( size );
1709 end else begin
1710 // ?g?????腥冴???祉???激?с?潟?ц??????????ф?域?篏???
1711 size := section.Size;
1712 sectionType := section.SectionType;
1713 section.SetType( NULL_SECTION );
1714
1715 p := CreateSection( sectionSize, sectionType );
1716 Move( PChar( section.FMemory )^, p^, size );
1717
1718 section.FMemory := p;
1719 end;
1720
1721 end;
1722
1723 end;
1724
1725 //==============================
1726 // Dump
1727 //==============================
1728 procedure TGikoDB.Dump(
1729 const filePath : string );
1730 begin
1731 //!!!!! 篏???筝 !!!!!
1732 end;
1733
1734 //==============================
1735 // Changed
1736 //==============================
1737 procedure TGikoDB.Changed( force : Boolean = False );
1738 var
1739 i : Integer;
1740 begin
1741
1742 if FChanged or force then begin
1743 // FSections ??????/span>
1744 for i := FSections.Count - 1 downto 0 do
1745 TObject( FSections[ i ] ).Free;
1746 FSections.Free;
1747
1748 // FSections ????罕?膀?
1749 ReadSections;
1750 end;
1751
1752 end;
1753
1754 //==============================
1755 // SelectValue
1756 //==============================
1757 function TGikoDB.SelectValue(
1758 founds : TList;
1759 value : Longword;
1760 columnIndex : Word = 0
1761 ) : Boolean;
1762 var
1763 foundIdx : Integer;
1764 l, h, m : Integer;
1765 index : TSortIndex;
1766 begin
1767
1768 Result := False;
1769 index := nil;
1770 foundIdx := -1;
1771 for l := 0 to FIndexes.Count - 1 do begin
1772 index := TSortIndex( FIndexes[ l ] );
1773 if index.ColumnIndex = columnIndex then
1774 Break;
1775 end;
1776 if index = nil then
1777 Exit;
1778
1779 // ??膣???????∝刈
1780 l := 0;
1781 h := index.Count;
1782 m := 0;
1783 while l < h do begin
1784 m := (l + h) shr 1;
1785 if index[ m ].FValue = value then begin
1786 foundIdx := m;
1787 founds.Add( Pointer( index[ m ].FATIndex ) );
1788 Break;
1789 end else if index[ m ].FValue < value then begin
1790 h := m;
1791 end else begin
1792 l := m;
1793 end;
1794 end;
1795 if foundIdx < 0 then
1796 Exit;
1797
1798 for l := m - 1 downto 0 do begin
1799 if index[ l ].FValue <> value then
1800 Break;
1801 founds.Add( Pointer( l ) );
1802 end;
1803 for l := m + 1 downto index.Count - 1 do begin
1804 if index[ l ].FValue <> value then
1805 Break;
1806 founds.Add( Pointer( index[ m ].FATIndex ) );
1807 end;
1808
1809 Result := True;
1810
1811 end;
1812
1813 //==============================
1814 // GetRecordByInteger
1815 //==============================
1816 function TGikoDB.GetRecordByInteger( primalyValue : Integer ) : TRecord;
1817 var
1818 founds : TList;
1819 sector : Integer;
1820 begin
1821
1822 Result := nil;
1823 founds := TList.Create;
1824 try
1825 if not SelectValue( founds, primalyValue ) then
1826 Exit;
1827
1828 sector := Integer( founds[ 0 ] );
1829 Result := TRecord.Create( Self, FAllocationTable[ sector ] );
1830 finally
1831 founds.Free;
1832 end;
1833
1834 end;
1835
1836 //==============================
1837 // GetRecordByString
1838 //==============================
1839 function TGikoDB.GetRecordByString( const primalyValue : string ) : TRecord;
1840 var
1841 hash : Longword;
1842 begin
1843
1844 hash := GetStringHash( primalyValue );
1845 Result := GetRecordByInteger( hash );
1846
1847 end;
1848
1849 //==============================
1850 // GetSector
1851 //==============================
1852 function TGikoDB.GetSector( sectorNo : Integer ) : Pointer;
1853 begin
1854 //!!!!! 篏???筝 !!!!!
1855 end;
1856
1857 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26