Commit 9bc33818 by Maarten L. Hekkelman

First steps to compile libcifpp 5 in Windows

parent f3a492fd
...@@ -234,6 +234,10 @@ if(BOOST_REGEX) ...@@ -234,6 +234,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
...@@ -129,7 +129,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -129,7 +129,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_gzheader, rhs.m_gzheader); std::swap(m_gzheader, rhs.m_gzheader);
auto p = std::copy(rhs.gptr(), rhs.egptr(), m_out_buffer.begin()); 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) if (m_zstream and m_zstream->avail_in > 0)
{ {
...@@ -137,7 +137,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -137,7 +137,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::copy(rhs.m_in_buffer.begin() + next_in_offset, std::copy(rhs.m_in_buffer.begin() + next_in_offset,
rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in, rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in,
m_in_buffer.begin()); 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> ...@@ -152,7 +152,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_gzheader, rhs.m_gzheader); std::swap(m_gzheader, rhs.m_gzheader);
auto p = std::copy(rhs.gptr(), rhs.egptr(), m_out_buffer.begin()); 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) if (m_zstream and m_zstream->avail_in > 0)
{ {
...@@ -160,7 +160,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -160,7 +160,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
std::copy(rhs.m_in_buffer.begin() + next_in_offset, std::copy(rhs.m_in_buffer.begin() + next_in_offset,
rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in, rhs.m_in_buffer.begin() + next_in_offset + m_zstream->avail_in,
m_in_buffer.begin()); 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; return *this;
...@@ -212,7 +212,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -212,7 +212,7 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
if (err == Z_OK) if (err == Z_OK)
{ {
zstream.next_in = reinterpret_cast<unsigned char *>(m_in_buffer.data()); 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); err = ::inflateGetHeader(&zstream, &header);
...@@ -238,12 +238,12 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -238,12 +238,12 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
while (this->gptr() == this->egptr()) while (this->gptr() == this->egptr())
{ {
zstream.next_out = reinterpret_cast<unsigned char *>(m_out_buffer.data()); 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) if (zstream.avail_in == 0)
{ {
zstream.next_in = reinterpret_cast<unsigned char *>(m_in_buffer.data()); 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); int err = ::inflate(&zstream, Z_SYNC_FLUSH);
...@@ -252,9 +252,9 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -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)) if (err == Z_STREAM_END or (err == Z_OK and n > 0))
{ {
this->setg( this->setg(
m_out_buffer.begin(), m_out_buffer.data(),
m_out_buffer.begin(), m_out_buffer.data(),
m_out_buffer.begin() + n); m_out_buffer.data() + n);
break; break;
} }
...@@ -319,7 +319,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -319,7 +319,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_zstream, rhs.m_zstream); std::swap(m_zstream, rhs.m_zstream);
std::swap(m_gzheader, rhs.m_gzheader); 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()); this->sputn(rhs.pbase(), rhs.pptr() - rhs.pbase());
rhs.setp(nullptr, nullptr); rhs.setp(nullptr, nullptr);
} }
...@@ -334,7 +334,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -334,7 +334,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
std::swap(m_zstream, rhs.m_zstream); std::swap(m_zstream, rhs.m_zstream);
std::swap(m_gzheader, rhs.m_gzheader); 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()); this->sputn(rhs.pbase(), rhs.pptr() - rhs.pbase());
rhs.setp(nullptr, nullptr); rhs.setp(nullptr, nullptr);
...@@ -393,7 +393,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -393,7 +393,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
err = ::deflateSetHeader(&zstream, &header); err = ::deflateSetHeader(&zstream, &header);
if (err == Z_OK) 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 else
zstream = z_stream_s{}; zstream = z_stream_s{};
...@@ -413,7 +413,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -413,7 +413,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
auto &zstream = *m_zstream; auto &zstream = *m_zstream;
zstream.next_in = reinterpret_cast<unsigned char *>(this->pbase()); 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]; char_type buffer[BufferSize];
...@@ -442,7 +442,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits> ...@@ -442,7 +442,7 @@ class basic_ogzip_streambuf : public basic_streambuf<CharT, Traits>
break; 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())) if (not traits_type::eq_int_type(ch, traits_type::eof()))
{ {
......
...@@ -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 <uint16_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, uint16_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; size_t size = last - first;
int r; size_t 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,12 +50,12 @@ void atom::atom_impl::moveTo(const point &p) ...@@ -49,12 +50,12 @@ 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", 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"}
}); });
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
*/ */
#include <cmath> #include <cmath>
#include <deque>
#include <iomanip> #include <iomanip>
#include <map> #include <map>
#include <regex> #include <regex>
...@@ -58,9 +59,9 @@ std::string cif2pdbDate(const std::string &d) ...@@ -58,9 +59,9 @@ std::string cif2pdbDate(const std::string &d)
int month = std::stoi(m[2].str()); int month = std::stoi(m[2].str());
if (m[3].matched) 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 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; return result;
...@@ -259,7 +260,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i ...@@ -259,7 +260,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
to_upper(pubname); to_upper(pubname);
const std::string kRefHeader = s1 + "REF %2.2s %-28.28s %2.2s%4.4s %5.5s %4.4s"; 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; << std::endl;
++result; ++result;
} }
...@@ -267,7 +268,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i ...@@ -267,7 +268,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
if (not issn.empty()) if (not issn.empty())
{ {
const std::string kRefHeader = s1 + "REFN ISSN %-25.25s"; const std::string kRefHeader = s1 + "REFN ISSN %-25.25s";
pdbFile << format(kRefHeader, issn) << std::endl; pdbFile << cif::format(kRefHeader, issn) << std::endl;
++result; ++result;
} }
...@@ -278,7 +279,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i ...@@ -278,7 +279,7 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
// const char kRefHeader[] = // const char kRefHeader[] =
// "REMARK 1 REFN %4.4s %-6.6s %2.2s %-25.25s"; // "REMARK 1 REFN %4.4s %-6.6s %2.2s %-25.25s";
// //
// pdbFile << (boost::format(kRefHeader) // pdbFile << (boost::cif::format(kRefHeader)
// % (astm.empty() ? "" : "ASTN") // % (astm.empty() ? "" : "ASTN")
// % astm // % astm
// % country // % country
...@@ -289,14 +290,14 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i ...@@ -289,14 +290,14 @@ size_t WriteCitation(std::ostream &pdbFile, const datablock &db, row_handle r, i
if (not pmid.empty()) if (not pmid.empty())
{ {
const std::string kPMID = s1 + "PMID %-60.60s "; const std::string kPMID = s1 + "PMID %-60.60s ";
pdbFile << format(kPMID, pmid) << std::endl; pdbFile << cif::format(kPMID, pmid) << std::endl;
++result; ++result;
} }
if (not doi.empty()) if (not doi.empty())
{ {
const std::string kDOI = s1 + "DOI %-60.60s "; const std::string kDOI = s1 + "DOI %-60.60s ";
pdbFile << format(kDOI, doi) << std::endl; pdbFile << cif::format(kDOI, doi) << std::endl;
++result; ++result;
} }
...@@ -345,7 +346,7 @@ void write_header_lines(std::ostream &pdbFile, const datablock &db) ...@@ -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 // TODO: implement
// OBSLTE (skip for now) // OBSLTE (skip for now)
...@@ -559,9 +560,9 @@ void WriteTitle(std::ostream &pdbFile, const datablock &db) ...@@ -559,9 +560,9 @@ void WriteTitle(std::ostream &pdbFile, const datablock &db)
{ {
std::string cs = ++continuation > 1 ? std::to_string(continuation) : std::string(); 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) 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; pdbFile << std::endl;
if (types.size() > 4) if (types.size() > 4)
...@@ -614,7 +615,7 @@ void WriteRemark2(std::ostream &pdbFile, const datablock &db) ...@@ -614,7 +615,7 @@ void WriteRemark2(std::ostream &pdbFile, const datablock &db)
{ {
float resHigh = refine.front()["ls_d_res_high"].as<float>(); float resHigh = refine.front()["ls_d_res_high"].as<float>();
pdbFile << "REMARK 2" << std::endl 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 (...) catch (...)
{ /* skip it */ { /* skip it */
...@@ -1591,7 +1592,7 @@ void WriteRemark3Phenix(std::ostream &pdbFile, const datablock &db) ...@@ -1591,7 +1592,7 @@ void WriteRemark3Phenix(std::ostream &pdbFile, const datablock &db)
percent_reflns_obs /= 100; 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 pdbFile << RM3("") << std::endl
...@@ -2559,7 +2560,7 @@ void WriteRemark465(std::ostream &pdbFile, const datablock &db) ...@@ -2559,7 +2560,7 @@ void WriteRemark465(std::ostream &pdbFile, const datablock &db)
cif::tie(modelNr, resName, chainID, iCode, seqNr) = cif::tie(modelNr, resName, chainID, iCode, seqNr) =
r.get("PDB_model_num", "auth_comp_id", "auth_asym_id", "PDB_ins_code", "auth_seq_id"); 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) ...@@ -2606,7 +2607,7 @@ void WriteRemark470(std::ostream &pdbFile, const datablock &db)
while (not a.second.empty()) 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) 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) ...@@ -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"); "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) 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", "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) idCode, chainID, seqBegin, insertBegin, seqEnd, insertEnd, db_name, db_code)
<< std::endl << std::endl
<< format( << cif::format(
"DBREF2 %4.4s %1.1s %-22.22s %10.10s %10.10s", "DBREF2 %4.4s %1.1s %-22.22s %10.10s %10.10s",
idCode, chainID, dbAccession, dbseqBegin, dbseqEnd) idCode, chainID, dbAccession, dbseqBegin, dbseqEnd)
<< std::endl; << std::endl;
else 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", "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) idCode, chainID, seqBegin, insertBegin, seqEnd, insertEnd, db_name, dbAccession, db_code, dbseqBegin, dbinsBeg, dbseqEnd, dbinsEnd)
<< std::endl; << std::endl;
...@@ -2731,7 +2732,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db) ...@@ -2731,7 +2732,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
to_upper(conflict); 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", "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) idCode, resName, chainID, seqNum, iCode, database, dbAccession, dbRes, dbSeq, conflict)
.str() .str()
...@@ -2761,7 +2762,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db) ...@@ -2761,7 +2762,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
if (t > 13) if (t > 13)
t = 13; t = 13;
pdbFile << format( pdbFile << cif::format(
"SEQRES %3d %1.1s %4d %-51.51s ", "SEQRES %3d %1.1s %4d %-51.51s ",
n++, std::string{ chainID }, seqresl[chainID], join(seq.begin(), seq.begin() + t, " ")) n++, std::string{ chainID }, seqresl[chainID], join(seq.begin(), seq.begin() + t, " "))
<< std::endl; << std::endl;
...@@ -2781,7 +2782,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db) ...@@ -2781,7 +2782,7 @@ int WritePrimaryStructure(std::ostream &pdbFile, const datablock &db)
cif::tie(chainID, seqNum, resName, iCode, stdRes, comment) = 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"); 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", "MODRES %4.4s %3.3s %1.1s %4.4s%1.1s %3.3s %-41.41s",
db.name(), resName, chainID, seqNum, iCode, stdRes, comment) db.name(), resName, chainID, seqNum, iCode, stdRes, comment)
.str() .str()
...@@ -2899,7 +2900,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db) ...@@ -2899,7 +2900,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
{ {
if (h.water) if (h.water)
continue; 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; ++numHet;
} }
...@@ -2914,7 +2915,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db) ...@@ -2914,7 +2915,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
for (;;) 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; ++c;
if (name.length() > 55) if (name.length() > 55)
...@@ -3006,7 +3007,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db) ...@@ -3006,7 +3007,7 @@ int WriteHeterogen(std::ostream &pdbFile, const datablock &db)
{ {
std::stringstream fs; 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; ++c;
if (formula.length() > 51) if (formula.length() > 51)
...@@ -3073,7 +3074,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl ...@@ -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"); "pdbx_PDB_helix_class", "pdbx_PDB_helix_length", "beg_auth_seq_id", "end_auth_seq_id");
++numHelix; ++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) 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; << std::endl;
} }
...@@ -3110,7 +3111,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl ...@@ -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", "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"); "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; first = false;
} }
...@@ -3129,7 +3130,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl ...@@ -3129,7 +3130,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
if (h.empty()) 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 else
{ {
...@@ -3142,7 +3143,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl ...@@ -3142,7 +3143,7 @@ std::tuple<int, int> WriteSecondaryStructure(std::ostream &pdbFile, const databl
curAtom = cif2pdbAtomName(curAtom, compID[0], db); curAtom = cif2pdbAtomName(curAtom, compID[0], db);
prevAtom = cif2pdbAtomName(prevAtom, compID[1], 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", "%-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) rangeID2, sheetID, numStrands, initResName, initChainID, initSeqNum, initICode, endResName, endChainID, endSeqNum, endICode, sense, curAtom, curResName, curChainID, curResSeq, curICode, prevAtom, prevResName, prevChainID, prevResSeq, prevICode)
<< std::endl; << std::endl;
...@@ -3181,7 +3182,7 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db) ...@@ -3181,7 +3182,7 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db)
sym1 = cif2pdbSymmetry(sym1); sym1 = cif2pdbSymmetry(sym1);
sym2 = cif2pdbSymmetry(sym2); 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; ++nr;
} }
...@@ -3208,10 +3209,10 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db) ...@@ -3208,10 +3209,10 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db)
sym1 = cif2pdbSymmetry(sym1); sym1 = cif2pdbSymmetry(sym1);
sym2 = cif2pdbSymmetry(sym2); 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()) if (not Length.empty())
pdbFile << format(" %5.2f", stod(Length)); pdbFile << cif::format(" %5.2f", stod(Length));
pdbFile << std::endl; pdbFile << std::endl;
} }
...@@ -3229,7 +3230,7 @@ void WriteConnectivity(std::ostream &pdbFile, const datablock &db) ...@@ -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_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"); "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; 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) ...@@ -3250,7 +3251,7 @@ int WriteMiscellaneousFeatures(std::ostream &pdbFile, const datablock &db)
cif::tie(siteID, resName, chainID, seq, iCode) = cif::tie(siteID, resName, chainID, seq, iCode) =
r.get("site_id", "auth_comp_id", "auth_asym_id", "auth_seq_id", "pdbx_auth_ins_code"); 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) for (auto s : sites)
...@@ -3263,7 +3264,7 @@ int WriteMiscellaneousFeatures(std::ostream &pdbFile, const datablock &db) ...@@ -3263,7 +3264,7 @@ int WriteMiscellaneousFeatures(std::ostream &pdbFile, const datablock &db)
int nr = 1; int nr = 1;
while (res.empty() == false) 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) for (int i = 0; i < 4; ++i)
{ {
...@@ -3292,7 +3293,7 @@ void WriteCrystallographic(std::ostream &pdbFile, const datablock &db) ...@@ -3292,7 +3293,7 @@ void WriteCrystallographic(std::ostream &pdbFile, const datablock &db)
r = db["cell"].find1(key("entry_id") == db.name()); 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) int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db)
...@@ -3301,18 +3302,18 @@ 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"]) 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 << 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 << 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", 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", 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; result += 3;
break; break;
} }
for (auto r : db["atom_sites"]) 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 << 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 << 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", 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", 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; result += 3;
break; break;
} }
...@@ -3322,9 +3323,9 @@ int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db) ...@@ -3322,9 +3323,9 @@ int WriteCoordinateTransformation(std::ostream &pdbFile, const datablock &db)
{ {
std::string given = r["code"] == "given" ? "1" : ""; 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 << 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 << 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", 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", 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; ++nr;
result += 3; result += 3;
...@@ -3374,7 +3375,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab ...@@ -3374,7 +3375,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
if (terminate) 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; ++serial;
terminatedChains.insert(chainID); terminatedChains.insert(chainID);
...@@ -3413,7 +3414,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab ...@@ -3413,7 +3414,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
if (charge != 0) if (charge != 0)
sCharge = std::to_string(charge) + (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; ++numCoord;
...@@ -3428,7 +3429,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab ...@@ -3428,7 +3429,7 @@ std::tuple<int, int> WriteCoordinatesForModel(std::ostream &pdbFile, const datab
tie(u11, u22, u33, u12, u13, u23) = 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]"); 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; ++serial;
...@@ -3480,7 +3481,7 @@ std::tuple<int, int> WriteCoordinate(std::ostream &pdbFile, const datablock &db) ...@@ -3480,7 +3481,7 @@ std::tuple<int, int> WriteCoordinate(std::ostream &pdbFile, const datablock &db)
for (int model_nr : models) for (int model_nr : models)
{ {
if (models.size() > 1) 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; std::set<std::string> TERminatedChains;
auto n = WriteCoordinatesForModel(pdbFile, db, last_resseq_for_chain_map, TERminatedChains, model_nr); 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 ...@@ -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) 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) ...@@ -3725,7 +3726,7 @@ void write(std::ostream &os, const datablock &db)
numXform = WriteCoordinateTransformation(os, db); numXform = WriteCoordinateTransformation(os, db);
std::tie(numCoord, numTer) = WriteCoordinate(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; << "END" << std::endl;
} }
......
...@@ -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