Commit 3d79278e by Maarten L. Hekkelman

Merge branch 'trunk' into develop

parents 5e0b197a 9c4170d9
Version 4.1.0 Version 4.1.0
- Some interface changes for mmcif::Atom - Some interface changes for mmcif::Atom
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 Version 4.0.0
- getResidue in mmcif::Structure now requires both a - getResidue in mmcif::Structure now requires both a
sequence ID and an auth sequence ID. As a result the code was cleaned sequence ID and an auth sequence ID. As a result the code was cleaned
......
...@@ -254,8 +254,15 @@ class Datablock ...@@ -254,8 +254,15 @@ class Datablock
const_iterator begin() const { return mCategories.begin(); } const_iterator begin() const { return mCategories.begin(); }
const_iterator end() const { return mCategories.end(); } 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); 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); std::tuple<iterator, bool> emplace(std::string_view name);
bool isValid(); bool isValid();
...@@ -285,6 +292,9 @@ class Datablock ...@@ -285,6 +292,9 @@ class Datablock
std::string mName; std::string mName;
const Validator *mValidator; const Validator *mValidator;
Datablock *mNext; Datablock *mNext;
// for returning empty categories in the const operator[]
mutable std::unique_ptr<Category> mNullCategory;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -1863,6 +1873,9 @@ class Category ...@@ -1863,6 +1873,9 @@ class Category
Row front() { return Row(mHead); } Row front() { return Row(mHead); }
Row back() { return Row(mTail); } Row back() { return Row(mTail); }
const Row front() const { return Row(mHead); }
const Row back() const { return Row(mTail); }
Row operator[](Condition &&cond); Row operator[](Condition &&cond);
const Row operator[](Condition &&cond) const; const Row operator[](Condition &&cond) const;
......
/*- /*-
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
* *
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute * Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer * list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
#include "cif++/Cif++.hpp" #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 /// \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 GetPDBHEADERLine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBCOMPNDLine(cif::File& cifFile, std::string::size_type truncate_at = 127); std::string GetPDBCOMPNDLine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBSOURCELine(cif::File& cifFile, std::string::size_type truncate_at = 127); std::string GetPDBSOURCELine(const cif::Datablock &data, std::string::size_type truncate_at = 127);
std::string GetPDBAUTHORLine(cif::File& cifFile, 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) ...@@ -409,6 +409,22 @@ Category &Datablock::operator[](std::string_view name)
return *i; 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) Category *Datablock::get(std::string_view name)
{ {
std::shared_lock lock(mLock); std::shared_lock lock(mLock);
...@@ -1525,6 +1541,11 @@ void Category::drop(const std::string &field) ...@@ -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 Category::operator[](Condition &&cond)
{ {
Row result; Row result;
......
...@@ -1373,7 +1373,7 @@ void File::save(const std::filesystem::path &path) ...@@ -1373,7 +1373,7 @@ void File::save(const std::filesystem::path &path)
out.push(outFile); out.push(outFile);
if (file.extension() == ".pdb") if (file.extension() == ".pdb")
WritePDBFile(out, *this); WritePDBFile(out, data());
else else
cif::File::save(out); 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