Bug 542731, Patch D: Make nsISMILType methods protected, & only give nsSMILValue access. r=roc
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 01 Feb 2010 18:46:13 -0800
changeset 37812 d9afac0e24583c862b617fe1be2362abba2a5461
parent 37811 5f645dd4152ad918ee42f7cfd957c4a0aed80624
child 37813 9ade02035cbd677f03b3f1c423d318038a38684f
push id11446
push userdholbert@mozilla.com
push dateTue, 02 Feb 2010 02:47:21 +0000
treeherdermozilla-central@9ade02035cbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs542731
milestone1.9.3a1pre
Bug 542731, Patch D: Make nsISMILType methods protected, & only give nsSMILValue access. r=roc
content/smil/SMILBoolType.h
content/smil/SMILEnumType.h
content/smil/nsISMILType.h
content/smil/nsSMILCSSValueType.h
content/smil/nsSMILFloatType.h
content/smil/nsSMILNullType.h
content/svg/content/src/nsSVGTransformSMILType.h
--- a/content/smil/SMILBoolType.h
+++ b/content/smil/SMILBoolType.h
@@ -39,30 +39,37 @@
 
 #include "nsISMILType.h"
 
 namespace mozilla {
 
 class SMILBoolType : public nsISMILType
 {
 public:
+  // Singleton for nsSMILValue objects to hold onto.
+  static SMILBoolType sSingleton;
+
+protected:
+  // nsISMILType Methods
+  // -------------------
   virtual nsresult Init(nsSMILValue& aValue) const;
   virtual void     Destroy(nsSMILValue&) const;
   virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
                                    double& aDistance) const;
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const;
 
-  static SMILBoolType sSingleton;
-
 private:
-  SMILBoolType() {}
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  SMILBoolType()  {}
+  ~SMILBoolType() {}
 };
 
 } // namespace mozilla
 
 #endif // MOZILLA_SMILBOOLTYPE_H_
--- a/content/smil/SMILEnumType.h
+++ b/content/smil/SMILEnumType.h
@@ -39,30 +39,37 @@
 
 #include "nsISMILType.h"
 
 namespace mozilla {
 
 class SMILEnumType : public nsISMILType
 {
 public:
+  // Singleton for nsSMILValue objects to hold onto.
+  static SMILEnumType sSingleton;
+
+protected:
+  // nsISMILType Methods
+  // -------------------
   virtual nsresult Init(nsSMILValue& aValue) const;
   virtual void     Destroy(nsSMILValue&) const;
   virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
                                    double& aDistance) const;
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const;
 
-  static SMILEnumType sSingleton;
-
 private:
-  SMILEnumType() {}
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  SMILEnumType()  {}
+  ~SMILEnumType() {}
 };
 
 } // namespace mozilla
 
 #endif // MOZILLA_SMILENUMTYPE_H_
--- a/content/smil/nsISMILType.h
+++ b/content/smil/nsISMILType.h
@@ -70,17 +70,22 @@ class nsSMILValue;
 // | -- SandwichAdd?     |     -         |    -?       |    X             |
 // | -- ComputeDistance? |     -         |    -        |    X?            |
 // | -- Interpolate?     |     -         |    X        |    X             |
 // +---------------------+---------------+-------------+------------------+
 //
 
 class nsISMILType
 {
-public:
+  /**
+   * Only give the nsSMILValue class access to this interface.
+   */
+  friend class nsSMILValue;
+
+protected:
   /**
    * Initialises aValue and sets it to some identity value such that adding
    * aValue to another value of the same type has no effect.
    *
    * @pre (aValue.mType == this && aValue.mU is valid)
    *      || aValue.mType == null-type
    * @post aValue.mType == this || NS_FAILED(rv)
    */
@@ -206,16 +211,17 @@ public:
    *
    * @pre aStartVal.mType == aEndVal.mType == aResult.mType == this
    */
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const = 0;
 
-  /*
-   * Virtual destructor: Nothing to do here, but subclasses
-   * may need it.
+  /**
+   * Protected destructor, to ensure that no one accidentally deletes an
+   * instance of this class.
+   * (The only instances in existence should be singletons - one per subclass.)
    */
-  virtual ~nsISMILType() {};
+  ~nsISMILType() {}
 };
 
 #endif // NS_ISMILTYPE_H_
--- a/content/smil/nsSMILCSSValueType.h
+++ b/content/smil/nsSMILCSSValueType.h
@@ -49,16 +49,20 @@ class nsIContent;
 class nsAString;
 
 /*
  * nsSMILCSSValueType: Represents a SMIL-animated CSS value.
  */
 class nsSMILCSSValueType : public nsISMILType
 {
 public:
+  // Singleton for nsSMILValue objects to hold onto.
+  static nsSMILCSSValueType sSingleton;
+
+protected:
   // nsISMILType Methods
   // -------------------
   NS_OVERRIDE virtual nsresult Init(nsSMILValue& aValue) const;
   NS_OVERRIDE virtual void     Destroy(nsSMILValue&) const;
   NS_OVERRIDE virtual nsresult Assign(nsSMILValue& aDest,
                                       const nsSMILValue& aSrc) const;
   NS_OVERRIDE virtual nsresult Add(nsSMILValue& aDest,
                                    const nsSMILValue& aValueToAdd,
@@ -66,17 +70,19 @@ public:
   NS_OVERRIDE virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                                const nsSMILValue& aTo,
                                                double& aDistance) const;
   NS_OVERRIDE virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                            const nsSMILValue& aEndVal,
                                            double aUnitDistance,
                                            nsSMILValue& aResult) const;
 
