Browse Source

[master] Merged trac1205a (unparse design)

Francis Dupont 8 years ago
parent
commit
99705e8b96
4 changed files with 74 additions and 3 deletions
  1. 14 0
      configure.ac
  2. 2 2
      src/lib/cc/Makefile.am
  3. 48 0
      src/lib/cc/cfg_to_element.h
  4. 10 1
      src/lib/dhcpsrv/libdhcpsrv.dox

+ 14 - 0
configure.ac

@@ -187,6 +187,20 @@ for retry in "none" "--std=c++11" "--std=c++0x" "--std=c++1x" "fail"; do
 		[AC_MSG_RESULT([no])
 		[AC_MSG_RESULT([no])
 		 continue])
 		 continue])
 
 
+	AC_MSG_CHECKING(variadic template support)
+	feature="variadic template"
+	AC_COMPILE_IFELSE(
+		[AC_LANG_PROGRAM(
+			[template<typename ... Args>
+			 struct A {
+			 void foo(Args... myargs) { return; };
+			 };],
+			 [A<> a;
+			  a.foo();])],
+		[AC_MSG_RESULT([yes])],
+		[AC_MSG_RESULT([no])
+		 continue])
+
 	AC_MSG_CHECKING(lambda support)
 	AC_MSG_CHECKING(lambda support)
 	feature="lambda"
 	feature="lambda"
 	AC_COMPILE_IFELSE(
 	AC_COMPILE_IFELSE(

+ 2 - 2
src/lib/cc/Makefile.am

@@ -6,7 +6,7 @@ AM_CXXFLAGS = $(KEA_CXXFLAGS)
 
 
 lib_LTLIBRARIES = libkea-cc.la
 lib_LTLIBRARIES = libkea-cc.la
 libkea_cc_la_SOURCES = data.cc data.h
 libkea_cc_la_SOURCES = data.cc data.h
-libkea_cc_la_SOURCES += dhcp_config_error.h
+libkea_cc_la_SOURCES += cfg_to_element.h dhcp_config_error.h
 libkea_cc_la_SOURCES += command_interpreter.cc command_interpreter.h
 libkea_cc_la_SOURCES += command_interpreter.cc command_interpreter.h
 libkea_cc_la_SOURCES += simple_parser.cc simple_parser.h
 libkea_cc_la_SOURCES += simple_parser.cc simple_parser.h
 
 
@@ -18,7 +18,7 @@ libkea_cc_la_LDFLAGS = -no-undefined -version-info 1:0:0
 # Since data.h is now used in the hooks interface, it needs to be
 # Since data.h is now used in the hooks interface, it needs to be
 # installed on target system.
 # installed on target system.
 libkea_cc_includedir = $(pkgincludedir)/cc
 libkea_cc_includedir = $(pkgincludedir)/cc
-libkea_cc_include_HEADERS = data.h dhcp_config_error.h
+libkea_cc_include_HEADERS = cfg_to_element.h data.h dhcp_config_error.h
 
 
 EXTRA_DIST = cc.dox
 EXTRA_DIST = cc.dox
 
 

+ 48 - 0
src/lib/cc/cfg_to_element.h

@@ -0,0 +1,48 @@
+// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef CFG_TO_ELEMENT_H
+#define CFG_TO_ELEMENT_H
+
+#include <exceptions/exceptions.h>
+#include <cc/data.h>
+
+namespace isc {
+
+/// @brief Cannot unparse error
+///
+/// This exception is expected to be thrown when toElement fails
+/// and to skip flawed elements is not wanted.
+class ToElementError : public isc::Exception {
+public:
+    ToElementError(const char* file, size_t line, const char* what) :
+        isc::Exception(file, line, what) { };
+};
+
+namespace data {
+
+/// @brief Abstract class for configuration Cfg_* classes
+///
+struct CfgToElement {
+    /// Destructor
+    virtual ~CfgToElement() { }
+
+    /// @brief Unparse a configuration objet
+    ///
+    /// Returns an element which must parse into the same objet, i.e.
+    /// @code
+    /// for all valid config C parse(parse(C)->toElement()) == parse(C)
+    /// @endcode
+    ///
+    /// @return a pointer to a configuration which can be parsed into
+    /// the initial configuration object
+    virtual isc::data::ElementPtr toElement() const = 0;
+};
+
+}; // namespace isc::dhcp
+}; // namespace isc
+
+#endif // CFG_TO_ELEMENT_H

+ 10 - 1
src/lib/dhcpsrv/libdhcpsrv.dox

@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -79,6 +79,15 @@ configuration. For example: the value of 1 identifies an immediate
 predecessor of the current configuration, the value of 2 identifies the
 predecessor of the current configuration, the value of 2 identifies the
 one that occurred before it etc.
 one that occurred before it etc.
 
 
+All configuration classes are derived from the abstract base class
+\ref isc::data::CfgToElement and define the toElement virtual method
+which returns a \ref isc::data::ConstElementPtr which must be
+parsed into the same object, i.e. fullfil this property:
+@code
+for all valid C: parse(parse(C)->toElement()) == parse(C)
+@endcode
+
+
 @section hostmgr Host Manager
 @section hostmgr Host Manager
 
 
 Host Manager implemented by the \ref isc::dhcp::HostMgr is a singleton object
 Host Manager implemented by the \ref isc::dhcp::HostMgr is a singleton object