1 // This is oxl/osl/osl_topology.h
2 #ifndef osl_topology_h_
3 #define osl_topology_h_
4 //:
5 // \file
6 // \author fsm
7 //
8 // *** This is a permanent conversion hack ***
9 // Do not expect that future Canny's will provide output in this form.
10 // Do not expect this code to be supported in any way whatsoever.
11 //
12 // \verbatim
13 //  Modifications
14 //   10 Sep. 2004 Peter Vanroose  Inlined all 1-line methods in class decl
15 // \endverbatim
16 
17 #include <iostream>
18 #include <list>
19 #ifdef _MSC_VER
20 #  include <vcl_msvc_warnings.h>
21 #endif
22 #include <vbl/vbl_ref_count.h>
23 
24 template <class T>
fsm_pop(std::list<T> * l)25 inline T fsm_pop(std::list<T> *l)
26 {
27   T tmp = l->front();
28   l->pop_front();
29   return tmp;
30 }
31 
32 //--------------------------------------------------------------------------------
33 
34 struct osl_stash_link;
35 
36 struct osl_topology_base : public vbl_ref_count
37 {
osl_topology_baseosl_topology_base38   osl_topology_base(osl_topology_base const& x)
39     : vbl_ref_count(), id(x.id), stash_head(x.stash_head) {}
40   int id{0};
41   osl_topology_base();
42   ~osl_topology_base() override;
43   void SetId(int );
44   int GetId() const;
45 
46   //: add another stash under that name.
47   void  stash_add     (char const *name, void const *data, void (*dtor)(void *) = nullptr);
48   //: replace first stash ith given name. the old dtor is \e not called.
49   void  stash_replace (char const *name, void const *data, void (*dtor)(void *) = nullptr);
50   //: return first stash with given name, 0 if none.
51   void *stash_retrieve(char const *name) const;
52   //: remove first stash with given name. the dtor is \e not called.
53   void *stash_remove  (char const *name);
54  private:
55    osl_stash_link *stash_head{nullptr};
56 };
57 
58 //--------------------------------------------------------------------------------
59 
60 //: call ref() on every object pointed to by an element of C.
61 template <class Container>
62 inline
osl_topology_ref(Container & C)63 void osl_topology_ref(Container &C)
64 {
65   for (typename Container::iterator i=C.begin(); i!=C.end(); ++i)
66     if (*i)
67       (*i)->ref();
68 }
69 
70 //: call unref() on every object pointed to by an element of C.
71 template <class Container>
72 inline
osl_topology_unref(Container & C)73 void osl_topology_unref(Container &C)
74 {
75   for (typename Container::iterator i=C.begin(); i!=C.end(); ++i)
76     if (*i)
77       (*i)->unref();
78 }
79 
80 #define OSL_TOPOLOGY_REF_UNREF_INSTANTIATE(C) \
81 /*template void osl_topology_ref(C &) ; */ \
82 /*template void osl_topology_unref(C &) */
83 
84 #endif // osl_topology_h_
85