X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9596c437646f369c3924dc78b20872762f3a47b9..b6dc7c53f5374b1798d74fe752e962266645cca0:/include/user_property.h diff --git a/include/user_property.h b/include/user_property.h index b269389a..78e5675a 100644 --- a/include/user_property.h +++ b/include/user_property.h @@ -7,6 +7,8 @@ $Author: faust $ #ifndef USER_PROPERTY_H #define USER_PROPERTY_H +#include // access + #include #include #include @@ -19,6 +21,7 @@ $Author: faust $ #include "stg_logger.h" #include "stg_locker.h" #include "script_executer.h" +#include "noncopyable.h" extern const volatile time_t stgTime; @@ -32,15 +35,11 @@ public: void Set(const varT & rvalue); USER_PROPERTY & operator= (const varT & rvalue); - USER_PROPERTY & operator-= (const varT & rvalue); - const varT * operator&() const throw(); - const varT & ConstData() const throw(); + const varT * operator&() const throw() { return &value; } + const varT & ConstData() const throw() { return value; } - operator const varT&() const throw() - { - return value; - } + operator const varT&() const throw() { return value; } void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); @@ -48,7 +47,7 @@ public: void AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n); void DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n); - time_t ModificationTime() const throw(); + time_t ModificationTime() const throw() { return modificationTime; } void ModifyTime() throw(); private: @@ -63,16 +62,16 @@ template class USER_PROPERTY_LOGGED: public USER_PROPERTY { public: USER_PROPERTY_LOGGED(varT & val, - const std::string n, + const std::string & n, bool isPassword, bool isStat, STG_LOGGER & logger, const std::string & sd); - virtual ~USER_PROPERTY_LOGGED(); + virtual ~USER_PROPERTY_LOGGED() {} - USER_PROPERTY_LOGGED * GetPointer() throw(); - const varT & Get() const; - const std::string & GetName() const; + USER_PROPERTY_LOGGED * GetPointer() throw() { return this; } + const varT & Get() const { return USER_PROPERTY::ConstData(); } + const std::string & GetName() const { return name; } bool Set(const varT & val, const ADMIN * admin, const std::string & login, @@ -104,7 +103,7 @@ private: const std::string scriptsDir; }; //----------------------------------------------------------------------------- -class USER_PROPERTIES { +class USER_PROPERTIES : private NONCOPYABLE { /* В этом месте важен порядок следования приватной и открытой частей. Это связано с тем, что часть которая находится в публичной секции @@ -171,25 +170,30 @@ public: //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- template +inline USER_PROPERTY::USER_PROPERTY(varT & val) - : value(val) + : value(val), + modificationTime(stgTime) { pthread_mutex_init(&mutex, NULL); -modificationTime = stgTime; } //----------------------------------------------------------------------------- template +inline USER_PROPERTY::~USER_PROPERTY() { +pthread_mutex_destroy(&mutex); } //----------------------------------------------------------------------------- template +inline void USER_PROPERTY::ModifyTime() throw() { modificationTime = stgTime; } //----------------------------------------------------------------------------- template +inline void USER_PROPERTY::Set(const varT & rvalue) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); @@ -211,6 +215,7 @@ while (ni != afterNotifiers.end()) } //----------------------------------------------------------------------------- template +inline USER_PROPERTY & USER_PROPERTY::operator= (const varT & newValue) { Set(newValue); @@ -218,26 +223,7 @@ return *this; } //----------------------------------------------------------------------------- template -USER_PROPERTY& USER_PROPERTY::operator-= (const varT & delta) -{ -varT newValue = ConstData() - delta; -Set(newValue); -return *this; -} -//----------------------------------------------------------------------------- -template -const varT * USER_PROPERTY::operator&() const throw() -{ -return &value; -} -//----------------------------------------------------------------------------- -template -const varT & USER_PROPERTY::ConstData() const throw() -{ -return value; -} -//----------------------------------------------------------------------------- -template +inline void USER_PROPERTY::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); @@ -245,6 +231,7 @@ beforeNotifiers.insert(n); } //----------------------------------------------------------------------------- template +inline void USER_PROPERTY::DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); @@ -252,6 +239,7 @@ beforeNotifiers.erase(n); } //----------------------------------------------------------------------------- template +inline void USER_PROPERTY::AddAfterNotifier(PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); @@ -259,23 +247,19 @@ afterNotifiers.insert(n); } //----------------------------------------------------------------------------- template +inline void USER_PROPERTY::DelAfterNotifier(PROPERTY_NOTIFIER_BASE * n) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); afterNotifiers.erase(n); } //----------------------------------------------------------------------------- -template -time_t USER_PROPERTY::ModificationTime() const throw() -{ -return modificationTime; -} -//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- template +inline USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, - std::string n, + const std::string & n, bool isPass, bool isSt, STG_LOGGER & logger, @@ -289,29 +273,6 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, scriptsDir(sd) { } -//----------------------------------------------------------------------------- -template -USER_PROPERTY_LOGGED::~USER_PROPERTY_LOGGED() -{ -} -//----------------------------------------------------------------------------- -template -USER_PROPERTY_LOGGED * USER_PROPERTY_LOGGED::GetPointer() throw() -{ -return this; -} -//----------------------------------------------------------------------------- -template -const varT & USER_PROPERTY_LOGGED::Get() const -{ -return USER_PROPERTY::ConstData(); -}; -//------------------------------------------------------------------------- -template -const std::string & USER_PROPERTY_LOGGED::GetName() const -{ -return name; -}; //------------------------------------------------------------------------- template bool USER_PROPERTY_LOGGED::Set(const varT & val, @@ -329,8 +290,8 @@ if ((priv->userConf && !isStat) || (priv->userPasswd && isPassword) || (priv->userCash && name == "cash")) { - stringstream oldVal; - stringstream newVal; + std::stringstream oldVal; + std::stringstream newVal; oldVal.flags(oldVal.flags() | ios::fixed); newVal.flags(newVal.flags() | ios::fixed); @@ -360,6 +321,7 @@ return true; } //------------------------------------------------------------------------- template +inline void USER_PROPERTY_LOGGED::WriteAccessDenied(const std::string & login, const ADMIN * admin, const std::string & parameter) @@ -369,6 +331,7 @@ stgLogger("%s Change user \'%s.\' Parameter \'%s\'. Access denied.", } //------------------------------------------------------------------------- template +inline void USER_PROPERTY_LOGGED::WriteSuccessChange(const std::string & login, const ADMIN * admin, const std::string & parameter, @@ -411,6 +374,7 @@ else //------------------------------------------------------------------------- //------------------------------------------------------------------------- template +inline ostream & operator<< (ostream & stream, const USER_PROPERTY & value) { return stream << value.ConstData();