diff options
Diffstat (limited to 'Src/Wasabi/api/service/svccache.h')
-rw-r--r-- | Src/Wasabi/api/service/svccache.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Src/Wasabi/api/service/svccache.h b/Src/Wasabi/api/service/svccache.h new file mode 100644 index 00000000..1e989e57 --- /dev/null +++ b/Src/Wasabi/api/service/svccache.h @@ -0,0 +1,43 @@ +#ifndef _SVC_CACHE_H +#define _SVC_CACHE_H + +#include <api/service/svc_enum.h> +#include <bfc/ptrlist.h> + +/** + This is a caching version of SvcEnum. Upon creation, it enumerates all + service factories in the family and keeps them in a list. Then you can + call findService() with a search string to quickly find the service you + want. If you don't have a search string, you can still use a SvcEnum. +*/ + +class SvcCache { +protected: + SvcCache(FOURCC type); + +public: + waServiceFactory *findServiceFactory(const wchar_t *searchval); + +private: + class waServiceFactoryCompare { + public: + static int compareItem(waServiceFactory *p1, waServiceFactory* p2); + static int compareAttrib(const wchar_t *attrib, waServiceFactory *item); + }; + PtrListQuickSorted<waServiceFactory, waServiceFactoryCompare> list; +}; + +template <class T> +class SvcCacheT : public SvcCache { +public: + SvcCacheT() : SvcCache(T::getServiceType()) { } + + T *findService(const char *key, int global_lock=TRUE) { + waServiceFactory *sf = findServiceFactory(key); + if (sf == NULL) return NULL; + T *ret = castService<T>(sf, global_lock); + return ret; + } +}; + +#endif |