00001 /* 00002 ** Configurable.h 00003 ** 00004 ** TConfigurable is an abstract base class for classes that must receive 00005 ** and process configuration file lines. That includes 00006 ** virtually all module internal objects, however, it is 00007 ** not absolute that all such objects will handle the lines. 00008 */ 00009 //--------------------------------------------------------------------------- 00010 #ifndef _WORM_CONFIGURABLE_H 00011 #define _WORM_CONFIGURABLE_H 00012 //--------------------------------------------------------------------------- 00013 #include <worm_defs.h> 00014 #include <worm_statuscode.h> 00015 #include "configsource.h" 00016 00017 00018 /* 00019 ** Handler Status -- commonly for configuration line handling 00020 */ 00021 enum HANDLE_STATUS 00022 { 00023 HANDLER_INVALID = -1 00024 , HANDLER_UNUSED = 0 00025 , HANDLER_USED = 1 00026 }; 00027 00028 00029 class TConfigurable 00030 { 00031 protected: 00032 /* Rather than requiring the implementing class to maintain its own state 00033 ** flag element, store it in this base class. 00034 ** Rather than a bool, using a WORM_STATUS_CODE to enable the state to be 00035 ** WORM_STAT_NOTINIT = IsReady() not yet called 00036 ** WORM_STAT_BADSTATE = one of the derivative classes found an error 00037 ** or WORM_STAT_SUCCESS = none of the derivative classes found an error 00038 ** 00039 ** Implemented as a global variable to simplify state checking across 00040 ** multiple objects. 00041 ** Essentially, configuration state should only be checked one time per 00042 ** program execution. 00043 */ 00044 WORM_STATUS_CODE ConfigState; 00045 00046 /* CheckConfig() -- allows derivative classes to report the status of their 00047 ** the lookup values. 00048 ** 00049 ** From within any deriving class, or further derivation, ALWAYS contain a call to 00050 ** <super_class>::CheckConfig() in their own CheckConfig() method... 00051 ** this ensures that all classes in the heirarchy get their chance to report status. 00052 ** 00053 ** All implementations should set ConfigStatus value to WORM_STAT_BADSTATE if there 00054 ** is a configuration problem, otherwise leave it alone. 00055 */ 00056 virtual void CheckConfig() { }; 00057 00058 public: 00059 TConfigurable(); 00060 00061 /* 00062 ** HandleConfigLine() 00063 ** 00064 ** PARMS: 00065 ** p_parser -- the parser being used, command string already 00066 ** in the current token for comparison with Its() 00067 ** 00068 ** RETURN: 00069 ** HANDLE_INVALID -- line invalid 00070 ** HANDLE_UNUSED -- line not used 00071 ** HANDLE_USED -- line used okay 00072 ** 00073 ** Override for child classes to handle command lines 00074 ** 00075 */ 00076 virtual HANDLE_STATUS HandleConfigLine( ConfigSource * p_parser ); 00077 00078 /* IsReady() -- is the internal element configured and ready to use? 00079 ** 00080 ** RETURNS: true | false 00081 ** 00082 ** Override CheckConfig() rather than the IsReady() method. 00083 */ 00084 bool IsReady(); 00085 }; 00086 00087 00088 #endif 00089