contrib/oxl/osl/osl_topology.h
Go to the documentation of this file.
00001 // This is oxl/osl/osl_topology.h
00002 #ifndef osl_topology_h_
00003 #define osl_topology_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author fsm
00010 //
00011 // *** This is a permanent conversion hack ***
00012 // Do not expect that future Canny's will provide output in this form.
00013 // Do not expect this code to be supported in any way whatsoever.
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   10 Sep. 2004 Peter Vanroose  Inlined all 1-line methods in class decl
00018 // \endverbatim
00019 
00020 #include <vcl_list.h>
00021 #include <vbl/vbl_ref_count.h>
00022 
00023 template <class T>
00024 inline T fsm_pop(vcl_list<T> *l)
00025 {
00026   T tmp = l->front();
00027   l->pop_front();
00028   return tmp;
00029 }
00030 
00031 //--------------------------------------------------------------------------------
00032 
00033 struct osl_stash_link;
00034 
00035 struct osl_topology_base : public vbl_ref_count
00036 {
00037   osl_topology_base(osl_topology_base const& x)
00038     : vbl_ref_count(), id(x.id), stash_head(x.stash_head) {}
00039   int id;
00040   osl_topology_base();
00041   ~osl_topology_base();
00042   void SetId(int );
00043   int GetId() const;
00044 
00045   //: add another stash under that name.
00046   void  stash_add     (char const *name, void const *data, void (*dtor)(void *) = 0);
00047   //: replace first stash ith given name. the old dtor is \e not called.
00048   void  stash_replace (char const *name, void const *data, void (*dtor)(void *) = 0);
00049   //: return first stash with given name, 0 if none.
00050   void *stash_retrieve(char const *name) const;
00051   //: remove first stash with given name. the dtor is \e not called.
00052   void *stash_remove  (char const *name);
00053  private:
00054   osl_stash_link *stash_head;
00055 };
00056 
00057 //--------------------------------------------------------------------------------
00058 
00059 //: call ref() on every object pointed to by an element of C.
00060 template <class Container>
00061 inline
00062 void osl_topology_ref(Container &C)
00063 {
00064   for (typename Container::iterator i=C.begin(); i!=C.end(); ++i)
00065     if (*i)
00066       (*i)->ref();
00067 }
00068 
00069 //: call unref() on every object pointed to by an element of C.
00070 template <class Container>
00071 inline
00072 void osl_topology_unref(Container &C)
00073 {
00074   for (typename Container::iterator i=C.begin(); i!=C.end(); ++i)
00075     if (*i)
00076       (*i)->unref();
00077 }
00078 
00079 #define OSL_TOPOLOGY_REF_UNREF_INSTANTIATE(C) \
00080 VCL_INSTANTIATE_INLINE(void osl_topology_ref(C &)); \
00081 VCL_INSTANTIATE_INLINE(void osl_topology_unref(C &))
00082 
00083 #endif // osl_topology_h_