#ifndef IDBKey_h
#define IDBKey_h
#if ENABLE(INDEXED_DATABASE)
#include "PlatformString.h"
#include <wtf/Forward.h>
#include <wtf/Threading.h>
namespace WebCore {
class IDBKey : public ThreadSafeRefCounted<IDBKey> {
public:
static PassRefPtr<IDBKey> createNull()
{
RefPtr<IDBKey> idbKey(new IDBKey());
idbKey->m_type = NullType;
return idbKey.release();
}
static PassRefPtr<IDBKey> createNumber(double number)
{
RefPtr<IDBKey> idbKey(new IDBKey());
idbKey->m_type = NumberType;
idbKey->m_number = number;
return idbKey.release();
}
static PassRefPtr<IDBKey> createString(const String& string)
{
RefPtr<IDBKey> idbKey(new IDBKey());
idbKey->m_type = StringType;
idbKey->m_string = string;
return idbKey.release();
}
static PassRefPtr<IDBKey> createDate(double date)
{
RefPtr<IDBKey> idbKey(new IDBKey());
idbKey->m_type = DateType;
idbKey->m_date = date;
return idbKey.release();
}
~IDBKey();
enum Type {
NullType = 0, StringType,
DateType,
NumberType
};
Type type() const { return m_type; }
const String& string() const
{
ASSERT(m_type == StringType);
return m_string;
}
double date() const
{
ASSERT(m_type == DateType);
return m_date;
}
double number() const
{
ASSERT(m_type == NumberType);
return m_number;
}
bool isLessThan(const IDBKey* other) const;
bool isEqual(const IDBKey* other) const;
using ThreadSafeRefCounted<IDBKey>::ref;
using ThreadSafeRefCounted<IDBKey>::deref;
private:
IDBKey();
Type m_type;
String m_string;
double m_date;
double m_number;
};
}
#endif // ENABLE(INDEXED_DATABASE)
#endif // IDBKey_h