Browse Source

[2155] inline methods in a canonical way

Yoshitaka Aharen 12 years ago
parent
commit
124780d941
3 changed files with 129 additions and 192 deletions
  1. 58 88
      src/bin/auth/statistics.h
  2. 21 31
      src/lib/statistics/counter.h
  3. 50 73
      src/lib/statistics/counter_dict.h

+ 58 - 88
src/bin/auth/statistics.h

@@ -62,120 +62,90 @@ 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),
+    zone_origin_(),
+    answer_sent_(false),
+    res_is_truncated_(false)
+    {};
+
     /// 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);
+                            const bool is_badsig)
+    {
+        req_is_tsig_ = is_tsig;
+        req_is_sig0_ = is_sig0;
+        req_is_badsig_ = is_badsig;
+    };
     /// \brief Set zone origin.
     /// \throw None
-    inline void setOrigin(const std::string& origin);
-    /// \brief Set if the answer has sent.
+    inline void setOrigin(const std::string& origin) {
+        zone_origin_ = origin;
+    };
+    /// \brief Set if the answer was sent.
     /// \throw None
-    inline void answerWasSent();
+    inline void answerWasSent() {
+        answer_sent_ = true;
+    };
     /// \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;
+        zone_origin_.clear();
+        answer_sent_ = 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),
-    zone_origin_(),
-    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::answerWasSent() {
-    answer_sent_ = true;
-}
-
-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;
-    zone_origin_.clear();
-    answer_sent_ = false;
-    res_is_truncated_ = false;
-}
-
 /// \brief Set of query counters.
 ///
 /// \c Counters is set of query counters class. It holds query counters

+ 21 - 31
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
 

+ 50 - 73
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