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"
18 /* this is handy wrapper around JSAPI to make it more pleasant to use.
19 * We collect the JSAPI errors and so that callers don't need to */
20 class MOZ_STACK_CLASS InfoObject
{
21 friend class GfxInfoBase
;
24 void DefineProperty(const char* name
, int value
);
25 void DefineProperty(const char* name
, const nsAString
& value
);
26 void DefineProperty(const char* name
, const char* value
);
29 // We need to ensure that this object lives on the stack so that GC sees it
31 explicit InfoObject(JSContext
* aCx
);
32 InfoObject(InfoObject
&);
35 JS::Rooted
<JSObject
*> mObj
;
41 Here's an example usage:
44 Foo::Foo() : mInfoCollector(this, &Foo::GetAweseomeness) {}
46 void GetAwesomeness(InfoObject &obj) {
47 obj.DefineProperty("awesome", mAwesome);
52 GfxInfoCollector<Foo> mInfoCollector;
55 This will define a property on the object
56 returned from calling getInfo() on a
59 gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
60 info = gfxInfo.getInfo();
66 class GfxInfoCollectorBase
{
68 GfxInfoCollectorBase();
69 virtual void GetInfo(InfoObject
& obj
) = 0;
70 virtual ~GfxInfoCollectorBase();
74 class GfxInfoCollector
: public GfxInfoCollectorBase
{
76 GfxInfoCollector(T
* aPointer
, void (T::*aFunc
)(InfoObject
& obj
))
77 : mPointer(aPointer
), mFunc(aFunc
) {}
78 virtual void GetInfo(InfoObject
& obj
) override
{ (mPointer
->*mFunc
)(obj
); }
82 void (T::*mFunc
)(InfoObject
& obj
);
86 } // namespace mozilla