std::format seems like a great idea.
Used it in one place. Better than printf derived functionality. But they never bothered to think through supporting user types, and that is a complete mess that is grossly inconsistent or simply not working from one compiler to the next.
This commit is contained in:
parent
fc9f82b6e5
commit
883bd8ebe8
@ -46,7 +46,6 @@ MyException::MyException(const char* sz, int i, const char* func__, const char*
|
|||||||
// usage
|
// usage
|
||||||
// throw MyException("Expected wallet file not found", __LINE__, __func__, __FILE__);
|
// throw MyException("Expected wallet file not found", __LINE__, __func__, __FILE__);
|
||||||
err_number(i) {
|
err_number(i) {
|
||||||
char buff[20];
|
err = std::format(R"|({}
|
||||||
snprintf(buff, 20, "%d", i);
|
line {}, function {}, file {})|", sz, i, func__, FILE__);
|
||||||
err = std::string(sz) + "\nline " + buff + ", function " + func__ + ", file " + FILE__;
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ namespace ro {
|
|||||||
sql(std::unique_ptr<Icompiled_sql>&& p) :std::unique_ptr<Icompiled_sql>(p.release()) { }
|
sql(std::unique_ptr<Icompiled_sql>&& p) :std::unique_ptr<Icompiled_sql>(p.release()) { }
|
||||||
~sql() = default;
|
~sql() = default;
|
||||||
template <typename T>auto column(int i) const {
|
template <typename T>auto column(int i) const {
|
||||||
if constexpr (ro::is_blob_field_type<T>::value) {
|
if constexpr (ro::blob_type<T>) {
|
||||||
auto st = (*this)->Isqlite3_column_blob(i);
|
auto st = (*this)->Isqlite3_column_blob(i);
|
||||||
if (st.size_bytes() != sizeof(T)) throw BadDataException();
|
if (st.size_bytes() != sizeof(T)) throw BadDataException();
|
||||||
static_assert (std::is_standard_layout<T>(), "not standard layout");
|
static_assert (std::is_standard_layout<T>(), "not standard layout");
|
||||||
|
@ -57,7 +57,7 @@ namespace ro {
|
|||||||
bool is_alphanumeric_fixed_length(unsigned int, const char*);
|
bool is_alphanumeric_fixed_length(unsigned int, const char*);
|
||||||
|
|
||||||
template <class T> typename std::enable_if<
|
template <class T> typename std::enable_if<
|
||||||
ro::is_blob_field_type<T>::value,
|
ro::blob_type<T>,
|
||||||
decltype(T::type_indentifier, uint32_t())
|
decltype(T::type_indentifier, uint32_t())
|
||||||
>::type fasthash(const T& p_blob) {
|
>::type fasthash(const T& p_blob) {
|
||||||
static_assert(sizeof(T) % 8 == 0, "fasthash assumes a multiple of 8 bytes");
|
static_assert(sizeof(T) % 8 == 0, "fasthash assumes a multiple of 8 bytes");
|
||||||
@ -181,3 +181,4 @@ namespace ro {
|
|||||||
this->operator char* [this->length] = '\0';
|
this->operator char* [this->length] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,17 +138,16 @@ namespace ro {
|
|||||||
static constexpr bool value = is_blob_field_type::template test<T>();
|
static constexpr bool value = is_blob_field_type::template test<T>();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class T> concept blob_type = ro::is_blob_field_type<T>::value;
|
||||||
|
|
||||||
|
|
||||||
// At present our serial classes consist of std::span<uint8_t> and custom classes that publicly inherit from std::span<byte>
|
// At present our serial classes consist of std::span<uint8_t> and custom classes that publicly inherit from std::span<byte>
|
||||||
// To handle compound objects, add custom classes inheriting from std::span<byte>[n]
|
// To handle compound objects, add custom classes inheriting from std::span<byte>[n]
|
||||||
|
|
||||||
// template class that generates a std::span of bytes over the blob
|
// template class that generates a std::span of bytes over the blob
|
||||||
// field of any object containing a blob record, which is normally sufficient
|
// field of any object containing a blob record, which is normally sufficient
|
||||||
// for a machine independent representation of that object
|
// for a machine independent representation of that object
|
||||||
template <typename T>
|
template <blob_type T> std::span<const byte> serialize(const T& pt) {
|
||||||
std::enable_if_t<
|
|
||||||
is_blob_field_type<T>::value,
|
|
||||||
std::span<const byte>
|
|
||||||
> serialize(const T& pt) {
|
|
||||||
return serialize(pt.blob);
|
return serialize(pt.blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +566,7 @@ namespace ristretto255 {
|
|||||||
{
|
{
|
||||||
// We will be reading points from the database, as blobs,
|
// We will be reading points from the database, as blobs,
|
||||||
// reading them from the network as blobs,
|
// reading them from the network as blobs,
|
||||||
// and reading them from human entered text as base52 encoded blobs.
|
// and reading them from human entered text as base58 encoded blobs.
|
||||||
// Therefore, invalid point initialization data is all too possible.
|
// Therefore, invalid point initialization data is all too possible.
|
||||||
public:
|
public:
|
||||||
static constexpr unsigned int type_indentifier = 1;
|
static constexpr unsigned int type_indentifier = 1;
|
||||||
@ -770,6 +769,7 @@ namespace ristretto255 {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(ro::blob_type<scalar> && !ro::blob_type<int>);
|
||||||
static_assert(ro::is_blob_field_type<scalar>::value);
|
static_assert(ro::is_blob_field_type<scalar>::value);
|
||||||
static_assert(ro::is_blob_field_type<scalar&>::value);
|
static_assert(ro::is_blob_field_type<scalar&>::value);
|
||||||
static_assert(ro::is_blob_field_type<point>::value);
|
static_assert(ro::is_blob_field_type<point>::value);
|
||||||
|
Loading…
Reference in New Issue
Block a user