2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Support for monikers, which are strings that you can pass to a magic
6 * factory to get objects supporting a particular interface, without actually
7 * knowing anything about the constructor for those objects.
15 class WvMonikerRegistry
;
17 typedef void *WvMonikerCreateFunc(WvStringParm parms
, IObject
*obj
);
20 * WvMonikerBase is an auto-registration class for putting things into
21 * a WvMonikerRegistry. When a WvMonikerBase instance is created, it
22 * registers a moniker prefix ("test:", "ssl:", "ini:", etc) and a factory
23 * function that can be used to create an IObject using that prefix.
25 * When the instance is destroyed, it auto-unregisters the moniker prefix
28 * You can't actually create one of these, because it's not typesafe. See
29 * WvMoniker<T> instead.
34 WvMonikerBase(const UUID
&iid
, WvStringParm _id
,
35 WvMonikerCreateFunc
*func
, const bool override
= false);
40 WvMonikerRegistry
*reg
;
45 * A type-safe version of WvMonikerBase that lets you provide create functions
46 * for object types other than IObject. (The objects themselves have to
47 * be derived from IObject, however.)
49 * See WvMonikerBase for details.
52 * static IWvStream *createfunc(WvStringParm s, IObject *obj,
55 * return new WvStream;
58 * static WvMoniker<IWvStream> registration("ssl", createfunc);
61 class WvMoniker
: public WvMonikerBase
64 typedef T
*CreateFunc(WvStringParm parms
, IObject
*obj
);
66 WvMoniker(WvStringParm _id
, CreateFunc
*_func
, const bool override
= false)
67 : WvMonikerBase(XPLC_IID
<T
>::get(), _id
, (WvMonikerCreateFunc
*)_func
,
70 // this looks pointless, but it ensures that T* can be safely,
71 // automatically downcast to IObject*. That means T is really derived
72 // from IObject, which is very important. The 'for' avoids a
74 for(IObject
*silly
= (T
*)NULL
; silly
; )
81 * Create an object registered in a WvMonikerRegistry. The iid specifies
82 * which registry to look in, and s, obj, and userdata are the parameters to
83 * supply to the object's factory. Most factories need only 's', which is the
86 * Most people don't use this function. See the templated, type-safe version
87 * of wvcreate() below.
89 void *wvcreate(const UUID
&iid
, WvStringParm s
, IObject
*obj
);
93 * Create an object registered in a WvMonikerRegistry. Exactly which
94 * registry is determined by the template type T.
96 * s, obj, and userdata are the parameters to supply to the object's
97 * factory. Most factories need only 's', which is the moniker itself.
100 * IWvStream *s = wvcreate<IWvStream>("tcp:localhost:25");
101 * IWvStream *s_ssl = wvcreate<IWvStream>("ssl:", s);
104 inline T
*wvcreate(WvStringParm s
, IObject
*obj
= 0)
106 return (T
*)(wvcreate(XPLC_IID
<T
>::get(), s
, obj
));
110 #endif // __WVMONIKER_H