michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_SMILVALUE_H_ michael@0: #define NS_SMILVALUE_H_ michael@0: michael@0: #include "nsISMILType.h" michael@0: #include "nsSMILNullType.h" michael@0: michael@0: /** michael@0: * Although objects of this type are generally only created on the stack and michael@0: * only exist during the taking of a new time sample, that's not always the michael@0: * case. The nsSMILValue objects obtained from attributes' base values are michael@0: * cached so that the SMIL engine can make certain optimizations during a michael@0: * sample if the base value has not changed since the last sample (potentially michael@0: * avoiding recomposing). These nsSMILValue objects typically live much longer michael@0: * than a single sample. michael@0: */ michael@0: class nsSMILValue michael@0: { michael@0: public: michael@0: nsSMILValue() : mU(), mType(nsSMILNullType::Singleton()) { } michael@0: explicit nsSMILValue(const nsISMILType* aType); michael@0: nsSMILValue(const nsSMILValue& aVal); michael@0: michael@0: ~nsSMILValue() michael@0: { michael@0: mType->Destroy(*this); michael@0: } michael@0: michael@0: const nsSMILValue& operator=(const nsSMILValue& aVal); michael@0: michael@0: // Equality operators. These are allowed to be conservative (return false michael@0: // more than you'd expect) - see comment above nsISMILType::IsEqual. michael@0: bool operator==(const nsSMILValue& aVal) const; michael@0: bool operator!=(const nsSMILValue& aVal) const { michael@0: return !(*this == aVal); michael@0: } michael@0: michael@0: bool IsNull() const michael@0: { michael@0: return (mType == nsSMILNullType::Singleton()); michael@0: } michael@0: michael@0: // Swaps the member data (mU & mPtr) of |this| with |aOther| michael@0: void Swap(nsSMILValue& aOther); michael@0: michael@0: nsresult Add(const nsSMILValue& aValueToAdd, uint32_t aCount = 1); michael@0: nsresult SandwichAdd(const nsSMILValue& aValueToAdd); michael@0: nsresult ComputeDistance(const nsSMILValue& aTo, double& aDistance) const; michael@0: nsresult Interpolate(const nsSMILValue& aEndVal, michael@0: double aUnitDistance, michael@0: nsSMILValue& aResult) const; michael@0: michael@0: union { michael@0: bool mBool; michael@0: uint64_t mUint; michael@0: int64_t mInt; michael@0: double mDouble; michael@0: struct { michael@0: float mAngle; michael@0: uint16_t mUnit; michael@0: uint16_t mOrientType; michael@0: } mOrient; michael@0: int32_t mIntPair[2]; michael@0: float mNumberPair[2]; michael@0: void* mPtr; michael@0: } mU; michael@0: const nsISMILType* mType; michael@0: michael@0: protected: michael@0: void InitAndCheckPostcondition(const nsISMILType* aNewType); michael@0: void DestroyAndCheckPostcondition(); michael@0: void DestroyAndReinit(const nsISMILType* aNewType); michael@0: }; michael@0: michael@0: #endif // NS_SMILVALUE_H_