CrystalSpace

Public API Reference

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

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 
00029 #include "csutil/scf.h"
00030 
00031 struct iObjectRegistryIterator;
00032 
00033 SCF_VERSION (iObjectRegistry, 0, 0, 4);
00034 
00052 struct iObjectRegistry : public iBase
00053 {
00054   // Allow implicit casts through static function.
00055   CS_IMPLEMENT_IMPLICIT_PTR_CAST (iObjectRegistry);
00056 
00060   virtual void Clear () = 0;
00061 
00078   virtual bool Register (iBase* obj, char const* tag = 0) = 0;
00079 
00091   virtual void Unregister (iBase* obj, char const* tag = 0) = 0;
00092 
00099   virtual iBase* Get (char const* tag) = 0;
00100 
00108   virtual iBase* Get (char const* tag, scfInterfaceID id, int version) = 0;
00109 
00116   virtual csPtr<iObjectRegistryIterator> Get (
00117         scfInterfaceID id, int version) = 0;
00118 
00125   virtual csPtr<iObjectRegistryIterator> Get () = 0;
00126 };
00127 
00128 SCF_VERSION (iObjectRegistryIterator, 0, 1, 0);
00129 
00134 struct iObjectRegistryIterator : public iBase
00135 {
00140   virtual bool Reset () = 0;
00141 
00145   virtual const char* GetCurrentTag () = 0;
00146 
00150   virtual bool HasNext () = 0;
00151 
00155   virtual iBase* Next () = 0;
00156 };
00157 
00163 template<class Interface>
00164 inline csPtr<Interface> csQueryRegistry (iObjectRegistry *Reg)
00165 { 
00166   iBase *base = Reg->Get (scfInterfaceTraits<Interface>::GetName (),
00167               scfInterfaceTraits<Interface>::GetID (),
00168               scfInterfaceTraits<Interface>::GetVersion ());
00169 
00170   if (base == 0) return csPtr<Interface> (0);
00171 
00172   Interface *x = (Interface*)base->QueryInterface (
00173     scfInterfaceTraits<Interface>::GetID (),
00174     scfInterfaceTraits<Interface>::GetVersion ());
00175 
00176   if (x) base->DecRef (); //release our base interface
00177   return csPtr<Interface> (x);
00178 }  
00179   
00183 inline csPtr<iBase> csQueryRegistryTag (iObjectRegistry *Reg, const char* Tag)
00184 {  
00185   return csPtr<iBase> (Reg->Get (Tag));
00186 }  
00187    
00191 template<class Interface>
00192 inline csPtr<Interface> csQueryRegistryTagInterface (
00193   iObjectRegistry *Reg, const char* Tag)
00194 {  
00195   iBase *base = Reg->Get (Tag,
00196               scfInterfaceTraits<Interface>::GetID (),
00197               scfInterfaceTraits<Interface>::GetVersion ());
00198 
00199   if (base == 0) return csPtr<Interface> (0);
00200 
00201   Interface *x = (Interface*)base->QueryInterface (
00202     scfInterfaceTraits<Interface>::GetID (),
00203     scfInterfaceTraits<Interface>::GetVersion ());
00204 
00205   if (x) base->DecRef (); //release our base interface
00206   return csPtr<Interface> (x);
00207 }  
00208 
00213 #define CS_QUERY_REGISTRY_TAG(Reg, Tag) (csQueryRegistryTag(Reg, Tag))
00214 
00218 #define CS_QUERY_REGISTRY(Reg,Interface) (csQueryRegistry<Interface>(Reg))
00219 
00223 #define CS_QUERY_REGISTRY_TAG_INTERFACE(Reg, Tag, Interface) \
00224   (csQueryRegistryTagInterface<Interface>(Reg, Tag))
00225 
00226 #endif // __CS_IUTIL_OBJREG_H__
00227 

Generated for Crystal Space by doxygen 1.4.4