LCOV - code coverage report
Current view: top level - dns - rrclass.h (source / functions) Hit Total Coverage
Test: report.info Lines: 22 22 100.0 %
Date: 2012-05-15 Functions: 6 8 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 30 70.0 %

           Branch data     Line data    Source code
       1                 :            : ///////////////
       2                 :            : ///////////////
       3                 :            : ///////////////   THIS FILE IS AUTOMATICALLY GENERATED BY gen-rdatacode.py.
       4                 :            : ///////////////   DO NOT EDIT!
       5                 :            : ///////////////
       6                 :            : ///////////////
       7                 :            : 
       8                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       9                 :            : //
      10                 :            : // Permission to use, copy, modify, and/or distribute this software for any
      11                 :            : // purpose with or without fee is hereby granted, provided that the above
      12                 :            : // copyright notice and this permission notice appear in all copies.
      13                 :            : //
      14                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
      15                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
      16                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      17                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      18                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      19                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      20                 :            : // PERFORMANCE OF THIS SOFTWARE.
      21                 :            : 
      22                 :            : #ifndef __RRCLASS_H
      23                 :            : #define __RRCLASS_H 1
      24                 :            : 
      25                 :            : #include <stdint.h>
      26                 :            : 
      27                 :            : #include <string>
      28                 :            : #include <ostream>
      29                 :            : 
      30                 :            : #include <exceptions/exceptions.h>
      31                 :            : 
      32                 :            : namespace isc {
      33                 :            : namespace util {
      34                 :            : class InputBuffer;
      35                 :            : class OutputBuffer;
      36                 :            : }
      37                 :            : 
      38                 :            : namespace dns {
      39                 :            : 
      40                 :            : // forward declarations
      41                 :            : class AbstractMessageRenderer;
      42                 :            : 
      43                 :            : ///
      44                 :            : /// \brief A standard DNS module exception that is thrown if an RRClass object
      45                 :            : /// is being constructed from an unrecognized string.
      46                 :            : ///
      47                 :         19 : class InvalidRRClass : public Exception {
      48                 :            : public:
      49                 :            :     InvalidRRClass(const char* file, size_t line, const char* what) :
      50         [ +  - ]:         19 :         isc::Exception(file, line, what) {}
      51                 :            : };
      52                 :            : 
      53                 :            : ///
      54                 :            : /// \brief A standard DNS module exception that is thrown if an RRClass object
      55                 :            : /// is being constructed from a incomplete (too short) wire-format data.
      56                 :            : ///
      57                 :          3 : class IncompleteRRClass : public Exception {
      58                 :            : public:
      59                 :            :     IncompleteRRClass(const char* file, size_t line, const char* what) :
      60                 :          6 :         isc::Exception(file, line, what) {}
      61                 :            : };
      62                 :            : 
      63                 :            : ///
      64                 :            : /// The \c RRClass class encapsulates DNS resource record classes.
      65                 :            : ///
      66                 :            : /// This class manages the 16-bit integer class codes in quite a straightforward
      67                 :            : /// way.  The only non trivial task is to handle textual representations of
      68                 :            : /// RR classes, such as "IN", "CH", or "CLASS65534".
      69                 :            : ///
      70                 :            : /// This class consults a helper \c RRParamRegistry class, which is a registry
      71                 :            : /// of RR related parameters and has the singleton object.  This registry
      72                 :            : /// provides a mapping between RR class codes and their "well-known" textual
      73                 :            : /// representations.
      74                 :            : /// Parameters of RR classes defined by DNS protocol standards are automatically
      75                 :            : /// registered at initialization time and are ensured to be always available for
      76                 :            : /// applications unless the application explicitly modifies the registry.
      77                 :            : ///
      78                 :            : /// For convenience, this class defines constant class objects corresponding to
      79                 :            : /// standard RR classes.  These are generally referred to as the form of
      80                 :            : /// <code>RRClass::{class-text}()</code>.
      81                 :            : /// For example, \c RRClass::IN() is an \c RRClass object corresponding to the
      82                 :            : /// IN class (class code 1).
      83                 :            : /// Note that these constants are used through a "proxy" function.
      84                 :            : /// This is because they may be used to initialize another non-local (e.g.
      85                 :            : /// global or namespace-scope) static object as follows:
      86                 :            : ///
      87                 :            : /// \code
      88                 :            : /// namespace foo {
      89                 :            : /// const RRClass default_class = RRClass::IN();
      90                 :            : /// } \endcode
      91                 :            : ///
      92                 :            : /// In order to ensure that the constant RRClass object has been initialized
      93                 :            : /// before the initialization for \c default_class, we need help from
      94                 :            : /// the proxy function.
      95                 :            : ///
      96                 :            : /// Note to developers: same note as \c RRType applies.
      97                 :            : class RRClass {
      98                 :            : public:
      99                 :            :     ///
     100                 :            :     /// \name Constructors and Destructor
     101                 :            :     ///
     102                 :            :     //@{
     103                 :            :     /// Constructor from an integer class code.
     104                 :            :     ///
     105                 :            :     /// This constructor never throws an exception.
     106                 :            :     ///
     107                 :            :     /// \param classcode An 16-bit integer code corresponding to the RRClass.
     108                 :       2909 :     explicit RRClass(uint16_t classcode) : classcode_(classcode) {}
     109                 :            :     ///
     110                 :            :     /// A valid string is one of "well-known" textual class representations
     111                 :            :     /// such as "IN" or "CH", or in the standard format for "unknown"
     112                 :            :     /// classes as defined in RFC3597, i.e., "CLASSnnnn".
     113                 :            :     ///
     114                 :            :     /// More precisely, the "well-known" representations are the ones stored
     115                 :            :     /// in the \c RRParamRegistry registry (see the class description).
     116                 :            :     ///
     117                 :            :     /// As for the format of "CLASSnnnn", "nnnn" must represent a valid 16-bit
     118                 :            :     /// unsigned integer, which may contain leading 0's as long as it consists
     119                 :            :     /// of at most 5 characters (inclusive).
     120                 :            :     /// For example, "CLASS1" and "CLASSS001" are valid and represent the same
     121                 :            :     /// class, but "CLASS65536" and "CLASS000001" are invalid.
     122                 :            :     /// A "CLASSnnnn" representation is valid even if the corresponding class
     123                 :            :     /// code is registered in the \c RRParamRegistry object.  For example, both
     124                 :            :     /// "IN" and "CLASS1" are valid and represent the same class.
     125                 :            :     ///
     126                 :            :     /// All of these representations are case insensitive; "IN" and "in", and
     127                 :            :     /// "CLASS1" and "class1" are all valid and represent the same classes,
     128                 :            :     /// respectively.
     129                 :            :     ///
     130                 :            :     /// If the given string is not recognized as a valid representation of
     131                 :            :     /// an RR class, an exception of class \c InvalidRRClass will be thrown.
     132                 :            :     ///
     133                 :            :     /// \param classstr A string representation of the \c RRClass
     134                 :            :     explicit RRClass(const std::string& classstr);
     135                 :            :     /// Constructor from wire-format data.
     136                 :            :     ///
     137                 :            :     /// The \c buffer parameter normally stores a complete DNS message
     138                 :            :     /// containing the RRClass to be constructed.  The current read position of
     139                 :            :     /// the buffer points to the head of the class.
     140                 :            :     ///
     141                 :            :     /// If the given data does not large enough to contain a 16-bit integer,
     142                 :            :     /// an exception of class \c IncompleteRRClass will be thrown.
     143                 :            :     ///
     144                 :            :     /// \param buffer A buffer storing the wire format data.
     145                 :            :     explicit RRClass(isc::util::InputBuffer& buffer);
     146                 :            :     ///
     147                 :            :     /// We use the default copy constructor intentionally.
     148                 :            :     //@}
     149                 :            :     /// We use the default copy assignment operator intentionally.
     150                 :            :     ///
     151                 :            : 
     152                 :            :     ///
     153                 :            :     /// \name Converter methods
     154                 :            :     ///
     155                 :            :     //@{
     156                 :            :     /// \brief Convert the \c RRClass to a string.
     157                 :            :     ///
     158                 :            :     /// If a "well known" textual representation for the class code is
     159                 :            :     /// registered in the RR parameter registry (see the class description),
     160                 :            :     /// that will be used as the return value of this method.  Otherwise, this
     161                 :            :     /// method creates a new string for an "unknown" class in the format defined
     162                 :            :     /// in RFC3597, i.e., "CLASSnnnn", and returns it.
     163                 :            :     ///
     164                 :            :     /// If resource allocation for the string fails, a corresponding standard
     165                 :            :     /// exception will be thrown.
     166                 :            :     ///
     167                 :            :     /// \return A string representation of the \c RRClass.
     168                 :            :     const std::string toText() const;
     169                 :            :     /// \brief Render the \c RRClass in the wire format.
     170                 :            :     ///
     171                 :            :     /// This method renders the class code in network byte order via
     172                 :            :     /// \c renderer, which encapsulates output buffer and other rendering
     173                 :            :     /// contexts.
     174                 :            :     ///
     175                 :            :     /// If resource allocation in rendering process fails, a corresponding
     176                 :            :     /// standard exception will be thrown.
     177                 :            :     ///
     178                 :            :     /// \param buffer An output buffer to store the wire data.
     179                 :            :     void toWire(AbstractMessageRenderer& renderer) const;
     180                 :            :     /// \brief Render the \c RRClass in the wire format.
     181                 :            :     ///
     182                 :            :     /// This method renders the class code in network byte order into the
     183                 :            :     /// \c buffer.
     184                 :            :     ///
     185                 :            :     /// If resource allocation in rendering process fails, a corresponding
     186                 :            :     /// standard exception will be thrown.
     187                 :            :     ///
     188                 :            :     /// \param renderer DNS message rendering context that encapsulates the
     189                 :            :     /// output buffer in which the RRClass is to be stored.
     190                 :            :     void toWire(isc::util::OutputBuffer& buffer) const;
     191                 :            :     //@}
     192                 :            : 
     193                 :            :     ///
     194                 :            :     /// \name Getter Methods
     195                 :            :     ///
     196                 :            :     //@{
     197                 :            :     /// \brief Returns the RR class code as a 16-bit unsigned integer.
     198                 :            :     ///
     199                 :            :     /// This method never throws an exception.
     200                 :            :     ///
     201                 :            :     /// \return An 16-bit integer code corresponding to the RRClass.
     202                 :       3323 :     uint16_t getCode() const { return (classcode_); }
     203                 :            :     //@}
     204                 :            : 
     205                 :            :     ///
     206                 :            :     /// \name Comparison methods
     207                 :            :     ///
     208                 :            :     //@{
     209                 :            :     /// \brief Return true iff two RRClasses are equal.
     210                 :            :     ///
     211                 :            :     /// Two RRClasses are equal iff their class codes are equal.
     212                 :            :     ///
     213                 :            :     /// This method never throws an exception.
     214                 :            :     ///
     215                 :            :     /// \param other the \c RRClass object to compare against.
     216                 :            :     /// \return true if the two RRClasses are equal; otherwise false.
     217                 :            :     bool equals(const RRClass& other) const
     218                 :      10966 :     { return (classcode_ == other.classcode_); }
     219                 :            :     /// \brief Same as \c equals().
     220                 :            :     bool operator==(const RRClass& other) const { return (equals(other)); }
     221                 :            : 
     222                 :            :     /// \brief Return true iff two RRClasses are not equal.
     223                 :            :     ///
     224                 :            :     /// This method never throws an exception.
     225                 :            :     ///
     226                 :            :     /// \param other the \c RRClass object to compare against.
     227                 :            :     /// \return true if the two RRClasses are not equal; otherwise false.
     228                 :            :     bool nequals(const RRClass& other) const
     229                 :      15761 :     { return (classcode_ != other.classcode_); }
     230                 :            :     /// \brief Same as \c nequals().
     231                 :            :     bool operator!=(const RRClass& other) const { return (nequals(other)); } 
     232                 :            : 
     233                 :            :     /// \brief Less-than comparison for RRClass against \c other
     234                 :            :     ///
     235                 :            :     /// We define the less-than relationship based on their class codes;
     236                 :            :     /// one RRClass is less than the other iff the code of the former is less
     237                 :            :     /// than that of the other as unsigned integers.
     238                 :            :     /// The relationship is meaningless in terms of DNS protocol; the only
     239                 :            :     /// reason we define this method is that RRClass objects can be stored in
     240                 :            :     /// STL containers without requiring user-defined less-than relationship.
     241                 :            :     /// We therefore don't define other comparison operators.
     242                 :            :     ///
     243                 :            :     /// This method never throws an exception.
     244                 :            :     ///
     245                 :            :     /// \param other the \c RRClass object to compare against.
     246                 :            :     /// \return true if \c this RRClass is less than the \c other; otherwise
     247                 :            :     /// false.
     248                 :            :     bool operator<(const RRClass& other) const
     249                 :      67769 :     { return (classcode_ < other.classcode_); }
     250                 :            : 
     251                 :            :     // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS
     252                 :            :     static const RRClass& IN();
     253                 :            :     static const RRClass& CH();
     254                 :            :     static const RRClass& HS();
     255                 :            :     static const RRClass& ANY();
     256                 :            :     // END_WELL_KNOWN_CLASS_DECLARATIONS
     257                 :            :     
     258                 :            :     static const RRClass& NONE();
     259                 :            : 
     260                 :            : private:
     261                 :            :     // \brief Meta-classes
     262                 :            :     enum {
     263                 :            :         RRCLASS_RESERVED0 = 0,
     264                 :            :         RRCLASS_NONE = 254
     265                 :            :     };
     266                 :            :     uint16_t classcode_;
     267                 :            : };
     268                 :            : 
     269                 :            : // BEGIN_WELL_KNOWN_CLASS_DEFINITIONS
     270                 :            : 
     271                 :            : inline const RRClass&
     272                 :       4956 : RRClass::IN() {
     273 [ +  + ][ +  - ]:      12940 :     static RRClass rrclass(1);
         [ +  + ][ +  - ]
     274                 :       4956 :     return (rrclass);
     275                 :            : }
     276                 :            : 
     277                 :            : inline const RRClass&
     278                 :       1263 : RRClass::CH() {
     279 [ +  + ][ +  - ]:       1403 :     static RRClass rrclass(3);
         [ +  + ][ +  - ]
     280                 :       1263 :     return (rrclass);
     281                 :            : }
     282                 :            : 
     283                 :            : inline const RRClass&
     284                 :          5 : RRClass::HS() {
     285 [ +  + ][ +  - ]:         20 :     static RRClass rrclass(4);
     286                 :          5 :     return (rrclass);
     287                 :            : }
     288                 :            : 
     289                 :            : inline const RRClass&
     290                 :       1176 : RRClass::ANY() {
     291 [ +  + ][ +  - ]:       2160 :     static RRClass rrclass(255);
     292                 :       1176 :     return (rrclass);
     293                 :            : }
     294                 :            : 
     295                 :            : // END_WELL_KNOWN_CLASS_DEFINITIONS
     296                 :            : 
     297                 :            : inline const RRClass&
     298                 :            : RRClass::NONE() {
     299 [ +  - ][ +  - ]:          1 :     static RRClass rrclass(RRCLASS_NONE);
     300                 :            : 
     301                 :            :     return (rrclass);
     302                 :            : }
     303                 :            : 
     304                 :            : ///
     305                 :            : /// \brief Insert the \c RRClass as a string into stream.
     306                 :            : ///
     307                 :            : /// This method convert the \c rrclass into a string and inserts it into the
     308                 :            : /// output stream \c os.
     309                 :            : ///
     310                 :            : /// This function overloads the global operator<< to behave as described in
     311                 :            : /// ostream::operator<< but applied to \c RRClass objects.
     312                 :            : ///
     313                 :            : /// \param os A \c std::ostream object on which the insertion operation is
     314                 :            : /// performed.
     315                 :            : /// \param rrclass The \c RRClass object output by the operation.
     316                 :            : /// \return A reference to the same \c std::ostream object referenced by
     317                 :            : /// parameter \c os after the insertion operation.
     318                 :            : std::ostream&
     319                 :            : operator<<(std::ostream& os, const RRClass& rrclass);
     320                 :            : }
     321                 :            : }
     322                 :            : #endif  // __RRCLASS_H
     323                 :            : 
     324                 :            : // Local Variables: 
     325                 :            : // mode: c++
     326                 :            : // End: 

Generated by: LCOV version 1.9