diff -r 000000000000 -r 6474c204b198 gfx/2d/UserData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfx/2d/UserData.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,128 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZILLA_GFX_USERDATA_H_ +#define MOZILLA_GFX_USERDATA_H_ + +#include +#include "Types.h" +#include "mozilla/Assertions.h" + +namespace mozilla { +namespace gfx { + +struct UserDataKey { + int unused; +}; + +/* this class is basically a clone of the user data concept from cairo */ +class UserData +{ + typedef void (*destroyFunc)(void *data); +public: + UserData() : count(0), entries(nullptr) {} + + /* Attaches untyped userData associated with key. destroy is called on destruction */ + void Add(UserDataKey *key, void *userData, destroyFunc destroy) + { + for (int i=0; i(realloc(entries, sizeof(Entry)*(count+1))); + + if (!entries) { + MOZ_CRASH(); + } + + entries[count].key = key; + entries[count].userData = userData; + entries[count].destroy = destroy; + + count++; + } + + /* Remove and return user data associated with key, without destroying it */ + void* Remove(UserDataKey *key) + { + for (int i=0; i