Bug 984761 - Add AttributeMap::EnumerateRead. r=roc

This commit is contained in:
Markus Stange 2014-03-20 10:12:44 +08:00
parent 12b3f841f0
commit be5c6e3640
2 changed files with 33 additions and 0 deletions

View File

@ -1603,6 +1603,8 @@ struct FilterAttribute {
return !(*this == aOther);
}
AttributeType Type() const { return mType; }
#define MAKE_CONSTRUCTOR_AND_ACCESSOR_BASIC(type, typeLabel) \
FilterAttribute(type aValue) \
: mType(AttributeType::e##typeLabel), m##typeLabel(aValue) \
@ -1839,6 +1841,34 @@ AttributeMap::operator==(const AttributeMap& aOther) const
return matchingMap.matches;
}
namespace {
struct HandlerWithUserData
{
AttributeMap::AttributeHandleCallback handler;
void* userData;
};
}
static PLDHashOperator
PassAttributeToHandleCallback(const uint32_t& aAttributeName,
Attribute* aAttribute,
void* aHandlerWithUserData)
{
HandlerWithUserData* handlerWithUserData =
static_cast<HandlerWithUserData*>(aHandlerWithUserData);
return handlerWithUserData->handler(AttributeName(aAttributeName),
aAttribute->Type(),
handlerWithUserData->userData) ?
PL_DHASH_NEXT : PL_DHASH_STOP;
}
void
AttributeMap::EnumerateRead(AttributeMap::AttributeHandleCallback aCallback, void* aUserData) const
{
HandlerWithUserData handlerWithUserData = { aCallback, aUserData };
mMap.EnumerateRead(PassAttributeToHandleCallback, &handlerWithUserData);
}
#define MAKE_ATTRIBUTE_HANDLERS_BASIC(type, typeLabel, defaultValue) \
type \
AttributeMap::Get##typeLabel(AttributeName aName) const { \

View File

@ -206,6 +206,9 @@ public:
AttributeMap GetAttributeMap(AttributeName aName) const;
const nsTArray<float>& GetFloats(AttributeName aName) const;
typedef bool (*AttributeHandleCallback)(AttributeName aName, AttributeType aType, void* aUserData);
void EnumerateRead(AttributeHandleCallback aCallback, void* aUserData) const;
private:
mutable nsClassHashtable<nsUint32HashKey, FilterAttribute> mMap;
};