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"}
});
......
......@@ -25,6 +25,7 @@
*/
#include <cmath>
#include <deque>
#include <iomanip>
#include <map>
#include <regex>
......@@ -58,9 +59,9 @@ std::string cif2pdbDate(const std::string &d)
int month = std::stoi(m[2].str());
if (m[3].matched)
result = format("%02.2d-%3.3s-%02.2d", stoi(m[3].str()), kMonths[month - 1], (year % 100)).str();
result = cif::format("%02.2d-%3.3s-%02.2d", stoi(m[3].str()), kMonths[month - 1], (year % 100)).str();
else
result = format("%3.3s-%02.2d", kMonths[month - 1], (year % 100)).str();
result = cif::format("%3.3s-%02.2d", kMonths[month - 1], (year % 100)).str();
}
return result;
......@@ -259,7 +260,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
to_upper(pubname);
const std::string kRefHeader = s1 + "REF %2.2s %-28.28s %2.2s%4.4s %5.5s %4.4s";
pdbFile << format(kRefHeader, "" /* continuation */, pubname, (volume.empty() ? "" : "V."), volume, pageFirst, year)
pdbFile << cif::format(kRefHeader, "" /* continuation */, pubname, (volume.empty() ? "" : "V."), volume, pageFirst, year)
<< std::endl;
++result;
}
......@@ -267,7 +268,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
if (not issn.empty())
{
const std::string kRefHeader = s1 + "REFN ISSN %-25.25s";
pdbFile << format(kRefHeader, issn) << std::endl;
pdbFile << cif::format(kRefHeader, issn) << std::endl;
++result;
}
......@@ -278,7 +279,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
// const char kRefHeader[] =
// "REMARK 1 REFN %4.4s %-6.6s %2.2s %-25.25s";
//
// pdbFile << (boost::format(kRefHeader)
// pdbFile << (boost::cif::format(kRefHeader)
// % (astm.empty() ? "" : "ASTN")
// % astm
// % country
......@@ -289,14 +290,14 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
if (not pmid.empty())
{
const std::string kPMID = s1 + "PMID %-60.60s ";
pdbFile << format(kPMID, pmid) << std::endl;
pdbFile << cif::format(kPMID, pmid) << std::endl;
++result;
}
if (not doi.empty())
{
const std::string kDOI = s1 + "DOI %-60.60s ";
pdbFile << format(kDOI, doi) << std::endl;
pdbFile << cif::format(kDOI, doi) << std::endl;
++result;
}
......@@ -345,7 +346,7 @@ void write_header_lines(std::ostream &pdbFile, const datablock &db)
}
}
pdbFile << format(kHeader, keywords, date, db.name()) << std::endl;
pdbFile << cif::format(kHeader, keywords, date, db.name()) << std::endl;
// TODO: implement
// OBSLTE (skip for now)
......@@ -559,9 +560,9 @@ void WriteTitle(std::ostream &pdbFile, const datablock &db)
{
std::string cs = ++continuation > 1 ? std::to_string(continuation) : std::string();
pdbFile << format(kRevDatFmt, revNum, cs, date, db.name(), modType);
pdbFile << cif::format(kRevDatFmt, revNum, cs, date, db.name(), modType);
for (size_t i = 0; i < 4; ++i)
pdbFile << format(" %-6.6s", (i < types.size() ? types[i] : std::string()));
pdbFile << cif::format(" %-6.6s", (i < types.size() ? types[i] : std::string()));
pdbFile << std::endl;
if (types.size() > 4)
......@@ -614,7 +615,7 @@ void WriteRemark2(std::ostream &pdbFile, const datablock &db)
{
float resHigh = refine.front()["ls_d_res_high"].as<float>();
pdbFile << "REMARK 2" << std::endl
<< format("REMARK 2 RESOLUTION. %7.2f ANGSTROMS.", resHigh) << std::endl;
<< cif::format("REMARK 2 RESOLUTION. %7.2f ANGSTROMS.", resHigh) << std::endl;
}
catch (...)
{ /* skip it */
......@@ -1591,7 +1592,7 @@ void WriteRemark3Phenix(std::ostream &pdbFile, const datablock &db)
percent_reflns_obs /= 100;
pdbFile << RM3(" ") << format("%3d %7.4f - %7.4f %4.2f %8d %5d %6.4f %6.4f", bin++, d_res_low, d_res_high, percent_reflns_obs, number_reflns_R_work, number_reflns_R_free, R_factor_R_work, R_factor_R_free) << std::endl;
pdbFile << RM3(" ") << cif::format("%3d %7.4f - %7.4f %4.2f %8d %5d %6.4f %6.4f", bin++, d_res_low, d_res_high, percent_reflns_obs, number_reflns_R_work, number_reflns_R_free, R_factor_R_work, R_factor_R_free) << std::endl;
}
pdbFile << RM3("") << std::endl
......@@ -2559,7 +2560,7 @@ void WriteRemark465(std::ostream &pdbFile, const datablock &db)
cif::tie(modelNr, resName, chainID, iCode, seqNr) =
r.get("PDB_model_num", "auth_comp_id", "auth_asym_id", "PDB_ins_code", "auth_seq_id");
pdbFile << format("REMARK 465 %3.3s %3.3s %1.1s %5d%1.1s", modelNr, resName, chainID, seqNr, iCode) << std::endl;
pdbFile << cif::format("REMARK 465 %3.3s %3.3s %1.1s %5d%1.1s", modelNr, resName, chainID, seqNr, iCode) << std::endl;
}
}
......@@ -2606,7 +2607,7 @@ void WriteRemark470(std::ostream &pdbFile, const datablock &db)
while (not a.second.empty())
{
pdbFile << format("REMARK 470 %3.3s %3.3s %1.1s%4d%1.1s ", modelNr, resName, chainID, seqNr, iCode) << " ";
pdbFile << cif::format("REMARK 470 %3.3s %3.3s %1.1s%4d%1.1s ", modelNr, resName, chainID, seqNr, iCode) << " ";
for (size_t i = 0; i < 6 and not a.second.empty(); ++i)
{
......@@ -2703,16 +2704,16 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
"pdbx_seq_align_end_ins_code", "pdbx_db_accession", "db_align_beg", "pdbx_db_align_beg_ins_code", "db_align_end", "pdbx_db_align_end_ins_code");
if (dbAccession.length() > 8 or db_code.length() > 12 or atoi(dbseqEnd.c_str()) >= 100000)
pdbFile << format(
pdbFile << cif::format(
"DBREF1 %4.4s %1.1s %4.4s%1.1s %4.4s%1.1s %-6.6s %-20.20s",
idCode, chainID, seqBegin, insertBegin, seqEnd, insertEnd, db_name, db_code)
<< std::endl
<< format(
<< cif::format(
"DBREF2 %4.4s %1.1s %-22.22s %10.10s %10.10s",
idCode, chainID, dbAccession, dbseqBegin, dbseqEnd)
<< std::endl;
else
pdbFile << format(
pdbFile << cif::format(
"DBREF %4.4s %1.1s %4.4s%1.1s %4.4s%1.1s %-6.6s %-8.8s %-12.12s %5.5s%1.1s %5.5s%1.1s",
idCode, chainID, seqBegin, insertBegin, seqEnd, insertEnd, db_name, dbAccession, db_code, dbseqBegin, dbinsBeg, dbseqEnd, dbinsEnd)
<< std::endl;
......@@ -2731,7 +2732,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
to_upper(conflict);
pdbFile << format(
pdbFile << cif::format(
"SEQADV %4.4s %3.3s %1.1s %4.4s%1.1s %-4.4s %-9.9s %3.3s %5.5s %-21.21s",
idCode, resName, chainID, seqNum, iCode, database, dbAccession, dbRes, dbSeq, conflict)
.str()
......@@ -2761,7 +2762,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
if (t > 13)
t = 13;
pdbFile << format(
pdbFile << cif::format(
"SEQRES %3d %1.1s %4d %-51.51s ",
n++, std::string{ chainID }, seqresl[chainID], join(seq.begin(), seq.begin() + t, " "))
<< std::endl;
......@@ -2781,7 +2782,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
cif::tie(chainID, seqNum, resName, iCode, stdRes, comment) =
r.get("auth_asym_id", "auth_seq_id", "auth_comp_id", "PDB_ins_code", "parent_comp_id", "details");
pdbFile << format(
pdbFile << cif::format(
"MODRES %4.4s %3.3s %1.1s %4.4s%1.1s %3.3s %-41.41s",
db.name(), resName, chainID, seqNum, iCode, stdRes, comment)
.str()
......@@ -2899,7 +2900,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
{
if (h.water)
continue;
pdbFile << format("HET %3.3s %c%4d%c %5d", h.hetID, h.chainID, h.seqNum, h.iCode, h.numHetAtoms) << std::endl;
pdbFile << cif::format("HET %3.3s %c%4d%c %5d", h.hetID, h.chainID, h.seqNum, h.iCode, h.numHetAtoms) << std::endl;
++numHet;
}
......@@ -2914,7 +2915,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
for (;;)
{
pdbFile << format("HETNAM %2.2s %3.3s ", (c > 1 ? std::to_string(c) : std::string()), id);
pdbFile << cif::format("HETNAM %2.2s %3.3s ", (c > 1 ? std::to_string(c) : std::string()), id);
++c;
if (name.length() > 55)
......@@ -3006,7 +3007,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
{
std::stringstream fs;
fs << format("FORMUL %2d %3.3s %2.2s%c", componentNr, hetID, (c > 1 ? std::to_string(c) : std::string()), (hetID == water_comp_id ? '*' : ' '));
fs << cif::format("FORMUL %2d %3.3s %2.2s%c", componentNr, hetID, (c > 1 ? std::to_string(c) : std::string()), (hetID == water_comp_id ? '*' : ' '));
++c;
if (formula.length() > 51)
......@@ -3073,7 +3074,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
"pdbx_PDB_helix_class", "pdbx_PDB_helix_length", "beg_auth_seq_id", "end_auth_seq_id");
++numHelix;
pdbFile << format("HELIX %3d %3.3s %3.3s %1.1s %4d%1.1s %3.3s %1.1s %4d%1.1s%2d%-30.30s %5d",
pdbFile << cif::format("HELIX %3d %3.3s %3.3s %1.1s %4d%1.1s %3.3s %1.1s %4d%1.1s%2d%-30.30s %5d",
numHelix, pdbx_PDB_helix_id, beg_label_comp_id, beg_auth_asym_id, beg_auth_seq_id, pdbx_beg_PDB_ins_code, end_label_comp_id, end_auth_asym_id, end_auth_seq_id, pdbx_end_PDB_ins_code, pdbx_PDB_helix_class, details, pdbx_PDB_helix_length)
<< std::endl;
}
......@@ -3110,7 +3111,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
"pdbx_end_PDB_ins_code", "beg_auth_comp_id", "beg_auth_asym_id", "beg_auth_seq_id",
"end_auth_comp_id", "end_auth_asym_id", "end_auth_seq_id");
pdbFile << format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d", rangeID1, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, 0) << std::endl;
pdbFile << cif::format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d", rangeID1, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, 0) << std::endl;
first = false;
}
......@@ -3129,7 +3130,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
if (h.empty())
{
pdbFile << format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d", rangeID2, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, sense) << std::endl;
pdbFile << cif::format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d", rangeID2, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, sense) << std::endl;
}
else
{
......@@ -3142,7 +3143,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
curAtom = cif2pdbAtomName(curAtom, compID[0], db);
prevAtom = cif2pdbAtomName(prevAtom, compID[1], db);
pdbFile << format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d "
pdbFile << cif::format("SHEET %3.3s %3.3s%2d %3.3s %1.1s%4d%1.1s %3.3s %1.1s%4d%1.1s%2d "
"%-4.4s%3.3s %1.1s%4d%1.1s %-4.4s%3.3s %1.1s%4d%1.1s",
rangeID2, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, sense, curAtom, curResName, curChainID, curResSeq, curICode, prevAtom, prevResName, prevChainID, prevResSeq, prevICode)
<< std::endl;
......@@ -3181,7 +3182,7 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db)
sym1 = cif2pdbSymmetry(sym1);
sym2 = cif2pdbSymmetry(sym2);
pdbFile << format("SSBOND %3d CYS %1.1s %4d%1.1s CYS %1.1s %4d%1.1s %6.6s %6.6s %5.2f", nr, chainID1, seqNum1, icode1, chainID2, seqNum2, icode2, sym1, sym2, Length) << std::endl;
pdbFile << cif::format("SSBOND %3d CYS %1.1s %4d%1.1s CYS %1.1s %4d%1.1s %6.6s %6.6s %5.2f", nr, chainID1, seqNum1, icode1, chainID2, seqNum2, icode2, sym1, sym2, Length) << std::endl;
++nr;
}
......@@ -3208,10 +3209,10 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db)
sym1 = cif2pdbSymmetry(sym1);
sym2 = cif2pdbSymmetry(sym2);
pdbFile << format("LINK %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %6.6s %6.6s", name1, altLoc1, resName1, chainID1, resSeq1, iCode1, name2, altLoc2, resName2, chainID2, resSeq2, iCode2, sym1, sym2);
pdbFile << cif::format("LINK %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %6.6s %6.6s", name1, altLoc1, resName1, chainID1, resSeq1, iCode1, name2, altLoc2, resName2, chainID2, resSeq2, iCode2, sym1, sym2);
if (not Length.empty())
pdbFile << format(" %5.2f", stod(Length));
pdbFile << cif::format(" %5.2f", stod(Length));
pdbFile << std::endl;
}
......@@ -3229,7 +3230,7 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db)
"pdbx_label_comp_id_2", "pdbx_auth_asym_id_2", "pdbx_auth_seq_id_2", "pdbx_PDB_ins_code_2",
"pdbx_PDB_model_num", "pdbx_omega_angle");
pdbFile << format("CISPEP %3.3s %3.3s %1.1s %4d%1.1s %3.3s %1.1s %4d%1.1s %3.3s %6.2f",
pdbFile << cif::format("CISPEP %3.3s %3.3s %1.1s %4d%1.1s %3.3s %1.1s %4d%1.1s %3.3s %6.2f",
serNum, pep1, chainID1, seqNum1, icode1, pep2, chainID2, seqNum2, icode2, modNum, measure) << std::endl;
}
}
......@@ -3250,7 +3251,7 @@ int WriteMiscellaneousFeatures(std::ostream &pdbFile, const datablock &db)
cif::tie(siteID, resName, chainID, seq, iCode) =
r.get("site_id", "auth_comp_id", "auth_asym_id", "auth_seq_id", "pdbx_auth_ins_code");
sites[siteID].push_back(format("%3.3s %1.1s%4d%1.1s ", resName, chainID, seq, iCode).str());
sites[siteID].push_back(cif::format("%3.3s %1.1s%4d%1.1s ", resName, chainID, seq, iCode).str());
}
for (auto s : sites)
......@@ -3263,7 +3264,7 @@ int WriteMiscellaneousFeatures(std::ostream &pdbFile, const datablock &db)
int nr = 1;
while (res.empty() == false)
{
pdbFile << format("SITE %3d %3.3s %2d ", nr, siteID, numRes);
pdbFile << cif::format("SITE %3d %3.3s %2d ", nr, siteID, numRes);
for (int i = 0; i < 4; ++i)
{
......@@ -3292,7 +3293,7 @@ void WriteCrystallographic(std::ostream &pdbFile, const datablock &db)
r = db["cell"].find1(key("entry_id") == db.name());
pdbFile << format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %-11.11s%4d", r["length_a"].as<double>(), r["length_b"].as<double>(), r["length_c"].as<double>(), r["angle_alpha"].as<double>(), r["angle_beta"].as<double>(), r["angle_gamma"].as<double>(), symmetry, r["Z_PDB"].as<int>()) << std::endl;
pdbFile << cif::format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %-11.11s%4d", r["length_a"].as<double>(), r["length_b"].as<double>(), r["length_c"].as<double>(), r["angle_alpha"].as<double>(), r["angle_beta"].as<double>(), r["angle_gamma"].as<double>(), symmetry, r["Z_PDB"].as<int>()) << std::endl;
}
int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db)
......@@ -3301,18 +3302,18 @@ int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db)
for (auto r : db["database_PDB_matrix"])
{
pdbFile << format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 1, r["origx[1][1]"].as<float>(), r["origx[1][2]"].as<float>(), r["origx[1][3]"].as<float>(), r["origx_vector[1]"].as<float>()) << std::endl;
pdbFile << format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 2, r["origx[2][1]"].as<float>(), r["origx[2][2]"].as<float>(), r["origx[2][3]"].as<float>(), r["origx_vector[2]"].as<float>()) << std::endl;
pdbFile << format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 3, r["origx[3][1]"].as<float>(), r["origx[3][2]"].as<float>(), r["origx[3][3]"].as<float>(), r["origx_vector[3]"].as<float>()) << std::endl;
pdbFile << cif::format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 1, r["origx[1][1]"].as<float>(), r["origx[1][2]"].as<float>(), r["origx[1][3]"].as<float>(), r["origx_vector[1]"].as<float>()) << std::endl;
pdbFile << cif::format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 2, r["origx[2][1]"].as<float>(), r["origx[2][2]"].as<float>(), r["origx[2][3]"].as<float>(), r["origx_vector[2]"].as<float>()) << std::endl;
pdbFile << cif::format("ORIGX%1d %10.6f%10.6f%10.6f %10.5f", 3, r["origx[3][1]"].as<float>(), r["origx[3][2]"].as<float>(), r["origx[3][3]"].as<float>(), r["origx_vector[3]"].as<float>()) << std::endl;
result += 3;
break;
}
for (auto r : db["atom_sites"])
{
pdbFile << format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 1, r["fract_transf_matrix[1][1]"].as<float>(), r["fract_transf_matrix[1][2]"].as<float>(), r["fract_transf_matrix[1][3]"].as<float>(), r["fract_transf_vector[1]"].as<float>()) << std::endl;
pdbFile << format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 2, r["fract_transf_matrix[2][1]"].as<float>(), r["fract_transf_matrix[2][2]"].as<float>(), r["fract_transf_matrix[2][3]"].as<float>(), r["fract_transf_vector[2]"].as<float>()) << std::endl;
pdbFile << format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 3, r["fract_transf_matrix[3][1]"].as<float>(), r["fract_transf_matrix[3][2]"].as<float>(), r["fract_transf_matrix[3][3]"].as<float>(), r["fract_transf_vector[3]"].as<float>()) << std::endl;
pdbFile << cif::format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 1, r["fract_transf_matrix[1][1]"].as<float>(), r["fract_transf_matrix[1][2]"].as<float>(), r["fract_transf_matrix[1][3]"].as<float>(), r["fract_transf_vector[1]"].as<float>()) << std::endl;
pdbFile << cif::format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 2, r["fract_transf_matrix[2][1]"].as<float>(), r["fract_transf_matrix[2][2]"].as<float>(), r["fract_transf_matrix[2][3]"].as<float>(), r["fract_transf_vector[2]"].as<float>()) << std::endl;
pdbFile << cif::format("SCALE%1d %10.6f%10.6f%10.6f %10.5f", 3, r["fract_transf_matrix[3][1]"].as<float>(), r["fract_transf_matrix[3][2]"].as<float>(), r["fract_transf_matrix[3][3]"].as<float>(), r["fract_transf_vector[3]"].as<float>()) << std::endl;
result += 3;
break;
}
......@@ -3322,9 +3323,9 @@ int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db)
{
std::string given = r["code"] == "given" ? "1" : "";
pdbFile << format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 1, nr, r["matrix[1][1]"].as<float>(), r["matrix[1][2]"].as<float>(), r["matrix[1][3]"].as<float>(), r["vector[1]"].as<float>(), given) << std::endl;
pdbFile << format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 2, nr, r["matrix[2][1]"].as<float>(), r["matrix[2][2]"].as<float>(), r["matrix[2][3]"].as<float>(), r["vector[2]"].as<float>(), given) << std::endl;
pdbFile << format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 3, nr, r["matrix[3][1]"].as<float>(), r["matrix[3][2]"].as<float>(), r["matrix[3][3]"].as<float>(), r["vector[3]"].as<float>(), given) << std::endl;
pdbFile << cif::format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 1, nr, r["matrix[1][1]"].as<float>(), r["matrix[1][2]"].as<float>(), r["matrix[1][3]"].as<float>(), r["vector[1]"].as<float>(), given) << std::endl;
pdbFile << cif::format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 2, nr, r["matrix[2][1]"].as<float>(), r["matrix[2][2]"].as<float>(), r["matrix[2][3]"].as<float>(), r["vector[2]"].as<float>(), given) << std::endl;
pdbFile << cif::format("MTRIX%1d %3d%10.6f%10.6f%10.6f %10.5f %1.1s", 3, nr, r["matrix[3][1]"].as<float>(), r["matrix[3][2]"].as<float>(), r["matrix[3][3]"].as<float>(), r["vector[3]"].as<float>(), given) << std::endl;
++nr;
result += 3;
......@@ -3374,7 +3375,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
if (terminate)
{
pdbFile << format("TER %5d %3.3s %1.1s%4d%1.1s", serial, resName, chainID, resSeq, iCode) << std::endl;
pdbFile << cif::format("TER %5d %3.3s %1.1s%4d%1.1s", serial, resName, chainID, resSeq, iCode) << std::endl;
++serial;
terminatedChains.insert(chainID);
......@@ -3413,7 +3414,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
if (charge != 0)
sCharge = std::to_string(charge) + (charge > 0 ? '+' : '-');
pdbFile << format("%-6.6s%5d %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %8.3f%8.3f%8.3f%6.2f%6.2f %2.2s%2.2s", group, serial, name, altLoc, resName, chainID, resSeq, iCode, x, y, z, occupancy, tempFactor, element, sCharge) << std::endl;
pdbFile << cif::format("%-6.6s%5d %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %8.3f%8.3f%8.3f%6.2f%6.2f %2.2s%2.2s", group, serial, name, altLoc, resName, chainID, resSeq, iCode, x, y, z, occupancy, tempFactor, element, sCharge) << std::endl;
++numCoord;
......@@ -3428,7 +3429,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
tie(u11, u22, u33, u12, u13, u23) =
ai.get("U[1][1]", "U[2][2]", "U[3][3]", "U[1][2]", "U[1][3]", "U[2][3]");
pdbFile << format("ANISOU%5d %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %7d%7d%7d%7d%7d%7d %2.2s%2.2s", serial, name, altLoc, resName, chainID, resSeq, iCode, std::lrintf(u11 * 10000), std::lrintf(u22 * 10000), std::lrintf(u33 * 10000), std::lrintf(u12 * 10000), std::lrintf(u13 * 10000), std::lrintf(u23 * 10000), element, sCharge) << std::endl;
pdbFile << cif::format("ANISOU%5d %-4.4s%1.1s%3.3s %1.1s%4d%1.1s %7d%7d%7d%7d%7d%7d %2.2s%2.2s", serial, name, altLoc, resName, chainID, resSeq, iCode, std::lrintf(u11 * 10000), std::lrintf(u22 * 10000), std::lrintf(u33 * 10000), std::lrintf(u12 * 10000), std::lrintf(u13 * 10000), std::lrintf(u23 * 10000), element, sCharge) << std::endl;
}
++serial;
......@@ -3480,7 +3481,7 @@ std::tuple<int, int> WriteCoordinate(std::ostream &pdbFile, const datablock &db)
for (int model_nr : models)
{
if (models.size() > 1)
pdbFile << format("MODEL %4d", model_nr) << std::endl;
pdbFile << cif::format("MODEL %4d", model_nr) << std::endl;
std::set<std::string> TERminatedChains;
auto n = WriteCoordinatesForModel(pdbFile, db, last_resseq_for_chain_map, TERminatedChains, model_nr);
......@@ -3552,7 +3553,7 @@ std::string get_HEADER_line(const datablock &db, std::string::size_type truncate
}
}
return FixStringLength(format("HEADER %-40.40s%-9.9s %-4.4s", keywords, date, db.name()).str(), truncate_at);
return FixStringLength(cif::format("HEADER %-40.40s%-9.9s %-4.4s", keywords, date, db.name()).str(), truncate_at);
}
std::string get_COMPND_line(const datablock &db, std::string::size_type truncate_at)
......@@ -3725,7 +3726,7 @@ void write(std::ostream &os, const datablock &db)
numXform = WriteCoordinateTransformation(os, db);
std::tie(numCoord, numTer) = WriteCoordinate(os, db);
os << format("MASTER %5d 0%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", numRemark, numHet, numHelix, numSheet, numTurn, numSite, numXform, numCoord, numTer, numConect, numSeq) << std::endl
os << cif::format("MASTER %5d 0%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", numRemark, numHet, numHelix, numSheet, numTurn, numSite, numXform, numCoord, numTer, numConect, numSeq) << std::endl
<< "END" << std::endl;
}
......
......@@ -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