diff options
Diffstat (limited to 'src/broker.cc')
-rw-r--r-- | src/broker.cc | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/src/broker.cc b/src/broker.cc index 4cb7787..507c8c4 100644 --- a/src/broker.cc +++ b/src/broker.cc @@ -1,9 +1,10 @@ -/** --------------------------------------------------------------------- +/** * @file broker.cc * @brief Implementation of the Broker class * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "broker.h" #include "convert.h" @@ -14,10 +15,9 @@ #include <map> #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- BrokerFactory::BrokerFactory(void) { brokers[Session::NONAUTHENTICATED] = new Broker(); @@ -25,86 +25,74 @@ BrokerFactory::BrokerFactory(void) brokers[Session::SELECTED] = new Broker(); } -//---------------------------------------------------------------------- BrokerFactory::~BrokerFactory(void) { - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) - delete i->second; + for (auto &[_, second] : brokers) + delete second; } -//---------------------------------------------------------------------- BrokerFactory &BrokerFactory::getInstance(void) { static BrokerFactory brokerfactory; return brokerfactory; } -//---------------------------------------------------------------------- void BrokerFactory::addCapability(const std::string &c) { - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) { - CapabilityOperator *o; - o = dynamic_cast<CapabilityOperator *>(i->second->get("CAPABILITY")); - if (o != 0) { + for (const auto &[_, second] : brokers) { + auto o = dynamic_cast<CapabilityOperator *>(second->get("CAPABILITY")); + if (o != nullptr) { o->addCapability(c); break; } } } -//---------------------------------------------------------------------- void BrokerFactory::assign(const string &fname, Operator *o) { int deletable = true; - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) - if (i->first & o->getState()) { - i->second->assign(fname, o, deletable); + for (const auto &[first, second] : brokers) { + if (first & o->getState()) { + second->assign(fname, o, deletable); deletable = false; } + } } -//---------------------------------------------------------------------- Operator *BrokerFactory::getOperator(int state, const string &name) const { if (brokers.find(state) == brokers.end()) - return 0; + return nullptr; else return brokers.find(state)->second->get(name); } -//---------------------------------------------------------------------- Broker *BrokerFactory::getBroker(int state) { if (brokers.find(state) == brokers.end()) { setLastError("No appropriate broker for state."); - return 0; + return nullptr; } return brokers[state]; } -//---------------------------------------------------------------------- Broker::Broker(void) {} -//---------------------------------------------------------------------- Broker::~Broker(void) {} -//---------------------------------------------------------------------- void Broker::assign(const string &fname, Operator *o, bool deletable) { deletables[fname] = deletable; operators[fname] = o; } -//---------------------------------------------------------------------- Operator *Broker::get(const string &name) const { - if (operators.find(name) == operators.end()) return 0; - + if (operators.find(name) == operators.end()) return nullptr; return operators.find(name)->second; } -//---------------------------------------------------------------------- Operator::ParseResult Broker::parseStub(Request &command) { Session &session = Session::getInstance(); @@ -117,6 +105,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; first token must be a tag"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -128,6 +117,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; second token must be a SPACE"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -139,6 +129,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; third token must be a command"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -154,8 +145,8 @@ Operator::ParseResult Broker::parseStub(Request &command) case Operator::ACCEPT: break; case Operator::REJECT: - session.setLastError("Syntax error; after UID there" - " must come a SPACE"); + session.setLastError("Syntax error; after UID there must come a SPACE"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -166,8 +157,8 @@ Operator::ParseResult Broker::parseStub(Request &command) case Operator::ACCEPT: break; case Operator::REJECT: - session.setLastError("Syntax error; after UID " - "SPACE there must come a command"); + session.setLastError("Syntax error; after UID SPACE there must come a command"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: |