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 nsSMILRepeatCount_h michael@0: #define nsSMILRepeatCount_h michael@0: michael@0: #include "nsDebug.h" michael@0: #include michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsSMILRepeatCount michael@0: // michael@0: // A tri-state non-negative floating point number for representing the number of michael@0: // times an animation repeat, i.e. the SMIL repeatCount attribute. michael@0: // michael@0: // The three states are: michael@0: // 1. not-set michael@0: // 2. set (with non-negative, non-zero count value) michael@0: // 3. indefinite michael@0: // michael@0: class nsSMILRepeatCount michael@0: { michael@0: public: michael@0: nsSMILRepeatCount() : mCount(kNotSet) {} michael@0: explicit nsSMILRepeatCount(double aCount) michael@0: : mCount(kNotSet) { SetCount(aCount); } michael@0: michael@0: operator double() const { michael@0: MOZ_ASSERT(IsDefinite(), michael@0: "Converting indefinite or unset repeat count to double"); michael@0: return mCount; michael@0: } michael@0: bool IsDefinite() const { michael@0: return mCount != kNotSet && mCount != kIndefinite; michael@0: } michael@0: bool IsIndefinite() const { return mCount == kIndefinite; } michael@0: bool IsSet() const { return mCount != kNotSet; } michael@0: michael@0: nsSMILRepeatCount& operator=(double aCount) michael@0: { michael@0: SetCount(aCount); michael@0: return *this; michael@0: } michael@0: void SetCount(double aCount) michael@0: { michael@0: NS_ASSERTION(aCount > 0.0, "Negative or zero repeat count"); michael@0: mCount = aCount > 0.0 ? aCount : kNotSet; michael@0: } michael@0: void SetIndefinite() { mCount = kIndefinite; } michael@0: void Unset() { mCount = kNotSet; } michael@0: michael@0: private: michael@0: static const double kNotSet; michael@0: static const double kIndefinite; michael@0: michael@0: double mCount; michael@0: }; michael@0: michael@0: #endif