context.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _SERVERCONFIG_CONTEXT_H_
00022 #define _SERVERCONFIG_CONTEXT_H_
00023
00024 #include "confignode.h"
00025
00026 namespace container{
00027 namespace serverconfig {
00028
00029 class ServerConfig;
00030
00039 enum paramflags_t
00040 {
00041 PARAM_NONE=0,
00042 PARAM_REQUIRED=0x1,
00043 PARAM_INHERITABLE=0x2,
00044 PARAM_SINGLE_OF_TYPE=0x4,
00045 PARAM_SINGLE_OF_NAME=0x8,
00046 };
00047
00051 class Context
00052 {
00053 public:
00054 class UnsetParam
00055 {
00056 int m_flags;
00057 public:
00058 UnsetParam(int flags=PARAM_NONE):m_flags(flags){}
00059 bool required() const {return m_flags & PARAM_REQUIRED;}
00060 bool inheritable() const {return m_flags & PARAM_INHERITABLE;}
00061 int flags() const {return m_flags;}
00062 };
00063 class CfgParamList: public std::list<ConfigNode>
00064 {
00065 public:
00066 int m_flags;
00067 public:
00068 bool add(const ConfigNode& node);
00069 };
00070 typedef CfgParamList cfgparamlist_t;
00071 typedef std::map<std::string,cfgparamlist_t> params_t;
00072 typedef std::list<Context*> ctxlist_t;
00073 typedef std::map<std::string,UnsetParam> unsetparams_t;
00074 private:
00075 ctxlist_t m_kids;
00076 params_t m_params;
00077 std::string m_type;
00078 std::string m_name;
00079 Context* m_parent;
00080 unsetparams_t m_unsetParams;
00081 ServerConfig& m_cfg;
00082 protected:
00087 virtual bool onPreComplete(){ return true; }
00092 virtual bool onPostComplete(){ return true; }
00093 virtual bool onSetParam(const ConfigNode& val)=0;
00101 virtual Context* getContext(const ConfigNode&)=0;
00102 unsetparams_t& getUnsetParams() {return m_unsetParams;}
00108 static bool setString(const ConfigNode&, std::string&);
00109 public:
00110 Context(ServerConfig& cfg, Context* parent)
00111 : m_parent(parent)
00112 , m_cfg(cfg)
00113 {}
00114 virtual ~Context();
00115 bool complete();
00116 const cfgparamlist_t* getParam(const std::string& type) const;
00117 bool setParam(const ConfigNode&);
00118 const std::string& getName() const {return m_name;}
00119 const std::string& getType() const {return m_type;}
00120 ServerConfig& getServerConfig() { return m_cfg; }
00128 bool process(ServerConfig&, ConfigNode*);
00129 void addChildContext(Context* ctx);
00136 bool setIgnore (const ConfigNode&)
00137 {return true;}
00141 Context* getParent()
00142 {return m_parent;}
00143 };
00144
00145 }
00146 }
00147 #endif //_SERVERCONFIG_CONTEXT_H_