WvStreams
wvmoniker.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * Support for monikers, which are strings that you can pass to a magic
00006  * factory to get objects supporting a particular interface, without actually
00007  * knowing anything about the constructor for those objects.
00008  */
00009 #ifndef __WVMONIKER_H
00010 #define __WVMONIKER_H
00011 
00012 #include "wvstring.h"
00013 #include "wvxplc.h"
00014 
00015 class WvMonikerRegistry;
00016 
00017 typedef void *WvMonikerCreateFunc(WvStringParm parms, IObject *obj);
00018 
00031 class WvMonikerBase
00032 {
00033 protected:
00034     WvMonikerBase(const UUID &iid, WvStringParm _id,
00035                   WvMonikerCreateFunc *func, const bool override = false);
00036     ~WvMonikerBase();
00037     
00038 public:
00039     WvString id;
00040     WvMonikerRegistry *reg;
00041 };
00042 
00043 
00060 template <class T>
00061 class WvMoniker : public WvMonikerBase
00062 {
00063 public:
00064     typedef T *CreateFunc(WvStringParm parms, IObject *obj);
00065     
00066     WvMoniker(WvStringParm _id, CreateFunc *_func, const bool override = false)
00067         : WvMonikerBase(XPLC_IID<T>::get(), _id, (WvMonikerCreateFunc *)_func,
00068                         override)
00069     { 
00070         // this looks pointless, but it ensures that T* can be safely,
00071         // automatically downcast to IObject*.  That means T is really derived
00072         // from IObject, which is very important. The 'for' avoids a
00073         // warning.
00074         for(IObject *silly = (T *)NULL; silly; )
00075             ;
00076     };
00077 };
00078 
00079 
00089 void *wvcreate(const UUID &iid, WvStringParm s, IObject *obj);
00090 
00091 
00103 template <class T>
00104 inline T *wvcreate(WvStringParm s, IObject *obj = 0)
00105 {
00106     return (T *)(wvcreate(XPLC_IID<T>::get(), s, obj));
00107 }
00108 
00109 
00110 #endif // __WVMONIKER_H