X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/fe9860ffc1555d5bf5a3f2132d9d073b5da85226..67eb91cd2fafdf89ba670706e684ab0cd74ae513:/include/stg/user_property.h diff --git a/include/stg/user_property.h b/include/stg/user_property.h index fbd6aa46..7c0f4da1 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -12,6 +12,7 @@ $Author: faust $ #include #include #include +#include #include #include @@ -24,11 +25,15 @@ $Author: faust $ #include "notifer.h" #include "noncopyable.h" -extern const volatile time_t stgTime; - +extern volatile time_t stgTime; +//----------------------------------------------------------------------------- +class USER_PROPERTY_BASE { +public: + virtual std::string ToString() const = 0; +}; //----------------------------------------------------------------------------- template -class USER_PROPERTY { +class USER_PROPERTY : public USER_PROPERTY_BASE { public: USER_PROPERTY(varT & val); virtual ~USER_PROPERTY(); @@ -43,14 +48,15 @@ public: operator const varT&() const throw() { return value; } void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); - void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); + void DelBeforeNotifier(const PROPERTY_NOTIFIER_BASE * n); void AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n); - void DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n); + void DelAfterNotifier(const PROPERTY_NOTIFIER_BASE * n); time_t ModificationTime() const throw() { return modificationTime; } void ModifyTime() throw(); + std::string ToString() const; private: varT & value; time_t modificationTime; @@ -67,7 +73,8 @@ public: bool isPassword, bool isStat, STG_LOGGER & logger, - const std::string & sd); + const std::string & sd, + std::map & properties); virtual ~USER_PROPERTY_LOGGED() {} USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } @@ -117,6 +124,7 @@ private: USER_STAT stat; USER_CONF conf; + std::map properties; public: USER_PROPERTIES(const std::string & sd); @@ -129,6 +137,9 @@ public: void SetProperties(const USER_PROPERTIES & p) { stat = p.stat; conf = p.conf; } + std::string GetPropertyValue(const std::string & name) const; + bool Exists(const std::string & name) const; + USER_PROPERTY_LOGGED cash; USER_PROPERTY_LOGGED up; USER_PROPERTY_LOGGED down; @@ -236,10 +247,10 @@ beforeNotifiers.insert(n); //----------------------------------------------------------------------------- template inline -void USER_PROPERTY::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) +void USER_PROPERTY::DelBeforeNotifier(const PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); -beforeNotifiers.erase(n); +beforeNotifiers.erase(const_cast *>(n)); } //----------------------------------------------------------------------------- template @@ -252,10 +263,10 @@ afterNotifiers.insert(n); //----------------------------------------------------------------------------- template inline -void USER_PROPERTY::DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n) +void USER_PROPERTY::DelAfterNotifier(const PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); -afterNotifiers.erase(n); +afterNotifiers.erase(const_cast *>(n)); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -267,7 +278,8 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, bool isPass, bool isSt, STG_LOGGER & logger, - const std::string & sd) + const std::string & sd, + std::map & properties) : USER_PROPERTY(val), stgLogger(logger), @@ -276,6 +288,7 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, name(n), scriptsDir(sd) { +properties.insert(std::make_pair(name, this)); } //------------------------------------------------------------------------- template @@ -295,8 +308,8 @@ if ((priv->userConf && !isStat) || std::stringstream oldVal; std::stringstream newVal; - oldVal.flags(oldVal.flags() | ios::fixed); - newVal.flags(newVal.flags() | ios::fixed); + oldVal.flags(oldVal.flags() | std::ios::fixed); + newVal.flags(newVal.flags() | std::ios::fixed); oldVal << USER_PROPERTY::ConstData(); newVal << val; @@ -375,12 +388,36 @@ else //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- +inline +std::string USER_PROPERTIES::GetPropertyValue(const std::string & name) const +{ +std::map::const_iterator it = properties.find(name); +if (it == properties.end()) + return ""; +return it->second->ToString(); +} +//----------------------------------------------------------------------------- +inline +bool USER_PROPERTIES::Exists(const std::string & name) const +{ +return properties.find(name) != properties.end(); +} +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- template inline -ostream & operator<< (ostream & stream, const USER_PROPERTY & value) +std::ostream & operator<< (std::ostream & stream, const USER_PROPERTY & value) { return stream << value.ConstData(); } //----------------------------------------------------------------------------- - +template +inline +std::string USER_PROPERTY::ToString() const +{ +std::ostringstream stream; +stream << value; +return stream.str(); +} #endif // USER_PROPERTY_H