A lot of updates for 1.4.12

This commit is contained in:
WolverinDEV 2020-04-08 13:01:37 +02:00
parent 607ae9a3e6
commit e0eb4c5a16
4 changed files with 36 additions and 10 deletions

View File

@ -1,7 +1,6 @@
#include <utility>
#pragma once #pragma once
#include <utility>
#include "misc/memtracker.h" #include "misc/memtracker.h"
#include <ThreadPool/Mutex.h> #include <ThreadPool/Mutex.h>
#include "Variable.h" #include "Variable.h"
@ -21,6 +20,8 @@
#define EXTERNALIZE_PROPERTY_DEFINITIONS #define EXTERNALIZE_PROPERTY_DEFINITIONS
#endif #endif
#define PROPERTIES_DEFINED
namespace ts { namespace ts {
namespace property { namespace property {
enum PropertyType { enum PropertyType {
@ -527,7 +528,8 @@ namespace ts {
return this->property_index == (int) other && this->type_property == type_from_enum<PropertyEnumType>(); return this->property_index == (int) other && this->type_property == type_from_enum<PropertyEnumType>();
} }
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}; constexpr static PropertyDescription undefined_property_description{UnknownProperties::UNKNOWN_UNDEFINED, "undefined", "", ValueType::TYPE_UNKNOWN, 0};
@ -576,7 +578,7 @@ namespace ts {
size_t index{begin}; size_t index{begin};
for(; index < property_list.size() - 1; index++) for(; index < property_list.size() - 1; index++)
if(property_list[index + 1].type_property != type) if(property_list[index + 1].type_property != type)
return index; return index + 1;
return property_list.size(); return property_list.size();
} }
@ -657,6 +659,16 @@ namespace ts {
return find(type_from_enum<PropertyEnumType>(), name); return find(type_from_enum<PropertyEnumType>(), name);
} }
template <typename PropertyEnumType, typename std::enable_if<std::is_enum<PropertyEnumType>::value, int>::type = 0>
inline std::vector<const PropertyDescription*> list() {
constexpr auto type = type_from_enum<PropertyEnumType>();
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 <typename PropertyEnumType, typename std::enable_if<std::is_enum<PropertyEnumType>::value, int>::type = 0> template <typename PropertyEnumType, typename std::enable_if<std::is_enum<PropertyEnumType>::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 ;) */ const_modifier inline const std::string_view& name(PropertyEnumType type) { /* defining the return type here to help out my IDE a bit ;) */
return describe<PropertyEnumType>(type).name; return describe<PropertyEnumType>(type).name;
@ -690,7 +702,6 @@ namespace ts {
struct PropertyBundle { struct PropertyBundle {
property::PropertyType type; property::PropertyType type;
size_t length; size_t length;
size_t offset;
PropertyData properties[0]; PropertyData properties[0];
}; };
#ifdef WIN32 #ifdef WIN32

View File

@ -129,6 +129,7 @@ DEFINE_VARIABLE_TRANSFORM_TYPE(type, ntype)
DEFINE_VARIABLE_TRANSFORM(class, VARTYPE_INT, std::to_string((size_type) in), static_cast<class>(in.as<size_type>())); DEFINE_VARIABLE_TRANSFORM(class, VARTYPE_INT, std::to_string((size_type) in), static_cast<class>(in.as<size_type>()));
DEFINE_VARIABLE_TRANSFORM(std::string, VARTYPE_TEXT, in, in.value()); 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(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()); DEFINE_VARIABLE_TRANSFORM(const char*, VARTYPE_TEXT, std::string((const char*) in), in.value().c_str());

View File

@ -145,6 +145,6 @@ void AcknowledgeManager::update_rto(size_t r) {
} else { } else {
this->rttvar = (1.f - alpha) * this->rttvar + beta * abs(this->srtt - r); this->rttvar = (1.f - alpha) * this->rttvar + beta * abs(this->srtt - r);
this->srtt = (1.f - alpha) * srtt + alpha * 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);
} }
} }

View File

@ -185,6 +185,13 @@ namespace ts {
this->put(key, std::string_view{data}); this->put(key, std::string_view{data});
} }
#ifdef PROPERTIES_DEFINED
template <typename PropertyType, typename T, std::enable_if_t<std::is_enum<PropertyType>::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 */ /* directly puts data without checking for duplicates */
inline void put_unchecked(const std::string_view& key, const std::string_view& value) { inline void put_unchecked(const std::string_view& key, const std::string_view& value) {
this->impl_put_unchecked(key, value); this->impl_put_unchecked(key, value);
@ -194,6 +201,13 @@ namespace ts {
this->put_unchecked(key, std::string_view{value}); this->put_unchecked(key, std::string_view{value});
} }
#ifdef PROPERTIES_DEFINED
template <typename PropertyType, typename T, std::enable_if_t<std::is_enum<PropertyType>::value, int> = 0>
inline void put_unchecked(PropertyType key, const T& value) {
this->put_unchecked(property::name(key), value);
}
#endif
template <typename T, std::enable_if_t<!(std::is_same<T, std::string_view>::value || std::is_same<T, std::string>::value), int> = 1> template <typename T, std::enable_if_t<!(std::is_same<T, std::string_view>::value || std::is_same<T, std::string>::value), int> = 1>
inline void put_unchecked(const std::string_view& key, const T& value) { inline void put_unchecked(const std::string_view& key, const T& value) {
static_assert(converter<T>::supported, "Target type isn't supported!"); static_assert(converter<T>::supported, "Target type isn't supported!");
@ -266,14 +280,14 @@ namespace ts {
return command_builder_bulk{this->flag_changed, this->bulks[index]}; return command_builder_bulk{this->flag_changed, this->bulks[index]};
} }
template <typename T> template <typename KeyT, typename ValueT>
inline void put(size_t index, const std::string_view& key, const T& value) { inline void put(size_t index, const KeyT& key, const ValueT& value) {
this->bulk(index).put(key, value); this->bulk(index).put(key, value);
} }
/* directly puts data without checking for duplicates */ /* directly puts data without checking for duplicates */
template <typename T> template <typename KeyT, typename ValueT>
inline void put_unchecked(size_t index, const std::string_view& key, const T& value) { inline void put_unchecked(size_t index, const KeyT& key, const ValueT& value) {
this->bulk(index).put_unchecked(key, value); this->bulk(index).put_unchecked(key, value);
} }