[MediaStream] Templatize MediaConstraint
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Aug 2016 19:02:48 +0000 (19:02 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Aug 2016 19:02:48 +0000 (19:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161092

Reviewed by Jer Noble.

No new tests, no functional change.

* platform/mediastream/MediaConstraints.cpp:
(WebCore::BooleanConstraint::getExact):
(WebCore::BooleanConstraint::getIdeal):
(WebCore::MediaConstraint::getMin): Deleted.
(WebCore::MediaConstraint::getMax): Deleted.
(WebCore::MediaConstraint::getExact): Deleted.
(WebCore::MediaConstraint::getIdeal): Deleted.
(WebCore::IntConstraint::create): Deleted.
(WebCore::IntConstraint::setMin): Deleted.
(WebCore::IntConstraint::setMax): Deleted.
(WebCore::IntConstraint::setExact): Deleted.
(WebCore::IntConstraint::setIdeal): Deleted.
(WebCore::IntConstraint::getMin): Deleted.
(WebCore::IntConstraint::getMax): Deleted.
(WebCore::IntConstraint::getExact): Deleted.
(WebCore::IntConstraint::getIdeal): Deleted.
(WebCore::DoubleConstraint::create): Deleted.
(WebCore::DoubleConstraint::setMin): Deleted.
(WebCore::DoubleConstraint::setMax): Deleted.
(WebCore::DoubleConstraint::setExact): Deleted.
(WebCore::DoubleConstraint::setIdeal): Deleted.
(WebCore::DoubleConstraint::getMin): Deleted.
(WebCore::DoubleConstraint::getMax): Deleted.
(WebCore::DoubleConstraint::getExact): Deleted.
(WebCore::DoubleConstraint::getIdeal): Deleted.
(WebCore::BooleanConstraint::create): Deleted.
(WebCore::BooleanConstraint::setExact): Deleted.
(WebCore::BooleanConstraint::setIdeal): Deleted.
(WebCore::StringConstraint::create): Deleted.
* platform/mediastream/MediaConstraints.h:
(WebCore::MediaConstraint::getMin):
(WebCore::MediaConstraint::getMax):
(WebCore::MediaConstraint::getExact):
(WebCore::MediaConstraint::getIdeal):
(WebCore::NumericConstraint::setMin):
(WebCore::NumericConstraint::setMax):
(WebCore::NumericConstraint::setExact):
(WebCore::NumericConstraint::setIdeal):
(WebCore::NumericConstraint::setHasMin): Deleted.
(WebCore::NumericConstraint::setHasMax): Deleted.
(WebCore::NumericConstraint::setHasExact): Deleted.
(WebCore::NumericConstraint::setHasIdeal): Deleted.
(WebCore::NumericConstraint::hasMin): Deleted.
(WebCore::NumericConstraint::hasMax): Deleted.
(WebCore::NumericConstraint::hasExact): Deleted.
(WebCore::NumericConstraint::hasIdeal): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204847 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/MediaConstraints.cpp
Source/WebCore/platform/mediastream/MediaConstraints.h

index d67b929..f43e02a 100644 (file)
@@ -1,3 +1,59 @@
+2016-08-23  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Templatize MediaConstraint
+        https://bugs.webkit.org/show_bug.cgi?id=161092
+
+        Reviewed by Jer Noble.
+
+        No new tests, no functional change.
+
+        * platform/mediastream/MediaConstraints.cpp:
+        (WebCore::BooleanConstraint::getExact):
+        (WebCore::BooleanConstraint::getIdeal):
+        (WebCore::MediaConstraint::getMin): Deleted.
+        (WebCore::MediaConstraint::getMax): Deleted.
+        (WebCore::MediaConstraint::getExact): Deleted.
+        (WebCore::MediaConstraint::getIdeal): Deleted.
+        (WebCore::IntConstraint::create): Deleted.
+        (WebCore::IntConstraint::setMin): Deleted.
+        (WebCore::IntConstraint::setMax): Deleted.
+        (WebCore::IntConstraint::setExact): Deleted.
+        (WebCore::IntConstraint::setIdeal): Deleted.
+        (WebCore::IntConstraint::getMin): Deleted.
+        (WebCore::IntConstraint::getMax): Deleted.
+        (WebCore::IntConstraint::getExact): Deleted.
+        (WebCore::IntConstraint::getIdeal): Deleted.
+        (WebCore::DoubleConstraint::create): Deleted.
+        (WebCore::DoubleConstraint::setMin): Deleted.
+        (WebCore::DoubleConstraint::setMax): Deleted.
+        (WebCore::DoubleConstraint::setExact): Deleted.
+        (WebCore::DoubleConstraint::setIdeal): Deleted.
+        (WebCore::DoubleConstraint::getMin): Deleted.
+        (WebCore::DoubleConstraint::getMax): Deleted.
+        (WebCore::DoubleConstraint::getExact): Deleted.
+        (WebCore::DoubleConstraint::getIdeal): Deleted.
+        (WebCore::BooleanConstraint::create): Deleted.
+        (WebCore::BooleanConstraint::setExact): Deleted.
+        (WebCore::BooleanConstraint::setIdeal): Deleted.
+        (WebCore::StringConstraint::create): Deleted.
+        * platform/mediastream/MediaConstraints.h:
+        (WebCore::MediaConstraint::getMin):
+        (WebCore::MediaConstraint::getMax):
+        (WebCore::MediaConstraint::getExact):
+        (WebCore::MediaConstraint::getIdeal):
+        (WebCore::NumericConstraint::setMin):
+        (WebCore::NumericConstraint::setMax):
+        (WebCore::NumericConstraint::setExact):
+        (WebCore::NumericConstraint::setIdeal):
+        (WebCore::NumericConstraint::setHasMin): Deleted.
+        (WebCore::NumericConstraint::setHasMax): Deleted.
+        (WebCore::NumericConstraint::setHasExact): Deleted.
+        (WebCore::NumericConstraint::setHasIdeal): Deleted.
+        (WebCore::NumericConstraint::hasMin): Deleted.
+        (WebCore::NumericConstraint::hasMax): Deleted.
+        (WebCore::NumericConstraint::hasExact): Deleted.
+        (WebCore::NumericConstraint::hasIdeal): Deleted.
+
 2016-08-23  Anders Carlsson  <andersca@apple.com>
 
         Add a workaround for iOS Frameworks that expect DOM bindings to be in WebCore
index fc318f1..bd5eed3 100644 (file)
@@ -62,272 +62,24 @@ RefPtr<MediaConstraint> MediaConstraint::create(const String& name)
     }
 }
 
