WvStreams
wvmoniker.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
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.
8  */
9 #ifndef __WVMONIKER_H
10 #define __WVMONIKER_H
11 
12 #include "wvstring.h"
13 #include "wvxplc.h"
14 
15 class WvMonikerRegistry;
16 
17 typedef void *WvMonikerCreateFunc(WvStringParm parms, IObject *obj);
18 
32 {
33 protected:
34  WvMonikerBase(const UUID &iid, WvStringParm _id,
35  WvMonikerCreateFunc *func, const bool override = false);
36  ~WvMonikerBase();
37 
38 public:
39  WvString id;
40  WvMonikerRegistry *reg;
41 };
42 
43 
60 template <class T>
61 class WvMoniker : public WvMonikerBase
62 {
63 public:
64  typedef T *CreateFunc(WvStringParm parms, IObject *obj);
65 
66  WvMoniker(WvStringParm _id, CreateFunc *_func, const bool override = false)
67  : WvMonikerBase(XPLC_IID<T>::get(), _id, (WvMonikerCreateFunc *)_func,
68  override)
69  {
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
73  // warning.
74  for(IObject *silly = (T *)NULL; silly; )
75  ;
76  };
77 };
78 
79 
89 void *wvcreate(const UUID &iid, WvStringParm s, IObject *obj);
90 
91 
103 template <class T>
104 inline T *wvcreate(WvStringParm s, IObject *obj = 0)
105 {
106  return (T *)(wvcreate(XPLC_IID<T>::get(), s, obj));
107 }
108 
109 
110 #endif // __WVMONIKER_H
XPLC_IID
Definition: uuid.h:128
WvMonikerRegistry
A list for holding moniker-prefix to factory-function mappings.
Definition: wvmonikerregistry.h:18
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvMoniker
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:61
IObject
Definition: IObject.h:65
WvMonikerBase
WvMonikerBase is an auto-registration class for putting things into a WvMonikerRegistry.
Definition: wvmoniker.h:31
_GUID
The structure underlying UUIDs.
Definition: uuid.h:94