[r5]: / Tags / The -Abstract Factory- Pattern / Abstract Factory1.project  Maximize  Restore  History

Download this file

171 lines (125 with data), 141.9 kB

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR

-------------------------------------------------------------------------------
FB_CsvLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_CsvLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('csv-', sMsg);
// open csv file
// write the message into the csv file
// close csv file
-------------------------------------------------------------------------------
FB_TxtLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_TxtLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('txt-', sMsg);
// open txt file
// write the message into the txt file
// close txt file
-------------------------------------------------------------------------------
FB_Logger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_Logger

VAR
    pTxtLogger: pointer;
    pCsvLogger: pointer;
    pXmlLogger: pointer;
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
IF (ipLogger <> 0) THEN
	Write := ipLogger.Write(CONCAT('logger: ', sMsg));
END_IF

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    sFilename: string;
END_VAR

VAR
    sFilenameExtension: string;
END_VAR
sFilenameExtension := RIGHT(sFilename, 3); // no more lowercase
IF (sFilenameExtension = 'txt') THEN
    pTxtLogger := __NEW(FB_TxtLogger);
    ipLogger := pTxtLogger^;
ELSIF (sFilenameExtension = 'csv') THEN
    pCsvLogger := __NEW(FB_CsvLogger);
    ipLogger := pCsvLogger^;
ELSIF (sFilenameExtension = 'xml') THEN
    pXmlLogger := __NEW(FB_XmlLogger);
    ipLogger := pXmlLogger^;
ELSE
    ipLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_exit
-------------------------------------------------------------------------------


METHOD FB_exit: BOOL

VAR_INPUT
    bInCopyCode: BOOL;
END_VAR
IF (pTxtLogger <> 0) THEN
	__DELETE(pTxtLogger);
	pTxtLogger := 0;
END_IF

IF (pCsvLogger <> 0) THEN
	__DELETE(pCsvLogger);
	pCsvLogger := 0;
END_IF

IF (pXmlLogger <> 0) THEN
	__DELETE(pXmlLogger);
	pXmlLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_XmlLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_XmlLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('xml-', sMsg);
// open xml file
// write the message into the xml file
// close xml file

-------------------------------------------------------------------------------
MAIN
-------------------------------------------------------------------------------


PROGRAM MAIN

VAR
    fbLogger: FB_Logger;
    retMsg: string;
END_VAR
retMsg := fbLogger.Write('Hello');