1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef __mozilla_widget_GfxInfoCollector_h__
9 #define __mozilla_widget_GfxInfoCollector_h__
11 #include "mozilla/Attributes.h"
12 #include "nsStringFwd.h"
13 #include "js/RootingAPI.h"
19 /* this is handy wrapper around JSAPI to make it more pleasant to use.
20 * We collect the JSAPI errors and so that callers don't need to */
21 class MOZ_STACK_CLASS InfoObject
23 friend class GfxInfoBase
;
26 void DefineProperty(const char *name
, int value
);
27 void DefineProperty(const char *name
, nsAString
&value
);
28 void DefineProperty(const char *name
, const char *value
);
31 // We need to ensure that this object lives on the stack so that GC sees it properly
32 explicit InfoObject(JSContext
*aCx
);
33 InfoObject(InfoObject
&);
36 JS::Rooted
<JSObject
*> mObj
;
42 Here's an example usage:
45 Foo::Foo() : mInfoCollector(this, &Foo::GetAweseomeness) {}
47 void GetAwesomeness(InfoObject &obj) {
48 obj.DefineProperty("awesome", mAwesome);
53 GfxInfoCollector<Foo> mInfoCollector;
56 This will define a property on the object
57 returned from calling getInfo() on a
60 gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
61 info = gfxInfo.getInfo();
67 class GfxInfoCollectorBase
70 GfxInfoCollectorBase();
71 virtual void GetInfo(InfoObject
&obj
) = 0;
72 virtual ~GfxInfoCollectorBase();
76 class GfxInfoCollector
: public GfxInfoCollectorBase
79 GfxInfoCollector(T
* aPointer
, void (T::*aFunc
)(InfoObject
&obj
)) : mPointer(aPointer
), mFunc(aFunc
) {
81 virtual void GetInfo(InfoObject
&obj
) override
{
82 (mPointer
->*mFunc
)(obj
);
87 void (T::*mFunc
)(InfoObject
&obj
);