-  /* ---------- Helper methods, not inherited from nsISMILType ---------- */
+public:
+  // Helper Methods
+  // --------------
   /**
    * Sets up the given nsSMILValue to represent the given string value.  The
    * string is interpreted as a value for the given property on the given
    * element.
    *
    * On failure, this method leaves aValue.mType == nsSMILNullType::sSingleton.
    * Otherwise, this method leaves aValue.mType == this class's singleton.
    *
@@ -102,16 +108,16 @@ public:
    * string will be empty.
    *
    * @param       aValue   The nsSMILValue to be converted into a string.
    * @param [out] aString  The string to be populated with the given value.
    * @return               PR_TRUE on success, PR_FALSE on failure.
    */
   static PRBool ValueToString(const nsSMILValue& aValue, nsAString& aString);
 
-  // Singleton for nsSMILValue objects to hold onto.
-  static nsSMILCSSValueType sSingleton;
-
 private:
-  nsSMILCSSValueType() {}
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  nsSMILCSSValueType()  {}
+  ~nsSMILCSSValueType() {}
 };
 
 #endif // NS_SMILCSSVALUETYPE_H_
--- a/content/smil/nsSMILFloatType.h
+++ b/content/smil/nsSMILFloatType.h
@@ -39,28 +39,35 @@
 #ifndef NS_SMILFLOATTYPE_H_
 #define NS_SMILFLOATTYPE_H_
 
 #include "nsISMILType.h"
 
 class nsSMILFloatType : public nsISMILType
 {
 public:
+  // Singleton for nsSMILValue objects to hold onto.
+  static nsSMILFloatType sSingleton;
+
+protected:
+  // nsISMILType Methods
+  // -------------------
   virtual nsresult Init(nsSMILValue& aValue) const;
   virtual void     Destroy(nsSMILValue&) const;
   virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
                                    double& aDistance) const;
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const;
 
-  static nsSMILFloatType sSingleton;
-
 private:
-  nsSMILFloatType() {}
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  nsSMILFloatType()  {}
+  ~nsSMILFloatType() {}
 };
 
 #endif // NS_SMILFLOATTYPE_H_
--- a/content/smil/nsSMILNullType.h
+++ b/content/smil/nsSMILNullType.h
@@ -39,28 +39,38 @@
 #ifndef NS_SMILNULLTYPE_H_
 #define NS_SMILNULLTYPE_H_
 
 #include "nsISMILType.h"
 
 class nsSMILNullType : public nsISMILType
 {
 public:
+  // Singleton for nsSMILValue objects to hold onto.
+  static nsSMILNullType sSingleton;
+
+protected:
+  // nsISMILType Methods
+  // -------------------
   virtual nsresult Init(nsSMILValue& aValue) const { return NS_OK; }
   virtual void Destroy(nsSMILValue& aValue) const {}
   virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
 
   // The remaining methods should never be called, so although they're very
   // simple they don't need to be inline.
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
                                    double& aDistance) const;
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const;
 
-  static nsSMILNullType sSingleton;
+private:
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  nsSMILNullType()  {}
+  ~nsSMILNullType() {}
 };
 
 #endif // NS_SMILNULLTYPE_H_
--- a/content/svg/content/src/nsSVGTransformSMILType.h
+++ b/content/svg/content/src/nsSVGTransformSMILType.h
@@ -101,40 +101,48 @@ class nsSMILValue;
 // Similar conditions hold for Interpolate() which in cases such as to-animation
 // may have use a start-value the base value of the target attribute (which as
 // we have seen above can contain 0..n elements) whilst the end-value comes from
 // the <animateTransform> and so can only hold 1 transform.
 //
 class nsSVGTransformSMILType : public nsISMILType
 {
 public:
-  // nsISMILType
+  // Singleton for nsSMILValue objects to hold onto.
+  static nsSVGTransformSMILType sSingleton;
+
+protected:
+  // nsISMILType Methods
+  // -------------------
   virtual nsresult Init(nsSMILValue& aValue) const;
   virtual void     Destroy(nsSMILValue& aValue) const;
   virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
   virtual nsresult Add(nsSMILValue& aDest,
                        const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult SandwichAdd(nsSMILValue& aDest,
                                const nsSMILValue& aValueToAdd) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
                                    double& aDistance) const;
   virtual nsresult Interpolate(const nsSMILValue& aStartVal,
                                const nsSMILValue& aEndVal,
                                double aUnitDistance,
                                nsSMILValue& aResult) const;
 
+public:
   // Transform array accessors
+  // -------------------------
   static PRUint32 GetNumTransforms(const nsSMILValue& aValue);
   static const nsSVGSMILTransform* GetTransformAt(PRUint32 aIndex,
                                                   const nsSMILValue& aValue);
   static nsresult AppendTransform(const nsSVGSMILTransform& aTransform,
                                   nsSMILValue& aValue);
 
 
-  static nsSVGTransformSMILType sSingleton;
-
 private:
-  nsSVGTransformSMILType() {}
+  // Private constructor & destructor: prevent instances beyond my singleton,
+  // and prevent others from deleting my singleton.
+  nsSVGTransformSMILType()  {}
+  ~nsSVGTransformSMILType() {}
 };
 
 #endif // NS_SVGTRANSFORMSMILTYPE_H_