[svn] commit: r420 - in /branches/jinmei-dnsmessageapi/src/lib/dns/cpp: name.cc name.h name_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Dec 30 23:09:48 UTC 2009


Author: jinmei
Date: Wed Dec 30 23:09:48 2009
New Revision: 420

Log:
s/getLabels()/getLabelCount()/ as the former may be confusing while the
latter has clearer on what it does.
the corresponding private member variable was also renamed to be consistent.

Modified:
    branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc
    branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h
    branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.cc Wed Dec 30 23:09:48 2009
@@ -233,8 +233,8 @@
         }
     }
 
-    labels_ = offsets.size();
-    assert(labels_ > 0 && labels_ <= Name::MAX_LABELS);
+    labelcount_ = offsets.size();
+    assert(labelcount_ > 0 && labelcount_ <= Name::MAX_LABELS);
     ndata_.assign(ndata.data(), ndata.size());
     length_ = ndata_.size();
     offsets_.assign(offsets.begin(), offsets.end());
@@ -350,7 +350,7 @@
         dns_throw(IncompleteName, "incomplete wire-format name");
     }
 
-    labels_ = offsets.size();
+    labelcount_ = offsets.size();
     length_ = nused;
     offsets_.assign(offsets.begin(), offsets.end());
     buffer.setPosition(pos_begin + cused);
@@ -375,13 +375,13 @@
         //
         // Special handling for the root label.  We ignore omit_final_dot.
         //
-        assert(labels_ == 1 && ndata_[0] == '\0');
+        assert(labelcount_ == 1 && ndata_[0] == '\0');
         return (".");
     }
 
     std::string::const_iterator np = ndata_.begin();
     std::string::const_iterator np_end = ndata_.end();
-    unsigned int labels = labels_; // use for integrity check
+    unsigned int labels = labelcount_; // use for integrity check
     // init with an impossible value to catch error cases in the end:
     unsigned int count = MAX_LABELLEN + 1;
 
@@ -456,8 +456,8 @@
     // of the names.
 
     unsigned int nlabels = 0;
-    unsigned int l1 = labels_;
-    unsigned int l2 = other.labels_;
+    unsigned int l1 = labelcount_;
+    unsigned int l2 = other.labelcount_;
     int ldiff = (int)l1 - (int)l2;
     unsigned int l = (ldiff < 0) ? l1 : l2;
 
