Commit a12acaa5 by Maarten L. Hekkelman

moving from namespace cif::v2 to cif

parent ff62efe7
#include <iostream>
#include <filesystem>
#include <cif++/Cif++.hpp>
#include <cif++/cif.hpp>
namespace fs = std::filesystem;
int main()
{
fs::path in("1cbs.cif.gz");
cif::File file;
file.loadDictionary("mmcif_pdbx_v50");
cif::file file;
file.load_dictionary("mmcif_pdbx_v50");
file.load("1cbs.cif.gz");
auto& db = file.firstDatablock()["atom_site"];
auto n = db.find(cif::Key("label_atom_id") == "OXT").size();
auto& db = file.front();
auto &atom_site = db["atom_site"];
auto n = atom_site.find(cif::key("label_atom_id") == "OXT").size();
std::cout << "File contains " << db.size() << " atoms of which " << n << (n == 1 ? " is" : " are") << " OXT" << std::endl
std::cout << "File contains " << atom_site.size() << " atoms of which " << n << (n == 1 ? " is" : " are") << " OXT" << std::endl
<< "residues with an OXT are:" << std::endl;
for (const auto& [asym, comp, seqnr]: db.find<std::string,std::string,int>(
cif::Key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id"))
for (const auto& [asym, comp, seqnr]: atom_site.find<std::string,std::string,int>(
cif::key("label_atom_id") == "OXT", "label_asym_id", "label_comp_id", "label_seq_id"))
{
std::cout << asym << ' ' << comp << ' ' << seqnr << std::endl;
}
......
......@@ -38,7 +38,7 @@
// https://en.cppreference.com/w/cpp/named_req/SequenceContainer
// and more?
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -660,4 +660,4 @@ class category
row *m_head = nullptr, *m_tail = nullptr;
};
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -33,7 +33,7 @@
#include <cif++/cif/row.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -612,4 +612,4 @@ namespace literals
}
} // namespace literals
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -30,7 +30,7 @@
#include <cif++/cif/category.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -86,4 +86,4 @@ class datablock : public std::list<category>
const validator *m_validator = nullptr;
};
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -28,9 +28,9 @@
#include <cif++/cif/validate.hpp>
namespace cif::v2
namespace cif
{
validator parse_dictionary(std::string_view name, std::istream &is);
} // namespace cif::v2
} // namespace cif
......@@ -29,7 +29,7 @@
#include <cif++/cif/datablock.hpp>
#include <cif++/cif/parser.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -83,4 +83,4 @@ class file : public std::list<datablock>
const validator *m_validator = nullptr;
};
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -29,7 +29,7 @@
#include <string>
#include <vector>
namespace cif::v2
namespace cif
{
class category;
......@@ -43,4 +43,4 @@ class row_handle;
class item;
class item_handle;
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -38,7 +38,7 @@
#include <cif++/cif/forward_decl.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -458,4 +458,4 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_same_v<T, std::str
}
};
} // namespace cif::v2
} // namespace cif
......@@ -28,7 +28,7 @@
#include <cif++/cif/row.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -466,4 +466,4 @@ void conditional_iterator_proxy<Category, Ts...>::swap(conditional_iterator_prox
std::swap(mCix, rhs.mCix);
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -28,7 +28,7 @@
#include <memory>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -76,4 +76,4 @@ class list
};
} // namespace cif::v2
} // namespace cif
......@@ -28,7 +28,7 @@
#include <cif++/cif/row.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -284,4 +284,4 @@ class parser : public sac_parser
row_handle m_row;
};
} // namespace cif::v2
} // namespace cif
......@@ -28,7 +28,7 @@
#include <cif++/cif/item.hpp>
namespace cif::v2
namespace cif
{
namespace detail
......@@ -266,4 +266,4 @@ class row_initializer
std::vector<item> m_items;
};
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -35,11 +35,10 @@
#include <cif++/utilities.hpp>
namespace cif::v2
namespace cif
{
struct category_validator;
class validator_factory;
// --------------------------------------------------------------------
......@@ -68,7 +67,7 @@ struct type_validator
{
std::string m_name;
DDL_PrimitiveType m_primitive_type;
// std::regex mRx;
// std::regex m_rx;
boost::regex m_rx;
bool operator<(const type_validator &rhs) const
......@@ -218,4 +217,4 @@ class validator_factory
std::list<validator> m_validators;
};
} // namespace cif::v2
} // namespace cif
......@@ -130,8 +130,8 @@ class Compound
friend class CCDCompoundFactoryImpl;
friend class CCP4CompoundFactoryImpl;
Compound(cif::v2::datablock &db);
Compound(cif::v2::datablock &db, const std::string &id, const std::string &name, const std::string &type, const std::string &group);
Compound(cif::datablock &db);
Compound(cif::datablock &db, const std::string &id, const std::string &name, const std::string &type, const std::string &group);
std::string mID;
std::string mName;
......
......@@ -63,7 +63,7 @@ class Atom
private:
struct AtomImpl : public std::enable_shared_from_this<AtomImpl>
{
AtomImpl(cif::v2::datablock &db, const std::string &id, cif::v2::row_handle row);
AtomImpl(cif::datablock &db, const std::string &id, cif::row_handle row);
// constructor for a symmetry copy of an atom
AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op);
......@@ -85,7 +85,7 @@ class Atom
const std::string get_property(const std::string_view name) const;
void set_property(const std::string_view name, const std::string &value);
const cif::v2::datablock &mDb;
const cif::datablock &mDb;
std::string mID;
AtomType mType;
......@@ -98,7 +98,7 @@ class Atom
Point mLocation;
int mRefcount;
cif::v2::row_handle mRow;
cif::row_handle mRow;
// mutable std::vector<std::tuple<std::string, cif::detail::ItemReference>> mCachedRefs;
......@@ -123,7 +123,7 @@ class Atom
{
}
Atom(cif::v2::datablock &db, cif::v2::row_handle &row);
Atom(cif::datablock &db, cif::row_handle &row);
// a special constructor to create symmetry copies
Atom(const Atom &rhs, const Point &symmmetry_location, const std::string &symmetry_operation);
......@@ -180,8 +180,8 @@ class Atom
void translateRotateAndTranslate(Point t1, Quaternion q, Point t2);
// for direct access to underlying data, be careful!
const cif::v2::row_handle getRow() const { return impl().mRow; }
const cif::v2::row_handle getRowAniso() const;
const cif::row_handle getRow() const { return impl().mRow; }
const cif::row_handle getRowAniso() const;
bool isSymmetryCopy() const { return impl().mSymmetryCopy; }
std::string symmetry() const { return impl().mSymmetryOperator; }
......@@ -513,7 +513,7 @@ class Polymer : public std::vector<Monomer>
Structure *mStructure;
std::string mEntityID;
std::string mAsymID;
// cif::v2::row_handleSet mPolySeq;
// cif::row_handleSet mPolySeq;
};
// --------------------------------------------------------------------
......@@ -578,7 +578,7 @@ class Branch : public std::vector<Sugar>
// file is a reference to the data stored in e.g. the cif file.
// This object is not copyable.
class File : public cif::v2::file
class File : public cif::file
{
public:
File() {}
......@@ -599,10 +599,10 @@ class File : public cif::v2::file
// void load(const std::filesystem::path &p) override;
// void save(const std::filesystem::path &p) override;
// using cif::v2::file::load;
// using cif::v2::file::save;
// using cif::file::load;
// using cif::file::save;
cif::v2::datablock &data() { return front(); }
cif::datablock &data() { return front(); }
};
// --------------------------------------------------------------------
......@@ -622,12 +622,12 @@ inline bool operator&(StructureOpenOptions a, StructureOpenOptions b)
class Structure
{
public:
Structure(cif::v2::file &p, size_t modelNr = 1, StructureOpenOptions options = {})
Structure(cif::file &p, size_t modelNr = 1, StructureOpenOptions options = {})
: Structure(p.front(), modelNr, options)
{
}
Structure(cif::v2::datablock &db, size_t modelNr = 1, StructureOpenOptions options = {});
Structure(cif::datablock &db, size_t modelNr = 1, StructureOpenOptions options = {});
Structure(Structure &&s) = default;
......@@ -756,12 +756,12 @@ class Structure
/// This method creates new atom records filled with info from the info.
///
/// \param entity_id The entity ID of the new nonpoly
/// \param atoms The array of sets of cif::v2::item data containing the data for the atoms.
/// \param atoms The array of sets of cif::item data containing the data for the atoms.
/// \return The newly create asym ID
std::string createNonpoly(const std::string &entity_id, std::vector<std::vector<cif::v2::item>> &atom_info);
std::string createNonpoly(const std::string &entity_id, std::vector<std::vector<cif::item>> &atom_info);
/// \brief Create a new (sugar) branch with one first NAG containing atoms constructed from \a nag_atom_info
Branch &createBranch(std::vector<std::vector<cif::v2::item>> &nag_atom_info);
Branch &createBranch(std::vector<std::vector<cif::item>> &nag_atom_info);
/// \brief Extend an existing (sugar) branch identified by \a asymID with one sugar containing atoms constructed from \a atom_info
///
......@@ -769,7 +769,7 @@ class Structure
/// \param atom_info Array containing the info for the atoms to construct for the new sugar
/// \param link_sugar The sugar to link to, note: this is the sugar number (1 based)
/// \param link_atom The atom id of the atom linked in the sugar
Branch &extendBranch(const std::string &asym_id, std::vector<std::vector<cif::v2::item>> &atom_info,
Branch &extendBranch(const std::string &asym_id, std::vector<std::vector<cif::item>> &atom_info,
int link_sugar, const std::string &link_atom);
/// \brief Remove \a branch
......@@ -797,12 +797,12 @@ class Structure
void cleanupEmptyCategories();
/// \brief Direct access to underlying data
cif::v2::category &category(std::string_view name) const
cif::category &category(std::string_view name) const
{
return mDb[name];
}
cif::v2::datablock &datablock() const
cif::datablock &datablock() const
{
return mDb;
}
......@@ -832,7 +832,7 @@ class Structure
void removeAtom(Atom &a, bool removeFromResidue);
void removeSugar(Sugar &sugar);
cif::v2::datablock &mDb;
cif::datablock &mDb;
size_t mModelNr;
AtomView mAtoms;
std::vector<size_t> mAtomIndex;
......
......@@ -34,7 +34,7 @@
// is inconsistent. It all depends whether a link is satified if a field taking part in the
// set of linked items is null at one side and not null in the other.
namespace cif::v2
namespace cif
{
const uint32_t kMaxLineLength = 132;
......@@ -1119,7 +1119,7 @@ void category::erase_orphans(condition &&cond)
std::string category::get_unique_id(std::function<std::string(int)> generator)
{
using namespace cif::v2::literals;
using namespace cif::literals;
std::string id_tag = "id";
if (m_cat_validator != nullptr and m_cat_validator->m_keys.size() == 1)
......@@ -1875,4 +1875,4 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
os << "# " << '\n';
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -27,7 +27,7 @@
#include <cif++/cif/category.hpp>
#include <cif++/cif/condition.hpp>
namespace cif::v2
namespace cif
{
iset get_category_fields(const category &cat)
......@@ -58,4 +58,4 @@ bool is_column_type_uchar(const category &cat, std::string_view col)
return result;
}
} // namespace cif::v2
} // namespace cif
......@@ -26,7 +26,7 @@
#include <cif++/cif/datablock.hpp>
namespace cif::v2
namespace cif
{
void datablock::set_validator(const validator *v)
......
......@@ -29,7 +29,7 @@
#include <cif++/cif/file.hpp>
#include <cif++/cif/parser.hpp>
namespace cif::v2
namespace cif
{
using namespace literals;
......@@ -194,7 +194,7 @@ class dictionary_parser : public parser
if (isCategorySaveFrame)
{
std::string category;
cif::v2::tie(category) = dict["category"].front().get("id");
cif::tie(category) = dict["category"].front().get("id");
std::vector<std::string> keys;
for (auto k : dict["category_key"])
......@@ -210,7 +210,7 @@ class dictionary_parser : public parser
{
// if the type code is missing, this must be a pointer, just skip it
std::string typeCode;
cif::v2::tie(typeCode) = dict["item_type"].front().get("code");
cif::tie(typeCode) = dict["item_type"].front().get("code");
const type_validator *tv = nullptr;
if (not(typeCode.empty() or typeCode == "?"))
......@@ -221,7 +221,7 @@ class dictionary_parser : public parser
ess.insert(e["value"].as<std::string>());
std::string defaultValue;
cif::v2::tie(defaultValue) = dict["item_default"].front().get("value");
cif::tie(defaultValue) = dict["item_default"].front().get("value");
bool defaultIsNull = false;
if (defaultValue.empty())
{
......@@ -238,7 +238,7 @@ class dictionary_parser : public parser
{
std::string tagName, category, mandatory;
cif::v2::tie(tagName, category, mandatory) = i.get("name", "category_id", "mandatory_code");
cif::tie(tagName, category, mandatory) = i.get("name", "category_id", "mandatory_code");
std::string catName, item_name;
std::tie(catName, item_name) = splitTagName(tagName);
......@@ -297,7 +297,7 @@ class dictionary_parser : public parser
{
std::string childTagName, parentTagName;
cif::v2::tie(childTagName, parentTagName) = i.get("child_name", "parent_name");
cif::tie(childTagName, parentTagName) = i.get("child_name", "parent_name");
mLinkedItems.emplace(childTagName, parentTagName);
}
......@@ -347,7 +347,7 @@ class dictionary_parser : public parser
{
std::string child, parent;
int link_group_id;
cif::v2::tie(child, parent, link_group_id) = gl.get("child_name", "parent_name", "link_group_id");
cif::tie(child, parent, link_group_id) = gl.get("child_name", "parent_name", "link_group_id");
auto civ = m_validator.get_validator_for_item(child);
if (civ == nullptr)
......@@ -441,7 +441,7 @@ class dictionary_parser : public parser
for (auto t : dict["item_type_list"])
{
std::string code, primitiveCode, construct;
cif::v2::tie(code, primitiveCode, construct) = t.get("code", "primitive_code", "construct");
cif::tie(code, primitiveCode, construct) = t.get("code", "primitive_code", "construct");
replace_all(construct, "\\n", "\n");
replace_all(construct, "\\t", "\t");
......@@ -494,4 +494,4 @@ validator parse_dictionary(std::string_view name, std::istream &is)
return result;
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -28,7 +28,7 @@
#include <cif++/cif/file.hpp>
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -165,4 +165,4 @@ void file::save(std::ostream &os) const
db.write(os);
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -26,7 +26,7 @@
#include <cif++/cif/row.hpp>
namespace cif::v2
namespace cif
{
std::string_view item_handle::text() const
......
......@@ -41,7 +41,7 @@ namespace cif
extern int VERBOSE;
}
namespace cif::v2
namespace cif
{
// --------------------------------------------------------------------
......@@ -817,4 +817,4 @@ void parser::produce_item(const std::string &category, const std::string &item,
m_row[item] = m_token_value;
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -26,7 +26,7 @@
#include <cif++/cif/category.hpp>
namespace cif::v2
namespace cif
{
void row_handle::assign(size_t column, std::string_view value, bool updateLinked, bool validate)
......@@ -60,4 +60,4 @@ row_initializer::row_initializer(row_handle rh)
m_items.emplace_back(cat.get_column_name(i->m_column_ix), i->text());
}
} // namespace cif::v2
\ No newline at end of file
} // namespace cif
\ No newline at end of file
......@@ -40,7 +40,7 @@ namespace cif
extern int VERBOSE;
}
namespace cif::v2
namespace cif
{
using cif::VERBOSE;
......@@ -430,4 +430,4 @@ void validator_factory::construct_validator(std::string_view name, std::istream
parse_dictionary(name, is);
}
} // namespace cif::v2
} // namespace cif
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