Commit 851a43ba by Maarten L. Hekkelman

Alternative layering of compound factory object implementations

parent 47ae50f7
......@@ -1404,6 +1404,7 @@ class iterator_proxy
using row_iterator = iterator_impl<RowType>;
iterator_proxy(Category& cat, row_iterator pos, char const* const columns[N]);
iterator_proxy(Category& cat, row_iterator pos, std::initializer_list<char const*> columns);
iterator_proxy(iterator_proxy&& p);
iterator_proxy& operator=(iterator_proxy&& p);
......@@ -1767,6 +1768,13 @@ class Category
return iterator_proxy<Row, Ts...>(*this, begin(), columns );
}
template<typename... Ts, typename... Ns>
iterator_proxy<Row, Ts...> rows(Ns... names)
{
static_assert(sizeof...(Ts) == sizeof...(Ns), "The number of column titles should be equal to the number of types to return");
return iterator_proxy<Row, Ts...>(*this, begin(), { names... });
}
conditional_iterator_proxy<Row> find(Condition&& cond)
{
return find(cbegin(), std::forward<Condition>(cond));
......@@ -2126,6 +2134,19 @@ iterator_proxy<RowType, Ts...>::iterator_proxy(Category& cat, row_iterator pos,
mCix[i] = mCat->getColumnIndex(columns[i]);
}
template<typename RowType, typename... Ts>
iterator_proxy<RowType, Ts...>::iterator_proxy(Category& cat, row_iterator pos, std::initializer_list<char const*> columns)
: mCat(&cat)
, mCBegin(pos)
, mCEnd(cat.end())
{
// 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;
for (auto column: columns)
mCix[i++] = mCat->getColumnIndex(column);
}
// --------------------------------------------------------------------
template<typename RowType, typename... Ts>
......
......@@ -97,11 +97,6 @@ struct CompoundBond
class Compound
{
public:
/// \brief factory method, create a Compound based on the three letter code
/// (for amino acids) or the one-letter code (for bases) or the
/// code as it is known in the CCD.
static const Compound *create(const std::string &id);
// accessors
......@@ -131,6 +126,7 @@ class Compound
friend class CompoundFactoryImpl;
friend class CCDCompoundFactoryImpl;
friend class CCP4CompoundFactoryImpl;
Compound(cif::Datablock &db);
Compound(cif::Datablock &db, const std::string &id, const std::string &name, const std::string &type);
......@@ -153,6 +149,14 @@ extern const std::map<std::string, char> kAAMap, kBaseMap;
class CompoundFactory
{
public:
/// \brief Initialise a singleton instance.
///
/// If you have a multithreaded application and want to have different
/// compounds in each thread (e.g. a web service processing user requests
/// with different sets of compounds) you can set the \a useThreadLocalInstanceOnly
/// flag to true.
static void init(bool useThreadLocalInstanceOnly);
static CompoundFactory &instance();
static void clear();
......@@ -163,7 +167,12 @@ class CompoundFactory
bool isKnownPeptide(const std::string &res_name) const;
bool isKnownBase(const std::string &res_name) const;
const Compound *get(std::string id);
/// \brief Create the Compound object for \a id
///
/// This will create the Compound instance for \a id if it doesn't exist already.
/// The result is owned by this factory and should not be deleted by the user.
/// \param id The Compound ID, a three letter code usually
/// \result The compound, or nullptr if it could not be created (missing info)
const Compound *create(std::string id);
~CompoundFactory();
......
......@@ -328,7 +328,7 @@ bool CompoundBondMap::bonded(const std::string &compoundID, const std::string& a
}
// not found in our cache, calculate
auto compound = CompoundFactory::instance().create(compoundID);
auto compound = mmcif::CompoundFactory::instance().create(compoundID);
if (not compound)
throw BondMapException("Missing compound bond info for " + compoundID);
......@@ -621,7 +621,7 @@ std::vector<std::string> BondMap::atomIDsForCompound(const std::string& compound
{
std::vector<std::string> result;
auto* compound = mmcif::Compound::create(compoundID);
auto* compound = mmcif::CompoundFactory::instance().create(compoundID);
if (compound == nullptr)
throw BondMapException("Missing bond information for compound " + compoundID);
......
......@@ -2575,7 +2575,7 @@ void PDBFileParser::ParseRemarks()
int seq = vI(22, 25);
char iCode = vC(26);
auto compound = mmcif::Compound::create(res);
auto compound = mmcif::CompoundFactory::instance().create(res);
if (compound == nullptr)
continue;
......@@ -4037,7 +4037,7 @@ void PDBFileParser::ConstructEntities()
letter = '(' + res.mMonID + ')';
// sja...
auto compound = mmcif::Compound::create(stdRes.empty() ? res.mMonID : stdRes);
auto compound = mmcif::CompoundFactory::instance().create(stdRes.empty() ? res.mMonID : stdRes);
if (compound != nullptr and
not iequals(compound->type(), "L-peptide linking") and
not iequals(compound->type(), "RNA linking"))
......@@ -4193,7 +4193,7 @@ void PDBFileParser::ConstructEntities()
{
if (mHetnams[hetID].empty())
{
auto compound = mmcif::Compound::create(hetID);
auto compound = mmcif::CompoundFactory::instance().create(hetID);
if (compound != nullptr)
mHetnams[hetID] = compound->name();
}
......@@ -4330,7 +4330,7 @@ void PDBFileParser::ConstructEntities()
for (auto cc: mChemComp)
{
auto compound = mmcif::Compound::create(
auto compound = mmcif::CompoundFactory::instance().create(
mMod2parent.count(cc) ? mMod2parent[cc] : cc
);
......@@ -4872,7 +4872,7 @@ static bool IsMetal(const std::string& resName, const std::string& atomID)
try
{
auto compound = mmcif::Compound::create(resName);
auto compound = mmcif::CompoundFactory::instance().create(resName);
if (compound != nullptr)
{
auto at = mmcif::AtomTypeTraits(compound->getAtomByID(atomID).typeSymbol);
......
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