| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# iutil/objreg.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2001 by Jorrit Tyberghein
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_IUTIL_OBJREG_H__
    00020 #define __CS_IUTIL_OBJREG_H__
    00021
    00030 #include "csutil/ref.h"
    00031 #include "csutil/scf_interface.h"
    00032
    00033 struct iObjectRegistryIterator;
    00034
    00048 struct iObjectRegistry : public virtual iBase
    00049 {
    00050   SCF_INTERFACE(iObjectRegistry, 2,0,0);
    00051   // Allow implicit casts through static function.
    00052   CS_IMPLEMENT_IMPLICIT_PTR_CAST (iObjectRegistry);
    00053
    00057   virtual void Clear () = 0;
    00058
    00075   virtual bool Register (iBase* obj, char const* tag = 0) = 0;
    00076
    00088   virtual void Unregister (iBase* obj, char const* tag = 0) = 0;
    00089
    00096   virtual iBase* Get (char const* tag) = 0;
    00097
    00105   virtual iBase* Get (char const* tag, scfInterfaceID id, int version) = 0;
    00106
    00113   virtual csPtr<iObjectRegistryIterator> Get (
    00114         scfInterfaceID id, int version) = 0;
    00115
    00122   virtual csPtr<iObjectRegistryIterator> Get () = 0;
    00123 };
    00124
    00125
    00130 struct iObjectRegistryIterator : public virtual iBase
    00131 {
    00132   SCF_INTERFACE(iObjectRegistryIterator, 2,0,0);
    00137   virtual bool Reset () = 0;
    00138
    00142   virtual const char* GetCurrentTag () = 0;
    00143
    00147   virtual bool HasNext () = 0;
    00148
    00152   virtual iBase* Next () = 0;
    00153 };
    00154
    00160 template<class Interface>
    00161 inline csPtr<Interface> csQueryRegistry (iObjectRegistry *Reg)
    00162 {
    00163   iBase *base = Reg->Get (scfInterfaceTraits<Interface>::GetName (),
    00164               scfInterfaceTraits<Interface>::GetID (),
    00165               scfInterfaceTraits<Interface>::GetVersion ());
    00166
    00167   if (base == 0) return csPtr<Interface> (0);
    00168
    00169   Interface *x = (Interface*)base->QueryInterface (
    00170     scfInterfaceTraits<Interface>::GetID (),
    00171     scfInterfaceTraits<Interface>::GetVersion ());
    00172
    00173   if (x) base->DecRef (); //release our base interface
    00174   return csPtr<Interface> (x);
    00175 }
    00176
    00180 inline csPtr<iBase> csQueryRegistryTag (iObjectRegistry *Reg, const char* Tag)
    00181 {
    00182   return csPtr<iBase> (Reg->Get (Tag));
    00183 }
    00184
    00188 template<class Interface>
    00189 inline csPtr<Interface> csQueryRegistryTagInterface (
    00190   iObjectRegistry *Reg, const char* Tag)
    00191 {
    00192   iBase *base = Reg->Get (Tag,
    00193               scfInterfaceTraits<Interface>::GetID (),
    00194               scfInterfaceTraits<Interface>::GetVersion ());
    00195
    00196   if (base == 0) return csPtr<Interface> (0);
    00197
    00198   Interface *x = (Interface*)base->QueryInterface (
    00199     scfInterfaceTraits<Interface>::GetID (),
    00200     scfInterfaceTraits<Interface>::GetVersion ());
    00201
    00202   if (x) base->DecRef (); //release our base interface
    00203   return csPtr<Interface> (x);
    00204 }
    00205
    00210 #define CS_QUERY_REGISTRY_TAG(Reg, Tag) (csQueryRegistryTag(Reg, Tag))
    00211
    00215 #define CS_QUERY_REGISTRY(Reg,Interface) (csQueryRegistry<Interface>(Reg))
    00216
    00220 #define CS_QUERY_REGISTRY_TAG_INTERFACE(Reg, Tag, Interface) \
    00221   (csQueryRegistryTagInterface<Interface>(Reg, Tag))
    00222
    00223 #endif // __CS_IUTIL_OBJREG_H__
    00224