#ifndef CONFIG_CONFIG_TYPE_POINTER_H #define CONFIG_CONFIG_TYPE_POINTER_H #include #include #include struct ConfigValue; class ConfigTypePointer : public ConfigType { std::map pointers_; public: ConfigTypePointer(void) : ConfigType("pointer"), pointers_() { } ~ConfigTypePointer() { pointers_.clear(); } bool get(const ConfigValue *cv, ConfigObject **cop) const { std::map::const_iterator it; it = pointers_.find(cv); if (it == pointers_.end()) { ERROR("/config/type/pointer") << "Value not set."; return (false); } ConfigObject *co = it->second; if (co == NULL) { *cop = NULL; return (true); } *cop = co; return (true); } template bool get(const ConfigValue *cv, ConfigObject **cop, T **ccp) const { std::map::const_iterator it; it = pointers_.find(cv); if (it == pointers_.end()) { ERROR("/config/type/pointer") << "Value not set."; return (false); } ConfigObject *co = it->second; if (co == NULL) { *cop = NULL; *ccp = NULL; return (true); } T *cc = co->coerce(); if (cc == NULL) { ERROR("/config/type/pointer") << "Pointer to object of wrong type."; return (false); } *cop = co; *ccp = cc; return (true); } void marshall(ConfigExporter *, const ConfigValue *) const; bool set(const ConfigValue *, const std::string&); }; extern ConfigTypePointer config_type_pointer; #endif /* !CONFIG_CONFIG_TYPE_POINTER_H */