summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/gdk/gdkmm/list.h
blob: 2c4da23bb73ce3c71fec85e7eee5f5bc92d88dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef _GDKMM_LIST_H_
#define _GDKMM_LIST_H_

namespace Gdk {

#ifdef GTKMM_CXX_HAVE_PARTIAL_SPECIALIZATION
// Dummy class to make it appear as though the user has the list.
/*
template<class Parent,class Iterator,class Access>
  class List 
  {
   public:
     typedef List<Parent,Iterator,Access> List;
   private:
     Parent* parent;
   public:
     List(Parent& p):parent(p) {}
     List():parent(0) {}
     List(const List& list):parent(list.parent) {}

     Iterator begin() 
       {
        if (parent)
          return Access::begin(parent);
        return Iterator();
       }
     Iterator end();
       {
        if (parent)
          return Access::end(parent);
        return Iterator();
       }
  };
*/

// An iterator that caches the current object to C++ for speed
template<class C_Obj, class Cpp_Obj>
  class List_Iterator 
  {
   public:
     typedef List_Iterator<C_Obj,Cpp_Obj> self;

   private:
     GList *node;
     Cpp_Obj cache;
     
   public:
     self& operator=(const self& x) 
       {
        cache.free();
        node=x.node;
       }

     bool operator==(const self& x) const 
       { return node == x.node; }
     bool operator!=(const self& x) const 
       { return node != x.node; }

     List_Iterator(GList *n) : node(n),cache(0) 
       {}
     List_Iterator() :node(0),cache(0)
       {}
     List_Iterator(const self& x) 
        : node(x.node),cache(0) 
       {}

     Cpp_Obj& operator*() const 
       {
        if (node) 
          {if (cache.gobj()!=node->data)
             cache=Cpp_Obj(node->data);
          }
        else
          cache=Cpp_Obj(0);
        cache=0;
        return ;
       }

     Cpp_Obj* operator->() const 
       {
        return &(operator*());
       }

     self&  operator++() 
       { 
        cache.free();
        if (node && node->next) 
          node = node->next;
        return *this;
       }

     self operator++(int) 
       { 
        self tmp = *this;
        ++*this;
        return tmp;
       }

     self& operator--() 
       {
        cache.free();
        if (node && node->prev)
          node=node->prev;
        return *this;
       }

     self operator--(int) 
       { 
        self tmp = *this;
        --*this;
        return tmp;
       }

   };

/*
List_Iterator<GdkWidget*,Widget> iter;
(*iter)  should be a Widget

Example usage:

  class Foo()
    {
     public: 
       typedef List_Iterator<GdkWidget*,Widget> Iterator;
       typedef List<Foo,Iterator,Child_Access) Child_List; 
     private:
       struct Child_Access
         {
          static Iterator begin(Foo& foo)
            {return foo.get_children_begin();}
          static Iterator end(Foo& foo)
            {return foo.get_children_end();}
         };
     public:
//       GList* get_children();
       Iterator get_children_begin()
         {return Iterator(gdk_foo_get_children(*this);}
       Iterator get_children_end()
         {
          GList* list=gdk_foo_get_children(*this);
          return Iterator(g_list_last(list);
         }
       Child_List get_children()
         {
          return Child_List(this);
         }
       
    };
*/

#endif

} /* namespace Gdk */


#endif // _GDKMM_LIST_H_