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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
|
#ifndef _INCLUDED_IFF_HPP_
#define _INCLUDED_IFF_HPP_
#include "fixer.h"
#if defined(_WIN32) || defined(WIN32) || defined(WINDOWS) || defined(_WINDOWS)
#define _IFF_WIN_TARGET
#include <windows.h>
#else // ! WIN32 && ! _WIN32 && ! WINDOWS && ! _WINDOWS
#include <stdio.h>
#endif // ! WIN32 && ! _WIN32 && ! WINDOWS && ! _WINDOWS
#include "media.hpp"
namespace IFF
{
/*************************/
/* Class Hierarchy: */
/* */
/* + Unknown */
/* + SerializableObj */
/* + GenericFile */
/* + File */
/* + Chunk */
/* + Composite */
/* + Form */
/* + Cat */
/* + List */
/* + Prop */
/* + MiscChunk */
/* + <user chunks> */
/* + Arvhive */
/* + ArchvIn */
/* + ArchvOut(*) */
/* + DataBlock */
/* + DataNode */
/* + SerialData */
/* + ArchvOut(*) */
/* + ChildNode */
/* + DeviceHandle */
/*************************/
#ifdef _IFF_WIN_TARGET
inline void DisplayMessage(TCHAR const * pszTitle,TCHAR const * pszText)
{
::MessageBox(NULL,pszText,pszTitle,MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND);
}
#else
inline void DisplayMessage(char const * pszTitle,char const * pszText)
{
::printf("DisplayMessage\n%s\n%s\n",pszTitle,pszText);
/*
while (::kbhit())
::getch();
while (!::kbhit() || '\r' != ::getch())
;
*/
}
#endif
// forward refs
//class Unknown;
//class SerializableObj;
//class GenericFile;
//class File;
//class Chunk;
class Composite;
//class Form;
//class Cat;
//class List;
//class Prop;
//class MiscChunk;
//class Archive;
//class ArchvIn;
//class ArchvOut;
//class DataBlock;
//class DataNode;
//class SerialData;
class ChildNode;
//class DeviceHandle;
/*****************************/
/* Original File: iffObj.hpp */
/*****************************/
class Unknown
{
public:
unsigned AddRef() { return ++m_nRefCnt; }
unsigned Release() { if (0==(--m_nRefCnt)) { delete this; return 0;} else return m_nRefCnt; }
protected:
virtual ~Unknown() {
#ifndef NDEBUG
DbForget(this);
#endif
}
Unknown() : m_nRefCnt(1) {
#ifndef NDEBUG
DbRemember(this);
#endif
}
Unknown(Unknown const &) : m_nRefCnt(1) {
#ifndef NDEBUG
DbRemember(this);
#endif
}
private:
unsigned m_nRefCnt;
#ifndef NDEBUG
friend void DbRemember(Unknown * pObj);
friend void DbForget(Unknown * pObj);
friend class AllocList;
#endif
};
/*******************************/
/* Original File: iffTypes.hpp */
/*******************************/
// deal with any silly bastard who's put #define BYTE ... in a header, etc.
#ifdef BYTE
#undef BYTE
#pragma message("BYTE was defined - undefining")
#endif
typedef int8_t BYTE;
typedef uint8_t UBYTE;
typedef int16_t INT16;
typedef uint16_t UINT16;
typedef int32_t INT32;
typedef uint32_t UINT32;
typedef int64_t INT64;
typedef uint64_t UINT64;
struct RGBTriple
{
UBYTE r;
UBYTE g;
UBYTE b;
};
union ID
{
UINT32 m_nID;
char m_sID[4];
inline ID(){}
inline ID(char const * pszID) { m_nID = *reinterpret_cast<UINT32 const *>(pszID); }
inline ID(UINT32 nID) : m_nID(nID) {}
inline operator UINT32 () const { return m_nID; }
inline operator char const * () const { return &m_sID[0]; }
inline bool operator == (ID const & rId) const { return !m_nID || !rId.m_nID || m_nID == rId.m_nID; }
inline bool operator != (ID const & rId) const { return ! operator == (rId); }
inline bool operator ! () const { return !m_nID; }
};
ID const ID_ANY(0U);
#ifndef IFF_READ_ONLY
/*******************************/
/* Original File: iffSData.hpp */
/*******************************/
class DataBlock : public Unknown
{
public:
virtual ~DataBlock();
DataBlock() : m_pBlock(new UBYTE [128]), m_nMaxSize(128), m_nCurSize(0) {}
unsigned GetDataSize() const;
UBYTE const * GetDataPtr() const;
bool WriteToFile(::MediaMedium * pMedium) const;
void Append(UBYTE byte);
void Append(void const * pData, unsigned nSize);
private:
void Expand(unsigned nMinSize);
UBYTE * m_pBlock;
unsigned m_nMaxSize;
unsigned m_nCurSize;
};
inline unsigned DataBlock::GetDataSize() const
{
return m_nCurSize;
}
inline UBYTE const * DataBlock::GetDataPtr() const
{
return m_pBlock;
}
inline void DataBlock::Append(UBYTE byte)
{
if (m_nCurSize >= m_nMaxSize)
Expand(m_nCurSize+1);
m_pBlock[m_nCurSize++] = byte;
}
inline void DataBlock::Append(void const * pData, unsigned nSize)
{
if (m_nCurSize+nSize > m_nMaxSize)
Expand(m_nCurSize+nSize+32);
memcpy(&m_pBlock[m_nCurSize],pData,nSize);
m_nCurSize += nSize;
}
class DataNode : public Unknown
{
public:
DataNode(DataNode * pNext, DataBlock * pData, DataNode * pPrev)
: m_pNext(pNext)
, m_pData(pData)
, m_pPrev(pPrev)
{
if (pNext) pNext->AddRef();
if (pData) pData->AddRef();
if (pPrev) pPrev->AddRef();
}
virtual ~DataNode();
unsigned GetDataSize() const;
bool WriteToFile(::MediaMedium * pMedium) const;
private:
DataNode * m_pNext;
DataBlock * m_pData;
DataNode * m_pPrev;
};
class SerialData : public Unknown
{
public:
virtual ~SerialData();
SerialData() : m_pData(new DataBlock), m_pPrev(NULL) {};
void Clear();
unsigned GetDataSize() const;
bool WriteToFile(::MediaMedium * pMedium) const;
void Append(UBYTE byte);
void Append(void const * pData, unsigned nSize);
void Append(SerialData * pData);
private:
DataBlock * m_pData;
DataNode * m_pPrev;
};
inline void SerialData::Append(UBYTE byte)
{
m_pData->Append(byte);
}
inline void SerialData::Append(void const * pData, unsigned nSize)
{
m_pData->Append(pData,nSize);
}
inline void SerialData::Append(SerialData * pIns)
{
DataNode * pNewNode = new DataNode(pIns->m_pPrev,m_pData,m_pPrev);
m_pData->Release();
m_pData = pIns->m_pData;
pIns->m_pData->AddRef();
if (m_pPrev)
m_pPrev->Release();
m_pPrev = pNewNode;
}
/*******************************/
/* Original File: iffArchv.hpp */
/*******************************/
class Archive : public Unknown
{
public:
// constructor - construct with true iff the archive is for loading data
Archive(bool bIsLoading) : m_bIsLoading(bIsLoading), m_bError(false) {}
// to determine easily whenever necessary if the archive is loading data
bool const m_bIsLoading;
bool m_bError;
// returns either the size in bytes of the data so far written to a storing archive
// or the number of bytes remaining to be read from a loading archive, could be negative
// if too many bytes were read
virtual signed GetSize() const = 0;
// if the archive is loading, nSize bytes are sectioned off to be read from a sub-archive
// or if the archive is storing, nSize is ignored and data written to the sub-archive
// will be stored when the sub-archive is closed
virtual Archive * OpenSubArchive(unsigned nSize = 0) = 0;
// commits data written temporarily to a sub-archive (if storing)
// and advances the archive to the next byte after the sub-archive's data
virtual void CloseSubArchive(Archive * pSub) = 0;
virtual void Open(::MediaMedium * pMedium) = 0;
virtual void Close() = 0;
virtual void Transfer(RGBTriple &) = 0;
virtual void Transfer(BYTE &) = 0;
virtual void Transfer(UBYTE &) = 0;
virtual void Transfer(INT16 &) = 0;
virtual void Transfer(UINT16 &) = 0;
virtual void Transfer(INT32 &) = 0;
virtual void Transfer(UINT32 &) = 0;
virtual void Transfer(INT64 &) = 0;
virtual void Transfer(UINT64 &) = 0;
virtual void Transfer(ID &) = 0;
virtual void TransferBlock(void * pData,unsigned nSize) = 0;
};
/*******************************/
/* Original File: iffArchO.hpp */
/*******************************/
class ArchvOut : public Archive, public SerialData
{
public:
ArchvOut() : Archive(false), m_pMedium(NULL) {}
~ArchvOut();
signed GetSize() const;
Archive * OpenSubArchive(unsigned nSize = 0);
void CloseSubArchive(Archive * pSub);
void Open(::MediaMedium * pMedium);
void Close();
void Transfer(RGBTriple &);
void Transfer(BYTE &);
void Transfer(UBYTE &);
void Transfer(INT16 &);
void Transfer(UINT16 &);
void Transfer(INT32 &);
void Transfer(UINT32 &);
void Transfer(INT64 &);
void Transfer(UINT64 &);
void Transfer(ID &);
void TransferBlock(void * pData,unsigned nSize);
private:
::MediaMedium * m_pMedium;
};
inline signed ArchvOut::GetSize() const
{
return GetDataSize();
}
inline void ArchvOut::Transfer(RGBTriple & n)
{
Append(n.r);
Append(n.g);
Append(n.b);
}
inline void ArchvOut::Transfer(BYTE & n)
{
Append(n);
}
inline void ArchvOut::Transfer(UBYTE & n)
{
Append(n);
}
inline void ArchvOut::Transfer(INT16 & n)
{
Append(static_cast<BYTE>(n >> 8));
Append(static_cast<BYTE>(n));
}
inline void ArchvOut::Transfer(UINT16 & n)
{
Append(static_cast<UBYTE>(n >> 8));
Append(static_cast<UBYTE>(n));
}
inline void ArchvOut::Transfer(INT32 & n)
{
Append(static_cast<BYTE>(n >> 24));
Append(static_cast<BYTE>(n >> 16));
Append(static_cast<BYTE>(n >> 8));
Append(static_cast<BYTE>(n));
}
inline void ArchvOut::Transfer(UINT32 & n)
{
Append(static_cast<UBYTE>(n >> 24));
Append(static_cast<UBYTE>(n >> 16));
Append(static_cast<UBYTE>(n >> 8));
Append(static_cast<UBYTE>(n));
}
inline void ArchvOut::Transfer(INT64 & n)
{
Append(static_cast<BYTE>(n >> 56));
Append(static_cast<BYTE>(n >> 48));
Append(static_cast<BYTE>(n >> 40));
Append(static_cast<BYTE>(n >> 32));
Append(static_cast<BYTE>(n >> 24));
Append(static_cast<BYTE>(n >> 16));
Append(static_cast<BYTE>(n >> 8));
Append(static_cast<BYTE>(n));
}
inline void ArchvOut::Transfer(UINT64 & n)
{
Append(static_cast<UBYTE>(n >> 56));
Append(static_cast<UBYTE>(n >> 48));
Append(static_cast<UBYTE>(n >> 40));
Append(static_cast<UBYTE>(n >> 32));
Append(static_cast<UBYTE>(n >> 24));
Append(static_cast<UBYTE>(n >> 16));
Append(static_cast<UBYTE>(n >> 8));
Append(static_cast<UBYTE>(n));
}
inline void ArchvOut::Transfer(ID & n)
{
Append(&n,4);
}
inline void ArchvOut::TransferBlock(void * pData,unsigned nSize)
{
Append(pData,nSize);
}
#endif // ! IFF_READ_ONLY
/*******************************/
/* Original File: iffArchI.hpp */
/*******************************/
#ifdef IFF_READ_ONLY
#define _IFF_ARCHI_BASE Unknown
#define _IFF_ARCHI_GENR ArchvIn
#define _IFF_ARCHI_FLAG m_bIsLoading
#define _IFF_ARCHI_INIT ,m_bError(false)
#else // ! IFF_READ_ONLY
#define _IFF_ARCHI_BASE Archive
#define _IFF_ARCHI_GENR Archive
#define _IFF_ARCHI_FLAG Archive
#define _IFF_ARCHI_INIT
#endif // ! IFF_READ_ONLY
class ArchvIn : public _IFF_ARCHI_BASE
{
public:
ArchvIn() : _IFF_ARCHI_FLAG(true), m_pMedium(NULL) _IFF_ARCHI_INIT {}
~ArchvIn();
#ifdef IFF_READ_ONLY
bool const m_bIsLoading;
bool m_bError;
#endif // IFF_READ_ONLY
signed GetSize() const;
_IFF_ARCHI_GENR * OpenSubArchive(unsigned nSize = 0);
void CloseSubArchive(_IFF_ARCHI_GENR * pSub);
void Open(::MediaMedium * pMedium);
void Close();
void Transfer(RGBTriple &);
void Transfer(BYTE &);
void Transfer(UBYTE &);
void Transfer(INT16 &);
void Transfer(UINT16 &);
void Transfer(INT32 &);
void Transfer(UINT32 &);
void Transfer(INT64 &);
void Transfer(UINT64 &);
void Transfer(ID &);
void TransferBlock(void * pData,unsigned nSize);
private:
ArchvIn(ArchvIn * pParent, unsigned nSize);
::MediaMedium * m_pMedium;
signed m_nBytesRemaining;
unsigned m_nEndPos;
};
#ifdef IFF_READ_ONLY
typedef ArchvIn Archive;
#endif // IFF_READ_ONLY
inline signed ArchvIn::GetSize() const
{
return m_nBytesRemaining;
}
inline void ArchvIn::Transfer(RGBTriple & n)
{
m_nBytesRemaining -= 3;
if (m_nBytesRemaining >= 0)
{
::MediaRead(m_pMedium, &n.r);
::MediaRead(m_pMedium, &n.g);
::MediaRead(m_pMedium, &n.b);
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(UBYTE & n)
{
m_nBytesRemaining -= 1;
if (m_nBytesRemaining >= 0)
{
::MediaRead(m_pMedium, &n);
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(BYTE & n)
{
m_nBytesRemaining -= 1;
if (m_nBytesRemaining >= 0)
{
::MediaRead(m_pMedium, &n);
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(UINT16 & n)
{
m_nBytesRemaining -= 2;
if (m_nBytesRemaining >= 0)
{
UBYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(INT16 & n)
{
m_nBytesRemaining -= 2;
if (m_nBytesRemaining >= 0)
{
BYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(UINT32 & n)
{
m_nBytesRemaining -= 4;
if (m_nBytesRemaining >= 0)
{
UBYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(INT32 & n)
{
m_nBytesRemaining -= 4;
if (m_nBytesRemaining >= 0)
{
BYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(UINT64 & n)
{
m_nBytesRemaining -= 8;
if (m_nBytesRemaining >= 0)
{
UBYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(INT64 & n)
{
m_nBytesRemaining -= 8;
if (m_nBytesRemaining >= 0)
{
BYTE byte;
::MediaRead(m_pMedium, &byte);
n = byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
::MediaRead(m_pMedium, &byte);
n <<= 8;
n |= byte;
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::Transfer(ID & n)
{
m_nBytesRemaining -= 4;
if (m_nBytesRemaining >= 0)
{
// cast pointer to pointer to 4 byte data type to force 4 byte 'fast' read
::MediaRead(m_pMedium, reinterpret_cast<UINT32 *>(&n.m_sID[0]));
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
inline void ArchvIn::TransferBlock(void * pData,unsigned nSize)
{
m_nBytesRemaining -= nSize;
if (m_nBytesRemaining >= 0)
{
m_pMedium->ReadBlock(pData,nSize);
if (m_pMedium->m_fError) m_bError = true;
}
else m_bError = true;
}
/*******************************/
/* Original File: iffSrlOb.hpp */
/*******************************/
class SerializableObj : public Unknown
{
public:
virtual void Serialize(Archive * pArchv) = 0;
};
/*******************************/
/* Original File: iffChunk.hpp */
/*******************************/
class Chunk : public SerializableObj
{
public:
ID m_idCk;
Chunk * GetProperty(ID idProp) const;
virtual bool IsUnknown() const { return false; }
void Write(Archive * pArchv);
static Chunk * Load(ID idParent, Archive * pArchv, ID idChunk = ID_ANY, bool bKnown = true);
static Chunk * DynCreate(ID idParent, ID idChunk);
static void Register(ID idParent, ID idChunk, Chunk * (* pfnCreate) () );
Composite const * GetParent() const { return m_pParent; }
protected:
Chunk() : m_pParent(NULL) {}
private:
Composite const * m_pParent; // mot reference counted
ChildNode const * m_pNode; // not reference counted either
friend class Composite;
};
#define IFF_IMPLEMENT_DYNCREATE(idParent,idChunk,tokenClassName) _IFF_IMPLEMENT_DYNCREATE_LINE_EX(idParent,idChunk,tokenClassName,__LINE__)
#define _IFF_IMPLEMENT_DYNCREATE_LINE_EX(idParent,idChunk,tokenClassName,nLine) _IFF_IMPLEMENT_DYNCREATE_LINE(idParent,idChunk,tokenClassName,nLine)
#define _IFF_IMPLEMENT_DYNCREATE_LINE(idParent,idChunk,tokenClassName,nLine) \
static IFF::Chunk * CreateClassObject ## tokenClassName ##_## nLine () { \
IFF::Chunk * pChunk = new IFF::tokenClassName; \
pChunk->m_idCk = idChunk; \
return pChunk; \
} \
class RegisterChunkClass ## tokenClassName ##_## nLine { \
public: RegisterChunkClass ## tokenClassName ##_## nLine () { \
IFF::Chunk::Register(idParent , idChunk , CreateClassObject ## tokenClassName ##_## nLine); \
} \
} rcc ## tokenClassName ##_## nLine;
/*******************************/
/* Original File: iffBlock.hpp */
/*******************************/
class ChildNode : public Unknown
{
public:
Chunk * GetChunk() const { return m_pChunk; }
private:
ChildNode * m_pNext;
ChildNode * m_pPrev;
Chunk * m_pChunk;
friend class Composite;
};
class Composite : public Chunk
{
public:
ID m_idData;
Composite() : m_pFirst(NULL), m_pLast(NULL) {}
virtual ~Composite();
ChildNode * GetFirstChild() const { return m_pFirst; }
ChildNode * GetFirstChild(ID idMatch) const;
ChildNode * GetLastChild() const { return m_pLast; }
ChildNode * GetLastChild(ID idMatch) const;
static ChildNode * GetNextChild(ChildNode const * pNode) { return pNode->m_pNext; }
static ChildNode * GetNextChild(ChildNode const * pNode, ID idMatch);
static ChildNode * GetPrevChild(ChildNode const * pNode) { return pNode->m_pPrev; }
static ChildNode * GetPrevChild(ChildNode const * pNode, ID idMatch);
Chunk * GetProperty(ChildNode const * pNode, ID idProp) const;
void DeleteChild(ChildNode * pNode);
void DeleteAllChildren();
ChildNode * InsertChildFirst(Chunk * pChunk);
ChildNode * InsertChildLast(Chunk * pChunk);
ChildNode * InsertChildAfter(ChildNode * pNode, Chunk * pChunk);
ChildNode * InsertChildBefore(ChildNode * pNode, Chunk * pChunk);
// pfnCallback should return true to continue the enumeration, false to finish
virtual bool EnumChildren(ID idData, ID idChunk, bool (* pfnCallback) (Chunk *, void *), void * pData) const;
protected:
virtual void Serialize(Archive * pArchv);
virtual Chunk * LoadChunk(Archive * pArchv) const;
virtual bool IsValidChildID(ID id) const;
private:
ChildNode * m_pFirst;
ChildNode * m_pLast;
};
class Form : public Composite
{
public:
Form() { m_idCk = "FORM"; }
protected:
virtual bool IsValidChildID(ID id) const;
};
class Cat : public Composite
{
public:
Cat() { m_idCk = "CAT "; }
virtual bool EnumChildren(ID idData, ID idChunk, bool (* pfnCallback) (Chunk *, void *), void * pData) const;
protected:
virtual bool IsValidChildID(ID id) const;
};
class List : public Composite
{
public:
List() { m_idCk = "LIST"; }
virtual bool EnumChildren(ID idData, ID idChunk, bool (* pfnCallback) (Chunk *, void *), void * pData) const;
protected:
virtual bool IsValidChildID(ID id) const;
};
class Prop : public Composite
{
public:
Prop() { m_idCk = "PROP"; }
protected:
virtual bool IsValidChildID(ID id) const;
};
/*******************************/
/* Original File: iffMscCk.hpp */
/*******************************/
class MiscChunk : public Chunk
{
public:
MiscChunk(ID id)
#ifndef IFF_READ_ONLY
: m_pData(NULL)
#endif // ! IFF_READ_ONLY
{
m_idCk = id;
}
virtual bool IsUnknown() const { return true; }
protected:
virtual void Serialize(Archive * pArchv);
#ifndef IFF_READ_ONLY
virtual ~MiscChunk();
#endif // ! IFF_READ_ONLY
private:
#ifndef IFF_READ_ONLY
BYTE * m_pData;
unsigned m_nSize;
#endif // ! IFF_READ_ONLY
};
/******************************/
/* Original File: iffFile.hpp */
/******************************/
class GenericFile : public SerializableObj
{
public:
#ifndef IFF_READ_ONLY
GenericFile() : m_pszFileName(NULL) {}
virtual ~GenericFile() { if (m_pszFileName) delete[] m_pszFileName; }
#endif
bool Load(TCHAR const * pszFileName);
bool Load(::MediaMedium * pMedium);
#ifndef IFF_READ_ONLY
bool Write(TCHAR const * pszFileName = NULL);
bool Write(::MediaMedium * pMedium);
#endif // ! IFF_READ_ONLY
private:
#ifndef IFF_READ_ONLY
TCHAR * m_pszFileName;
#endif // ! IFF_READ_ONLY
};
class File : public GenericFile
{
public:
virtual ~File();
File() : m_pContents(NULL) {}
Composite * GetContents() const;
void SetContents(Composite * pContents);
protected:
virtual void Serialize(Archive * pArchv);
private:
ID m_idType;
Composite * m_pContents;
};
inline Composite * File::GetContents() const
{
return m_pContents;
}
inline void File::SetContents(Composite * pContents)
{
if (m_pContents) m_pContents->Release();
if (pContents)
{
pContents->AddRef();
m_idType = pContents->m_idCk;
}
m_pContents = pContents;
}
// Have a static object of this in each file:
// It will detect if some files are compiled with
// IFF_READ_ONLY defined differently to each other
static class ConsistencyCheck
{
public: inline ConsistencyCheck()
{
#ifdef IFF_READ_ONLY
static bool bReadOnly = true;
if (!bReadOnly)
#else
static bool bReadOnly = false;
if (bReadOnly)
#endif
{
DisplayMessage
(
#ifdef NDEBUG
TEXT("Error"),
TEXT("IFF_READ_ONLY definition not consistent")
#else
TEXT("IFF Compile Option Error"),
TEXT("Some files which #include \"iff.hpp\"\n")
TEXT("have the macro IFF_READ_ONLY defined\n")
TEXT("and some don't.\n\n")
TEXT("Please ensure this is consistent and recompile.")
#endif
);
exit(-45);
}
}
}
consistencyCheck;
} // namespace IFF
#endif // ! _INCLUDED_IFF_HPP_
|