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