#ifndef CounterDirectives_h
#define CounterDirectives_h
#include "wtf/HashMap.h"
#include "wtf/MathExtras.h"
#include "wtf/RefPtr.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/AtomicStringHash.h"
namespace WebCore {
class CounterDirectives {
public:
CounterDirectives()
: m_isResetSet(false)
, m_isIncrementSet(false)
, m_resetValue(0)
, m_incrementValue(0)
{
}
bool isReset() const { return m_isResetSet; }
int resetValue() const { return m_resetValue; }
void setResetValue(int value)
{
m_resetValue = value;
m_isResetSet = true;
}
void clearReset()
{
m_resetValue = 0;
m_isResetSet = false;
}
void inheritReset(CounterDirectives& parent)
{
m_resetValue = parent.m_resetValue;
m_isResetSet = parent.m_isResetSet;
}
bool isIncrement() const { return m_isIncrementSet; }
int incrementValue() const { return m_incrementValue; }
void addIncrementValue(int value)
{
m_incrementValue = clampToInteger((double)m_incrementValue + value);
m_isIncrementSet = true;
}
void clearIncrement()
{
m_incrementValue = 0;
m_isIncrementSet = false;
}
void inheritIncrement(CounterDirectives& parent)
{
m_incrementValue = parent.m_incrementValue;
m_isIncrementSet = parent.m_isIncrementSet;
}
bool isDefined() const { return isReset() || isIncrement(); }
int combinedValue() const
{
ASSERT(m_isResetSet || !m_resetValue);
ASSERT(m_isIncrementSet || !m_incrementValue);
return m_resetValue + m_incrementValue;
}
private:
bool m_isResetSet;
bool m_isIncrementSet;
int m_resetValue;
int m_incrementValue;
};
bool operator==(const CounterDirectives&, const CounterDirectives&);
inline bool operator!=(const CounterDirectives& a, const CounterDirectives& b) { return !(a == b); }
typedef HashMap<AtomicString, CounterDirectives> CounterDirectiveMap;
PassOwnPtr<CounterDirectiveMap> clone(const CounterDirectiveMap&);
}
#endif