@@ -511,11 +511,11 @@
 bool
 Name::equals(const Name& other) const
 {
-    if (length_ != other.length_ || labels_ != other.labels_) {
+    if (length_ != other.length_ || labelcount_ != other.labelcount_) {
         return (false);
     }
 
-    for (unsigned int l = labels_, pos = 0; l > 0; --l) {
+    for (unsigned int l = labelcount_, pos = 0; l > 0; --l) {
         unsigned char count = ndata_[pos];
         if (count != other.ndata_[pos]) {
             return (false);
@@ -583,7 +583,7 @@
 Name::concatenate(const Name& suffix) const
 {
     assert(this->length_ > 0 && suffix.length_ > 0);
-    assert(this->labels_ > 0 && suffix.labels_ > 0);
+    assert(this->labelcount_ > 0 && suffix.labelcount_ > 0);
 
     unsigned int length = this->length_ + suffix.length_ - 1;
     if (length > Name::MAX_WIRE) {
@@ -603,16 +603,16 @@
     // excluding that for the trailing dot, and append the offsets of the
     // suffix name with the additional offset of the length of the prefix.
     //
-    unsigned int labels = this->labels_ + suffix.labels_ - 1;
+    unsigned int labels = this->labelcount_ + suffix.labelcount_ - 1;
     assert(labels <= Name::MAX_LABELS);
     retname.offsets_.reserve(labels);
     retname.offsets_.assign(&this->offsets_[0],
-                            &this->offsets_[0] + this->labels_ - 1);
+                            &this->offsets_[0] + this->labelcount_ - 1);
     transform(suffix.offsets_.begin(), suffix.offsets_.end(),
               back_inserter(retname.offsets_),
               bind2nd(OffsetAdjuster(), this->length_ - 1));
     assert(retname.offsets_.size() == labels);
-    retname.labels_ = labels;
+    retname.labelcount_ = labels;
 
     return (retname);
 }
@@ -620,14 +620,14 @@
 Name
 Name::split(unsigned int first, unsigned int n) const
 {
-    if (n == 0 || first + n > labels_) {
+    if (n == 0 || first + n > labelcount_) {
         dns_throw(OutOfRange, "Name::split: invalid split range");
     }
 
     Name retname;
     // If the specified range doesn't include the trailing dot, we need one
     // more label for that.
-    unsigned int newlabels = (first + n == labels_) ? n : n + 1;
+    unsigned int newlabels = (first + n == labelcount_) ? n : n + 1;
 
     //
     // Set up offsets: copy the corresponding range of the original offsets
@@ -649,8 +649,8 @@
     retname.ndata_.push_back(0);
 
     retname.length_ = retname.ndata_.size();
-    retname.labels_ = retname.offsets_.size();
-    assert(retname.labels_ == newlabels);
+    retname.labelcount_ = retname.offsets_.size();
+    assert(retname.labelcount_ == newlabels);
 
     return (retname);
 }
@@ -659,7 +659,7 @@
 Name::downcase()
 {
     unsigned int nlen = length_;
-    unsigned int labels = labels_;
+    unsigned int labels = labelcount_;
     unsigned int pos = 0;
 
     while (labels > 0 && nlen > 0) {

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name.h Wed Dec 30 23:09:48 2009
@@ -223,7 +223,7 @@
     /// the moment defined as private because it will construct an incomplete
     /// object in that it doesn't have any labels.  We may reconsider this
     /// design choice as we see more applications of the class.
-    Name() : length_(0), labels_(0) {}
+    Name() : length_(0), labelcount_(0) {}
 public:
     /// Constructor from a string
     ///
@@ -264,7 +264,8 @@
     ///
     /// This method never throws an exception.
     ///
-    /// \return the length of the <code>Name</code>
+    /// \return the length (the number of octets in wire format) of the
+    /// <code>Name</code>
     size_t getLength() const { return (length_); }
 
     /// \brief Returns the number of labels contained in the <code>Name</code>.
@@ -275,7 +276,7 @@
     /// This method never throws an exception.
     ///
     /// \return the number of labels
-    unsigned int getLabels() const { return (labels_); }
+    unsigned int getLabelCount() const { return (labelcount_); }
     //@}
 
     ///
@@ -545,7 +546,7 @@
     std::string ndata_;
     std::vector<unsigned char> offsets_;
     unsigned int length_;
-    unsigned int labels_;
+    unsigned int labelcount_;
 };
 
 ///

Modified: branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc
==============================================================================
--- branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc (original)
+++ branches/jinmei-dnsmessageapi/src/lib/dns/cpp/name_unittest.cc Wed Dec 30 23:09:48 2009
@@ -203,7 +203,7 @@
                           "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9." // 200
                           "0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9." // 240
                           "0.1.2.3.4.5.6.");
-    EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabels());
+    EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabelCount());
 }
 
 TEST_F(NameTest, fromWire)
@@ -253,7 +253,8 @@
                  isc::dns::TooLongName);
 
     // A name with possible maximum number of labels; awkward but valid
-    EXPECT_EQ(nameFactoryFromWire("testdata/name_fromWire11", 0).getLabels(),
+    EXPECT_EQ(nameFactoryFromWire("testdata/name_fromWire11",
+                                  0).getLabelCount(),
               Name::MAX_LABELS);
 
     // Wire format including an invalid label length
@@ -264,7 +265,8 @@
     EXPECT_EQ("vix.com.", nameFactoryFromWire("testdata/name_fromWire1",
                                               25, true).toText());
     EXPECT_EQ(3,
-              nameFactoryFromWire("testdata/name_fromWire1", 25).getLabels());
+              nameFactoryFromWire("testdata/name_fromWire1",
+                                  25).getLabelCount());
 }
 
 TEST_F(NameTest, toText)




More information about the bind10-changes mailing list