Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvmoniker.h

Go to the documentation of this file.
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 "wvxplc.h" 00013 #include "wvstring.h" 00014 00015 class WvMonikerRegistry; 00016 00017 typedef IObject *WvMonikerCreateFunc(WvStringParm parms, 00018 IObject *obj, void *userdata); 00019 00020 /** 00021 * WvMonikerBase is an auto-registration class for putting things into 00022 * a WvMonikerRegistry. When a WvMonikerBase instance is created, it 00023 * registers a moniker prefix ("test:", "ssl:", "ini:", etc) and a factory 00024 * function that can be used to create an IObject using that prefix. 00025 * 00026 * When the instance is destroyed, it auto-unregisters the moniker prefix 00027 * from the registry. 00028 * 00029 * You can't actually create one of these, because it's not typesafe. See 00030 * WvMoniker<T> instead. 00031 */ 00032 class WvMonikerBase 00033 { 00034 protected: 00035 WvMonikerBase(const XUUID &iid, WvStringParm _id, 00036 WvMonikerCreateFunc *func); 00037 ~WvMonikerBase(); 00038 00039 public: 00040 WvString id; 00041 WvMonikerRegistry *reg; 00042 }; 00043 00044 00045 /** 00046 * A type-safe version of WvMonikerBase that lets you provide create functions 00047 * for object types other than IObject. (The objects themselves have to 00048 * be derived from IObject, however.) 00049 * 00050 * See WvMonikerBase for details. 00051 * 00052 * Example: 00053 * static IWvStream *createfunc(WvStringParm s, IObject *obj, 00054 * void *userdata) 00055 * { 00056 * return new WvStream; 00057 * } 00058 * 00059 * static WvMoniker<IWvStream> registration("ssl", createfunc); 00060 */ 00061 template <class T> 00062 class WvMoniker : public WvMonikerBase 00063 { 00064 public: 00065 typedef T *CreateFunc(WvStringParm parms, IObject *obj, void *userdata); 00066 IObject *silly; 00067 00068 WvMoniker(WvStringParm _id, CreateFunc *_func) 00069 : WvMonikerBase(XIID<T>::get(), _id, (WvMonikerCreateFunc *)_func) 00070 { 00071 // this looks pointless, but it ensures that T* can be safely, 00072 // automatically downcast to IObject*. That means T is really derived 00073 // from IObject, which is very important. 00074 silly = (T *)NULL; 00075 }; 00076 }; 00077 00078 00079 /** 00080 * Create an object registered in a WvMonikerRegistry. The iid specifies 00081 * which registry to look in, and s, obj, and userdata are the parameters to 00082 * supply to the object's factory. Most factories need only 's', which is the 00083 * moniker itself. 00084 * 00085 * Most people don't use this function. See the templated, type-safe version 00086 * of wvcreate() below. 00087 */ 00088 IObject *wvcreate(const XUUID &iid, 00089 WvStringParm s, IObject *obj = NULL, void *userdata = NULL); 00090 00091 00092 /** 00093 * Create an object registered in a WvMonikerRegistry. Exactly which 00094 * registry is determined by the template type T. 00095 * 00096 * s, obj, and userdata are the parameters to supply to the object's 00097 * factory. Most factories need only 's', which is the moniker itself. 00098 * 00099 * Example: 00100 * IWvStream *s = wvcreate<IWvStream>("tcp:localhost:25"); 00101 * IWvStream *s_ssl = wvcreate<IWvStream>("ssl:", s); 00102 */ 00103 template <class T> 00104 inline T *wvcreate(WvStringParm s, IObject *obj = NULL, void *userdata = NULL) 00105 { 00106 return mutate<T>(wvcreate(XIID<T>::get(), s, obj, userdata)); 00107 } 00108 00109 00110 #endif // __WVMONIKER_H

Generated on Tue Oct 5 01:09:20 2004 for WvStreams by doxygen 1.3.7