LCOV - code coverage report
Current view: top level - nsas - hash_key.h (source / functions) Hit Total Coverage
Test: report.info Lines: 2 2 100.0 %
Date: 2012-05-15 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 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 __HASH_KEY_H
      16                 :            : #define __HASH_KEY_H
      17                 :            : 
      18                 :            : #include <dns/rrclass.h>
      19                 :            : 
      20                 :            : #include <stdint.h>
      21                 :            : #include <string>
      22                 :            : 
      23                 :            : namespace isc {
      24                 :            : namespace nsas {
      25                 :            : 
      26                 :            : /// \brief Hash Key
      27                 :            : ///
      28                 :            : /// In the nameserver address store, an object is placed into a hash table
      29                 :            : /// according to its key (name) and class.
      30                 :            : ///
      31                 :            : /// The key comprises two elements, a pointer to the start of a char string
      32                 :            : /// holding the data that describes the key and a length.  This has been
      33                 :            : /// chosen over a std::string because:
      34                 :            : ///
      35                 :            : /// # The key may not be a string, it may be binary data
      36                 :            : /// # The overhead of creating std::string objects from such data.
      37                 :            : ///
      38                 :            : /// "key" is declared as "const char*" - rather than the more semantically
      39                 :            : /// correct "const uint8_t*" - simply because if std::strings are used, then
      40                 :            : /// the c_str function will return a "const char*".
      41                 :            : ///
      42                 :            : /// To avoid passing round three elements (key, key length, and class), they
      43                 :            : /// have been combined into this simple struct.
      44                 :            : struct HashKey {
      45                 :            : 
      46                 :            :     /// \brief Constructor
      47                 :            :     ///
      48                 :            :     /// Basic constructor to make the hash key.
      49                 :            :     ///
      50                 :            :     /// \param the_key Array of bytes for which key is to be constructed
      51                 :            :     /// \param the_keylen Length of the byte array
      52                 :            :     /// \param the_class_code Class of this entry
      53                 :            :     HashKey(const char* the_key, uint32_t the_keylen,
      54                 :            :         const isc::dns::RRClass& the_class_code) :
      55                 :            :         key(the_key),
      56                 :            :         keylen(the_keylen),
      57                 :         69 :         class_code(the_class_code)
      58                 :            :     {}
      59                 :            : 
      60                 :            :     /// \brief String Constructor
      61                 :            :     ///
      62                 :            :     /// Convenience constructor using a std::string.
      63                 :            :     ///
      64                 :            :     /// \param the_key Name to use as the key for the hash
      65                 :            :     /// \param the_class_code Class of this entry
      66                 :            :     HashKey(const std::string& the_key,
      67                 :            :         const isc::dns::RRClass& the_class_code) :
      68                 :            :         key(the_key.c_str()),
      69                 :            :         keylen(the_key.size()),
      70                 :       9495 :         class_code(the_class_code)
      71                 :            :     {}
      72                 :            : 
      73                 :            :     /// \brief Equality
      74                 :            :     ///
      75                 :            :     /// Convenience for unit testing, this matches two hash keys as being
      76                 :            :     /// equal if the key strings match on a case-independent basis and the
      77                 :            :     /// classes match.
      78                 :            :     ///
      79                 :            :     /// Note that the class strings may include null bytes; the match is
      80                 :            :     /// done on a byte-by-byte basis, with codes in the range 'A' to 'Z' being
      81                 :            :     /// mapped to 'a' to 'z'.
      82                 :            :     ///
      83                 :            :     /// \param other Hash key to compare against.
      84                 :            :     ///
      85                 :            :     /// \return true if the two hash key objects are the same.
      86                 :            :     bool operator==(const isc::nsas::HashKey& other);
      87                 :            : 
      88                 :            :     const char* key;        ///< Pointer to the start of the key string
      89                 :            :     uint32_t    keylen;     ///< Length of the key string
      90                 :            :     isc::dns::RRClass class_code; ///< Class associated with the key
      91                 :            : };
      92                 :            : 
      93                 :            : } // namespace nsas
      94                 :            : } // namespace isc
      95                 :            : 
      96                 :            : #endif // __HASH_KEY_H

Generated by: LCOV version 1.9