Browse Source

[trac981] Implementation of the NOT creator

Michal 'vorner' Vaner 14 years ago
parent
commit
376fd54600
2 changed files with 36 additions and 4 deletions
  1. 35 3
      src/lib/acl/logic_check.h
  2. 1 1
      src/lib/acl/tests/logic_check_test.cc

+ 35 - 3
src/lib/acl/logic_check.h

@@ -239,13 +239,45 @@ private:
 template<typename Context, typename Action = BasicAction>
 class NotCreator : public Loader<Context, Action>::CheckCreator {
 public:
-    NotCreator(const std::string& name);
-    virtual std::vector<std::string> names() const;
+    /**
+     * \brief Constructor
+     *
+     * \param name The name of the NOT operator to be loaded as.
+     */
+    NotCreator(const std::string& name) :
+        name_(name)
+    { }
+    /**
+     * \brief List of the names this loads
+     *
+     * \return Single-value vector containing the name passed to the
+     *     constructor.
+     */
+    virtual std::vector<std::string> names() const {
+        std::vector<std::string> result;
+        result.push_back(name_);
+        return (result);
+    }
+    /// \brief Create the check.
     virtual boost::shared_ptr<Check<Context> > create(const std::string&,
                                                       data::ConstElementPtr
                                                       definition,
                                                       const Loader<Context,
-                                                      Action>& loader);
+                                                      Action>& loader)
+    {
+        return (boost::shared_ptr<Check<Context> >(new NotCheck<Context>(
+                    loader.loadCheck(definition))));
+    }
+    /**
+     * \brief Or-abbreviated form.
+     *
+     * This returns false. In theory, the NOT operator could be used with
+     * the abbreviated form, but it would be confusing. Such syntax is
+     * therefore explicitly forbidden.
+     */
+    virtual bool allowListAbbreviation() const { return (false); }
+public:
+    const std::string name_;
 };
 
 }

+ 1 - 1
src/lib/acl/tests/logic_check_test.cc

@@ -276,7 +276,7 @@ TEST_F(LogicCreatorTest, notInvalid) {
                  LoaderError);
     EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": [{"
                                                      "\"logcheck\": [0, true]"
-                                                     "]}]}")),
+                                                     "}]}")),
                  LoaderError);
 }