RIP tp::Strings

This commit is contained in:
IlyaShurupov 2024-03-22 14:44:26 +03:00 committed by Ilya Shurupov
parent fa2d0aaa92
commit 1756ca026d
90 changed files with 419 additions and 1475 deletions

Binary file not shown.

View file

@ -45,4 +45,5 @@ namespace tp {
ualni hash(halni bytes) { return hash(alni(bytes)); }
ualni hash(uhalni bytes) { return hash(alni(bytes)); }
ualni hash(ualni bytes) { return hash(alni(bytes)); }
ualni hash(const std::string& in) { return hash(in.c_str()); }
}

View file

@ -51,6 +51,8 @@ namespace tp {
// check if type has explicit write method. if not write as bytes
template <typename Type>
void operator<<(const Type& val) {
static_assert(!std::is_same<Type, std::string>::value);
static_assert(!tRead);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Write<Type>::value) {
@ -63,6 +65,8 @@ namespace tp {
// check if type has explicit read method. if not read as bytes
template <typename Type>
void operator>>(Type& val) {
static_assert(!std::is_same<Type, std::string>::value);
static_assert(tRead);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Read<Type>::value) {
@ -75,6 +79,8 @@ namespace tp {
// check if type has explicit archive method. if not read/write as bytes
template <typename Type>
void operator%(Type& val) {
static_assert(!std::is_same<Type, std::string>::value);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Archive<Type>::value) {
val.archive(*this);
@ -89,6 +95,8 @@ namespace tp {
template <typename Type>
void operator%(const Type& val) {
static_assert(!std::is_same<Type, std::string>::value);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Archive<Type>::value) {
((Type&) val).archive(*this);
@ -132,29 +140,4 @@ namespace tp {
ualni mAddress = 0;
ualni mFirstNotWritten = 0;
};
struct StringArchiver {
std::string* val;
StringArchiver(std::string& val) { this->val = &val; }
template <typename tArchiver>
void archiveRead(tArchiver& ar) {
ualni len;
ar >> len;
val->resize(len);
for (ualni i = 0; i < len; i++) {
ar >> (*val)[i];
}
}
template <typename tArchiver>
void archiveWrite(tArchiver& ar) const {
ualni len = val->size();
ar << len;
for (ualni i = 0; i < len; i++) {
ar << (*val)[i];
}
}
};
}

View file

@ -6,6 +6,7 @@
#include <initializer_list>
#include <typeinfo>
#include <utility>
#include <string>
namespace tp {
template <typename Type>
@ -49,6 +50,7 @@ namespace tp {
ualni hash(uhalni bytes);
ualni hash(ualni bytes);
ualni hash(alnf bytes);
ualni hash(const std::string& in);
template <typename T>
T clamp(T v, T l, T u) {