-bool MediaConstraint::getMin(int&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMax(int&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getExact(int&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getIdeal(int&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMin(double&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMax(double&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getExact(double&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getIdeal(double&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMin(bool&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMax(bool&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getExact(bool&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getIdeal(bool&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMin(Vector<String>&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getMax(Vector<String>&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getExact(Vector<String>&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool MediaConstraint::getIdeal(Vector<String>&) const
-{
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-Ref<IntConstraint> IntConstraint::create(MediaConstraintType type)
-{
-    return adoptRef(*new IntConstraint(type));
-}
-
-void IntConstraint::setMin(int value)
-{
-    m_min = value;
-    setHasMin(true);
-}
-
-void IntConstraint::setMax(int value)
-{
-    m_max = value;
-    setHasMax(true);
-}
-
-void IntConstraint::setExact(int value)
-{
-    m_exact = value;
-    setHasExact(true);
-}
-
-void IntConstraint::setIdeal(int value)
-{
-    m_ideal = value;
-    setHasIdeal(true);
-}
-
-bool IntConstraint::getMin(int& min) const
-{
-    if (!hasMin())
-        return false;
-
-    min = m_min;
-    return true;
-}
-
-bool IntConstraint::getMax(int& max) const
-{
-    if (!hasMax())
-        return false;
-
-    max = m_max;
-    return true;
-}
-
-bool IntConstraint::getExact(int& exact) const
-{
-    if (!hasExact())
-        return false;
-
-    exact = m_exact;
-    return true;
-}
-
-bool IntConstraint::getIdeal(int& ideal) const
-{
-    if (!hasIdeal())
-        return false;
-
-    ideal = m_ideal;
-    return true;
-}
-
-Ref<DoubleConstraint> DoubleConstraint::create(MediaConstraintType type)
-{
-    return adoptRef(*new DoubleConstraint(type));
-}
-
-void DoubleConstraint::setMin(double value)
-{
-    m_min = value;
-    setHasMin(true);
-}
-
-void DoubleConstraint::setMax(double value)
-{
-    m_max = value;
-    setHasMax(true);
-}
-
-void DoubleConstraint::setExact(double value)
-{
-    m_exact = value;
-    setHasExact(true);
-}
-
-void DoubleConstraint::setIdeal(double value)
-{
-    m_ideal = value;
-    setHasIdeal(true);
-}
-
-bool DoubleConstraint::getMin(double& min) const
-{
-    if (!hasMin())
-        return false;
-    
-    min = m_min;
-    return true;
-}
-
-bool DoubleConstraint::getMax(double& max) const
-{
-    if (!hasMax())
-        return false;
-    
-    max = m_max;
-    return true;
-}
-
-bool DoubleConstraint::getExact(double& exact) const
-{
-    if (!hasExact())
-        return false;
-    
-    exact = m_exact;
-    return true;
-}
-
-bool DoubleConstraint::getIdeal(double& ideal) const
-{
-    if (!hasIdeal())
-        return false;
-    
-    ideal = m_ideal;
-    return true;
-}
-
-Ref<BooleanConstraint> BooleanConstraint::create(MediaConstraintType type)
-{
-    return adoptRef(*new BooleanConstraint(type));
-}
-
-void BooleanConstraint::setExact(bool value)
-{
-    m_exact = value;
-    m_hasExact = true;
-}
-
-void BooleanConstraint::setIdeal(bool value)
-{
-    m_ideal = value;
-    m_hasIdeal = true;
-}
-
 bool BooleanConstraint::getExact(bool& exact) const
 {
-    if (!m_hasExact)
+    if (!m_exact)
         return false;
     
-    exact = m_exact;
+    exact = m_exact.value();
     return true;
 }
 
 bool BooleanConstraint::getIdeal(bool& ideal) const
 {
-    if (!m_hasIdeal)
+    if (!m_ideal)
         return false;
     
-    ideal = m_ideal;
+    ideal = m_ideal.value();
     return true;
 }
 
-Ref<StringConstraint> StringConstraint::create(MediaConstraintType type)
-{
-    return adoptRef(*new StringConstraint(type));
-}
-
 void StringConstraint::setExact(const String& value)
 {
     m_exact.clear();
index 7136889..e0ae8d6 100644 (file)
@@ -49,29 +49,28 @@ public:
     virtual bool isEmpty() const = 0;
     virtual bool isMandatory() const = 0;
 
-    virtual bool getMin(int&) const;
-    virtual bool getMax(int&) const;
-    virtual bool getExact(int&) const;
-    virtual bool getIdeal(int&) const;
-
-    virtual bool getMin(double&) const;
-    virtual bool getMax(double&) const;
-    virtual bool getExact(double&) const;
-    virtual bool getIdeal(double&) const;
-
-    virtual bool getMin(bool&) const;
-    virtual bool getMax(bool&) const;
-    virtual bool getExact(bool&) const;
-    virtual bool getIdeal(bool&) const;
-
-    virtual bool getMin(Vector<String>&) const;
-    virtual bool getMax(Vector<String>&) const;
-    virtual bool getExact(Vector<String>&) const;
-    virtual bool getIdeal(Vector<String>&) const;
+    virtual bool getMin(int&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getMax(int&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getExact(int&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getIdeal(int&) const { ASSERT_NOT_REACHED(); return false; }
+
+    virtual bool getMin(double&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getMax(double&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getExact(double&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getIdeal(double&) const { ASSERT_NOT_REACHED(); return false; }
+
+    virtual bool getMin(bool&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getMax(bool&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getExact(bool&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getIdeal(bool&) const { ASSERT_NOT_REACHED(); return false; }
+
+    virtual bool getMin(Vector<String>&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getMax(Vector<String>&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getExact(Vector<String>&) const { ASSERT_NOT_REACHED(); return false; }
+    virtual bool getIdeal(Vector<String>&) const { ASSERT_NOT_REACHED(); return false; }
 
     MediaConstraintType type() const { return m_type; }
 
-
 protected:
     explicit MediaConstraint(MediaConstraintType type)
         : m_type(type)
@@ -82,10 +81,48 @@ private:
     MediaConstraintType m_type;
 };
 
+template<class ValueType>
 class NumericConstraint : public MediaConstraint {
 public:
-    bool isEmpty() const override { return !m_hasMin && !m_hasMax && !m_hasExact && !m_hasIdeal; }
-    bool isMandatory() const override { return m_hasMin || m_hasMax || m_hasExact; }
+    bool isEmpty() const override { return !m_min && !m_max && !m_exact && !m_ideal; }
+    bool isMandatory() const override { return m_min || m_max || m_exact; }
+
+    void setMin(ValueType value) { m_min = value; }
+    void setMax(ValueType value) { m_max = value; }
+    void setExact(ValueType value) { m_exact = value; }
+    void setIdeal(ValueType value) { m_ideal = value; }
+
+    bool getMin(ValueType& min) const final {
+        if (!m_min)
+            return false;
+
+        min = m_min.value();
+        return true;
+    }
+
+    bool getMax(ValueType& max) const final {
+        if (!m_max)
+            return false;
+
+        max = m_max.value();
+        return true;
+    }
+
+    bool getExact(ValueType& exact) const final {
+        if (!m_exact)
+            return false;
+
+        exact = m_exact.value();
+        return true;
+    }
+
+    bool getIdeal(ValueType& ideal) const final {
+        if (!m_ideal)
+            return false;
+
+        ideal = m_ideal.value();
+        return true;
+    }
 
 protected:
     explicit NumericConstraint(MediaConstraintType type)
@@ -93,87 +130,47 @@ protected:
     {
     }
 
-    void setHasMin(bool value) { m_hasMin = value; }
-    void setHasMax(bool value) { m_hasMax = value; }
-    void setHasExact(bool value) { m_hasExact = value; }
-    void setHasIdeal(bool value) { m_hasIdeal = value; }
-
-    bool hasMin() const { return m_hasMin; }
-    bool hasMax() const { return m_hasMax; }
-    bool hasExact() const { return m_hasExact; }
-    bool hasIdeal() const { return m_hasIdeal; }
-
 private:
-    bool m_hasMin { false };
-    bool m_hasMax { false };
-    bool m_hasExact { false };
-    bool m_hasIdeal { false };
+    Optional<ValueType> m_min;
+    Optional<ValueType> m_max;
+    Optional<ValueType> m_exact;
+    Optional<ValueType> m_ideal;
 };
 
-class IntConstraint final : public NumericConstraint {
+class IntConstraint final : public NumericConstraint<int> {
 public:
-    static Ref<IntConstraint> create(MediaConstraintType);
-
-    void setMin(int value);
-    void setMax(int value);
-    void setExact(int value);
-    void setIdeal(int value);
-
-    bool getMin(int&) const final;
-    bool getMax(int&) const final;
-    bool getExact(int&) const final;
-    bool getIdeal(int&) const final;
+    static Ref<IntConstraint> create(MediaConstraintType type) { return adoptRef(*new IntConstraint(type)); }
 
 private:
     explicit IntConstraint(MediaConstraintType type)
-        : WebCore::NumericConstraint(type)
+        : NumericConstraint<int>(type)
     {
     }
-
-    int m_min;
-    int m_max;
-    int m_exact;
-    int m_ideal;
 };
 
-class DoubleConstraint final : public NumericConstraint {
+class DoubleConstraint final : public NumericConstraint<double> {
 public:
-    static Ref<DoubleConstraint> create(MediaConstraintType);
-
-    void setMin(double value);
-    void setMax(double value);
-    void setExact(double value);
-    void setIdeal(double value);
-
-    bool getMin(double&) const final;
-    bool getMax(double&) const final;
-    bool getExact(double&) const final;
-    bool getIdeal(double&) const final;
+    static Ref<DoubleConstraint> create(MediaConstraintType type) { return adoptRef(*new DoubleConstraint(type)); }
 
 private:
     explicit DoubleConstraint(MediaConstraintType type)
-        : WebCore::NumericConstraint(type)
+        : NumericConstraint<double>(type)
     {
     }
-
-    double m_min;
-    double m_max;
-    double m_exact;
-    double m_ideal;
 };
 
 class BooleanConstraint final : public MediaConstraint {
 public:
-    static Ref<BooleanConstraint> create(MediaConstraintType);
+    static Ref<BooleanConstraint> create(MediaConstraintType type) { return adoptRef(*new BooleanConstraint(type)); }
 
-    void setExact(bool value);
-    void setIdeal(bool value);
+    void setExact(bool value) { m_exact = value; }
+    void setIdeal(bool value) { m_ideal = value; }
 
     bool getExact(bool&) const final;
     bool getIdeal(bool&) const final;
 
-    bool isEmpty() const final { return !m_hasExact && !m_hasIdeal; };
-    bool isMandatory() const final { return m_hasExact; }
+    bool isEmpty() const final { return !m_exact && !m_ideal; };
+    bool isMandatory() const final { return bool(m_exact); }
 
 private:
     explicit BooleanConstraint(MediaConstraintType type)
@@ -181,15 +178,13 @@ private:
     {
     }
 
-    bool m_exact { false };
-    bool m_ideal { false };
-    bool m_hasExact { false };
-    bool m_hasIdeal { false };
+    Optional<bool> m_exact { false };
+    Optional<bool> m_ideal { false };
 };
 
 class StringConstraint final : public MediaConstraint {
 public:
-    static Ref<StringConstraint> create(MediaConstraintType);
+    static Ref<StringConstraint> create(MediaConstraintType type) { return adoptRef(*new StringConstraint(type)); }
 
     void setExact(const String&);
     void appendExact(const String&);