From: Maxim Mamontov Date: Fri, 3 Oct 2014 09:07:49 +0000 (+0300) Subject: Added SERVICES::Find for resetable value. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/d7e2dad86a72fd5a3cd8717a9e1518832c193a3e?ds=sidebyside Added SERVICES::Find for resetable value. --- diff --git a/include/stg/services.h b/include/stg/services.h index 1fe4dca1..140391d0 100644 --- a/include/stg/services.h +++ b/include/stg/services.h @@ -34,6 +34,7 @@ public: virtual int Del(const std::string & name, const ADMIN * admin) = 0; virtual int Change(const SERVICE_CONF & service, const ADMIN * admin) = 0; virtual bool Find(const std::string & name, SERVICE_CONF * service) const = 0; + virtual bool Find(const std::string & name, SERVICE_CONF_RES * service) const = 0; virtual bool Exists(const std::string & name) const = 0; virtual const std::string & GetStrError() const = 0; virtual size_t Count() const = 0; diff --git a/projects/stargazer/services_impl.cpp b/projects/stargazer/services_impl.cpp index ac856000..bb9fdc1a 100644 --- a/projects/stargazer/services_impl.cpp +++ b/projects/stargazer/services_impl.cpp @@ -54,7 +54,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si != data.end()) { @@ -92,7 +92,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si == data.end()) { @@ -136,7 +136,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si == data.end()) { @@ -145,7 +145,9 @@ if (si == data.end()) return -1; } +printfd(__FILE__, "Old cost = %f, old pay day = %d\n", si->cost, (unsigned)si->payDay); *si = service; +printfd(__FILE__, "New cost = %f, New pay day = %d\n", si->cost, (unsigned)si->payDay); if (store->SaveService(service)) { WriteServLog("Cannot write service %s.", service.name.c_str()); @@ -192,7 +194,26 @@ STG_LOCKER lock(&mutex); if (data.empty()) return false; -const_iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); + +if (si != data.end()) + { + *service = *si; + return false; + } + +return true; +} +//----------------------------------------------------------------------------- +bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF_RES * service) const +{ +assert(service != NULL && "Pointer to service is not null"); + +STG_LOCKER lock(&mutex); +if (data.empty()) + return false; + +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) { @@ -208,11 +229,11 @@ bool SERVICES_IMPL::Exists(const std::string & name) const STG_LOCKER lock(&mutex); if (data.empty()) { - printfd(__FILE__, "no admin in system!\n"); + printfd(__FILE__, "No services in the system!\n"); return true; } -const_iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) return true; diff --git a/projects/stargazer/services_impl.h b/projects/stargazer/services_impl.h index 0415183c..56202c7a 100644 --- a/projects/stargazer/services_impl.h +++ b/projects/stargazer/services_impl.h @@ -45,6 +45,7 @@ public: int Del(const std::string & name, const ADMIN * admin); int Change(const SERVICE_CONF & service, const ADMIN * admin); bool Find(const std::string & name, SERVICE_CONF * service) const; + bool Find(const std::string & name, SERVICE_CONF_RES * service) const; bool Exists(const std::string & name) const; const std::string & GetStrError() const { return strError; }