[svn] commit: r870 - in /branches/jelte-configuration/src/lib/config/cpp: ccsession.cc data_def.cc data_def.h data_def_unittests.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Feb 18 14:44:48 UTC 2010


Author: jelte
Date: Thu Feb 18 14:44:48 2010
New Revision: 870

Log:
ModuleSpec initializer not takes ElementPtr instead of file name,
for creation from file name or ifstream there are the non-member moduleSpecFromFile functions now


Modified:
    branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
    branches/jelte-configuration/src/lib/config/cpp/data_def.cc
    branches/jelte-configuration/src/lib/config/cpp/data_def.h
    branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc

Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.cc Thu Feb 18 14:44:48 2010
@@ -48,6 +48,7 @@
 using isc::data::ModuleSpec;
 using isc::data::ParseError;
 using isc::data::ModuleSpecError;
+using namespace isc::data;
 
 void
 ModuleCCSession::read_module_specification(const std::string& filename) {
@@ -61,7 +62,7 @@
     }
 
     try {
-        module_specification_ = ModuleSpec(file, true);
+        module_specification_ = moduleSpecFromFile(file, true);
     } catch (ParseError pe) {
         cout << "Error parsing module specification file: " << pe.what() << endl;
         exit(1);

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.cc Thu Feb 18 14:44:48 2010
@@ -24,7 +24,8 @@
 
 // todo: add more context to thrown ModuleSpecErrors?
 
-using namespace isc::data;
+namespace isc {
+namespace data {
 
 //
 // static functions
@@ -170,9 +171,54 @@
 // Public functions
 //
 
-ModuleSpec::ModuleSpec(const std::string& file_name,
-                               const bool check)
-                               throw(ParseError, ModuleSpecError) {
+ModuleSpec::ModuleSpec(ElementPtr module_spec_element,
+                       const bool check)
+                       throw(ModuleSpecError)
+                       
+{
+    module_specification = module_spec_element;
+    if (check) {
+        check_module_specification(module_specification);
+    }
+}
+
+const ElementPtr
+ModuleSpec::getCommandsSpec()
+{
+    if (module_specification->contains("commands")) {
+        return module_specification->get("commands");
+    } else {
+        return ElementPtr();
+    }
+}
+
+const ElementPtr
+ModuleSpec::getConfigSpec()
+{
+    if (module_specification->contains("config_data")) {
+        return module_specification->get("config_data");
+    } else {
+        return ElementPtr();
+    }
+}
+
+const std::string
+ModuleSpec::getModuleName()
+{
+    return module_specification->get("module_name")->stringValue();
+}
+
+bool
+ModuleSpec::validate(const ElementPtr data)
+{
+    ElementPtr spec = module_specification->find("module_spec/config_data");
+    return validate_spec_list(spec, data);
+}
+
+ModuleSpec
+moduleSpecFromFile(const std::string& file_name, const bool check)
+                   throw(ParseError, ModuleSpecError)
+{
     std::ifstream file;
 
     file.open(file_name.c_str());
@@ -182,53 +228,15 @@
         throw ModuleSpecError(errs.str());
     }
 
-    module_specification = Element::createFromString(file, file_name);
-    if (check) {
-        check_module_specification(module_specification);
-    }
-}
-
-
-ModuleSpec::ModuleSpec(std::istream& in, const bool check)
-                               throw(ParseError, ModuleSpecError) {
-    module_specification = Element::createFromString(in);
-    // make sure the whole structure is complete and valid
-    if (check) {
-        check_module_specification(module_specification);
-    }
-}
-
-const ElementPtr
-ModuleSpec::getCommandsSpec()
-{
-    if (module_specification->contains("commands")) {
-        return module_specification->get("commands");
-    } else {
-        return ElementPtr();
-    }
-}
-
-const ElementPtr
-ModuleSpec::getConfigSpec()
-{
-    if (module_specification->contains("config_data")) {
-        return module_specification->get("config_data");
-    } else {
-        return ElementPtr();
-    }
-}
-
-const std::string
-ModuleSpec::getModuleName()
-{
-    return module_specification->get("module_name")->stringValue();
-}
-
-bool
-ModuleSpec::validate(const ElementPtr data)
-{
-    ElementPtr spec = module_specification->find("module_spec/config_data");
-    return validate_spec_list(spec, data);
+    ElementPtr module_spec_element = Element::createFromString(file, file_name);
+    return ModuleSpec(module_spec_element, check);
+}
+
+ModuleSpec
+moduleSpecFromFile(std::ifstream& in, const bool check)
+                   throw(ParseError, ModuleSpecError) {
+    ElementPtr module_spec_element = Element::createFromString(in);
+    return ModuleSpec(module_spec_element, check);
 }
 
 
@@ -332,3 +340,5 @@
     return true;
 }
 
+}
+}

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.h Thu Feb 18 14:44:48 2010
@@ -53,29 +53,8 @@
         /// Create a \c ModuleSpec instance with the given data as
         /// the specification
         /// \param e The Element containing the data specification
