Commit 2d4a1731 by Maarten L. Hekkelman

Merge branch 'develop' into trunk

parents be1e3073 6fe5a04c
...@@ -141,6 +141,27 @@ set(CMAKE_THREAD_PREFER_PTHREAD) ...@@ -141,6 +141,27 @@ set(CMAKE_THREAD_PREFER_PTHREAD)
set(THREADS_PREFER_PTHREAD_FLAG) set(THREADS_PREFER_PTHREAD_FLAG)
find_package(Threads) find_package(Threads)
if(MSVC)
# Avoid linking the shared library of zlib
# Search ZLIB_ROOT first if it is set.
if(ZLIB_ROOT)
set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
endif()
# Normal search.
set(_ZLIB_x86 "(x86)")
set(_ZLIB_SEARCH_NORMAL
PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
"$ENV{ProgramFiles}/zlib"
"$ENV{ProgramFiles${_ZLIB_x86}}/zlib")
unset(_ZLIB_x86)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
foreach(search ${_ZLIB_SEARCHES})
find_library(ZLIB_LIBRARY NAMES zlibstatic NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()
endif()
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
include(FindFilesystem) include(FindFilesystem)
...@@ -234,6 +255,10 @@ if(BOOST_REGEX) ...@@ -234,6 +255,10 @@ if(BOOST_REGEX)
target_include_directories(cifpp PRIVATE regex/include) target_include_directories(cifpp PRIVATE regex/include)
endif() endif()
if(MSVC)
target_compile_definitions(cifpp PUBLIC NOMINMAX=1)
endif()
set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cifpp target_include_directories(cifpp
......
...@@ -458,7 +458,7 @@ class category ...@@ -458,7 +458,7 @@ class category
{ {
using namespace std::literals; using namespace std::literals;
size_t result = get_column_ix(column_name); uint16_t result = get_column_ix(column_name);
if (result == m_columns.size()) if (result == m_columns.size())
{ {
...@@ -507,7 +507,7 @@ class category ...@@ -507,7 +507,7 @@ class category
} }
private: private:
void update_value(row *row, size_t column, std::string_view value, bool updateLinked, bool validate = true); void update_value(row *row, uint16_t column, std::string_view value, bool updateLinked, bool validate = true);
private: private:
void erase_orphans(condition &&cond, category &parent); void erase_orphans(condition &&cond, category &parent);
...@@ -580,7 +580,7 @@ class category ...@@ -580,7 +580,7 @@ class category
// -------------------------------------------------------------------- // --------------------------------------------------------------------
void swap_item(size_t column_ix, row_handle &a, row_handle &b); void swap_item(uint16_t column_ix, row_handle &a, row_handle &b);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -53,15 +53,15 @@ namespace detail ...@@ -53,15 +53,15 @@ namespace detail
{ {
virtual ~condition_impl() {} virtual ~condition_impl() {}
virtual condition_impl *prepare(const category &c) { return this; } virtual condition_impl *prepare(const category &) { return this; }
virtual bool test(row_handle r) const = 0; virtual bool test(row_handle) const = 0;
virtual void str(std::ostream &os) const = 0; virtual void str(std::ostream &) const = 0;
virtual std::optional<row_handle> single() const { return {}; }; virtual std::optional<row_handle> single() const { return {}; };
}; };
struct all_condition_impl : public condition_impl struct all_condition_impl : public condition_impl
{ {
bool test(row_handle r) const override { return true; } bool test(row_handle) const override { return true; }
void str(std::ostream &os) const override { os << "*"; } void str(std::ostream &os) const override { os << "*"; }
}; };
...@@ -178,7 +178,7 @@ namespace detail ...@@ -178,7 +178,7 @@ namespace detail
} }
std::string m_item_tag; std::string m_item_tag;
size_t m_item_ix = 0; uint16_t m_item_ix = 0;
}; };
struct key_equals_condition_impl : public condition_impl struct key_equals_condition_impl : public condition_impl
...@@ -209,7 +209,7 @@ namespace detail ...@@ -209,7 +209,7 @@ namespace detail
} }
std::string m_item_tag; std::string m_item_tag;
size_t m_item_ix = 0; uint16_t m_item_ix = 0;
bool m_icase = false; bool m_icase = false;
std::string m_value; std::string m_value;
std::optional<row_handle> m_single_hit; std::optional<row_handle> m_single_hit;
...@@ -217,13 +217,12 @@ namespace detail ...@@ -217,13 +217,12 @@ namespace detail
struct key_equals_or_empty_condition_impl : public condition_impl struct key_equals_or_empty_condition_impl : public condition_impl
{ {
key_equals_or_empty_condition_impl(key_equals_condition_impl *equals, key_is_empty_condition_impl *empty) key_equals_or_empty_condition_impl(key_equals_condition_impl *equals)
: m_item_tag(equals->m_item_tag) : m_item_tag(equals->m_item_tag)
, m_value(equals->m_value) , m_value(equals->m_value)
, m_icase(equals->m_icase) , m_icase(equals->m_icase)
, m_single_hit(equals->m_single_hit) , m_single_hit(equals->m_single_hit)
{ {
assert(empty->m_item_ix == equals->m_item_ix);
} }
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
...@@ -254,7 +253,7 @@ namespace detail ...@@ -254,7 +253,7 @@ namespace detail
} }
std::string m_item_tag; std::string m_item_tag;
size_t m_item_ix = 0; uint16_t m_item_ix = 0;
std::string m_value; std::string m_value;
bool m_icase = false; bool m_icase = false;
std::optional<row_handle> m_single_hit; std::optional<row_handle> m_single_hit;
...@@ -288,7 +287,7 @@ namespace detail ...@@ -288,7 +287,7 @@ namespace detail
} }
std::string m_item_tag; std::string m_item_tag;
size_t m_item_ix = 0; uint16_t m_item_ix = 0;
bool m_icase = false; bool m_icase = false;
std::function<bool(row_handle, bool)> m_compare; std::function<bool(row_handle, bool)> m_compare;
std::string m_str; std::string m_str;
...@@ -321,7 +320,7 @@ namespace detail ...@@ -321,7 +320,7 @@ namespace detail
} }
std::string m_item_tag; std::string m_item_tag;
size_t m_item_ix; uint16_t m_item_ix;
std::regex mRx; std::regex mRx;
}; };
......
...@@ -53,21 +53,6 @@ namespace detail ...@@ -53,21 +53,6 @@ namespace detail
T m_value; T m_value;
}; };
// template <>
// struct to_varg<char>
// {
// using type = const char *;
// to_varg(const char &v)
// : m_value({ v })
// {
// }
// type operator*() { return m_value.c_str(); }
// std::string m_value;
// };
template <> template <>
struct to_varg<const char *> struct to_varg<const char *>
{ {
......
...@@ -41,6 +41,6 @@ class row; ...@@ -41,6 +41,6 @@ class row;
class row_handle; class row_handle;
class item; class item;
class item_handle; struct item_handle;
} // namespace cif } // namespace cif
\ No newline at end of file
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
/// whether to use a compressions/decompression algorithm is /// whether to use a compressions/decompression algorithm is
/// based on the extension of the \a filename argument. /// based on the extension of the \a filename argument.
// This is a stripped down version of the gzio library from // This is a stripped down version of the gxrio library from
// https://github.com/mhekkel/gzio.git // https://github.com/mhekkel/gxrio.git
// Most notably, the lzma support has been removed since getting // Most notably, the lzma support has been removed since getting
// that to work in Windows proved to be too much work. // that to work in Windows proved to be too much work.
......
...@@ -79,7 +79,7 @@ class iterator_impl ...@@ -79,7 +79,7 @@ class iterator_impl
} }
template <typename IRowType> template <typename IRowType>
iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<size_t, N> &cix) iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<uint16_t, N> &cix)
: m_category(rhs.m_category) : m_category(rhs.m_category)
, m_current(rhs.m_current) , m_current(rhs.m_current)
, m_column_ix(cix) , m_column_ix(cix)
...@@ -151,7 +151,7 @@ class iterator_impl ...@@ -151,7 +151,7 @@ class iterator_impl
} }
private: private:
template <std::size_t... Is> template <size_t... Is>
tuple_type get(std::index_sequence<Is...>) const tuple_type get(std::index_sequence<Is...>) const
{ {
if (m_current != nullptr) if (m_current != nullptr)
...@@ -166,7 +166,7 @@ class iterator_impl ...@@ -166,7 +166,7 @@ class iterator_impl
category_type *m_category = nullptr; category_type *m_category = nullptr;
row_type *m_current = nullptr; row_type *m_current = nullptr;
value_type m_value; value_type m_value;
std::array<size_t, N> m_column_ix; std::array<uint16_t, N> m_column_ix;
}; };
template<typename Category> template<typename Category>
...@@ -204,7 +204,7 @@ class iterator_impl<Category> ...@@ -204,7 +204,7 @@ class iterator_impl<Category>
} }
template <typename IRowType> template <typename IRowType>
iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<size_t, 0> &cix) iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<uint16_t, 0> &)
: m_category(rhs.m_category) : m_category(rhs.m_category)
, m_current(rhs.m_current) , m_current(rhs.m_current)
{ {
...@@ -317,7 +317,7 @@ class iterator_impl<Category, T> ...@@ -317,7 +317,7 @@ class iterator_impl<Category, T>
} }
template <typename IRowType> template <typename IRowType>
iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<size_t, 1> &cix) iterator_impl(const iterator_impl<IRowType> &rhs, const std::array<uint16_t, 1> &cix)
: m_category(rhs.m_category) : m_category(rhs.m_category)
, m_current(rhs.m_current) , m_current(rhs.m_current)
, m_column_ix(cix[0]) , m_column_ix(cix[0])
...@@ -403,7 +403,7 @@ class iterator_impl<Category, T> ...@@ -403,7 +403,7 @@ class iterator_impl<Category, T>
category_type *m_category = nullptr; category_type *m_category = nullptr;
row_type *m_current = nullptr; row_type *m_current = nullptr;
value_type m_value; value_type m_value;
size_t m_column_ix; uint16_t m_column_ix;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -455,7 +455,7 @@ class iterator_proxy ...@@ -455,7 +455,7 @@ class iterator_proxy
private: private:
category_type *m_category; category_type *m_category;
row_iterator m_begin, m_end; row_iterator m_begin, m_end;
std::array<size_t, N> m_column_ix; std::array<uint16_t, N> m_column_ix;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -483,7 +483,7 @@ class conditional_iterator_proxy ...@@ -483,7 +483,7 @@ class conditional_iterator_proxy
using pointer = value_type *; using pointer = value_type *;
using reference = value_type; using reference = value_type;
conditional_iterator_impl(CategoryType &cat, row_iterator pos, const condition &cond, const std::array<size_t, N> &cix); conditional_iterator_impl(CategoryType &cat, row_iterator pos, const condition &cond, const std::array<uint16_t, N> &cix);
conditional_iterator_impl(const conditional_iterator_impl &i) = default; conditional_iterator_impl(const conditional_iterator_impl &i) = default;
conditional_iterator_impl &operator=(const conditional_iterator_impl &i) = default; conditional_iterator_impl &operator=(const conditional_iterator_impl &i) = default;
...@@ -567,7 +567,7 @@ class conditional_iterator_proxy ...@@ -567,7 +567,7 @@ class conditional_iterator_proxy
CategoryType *m_cat; CategoryType *m_cat;
condition m_condition; condition m_condition;
row_iterator mCBegin, mCEnd; row_iterator mCBegin, mCEnd;
std::array<size_t, N> mCix; std::array<uint16_t, N> mCix;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -578,7 +578,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos, ...@@ -578,7 +578,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos,
, m_begin(pos) , m_begin(pos)
, m_end(cat.end()) , m_end(cat.end())
{ {
for (size_t i = 0; i < N; ++i) for (uint16_t i = 0; i < N; ++i)
m_column_ix[i] = m_category->get_column_ix(columns[i]); m_column_ix[i] = m_category->get_column_ix(columns[i]);
} }
...@@ -590,7 +590,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos, ...@@ -590,7 +590,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos,
{ {
// static_assert(columns.size() == N, "The list of column names should be exactly the same as the list of requested columns"); // static_assert(columns.size() == N, "The list of column names should be exactly the same as the list of requested columns");
std::size_t i = 0; std::uint16_t i = 0;
for (auto column : columns) for (auto column : columns)
m_column_ix[i++] = m_category->get_column_ix(column); m_column_ix[i++] = m_category->get_column_ix(column);
} }
...@@ -599,7 +599,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos, ...@@ -599,7 +599,7 @@ iterator_proxy<Category, Ts...>::iterator_proxy(Category &cat, row_iterator pos,
template <typename Category, typename... Ts> template <typename Category, typename... Ts>
conditional_iterator_proxy<Category, Ts...>::conditional_iterator_impl::conditional_iterator_impl( conditional_iterator_proxy<Category, Ts...>::conditional_iterator_impl::conditional_iterator_impl(
Category &cat, row_iterator pos, const condition &cond, const std::array<size_t, N> &cix) Category &cat, row_iterator pos, const condition &cond, const std::array<uint16_t, N> &cix)
: mCat(&cat) : mCat(&cat)
, mBegin(pos, cix) , mBegin(pos, cix)
, mEnd(cat.end(), cix) , mEnd(cat.end(), cix)
...@@ -634,7 +634,7 @@ conditional_iterator_proxy<Category, Ts...>::conditional_iterator_proxy(Category ...@@ -634,7 +634,7 @@ conditional_iterator_proxy<Category, Ts...>::conditional_iterator_proxy(Category
while (mCBegin != mCEnd and not m_condition(*mCBegin)) while (mCBegin != mCEnd and not m_condition(*mCBegin))
++mCBegin; ++mCBegin;
size_t i = 0; uint16_t i = 0;
((mCix[i++] = m_cat->get_column_ix(names)), ...); ((mCix[i++] = m_cat->get_column_ix(names)), ...);
} }
......
...@@ -40,13 +40,13 @@ namespace detail ...@@ -40,13 +40,13 @@ namespace detail
{ {
static constexpr size_t N = sizeof...(C); static constexpr size_t N = sizeof...(C);
get_row_result(const row_handle &r, std::array<size_t, N> &&columns) get_row_result(const row_handle &r, std::array<uint16_t, N> &&columns)
: m_row(r) : m_row(r)
, m_columns(std::move(columns)) , m_columns(std::move(columns))
{ {
} }
const item_handle operator[](size_t ix) const const item_handle operator[](uint16_t ix) const
{ {
return m_row[m_columns[ix]]; return m_row[m_columns[ix]];
} }
...@@ -57,14 +57,14 @@ namespace detail ...@@ -57,14 +57,14 @@ namespace detail
return get<Ts...>(std::index_sequence_for<Ts...>{}); return get<Ts...>(std::index_sequence_for<Ts...>{});
} }
template <typename... Ts, std::size_t... Is> template <typename... Ts, size_t... Is>
std::tuple<Ts...> get(std::index_sequence<Is...>) const std::tuple<Ts...> get(std::index_sequence<Is...>) const
{ {
return std::tuple<Ts...>{ m_row[m_columns[Is]].template as<Ts>()... }; return std::tuple<Ts...>{ m_row[m_columns[Is]].template as<Ts>()... };
} }
const row_handle &m_row; const row_handle &m_row;
std::array<size_t, N> m_columns; std::array<uint16_t, N> m_columns;
}; };
// we want to be able to tie some variables to a get_row_result, for this we use tiewraps // we want to be able to tie some variables to a get_row_result, for this we use tiewraps
...@@ -108,12 +108,12 @@ class row : public std::vector<item_value> ...@@ -108,12 +108,12 @@ class row : public std::vector<item_value>
public: public:
row() = default; row() = default;
item_value* get(size_t ix) item_value* get(uint16_t ix)
{ {
return ix < size() ? &at(ix) : nullptr; return ix < size() ? &at(ix) : nullptr;
} }
const item_value* get(size_t ix) const const item_value* get(uint16_t ix) const
{ {
return ix < size() ? &at(ix) : nullptr; return ix < size() ? &at(ix) : nullptr;
} }
...@@ -125,7 +125,7 @@ class row : public std::vector<item_value> ...@@ -125,7 +125,7 @@ class row : public std::vector<item_value>
template <typename, typename...> template <typename, typename...>
friend class iterator_impl; friend class iterator_impl;
void append(size_t ix, item_value &&iv) void append(uint16_t ix, item_value &&iv)
{ {
if (ix >= size()) if (ix >= size())
resize(ix + 1); resize(ix + 1);
...@@ -133,7 +133,7 @@ class row : public std::vector<item_value> ...@@ -133,7 +133,7 @@ class row : public std::vector<item_value>
at(ix) = std::move(iv); at(ix) = std::move(iv);
} }
void remove(size_t ix) void remove(uint16_t ix)
{ {
if (ix < size()) if (ix < size())
at(ix) = item_value{}; at(ix) = item_value{};
...@@ -148,7 +148,7 @@ class row : public std::vector<item_value> ...@@ -148,7 +148,7 @@ class row : public std::vector<item_value>
class row_handle class row_handle
{ {
public: public:
friend class item_handle; friend struct item_handle;
friend class category; friend class category;
friend class category_index; friend class category_index;
friend class row_initializer; friend class row_initializer;
...@@ -182,12 +182,12 @@ class row_handle ...@@ -182,12 +182,12 @@ class row_handle
return not empty(); return not empty();
} }
item_handle operator[](uint32_t column_ix) item_handle operator[](uint16_t column_ix)
{ {
return empty() ? item_handle::s_null_item : item_handle(column_ix, *this); return empty() ? item_handle::s_null_item : item_handle(column_ix, *this);
} }
const item_handle operator[](uint32_t column_ix) const const item_handle operator[](uint16_t column_ix) const
{ {
return empty() ? item_handle::s_null_item : item_handle(column_ix, const_cast<row_handle &>(*this)); return empty() ? item_handle::s_null_item : item_handle(column_ix, const_cast<row_handle &>(*this));
} }
...@@ -231,7 +231,7 @@ class row_handle ...@@ -231,7 +231,7 @@ class row_handle
assign(add_column(name), value, updateLinked, validate); assign(add_column(name), value, updateLinked, validate);
} }
void assign(size_t column, std::string_view value, bool updateLinked, bool validate = true); void assign(uint16_t column, std::string_view value, bool updateLinked, bool validate = true);
bool operator==(const row_handle &rhs) const { return m_category == rhs.m_category and m_row == rhs.m_row; } bool operator==(const row_handle &rhs) const { return m_category == rhs.m_category and m_row == rhs.m_row; }
bool operator!=(const row_handle &rhs) const { return m_category != rhs.m_category or m_row != rhs.m_row; } bool operator!=(const row_handle &rhs) const { return m_category != rhs.m_category or m_row != rhs.m_row; }
...@@ -257,7 +257,7 @@ class row_handle ...@@ -257,7 +257,7 @@ class row_handle
assign(i.name(), i.value(), updateLinked); assign(i.name(), i.value(), updateLinked);
} }
void swap(size_t column, row_handle &r); void swap(uint16_t column, row_handle &r);
category *m_category = nullptr; category *m_category = nullptr;
row *m_row = nullptr; row *m_row = nullptr;
......
...@@ -28,13 +28,76 @@ ...@@ -28,13 +28,76 @@
#include <charconv> #include <charconv>
#include <cmath> #include <cmath>
#include <limits>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <tuple> #include <tuple>
#include <vector> #include <vector>
#if __has_include(<experimental/type_traits>) #if __has_include(<experimental/type_traits>)
#include <experimental/type_traits> #include <experimental/type_traits>
#else
#include <type_traits>
#endif
#if (not defined(__cpp_lib_experimental_detect) or (__cpp_lib_experimental_detect < 201505)) and (not defined(_LIBCPP_VERSION) or _LIBCPP_VERSION < 5000)
// This code is copied from:
// https://ld2015.scusa.lsu.edu/cppreference/en/cpp/experimental/is_detected.html
namespace std
{
template< class... >
using void_t = void;
namespace experimental
{
namespace detail
{
template <class Default, class AlwaysVoid,
template<class...> class Op, class... Args>
struct detector
{
using value_t = false_type;
using type = Default;
};
template <class Default, template<class...> class Op, class... Args>
struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
// Note that std::void_t is a c++17 feature
using value_t = true_type;
using type = Op<Args...>;
};
} // namespace detail
struct nonesuch
{
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(nonesuch const&) = delete;
void operator=(nonesuch const&) = delete;
};
template <template<class...> class Op, class... Args>
using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
template <template<class...> class Op, class... Args>
constexpr inline bool is_detected_v = is_detected<Op,Args...>::value;
template <template<class...> class Op, class... Args>
using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type;
template <class Default, template<class...> class Op, class... Args>
using detected_or = detail::detector<Default, void, Op, Args...>;
template <class Expected, template <class...> class Op, class... Args>
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template <class Expected, template<class...> class Op, class... Args>
constexpr inline bool is_detected_exact_v = is_detected_exact<Expected, Op, Args...>::value;
}
}
#endif #endif
namespace cif namespace cif
...@@ -95,10 +158,10 @@ std::vector<StringType> split(std::string_view s, std::string_view separators, b ...@@ -95,10 +158,10 @@ std::vector<StringType> split(std::string_view s, std::string_view separators, b
{ {
std::vector<StringType> result; std::vector<StringType> result;
auto b = s.begin(); auto b = s.data();
auto e = b; auto e = b;
while (e != s.end()) while (e != s.data() + s.length())
{ {
if (separators.find(*e) != std::string_view::npos) if (separators.find(*e) != std::string_view::npos)
{ {
...@@ -346,8 +409,8 @@ enum class chars_format ...@@ -346,8 +409,8 @@ enum class chars_format
template <typename FloatType, std::enable_if_t<std::is_floating_point_v<FloatType>, int> = 0> template <typename FloatType, std::enable_if_t<std::is_floating_point_v<FloatType>, int> = 0>
std::to_chars_result to_chars(char *first, char *last, FloatType &value, chars_format fmt) std::to_chars_result to_chars(char *first, char *last, FloatType &value, chars_format fmt)
{ {
int size = last - first; int size = static_cast<int>(last - first);
int r; int r = 0;
switch (fmt) switch (fmt)
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
*/ */
#include <numeric> #include <numeric>
#include <stack>
#include <cif++/category.hpp> #include <cif++/category.hpp>
#include <cif++/datablock.hpp> #include <cif++/datablock.hpp>
...@@ -52,7 +53,7 @@ class row_comparator ...@@ -52,7 +53,7 @@ class row_comparator
for (auto k : cv->m_keys) for (auto k : cv->m_keys)
{ {
size_t ix = cat.add_column(k); uint16_t ix = cat.add_column(k);
auto iv = cv->get_validator_for_item(k); auto iv = cv->get_validator_for_item(k);
if (iv == nullptr) if (iv == nullptr)
...@@ -79,7 +80,7 @@ class row_comparator ...@@ -79,7 +80,7 @@ class row_comparator
int d = 0; int d = 0;
for (auto &c : m_comparator) for (auto &c : m_comparator)
{ {
size_t k; uint16_t k;
compareFunc f; compareFunc f;
std::tie(k, f) = c; std::tie(k, f) = c;
...@@ -105,7 +106,7 @@ class row_comparator ...@@ -105,7 +106,7 @@ class row_comparator
int d = 0, i = 0; int d = 0, i = 0;
for (auto &c : m_comparator) for (auto &c : m_comparator)
{ {
size_t k; uint16_t k;
compareFunc f; compareFunc f;
std::tie(k, f) = c; std::tie(k, f) = c;
...@@ -124,7 +125,7 @@ class row_comparator ...@@ -124,7 +125,7 @@ class row_comparator
private: private:
typedef std::function<int(std::string_view, std::string_view)> compareFunc; typedef std::function<int(std::string_view, std::string_view)> compareFunc;
typedef std::tuple<size_t, compareFunc> key_comparator; typedef std::tuple<uint16_t, compareFunc> key_comparator;
std::vector<key_comparator> m_comparator; std::vector<key_comparator> m_comparator;
category &m_category; category &m_category;
...@@ -878,7 +879,7 @@ bool category::is_valid() const ...@@ -878,7 +879,7 @@ bool category::is_valid() const
for (auto ri = m_head; ri != nullptr; ri = ri->m_next) for (auto ri = m_head; ri != nullptr; ri = ri->m_next)
{ {
for (size_t cix = 0; cix < m_columns.size(); ++cix) for (uint16_t cix = 0; cix < m_columns.size(); ++cix)
{ {
bool seen = false; bool seen = false;
auto iv = m_columns[cix].m_validator; auto iv = m_columns[cix].m_validator;
...@@ -1297,7 +1298,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator) ...@@ -1297,7 +1298,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
// calling size() often is a waste of resources // calling size() often is a waste of resources
if (m_last_unique_num == 0) if (m_last_unique_num == 0)
m_last_unique_num = size(); m_last_unique_num = static_cast<uint32_t>(size());
for (;;) for (;;)
{ {
...@@ -1439,7 +1440,7 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie ...@@ -1439,7 +1440,7 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
} }
} }
void category::update_value(row *row, size_t column, std::string_view value, bool updateLinked, bool validate) void category::update_value(row *row, uint16_t column, std::string_view value, bool updateLinked, bool validate)
{ {
// make sure we have an index, if possible // make sure we have an index, if possible
if (m_index == nullptr and m_cat_validator != nullptr) if (m_index == nullptr and m_cat_validator != nullptr)
...@@ -1573,7 +1574,7 @@ row *category::clone_row(const row &r) ...@@ -1573,7 +1574,7 @@ row *category::clone_row(const row &r)
try try
{ {
for (size_t ix = 0; ix < r.size(); ++ix) for (uint16_t ix = 0; ix < r.size(); ++ix)
{ {
auto &i = r[ix]; auto &i = r[ix];
if (not i) if (not i)
...@@ -1606,7 +1607,7 @@ row_handle category::create_copy(row_handle r) ...@@ -1606,7 +1607,7 @@ row_handle category::create_copy(row_handle r)
// copy the values // copy the values
std::vector<item> items; std::vector<item> items;
for (size_t ix = 0; ix < r.m_row->size(); ++ix) for (uint16_t ix = 0; ix < r.m_row->size(); ++ix)
{ {
auto i = r.m_row->get(ix); auto i = r.m_row->get(ix);
if (i != nullptr) if (i != nullptr)
...@@ -1712,7 +1713,7 @@ category::iterator category::insert_impl(const_iterator pos, row *n) ...@@ -1712,7 +1713,7 @@ category::iterator category::insert_impl(const_iterator pos, row *n)
// #endif // #endif
} }
void category::swap_item(size_t column_ix, row_handle &a, row_handle &b) void category::swap_item(uint16_t column_ix, row_handle &a, row_handle &b)
{ {
assert(this == a.m_category); assert(this == a.m_category);
assert(this == b.m_category); assert(this == b.m_category);
...@@ -1851,7 +1852,7 @@ std::vector<std::string> category::get_tag_order() const ...@@ -1851,7 +1852,7 @@ std::vector<std::string> category::get_tag_order() const
void category::write(std::ostream &os) const void category::write(std::ostream &os) const
{ {
std::vector<uint16_t> order(m_columns.size()); std::vector<uint16_t> order(m_columns.size());
iota(order.begin(), order.end(), 0); iota(order.begin(), order.end(), static_cast<uint16_t>(0));
write(os, order, false); write(os, order, false);
} }
...@@ -1869,7 +1870,7 @@ void category::write(std::ostream &os, const std::vector<std::string> &columns, ...@@ -1869,7 +1870,7 @@ void category::write(std::ostream &os, const std::vector<std::string> &columns,
if (addMissingColumns) if (addMissingColumns)
{ {
for (size_t i = 0; i < m_columns.size(); ++i) for (uint16_t i = 0; i < m_columns.size(); ++i)
{ {
if (std::find(order.begin(), order.end(), i) == order.end()) if (std::find(order.begin(), order.end(), i) == order.end())
order.push_back(i); order.push_back(i);
...@@ -1905,7 +1906,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool ...@@ -1905,7 +1906,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
for (auto r = m_head; r != nullptr; r = r->m_next) for (auto r = m_head; r != nullptr; r = r->m_next)
{ {
for (size_t ix = 0; ix < r->size(); ++ix) for (uint16_t ix = 0; ix < r->size(); ++ix)
{ {
auto v = r->get(ix); auto v = r->get(ix);
if (v == nullptr) if (v == nullptr)
...@@ -1931,7 +1932,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool ...@@ -1931,7 +1932,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
{ {
size_t offset = 0; size_t offset = 0;
for (size_t cix : order) for (uint16_t cix : order)
{ {
size_t w = columnWidths[cix]; size_t w = columnWidths[cix];
...@@ -1983,7 +1984,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool ...@@ -1983,7 +1984,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
l += 3; l += 3;
for (size_t cix : order) for (uint16_t cix : order)
{ {
auto &col = m_columns[cix]; auto &col = m_columns[cix];
......
...@@ -115,9 +115,9 @@ namespace detail ...@@ -115,9 +115,9 @@ namespace detail
empty = dynamic_cast<key_is_empty_condition_impl*>(mA); empty = dynamic_cast<key_is_empty_condition_impl*>(mA);
} }
if (equals != nullptr and empty != nullptr) if (equals != nullptr and empty != nullptr and equals->m_item_tag == empty->m_item_tag)
{ {
result = new detail::key_equals_or_empty_condition_impl(equals, empty); result = new detail::key_equals_or_empty_condition_impl(equals);
result = result->prepare(c); result = result->prepare(c);
delete this; delete this;
} }
......
...@@ -38,7 +38,7 @@ void datablock::set_validator(const validator *v) ...@@ -38,7 +38,7 @@ void datablock::set_validator(const validator *v)
for (auto &cat : *this) for (auto &cat : *this)
cat.set_validator(v, *this); cat.set_validator(v, *this);
} }
catch(const std::exception& e) catch (const std::exception &)
{ {
throw_with_nested(std::runtime_error("Error while setting validator in datablock " + m_name)); throw_with_nested(std::runtime_error("Error while setting validator in datablock " + m_name));
} }
......
...@@ -34,12 +34,6 @@ namespace cif ...@@ -34,12 +34,6 @@ namespace cif
using namespace literals; using namespace literals;
inline void replace_all(std::string &s, std::string_view pat, std::string_view rep)
{
for (std::string::size_type i = s.find(pat); i != std::string::npos; i = s.find(pat, i))
s.replace(i, pat.size(), rep.data(), rep.size());
}
class dictionary_parser : public parser class dictionary_parser : public parser
{ {
public: public:
......
...@@ -190,7 +190,7 @@ void file::load(const std::filesystem::path &p) ...@@ -190,7 +190,7 @@ void file::load(const std::filesystem::path &p)
load(in); load(in);
} }
catch (const std::exception &ex) catch (const std::exception &)
{ {
throw_with_nested(std::runtime_error("Error reading file " + p.string())); throw_with_nested(std::runtime_error("Error reading file " + p.string()));
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <numeric> #include <numeric>
#include <stack>
namespace fs = std::filesystem; namespace fs = std::filesystem;
...@@ -49,13 +50,13 @@ void atom::atom_impl::moveTo(const point &p) ...@@ -49,13 +50,13 @@ void atom::atom_impl::moveTo(const point &p)
auto r = row(); auto r = row();
#if __cpp_lib_format #if __cpp_lib_format
r.assign("Cartn_x", std::format("{:.3f}", p.getX()), false, false); r.assign("Cartn_x", std::format("{:.3f}", p.m_x), false, false);
r.assign("Cartn_y", std::format("{:.3f}", p.getY()), false, false); r.assign("Cartn_y", std::format("{:.3f}", p.m_y), false, false);
r.assign("Cartn_z", std::format("{:.3f}", p.getZ()), false, false); r.assign("Cartn_z", std::format("{:.3f}", p.m_z), false, false);
#else #else
r.assign("Cartn_x", format("%.3f", p.m_x).str(), false, false); r.assign("Cartn_x", cif::format("%.3f", p.m_x).str(), false, false);
r.assign("Cartn_y", format("%.3f", p.m_y).str(), false, false); r.assign("Cartn_y", cif::format("%.3f", p.m_y).str(), false, false);
r.assign("Cartn_z", format("%.3f", p.m_z).str(), false, false); r.assign("Cartn_z", cif::format("%.3f", p.m_z).str(), false, false);
#endif #endif
m_location = p; m_location = p;
} }
...@@ -1410,7 +1411,7 @@ atom structure::get_atom_by_id(const std::string &id) const ...@@ -1410,7 +1411,7 @@ atom structure::get_atom_by_id(const std::string &id) const
{ {
assert(m_atoms.size() == m_atom_index.size()); assert(m_atoms.size() == m_atom_index.size());
int L = 0, R = m_atoms.size() - 1; int L = 0, R = static_cast<int>(m_atoms.size() - 1);
while (L <= R) while (L <= R)
{ {
int i = (L + R) / 2; int i = (L + R) / 2;
...@@ -1669,7 +1670,7 @@ std::string structure::insert_compound(const std::string &compoundID, bool is_en ...@@ -1669,7 +1670,7 @@ std::string structure::insert_compound(const std::string &compoundID, bool is_en
atom &structure::emplace_atom(atom &&atom) atom &structure::emplace_atom(atom &&atom)
{ {
int L = 0, R = m_atom_index.size() - 1; int L = 0, R = static_cast<int>(m_atom_index.size() - 1);
while (L <= R) while (L <= R)
{ {
int i = (L + R) / 2; int i = (L + R) / 2;
...@@ -1728,7 +1729,7 @@ void structure::remove_atom(atom &a, bool removeFromResidue) ...@@ -1728,7 +1729,7 @@ void structure::remove_atom(atom &a, bool removeFromResidue)
bool removed = false; bool removed = false;
#endif #endif
int L = 0, R = m_atom_index.size() - 1; int L = 0, R = static_cast<int>(m_atom_index.size() - 1);
while (L <= R) while (L <= R)
{ {
int i = (L + R) / 2; int i = (L + R) / 2;
...@@ -1974,10 +1975,10 @@ void structure::remove_sugar(sugar &s) ...@@ -1974,10 +1975,10 @@ void structure::remove_sugar(sugar &s)
dix.insert(tix); dix.insert(tix);
for (auto &s : branch) for (auto &s2 : branch)
{ {
if (s.get_link_nr() == tix) if (s2.get_link_nr() == tix)
test.push(s.num()); test.push(s2.num());
} }
for (auto atom : branch[tix - 1].atoms()) for (auto atom : branch[tix - 1].atoms())
...@@ -2101,7 +2102,7 @@ std::string structure::create_non_poly(const std::string &entity_id, const std:: ...@@ -2101,7 +2102,7 @@ std::string structure::create_non_poly(const std::string &entity_id, const std::
} }
auto &pdbx_nonpoly_scheme = m_db["pdbx_nonpoly_scheme"]; auto &pdbx_nonpoly_scheme = m_db["pdbx_nonpoly_scheme"];
int ndb_nr = pdbx_nonpoly_scheme.find("asym_id"_key == asym_id and "entity_id"_key == entity_id).size() + 1; size_t ndb_nr = pdbx_nonpoly_scheme.find("asym_id"_key == asym_id and "entity_id"_key == entity_id).size() + 1;
pdbx_nonpoly_scheme.emplace({ pdbx_nonpoly_scheme.emplace({
{"asym_id", asym_id}, {"asym_id", asym_id},
{"entity_id", entity_id}, {"entity_id", entity_id},
...@@ -2163,7 +2164,7 @@ std::string structure::create_non_poly(const std::string &entity_id, std::vector ...@@ -2163,7 +2164,7 @@ std::string structure::create_non_poly(const std::string &entity_id, std::vector
} }
auto &pdbx_nonpoly_scheme = m_db["pdbx_nonpoly_scheme"]; auto &pdbx_nonpoly_scheme = m_db["pdbx_nonpoly_scheme"];
int ndb_nr = pdbx_nonpoly_scheme.find("asym_id"_key == asym_id and "entity_id"_key == entity_id).size() + 1; size_t ndb_nr = pdbx_nonpoly_scheme.find("asym_id"_key == asym_id and "entity_id"_key == entity_id).size() + 1;
pdbx_nonpoly_scheme.emplace({ pdbx_nonpoly_scheme.emplace({
{"asym_id", asym_id}, {"asym_id", asym_id},
{"entity_id", entity_id}, {"entity_id", entity_id},
...@@ -2296,7 +2297,7 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini ...@@ -2296,7 +2297,7 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini
branch &branch = *bi; branch &branch = *bi;
int sugarNum = branch.size() + 1; int sugarNum = static_cast<int>(branch.size() + 1);
auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum); auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum);
...@@ -2331,31 +2332,31 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini ...@@ -2331,31 +2332,31 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini
auto r = struct_asym.find1("id"_key == asym_id); auto r = struct_asym.find1("id"_key == asym_id);
r["entity_id"] = entity_id; r["entity_id"] = entity_id;
for (auto &sugar : branch) for (auto &s2 : branch)
{ {
for (auto atom : sugar.atoms()) for (auto atom : s2.atoms())
atom.set_property("label_entity_id", entity_id); atom.set_property("label_entity_id", entity_id);
} }
auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"]; auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
pdbx_branch_scheme.erase("asym_id"_key == asym_id); pdbx_branch_scheme.erase("asym_id"_key == asym_id);
for (auto &sugar : branch) for (auto &s2 : branch)
{ {
pdbx_branch_scheme.emplace({ pdbx_branch_scheme.emplace({
{"asym_id", asym_id}, {"asym_id", asym_id},
{"entity_id", entity_id}, {"entity_id", entity_id},
{"num", sugar.num()}, {"num", s2.num()},
{"mon_id", sugar.get_compound_id()}, {"mon_id", s2.get_compound_id()},
{"pdb_asym_id", asym_id}, {"pdb_asym_id", asym_id},
{"pdb_seq_num", sugar.num()}, {"pdb_seq_num", s2.num()},
{"pdb_mon_id", sugar.get_compound_id()}, {"pdb_mon_id", s2.get_compound_id()},
// TODO: need fix, collect from nag_atoms? // TODO: need fix, collect from nag_atoms?
{"auth_asym_id", asym_id}, {"auth_asym_id", asym_id},
{"auth_mon_id", sugar.get_compound_id()}, {"auth_mon_id", s2.get_compound_id()},
{"auth_seq_num", sugar.get_auth_seq_id()}, {"auth_seq_num", s2.get_auth_seq_id()},
{"hetero", "n"} {"hetero", "n"}
}); });
......
...@@ -918,7 +918,7 @@ class PDBFileParser ...@@ -918,7 +918,7 @@ class PDBFileParser
if (year < 1950) if (year < 1950)
year += 100; year += 100;
s = format("%04d-%02d", year, month).str(); s = cif::format("%04d-%02d", year, month).str();
} }
else else
ec = error::make_error_code(error::pdbErrors::invalidDate); ec = error::make_error_code(error::pdbErrors::invalidDate);
...@@ -3266,18 +3266,18 @@ void PDBFileParser::ParseRemark350() ...@@ -3266,18 +3266,18 @@ void PDBFileParser::ParseRemark350()
{ "type", type }, { "type", type },
// { "name", "" }, // { "name", "" },
// { "symmetryOperation", "" }, // { "symmetryOperation", "" },
{ "matrix[1][1]", format("%12.10f", mat[0]).str() }, { "matrix[1][1]", cif::format("%12.10f", mat[0]).str() },
{ "matrix[1][2]", format("%12.10f", mat[1]).str() }, { "matrix[1][2]", cif::format("%12.10f", mat[1]).str() },
{ "matrix[1][3]", format("%12.10f", mat[2]).str() }, { "matrix[1][3]", cif::format("%12.10f", mat[2]).str() },
{ "vector[1]", format("%12.10f", vec[0]).str() }, { "vector[1]", cif::format("%12.10f", vec[0]).str() },
{ "matrix[2][1]", format("%12.10f", mat[3]).str() }, { "matrix[2][1]", cif::format("%12.10f", mat[3]).str() },
{ "matrix[2][2]", format("%12.10f", mat[4]).str() }, { "matrix[2][2]", cif::format("%12.10f", mat[4]).str() },
{ "matrix[2][3]", format("%12.10f", mat[5]).str() }, { "matrix[2][3]", cif::format("%12.10f", mat[5]).str() },
{ "vector[2]", format("%12.10f", vec[1]).str() }, { "vector[2]", cif::format("%12.10f", vec[1]).str() },
{ "matrix[3][1]", format("%12.10f", mat[6]).str() }, { "matrix[3][1]", cif::format("%12.10f", mat[6]).str() },
{ "matrix[3][2]", format("%12.10f", mat[7]).str() }, { "matrix[3][2]", cif::format("%12.10f", mat[7]).str() },
{ "matrix[3][3]", format("%12.10f", mat[8]).str() }, { "matrix[3][3]", cif::format("%12.10f", mat[8]).str() },
{ "vector[3]", format("%12.10f", vec[2]).str() } }); { "vector[3]", cif::format("%12.10f", vec[2]).str() } });
} }
catch (duplicate_key_error &ex) catch (duplicate_key_error &ex)
{ {
...@@ -5666,7 +5666,7 @@ void PDBFileParser::ParseCoordinate(int modelNr) ...@@ -5666,7 +5666,7 @@ void PDBFileParser::ParseCoordinate(int modelNr)
throw std::runtime_error("ANISOU record should follow corresponding ATOM record"); throw std::runtime_error("ANISOU record should follow corresponding ATOM record");
auto f = [](float f) -> std::string auto f = [](float f) -> std::string
{ return format("%6.4f", f).str(); }; { return cif::format("%6.4f", f).str(); };
getCategory("atom_site_anisotrop")->emplace({ getCategory("atom_site_anisotrop")->emplace({
{ "id", mAtomID }, { "id", mAtomID },
...@@ -6202,7 +6202,7 @@ file read(std::istream &is) ...@@ -6202,7 +6202,7 @@ file read(std::istream &is)
auto *buffer = is.rdbuf(); auto *buffer = is.rdbuf();
if (buffer) if (buffer)
{ {
char ch = buffer->sgetc(); char ch = std::char_traits<char>::to_char_type(buffer->sgetc());
// All PDB files should always start with a HEADER line // All PDB files should always start with a HEADER line
// and so the very first character in a valid PDB file // and so the very first character in a valid PDB file
......
...@@ -66,7 +66,7 @@ struct tls_residue ...@@ -66,7 +66,7 @@ struct tls_residue
} }
}; };
void dump_selection(const std::vector<tls_residue> &selected, int indentLevel) void dump_selection(const std::vector<tls_residue> &selected, size_t indentLevel)
{ {
std::string indent(indentLevel * 2, ' '); std::string indent(indentLevel * 2, ' ');
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
namespace cif namespace cif
{ {
void row_handle::assign(size_t column, std::string_view value, bool updateLinked, bool validate) void row_handle::assign(uint16_t column, std::string_view value, bool updateLinked, bool validate)
{ {
if (not m_category) if (not m_category)
throw std::runtime_error("uninitialized row"); throw std::runtime_error("uninitialized row");
...@@ -61,7 +61,7 @@ uint16_t row_handle::add_column(std::string_view name) ...@@ -61,7 +61,7 @@ uint16_t row_handle::add_column(std::string_view name)
return m_category->add_column(name); return m_category->add_column(name);
} }
void row_handle::swap(size_t column, row_handle &b) void row_handle::swap(uint16_t column, row_handle &b)
{ {
if (not m_category) if (not m_category)
throw std::runtime_error("uninitialized row"); throw std::runtime_error("uninitialized row");
...@@ -81,7 +81,7 @@ row_initializer::row_initializer(row_handle rh) ...@@ -81,7 +81,7 @@ row_initializer::row_initializer(row_handle rh)
row *r = rh.get_row(); row *r = rh.get_row();
auto &cat = *rh.m_category; auto &cat = *rh.m_category;
for (size_t ix = 0; ix < r->size(); ++ix) for (uint16_t ix = 0; ix < r->size(); ++ix)
{ {
auto &i = r->operator[](ix); auto &i = r->operator[](ix);
if (not i) if (not i)
......
...@@ -128,7 +128,7 @@ std::string to_lower_copy(std::string_view s) ...@@ -128,7 +128,7 @@ std::string to_lower_copy(std::string_view s)
void to_upper(std::string &s) void to_upper(std::string &s)
{ {
for (auto &c : s) for (auto &c : s)
c = toupper(c); c = static_cast<char>(toupper(c));
} }
void replace_all(std::string &s, std::string_view what, std::string_view with) void replace_all(std::string &s, std::string_view what, std::string_view with)
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <deque>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip> #include <iomanip>
......
...@@ -137,8 +137,8 @@ int type_validator::compare(std::string_view a, std::string_view b) const ...@@ -137,8 +137,8 @@ int type_validator::compare(std::string_view a, std::string_view b) const
std::from_chars_result ra, rb; std::from_chars_result ra, rb;
ra = selected_charconv<double>::from_chars(a.begin(), a.end(), da); ra = selected_charconv<double>::from_chars(a.data(), a.data() + a.length(), da);
rb = selected_charconv<double>::from_chars(b.begin(), b.end(), db); rb = selected_charconv<double>::from_chars(b.data(), b.data() + b.length(), db);
if (ra.ec == std::errc() and rb.ec == std::errc()) if (ra.ec == std::errc() and rb.ec == std::errc())
{ {
......
...@@ -77,9 +77,9 @@ BOOST_AUTO_TEST_CASE(fmt_1) ...@@ -77,9 +77,9 @@ BOOST_AUTO_TEST_CASE(fmt_1)
std::ostringstream os; std::ostringstream os;
std::string world("world"); std::string world("world");
os << cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, M_PI); os << cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, cif::kPI);
BOOST_CHECK_EQUAL(os.str(), "Hello, world , the magic number is 42 and pi is 3.14159"); BOOST_CHECK_EQUAL(os.str(), "Hello, world , the magic number is 42 and pi is 3.14159");
BOOST_CHECK_EQUAL(cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, M_PI).str(), BOOST_CHECK_EQUAL(cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, cif::kPI).str(),
"Hello, world , the magic number is 42 and pi is 3.14159"); "Hello, world , the magic number is 42 and pi is 3.14159");
} }
\ No newline at end of file
...@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(cc_1) ...@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(cc_1)
for (const auto &[txt, val, ch] : tests) for (const auto &[txt, val, ch] : tests)
{ {
float tv; float tv;
const auto &[ptr, ec] = cif::from_chars(txt.begin(), txt.end(), tv); const auto &[ptr, ec] = cif::from_chars(txt.data(), txt.data() + txt.length(), tv);
BOOST_CHECK(ec == std::errc()); BOOST_CHECK(ec == std::errc());
BOOST_CHECK_EQUAL(tv, val); BOOST_CHECK_EQUAL(tv, val);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment