2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
/////////////////////////////////////////////////////////////////
58
// class XMemFile - utility to put/get misc data into binary pool,
59
// read/write it to disk
61
// 28.05.97 22:32, Postnikov
62
/////////////////////////////////////////////////////////////////
71
# include "swabytes.h"
74
class XMemFile : public XPool
76
Int32 nFileLength; // count of bytes in use (put into)
77
Word8* pCur; // current ptr
80
XMemFile( Int32 init_size = 0 )
82
{ pCur=(Word8*)Data; nFileLength = 0; };
85
{ return pCur - (Word8*)Data; };
88
{ return nFileLength; };
90
void RestoreFileLength(Int32 len) // Oleg : knot for second recongition
93
Bool Seek( Int32 nOffset )
94
{ if ((nOffset > nFileLength)||(nOffset < 0))
96
pCur= ((Word8*)Data)+nOffset;
100
void SeekToStart( void ) { pCur= ((Word8*)Data); };
101
void SeekToFinish( void ) { pCur= ((Word8*)Data)+nFileLength; };
103
void Reset() { nFileLength = 0; SeekToStart(); };
105
Bool Get( void* data, Int32 size )
107
if (size < 0 || size+Tell() > nFileLength)
111
stdMemcpy(data, pCur, size);
116
Bool Writeln( const char* str )
118
return Put(str, strlen(str)+1);
120
char* Readln(void) // be sure that there is zt string!
122
int nRest = nFileLength - Tell();
125
char* pNext = (char*)memchr(pCur, 0, nRest);
128
char* ret = (char*)pCur;
129
pCur = (Word8*)pNext; pCur++;
133
Bool Reserve( Int32 size )
136
RET_FALSE; // too strange...
138
if (size+tell <= Volume)
139
return TRUE; // there is enough place
141
Int32 new_size = maxi(size+tell, Volume*2);
142
if (!Realloc( new_size ))
144
if ( size+tell < Volume*2 &&
147
RET_FALSE; // can't realloc
153
Bool Put( const void* data, Int32 size )
157
if (!Reserve(size)) // prepeare place to put
160
stdMemcpy(pCur, (void*)data, size);
167
Bool Get( Int32& t ) { return Get( &t, sizeof(Int32) ); }
168
Bool Put( Int32& t ) { return Put( &t, sizeof(Int32) ); }
169
Bool Get( Int16& t ) { return Get( &t, sizeof(Int16) ); }
170
Bool Put( Int16& t ) { return Put( &t, sizeof(Int16) ); }
171
Bool Get( Int8& t ) { return Get( &t, sizeof(Int8) ); }
172
Bool Put( Int8& t ) { return Put( &t, sizeof(Int8) ); }
173
Bool Get( Word32& t ) { return Get( &t, sizeof(Word32) ); }
174
Bool Put( Word32& t ) { return Put( &t, sizeof(Word32) ); }
175
Bool Get( Word16& t ) { return Get( &t, sizeof(Word16) ); }
176
Bool Put( Word16& t ) { return Put( &t, sizeof(Word16) ); }
177
Bool Get( Word8& t ) { return Get( &t, sizeof(Word8) ); }
178
Bool Put( Word8& t ) { return Put( &t, sizeof(Word8) ); }
179
Bool Get( Rect16& t ) { return Get( &t, sizeof(Rect16) ); }
180
Bool Put( Rect16& t ) { return Put( &t, sizeof(Rect16) ); }
181
Bool Get( Point16& t ) { return Get( &t, sizeof(Point16) ); }
182
Bool Put( Point16& t ) { return Put( &t, sizeof(Point16) ); }
183
Bool Get( Rect32& t ) { return Get( &t, sizeof(Rect32) ); }
184
Bool Put( Rect32& t ) { return Put( &t, sizeof(Rect32) ); }
185
Bool Get( Point32& t ) { return Get( &t, sizeof(Point32) ); }
186
Bool Put( Point32& t ) { return Put( &t, sizeof(Point32) ); }
190
Bool Get( T& t ) { return Get( &t, sizeof(T) ); }
193
Bool Put( T& t ) { return Put( &t, sizeof(T) ); }
195
Bool GetArray( void* p_start, Int32& nCount, Int32 cbElemSize )
196
{ if (!Get( nCount ))
198
if (!Get( p_start, nCount*cbElemSize ))
203
Bool PutArray( void* p_start, Int32 nCount, Int32 cbElemSize )
204
{ if (!Put( nCount ))
206
if (!Put( p_start, nCount*cbElemSize ))
211
void Destroy() { XPool::Destroy(); pCur = NULL; nFileLength = 0; };
212
/////////////////////////////////////////////////////
214
Err16 Read( XFile & xf, Bool32 swap_bytes = FALSE )
216
RETIFERR( XPool::Read(xf, swap_bytes) );
217
nFileLength = XPool::GetVolume();
222
Bool Write( XFile & xf ) const
224
if(!XPool::Write(xf, nFileLength)) RET_FALSE;
228
/////////////////////////////////////////////////////
230
Bool CopyFrom( XMemFile& src )
233
if (!XPool::CopyFrom( *(XPool*)&src ))
236
nFileLength = src.FileLength();
242
#endif // __XMEMFILE_H