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);
00018 
00031 class WvMonikerBase
00032 {
00033 protected:
00034     WvMonikerBase(const UUID &iid, WvStringParm _id,
00035                   WvMonikerCreateFunc *func);
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);
00065     
00066     WvMoniker(WvStringParm _id, CreateFunc *_func)
00067         : WvMonikerBase(XPLC_IID<T>::get(), _id, (WvMonikerCreateFunc *)_func)
00068     { 
00069         // this looks pointless, but it ensures that T* can be safely,
00070         // automatically downcast to IObject*.  That means T is really derived
00071         // from IObject, which is very important. The 'for' avoids a
00072         // warning.
00073         for(IObject *silly = (T *)NULL; silly; )
00074             ;
00075     };
00076 };
00077 
00078 
00088 void *wvcreate(const UUID &iid, WvStringParm s);
00089 
00090 
00102 template <class T>
00103 inline T *wvcreate(WvStringParm s)
00104 {
00105     return (T *)(wvcreate(XPLC_IID<T>::get(), s));
00106 }
00107 
00108 
00109 #endif // __WVMONIKER_H

Generated on Mon Feb 5 10:54:29 2007 for WvStreams by  doxygen 1.5.1