Commit 9bc33818 by Maarten L. Hekkelman

First steps to compile libcifpp 5 in Windows

parent f3a492fd
......@@ -234,6 +234,10 @@ if(BOOST_REGEX)
target_include_directories(cifpp PRIVATE regex/include)
endif()
if(MSVC)
target_compile_definitions(cifpp PUBLIC NOMINMAX=1)
endif()
set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cifpp
......
......@@ -458,7 +458,7 @@ class category
{
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())
{
......@@ -507,7 +507,7 @@ class category
}
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:
void erase_orphans(condition &&cond, category &parent);
......@@ -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
{
virtual ~condition_impl() {}
virtual condition_impl *prepare(const category &c) { return this; }
virtual bool test(row_handle r) const = 0;
virtual void str(std::ostream &os) const = 0;
virtual condition_impl *prepare(const category &) { return this; }
virtual bool test(row_handle) const = 0;
virtual void str(std::ostream &) const = 0;
virtual std::optional<row_handle> single() const { return {}; };
};
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 << "*"; }
};
......@@ -178,7 +178,7 @@ namespace detail
}
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
......@@ -209,7 +209,7 @@ namespace detail
}
std::string m_item_tag;
size_t m_item_ix = 0;
uint16_t m_item_ix = 0;
bool m_icase = false;
std::string m_value;
std::optional<row_handle> m_single_hit;
......@@ -217,13 +217,12 @@ namespace detail
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_value(equals->m_value)
, m_icase(equals->m_icase)
, m_single_hit(equals->m_single_hit)
{
assert(empty->m_item_ix == equals->m_item_ix);
}
condition_impl *prepare(const category &c) override
......@@ -254,7 +253,7 @@ namespace detail
}
std::string m_item_tag;
size_t m_item_ix = 0;
uint16_t m_item_ix = 0;
std::string m_value;
bool m_icase = false;
std::optional<row_handle> m_single_hit;
......@@ -288,7 +287,7 @@ namespace detail
}
std::string m_item_tag;
size_t m_item_ix = 0;
uint16_t m_item_ix = 0;
bool m_icase = false;
std::function<bool(row_handle, bool)> m_compare;
std::string m_str;
......@@ -321,7 +320,7 @@ namespace detail
}
std::string m_item_tag;
size_t m_item_ix;
uint16_t m_item_ix;
std::regex mRx;
};
......
......@@ -53,21 +53,6 @@ namespace detail
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 <>
struct to_varg<const char *>
{
......
......@@ -41,6 +41,6 @@ class row;
class row_handle;
class item;
class item_handle;
struct item_handle;
} // namespace cif
\ No newline at end of file
......@@ -129,7 +129,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_gzheader, rhs.m_gzheader);
auto p = std::copy(rhs.gptr(), rhs.egptr(), m_out_buffer.begin());
this->setg(m_out_buffer.begin(), m_out_buffer.begin(), p);
this->setg(m_out_buffer.data(), m_out_buffer.data() + m_out_buffer.size(), p);
if (m_zstream and m_zstream->avail_in > 0)
{
......@@ -137,7 +137,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::copy(rhs.m_in_buffer.begin() + next_in_offset,
rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in,
m_in_buffer.begin());
m_zstream->next_in = m_in_buffer.begin();
m_zstream->next_in = m_in_buffer.data();
}
}
......@@ -152,7 +152,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_gzheader, rhs.m_gzheader);
auto p = std::copy(rhs.gptr(), rhs.egptr(), m_out_buffer.begin());
this->setg(m_out_buffer.begin(), m_out_buffer.begin(), p);
this->setg(m_out_buffer.data(), m_out_buffer.data() + m_out_buffer.size(), p);
if (m_zstream and m_zstream->avail_in > 0)
{
......@@ -160,7 +160,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::copy(rhs.m_in_buffer.begin() + next_in_offset,
rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in,
m_in_buffer.begin());
m_zstream->next_in = reinterpret_cast<unsigned char *>(m_in_buffer.begin());
m_zstream->next_in = reinterpret_cast<unsigned char *>(m_in_buffer.data());
}
return *this;
......@@ -212,7 +212,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
if (err == Z_OK)
{
zstream.next_in = reinterpret_cast<unsigned char *>(m_in_buffer.data());
zstream.avail_in = this->m_upstream->sgetn(m_in_buffer.data(), m_in_buffer.size());
zstream.avail_in = static_cast<uInt>(this->m_upstream->sgetn(m_in_buffer.data(), m_in_buffer.size()));
err = ::inflateGetHeader(&zstream, &header);
......@@ -238,12 +238,12 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
while (this->gptr() == this->egptr())
{
zstream.next_out = reinterpret_cast<unsigned char *>(m_out_buffer.data());
zstream.avail_out = kBufferByteSize;
zstream.avail_out = static_cast<uInt>(kBufferByteSize);
if (zstream.avail_in == 0)
{
zstream.next_in = reinterpret_cast<unsigned char *>(m_in_buffer.data());
zstream.avail_in = this->m_upstream->sgetn(m_in_buffer.data(), m_in_buffer.size());
zstream.avail_in = static_cast<uInt>(this->m_upstream->sgetn(m_in_buffer.data(), m_in_buffer.size()));
}
int err = ::inflate(&zstream, Z_SYNC_FLUSH);
......@@ -252,9 +252,9 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
if (err == Z_STREAM_END or (err == Z_OK and n > 0))
{
this->setg(
m_out_buffer.begin(),
m_out_buffer.begin(),
m_out_buffer.begin() + n);
m_out_buffer.data(),
m_out_buffer.data(),
m_out_buffer.data() + n);
break;
}
......@@ -319,7 +319,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_zstream, rhs.m_zstream);
std::swap(m_gzheader, rhs.m_gzheader);
this->setp(m_in_buffer.begin(), m_in_buffer.end());
this->setp(m_in_buffer.data(), m_in_buffer.data() + m_in_buffer.size());
this->sputn(rhs.pbase(), rhs.pptr() - rhs.pbase());
rhs.setp(nullptr, nullptr);
}
......@@ -334,7 +334,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_zstream, rhs.m_zstream);
std::swap(m_gzheader, rhs.m_gzheader);
this->setp(m_in_buffer.begin(), m_in_buffer.end());
this->setp(m_in_buffer.data(), m_in_buffer.data() + m_in_buffer.size());
this->sputn(rhs.pbase(), rhs.pptr() - rhs.pbase());
rhs.setp(nullptr, nullptr);
......@@ -393,7 +393,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
err = ::deflateSetHeader(&zstream, &header);
if (err == Z_OK)
this->setp(this->m_in_buffer.begin(), this->m_in_buffer.end());
this->setp(this->m_in_buffer.data(), this->m_in_buffer.data() + this->m_in_buffer.size());
else
zstream = z_stream_s{};
......@@ -413,7 +413,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
auto &zstream = *m_zstream;
zstream.next_in = reinterpret_cast<unsigned char *>(this->pbase());
zstream.avail_in = this->pptr() - this->pbase();
zstream.avail_in = static_cast<uInt>(this->pptr() - this->pbase());
char_type buffer[BufferSize];
......@@ -442,7 +442,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
break;
}
this->setp(this->m_in_buffer.begin(), this->m_in_buffer.end());
this->setp(this->m_in_buffer.data(), this->m_in_buffer.data() + this->m_in_buffer.size());
if (not traits_type::eq_int_type(ch, traits_type::eof()))
{
......
......@@ -79,7 +79,7 @@ class iterator_impl
}
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_current(rhs.m_current)
, m_column_ix(cix)
......@@ -151,7 +151,7 @@ class iterator_impl
}
private:
template <std::size_t... Is>
template <uint16_t... Is>
tuple_type get(std::index_sequence<Is...>) const
{
if (m_current != nullptr)
......@@ -166,7 +166,7 @@ class iterator_impl
category_type *m_category = nullptr;
row_type *m_current = nullptr;
value_type m_value;
std::array<size_t, N> m_column_ix;
std::array<uint16_t, N> m_column_ix;
};
template<typename Category>
......@@ -204,7 +204,7 @@ class iterator_impl<Category>
}
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_current(rhs.m_current)
{
......@@ -317,7 +317,7 @@ class iterator_impl<Category, T>
}
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_current(rhs.m_current)
, m_column_ix(cix[0])
......@@ -403,7 +403,7 @@ class iterator_impl<Category, T>
category_type *m_category = nullptr;
row_type *m_current = nullptr;
value_type m_value;
size_t m_column_ix;
uint16_t m_column_ix;
};
// --------------------------------------------------------------------
......@@ -455,7 +455,7 @@ class iterator_proxy
private:
category_type *m_category;
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
using pointer = 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 &operator=(const conditional_iterator_impl &i) = default;
......@@ -567,7 +567,7 @@ class conditional_iterator_proxy
CategoryType *m_cat;
condition m_condition;
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,
, m_begin(pos)
, 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]);
}
......@@ -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");
std::size_t i = 0;
std::uint16_t i = 0;
for (auto column : columns)
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,
template <typename Category, typename... Ts>
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)
, mBegin(pos, cix)
, mEnd(cat.end(), cix)
......@@ -634,7 +634,7 @@ conditional_iterator_proxy<Category, Ts...>::conditional_iterator_proxy(Category
while (mCBegin != mCEnd and not m_condition(*mCBegin))
++mCBegin;
size_t i = 0;
uint16_t i = 0;
((mCix[i++] = m_cat->get_column_ix(names)), ...);
}
......
......@@ -40,13 +40,13 @@ namespace detail
{
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_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]];
}
......@@ -57,14 +57,14 @@ namespace detail
return get<Ts...>(std::index_sequence_for<Ts...>{});
}
template <typename... Ts, std::size_t... Is>
template <typename... Ts, uint16_t... Is>
std::tuple<Ts...> get(std::index_sequence<Is...>) const
{
return std::tuple<Ts...>{ m_row[m_columns[Is]].template as<Ts>()... };
}
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
......@@ -108,12 +108,12 @@ class row : public std::vector<item_value>
public:
row() = default;
item_value* get(size_t ix)
item_value* get(uint16_t ix)
{
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;
}
......@@ -125,7 +125,7 @@ class row : public std::vector<item_value>
template <typename, typename...>
friend class iterator_impl;
void append(size_t ix, item_value &&iv)
void append(uint16_t ix, item_value &&iv)
{
if (ix >= size())
resize(ix + 1);
......@@ -133,7 +133,7 @@ class row : public std::vector<item_value>
at(ix) = std::move(iv);
}
void remove(size_t ix)
void remove(uint16_t ix)
{
if (ix < size())
at(ix) = item_value{};
......@@ -148,7 +148,7 @@ class row : public std::vector<item_value>
class row_handle
{
public:
friend class item_handle;
friend struct item_handle;
friend class category;
friend class category_index;
friend class row_initializer;
......@@ -182,12 +182,12 @@ class row_handle
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);
}
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));
}
......@@ -231,7 +231,7 @@ class row_handle
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 or m_row != rhs.m_row; }
......@@ -257,7 +257,7 @@ class row_handle
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;
row *m_row = nullptr;
......
......@@ -28,13 +28,76 @@
#include <charconv>
#include <cmath>
#include <limits>
#include <set>
#include <sstream>
#include <tuple>
#include <vector>
#if __has_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
namespace cif
......@@ -95,10 +158,10 @@ std::vector<StringType> split(std::string_view s, std::string_view separators, b
{
std::vector<StringType> result;
auto b = s.begin();
auto b = s.data();
auto e = b;
while (e != s.end())
while (e != s.data() + s.length())
{
if (separators.find(*e) != std::string_view::npos)
{
......@@ -346,8 +409,8 @@ enum class chars_format
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)
{
int size = last - first;
int r;
size_t size = last - first;
size_t r = 0;
switch (fmt)
{
......
......@@ -25,6 +25,7 @@
*/
#include <numeric>
#include <stack>
#include <cif++/category.hpp>
#include <cif++/datablock.hpp>
......@@ -52,7 +53,7 @@ class row_comparator
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);
if (iv == nullptr)
......@@ -79,7 +80,7 @@ class row_comparator
int d = 0;
for (auto &c : m_comparator)
{
size_t k;
uint16_t k;
compareFunc f;
std::tie(k, f) = c;
......@@ -105,7 +106,7 @@ class row_comparator
int d = 0, i = 0;
for (auto &c : m_comparator)
{
size_t k;
uint16_t k;
compareFunc f;
std::tie(k, f) = c;
......@@ -124,7 +125,7 @@ class row_comparator
private:
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;
category &m_category;
......@@ -878,7 +879,7 @@ bool category::is_valid() const
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;
auto iv = m_columns[cix].m_validator;
......@@ -1297,7 +1298,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
// calling size() often is a waste of resources
if (m_last_unique_num == 0)
m_last_unique_num = size();
m_last_unique_num = static_cast<uint32_t>(size());
for (;;)
{
......@@ -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
if (m_index == nullptr and m_cat_validator != nullptr)
......@@ -1573,7 +1574,7 @@ row *category::clone_row(const row &r)
try
{
for (size_t ix = 0; ix < r.size(); ++ix)
for (uint16_t ix = 0; ix < r.size(); ++ix)
{
auto &i = r[ix];
if (not i)
......@@ -1606,7 +1607,7 @@ row_handle category::create_copy(row_handle r)
// copy the values
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);
if (i != nullptr)
......@@ -1712,7 +1713,7 @@ category::iterator category::insert_impl(const_iterator pos, row *n)
// #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 == b.m_category);
......@@ -1851,7 +1852,7 @@ std::vector<std::string> category::get_tag_order() const
void category::write(std::ostream &os) const
{
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);
}
......@@ -1869,7 +1870,7 @@ void category::write(std::ostream &os, const std::vector<std::string> &columns,
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())
order.push_back(i);
......@@ -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 (size_t ix = 0; ix < r->size(); ++ix)
for (uint16_t ix = 0; ix < r->size(); ++ix)
{
auto v = r->get(ix);
if (v == nullptr)
......@@ -1931,7 +1932,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
{
size_t offset = 0;
for (size_t cix : order)
for (uint16_t cix : order)
{
size_t w = columnWidths[cix];
......@@ -1983,7 +1984,7 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
l += 3;
for (size_t cix : order)
for (uint16_t cix : order)
{
auto &col = m_columns[cix];
......
......@@ -115,9 +115,9 @@ namespace detail
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);
delete this;
}
......
......@@ -38,7 +38,7 @@ void datablock::set_validator(const validator *v)
for (auto &cat : *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));
}
......
......@@ -34,12 +34,6 @@ namespace cif
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
{
public:
......
......@@ -190,7 +190,7 @@ void file::load(const std::filesystem::path &p)
load(in);
}
catch (const std::exception &ex)
catch (const std::exception &)
{
throw_with_nested(std::runtime_error("Error reading file " + p.string()));
}
......
......@@ -30,6 +30,7 @@
#include <fstream>
#include <iomanip>
#include <numeric>
#include <stack>
namespace fs = std::filesystem;
......@@ -49,12 +50,12 @@ void atom::atom_impl::moveTo(const point &p)
auto r = row();
#if __cpp_lib_format
r.assign("Cartn_x", std::format("{:.3f}", p.getX()), false, false);
r.assign("Cartn_y", std::format("{:.3f}", p.getY()), false, false);
r.assign("Cartn_z", std::format("{:.3f}", p.getZ()), false, false);
r.assign("Cartn_x", std::format("{:.3f}", p.m_x), false, false);
r.assign("Cartn_y", std::format("{:.3f}", p.m_y), false, false);
r.assign("Cartn_z", std::format("{:.3f}", p.m_z), false, false);
#else
r.assign("Cartn_x", format("%.3f", p.m_x).str(), false, false);
r.assign("Cartn_y", format("%.3f", p.m_y).str(), false, false);
r.assign("Cartn_x", cif::format"%.3f", p.m_x).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);
#endif
m_location = p;
......@@ -1410,7 +1411,7 @@ atom structure::get_atom_by_id(const std::string &id) const
{
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)
{
int i = (L + R) / 2;
......@@ -1669,7 +1670,7 @@ std::string structure::insert_compound(const std::string &compoundID, bool is_en
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)
{
int i = (L + R) / 2;
......@@ -1728,7 +1729,7 @@ void structure::remove_atom(atom &a, bool removeFromResidue)
bool removed = false;
#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)
{
int i = (L + R) / 2;
......@@ -1974,10 +1975,10 @@ void structure::remove_sugar(sugar &s)
dix.insert(tix);
for (auto &s : branch)
for (auto &s2 : branch)
{
if (s.get_link_nr() == tix)
test.push(s.num());
if (s2.get_link_nr() == tix)
test.push(s2.num());
}
for (auto atom : branch[tix - 1].atoms())
......@@ -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"];
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({
{"asym_id", asym_id},
{"entity_id", entity_id},
......@@ -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"];
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({
{"asym_id", asym_id},
{"entity_id", entity_id},
......@@ -2296,7 +2297,7 @@ branch &structure::extend_branch(const std::string &asym_id, std::vector<row_ini
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);
......@@ -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);
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);
}
auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
pdbx_branch_scheme.erase("asym_id"_key == asym_id);
for (auto &sugar : branch)
for (auto &s2 : branch)
{
pdbx_branch_scheme.emplace({
{"asym_id", asym_id},
{"entity_id", entity_id},
{"num", sugar.num()},
{"mon_id", sugar.get_compound_id()},
{"num", s2.num()},
{"mon_id", s2.get_compound_id()},
{"pdb_asym_id", asym_id},
{"pdb_seq_num", sugar.num()},
{"pdb_mon_id", sugar.get_compound_id()},
{"pdb_seq_num", s2.num()},
{"pdb_mon_id", s2.get_compound_id()},
// TODO: need fix, collect from nag_atoms?
{"auth_asym_id", asym_id},
{"auth_mon_id", sugar.get_compound_id()},
{"auth_seq_num", sugar.get_auth_seq_id()},
{"auth_mon_id", s2.get_compound_id()},
{"auth_seq_num", s2.get_auth_seq_id()},
{"hetero", "n"}
});
......
......@@ -918,7 +918,7 @@ class PDBFileParser
if (year < 1950)
year += 100;
s = format("%04d-%02d", year, month).str();
s = cif::format("%04d-%02d", year, month).str();
}
else
ec = error::make_error_code(error::pdbErrors::invalidDate);
......@@ -3266,18 +3266,18 @@ void PDBFileParser::ParseRemark350()
{ "type", type },
// { "name", "" },
// { "symmetryOperation", "" },
{ "matrix[1][1]", format("%12.10f", mat[0]).str() },
{ "matrix[1][2]", format("%12.10f", mat[1]).str() },
{ "matrix[1][3]", format("%12.10f", mat[2]).str() },
{ "vector[1]", format("%12.10f", vec[0]).str() },
{ "matrix[2][1]", format("%12.10f", mat[3]).str() },
{ "matrix[2][2]", format("%12.10f", mat[4]).str() },
{ "matrix[2][3]", format("%12.10f", mat[5]).str() },
{ "vector[2]", format("%12.10f", vec[1]).str() },
{ "matrix[3][1]", format("%12.10f", mat[6]).str() },
{ "matrix[3][2]", format("%12.10f", mat[7]).str() },
{ "matrix[3][3]", format("%12.10f", mat[8]).str() },
{ "vector[3]", format("%12.10f", vec[2]).str() } });
{ "matrix[1][1]", cif::format("%12.10f", mat[0]).str() },
{ "matrix[1][2]", cif::format("%12.10f", mat[1]).str() },
{ "matrix[1][3]", cif::format("%12.10f", mat[2]).str() },
{ "vector[1]", cif::format("%12.10f", vec[0]).str() },
{ "matrix[2][1]", cif::format("%12.10f", mat[3]).str() },
{ "matrix[2][2]", cif::format("%12.10f", mat[4]).str() },
{ "matrix[2][3]", cif::format("%12.10f", mat[5]).str() },
{ "vector[2]", cif::format("%12.10f", vec[1]).str() },
{ "matrix[3][1]", cif::format("%12.10f", mat[6]).str() },
{ "matrix[3][2]", cif::format("%12.10f", mat[7]).str() },
{ "matrix[3][3]", cif::format("%12.10f", mat[8]).str() },
{ "vector[3]", cif::format("%12.10f", vec[2]).str() } });
}
catch (duplicate_key_error &ex)
{
......@@ -5666,7 +5666,7 @@ void PDBFileParser::ParseCoordinate(int modelNr)
throw std::runtime_error("ANISOU record should follow corresponding ATOM record");
auto f = [](float f) -> std::string
{ return format("%6.4f", f).str(); };
{ return cif::format("%6.4f", f).str(); };
getCategory("atom_site_anisotrop")->emplace({
{ "id", mAtomID },
......@@ -6202,7 +6202,7 @@ file read(std::istream &is)
auto *buffer = is.rdbuf();
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
// and so the very first character in a valid PDB file
......
......@@ -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, ' ');
......
......@@ -29,7 +29,7 @@
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)
throw std::runtime_error("uninitialized row");
......@@ -61,7 +61,7 @@ uint16_t row_handle::add_column(std::string_view 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)
throw std::runtime_error("uninitialized row");
......@@ -81,7 +81,7 @@ row_initializer::row_initializer(row_handle rh)
row *r = rh.get_row();
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);
if (not i)
......
......@@ -128,7 +128,7 @@ std::string to_lower_copy(std::string_view s)
void to_upper(std::string &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)
......
......@@ -28,6 +28,7 @@
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
......
......@@ -137,8 +137,8 @@ int type_validator::compare(std::string_view a, std::string_view b) const
std::from_chars_result ra, rb;
ra = selected_charconv<double>::from_chars(a.begin(), a.end(), da);
rb = selected_charconv<double>::from_chars(b.begin(), b.end(), db);
ra = selected_charconv<double>::from_chars(a.data(), a.data() + a.length(), da);
rb = selected_charconv<double>::from_chars(b.data(), b.data() + b.length(), db);
if (ra.ec == std::errc() and rb.ec == std::errc())
{
......
......@@ -77,9 +77,9 @@ BOOST_AUTO_TEST_CASE(fmt_1)
std::ostringstream os;
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(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");
}
\ No newline at end of file
......@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(cc_1)
for (const auto &[txt, val, ch] : tests)
{
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_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