buffet: Change OneOf constraint to use generic PropValue list

Now ContraintOneOf contains a vector<PropValue> as opposed to
vector<T>. This will enable support for array types, because the
alternative would be to add explicit specializations for combinations
of basic types (int, bool, double, string,... ) and a vector.

BUG=brillo:107
TEST=`FEATURES=test emerge-link buffet`

Change-Id: Ia6bd93db23517c463ba6d915617d9571499a8491
Reviewed-on: https://chromium-review.googlesource.com/261564
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/prop_constraints.h b/buffet/commands/prop_constraints.h
index 79cc72a..e5efdd2 100644
--- a/buffet/commands/prop_constraints.h
+++ b/buffet/commands/prop_constraints.h
@@ -295,13 +295,12 @@
 };
 
 // Implementation of OneOf constraint for different data types.
-template<typename T>
 class ConstraintOneOf : public Constraint {
  public:
-  explicit ConstraintOneOf(const InheritableAttribute<std::vector<T>>& set)
-      : set_(set) {}
-  explicit ConstraintOneOf(const std::vector<T>& set)
-      : set_(set) {}
+  using ChoiceList = std::vector<std::unique_ptr<const PropValue>>;
+
+  explicit ConstraintOneOf(InheritableAttribute<ChoiceList> set);
+  explicit ConstraintOneOf(ChoiceList set);
 
   // Implementation of Constraint::GetType().
   ConstraintType GetType() const override {
@@ -315,46 +314,24 @@
 
   // Implementation of Constraint::Validate().
   bool Validate(const PropValue& value,
-                chromeos::ErrorPtr* error) const override {
-    using chromeos::string_utils::ToString;
-    T v = value.GetValueAsAny().Get<T>();
-    for (const auto& item : set_.value) {
-      if (CompareValue(v, item))
-        return true;
-    }
-    std::vector<std::string> values;
-    values.reserve(set_.value.size());
-    for (const auto& item : set_.value) {
-      values.push_back(ToString(item));
-    }
-    return ReportErrorNotOneOf(error, ToString(v), values);
-  }
+                chromeos::ErrorPtr* error) const override;
 
   // Implementation of Constraint::Clone().
-  std::unique_ptr<Constraint> Clone() const override {
-    return std::unique_ptr<Constraint>{new ConstraintOneOf{set_}};
-  }
+  std::unique_ptr<Constraint> Clone() const override;
 
   // Implementation of Constraint::CloneAsInherited().
-  std::unique_ptr<Constraint> CloneAsInherited() const override {
-    return std::unique_ptr<Constraint>{new ConstraintOneOf{set_.value}};
-  }
+  std::unique_ptr<Constraint> CloneAsInherited() const override;
 
   // Implementation of Constraint::ToJson().
-  std::unique_ptr<base::Value> ToJson(
-      chromeos::ErrorPtr* error) const override {
-    return TypedValueToJson(set_.value, error);
-  }
+  std::unique_ptr<base::Value> ToJson(chromeos::ErrorPtr* error) const override;
 
   // Implementation of Constraint::GetDictKey().
-  const char* GetDictKey() const override {
-    return commands::attributes::kOneOf_Enum;
-  }
+  const char* GetDictKey() const override;
 
   // Stores the list of acceptable values for the parameter.
   // |set_.is_inherited| indicates whether the constraint is inherited
   // from base schema or overridden.
-  InheritableAttribute<std::vector<T>> set_;
+  InheritableAttribute<ChoiceList> set_;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(ConstraintOneOf);