From f3914d5dbebd8d242650162251244ef6234fe9a1 Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Tue, 14 Aug 2012 12:04:07 +0200 Subject: [PATCH] remove Push/PopFlag --- modules/conop/src/processor.hh | 83 +++++++------------- modules/conop/src/rule_based.cc | 2 +- modules/conop/src/rule_based.hh | 29 ++----- modules/conop/tests/test_rule_based_conop.cc | 18 +---- 4 files changed, 38 insertions(+), 94 deletions(-) diff --git a/modules/conop/src/processor.hh b/modules/conop/src/processor.hh index daba929a3..d8e3e6bf6 100644 --- a/modules/conop/src/processor.hh +++ b/modules/conop/src/processor.hh @@ -34,27 +34,13 @@ enum ConopAction { CONOP_FATAL }; -struct ProcessorOptions { - ProcessorOptions(): check_bond_feasibility(false), assign_torsions(false), - connect(true), unk_atom_treatment(CONOP_WARN), unk_res_treatment(CONOP_WARN), - zero_occ_treatment(CONOP_SILENT) - { } - bool check_bond_feasibility; - bool assign_torsions; - bool connect; - ConopAction unk_atom_treatment; - ConopAction unk_res_treatment; - ConopAction zero_occ_treatment; -}; - +class Processor; +typedef boost::shared_ptr<Processor> ProcessorPtr; // the base class for all options class DLLEXPORT_OST_CONOP Processor { public: DiagnosticsPtr Process(mol::EntityHandle ent) const; - - - virtual void PushFlags() = 0; - virtual void PopFlags() = 0; + virtual ProcessorPtr Copy() const = 0; protected: virtual void DoProcess(DiagnosticsPtr diags, mol::EntityHandle ent) const = 0; @@ -62,85 +48,70 @@ protected: mol::EntityHandle ent) const { return true; } virtual bool EndProcessing(DiagnosticsPtr diags, mol::EntityHandle ent) const { return true; } -}; - -// Provides accessor methods for the basic Processor options. All -// processors should derive from this class -template <typename O> -class ProcessorBase : public Processor { public: - typedef O option_type; - ProcessorBase(): option_stack_(1, O()) - {} - + Processor(): strict_hydrogens_(false), check_bond_feasibility_(false), + assign_torsions_(false), connect_(true), unk_atom_treatment_(CONOP_WARN), + unk_res_treatment_(CONOP_WARN), zero_occ_treatment_(CONOP_SILENT) {} void SetConnect(bool connect) { - this->GetOptions().connect = connect; + connect_ = connect; } bool GetConnect() const { - return this->GetOptions().connect; + return connect_; } void SetAssignTorsions(bool flag) { - this->GetOptions().assign_torsions = flag; + assign_torsions_ = flag; } bool GetAssignTorsions() const { - return this->GetOptions().assign_torsions; + return assign_torsions_; } ConopAction GetUnkResidueTreatment() const { - return this->GetOptions().unk_res_treatment; + return unk_res_treatment_; } ConopAction GetUnkAtomTreatment() const { - return this->GetOptions().unk_atom_treatment; + return unk_atom_treatment_; } bool GetCheckBondFeasibility() const { - return this->GetOptions().check_bond_feasibility; + return check_bond_feasibility_; } bool GetStrictHydrogens() const { - return this->GetOptions().strict_hydrogens; + return strict_hydrogens_; } void SetStrictHydrogens(bool flag) { - this->GetOptions().strict_hydrogens = flag; + strict_hydrogens_ = flag; } void SetCheckBondFeasibility(bool flag) { - this->GetOptions().check_bond_feasibility = flag; + check_bond_feasibility_ = flag; } void SetUnkResidueTreatment(ConopAction action) { - this->GetOptions().unk_res_treatment = action; + unk_res_treatment_ = action; } void SetUnkAtomTreatment(ConopAction action) { - this->GetOptions().unk_atom_treatment = action; + unk_atom_treatment_ = action; } ConopAction GetZeroOccTreatment() const { - return this->GetOptions().zero_occ_treatment; + return zero_occ_treatment_; } void SetZeroOccTreatment(ConopAction action) { - this->GetOptions().zero_occ_treatment = action; - } - - virtual void PushFlags() { - option_stack_.push_back(option_stack_.back()); + zero_occ_treatment_ = action; } - - virtual void PopFlags() { - if (option_stack_.size() == 1) { - throw std::runtime_error("Can't pop from stack with one item left"); - } - option_stack_.pop_back(); - } -protected: - const option_type& GetOptions() const { return option_stack_.back(); } - option_type& GetOptions() { return option_stack_.back(); } private: - std::vector<option_type> option_stack_; + bool strict_hydrogens_; + bool check_bond_feasibility_; + bool assign_torsions_; + bool connect_; + ConopAction unk_atom_treatment_; + ConopAction unk_res_treatment_; + ConopAction zero_occ_treatment_; }; diff --git a/modules/conop/src/rule_based.cc b/modules/conop/src/rule_based.cc index 3425fb076..224b11024 100644 --- a/modules/conop/src/rule_based.cc +++ b/modules/conop/src/rule_based.cc @@ -69,7 +69,7 @@ void RuleBasedProcessor::ProcessUnkAtoms(DiagnosticsPtr diags, return; } - assert(unks.empty() && "empty unk list"); + assert(!unks.empty() && "empty unk list"); mol::XCSEditor edi = unks.front().GetEntity().EditXCS(); for (mol::AtomHandleList::iterator i = unks.begin(), e = unks.end(); i != e; ++i) { diff --git a/modules/conop/src/rule_based.hh b/modules/conop/src/rule_based.hh index 62b2417f3..4ea5246a6 100644 --- a/modules/conop/src/rule_based.hh +++ b/modules/conop/src/rule_based.hh @@ -26,39 +26,25 @@ namespace ost { namespace conop { -struct RuleBasedProcessorOptions : ProcessorOptions { - RuleBasedProcessorOptions(): ProcessorOptions(), - strict_hydrogens(false), fix_element(true) - {} - bool strict_hydrogens; - bool fix_element; -}; - /// \brief returns all atoms not listed in the specifictaion of compound mol::AtomHandleList DLLEXPORT_OST_CONOP GetUnknownAtoms(mol::ResidueHandle res, CompoundPtr compound); -class DLLEXPORT_OST_CONOP RuleBasedProcessor : - public ProcessorBase<RuleBasedProcessorOptions> { +class DLLEXPORT_OST_CONOP RuleBasedProcessor : public Processor { public: RuleBasedProcessor(CompoundLibPtr compound_lib): - ProcessorBase<RuleBasedProcessorOptions>(), lib_(compound_lib) + lib_(compound_lib) { } - bool GetStrictHydrogens() const { - return this->GetOptions().strict_hydrogens; - } - - void SetStrictHydrogens(bool flag) { - this->GetOptions().strict_hydrogens = flag; - } - bool GetFixElement() const { - return this->GetOptions().fix_element; + return fix_element_; } void SetFixElement(bool flag) { - this->GetOptions().fix_element = flag; + fix_element_ = flag; + } + virtual ProcessorPtr Copy() const { + return ProcessorPtr(new RuleBasedProcessor(*this)); } protected: virtual void DoProcess(DiagnosticsPtr diags, @@ -76,6 +62,7 @@ private: bool IsBondFeasible(const mol::AtomHandle&, const mol::AtomHandle&) const; mol::AtomHandle LocateAtom(const mol::AtomHandleList&, int ordinal) const; CompoundLibPtr lib_; + bool fix_element_; }; diff --git a/modules/conop/tests/test_rule_based_conop.cc b/modules/conop/tests/test_rule_based_conop.cc index 7c0af2735..3d08c8061 100644 --- a/modules/conop/tests/test_rule_based_conop.cc +++ b/modules/conop/tests/test_rule_based_conop.cc @@ -61,32 +61,18 @@ BOOST_AUTO_TEST_CASE(rule_based_set_get_flags) BOOST_CHECK_EQUAL(rbc.GetUnkAtomTreatment(), CONOP_WARN); BOOST_CHECK_EQUAL(rbc.GetUnkResidueTreatment(), CONOP_WARN); BOOST_CHECK_EQUAL(rbc.GetStrictHydrogens(), false); - rbc.PushFlags(); rbc.SetConnect(false); + rbc.SetStrictHydrogens(true); rbc.SetCheckBondFeasibility(true); rbc.SetUnkResidueTreatment(CONOP_FATAL); rbc.SetUnkAtomTreatment(CONOP_REMOVE); BOOST_CHECK_EQUAL(rbc.GetConnect(), false); + BOOST_CHECK_EQUAL(rbc.GetStrictHydrogens(), true); BOOST_CHECK_EQUAL(rbc.GetCheckBondFeasibility(),true); BOOST_CHECK_EQUAL(rbc.GetUnkResidueTreatment(),CONOP_FATAL); BOOST_CHECK_EQUAL(rbc.GetUnkAtomTreatment(),CONOP_REMOVE); - rbc.PopFlags(); } -BOOST_AUTO_TEST_CASE(rule_based_push_pop_flags) -{ - CompoundLibPtr lib=load_lib(); - if (!lib) { return; } - RuleBasedProcessor rbc(lib); - BOOST_CHECK_THROW(rbc.PopFlags(), std::runtime_error); - rbc.PushFlags(); - rbc.PopFlags(); - rbc.PushFlags(); - rbc.SetConnect(false); - BOOST_CHECK(!rbc.GetConnect()); - rbc.PopFlags(); - BOOST_CHECK(rbc.GetConnect()); -} BOOST_AUTO_TEST_CASE(rule_based_connect) { -- GitLab