diff --git a/src/AttributeName.cpp b/src/AttributeName.cpp index eb4b1abca42c884ff28009a99ae7aed5f71cf92b..80293f0c70e72daa30053bf47f9870df54014c26 100644 --- a/src/AttributeName.cpp +++ b/src/AttributeName.cpp @@ -59,14 +59,14 @@ void AttributeName::clear() noexcept //============================================================================= //============================================================================= -const string &AttributeName::tangoHost() +auto AttributeName::tangoHost() -> const std::string & { validate(); if (_tango_host_cache.empty()) { - // if tango:// exists on the string, strip it off by moving the start in 8 characters - auto start = _fqdn_attr_name.find("tango://") == string::npos ? 0 : 8; + // if tango:// exists on the std::string, strip it off by moving the start in 8 characters + auto start = _fqdn_attr_name.find("tango://") == std::string::npos ? 0 : 8; auto end = _fqdn_attr_name.find('/', start); _tango_host_cache = _fqdn_attr_name.substr(start, end - start); } @@ -76,17 +76,17 @@ const string &AttributeName::tangoHost() //============================================================================= //============================================================================= -const string &AttributeName::tangoHostWithDomain() +auto AttributeName::tangoHostWithDomain() -> const std::string & { validate(); if (_tango_host_with_domain_cache.empty()) { - string tango_host = tangoHost(); + std::string tango_host = tangoHost(); - if (tango_host.find('.') == string::npos) + if (tango_host.find('.') == std::string::npos) { - string server_name_with_domain; + std::string server_name_with_domain; auto server_name = tango_host.substr(0, tango_host.find(':', 0)); struct addrinfo hints = {}; @@ -124,7 +124,7 @@ const string &AttributeName::tangoHostWithDomain() return tangoHost(); } - server_name_with_domain = string(result->ai_canonname) + tango_host.substr(tango_host.find(':', 0)); + server_name_with_domain = std::string(result->ai_canonname) + tango_host.substr(tango_host.find(':', 0)); freeaddrinfo(result); // all done with this structure _tango_host_with_domain_cache = server_name_with_domain; @@ -140,14 +140,14 @@ const string &AttributeName::tangoHostWithDomain() //============================================================================= //============================================================================= -const string &AttributeName::fullAttributeName() +auto AttributeName::fullAttributeName() -> const std::string & { validate(); if (_full_attribute_name_cache.empty()) { - // if tango:// exists on the string, strip it off by moving the start in 8 characters - auto start = _fqdn_attr_name.find("tango://") == string::npos ? 0 : 8; + // if tango:// exists on the std::string, strip it off by moving the start in 8 characters + auto start = _fqdn_attr_name.find("tango://") == std::string::npos ? 0 : 8; start = _fqdn_attr_name.find('/', start); start++; _full_attribute_name_cache = _fqdn_attr_name.substr(start); @@ -158,7 +158,7 @@ const string &AttributeName::fullAttributeName() //============================================================================= //============================================================================= -const std::string &AttributeName::domain() +auto AttributeName::domain() -> const std::string & { validate(); @@ -170,7 +170,7 @@ const std::string &AttributeName::domain() //============================================================================= //============================================================================= -const std::string &AttributeName::family() +auto AttributeName::family() -> const std::string & { validate(); @@ -182,7 +182,7 @@ const std::string &AttributeName::family() //============================================================================= //============================================================================= -const std::string &AttributeName::member() +auto AttributeName::member() -> const std::string & { validate(); @@ -194,7 +194,7 @@ const std::string &AttributeName::member() //============================================================================= //============================================================================= -const std::string &AttributeName::name() +auto AttributeName::name() -> const std::string & { validate(); @@ -206,31 +206,31 @@ const std::string &AttributeName::name() //============================================================================= //============================================================================= -void AttributeName::setDomainFamilyMemberName(const string &full_attr_name) +void AttributeName::setDomainFamilyMemberName(const std::string &full_attr_name) { auto first_slash = full_attr_name.find('/'); - if (first_slash == string::npos) + if (first_slash == std::string::npos) { - string msg {"Invalid attribute name: " + full_attr_name + ". There is no slash in attribute name"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". There is no slash in attribute name"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } auto second_slash = full_attr_name.find('/', first_slash + 1); - if (second_slash == string::npos) + if (second_slash == std::string::npos) { - string msg {"Invalid attribute name: " + full_attr_name + ". There is only one slash in attribute name"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". There is only one slash in attribute name"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } auto third_slash = full_attr_name.find('/', second_slash + 1); - if (third_slash == string::npos) + if (third_slash == std::string::npos) { - string msg {"Invalid attribute name: " + full_attr_name + ". There are only two slashes in attribute name"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". There are only two slashes in attribute name"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } @@ -239,35 +239,35 @@ void AttributeName::setDomainFamilyMemberName(const string &full_attr_name) if (last_slash != third_slash) { - string msg {"Invalid attribute name: " + full_attr_name + ". Too many slashes provided in attribute name"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". Too many slashes provided in attribute name"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } if (first_slash == 0) { - string msg {"Invalid attribute name: " + full_attr_name + ". Empty domain"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". Empty domain"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } if (second_slash - first_slash - 1 == 0) { - string msg {"Invalid attribute name: " + full_attr_name + ". Empty family"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". Empty family"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } if (third_slash - second_slash - 1 == 0) { - string msg {"Invalid attribute name: " + full_attr_name + ". Empty member"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". Empty member"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } if (third_slash + 1 == full_attr_name.length()) { - string msg {"Invalid attribute name: " + full_attr_name + ". Empty name"}; + std::string msg {"Invalid attribute name: " + full_attr_name + ". Empty name"}; spdlog::error("Error: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } @@ -286,7 +286,7 @@ void AttributeName::validate() // it means we just tried to execute a complex operation if (empty()) { - string msg {"AttributeName is empty."}; + std::string msg {"AttributeName is empty."}; spdlog::error("Failed validation for attribute: {}", msg); Tango::Except::throw_exception("Invalid Argument", msg, LOCATION_INFO); } @@ -301,7 +301,7 @@ void AttributeName::print(ostream &os) const //============================================================================= //============================================================================= -AttributeName &AttributeName::operator=(const AttributeName &other) +auto AttributeName::operator=(const AttributeName &other) -> AttributeName & { // clear the cache clear(); @@ -313,7 +313,7 @@ AttributeName &AttributeName::operator=(const AttributeName &other) //============================================================================= //============================================================================= -AttributeName &AttributeName::operator=(AttributeName &&other) noexcept +auto AttributeName::operator=(AttributeName &&other) noexcept -> AttributeName & { // clear the cache clear(); diff --git a/src/AttributeName.hpp b/src/AttributeName.hpp index 809400a51691095d52a3c3a353a7286884222cc1..ce9420cb7241a058b94f5493c3056554f8757332 100644 --- a/src/AttributeName.hpp +++ b/src/AttributeName.hpp @@ -45,49 +45,49 @@ public: AttributeName(const AttributeName &attr_name) { *this = attr_name; } AttributeName(const std::string &fqdn_attr_name); - const std::string &fqdnAttributeName() const noexcept { return _fqdn_attr_name; } - const std::string &fullAttributeName(); + auto fqdnAttributeName() const noexcept -> const std::string & { return _fqdn_attr_name; } + auto fullAttributeName() -> const std::string &; // tango host info - const std::string &tangoHost(); - const std::string &tangoHostWithDomain(); + auto tangoHost() -> const std::string &; + auto tangoHostWithDomain() -> const std::string &; // attribute name elements - const std::string &domain(); - const std::string &family(); - const std::string &member(); - const std::string &name(); + auto domain() -> const std::string &; + auto family() -> const std::string &; + auto member() -> const std::string &; + auto name() -> const std::string &; // utility functions void set(const std::string &fqdn_attr_name); void clear() noexcept; - bool empty() const noexcept { return _fqdn_attr_name.empty(); } + auto empty() const noexcept -> bool { return _fqdn_attr_name.empty(); } void print(std::ostream &os) const; - bool operator==(const AttributeName &other) const { return _fqdn_attr_name == other._fqdn_attr_name; } - bool operator!=(const AttributeName &other) const { return !(_fqdn_attr_name == other._fqdn_attr_name); } - AttributeName &operator=(const AttributeName &other); - AttributeName &operator=(AttributeName &&other) noexcept; + auto operator==(const AttributeName &other) const -> bool { return _fqdn_attr_name == other._fqdn_attr_name; } + auto operator!=(const AttributeName &other) const -> bool { return !(_fqdn_attr_name == other._fqdn_attr_name); } + auto operator=(const AttributeName &other) -> AttributeName &; + auto operator=(AttributeName &&other) noexcept -> AttributeName &; private: // extract the full attribute name, i.e. domain/family/member/name - std::string getFullAttributeName(const std::string &fqdn_attr_name); + auto getFullAttributeName(const std::string &fqdn_attr_name) -> std::string; // takes the fqdn and breaks out the various component parts, such // as domain, family etc void setDomainFamilyMemberName(const std::string &full_attr_name); - // combine the local domain and tango host as a string - std::string addDomainToTangoHost(const std::string &tango_host); + // combine the local domain and tango host as a std::string + auto addDomainToTangoHost(const std::string &tango_host) -> std::string; // check if the AttributeName is empty before executing a complex // operation, such as returning the tango host void validate(); - // the fully qualified domain name string + // the fully qualified domain name std::string std::string _fqdn_attr_name; - // each string is a cache, and generated only once to save + // each std::string is a cache, and generated only once to save // on performance std::string _full_attribute_name_cache; std::string _tango_host_cache; diff --git a/src/AttributeTraits.cpp b/src/AttributeTraits.cpp index 5d7ed552deeac23aedc9f695638f5906bb930821..61188e53f8172fc35b89894a9702ea8216750b4e 100644 --- a/src/AttributeTraits.cpp +++ b/src/AttributeTraits.cpp @@ -25,7 +25,7 @@ namespace hdbpp_internal { //============================================================================= //============================================================================= -bool AttributeTraits::isValid() const noexcept +auto AttributeTraits::isValid() const noexcept -> bool { // ensure all the type information is valid return _attr_write_type != Tango::WT_UNKNOWN && _attr_format != Tango::FMT_UNKNOWN && diff --git a/src/AttributeTraits.hpp b/src/AttributeTraits.hpp index 55e6b70ed1815e1495aabd5a28dde8af4df09fc4..5e0a87f6c90f56507625c47e82f9c0b44d5840ed 100644 --- a/src/AttributeTraits.hpp +++ b/src/AttributeTraits.hpp @@ -54,38 +54,38 @@ public: {} // general validation - bool isValid() const noexcept; - bool isInvalid() const noexcept { return !isValid(); } + auto isValid() const noexcept -> bool; + auto isInvalid() const noexcept -> bool { return !isValid(); } // format type information - bool isArray() const noexcept { return _attr_format == Tango::SPECTRUM; } - bool isScalar() const noexcept { return _attr_format == Tango::SCALAR; } - bool isImage() const noexcept { return _attr_format == Tango::IMAGE; } + auto isArray() const noexcept -> bool { return _attr_format == Tango::SPECTRUM; } + auto isScalar() const noexcept -> bool { return _attr_format == Tango::SCALAR; } + auto isImage() const noexcept -> bool { return _attr_format == Tango::IMAGE; } // write type information - bool isReadOnly() const noexcept { return _attr_write_type == Tango::READ; } - bool isWriteOnly() const noexcept { return _attr_write_type == Tango::WRITE; } - bool isReadWrite() const noexcept { return _attr_write_type == Tango::READ_WRITE; } - bool isReadWithWrite() const noexcept { return _attr_write_type == Tango::READ_WITH_WRITE; } - bool hasReadData() const noexcept { return isReadOnly() || isReadWrite() || isReadWithWrite(); } - bool hasWriteData() const noexcept { return isWriteOnly() || isReadWrite() || isReadWithWrite(); } + auto isReadOnly() const noexcept -> bool { return _attr_write_type == Tango::READ; } + auto isWriteOnly() const noexcept -> bool { return _attr_write_type == Tango::WRITE; } + auto isReadWrite() const noexcept -> bool { return _attr_write_type == Tango::READ_WRITE; } + auto isReadWithWrite() const noexcept -> bool { return _attr_write_type == Tango::READ_WITH_WRITE; } + auto hasReadData() const noexcept -> bool { return isReadOnly() || isReadWrite() || isReadWithWrite(); } + auto hasWriteData() const noexcept -> bool { return isWriteOnly() || isReadWrite() || isReadWithWrite(); } // type access - Tango::CmdArgType type() const noexcept { return _attr_type; } - Tango::AttrWriteType writeType() const noexcept { return _attr_write_type; } - Tango::AttrDataFormat formatType() const noexcept { return _attr_format; } + auto type() const noexcept -> Tango::CmdArgType { return _attr_type; } + auto writeType() const noexcept -> Tango::AttrWriteType { return _attr_write_type; } + auto formatType() const noexcept -> Tango::AttrDataFormat { return _attr_format; } // various utilities - AttributeTraits &operator=(const AttributeTraits &) = default; - AttributeTraits &operator=(AttributeTraits &&) = default; + auto operator=(const AttributeTraits &) -> AttributeTraits & = default; + auto operator=(AttributeTraits &&) -> AttributeTraits & = default; - bool operator==(const AttributeTraits &other) const + auto operator==(const AttributeTraits &other) const -> bool { return _attr_write_type == other.writeType() && _attr_format == other.formatType() && _attr_type == other.type(); } - bool operator!=(const AttributeTraits &other) const { return !(*this == other); } + auto operator!=(const AttributeTraits &other) const -> bool { return !(*this == other); } void print(std::ostream &os) const noexcept; diff --git a/src/ColumnCache.hpp b/src/ColumnCache.hpp index 97d83cc4778b03a0714a3371581f0ad933a7c13f..ad37e6f98f8c9520f55b3b24b4ad876441d4f7f1 100644 --- a/src/ColumnCache.hpp +++ b/src/ColumnCache.hpp @@ -44,13 +44,13 @@ namespace pqxx_conn // query if the reference has a value, if its not cached it will be // loaded from the database - bool valueExists(const TRef &reference); + auto valueExists(const TRef &reference) -> bool; // get the value associated with the reference, throws and exception if it does not // exist either in the cache or database. The caller can check valueExists() // before calling this function to know if its valid to attempt to return // the value - TValue value(const TRef &reference); + auto value(const TRef &reference) -> TValue; // cache a value in the internal maps void cacheValue(const TValue &value, const TRef &reference); @@ -60,7 +60,7 @@ namespace pqxx_conn // utility functions void clear() noexcept { _values.clear(); } - int size() const noexcept { return _values.size(); } + auto size() const noexcept -> int { return _values.size(); } void print(std::ostream &os) const noexcept; private: @@ -157,7 +157,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= template<typename TValue, typename TRef> - bool ColumnCache<TValue, TRef>::valueExists(const TRef &reference) + auto ColumnCache<TValue, TRef>::valueExists(const TRef &reference) -> bool { assert(_conn != nullptr); @@ -231,7 +231,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= template<typename TValue, typename TRef> - TValue ColumnCache<TValue, TRef>::value(const TRef &reference) + auto ColumnCache<TValue, TRef>::value(const TRef &reference) -> TValue { assert(_conn != nullptr); diff --git a/src/ConnectionBase.hpp b/src/ConnectionBase.hpp index 58d3783ecb65dbe5cda636c3a58ac6c7872438be..24ae4fac412f7f69447d297bf53e930eace6b16c 100644 --- a/src/ConnectionBase.hpp +++ b/src/ConnectionBase.hpp @@ -35,8 +35,8 @@ public: // connection API virtual void connect(const std::string &connect_string) = 0; virtual void disconnect() = 0; - virtual bool isOpen() const noexcept = 0; - virtual bool isClosed() const noexcept = 0; + virtual auto isOpen() const noexcept -> bool = 0; + virtual auto isClosed() const noexcept -> bool = 0; }; }; // namespace hdbpp_internal diff --git a/src/DbConnection.cpp b/src/DbConnection.cpp index 73fe18b4f1d6bd590c42c2dc8ebaa881e8fa0caf..51982c0dea1ad432a00e754403b0f772c5df7b78 100644 --- a/src/DbConnection.cpp +++ b/src/DbConnection.cpp @@ -253,6 +253,7 @@ namespace pqxx_conn void DbConnection::storeParameterEvent(const string &full_attr_name, double event_time, const string &label, + const vector<string> &enum_labels, const string &unit, const string &standard_unit, const string &display_unit, @@ -276,6 +277,7 @@ namespace pqxx_conn }; check_parameter("label", label); + check_parameter("enum_labels", enum_labels); check_parameter("unit", unit); check_parameter("standard_unit", standard_unit); check_parameter("display_unit", display_unit); @@ -283,11 +285,12 @@ namespace pqxx_conn check_parameter("archive_abs_change", archive_abs_change); check_parameter("archive_period", archive_period); check_parameter("description", description); - - spdlog::trace("Parmater event data: event_time {}, label {}, unit {}, standard_unit {}, display_unit {}, " +/* + spdlog::trace("Parameter event data: event_time {}, label {}, enum_labels {}, unit {}, standard_unit {}, display_unit {}, " "format {}, archive_rel_change {}, archive_abs_change {}, archive_period {}, description {}", event_time, label, + enum_labels, unit, standard_unit, display_unit, @@ -296,7 +299,7 @@ namespace pqxx_conn archive_abs_change, archive_period, description); - +*/ checkConnection(LOCATION_INFO); checkAttributeExists(full_attr_name, LOCATION_INFO); @@ -312,11 +315,19 @@ namespace pqxx_conn spdlog::trace("Created prepared statement for: {}", StoreParameterEvent); } + // a string needs quoting to be stored via this method, so it does not cause + // an error in the prepared statement + vector<string> enum_labels_escaped; + enum_labels_escaped.reserve(enum_labels.size()); + for(const auto &label : enum_labels) + enum_labels_escaped.push_back(tx.esc(label)); + // no result expected tx.exec_prepared0(StoreParameterEvent, _conf_id_cache->value(full_attr_name), event_time, label, + enum_labels_escaped, unit, standard_unit, display_unit, @@ -473,7 +484,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - string DbConnection::fetchLastHistoryEvent(const string &full_attr_name) + auto DbConnection::fetchLastHistoryEvent(const string &full_attr_name) -> string { assert(!full_attr_name.empty()); assert(_conn != nullptr); @@ -524,7 +535,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - bool DbConnection::fetchAttributeArchived(const std::string &full_attr_name) + auto DbConnection::fetchAttributeArchived(const std::string &full_attr_name) -> bool { assert(!full_attr_name.empty()); assert(_conn != nullptr); @@ -544,7 +555,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - AttributeTraits DbConnection::fetchAttributeTraits(const std::string &full_attr_name) + auto DbConnection::fetchAttributeTraits(const std::string &full_attr_name) -> AttributeTraits { assert(!full_attr_name.empty()); assert(_conn != nullptr); diff --git a/src/DbConnection.hpp b/src/DbConnection.hpp index 21adc2e52cb9016d12a9a7d2223f14c1d6b3e2af..188cf4d11639f955eaa9a709fd1bc001089442d2 100644 --- a/src/DbConnection.hpp +++ b/src/DbConnection.hpp @@ -61,8 +61,8 @@ namespace pqxx_conn // connection API void connect(const string &connect_string) override; void disconnect() override; - bool isOpen() const noexcept override { return _connected; } - bool isClosed() const noexcept override { return !isOpen(); } + auto isOpen() const noexcept -> bool override { return _connected; } + auto isClosed() const noexcept -> bool override { return !isOpen(); } // this API allows the connection to buffer the event data store // requests, and send them all at once to the db, this will increase @@ -89,6 +89,7 @@ namespace pqxx_conn void storeParameterEvent(const std::string &full_attr_name, double event_time, const std::string &label, + const std::vector<std::string> &enum_labels, const std::string &unit, const std::string &standard_unit, const std::string &display_unit, @@ -122,13 +123,13 @@ namespace pqxx_conn // fetch API // get the last history event for the given attribute - std::string fetchLastHistoryEvent(const std::string &full_attr_name); + auto fetchLastHistoryEvent(const std::string &full_attr_name) -> std::string; // check if the given attribute is stored in the database - bool fetchAttributeArchived(const std::string &full_attr_name); + auto fetchAttributeArchived(const std::string &full_attr_name) -> bool; // get the AttributeTraits of an attribute in the database - AttributeTraits fetchAttributeTraits(const std::string &full_attr_name); + auto fetchAttributeTraits(const std::string &full_attr_name) -> AttributeTraits; private: void storeEvent(const std::string &full_attr_name, const std::string &event); diff --git a/src/HdbppTimescaleDb.cpp b/src/HdbppTimescaleDb.cpp index 9e7bc89e08e8399358d9df502baaab694c102a24..9e39a0cda2ba4c687829253eaa6d346c431a99bc 100644 --- a/src/HdbppTimescaleDb.cpp +++ b/src/HdbppTimescaleDb.cpp @@ -25,7 +25,7 @@ namespace hdbpp { //============================================================================= //============================================================================= -AbstractDB *HdbppTimescaleDbFactory::create_db(const string &id, const vector<string> &configuration) +auto HdbppTimescaleDbFactory::create_db(const string &id, const vector<string> &configuration) -> AbstractDB * { return new hdbpp::HdbppTimescaleDbApi(id, configuration); } @@ -33,7 +33,7 @@ AbstractDB *HdbppTimescaleDbFactory::create_db(const string &id, const vector<st //============================================================================= //============================================================================= -hdbpp::DBFactory *getDBFactory() +auto getDBFactory() -> hdbpp::DBFactory * { auto *factory = new hdbpp::HdbppTimescaleDbFactory(); return static_cast<hdbpp::DBFactory *>(factory); diff --git a/src/HdbppTimescaleDbApi.cpp b/src/HdbppTimescaleDbApi.cpp index aadd0989f4cd7603eaade235eb692fa42f2fc1e3..22478cf6f018b59321eeb1ab71dcd5a8f27e0c75 100644 --- a/src/HdbppTimescaleDbApi.cpp +++ b/src/HdbppTimescaleDbApi.cpp @@ -38,13 +38,13 @@ namespace hdbpp // simple class to gather utility functions struct HdbppTimescaleDbApiUtils { - static string getConfigParam(const map<string, string> &conf, const string ¶m, bool mandatory); - static map<string, string> extractConfig(const vector<string> &config, const string &separator); + static auto getConfigParam(const map<string, string> &conf, const string ¶m, bool mandatory) -> string; + static auto extractConfig(const vector<string> &config, const string &separator) -> map<string, string>; }; //============================================================================= //============================================================================= -map<string, string> HdbppTimescaleDbApiUtils::extractConfig(const vector<string> &config, const string &separator) +auto HdbppTimescaleDbApiUtils::extractConfig(const vector<string> &config, const string &separator) -> map<string, string> { map<string, string> results; @@ -61,7 +61,7 @@ map<string, string> HdbppTimescaleDbApiUtils::extractConfig(const vector<string> //============================================================================= //============================================================================= -string HdbppTimescaleDbApiUtils::getConfigParam(const map<string, string> &conf, const string ¶m, bool mandatory) +auto HdbppTimescaleDbApiUtils::getConfigParam(const map<string, string> &conf, const string ¶m, bool mandatory) -> string { auto iter = conf.find(param); @@ -247,7 +247,7 @@ void HdbppTimescaleDbApi::insert_history_event(const std::string &fqdn_attr_name //============================================================================= //============================================================================= -bool HdbppTimescaleDbApi::supported(HdbppFeatures feature) +auto HdbppTimescaleDbApi::supported(HdbppFeatures feature) -> bool { auto supported = false; diff --git a/src/HdbppTimescaleDbApi.hpp b/src/HdbppTimescaleDbApi.hpp index 7e632ce7aeb7f0cef7568de7b0f1d0610216dae2..0c83596cfd3b0ce611aa24ba104444b83ae0bc3b 100644 --- a/src/HdbppTimescaleDbApi.hpp +++ b/src/HdbppTimescaleDbApi.hpp @@ -69,7 +69,7 @@ public: void insert_history_event(const std::string &fqdn_attr_name, unsigned char event) override; // Check what hdbpp features this library supports. This library supports: TTL, BATCH_INSERTS - bool supported(HdbppFeatures feature) override; + auto supported(HdbppFeatures feature) -> bool override; private: void doInsertEvent(Tango::EventData *event_data, const HdbEventDataType &data_type); diff --git a/src/HdbppTxBase.hpp b/src/HdbppTxBase.hpp index 3716390a0837a831c609db79be3ccddd23681abb..7440d0674b438eea72862b423052a3fc682e632b 100644 --- a/src/HdbppTxBase.hpp +++ b/src/HdbppTxBase.hpp @@ -47,21 +47,21 @@ public: // simple feedback that the transaction was successfull. Most // errors are handled with exceptions which are thrown to the // tx creator. - bool result() const noexcept { return _result; }; + auto result() const noexcept -> bool { return _result; }; virtual void print(std::ostream &os) const noexcept { os << "HdbppTxBase(_result: " << _result << ")"; } protected: // access functions for the connection the transaction // is templated with - Conn &connection() { return _conn; } - const Conn &connection() const { return _conn; } + auto connection() -> Conn & { return _conn; } + auto connection() const -> const Conn & { return _conn; } void setResult(bool state) noexcept { _result = state; } // small helper to generate the attribute name for the db consistently // across all the different tx classes - static std::string attrNameForStorage(AttributeName &attr_name) + static auto attrNameForStorage(AttributeName &attr_name) -> std::string { return "tango://" + attr_name.tangoHostWithDomain() + "/" + attr_name.fullAttributeName(); } diff --git a/src/HdbppTxDataEvent.hpp b/src/HdbppTxDataEvent.hpp index be3c4165ac86add434564c364725a425cebce7c6..5d5f5db7f31e1625639ee77ddeb46d4976834123 100644 --- a/src/HdbppTxDataEvent.hpp +++ b/src/HdbppTxDataEvent.hpp @@ -38,7 +38,7 @@ private: public: HdbppTxDataEvent(Conn &conn) : HdbppTxDataEventBase<Conn, HdbppTxDataEvent>(conn) {} - HdbppTxDataEvent<Conn> &withAttribute(Tango::DeviceAttribute *dev_attr) + auto withAttribute(Tango::DeviceAttribute *dev_attr) -> HdbppTxDataEvent<Conn> & { // just set the pointer here, we will do a full event data extraction at // point of storage, this reduces complexity but limits the functionality, i.e @@ -48,7 +48,7 @@ public: } // trigger the database storage routines - HdbppTxDataEvent<Conn> &store(); + auto store() -> HdbppTxDataEvent<Conn> &; void print(std::ostream &os) const noexcept override; @@ -66,7 +66,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxDataEvent<Conn> &HdbppTxDataEvent<Conn>::store() +auto HdbppTxDataEvent<Conn>::store() -> HdbppTxDataEvent<Conn> & { if (Base::attributeName().empty()) { @@ -143,7 +143,7 @@ HdbppTxDataEvent<Conn> &HdbppTxDataEvent<Conn>::store() break; - //case Tango::DEV_ENUM: this->template doStoreEnum<?>(); break; // TODO + case Tango::DEV_ENUM: this->template doStore<int16_t>(read_extractor, write_extractor); break; //case Tango::DEV_ENCODED: this->template doStoreEncoded<vector<uint8_t>>(); break; // TODO default: std::string msg { diff --git a/src/HdbppTxDataEventBase.hpp b/src/HdbppTxDataEventBase.hpp index 8d0fac95574a25370e5b205c6ca8e5adaf559621..bb74c6a279be190c966ceb71e785cd771603760c 100644 --- a/src/HdbppTxDataEventBase.hpp +++ b/src/HdbppTxDataEventBase.hpp @@ -42,32 +42,32 @@ public: HdbppTxDataEventBase(Conn &conn) : HdbppTxBase<Conn>(conn) {} - Derived<Conn> &withName(const std::string &fqdn_attr_name) + auto withName(const std::string &fqdn_attr_name) -> Derived<Conn> & { _attr_name = AttributeName {fqdn_attr_name}; return static_cast<Derived<Conn> &>(*this); } - Derived<Conn> &withTraits(Tango::AttrWriteType write, Tango::AttrDataFormat format, Tango::CmdArgType type) + auto withTraits(Tango::AttrWriteType write, Tango::AttrDataFormat format, Tango::CmdArgType type) -> Derived<Conn> & { _traits = AttributeTraits(write, format, type); return static_cast<Derived<Conn> &>(*this); } - Derived<Conn> &withTraits(AttributeTraits &traits) + auto withTraits(AttributeTraits &traits) -> Derived<Conn> & { _traits = traits; return static_cast<Derived<Conn> &>(*this); } - Derived<Conn> &withEventTime(Tango::TimeVal tv) + auto withEventTime(Tango::TimeVal tv) -> Derived<Conn> & { // convert to something more usable _event_time = tv.tv_sec + tv.tv_usec / 1.0e6; return static_cast<Derived<Conn> &>(*this); } - Derived<Conn> &withQuality(Tango::AttrQuality quality) + auto withQuality(Tango::AttrQuality quality) -> Derived<Conn> & { _quality = quality; return static_cast<Derived<Conn> &>(*this); @@ -78,10 +78,10 @@ public: protected: // release the private data safely for the derived classes - AttributeName &attributeName() { return _attr_name; } - const AttributeTraits &attributeTraits() const { return _traits; } - Tango::AttrQuality quality() const { return _quality; } - double eventTime() const { return _event_time; } + auto attributeName() -> AttributeName & { return _attr_name; } + auto attributeTraits() const -> const AttributeTraits & { return _traits; } + auto quality() const -> Tango::AttrQuality { return _quality; } + auto eventTime() const -> double { return _event_time; } private: AttributeName _attr_name; diff --git a/src/HdbppTxDataEventError.hpp b/src/HdbppTxDataEventError.hpp index 69820f1668cd723a60eda4a036acb37338030570..fd4de28b3c360238f67c8aa5f8cdd2180ea0adc3 100644 --- a/src/HdbppTxDataEventError.hpp +++ b/src/HdbppTxDataEventError.hpp @@ -37,14 +37,14 @@ private: public: HdbppTxDataEventError(Conn &conn) : HdbppTxDataEventBase<Conn, HdbppTxDataEventError>(conn) {} - HdbppTxDataEventError<Conn> &withError(const std::string &error_msg) + auto withError(const std::string &error_msg) -> HdbppTxDataEventError<Conn> & { _error_msg = error_msg; return *this; } // trigger the database storage routines - HdbppTxDataEventError<Conn> &store(); + auto store() -> HdbppTxDataEventError<Conn> &; /// @brief Print the HdbppTxDataEventError object to the stream void print(std::ostream &os) const noexcept override; @@ -56,7 +56,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxDataEventError<Conn> &HdbppTxDataEventError<Conn>::store() +auto HdbppTxDataEventError<Conn>::store() -> HdbppTxDataEventError<Conn> & { if (Base::attributeName().empty()) { diff --git a/src/HdbppTxFactory.hpp b/src/HdbppTxFactory.hpp index eb5a510b4c5061c41822437ac349aafe7d925c31..d93395e7d0e6519376c6ef67ee72a572d4753f04 100644 --- a/src/HdbppTxFactory.hpp +++ b/src/HdbppTxFactory.hpp @@ -31,7 +31,7 @@ public: // this generic method creates transaction objects based on the template // parameter. Any parameters are forward directly to the new object template<template<typename> class Class, typename... Params> - Class<Conn> createTx(Params &&... params) + auto createTx(Params &&... params) -> Class<Conn> { return Class<Conn>((static_cast<Conn &>(*this)), std::forward<Params>(params)...); } diff --git a/src/HdbppTxHistoryEvent.hpp b/src/HdbppTxHistoryEvent.hpp index 95041f19e79717b3c7b4377958ab44ef64c90f88..eb63b10d55ffc7310d4dc2892a67bfb7e0d27390 100644 --- a/src/HdbppTxHistoryEvent.hpp +++ b/src/HdbppTxHistoryEvent.hpp @@ -39,7 +39,7 @@ public: HdbppTxHistoryEvent(Conn &conn) : HdbppTxBase<Conn>(conn) {} - HdbppTxHistoryEvent<Conn> &withName(const std::string &fqdn_attr_name) + auto withName(const std::string &fqdn_attr_name) -> HdbppTxHistoryEvent<Conn> & { _attr_name = AttributeName {fqdn_attr_name}; return *this; @@ -47,17 +47,17 @@ public: // this overload converts the event types defined in libhdb to // usable strings - HdbppTxHistoryEvent<Conn> &withEvent(unsigned char event); + auto withEvent(unsigned char event) -> HdbppTxHistoryEvent<Conn> &; // allow the adding of any type of event - HdbppTxHistoryEvent<Conn> &withEvent(const std::string &event) + auto withEvent(const std::string &event) -> HdbppTxHistoryEvent<Conn> & { _event = event; return *this; } // trigger the database storage routines - HdbppTxHistoryEvent<Conn> &store(); + auto store() -> HdbppTxHistoryEvent<Conn> &; /// @brief Print the HdbppTxHistoryEvent object to the stream void print(std::ostream &os) const noexcept override; @@ -70,7 +70,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxHistoryEvent<Conn> &HdbppTxHistoryEvent<Conn>::withEvent(unsigned char event) +auto HdbppTxHistoryEvent<Conn>::withEvent(unsigned char event) -> HdbppTxHistoryEvent<Conn> & { // convert the unsigned char history type of a string, we will store the event // based on this string, so its simpler to extract the data at a later point @@ -98,7 +98,7 @@ HdbppTxHistoryEvent<Conn> &HdbppTxHistoryEvent<Conn>::withEvent(unsigned char ev //============================================================================= //============================================================================= template<typename Conn> -HdbppTxHistoryEvent<Conn> &HdbppTxHistoryEvent<Conn>::store() +auto HdbppTxHistoryEvent<Conn>::store() -> HdbppTxHistoryEvent<Conn> & { if (_attr_name.empty()) { diff --git a/src/HdbppTxNewAttribute.hpp b/src/HdbppTxNewAttribute.hpp index bbcced70b259a9a9ec9ab38f69c5a0a45ec922ef..587114cf2d9e75d40ba88478769d3cc03c9000ca 100644 --- a/src/HdbppTxNewAttribute.hpp +++ b/src/HdbppTxNewAttribute.hpp @@ -37,27 +37,27 @@ class HdbppTxNewAttribute : public HdbppTxBase<Conn> public: HdbppTxNewAttribute(Conn &conn) : HdbppTxBase<Conn>(conn) {} - HdbppTxNewAttribute<Conn> &withName(const std::string &fqdn_attr_name) + auto withName(const std::string &fqdn_attr_name) -> HdbppTxNewAttribute<Conn> & { _attr_name = AttributeName {fqdn_attr_name}; return *this; } - HdbppTxNewAttribute<Conn> &withTraits( - Tango::AttrWriteType write, Tango::AttrDataFormat format, Tango::CmdArgType type) + auto withTraits( + Tango::AttrWriteType write, Tango::AttrDataFormat format, Tango::CmdArgType type) -> HdbppTxNewAttribute<Conn> & { _traits = AttributeTraits(write, format, type); return *this; } - HdbppTxNewAttribute<Conn> &withTtl(unsigned int ttl) + auto withTtl(unsigned int ttl) -> HdbppTxNewAttribute<Conn> & { _ttl = ttl; return *this; } // trigger the database storage routines - HdbppTxNewAttribute<Conn> &store(); + auto store() -> HdbppTxNewAttribute<Conn> &; /// @brief Print the HdbppTxNewAttribute object to the stream void print(std::ostream &os) const noexcept override; @@ -71,7 +71,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxNewAttribute<Conn> &HdbppTxNewAttribute<Conn>::store() +auto HdbppTxNewAttribute<Conn>::store() -> HdbppTxNewAttribute<Conn> & { if (_attr_name.empty()) { @@ -107,7 +107,7 @@ HdbppTxNewAttribute<Conn> &HdbppTxNewAttribute<Conn>::store() } // unsupported types - if (_traits.type() == Tango::DEV_ENUM || _traits.type() == Tango::DEV_ENCODED) + if (_traits.type() == Tango::DEV_ENCODED) { std::string msg {"Unsupported attribute type: " + tangoEnumToString(_traits.type()) + ". For attribute: " + _attr_name.fqdnAttributeName()}; diff --git a/src/HdbppTxParameterEvent.hpp b/src/HdbppTxParameterEvent.hpp index 709e3998851a7c3ab0abcddca3cca18daf771c65..2ee37b9ae3480c1770494e657d74f1d9f68f6f72 100644 --- a/src/HdbppTxParameterEvent.hpp +++ b/src/HdbppTxParameterEvent.hpp @@ -38,20 +38,20 @@ class HdbppTxParameterEvent : public HdbppTxBase<Conn> public: HdbppTxParameterEvent(Conn &conn) : HdbppTxBase<Conn>(conn) {} - HdbppTxParameterEvent<Conn> &withName(const std::string &fqdn_attr_name) + auto withName(const std::string &fqdn_attr_name) -> HdbppTxParameterEvent<Conn> & { _attr_name = AttributeName {fqdn_attr_name}; return *this; } - HdbppTxParameterEvent<Conn> &withAttrInfo(const Tango::AttributeInfoEx &attr_conf) + auto withAttrInfo(const Tango::AttributeInfoEx &attr_conf) -> HdbppTxParameterEvent<Conn> & { _attr_info_ex = attr_conf; _attr_info_ex_set = true; return *this; } - HdbppTxParameterEvent<Conn> &withEventTime(Tango::TimeVal tv) + auto withEventTime(Tango::TimeVal tv) -> HdbppTxParameterEvent<Conn> & { // convert to a double that can be passed on to the storage api _event_time = tv.tv_sec + tv.tv_usec / 1.0e6; @@ -59,7 +59,7 @@ public: } // trigger the database storage routines - HdbppTxParameterEvent<Conn> &store(); + auto store() -> HdbppTxParameterEvent<Conn> &; /// @brief Print the HdbppTxParameterEvent object to the stream void print(std::ostream &os) const noexcept override; @@ -83,7 +83,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxParameterEvent<Conn> &HdbppTxParameterEvent<Conn>::store() +auto HdbppTxParameterEvent<Conn>::store() -> HdbppTxParameterEvent<Conn> & { if (_attr_name.empty()) { @@ -118,6 +118,7 @@ HdbppTxParameterEvent<Conn> &HdbppTxParameterEvent<Conn>::store() HdbppTxBase<Conn>::connection().storeParameterEvent(HdbppTxBase<Conn>::attrNameForStorage(_attr_name), _event_time, _attr_info_ex.label, + _attr_info_ex.enum_labels, _attr_info_ex.unit, _attr_info_ex.standard_unit, _attr_info_ex.display_unit, diff --git a/src/HdbppTxUpdateTtl.hpp b/src/HdbppTxUpdateTtl.hpp index d957585bb22cc6e4d6e4bf3688cf0c05531f3040..883976dcf1634cdf066ed97e879fff4793effd97 100644 --- a/src/HdbppTxUpdateTtl.hpp +++ b/src/HdbppTxUpdateTtl.hpp @@ -36,20 +36,20 @@ class HdbppTxUpdateTtl : public HdbppTxBase<Conn> public: HdbppTxUpdateTtl(Conn &conn) : HdbppTxBase<Conn>(conn) {} - HdbppTxUpdateTtl<Conn> &withName(const std::string &fqdn_attr_name) + auto withName(const std::string &fqdn_attr_name) -> HdbppTxUpdateTtl<Conn> & { _attr_name = AttributeName {fqdn_attr_name}; return *this; } - HdbppTxUpdateTtl<Conn> &withTtl(unsigned int ttl) + auto withTtl(unsigned int ttl) -> HdbppTxUpdateTtl<Conn> & { _ttl = ttl; return *this; } // trigger the database storage routines - HdbppTxUpdateTtl<Conn> &store(); + auto store() -> HdbppTxUpdateTtl<Conn> &; /// @brief Print the HdbppTxUpdateTtl object to the stream void print(std::ostream &os) const noexcept override; @@ -64,7 +64,7 @@ private: //============================================================================= //============================================================================= template<typename Conn> -HdbppTxUpdateTtl<Conn> &HdbppTxUpdateTtl<Conn>::store() +auto HdbppTxUpdateTtl<Conn>::store() -> HdbppTxUpdateTtl<Conn> & { if (_attr_name.empty()) { diff --git a/src/LibUtils.cpp b/src/LibUtils.cpp index 01fd4bad43f9c07fb56db4160f879f43839450bd..72492b8706d71e1ea650de2d655ef7e2ffecde89 100644 --- a/src/LibUtils.cpp +++ b/src/LibUtils.cpp @@ -30,7 +30,7 @@ namespace hdbpp_internal { //============================================================================= //============================================================================= -string tangoEnumToString(Tango::AttrWriteType write_type) +auto tangoEnumToString(Tango::AttrWriteType write_type) -> string { switch (write_type) { @@ -46,7 +46,7 @@ string tangoEnumToString(Tango::AttrWriteType write_type) //============================================================================= //============================================================================= -string tangoEnumToString(Tango::AttrDataFormat format) +auto tangoEnumToString(Tango::AttrDataFormat format) -> string { switch (format) { @@ -61,7 +61,7 @@ string tangoEnumToString(Tango::AttrDataFormat format) //============================================================================= //============================================================================= -string tangoEnumToString(Tango::CmdArgType type) +auto tangoEnumToString(Tango::CmdArgType type) -> string { switch (type) { @@ -87,7 +87,7 @@ string tangoEnumToString(Tango::CmdArgType type) //============================================================================= //============================================================================= -string tangoEnumToString(Tango::AttrQuality quality) +auto tangoEnumToString(Tango::AttrQuality quality) -> string { switch (quality) { @@ -103,7 +103,7 @@ string tangoEnumToString(Tango::AttrQuality quality) //============================================================================= //============================================================================= -ostream &operator<<(ostream &os, Tango::AttrWriteType write_type) +auto operator<<(ostream &os, Tango::AttrWriteType write_type) -> ostream & { os << tangoEnumToString(write_type); return os; @@ -111,7 +111,7 @@ ostream &operator<<(ostream &os, Tango::AttrWriteType write_type) //============================================================================= //============================================================================= -ostream &operator<<(ostream &os, Tango::AttrDataFormat format) +auto operator<<(ostream &os, Tango::AttrDataFormat format) -> ostream & { os << tangoEnumToString(format); return os; @@ -119,7 +119,7 @@ ostream &operator<<(ostream &os, Tango::AttrDataFormat format) //============================================================================= //============================================================================= -ostream &operator<<(ostream &os, Tango::CmdArgType type) +auto operator<<(ostream &os, Tango::CmdArgType type) -> ostream & { os << tangoEnumToString(type); return os; @@ -127,7 +127,7 @@ ostream &operator<<(ostream &os, Tango::CmdArgType type) //============================================================================= //============================================================================= -ostream &operator<<(ostream &os, Tango::AttrQuality quality) +auto operator<<(ostream &os, Tango::AttrQuality quality) -> ostream & { os << tangoEnumToString(quality); return os; diff --git a/src/LibUtils.hpp b/src/LibUtils.hpp index 0a778f8c348cfa907577bbc8e0f86ee440e842b0..19f1cfffa369d109f4a71d261ccf1c2224808c6f 100644 --- a/src/LibUtils.hpp +++ b/src/LibUtils.hpp @@ -47,16 +47,16 @@ auto operator<<(std::ostream &os, const T &t) -> decltype(t.print(os), static_ca } // to_string functions for tango enums -std::string tangoEnumToString(Tango::AttrWriteType write_type); -std::string tangoEnumToString(Tango::AttrDataFormat format); -std::string tangoEnumToString(Tango::CmdArgType type); -std::string tangoEnumToString(Tango::AttrQuality quality); +auto tangoEnumToString(Tango::AttrWriteType write_type) -> std::string; +auto tangoEnumToString(Tango::AttrDataFormat format) -> std::string; +auto tangoEnumToString(Tango::CmdArgType type) -> std::string; +auto tangoEnumToString(Tango::AttrQuality quality) -> std::string; // some output operators for tango enums -std::ostream &operator<<(std::ostream &os, Tango::AttrWriteType write_type); -std::ostream &operator<<(std::ostream &os, Tango::AttrDataFormat format); -std::ostream &operator<<(std::ostream &os, Tango::CmdArgType type); -std::ostream &operator<<(std::ostream &os, Tango::AttrQuality quality); +auto operator<<(std::ostream &os, Tango::AttrWriteType write_type) -> std::ostream &; +auto operator<<(std::ostream &os, Tango::AttrDataFormat format) -> std::ostream &; +auto operator<<(std::ostream &os, Tango::CmdArgType type) -> std::ostream &; +auto operator<<(std::ostream &os, Tango::AttrQuality quality) -> std::ostream &; struct LogConfigurator { @@ -76,7 +76,7 @@ namespace logging_utils const std::string SyslogIdent = "hdbpp-timescale-"; // get the file name from the __FILE__ variable for error messages - constexpr auto *getFileName(const char *const path) + constexpr auto getFileName(const char *const path) -> auto * { // We silence clang warnings for this funciton, this is a quick and simple // way to produce the file name, and yes we use pointer arithmetic, but diff --git a/src/PqxxExtension.hpp b/src/PqxxExtension.hpp index 1b7092914025c02bdbdd5a455f721f3f64ad6b61..285e497b8669a18ee742207632b20dc5e806abdb 100644 --- a/src/PqxxExtension.hpp +++ b/src/PqxxExtension.hpp @@ -144,7 +144,7 @@ template<typename T> struct string_traits<std::vector<T>> { public: - static constexpr const char *name() noexcept { return internal::type_name<T>::value; } + static constexpr auto name() noexcept -> const char * { return internal::type_name<T>::value; } // NOLINTNEXTLINE (readability-identifier-naming) static constexpr bool has_null() noexcept { return false; } @@ -152,7 +152,7 @@ public: // NOLINTNEXTLINE (readability-identifier-naming) static bool is_null(const std::vector<T> & /*unused*/) { return false; } - [[noreturn]] static std::vector<T> null() { internal::throw_null_conversion(name()); } + [[noreturn]] static auto null() -> std::vector<T> { internal::throw_null_conversion(name()); } // NOLINTNEXTLINE (readability-identifier-naming) static void from_string(const char str[], std::vector<T> &value) @@ -209,7 +209,7 @@ template<> struct string_traits<std::vector<std::string>> { public: - static constexpr const char *name() noexcept { return "vector<string>"; } + static constexpr auto name() noexcept -> const char * { return "vector<string>"; } // NOLINTNEXTLINE (readability-identifier-naming) static constexpr bool has_null() noexcept { return false; } @@ -217,7 +217,7 @@ public: // NOLINTNEXTLINE (readability-identifier-naming) static bool is_null(const std::vector<std::string> & /*unused*/) { return false; } - [[noreturn]] static std::vector<std::string> null() { internal::throw_null_conversion(name()); } + [[noreturn]] static auto null() -> std::vector<std::string> { internal::throw_null_conversion(name()); } // NOLINTNEXTLINE (readability-identifier-naming) static void from_string(const char str[], std::vector<std::string> &value) @@ -272,7 +272,7 @@ template<> struct string_traits<std::vector<bool>> { public: - static constexpr const char *name() noexcept { return "std::vector<bool>"; } + static constexpr auto name() noexcept -> const char * { return "std::vector<bool>"; } // NOLINTNEXTLINE (readability-identifier-naming) static constexpr bool has_null() noexcept { return false; } @@ -280,7 +280,7 @@ public: // NOLINTNEXTLINE (readability-identifier-naming) static bool is_null(const std::vector<bool> & /*unused*/) { return false; } - [[noreturn]] static std::vector<bool> null() { internal::throw_null_conversion(name()); } + [[noreturn]] static auto null() -> std::vector<bool> { internal::throw_null_conversion(name()); } // NOLINTNEXTLINE (readability-identifier-naming) static void from_string(const char str[], std::vector<bool> &value) diff --git a/src/QueryBuilder.cpp b/src/QueryBuilder.cpp index f4a6dc694ed0c10802dfe738933327485d687e09..a335346530433923ba698937a3673bfaea8c7f9a 100644 --- a/src/QueryBuilder.cpp +++ b/src/QueryBuilder.cpp @@ -34,79 +34,79 @@ namespace pqxx_conn // this is important for the custom types, since the library libpqxx and postgres will // not know how to store them. template<> - std::string postgresCast<double>(bool is_array) + auto postgresCast<double>(bool is_array) -> std::string { return is_array ? "float8[]" : "float8"; } template<> - std::string postgresCast<float>(bool is_array) + auto postgresCast<float>(bool is_array) -> std::string { return is_array ? "float4[]" : "float4"; } template<> - std::string postgresCast<string>(bool is_array) + auto postgresCast<string>(bool is_array) -> std::string { return is_array ? "text[]" : "text"; } template<> - std::string postgresCast<bool>(bool is_array) + auto postgresCast<bool>(bool is_array) -> std::string { return is_array ? "bool[]" : "bool"; } template<> - std::string postgresCast<int32_t>(bool is_array) + auto postgresCast<int32_t>(bool is_array) -> std::string { return is_array ? "int4[]" : "int4"; } template<> - std::string postgresCast<uint32_t>(bool is_array) + auto postgresCast<uint32_t>(bool is_array) -> std::string { return is_array ? "ulong[]" : "ulong"; } template<> - std::string postgresCast<int64_t>(bool is_array) + auto postgresCast<int64_t>(bool is_array) -> std::string { return is_array ? "int8[]" : "int8"; } template<> - std::string postgresCast<uint64_t>(bool is_array) + auto postgresCast<uint64_t>(bool is_array) -> std::string { return is_array ? "ulong64[]" : "ulong64"; } template<> - std::string postgresCast<int16_t>(bool is_array) + auto postgresCast<int16_t>(bool is_array) -> std::string { return is_array ? "int2[]" : "int2"; } template<> - std::string postgresCast<uint16_t>(bool is_array) + auto postgresCast<uint16_t>(bool is_array) -> std::string { return is_array ? "ushort[]" : "ushort"; } template<> - std::string postgresCast<uint8_t>(bool is_array) + auto postgresCast<uint8_t>(bool is_array) -> std::string { return is_array ? "uchar[]" : "uchar"; } template<> - std::string postgresCast<vector<uint8_t>>(bool is_array) + auto postgresCast<vector<uint8_t>>(bool is_array) -> std::string { return is_array ? "bytea[]" : "bytea"; } template<> - std::string postgresCast<Tango::DevState>(bool is_array) + auto postgresCast<Tango::DevState>(bool is_array) -> std::string { return is_array ? "int4[]" : "int4"; } @@ -114,7 +114,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeDataEventName(const AttributeTraits &traits) + auto QueryBuilder::storeDataEventName(const AttributeTraits &traits) -> const string & { // generic check and emplace for new items return handleCache(_data_event_query_names, traits, StoreDataEvent); @@ -122,7 +122,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeDataEventErrorName(const AttributeTraits &traits) + auto QueryBuilder::storeDataEventErrorName(const AttributeTraits &traits) -> const string & { // generic check and emplace for new items return handleCache(_data_event_error_query_names, traits, StoreDataEventError); @@ -130,7 +130,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeAttributeStatement() + auto QueryBuilder::storeAttributeStatement() -> const string & { // clang-format off static string query = @@ -168,7 +168,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeHistoryStringStatement() + auto QueryBuilder::storeHistoryStringStatement() -> const string & { // clang-format off static string query = @@ -182,7 +182,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeHistoryEventStatement() + auto QueryBuilder::storeHistoryEventStatement() -> const string & { // clang-format off static string query = @@ -201,7 +201,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeParameterEventStatement() + auto QueryBuilder::storeParameterEventStatement() -> const string & { // clang-format off static string query = @@ -210,6 +210,7 @@ namespace pqxx_conn schema::ParamColId + "," + schema::ParamColEvTime + "," + schema::ParamColLabel + "," + + schema::ParamColEnumLabels + "," + schema::ParamColUnit + "," + schema::ParamColStandardUnit + "," + schema::ParamColDisplayUnit + "," + @@ -218,7 +219,7 @@ namespace pqxx_conn schema::ParamColArchiveAbsChange + "," + schema::ParamColArchivePeriod + "," + schema::ParamColDescription + ") " + - "VALUES ($1, TO_TIMESTAMP($2), $3, $4, $5, $6, $7, $8, $9, $10, $11)"; + "VALUES ($1, TO_TIMESTAMP($2), $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"; // clang-format on return query; @@ -226,7 +227,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeDataEventErrorStatement(const AttributeTraits &traits) + auto QueryBuilder::storeDataEventErrorStatement(const AttributeTraits &traits) -> const string & { // search the cache for a previous entry auto result = _data_event_error_queries.find(traits); @@ -263,11 +264,11 @@ namespace pqxx_conn //============================================================================= //============================================================================= - string QueryBuilder::storeDataEventErrorString(const string &id, + auto QueryBuilder::storeDataEventErrorString(const string &id, const string &event_time, const string &quality, const string &err_id, - const AttributeTraits &traits) + const AttributeTraits &traits) -> std::string { // clang-format off auto query = "INSERT INTO " + @@ -288,7 +289,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::storeErrorStatement() + auto QueryBuilder::storeErrorStatement() -> const string & { // clang-format off static string query = @@ -304,7 +305,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const std::string &QueryBuilder::storeTtlStatement() + auto QueryBuilder::storeTtlStatement() -> const string & { // clang-format off static string query = @@ -317,23 +318,23 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string QueryBuilder::fetchAllValuesStatement( - const string &column_name, const string &table_name, const string &reference) + auto QueryBuilder::fetchAllValuesStatement( + const string &column_name, const string &table_name, const string &reference) -> const string { return "SELECT " + column_name + ", " + reference + " " + "FROM " + table_name; } //============================================================================= //============================================================================= - const string QueryBuilder::fetchValueStatement( - const string &column_name, const string &table_name, const string &reference) + auto QueryBuilder::fetchValueStatement( + const string &column_name, const string &table_name, const string &reference) -> const string { return "SELECT " + column_name + " " + "FROM " + table_name + " WHERE " + reference + "=$1"; } //============================================================================= //============================================================================= - const string &QueryBuilder::fetchLastHistoryEventStatement() + auto QueryBuilder::fetchLastHistoryEventStatement() -> const string & { // clang-format off static string query = @@ -351,7 +352,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const std::string &QueryBuilder::fetchAttributeTraitsStatement() + auto QueryBuilder::fetchAttributeTraitsStatement() -> const string & { // clang-format off static string query = @@ -381,7 +382,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= - string QueryBuilder::tableName(const AttributeTraits &traits) + auto QueryBuilder::tableName(const AttributeTraits &traits) -> string { return schema::SchemaTablePrefix + [&traits]() { @@ -419,8 +420,8 @@ namespace pqxx_conn //============================================================================= //============================================================================= - const string &QueryBuilder::handleCache( - map<AttributeTraits, string> &cache, const AttributeTraits &traits, const string &stub) + auto QueryBuilder::handleCache( + map<AttributeTraits, string> &cache, const AttributeTraits &traits, const string &stub) -> const string & { auto result = cache.find(traits); diff --git a/src/QueryBuilder.hpp b/src/QueryBuilder.hpp index 92d4f0fda3cb9407b8f61c7db1023e87b369d685..504c567463efd6f205f3fe183cd29c04cf1bd76b 100644 --- a/src/QueryBuilder.hpp +++ b/src/QueryBuilder.hpp @@ -37,7 +37,7 @@ namespace std template<> struct less<hdbpp_internal::AttributeTraits> { - bool operator()(const hdbpp_internal::AttributeTraits &lhs, const hdbpp_internal::AttributeTraits &rhs) const + auto operator()(const hdbpp_internal::AttributeTraits &lhs, const hdbpp_internal::AttributeTraits &rhs) -> bool { auto a = lhs.type(); auto b = lhs.writeType(); @@ -59,7 +59,7 @@ namespace pqxx_conn // This function generates the postgres cast for the event data insert // queries, it is specialized for all possible tango types template<typename T> - std::string postgresCast(bool is_array); + auto postgresCast(bool is_array) -> std::string; // Convert the given data into a string suitable for storing in the database. These calls // are used to build the string version of the insert command, they are required since we @@ -68,7 +68,7 @@ namespace pqxx_conn template<typename T> struct DataToString { - static std::string run(const std::unique_ptr<std::vector<T>> &value, const AttributeTraits &traits) + static auto run(const std::unique_ptr<std::vector<T>> &value, const AttributeTraits &traits) -> std::string { if (traits.isScalar()) return pqxx::to_string((*value)[0]); @@ -81,7 +81,7 @@ namespace pqxx_conn template<> struct DataToString<bool> { - static std::string run(const std::unique_ptr<std::vector<bool>> &value, const AttributeTraits &traits) + static auto run(const std::unique_ptr<std::vector<bool>> &value, const AttributeTraits &traits) -> std::string { // a vector<bool> is not actually a vector<bool>, rather its some kind of bitfield. When // trying to return an element, we appear to get some kind of bitfield reference, @@ -103,8 +103,8 @@ namespace pqxx_conn template<> struct DataToString<std::string> { - static std::string run( - const std::unique_ptr<std::vector<std::string>> &value, const AttributeTraits &traits) + static auto run( + const std::unique_ptr<std::vector<std::string>> &value, const AttributeTraits &traits) -> std::string { // arrays of strings need both the ARRAY keywords and dollar escaping, this is so we // do not have to rely on the postgres escape functions that double and then store @@ -158,64 +158,64 @@ namespace pqxx_conn // these builder functions require no caching, so can be simple static // functions - static std::string tableName(const AttributeTraits &traits); - static const std::string &storeAttributeStatement(); - static const std::string &storeHistoryEventStatement(); - static const std::string &storeHistoryStringStatement(); - static const std::string &storeParameterEventStatement(); - static const std::string &storeErrorStatement(); - static const std::string &storeTtlStatement(); - static const std::string &fetchLastHistoryEventStatement(); - static const std::string &fetchAttributeTraitsStatement(); + static auto tableName(const AttributeTraits &traits) -> std::string; + static auto storeAttributeStatement() -> const std::string &; + static auto storeHistoryEventStatement() -> const std::string &; + static auto storeHistoryStringStatement() -> const std::string &; + static auto storeParameterEventStatement() -> const std::string &; + static auto storeErrorStatement() -> const std::string &; + static auto storeTtlStatement() -> const std::string &; + static auto fetchLastHistoryEventStatement() -> const std::string &; + static auto fetchAttributeTraitsStatement() -> const std::string &; - static const std::string fetchValueStatement( - const std::string &column_name, const std::string &table_name, const std::string &reference); + static auto fetchValueStatement( + const std::string &column_name, const std::string &table_name, const std::string &reference) -> const std::string; - static const std::string fetchAllValuesStatement( - const std::string &column_name, const std::string &table_name, const std::string &reference); + static auto fetchAllValuesStatement( + const std::string &column_name, const std::string &table_name, const std::string &reference) -> const std::string; // Non-static prepared statements // these builder functions cache the built queries, therefore they // are not static like the others sincethey require data storage - const std::string &storeDataEventName(const AttributeTraits &traits); - const std::string &storeDataEventErrorName(const AttributeTraits &traits); + auto storeDataEventName(const AttributeTraits &traits) -> const std::string &; + auto storeDataEventErrorName(const AttributeTraits &traits) -> const std::string &; // Builds a prepared statement for the given traits, the statement is cached // internally to improve execution time template<typename T> - const std::string &storeDataEventStatement(const AttributeTraits &traits); + auto storeDataEventStatement(const AttributeTraits &traits) -> const std::string &; // A variant of storeDataEventStatement that builds a string based on the // parameters, this is then passed back to the caller to be executed. No // internal caching, so its less efficient, but can be chained in a pipe // to batch data to the database. template<typename T> - static std::string storeDataEventString(const std::string &id, + static auto storeDataEventString(const std::string &id, const std::string &event_time, const std::string &quality, const std::unique_ptr<vector<T>> &value_r, const std::unique_ptr<vector<T>> &value_w, - const AttributeTraits &traits); + const AttributeTraits &traits) -> std::string; // Builds a prepared statement for data event errors - const std::string &storeDataEventErrorStatement(const AttributeTraits &traits); + auto storeDataEventErrorStatement(const AttributeTraits &traits) -> const std::string &; // A vareint of storeDataEventErrorStatement that build and returns a string // instead of a prepared statement - static std::string storeDataEventErrorString(const std::string &id, + static auto storeDataEventErrorString(const std::string &id, const std::string &event_time, const std::string &quality, const std::string &err_id, - const AttributeTraits &traits); + const AttributeTraits &traits) -> std::string; // Utility void print(std::ostream &os) const noexcept; private: // generic function to handle caching items into the cache maps - const string &handleCache( - std::map<AttributeTraits, std::string> &cache, const AttributeTraits &traits, const std::string &stub); + auto handleCache( + std::map<AttributeTraits, std::string> &cache, const AttributeTraits &traits, const std::string &stub) -> const std::string &; // cached query names, these are built from the traits object std::map<AttributeTraits, std::string> _data_event_query_names; @@ -229,7 +229,7 @@ namespace pqxx_conn //============================================================================= //============================================================================= template<typename T> - const string &QueryBuilder::storeDataEventStatement(const AttributeTraits &traits) + auto QueryBuilder::storeDataEventStatement(const AttributeTraits &traits) -> const std::string & { // search the cache for a previous entry auto result = _data_event_queries.find(traits); @@ -280,12 +280,12 @@ namespace pqxx_conn } template<typename T> - std::string QueryBuilder::storeDataEventString(const std::string &id, + auto QueryBuilder::storeDataEventString(const std::string &id, const std::string &event_time, const std::string &quality, const std::unique_ptr<vector<T>> &value_r, const std::unique_ptr<vector<T>> &value_w, - const AttributeTraits &traits) + const AttributeTraits &traits) -> std::string { auto query = "INSERT INTO " + QueryBuilder::tableName(traits) + " (" + schema::DatColId + "," + schema::DatColDataTime; diff --git a/src/TimescaleSchema.hpp b/src/TimescaleSchema.hpp index 6a8e48b20ca22c15540b2da51aa83cc2cbbde3c2..472162c710b4b449caba2aefae4c502d0f19e58e 100644 --- a/src/TimescaleSchema.hpp +++ b/src/TimescaleSchema.hpp @@ -102,6 +102,7 @@ namespace pqxx_conn const std::string ParamColInsTime = "insert_time"; const std::string ParamColEvTime = "recv_time"; const std::string ParamColLabel = "label"; + const std::string ParamColEnumLabels = "enum_labels"; const std::string ParamColUnit = "unit"; const std::string ParamColStandardUnit = "standard_unit"; const std::string ParamColDisplayUnit = "display_unit"; diff --git a/test/DbConnectionTests.cpp b/test/DbConnectionTests.cpp index b38f08b18e4cdfef27fd74b5775c7ca9770681e8..29e47030cbc93b6a58b51cb41b12274312965703 100644 --- a/test/DbConnectionTests.cpp +++ b/test/DbConnectionTests.cpp @@ -448,6 +448,69 @@ TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, SUCCEED("Passed"); } +TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, + "Storing Attributes in the database in uppercase", + "[db-access][hdbpp-db-access][db-connection]") +{ + DbConnection conn(DbConnection::DbStoreMethod::PreparedStatement); + AttributeTraits traits {Tango::READ, Tango::SCALAR, Tango::DEV_STRING}; + + REQUIRE_NOTHROW(clearTables()); + + auto param_to_upper = [](auto param) { + locale loc; + string tmp; + + for (string::size_type i = 0; i < param.length(); ++i) + tmp += toupper(param[i], loc); + + return tmp; + }; + + testConn().storeAttribute(param_to_upper(attr_name::TestAttrFinalName), + param_to_upper(attr_name::TestAttrCs), + param_to_upper(attr_name::TestAttrDomain), + param_to_upper(attr_name::TestAttrFamily), + param_to_upper(attr_name::TestAttrMember), + param_to_upper(attr_name::TestAttrName), + 100, + traits); + + { + pqxx::work tx {verifyConn()}; + auto attr_row(tx.exec1("SELECT * FROM " + schema::ConfTableName)); + + auto type_row(tx.exec1("SELECT " + schema::ConfTypeColTypeId + " FROM " + schema::ConfTypeTableName + + " WHERE " + schema::ConfTypeColTypeNum + " = " + std::to_string(traits.type()))); + + auto format_row(tx.exec1("SELECT " + schema::ConfFormatColFormatId + " FROM " + schema::ConfFormatTableName + + " WHERE " + schema::ConfFormatColFormatNum + " = " + std::to_string(traits.formatType()))); + + auto access_row(tx.exec1("SELECT " + schema::ConfWriteColWriteId + " FROM " + schema::ConfWriteTableName + + " WHERE " + schema::ConfWriteColWriteNum + " = " + std::to_string(traits.writeType()))); + + tx.commit(); + + REQUIRE(attr_row.at(schema::ConfColName).as<string>() == param_to_upper(attr_name::TestAttrFQDName)); + REQUIRE(attr_row.at(schema::ConfColCsName).as<string>() == param_to_upper(attr_name::TestAttrCs)); + REQUIRE(attr_row.at(schema::ConfColDomain).as<string>() == param_to_upper(attr_name::TestAttrDomain)); + REQUIRE(attr_row.at(schema::ConfColFamily).as<string>() == param_to_upper(attr_name::TestAttrFamily)); + REQUIRE(attr_row.at(schema::ConfColMember).as<string>() == param_to_upper(attr_name::TestAttrMember)); + REQUIRE(attr_row.at(schema::ConfColLastName).as<string>() == param_to_upper(attr_name::TestAttrName)); + REQUIRE(attr_row.at(schema::ConfColTableName).as<string>() == QueryBuilder().tableName(traits)); + + REQUIRE(attr_row.at(schema::ConfColTypeId).as<int>() == type_row.at(schema::ConfTypeColTypeId).as<int>()); + + REQUIRE(attr_row.at(schema::ConfColFormatTypeId).as<int>() == + format_row.at(schema::ConfFormatColFormatId).as<int>()); + + REQUIRE( + attr_row.at(schema::ConfColWriteTypeId).as<int>() == access_row.at(schema::ConfWriteColWriteId).as<int>()); + } + + SUCCEED("Passed"); +} + TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, "Storing a series of the same History Events in the database successfully", "[db-access][hdbpp-db-access][db-connection]") @@ -564,6 +627,7 @@ TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, REQUIRE_NOTHROW(testConn().storeParameterEvent(attr_name::TestAttrFinalName, event_time, attr_info::AttrInfoLabel, + attr_info::AttrInfoEnumLabels, attr_info::AttrInfoUnit, attr_info::AttrInfoStandardUnit, attr_info::AttrInfoDisplayUnit, @@ -582,6 +646,8 @@ TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, // TODO check event time //REQUIRE(param_row.at(schema::ParamColEvTime).as<double>() == event_time); REQUIRE(param_row.at(schema::ParamColLabel).as<string>() == attr_info::AttrInfoLabel); + // TODO check enum labels + REQUIRE(param_row.at(schema::ParamColEnumLabels).as<vector<string>>() == attr_info::AttrInfoEnumLabels); REQUIRE(param_row.at(schema::ParamColUnit).as<string>() == attr_info::AttrInfoUnit); REQUIRE(param_row.at(schema::ParamColStandardUnit).as<string>() == attr_info::AttrInfoStandardUnit); REQUIRE(param_row.at(schema::ParamColDisplayUnit).as<string>() == attr_info::AttrInfoDisplayUnit); @@ -598,6 +664,7 @@ TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, REQUIRE_NOTHROW(testConn().storeParameterEvent(attr_name::TestAttrFinalName, event_time, attr_info::AttrInfoLabel, + attr_info::AttrInfoEnumLabels, attr_info::AttrInfoUnit, attr_info::AttrInfoStandardUnit, attr_info::AttrInfoDisplayUnit, @@ -633,6 +700,7 @@ TEST_CASE_METHOD(pqxx_conn_test::DbConnectionTestsFixture, REQUIRE_THROWS_AS(conn.storeParameterEvent(attr_name::TestAttrFinalName, event_time, attr_info::AttrInfoLabel, + attr_info::AttrInfoEnumLabels, attr_info::AttrInfoUnit, attr_info::AttrInfoStandardUnit, attr_info::AttrInfoDisplayUnit, diff --git a/test/HdbppTxDataEventTests.cpp b/test/HdbppTxDataEventTests.cpp index 4d06bce9128c1952c1e75064efebb8d77489286f..6531309a0d68977f3bc21f85e0e512971561e680 100644 --- a/test/HdbppTxDataEventTests.cpp +++ b/test/HdbppTxDataEventTests.cpp @@ -85,8 +85,9 @@ Tango::DeviceAttribute createDeviceAttribute(const AttributeTraits &traits) return Tango::DeviceAttribute( TestAttrFQDName.c_str(), *generateSpectrumData<Tango::DEV_STATE>(false, size_x + size_y)); - //case Tango::DEV_ENUM: - //return Tango::DeviceAttribute(TestAttrFQDName.c_str(), *generateSpectrumData<Tango::DEV_ENUM>(false, size_x + size_y)); + case Tango::DEV_ENUM: + return Tango::DeviceAttribute( + TestAttrFQDName.c_str(), *generateSpectrumData<Tango::DEV_ENUM>(false, size_x + size_y)); //case Tango::DEV_ENCODED: //return Tango::DeviceAttribute(TestAttrFQDName.c_str(), *generateSpectrumData<Tango::DEV_ENCODED>(false, size_x + size_y)); @@ -439,8 +440,8 @@ TEST_CASE("Creating HdbppTxDataEvents for each tango type and storing them", "[d Tango::DEV_USHORT, Tango::DEV_UCHAR, Tango::DEV_STATE, - /* Tango::DEV_ENCODED, - Tango::DEV_ENUM */}; + /* Tango::DEV_ENCODED,*/ + Tango::DEV_ENUM}; vector<Tango::AttrWriteType> write_types {Tango::READ, Tango::WRITE, Tango::READ_WRITE, Tango::READ_WITH_WRITE}; vector<Tango::AttrDataFormat> format_types {Tango::SCALAR, Tango::SPECTRUM}; diff --git a/test/HdbppTxParameterEventTests.cpp b/test/HdbppTxParameterEventTests.cpp index 90e9eca28000f3dfa412e9b0f4af7d05641f6ac2..1d42215e7c2606514fbc21387b15b1d6452d3d24 100644 --- a/test/HdbppTxParameterEventTests.cpp +++ b/test/HdbppTxParameterEventTests.cpp @@ -44,6 +44,7 @@ AttributeInfoEx createAttributeInfoEx() AttributeInfoEx attr_info; attr_info.description = AttrInfoDescription; attr_info.label = AttrInfoLabel; + attr_info.enum_labels = AttrInfoEnumLabels; attr_info.unit = AttrInfoUnit; attr_info.standard_unit = AttrInfoStandardUnit; attr_info.display_unit = AttrInfoDisplayUnit; @@ -68,6 +69,7 @@ public: void storeParameterEvent(const string &full_attr_name, double event_time, const string &label, + const vector<string> &enum_labels, const string &unit, const string &standard_unit, const string &display_unit, @@ -83,6 +85,7 @@ public: att_name = full_attr_name; att_event_time = event_time; att_label = label; + att_enum_labels = enum_labels; att_unit = unit; att_standard_unit = standard_unit; att_display_unit = display_unit; @@ -98,6 +101,7 @@ public: string att_name; double att_event_time = 0; string att_label; + vector<string> att_enum_labels; string att_unit; string att_standard_unit; string att_display_unit; @@ -151,6 +155,7 @@ SCENARIO("Construct and store HdbppTxParameterEvent data without error", "[hdbpp REQUIRE(conn.att_name == TestAttrFinalName); REQUIRE(conn.att_event_time == (tango_tv.tv_sec + tango_tv.tv_usec / 1.0e6)); REQUIRE(conn.att_label == AttrInfoLabel); + REQUIRE(conn.att_enum_labels == AttrInfoEnumLabels); REQUIRE(conn.att_unit == AttrInfoUnit); REQUIRE(conn.att_standard_unit == AttrInfoStandardUnit); REQUIRE(conn.att_display_unit == AttrInfoDisplayUnit); @@ -270,4 +275,4 @@ SCENARIO("HdbppTxParameterEvent Simulated exception received", "[hdbpp-tx][hdbpp THEN("An exception is raised") { REQUIRE_THROWS_AS(tx.store(), runtime_error); } } } -} \ No newline at end of file +} diff --git a/test/TestHelpers.cpp b/test/TestHelpers.cpp index b432432f701d815baeff08742af864bb74c38aa8..9e57883caa35ff3364c5bde109a801daf47eb788 100644 --- a/test/TestHelpers.cpp +++ b/test/TestHelpers.cpp @@ -234,6 +234,14 @@ namespace data_gen return value; } + + //============================================================================= + //============================================================================= + template<> + typename TangoTypeTraits<Tango::DEV_ENUM>::array data<Tango::DEV_ENUM>(int size) + { + return move(genericData<int16_t>(size)); + } } // namespace data_gen namespace utils @@ -302,4 +310,4 @@ namespace utils return traits_array; } } // namespace utils -} // namespace hdbpp_test \ No newline at end of file +} // namespace hdbpp_test diff --git a/test/TestHelpers.hpp b/test/TestHelpers.hpp index 089cb7c0f129d4f23bfc95b3ae77a2f970e26f1f..f59fa28788f4180511bbf9d91dd5be77ebf093d0 100644 --- a/test/TestHelpers.hpp +++ b/test/TestHelpers.hpp @@ -73,6 +73,7 @@ namespace attr_info "Description about attribute, its \"quoted\", and 'quoted', yet does it work?"; const std::string AttrInfoLabel = "Label"; + const std::vector<std::string> AttrInfoEnumLabels = {"label1", "label2"}; const std::string AttrInfoUnit = "Unit %"; const std::string AttrInfoStandardUnit = "Standard Unit"; const std::string AttrInfoDisplayUnit = "Display Unit $"; @@ -171,6 +172,14 @@ namespace data_gen using type = Tango::DevState; using array = std::unique_ptr<std::vector<Tango::DevState>>; }; + + template<> + struct TangoTypeTraits<Tango::DEV_ENUM> + { + using type = int16_t; + using array = std::unique_ptr<std::vector<int16_t>>; + }; + template<Tango::CmdArgType Type> typename TangoTypeTraits<Type>::array data(int size); @@ -210,6 +219,9 @@ namespace data_gen template<> typename TangoTypeTraits<Tango::DEV_STATE>::array data<Tango::DEV_STATE>(int size); + + template<> + typename TangoTypeTraits<Tango::DEV_ENUM>::array data<Tango::DEV_ENUM>(int size); template<typename T> std::unique_ptr<std::vector<T>> genericData(int size)