cfg_to_element.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef CFG_TO_ELEMENT_H
  7. #define CFG_TO_ELEMENT_H
  8. #include <exceptions/exceptions.h>
  9. #include <cc/data.h>
  10. namespace isc {
  11. /// @brief Cannot unparse error
  12. ///
  13. /// This exception is expected to be thrown when toElement fails
  14. /// and to skip flawed elements is not wanted.
  15. class ToElementError : public isc::Exception {
  16. public:
  17. ToElementError(const char* file, size_t line, const char* what) :
  18. isc::Exception(file, line, what) { };
  19. };
  20. namespace data {
  21. /// @brief Abstract class for configuration Cfg_* classes
  22. ///
  23. struct CfgToElement {
  24. /// Destructor
  25. virtual ~CfgToElement() { }
  26. /// @brief Unparse a configuration object
  27. ///
  28. /// Returns an element which must parse into the same object, i.e.
  29. /// @code
  30. /// for all valid config C parse(parse(C)->toElement()) == parse(C)
  31. /// @endcode
  32. ///
  33. /// @return a pointer to a configuration which can be parsed into
  34. /// the initial configuration object
  35. virtual isc::data::ElementPtr toElement() const = 0;
  36. };
  37. }; // namespace isc::dhcp
  38. }; // namespace isc
  39. #endif // CFG_TO_ELEMENT_H