record_factory.cpp
1#include <qpro/common.h>
2
3#include <iostream>
4
5#include <qpro/record_factory.h>
6
7#define NEWFUNC(x) static QpRec* NEW_##x (TQP_INT16 pLen, QpIStream& pIn) { return new x (pLen, pIn); }
8
9NEWFUNC(QpRecBof)
10NEWFUNC(QpRecBop)
11NEWFUNC(QpRecEof)
12NEWFUNC(QpRecEmptyCell)
13NEWFUNC(QpRecFloatingPointCell)
14NEWFUNC(QpRecFormulaCell)
15NEWFUNC(QpRecIntegerCell)
16NEWFUNC(QpRecLabelCell)
17NEWFUNC(QpRecPageName)
18NEWFUNC(QpRecPassword)
19NEWFUNC(QpRecRecalcMode)
20NEWFUNC(QpRecRecalcOrder)
21
22struct Record
23{
24 TQP_INT16 Type;
25 TQP_INT16 Len;
26 QpRec* (*Func)(TQP_INT16, QpIStream&);
27};
28
29
30// The functions in the Record table below (NEW_QpRecBof etc.)
31// come from the NEWFUNC #define above
32
33static Record gRecord[] =
34{
35 {QpBof, 2, NEW_QpRecBof},
36 {QpEof, 0, NEW_QpRecEof},
37 {QpRecalcMode, 1, NEW_QpRecRecalcMode},
38 {QpRecalcOrder, 1, NEW_QpRecRecalcOrder},
39 {QpEmptyCell, 6, NEW_QpRecEmptyCell},
40 {QpIntegerCell, 8, NEW_QpRecIntegerCell},
41 {QpFloatingPointCell, 14, NEW_QpRecFloatingPointCell},
42 {QpLabelCell, 0, NEW_QpRecLabelCell},
43 {QpFormulaCell, 0, NEW_QpRecFormulaCell},
44 {QpBop, 0, NEW_QpRecBop},
45 {QpPageName, 0, NEW_QpRecPageName},
46 {QpPassword, 0, NEW_QpRecPassword},
47 {0, 0, 0}
48};
49
50QpRecFactory::QpRecFactory(QpIStream& pIn)
51 : cIn(pIn)
52{
53}
54
55QpRecFactory::~QpRecFactory()
56{
57}
58
59QpRec*
60QpRecFactory::nextRecord()
61{
62 TQP_INT16 lType;
63 TQP_INT16 lLen;
64 QpRec* lResult=0;
65
66 cIn >> lType >> lLen;
67
68 for( Record* lRecord=gRecord; lResult == 0 ; ++lRecord )
69 {
70 if( lRecord->Func == 0 )
71 {
72 lResult = new QpRecUnknown( lType, lLen, cIn );
73 }
74 else
75 if( lRecord->Type == lType )
76 {
77 // ??? check length
78 lResult = lRecord->Func(lLen, cIn);
79 }
80 }
81
82 return lResult;
83}