LCOV - code coverage report
Current view: top level - dns - rrsetlist.h (source / functions) Hit Total Coverage
Test: report.info Lines: 10 10 100.0 %
Date: 2012-05-15 Functions: 2 3 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 24 25.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __RRSETLIST_H
      16                 :            : #define __RRSETLIST_H 1
      17                 :            : 
      18                 :            : #include <iostream>
      19                 :            : #include <iterator>
      20                 :            : #include <vector>
      21                 :            : 
      22                 :            : #include <boost/shared_ptr.hpp>
      23                 :            : 
      24                 :            : #include <dns/rrset.h>
      25                 :            : #include <dns/rrclass.h>
      26                 :            : #include <dns/rrtype.h>
      27                 :            : 
      28                 :            : namespace isc {
      29                 :            : namespace dns {
      30                 :            : 
      31                 :          2 : class DuplicateRRset : public Exception {
      32                 :            : public:
      33                 :            :     DuplicateRRset(const char* file, size_t line, const char* what) :
      34                 :          2 :         isc::Exception(file, line, what) {}
      35                 :            : };
      36                 :            : 
      37                 :            : template <typename T, typename P, typename R>
      38                 :            : class RRsetListIterator :
      39                 :            :         public std::iterator<std::input_iterator_tag, RRsetPtr> {
      40                 :            : public:
      41                 :            :     RRsetListIterator() {}
      42                 :            :     explicit RRsetListIterator(const T& it) :
      43                 :            :         it_(it) {}
      44                 :            :     RRsetListIterator& operator++()
      45                 :            :     {
      46                 :        268 :         ++it_;
      47                 :            :         return (*this);
      48                 :            :     }
      49                 :            :     RRsetListIterator operator++(int)
      50                 :            :     {
      51                 :            :         RRsetListIterator tmp(*this);
      52                 :            :         ++it_;
      53                 :            :         return (tmp);
      54                 :            :     }
      55                 :            :     R operator*() const
      56                 :            :     {
      57                 :        611 :         return (*it_);
      58                 :            :     }
      59                 :            :     P operator->() const
      60                 :            :     {
      61                 :            :         return (&(operator*()));
      62                 :            :     }
      63                 :            :     bool operator==(const RRsetListIterator& other)
      64                 :            :     {
      65                 :        367 :         return (it_ == other.it_);
      66                 :            :     }
      67                 :            :     bool operator!=(const RRsetListIterator& other)
      68                 :            :     {
      69                 :        329 :         return (it_ != other.it_);
      70                 :            :     }
      71                 :            :     
      72                 :            : private:
      73                 :            :     T it_;
      74                 :            : };
      75                 :            : 
      76                 :            : /// A set of RRsets.
      77                 :            : ///
      78                 :            : /// \note Do not use this class unless you really understand what
      79                 :            : /// you're doing and you're 100% sure that this class is the best choice
      80                 :            : /// for your purpose.
      81                 :            : ///
      82                 :            : /// Counter intuitively, this class is not a "list" of RRsets but a
      83                 :            : /// "set" of them; it doesn't allow multiple RRsets of the same RR
      84                 :            : /// type and RR class to be added at the same time.  And, for that
      85                 :            : /// reason, adding an RRset is more expensive than you'd expect.  The
      86                 :            : /// class name is confusing, but was named so as a result of
      87                 :            : /// compromise: "RRsetset" would look awkward; RRsets would be
      88                 :            : /// confusing (with RRset).
      89                 :            : ///
      90                 :            : /// In any case, if you want a list like container of RRsets, your best choice
      91                 :            : /// would be \c std::vector<RRset> or \c std::list<RRset>, not this class.
      92                 :            : /// In fact, in many cases \c RRsetList will be a suboptimal choice.
      93                 :            : /// This class is defined publicly as part of libdns++ for a historical
      94                 :            : /// reason and is actually quite specific to a particular need for libdatasrc.
      95                 :            : /// If you are tempted to use it, think twice to assess if this class
      96                 :            : /// is really what you want.  Again, in many cases the answer will be no.
      97 [ +  - ][ +  - ]:        703 : class RRsetList {
         [ #  # ][ +  - ]
         [ +  - ][ #  # ]
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
      98                 :            : private:
      99                 :            :     RRsetList(const RRsetList& source);
     100                 :            :     RRsetList& operator=(const RRsetList& source);
     101                 :            : public:
     102                 :        700 :     RRsetList() {}
     103                 :            :     void addRRset(RRsetPtr new_rrsetptr);
     104                 :            :     void append(RRsetList& source);
     105                 :            :     RRsetPtr findRRset(const RRType& rrtype, const RRClass& rrclass);
     106                 :            : 
     107                 :            :     typedef RRsetListIterator<std::vector<RRsetPtr>::iterator,
     108                 :            :                               RRsetPtr*,
     109                 :            :                               RRsetPtr&> iterator;
     110                 :            :     typedef RRsetListIterator<std::vector<RRsetPtr>::const_iterator,
     111                 :            :                               const RRsetPtr*,
     112                 :            :                               const RRsetPtr&> const_iterator;
     113                 :            : 
     114                 :            :     const_iterator begin() const { return (const_iterator(rrsets_.begin())); }
     115                 :            :     const_iterator end() const { return (const_iterator(rrsets_.end())); }
     116                 :            : 
     117                 :        323 :     iterator begin() { return (iterator(rrsets_.begin())); }
     118                 :       1036 :     iterator end() { return (iterator(rrsets_.end())); }
     119                 :            : 
     120                 :            :     size_t size() const { return (rrsets_.size()); }
     121                 :            : 
     122                 :            : private:
     123                 :            :     std::vector<RRsetPtr> rrsets_;
     124                 :            : };
     125                 :            : 
     126                 :            : } // end of namespace dns
     127                 :            : } // end of namespace isc
     128                 :            : #endif  // __RRSETLIST_H
     129                 :            : 
     130                 :            : // Local Variables: 
     131                 :            : // mode: c++
     132                 :            : // End: 

Generated by: LCOV version 1.9