Commit 9c4170d9 by Maarten L. Hekkelman

- Added more const members

- change PDB writing interface
parent 4a82a8d5
......@@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.16)
# set the project name
project(cifpp VERSION 4.0.0 LANGUAGES CXX)
project(cifpp VERSION 4.0.1 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......
Version 4.0.1
- Added a bunch of const methods to Datablock and Category.
- Changed PDB writing interface to accept Datablock instead of File.
Version 4.0.0
- getResidue in mmcif::Structure now requires both a
sequence ID and an auth sequence ID. As a result the code was cleaned
......
......@@ -254,8 +254,15 @@ class Datablock
const_iterator begin() const { return mCategories.begin(); }
const_iterator end() const { return mCategories.end(); }
/// \brief Access to the category with name \a name, will create it if it doesn't exist.
Category &operator[](std::string_view name);
// /// \brief Access to the category with name \a name, will throw if it doesn't exist.
// const Category &operator[](std::string_view name) const;
/// \brief Access to the category with name \a name, will return an empty category if is doesn't exist.
const Category &operator[](std::string_view name) const;
std::tuple<iterator, bool> emplace(std::string_view name);
bool isValid();
......@@ -285,6 +292,9 @@ class Datablock
std::string mName;
const Validator *mValidator;
Datablock *mNext;
// for returning empty categories in the const operator[]
mutable std::unique_ptr<Category> mNullCategory;
};
// --------------------------------------------------------------------
......@@ -1863,6 +1873,9 @@ class Category
Row front() { return Row(mHead); }
Row back() { return Row(mTail); }
const Row front() const { return Row(mHead); }
const Row back() const { return Row(mTail); }
Row operator[](Condition &&cond);
const Row operator[](Condition &&cond) const;
......
......@@ -28,12 +28,12 @@
#include "cif++/Cif++.hpp"
void WritePDBFile(std::ostream& pdbFile, cif::File& cifFile);
void WritePDBFile(std::ostream &os, const cif::Datablock &data);
/// \brief Just the HEADER, COMPND, SOURCE and AUTHOR lines
void WritePDBHeaderLines(std::ostream& os, cif::File& cifFile);
void WritePDBHeaderLines(std::ostream &os, const cif::Datablock &data);
std::string GetPDBHEADERLine(cif::File& cifFile, std::string::size_type truncate_at = 127);
std::string GetPDBCOMPNDLine(cif::File& cifFile, std::string::size_type truncate_at = 127);
std::string GetPDBSOURCELine(cif::File& cifFile, std::string::size_type truncate_at = 127);
std::string GetPDBAUTHORLine(cif::File& cifFile, std::string::size_type truncate_at = 127);
std::string GetPDBHEADERLine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBCOMPNDLine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBSOURCELine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBAUTHORLine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
......@@ -409,6 +409,22 @@ Category &Datablock::operator[](std::string_view name)
return *i;
}
const Category &Datablock::operator[](std::string_view name) const
{
using namespace std::literals;
auto result = get(name);
if (result == nullptr)
// throw std::out_of_range("The category with name " + std::string(name) + " does not exist");
{
std::unique_lock lock(mLock);
if (not mNullCategory)
mNullCategory.reset(new Category(const_cast<Datablock&>(*this), "<null>", nullptr));
result = mNullCategory.get();
}
return *result;
}
Category *Datablock::get(std::string_view name)
{
std::shared_lock lock(mLock);
......@@ -1525,6 +1541,11 @@ void Category::drop(const std::string &field)
}
}
const Row Category::operator[](Condition &&cond) const
{
return const_cast<Category*>(this)->operator[](std::forward<Condition>(cond));
}
Row Category::operator[](Condition &&cond)
{
Row result;
......
......@@ -1380,7 +1380,7 @@ void File::save(const std::filesystem::path &path)
out.push(outFile);
if (file.extension() == ".pdb")
WritePDBFile(out, *this);
WritePDBFile(out, data());
else
cif::File::save(out);
}
......
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