From: Yoshitaka Aharen Date: Wed, 10 Oct 2012 10:32:37 +0000 (+0900) Subject: [2155] inline methods in a canonical way X-Git-Tag: bind10-1.1.0beta1-release~85^2~5^2~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b92e04d29ae21a217b8ce01fe3487ccd4ca180b;p=thirdparty%2Fkea.git [2155] inline methods in a canonical way Conflicts: src/bin/auth/statistics.h --- diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h index 03e5cb0152..1cda1760cb 100644 --- a/src/bin/auth/statistics.h +++ b/src/bin/auth/statistics.h @@ -54,7 +54,6 @@ private: bool req_is_sig0_; // signed with valid SIG(0) bool req_is_badsig_; // signed but bad signature // response attributes - bool answer_sent_; // DNS message has sent bool res_is_truncated_; // DNS message is truncated public: /// \brief The constructor. @@ -62,120 +61,76 @@ public: /// This constructor is mostly exception free. But it may still throw /// a standard exception if memory allocation fails inside the method. /// - inline QRAttributes(); + inline QRAttributes() : + req_ip_version_(0), req_transport_protocol_(0), + req_opcode_(0), + req_is_edns_0_(false), req_is_edns_badver_(false), + req_is_dnssec_ok_(false), + req_is_tsig_(false), req_is_sig0_(false), req_is_badsig_(false), + res_is_truncated_(false) + {}; /// \brief The destructor. /// /// This method never throws an exception. /// - inline ~QRAttributes(); - + inline ~QRAttributes() {}; /// \brief Set query opcode. /// \throw None - inline void setQueryOpCode(const int opcode); - + inline void setQueryOpCode(const int opcode) { + req_opcode_ = opcode; + }; /// \brief Set IP version carrying a query. /// \throw None - inline void setQueryIPVersion(const int ip_version); - + inline void setQueryIPVersion(const int ip_version) { + req_ip_version_ = ip_version; + }; /// \brief Set transport protocol carrying a query. /// \throw None - inline void setQueryTransportProtocol(const int transport_protocol); - + inline void setQueryTransportProtocol(const int transport_protocol) { + req_transport_protocol_ = transport_protocol; + }; /// \brief Set query EDNS attributes. /// \throw None - inline void setQueryEDNS(const bool is_edns_0, const bool is_edns_badver); - + inline void setQueryEDNS(const bool is_edns_0, const bool is_edns_badver) { + req_is_edns_0_ = is_edns_0; + req_is_edns_badver_ = is_edns_badver; + }; /// \brief Set query DO bit. /// \throw None - inline void setQueryDO(const bool is_dnssec_ok); - + inline void setQueryDO(const bool is_dnssec_ok) { + req_is_dnssec_ok_ = is_dnssec_ok; + }; /// \brief Set query TSIG attributes. /// \throw None inline void setQuerySig(const bool is_tsig, const bool is_sig0, - const bool is_badsig); - - /// \brief Set zone origin. - /// \throw None - inline void setOrigin(const std::string& origin); - + const bool is_badsig) + { + req_is_tsig_ = is_tsig; + req_is_sig0_ = is_sig0; + req_is_badsig_ = is_badsig; + }; /// \brief Set if the response is truncated. /// \throw None - inline void setResponseTruncated(const bool is_truncated); - + inline void setResponseTruncated(const bool is_truncated) { + res_is_truncated_ = is_truncated; + }; /// \brief Reset attributes. /// \throw None - inline void reset(); + inline void reset() { + req_ip_version_ = 0; + req_transport_protocol_ = 0; + req_opcode_ = 0; + req_is_edns_0_ = false; + req_is_edns_badver_ = false; + req_is_dnssec_ok_ = false; + req_is_tsig_ = false; + req_is_sig0_ = false; + req_is_badsig_ = false; + res_is_truncated_ = false; + }; }; -inline QRAttributes::QRAttributes() : - req_ip_version_(0), req_transport_protocol_(0), - req_opcode_(0), - req_is_edns_0_(false), req_is_edns_badver_(false), - req_is_dnssec_ok_(false), - req_is_tsig_(false), req_is_sig0_(false), req_is_badsig_(false), - answer_sent_(false), - res_is_truncated_(false) -{} - -inline QRAttributes::~QRAttributes() -{} - -inline void -QRAttributes::setQueryIPVersion(const int ip_version) { - req_ip_version_ = ip_version; -} - -inline void -QRAttributes::setQueryTransportProtocol(const int transport_protocol) { - req_transport_protocol_ = transport_protocol; -} - -inline void -QRAttributes::setQueryOpCode(const int opcode) { - req_opcode_ = opcode; -} - -inline void -QRAttributes::setQueryEDNS(const bool is_edns_0, const bool is_edns_badver) { - req_is_edns_0_ = is_edns_0; - req_is_edns_badver_ = is_edns_badver; -} - -inline void -QRAttributes::setQueryDO(const bool is_dnssec_ok) { - req_is_dnssec_ok_ = is_dnssec_ok; -} - -inline void -QRAttributes::setQuerySig(const bool is_tsig, const bool is_sig0, - const bool is_badsig) -{ - req_is_tsig_ = is_tsig; - req_is_sig0_ = is_sig0; - req_is_badsig_ = is_badsig; -} - -inline void -QRAttributes::setResponseTruncated(const bool is_truncated) { - res_is_truncated_ = is_truncated; -} - -inline void -QRAttributes::reset() { - req_ip_version_ = 0; - req_transport_protocol_ = 0; - req_opcode_ = 0; - req_is_edns_0_ = false; - req_is_edns_badver_ = false; - req_is_dnssec_ok_ = false; - req_is_tsig_ = false; - req_is_sig0_ = false; - req_is_badsig_ = false; - answer_sent_ = false; - res_is_truncated_ = false; -} - /// \brief Set of query counters. /// /// \c Counters is set of query counters class. It holds query counters diff --git a/src/lib/statistics/counter.h b/src/lib/statistics/counter.h index ed5c276060..af9a5f7937 100644 --- a/src/lib/statistics/counter.h +++ b/src/lib/statistics/counter.h @@ -46,55 +46,45 @@ public: /// \param items A number of counter items to hold (greater than 0) /// /// \throw isc::InvalidParameter \a items is 0 - explicit inline Counter(const size_t items); + explicit inline Counter(const size_t items) : + counters_(items, InitialValue) + { + if (items == 0) { + isc_throw(isc::InvalidParameter, "Items must not be 0"); + } + }; /// The destructor. /// /// This method never throws an exception. - inline ~Counter(); + inline ~Counter() {}; /// \brief Increment a counter item specified with \a type. /// /// \param type %Counter item to increment /// /// \throw isc::OutOfRange \a type is invalid - inline void inc(const Counter::Type); + inline void inc(const Counter::Type type) { + if (type >= counters_.size()) { + isc_throw(isc::OutOfRange, "Counter type is out of range"); + } + ++counters_.at(type); + return; + }; /// \brief Get the value of a counter item specified with \a type. /// /// \param type %Counter item to get the value of /// /// \throw isc::OutOfRange \a type is invalid - inline const Counter::Value& get(const Counter::Type) const; + inline const Counter::Value& get(const Counter::Type type) const { + if (type >= counters_.size()) { + isc_throw(isc::OutOfRange, "Counter type is out of range"); + } + return (counters_.at(type)); + }; }; -inline Counter::Counter(const size_t items) : - counters_(items, InitialValue) -{ - if (items == 0) { - isc_throw(isc::InvalidParameter, "Items must not be 0"); - } -} - -inline Counter::~Counter() {} - -inline void -Counter::inc(const Counter::Type type) { - if(type >= counters_.size()) { - isc_throw(isc::OutOfRange, "Counter type is out of range"); - } - ++counters_.at(type); - return; -} - -inline const Counter::Value& -Counter::get(const Counter::Type type) const { - if(type >= counters_.size()) { - isc_throw(isc::OutOfRange, "Counter type is out of range"); - } - return (counters_.at(type)); -} - } // namespace statistics } // namespace isc diff --git a/src/lib/statistics/counter_dict.h b/src/lib/statistics/counter_dict.h index 0d8b0f07d1..6861abf3db 100644 --- a/src/lib/statistics/counter_dict.h +++ b/src/lib/statistics/counter_dict.h @@ -48,12 +48,50 @@ private: // specified at the construction of this class. CounterDictionary(); public: - explicit inline CounterDictionary(const size_t items); - inline ~CounterDictionary(); - inline void addElement(const std::string& name); - inline void deleteElement(const std::string& name); - inline Counter& getElement(const std::string& name); - inline Counter& operator[](const std::string& name); + explicit inline CounterDictionary(const size_t items) : + items_(items) + { + // The number of items must not be 0 + if (items == 0) { + isc_throw(isc::InvalidParameter, "Items must not be 0"); + } + }; + inline ~CounterDictionary() {}; + inline void addElement(const std::string& name) { + // throw if the element already exists + if (dictionary_.count(name) != 0) { + isc_throw(isc::InvalidParameter, + "Element " << name << " already exists"); + } + assert(items_ != 0); + // Create a new Counter and add to the map + dictionary_.insert( + DictionaryMap::value_type(name, CounterPtr(new Counter(items_)))); + }; + inline void deleteElement(const std::string& name) { + size_t result = dictionary_.erase(name); + if (result != 1) { + // If an element with specified name does not exist, throw + // isc::OutOfRange. + isc_throw(isc::OutOfRange, + "Element " << name << " does not exist"); + } + }; + inline Counter& getElement(const std::string& name) { + DictionaryMap::const_iterator i = dictionary_.find(name); + if (i != dictionary_.end()) { + // the key was found. return the element. + return (*(i->second)); + } else { + // If an element with specified name does not exist, throw + // isc::OutOfRange. + isc_throw(isc::OutOfRange, + "Element " << name << " does not exist"); + } + }; + inline Counter& operator[](const std::string& name) { + return (getElement(name)); + }; /// \brief \c ConstIterator is a constant iterator that provides an /// interface for enumerating name of zones stored in CounterDictionary. /// @@ -107,77 +145,16 @@ public: DictionaryMap::const_iterator iterator_; }; - inline ConstIterator begin() const; - inline ConstIterator end() const; + inline ConstIterator begin() const { + return (CounterDictionary::ConstIterator(dictionary_.begin())); + }; + inline ConstIterator end() const { + return (CounterDictionary::ConstIterator(dictionary_.end())); + }; typedef ConstIterator const_iterator; }; - -inline CounterDictionary::ConstIterator -CounterDictionary::begin() const { - return (CounterDictionary::ConstIterator(dictionary_.begin())); -} - -inline CounterDictionary::ConstIterator -CounterDictionary::end() const { - return (CounterDictionary::ConstIterator(dictionary_.end())); -} - -// Constructor with number of items -inline CounterDictionary::CounterDictionary(const size_t items) : - items_(items) -{ - // The number of items must not be 0 - if (items == 0) { - isc_throw(isc::InvalidParameter, "Items must not be 0"); - } -} - -// Destructor -inline CounterDictionary::~CounterDictionary() {} - -inline void -CounterDictionary::addElement(const std::string& name) { - // throw if the element already exists - if (dictionary_.count(name) != 0) { - isc_throw(isc::InvalidParameter, - "Element " << name << " already exists"); - } - assert(items_ != 0); - // Create a new Counter and add to the map - dictionary_.insert( - DictionaryMap::value_type(name, CounterPtr(new Counter(items_)))); -} - -inline void -CounterDictionary::deleteElement(const std::string& name) { - size_t result = dictionary_.erase(name); - if (result != 1) { - // If an element with specified name does not exist, throw - // isc::OutOfRange. - isc_throw(isc::OutOfRange, "Element " << name << " does not exist"); - } -} - -inline Counter& -CounterDictionary::getElement(const std::string& name) { - DictionaryMap::const_iterator i = dictionary_.find(name); - if (i != dictionary_.end()) { - // the key was found. return the element. - return (*(i->second)); - } else { - // If an element with specified name does not exist, throw - // isc::OutOfRange. - isc_throw(isc::OutOfRange, "Element " << name << " does not exist"); - } -} - -inline Counter& -CounterDictionary::operator[](const std::string& name) { - return (getElement(name)); -} - } // namespace statistics } // namespace isc