00001 #include <qpro/common.h>
00002
00003 #include <iostream>
00004
00005 #include <qpro/record_factory.h>
00006
00007 #define NEWFUNC(x) static QpRec* NEW_##x (QP_INT16 pLen, QpIStream& pIn) { return new x (pLen, pIn); }
00008
00009 NEWFUNC(QpRecBof)
00010 NEWFUNC(QpRecBop)
00011 NEWFUNC(QpRecEof)
00012 NEWFUNC(QpRecEmptyCell)
00013 NEWFUNC(QpRecFloatingPointCell)
00014 NEWFUNC(QpRecFormulaCell)
00015 NEWFUNC(QpRecIntegerCell)
00016 NEWFUNC(QpRecLabelCell)
00017 NEWFUNC(QpRecPageName)
00018 NEWFUNC(QpRecPassword)
00019 NEWFUNC(QpRecRecalcMode)
00020 NEWFUNC(QpRecRecalcOrder)
00021
00022 struct Record
00023 {
00024 QP_INT16 Type;
00025 QP_INT16 Len;
00026 QpRec* (*Func)(QP_INT16, QpIStream&);
00027 };
00028
00029
00030
00031
00032
00033 static Record gRecord[] =
00034 {
00035 {QpBof, 2, NEW_QpRecBof},
00036 {QpEof, 0, NEW_QpRecEof},
00037 {QpRecalcMode, 1, NEW_QpRecRecalcMode},
00038 {QpRecalcOrder, 1, NEW_QpRecRecalcOrder},
00039 {QpEmptyCell, 6, NEW_QpRecEmptyCell},
00040 {QpIntegerCell, 8, NEW_QpRecIntegerCell},
00041 {QpFloatingPointCell, 14, NEW_QpRecFloatingPointCell},
00042 {QpLabelCell, 0, NEW_QpRecLabelCell},
00043 {QpFormulaCell, 0, NEW_QpRecFormulaCell},
00044 {QpBop, 0, NEW_QpRecBop},
00045 {QpPageName, 0, NEW_QpRecPageName},
00046 {QpPassword, 0, NEW_QpRecPassword},
00047 {0, 0, 0}
00048 };
00049
00050 QpRecFactory::QpRecFactory(QpIStream& pIn)
00051 : cIn(pIn)
00052 {
00053 }
00054
00055 QpRecFactory::~QpRecFactory()
00056 {
00057 }
00058
00059 QpRec*
00060 QpRecFactory::nextRecord()
00061 {
00062 QP_INT16 lType;
00063 QP_INT16 lLen;
00064 QpRec* lResult=0;
00065
00066 cIn >> lType >> lLen;
00067
00068 for( Record* lRecord=gRecord; lResult == 0 ; ++lRecord )
00069 {
00070 if( lRecord->Func == 0 )
00071 {
00072 lResult = new QpRecUnknown( lType, lLen, cIn );
00073 }
00074 else
00075 if( lRecord->Type == lType )
00076 {
00077
00078 lResult = lRecord->Func(lLen, cIn);
00079 }
00080 }
00081
00082 return lResult;
00083 }