SVGAnimatedEnumerationPropertyTearOff.h [plain text]
#pragma once
#include "SVGAnimatedStaticPropertyTearOff.h"
#include "SVGException.h"
#include "SVGPropertyTraits.h"
namespace WebCore {
template<typename EnumType>
class SVGAnimatedEnumerationPropertyTearOff final : public SVGAnimatedStaticPropertyTearOff<unsigned> {
public:
const unsigned& baseVal() final
{
const unsigned& baseVal = SVGAnimatedStaticPropertyTearOff::baseVal();
if (baseVal > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue())
return m_outOfRangeEnumValue;
return baseVal;
}
const unsigned& animVal() final
{
const unsigned& animVal = SVGAnimatedStaticPropertyTearOff::animVal();
if (animVal > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue())
return m_outOfRangeEnumValue;
return animVal;
}
ExceptionOr<void> setBaseVal(const unsigned& property) final
{
if (!property || property > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue())
return Exception { SVGException::SVG_INVALID_VALUE_ERR };
return SVGAnimatedStaticPropertyTearOff<unsigned>::setBaseVal(property);
}
static Ref<SVGAnimatedEnumerationPropertyTearOff<EnumType>> create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, EnumType& property)
{
ASSERT(contextElement);
return adoptRef(*new SVGAnimatedEnumerationPropertyTearOff<EnumType>(contextElement, attributeName, animatedPropertyType, reinterpret_cast<unsigned&>(property)));
}
EnumType& currentAnimatedValue()
{
unsigned& animatedValue = SVGAnimatedStaticPropertyTearOff<unsigned>::currentAnimatedValue();
ASSERT(animatedValue <= SVGPropertyTraits<EnumType>::highestEnumValue());
return reinterpret_cast<EnumType&>(animatedValue);
}
private:
SVGAnimatedEnumerationPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, unsigned& property)
: SVGAnimatedStaticPropertyTearOff<unsigned>(contextElement, attributeName, animatedPropertyType, property)
{
}
static unsigned m_outOfRangeEnumValue;
};
template<typename EnumType>
unsigned SVGAnimatedEnumerationPropertyTearOff<EnumType>::m_outOfRangeEnumValue = 0;
}