-        explicit ModuleSpec(ElementPtr e) : module_specification(e) {};
-
-        /// Creates a \c ModuleSpec instance from the contents
-        /// of the file given by file_name.
-        /// If check is true, and the module specification is not of
-        /// the correct form, a ModuleSpecError is thrown. If the file
-        /// could not be parse, a ParseError is thrown.
-        /// \param file_name The file to be opened and parsed
-        /// \param check If true, the module specification in the file
-        /// is checked to be of the correct form
-        ModuleSpec(const std::string& file_name, const bool check = true)
-                       throw(ParseError, ModuleSpecError);
-
-        /// Creates a \c ModuleSpec instance from the given input
-        /// stream that contains the contents of a .spec file.
-        /// If check is true, and the module specification is not of
-        /// the correct form, a ModuleSpecError is thrown. If the
-        /// file could not be parsed, a ParseError is thrown.
-        /// \param in The std::istream containing the .spec file data
-        /// \param check If true, the module specification is checked
-        /// to be of the correct form
-        explicit ModuleSpec(std::istream& in, const bool check = true)
-                                throw(ParseError, ModuleSpecError);
+        explicit ModuleSpec(ElementPtr e, const bool check = true)
+                            throw(ModuleSpecError);
 
         /// Returns the commands part of the specification as an
         /// ElementPtr, returns an empty ElementPtr if there is none
@@ -112,6 +91,29 @@
         ElementPtr module_specification;
     };
 
+    /// Creates a \c ModuleSpec instance from the contents
+    /// of the file given by file_name.
+    /// If check is true, and the module specification is not of
+    /// the correct form, a ModuleSpecError is thrown. If the file
+    /// could not be parse, a ParseError is thrown.
+    /// \param file_name The file to be opened and parsed
+    /// \param check If true, the module specification in the file
+    /// is checked to be of the correct form
+    ModuleSpec
+    moduleSpecFromFile(const std::string& file_name, const bool check = true)
+                       throw(ParseError, ModuleSpecError);
+
+    /// Creates a \c ModuleSpec instance from the given input
+    /// stream that contains the contents of a .spec file.
+    /// If check is true, and the module specification is not of
+    /// the correct form, a ModuleSpecError is thrown. If the
+    /// file could not be parsed, a ParseError is thrown.
+    /// \param in The std::istream containing the .spec file data
+    /// \param check If true, the module specification is checked
+    /// to be of the correct form
+    ModuleSpec
+    moduleSpecFromFile(std::ifstream& in, const bool check = true)
+                       throw(ParseError, ModuleSpecError);
 } }
 
 #endif // _DATA_DEF_H

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc Thu Feb 18 14:44:48 2010
@@ -34,9 +34,9 @@
                const std::string& error2 = "",
                const std::string& error3 = "")
 {
-    EXPECT_THROW(ModuleSpec(specfile(file)), ModuleSpecError);
+    EXPECT_THROW(moduleSpecFromFile(specfile(file)), ModuleSpecError);
     try {
-        ModuleSpec dd = ModuleSpec(specfile(file));
+        ModuleSpec dd = moduleSpecFromFile(specfile(file));
     } catch (ModuleSpecError dde) {
         std::string ddew = dde.what();
         EXPECT_EQ(error1 + error2 + error3, ddew);
@@ -46,11 +46,11 @@
 TEST(ModuleSpec, ReadingSpecfiles) {
     // Tests whether we can open specfiles and if we get the
     // right parse errors
-    ModuleSpec dd = ModuleSpec(specfile("spec1.spec"));
+    ModuleSpec dd = moduleSpecFromFile(specfile("spec1.spec"));
     EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
-    dd = ModuleSpec(specfile("spec2.spec"));
+    dd = moduleSpecFromFile(specfile("spec2.spec"));
     EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("config_data")->size(), 6);
     data_def_error("doesnotexist",
@@ -60,7 +60,7 @@
 
     std::ifstream file;
     file.open(specfile("spec1.spec").c_str());
-    dd = ModuleSpec(file);
+    dd = moduleSpecFromFile(file);
     EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
@@ -132,7 +132,7 @@
 }
 
 TEST(ModuleSpec, DataValidation) {
-    ModuleSpec dd = ModuleSpec(specfile("spec22.spec"));
+    ModuleSpec dd = moduleSpecFromFile(specfile("spec22.spec"));
 
     EXPECT_TRUE(data_test(dd, "data22_1.data"));
     EXPECT_FALSE(data_test(dd, "data22_2.data"));




More information about the bind10-changes mailing list