Fixed regression in scripts/regenerate-properties
authorJoris Mooij <joris.mooij@tuebingen.mpg.de>
Fri, 27 Nov 2009 22:42:01 +0000 (23:42 +0100)
committerJoris Mooij <joris.mooij@tuebingen.mpg.de>
Fri, 27 Nov 2009 22:42:01 +0000 (23:42 +0100)
(now all errors are gathered before throwing the exception, as used to be the case)

include/dai/bbp.h
include/dai/cbp.h
include/dai/exceptions.h
scripts/regenerate-properties
src/bbp.cpp
src/cbp.cpp
src/exceptions.cpp

index b24cf39..fda1036 100644 (file)
@@ -338,7 +338,8 @@ class BBP {
     public:
         /// Parameters for BBP
         /* PROPERTIES(props,BBP) {
-           /// \brief Enumeration of possible update schedules
+           /// Enumeration of possible update schedules
+           /// The following update schedules are defined:
            /// - SEQ_FIX fixed sequential updates
            /// - SEQ_MAX maximum residual updates (inspired by [\ref EMK06])
            /// - SEQ_BP_REV schedule used by BP, but reversed
@@ -393,7 +394,7 @@ class BBP {
             UpdateType updates;
 
             /// Set members from PropertySet
-            /** \throw UNKNOWN_PROPERTY_TYPE if a Property key is not recognized
+            /** \throw UNKNOWN_PROPERTY if a Property key is not recognized
              *  \throw NOT_ALL_PROPERTIES_SPECIFIED if an expected Property is missing
              */
             void set(const PropertySet &opts);
index 8caf058..f19c2b8 100644 (file)
@@ -179,7 +179,7 @@ class CBP : public DAIAlgFG {
             std::string clamp_outfile;
 
             /// Set members from PropertySet
-            /** \throw UNKNOWN_PROPERTY_TYPE if a Property key is not recognized
+            /** \throw UNKNOWN_PROPERTY if a Property key is not recognized
              *  \throw NOT_ALL_PROPERTIES_SPECIFIED if an expected Property is missing
              */
             void set(const PropertySet &opts);
index 7f710b5..7961d2f 100644 (file)
@@ -83,6 +83,7 @@ class Exception : public std::runtime_error {
                    UNKNOWN_DAI_ALGORITHM,
                    UNKNOWN_PARAMETER_ESTIMATION_METHOD,
                    UNKNOWN_PROPERTY_TYPE,
+                   UNKNOWN_PROPERTY,
                    MALFORMED_PROPERTY,
                    NOT_ALL_PROPERTIES_SPECIFIED,
                    CANNOT_READ_FILE,
index c0c8e39..16f9d46 100755 (executable)
@@ -189,7 +189,7 @@ EOF
   $text .= <<EOF;
 
             /// Set members from PropertySet
-            /** \\throw UNKNOWN_PROPERTY_TYPE if a Property key is not recognized
+            /** \\throw UNKNOWN_PROPERTY if a Property key is not recognized
              *  \\throw NOT_ALL_PROPERTIES_SPECIFIED if an expected Property is missing
              */
             void set(const PropertySet &opts);
@@ -206,36 +206,40 @@ namespace dai {
 void ${class}::Properties::set(const PropertySet &opts)
 {
     const std::set<PropertyKey> &keys = opts.keys();
-    std::set<PropertyKey>::const_iterator i;
-    for(i=keys.begin(); i!=keys.end(); i++) {
+    std::string errormsg;
+    for( std::set<PropertyKey>::const_iterator i = keys.begin(); i != keys.end(); i++ ) {
 EOF
   for my $v (@vars) {
     my ($type,$name,$default,$cmt) = @$v;
     $stext .= <<EOF;
-        if(*i == "$name") continue;
+        if( *i == "$name" ) continue;
 EOF
   }
   $stext .= <<EOF;
-        DAI_THROWE(UNKNOWN_PROPERTY_TYPE, "$class: Unknown property " + *i);
+        errormsg = errormsg + "$class: Unknown property " + *i + "\\n";
     }
+    if( !errormsg.empty() )
+        DAI_THROWE(UNKNOWN_PROPERTY, errormsg);
 EOF
   for my $v (@vars) {
     my ($type,$name,$default,$cmt) = @$v;
     if(!defined $default) {
       $stext .= <<EOF;
-    if(!opts.hasKey("$name"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"$class: Missing property \\\"$name\\\" for method \\\"\Q$class\E\\\"");
+    if( !opts.hasKey("$name") )
+        errormsg = errormsg + "$class: Missing property \\\"$name\\\" for method \\\"\Q$class\E\\\"\\n";
 EOF
     }
 
   }
   $stext .= <<EOF;
+    if( !errormsg.empty() )
+        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,errormsg);
 EOF
   for my $v (@vars) {
     my ($type,$name,$default,$cmt) = @$v;
     if(defined $default) {
       $stext .= <<EOF;
-    if(opts.hasKey("$name")) {
+    if( opts.hasKey("$name") ) {
         $name = opts.getStringAs<$type>("$name");
     } else {
         $name = $default;
index 3f0c56a..bd41b72 100644 (file)
@@ -1141,25 +1141,29 @@ namespace dai {
 void BBP::Properties::set(const PropertySet &opts)
 {
     const std::set<PropertyKey> &keys = opts.keys();
-    std::set<PropertyKey>::const_iterator i;
-    for(i=keys.begin(); i!=keys.end(); i++) {
-        if(*i == "verbose") continue;
-        if(*i == "maxiter") continue;
-        if(*i == "tol") continue;
-        if(*i == "damping") continue;
-        if(*i == "updates") continue;
-        DAI_THROWE(UNKNOWN_PROPERTY_TYPE, "BBP: Unknown property " + *i);
+    std::string errormsg;
+    for( std::set<PropertyKey>::const_iterator i = keys.begin(); i != keys.end(); i++ ) {
+        if( *i == "verbose" ) continue;
+        if( *i == "maxiter" ) continue;
+        if( *i == "tol" ) continue;
+        if( *i == "damping" ) continue;
+        if( *i == "updates" ) continue;
+        errormsg = errormsg + "BBP: Unknown property " + *i + "\n";
     }
-    if(!opts.hasKey("verbose"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"BBP: Missing property \"verbose\" for method \"BBP\"");
-    if(!opts.hasKey("maxiter"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"BBP: Missing property \"maxiter\" for method \"BBP\"");
-    if(!opts.hasKey("tol"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"BBP: Missing property \"tol\" for method \"BBP\"");
-    if(!opts.hasKey("damping"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"BBP: Missing property \"damping\" for method \"BBP\"");
-    if(!opts.hasKey("updates"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"BBP: Missing property \"updates\" for method \"BBP\"");
+    if( !errormsg.empty() )
+        DAI_THROWE(UNKNOWN_PROPERTY, errormsg);
+    if( !opts.hasKey("verbose") )
+        errormsg = errormsg + "BBP: Missing property \"verbose\" for method \"BBP\"\n";
+    if( !opts.hasKey("maxiter") )
+        errormsg = errormsg + "BBP: Missing property \"maxiter\" for method \"BBP\"\n";
+    if( !opts.hasKey("tol") )
+        errormsg = errormsg + "BBP: Missing property \"tol\" for method \"BBP\"\n";
+    if( !opts.hasKey("damping") )
+        errormsg = errormsg + "BBP: Missing property \"damping\" for method \"BBP\"\n";
+    if( !opts.hasKey("updates") )
+        errormsg = errormsg + "BBP: Missing property \"updates\" for method \"BBP\"\n";
+    if( !errormsg.empty() )
+        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,errormsg);
     verbose = opts.getStringAs<size_t>("verbose");
     maxiter = opts.getStringAs<size_t>("maxiter");
     tol = opts.getStringAs<Real>("tol");
index 4d9a6ce..d609253 100644 (file)
@@ -522,45 +522,49 @@ namespace dai {
 void CBP::Properties::set(const PropertySet &opts)
 {
     const std::set<PropertyKey> &keys = opts.keys();
-    std::set<PropertyKey>::const_iterator i;
-    for(i=keys.begin(); i!=keys.end(); i++) {
-        if(*i == "verbose") continue;
-        if(*i == "tol") continue;
-        if(*i == "updates") continue;
-        if(*i == "maxiter") continue;
-        if(*i == "rec_tol") continue;
-        if(*i == "max_levels") continue;
-        if(*i == "min_max_adj") continue;
-        if(*i == "choose") continue;
-        if(*i == "recursion") continue;
-        if(*i == "clamp") continue;
-        if(*i == "bbp_props") continue;
-        if(*i == "bbp_cfn") continue;
-        if(*i == "rand_seed") continue;
-        if(*i == "clamp_outfile") continue;
-        DAI_THROWE(UNKNOWN_PROPERTY_TYPE, "CBP: Unknown property " + *i);
+    std::string errormsg;
+    for( std::set<PropertyKey>::const_iterator i = keys.begin(); i != keys.end(); i++ ) {
+        if( *i == "verbose" ) continue;
+        if( *i == "tol" ) continue;
+        if( *i == "updates" ) continue;
+        if( *i == "maxiter" ) continue;
+        if( *i == "rec_tol" ) continue;
+        if( *i == "max_levels" ) continue;
+        if( *i == "min_max_adj" ) continue;
+        if( *i == "choose" ) continue;
+        if( *i == "recursion" ) continue;
+        if( *i == "clamp" ) continue;
+        if( *i == "bbp_props" ) continue;
+        if( *i == "bbp_cfn" ) continue;
+        if( *i == "rand_seed" ) continue;
+        if( *i == "clamp_outfile" ) continue;
+        errormsg = errormsg + "CBP: Unknown property " + *i + "\n";
     }
-    if(!opts.hasKey("tol"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"tol\" for method \"CBP\"");
-    if(!opts.hasKey("updates"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"updates\" for method \"CBP\"");
-    if(!opts.hasKey("maxiter"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"maxiter\" for method \"CBP\"");
-    if(!opts.hasKey("rec_tol"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"rec_tol\" for method \"CBP\"");
-    if(!opts.hasKey("min_max_adj"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"min_max_adj\" for method \"CBP\"");
-    if(!opts.hasKey("choose"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"choose\" for method \"CBP\"");
-    if(!opts.hasKey("recursion"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"recursion\" for method \"CBP\"");
-    if(!opts.hasKey("clamp"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"clamp\" for method \"CBP\"");
-    if(!opts.hasKey("bbp_props"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"bbp_props\" for method \"CBP\"");
-    if(!opts.hasKey("bbp_cfn"))
-        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,"CBP: Missing property \"bbp_cfn\" for method \"CBP\"");
-    if(opts.hasKey("verbose")) {
+    if( !errormsg.empty() )
+        DAI_THROWE(UNKNOWN_PROPERTY, errormsg);
+    if( !opts.hasKey("tol") )
+        errormsg = errormsg + "CBP: Missing property \"tol\" for method \"CBP\"\n";
+    if( !opts.hasKey("updates") )
+        errormsg = errormsg + "CBP: Missing property \"updates\" for method \"CBP\"\n";
+    if( !opts.hasKey("maxiter") )
+        errormsg = errormsg + "CBP: Missing property \"maxiter\" for method \"CBP\"\n";
+    if( !opts.hasKey("rec_tol") )
+        errormsg = errormsg + "CBP: Missing property \"rec_tol\" for method \"CBP\"\n";
+    if( !opts.hasKey("min_max_adj") )
+        errormsg = errormsg + "CBP: Missing property \"min_max_adj\" for method \"CBP\"\n";
+    if( !opts.hasKey("choose") )
+        errormsg = errormsg + "CBP: Missing property \"choose\" for method \"CBP\"\n";
+    if( !opts.hasKey("recursion") )
+        errormsg = errormsg + "CBP: Missing property \"recursion\" for method \"CBP\"\n";
+    if( !opts.hasKey("clamp") )
+        errormsg = errormsg + "CBP: Missing property \"clamp\" for method \"CBP\"\n";
+    if( !opts.hasKey("bbp_props") )
+        errormsg = errormsg + "CBP: Missing property \"bbp_props\" for method \"CBP\"\n";
+    if( !opts.hasKey("bbp_cfn") )
+        errormsg = errormsg + "CBP: Missing property \"bbp_cfn\" for method \"CBP\"\n";
+    if( !errormsg.empty() )
+        DAI_THROWE(NOT_ALL_PROPERTIES_SPECIFIED,errormsg);
+    if( opts.hasKey("verbose") ) {
         verbose = opts.getStringAs<size_t>("verbose");
     } else {
         verbose = 0;
@@ -569,7 +573,7 @@ void CBP::Properties::set(const PropertySet &opts)
     updates = opts.getStringAs<UpdateType>("updates");
     maxiter = opts.getStringAs<size_t>("maxiter");
     rec_tol = opts.getStringAs<Real>("rec_tol");
-    if(opts.hasKey("max_levels")) {
+    if( opts.hasKey("max_levels") ) {
         max_levels = opts.getStringAs<size_t>("max_levels");
     } else {
         max_levels = 10;
@@ -580,12 +584,12 @@ void CBP::Properties::set(const PropertySet &opts)
     clamp = opts.getStringAs<ClampType>("clamp");
     bbp_props = opts.getStringAs<PropertySet>("bbp_props");
     bbp_cfn = opts.getStringAs<BBPCostFunction>("bbp_cfn");
-    if(opts.hasKey("rand_seed")) {
+    if( opts.hasKey("rand_seed") ) {
         rand_seed = opts.getStringAs<size_t>("rand_seed");
     } else {
         rand_seed = 0;
     }
-    if(opts.hasKey("clamp_outfile")) {
+    if( opts.hasKey("clamp_outfile") ) {
         clamp_outfile = opts.getStringAs<std::string>("clamp_outfile");
     } else {
         clamp_outfile = "";
index 2a73fbf..f3d7c02 100644 (file)
@@ -24,6 +24,7 @@ namespace dai {
         "Unknown DAI algorithm",
         "Unrecognized parameter estimation method",
         "Unknown Property type",
+        "Unknown Property",
         "Malformed Property",
         "Not all mandatory Properties specified",
         "Cannot read file",