lexer_util.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2013 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. #ifndef DNS_RDATA_LEXER_UTIL_H
  15. #define DNS_RDATA_LEXER_UTIL_H 1
  16. #include <dns/name.h>
  17. #include <dns/master_lexer.h>
  18. /// \file lexer_util.h
  19. /// \brief Utilities for extracting RDATA fields from lexer.
  20. ///
  21. /// This file intends to define convenient small routines that can be
  22. /// commonly used in the RDATA implementation to build RDATA fields from
  23. /// a \c MasterLexer.
  24. namespace isc {
  25. namespace dns {
  26. namespace rdata {
  27. namespace generic {
  28. namespace detail {
  29. /// \brief Construct a Name object using a master lexer and optional origin.
  30. ///
  31. /// This is a convenient shortcut of commonly used code pattern that would
  32. /// be used to build RDATA that contain a domain name field.
  33. ///
  34. /// Note that this function throws an exception against invalid input.
  35. /// The (direct or indirect) caller's responsibility needs to expect and
  36. /// handle exceptions appropriately.
  37. ///
  38. /// \throw MasterLexer::LexerError The next token from lexer is not string.
  39. /// \throw Other Exceptions from the \c Name class constructor if the next
  40. /// string token from the lexer does not represent a valid name.
  41. ///
  42. /// \param lexer A \c MasterLexer object. Its next token is expected to be
  43. /// a string that represent a domain name.
  44. /// \param origin If non NULL, specifies the origin of the name to be
  45. /// constructed.
  46. ///
  47. /// \return A new Name object that corresponds to the next string token of
  48. /// the \c lexer.
  49. inline Name
  50. createNameFromLexer(MasterLexer& lexer, const Name* origin) {
  51. const MasterToken::StringRegion& str_region =
  52. lexer.getNextToken(MasterToken::STRING).getStringRegion();
  53. return (Name(str_region.beg, str_region.len, origin));
  54. }
  55. } // namespace detail
  56. } // namespace generic
  57. } // namespace rdata
  58. } // namespace dns
  59. } // namespace isc
  60. #endif // DNS_RDATA_LEXER_UTIL_H
  61. // Local Variables:
  62. // mode: c++
  63. // End: