diff --git a/src/Properties.h b/src/Properties.h index df34b45..bec4d10 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -1,7 +1,6 @@ -#include - #pragma once +#include #include "misc/memtracker.h" #include #include "Variable.h" @@ -21,6 +20,8 @@ #define EXTERNALIZE_PROPERTY_DEFINITIONS #endif +#define PROPERTIES_DEFINED + namespace ts { namespace property { enum PropertyType { @@ -527,7 +528,8 @@ namespace ts { return this->property_index == (int) other && this->type_property == type_from_enum(); } - inline bool validate_input(const std::string& value) const { return impl::validateInput(value, this->type_value); } + [[nodiscard]] inline bool is_undefined() const { return property_index == 0; } + [[nodiscard]] inline bool validate_input(const std::string& value) const { return impl::validateInput(value, this->type_value); } }; constexpr static PropertyDescription undefined_property_description{UnknownProperties::UNKNOWN_UNDEFINED, "undefined", "", ValueType::TYPE_UNKNOWN, 0}; @@ -576,7 +578,7 @@ namespace ts { size_t index{begin}; for(; index < property_list.size() - 1; index++) if(property_list[index + 1].type_property != type) - return index; + return index + 1; return property_list.size(); } @@ -657,6 +659,16 @@ namespace ts { return find(type_from_enum(), name); } + template ::value, int>::type = 0> + inline std::vector list() { + constexpr auto type = type_from_enum(); + if(type >= property_list_info.end_index.size()) return {}; + + const auto begin = property_list_info.begin_index[type]; + const auto end = property_list_info.end_index[type]; + return {property_list.begin() + begin, property_list.begin() + end}; + } + template ::value, int>::type = 0> const_modifier inline const std::string_view& name(PropertyEnumType type) { /* defining the return type here to help out my IDE a bit ;) */ return describe(type).name; @@ -690,7 +702,6 @@ namespace ts { struct PropertyBundle { property::PropertyType type; size_t length; - size_t offset; PropertyData properties[0]; }; #ifdef WIN32 diff --git a/src/Variable.h b/src/Variable.h index 4ab4853..218861c 100644 --- a/src/Variable.h +++ b/src/Variable.h @@ -129,6 +129,7 @@ DEFINE_VARIABLE_TRANSFORM_TYPE(type, ntype) DEFINE_VARIABLE_TRANSFORM(class, VARTYPE_INT, std::to_string((size_type) in), static_cast(in.as())); DEFINE_VARIABLE_TRANSFORM(std::string, VARTYPE_TEXT, in, in.value()); +DEFINE_VARIABLE_TRANSFORM(std::string_view, VARTYPE_TEXT, std::string{in}, std::string_view{in}); DEFINE_VARIABLE_TRANSFORM(char*, VARTYPE_TEXT, std::string((const char*) in), (char*) in.value().c_str()); DEFINE_VARIABLE_TRANSFORM(const char*, VARTYPE_TEXT, std::string((const char*) in), in.value().c_str()); diff --git a/src/protocol/AcknowledgeManager.cpp b/src/protocol/AcknowledgeManager.cpp index bbe0b41..0edb8a6 100644 --- a/src/protocol/AcknowledgeManager.cpp +++ b/src/protocol/AcknowledgeManager.cpp @@ -145,6 +145,6 @@ void AcknowledgeManager::update_rto(size_t r) { } else { this->rttvar = (1.f - alpha) * this->rttvar + beta * abs(this->srtt - r); this->srtt = (1.f - alpha) * srtt + alpha * r; - this->rto = std::min(200.f, this->srtt + 4 * this->rttvar); + this->rto = std::max(200.f, this->srtt + 4 * this->rttvar); } } \ No newline at end of file diff --git a/src/query/command3.h b/src/query/command3.h index 9574a8c..f6e224a 100644 --- a/src/query/command3.h +++ b/src/query/command3.h @@ -185,6 +185,13 @@ namespace ts { this->put(key, std::string_view{data}); } +#ifdef PROPERTIES_DEFINED + template ::value, int> = 0> + inline void put(PropertyType key, const T& value) { + this->put(property::name(key), value); + } +#endif + /* directly puts data without checking for duplicates */ inline void put_unchecked(const std::string_view& key, const std::string_view& value) { this->impl_put_unchecked(key, value); @@ -194,6 +201,13 @@ namespace ts { this->put_unchecked(key, std::string_view{value}); } +#ifdef PROPERTIES_DEFINED + template ::value, int> = 0> + inline void put_unchecked(PropertyType key, const T& value) { + this->put_unchecked(property::name(key), value); + } +#endif + template ::value || std::is_same::value), int> = 1> inline void put_unchecked(const std::string_view& key, const T& value) { static_assert(converter::supported, "Target type isn't supported!"); @@ -266,14 +280,14 @@ namespace ts { return command_builder_bulk{this->flag_changed, this->bulks[index]}; } - template - inline void put(size_t index, const std::string_view& key, const T& value) { + template + inline void put(size_t index, const KeyT& key, const ValueT& value) { this->bulk(index).put(key, value); } /* directly puts data without checking for duplicates */ - template - inline void put_unchecked(size_t index, const std::string_view& key, const T& value) { + template + inline void put_unchecked(size_t index, const KeyT& key, const ValueT& value) { this->bulk(index).put_unchecked(key, value); }