Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
#ifndef SIGCXX_MARSHALLER_H
2
#define SIGCXX_MARSHALLER_H
3
#include 
4
 
5
#ifndef SIGC_CXX_PARTIAL_SPEC
6
#include 
7
#endif
8
 
9
#ifdef SIGC_PTHREADS
10
#include 
11
#endif
12
 
13
#ifdef SIGC_CXX_NAMESPACES
14
namespace SigC
15
{
16
#endif
17
 
18
/*
19
 
20
All classes used to marshal return values should have the following
21
 
22
  class SomeMarshal
23
    {
24
     // both typedefs must be defined.
25
     typedef Type1 InType;
26
     typedef Type2 OutType;
27
 
28
     public:
29
       // Return final return code.
30
       OutType value();
31
 
32
       // Captures return codes and returns TRUE to stop emittion.
33
       bool marshal(const InType&);
34
 
35
       SomeMarshal();
36
   };
37
 
38
It is not necessary for the InType to match the OutType.
39
This is to allow for things like list capturing.
40
 
41
*/
42
 
43
/*******************************************************************
44
***** Marshal
45
*******************************************************************/
46
 
47
// A struct that holds an flag for determining
48
// if the return value is to be ignored.
49
class LIBSIGC_API RetCode
50
  {
51
   public:
52
     static int check_ignore();
53
     static void ignore();
54
  };
55
 
56
// Basic Marshal class.
57
template 
58
class Marshal
59
  {
60
   public:
61
     typedef R OutType;
62
#ifdef SIGC_CXX_PARTIAL_SPEC
63
     typedef R InType;
64
   protected:
65
     typedef OutType OutType_;
66
#else
67
     typedef Trait::type InType;
68
   protected:
69
     typedef InType OutType_;
70
#endif
71
     OutType_ value_;
72
   public:
73
     OutType_& value() {return value_;}
74
 
75
     static OutType_ default_value()
76
#ifdef SIGC_CXX_INT_CTOR
77
       {return OutType_();}
78
#else
79
       {OutType_ r; new (&r) OutType_(); return r;}
80
#endif
81
 
82
     // This captures return values.  Return TRUE to stop emittion process.
83
     bool marshal(const InType& newval)
84
       {
85
        if (!RetCode::check_ignore()) value_=newval;
86
        return 0;  // continue emittion process
87
       };
88
     Marshal()
89
#ifdef SIGC_CXX_INT_CTOR
90
       :value_()
91
       {RetCode::check_ignore();}
92
#else
93
       {
94
        RetCode::check_ignore();
95
        new (&value_) OutType_();
96
       }
97
#endif
98
  };
99
 
100
#ifdef SIGC_CXX_SPECIALIZE_REFERENCES
101
// Basic Marshal class.
102
template 
103
class Marshal
104
  {
105
    public:
106
     typedef R& OutType;
107
     typedef R& InType;
108
     R* value_;
109
     OutType value() {return value_;}
110
     static OutType default_value() {return Default;}
111
     static R Default;
112
 
113
     // This captures return values.  Return TRUE to stop emittion process.
114
     bool marshal(InType newval)
115
       {
116
        if (!RetCode::check_ignore()) value_=&newval;
117
        return 0;  // continue emittion process
118
       };
119
     Marshal()
120
       :value_(&Default)
121
       {RetCode::check_ignore();}
122
     ~Marshal()
123
       {}
124
  };
125
 
126
template  T Marshal::Default;
127
#endif
128
 
129
#ifdef SIGC_CXX_PARTIAL_SPEC
130
// dummy marshaller for void type.
131
template <>
132
class Marshal
133
  {
134
   public:
135
   Marshal()
136
     {}
137
   ~Marshal()
138
     {}
139
  };
140
#endif
141
 
142
 
143
// starts with a fixed value
144
template 
145
class FixedMarshal
146
  {
147
    public:
148
     typedef R OutType;
149
     typedef R InType;
150
     R value_;
151
     OutType& value() {return value_;}
152
     static OutType default_value() { return initial; }
153
 
154
     bool marshal(const InType& newval)
155
       {
156
        if (!RetCode::check_ignore()) value_=newval;
157
        return 0;  // continue emittion process
158
       };
159
 
160
     FixedMarshal()
161
       :value_(initial)
162
       {RetCode::check_ignore();}
163
     ~FixedMarshal()
164
       {}
165
  };
166
 
167
template 
168
struct FastMarshal
169
  {
170
     typedef R OutType;
171
     typedef R InType;
172
 
173
     R value_;
174
     OutType& value() {return value_;}
175
     static OutType default_value()
176
#ifdef SIGC_CXX_INT_CTOR
177
       {return R();}
178
#else
179
       {R r; new (&r) R(); return r;}
180
#endif
181
 
182
     bool marshal(const InType& newval)
183
       {
184
        value_=newval;
185
        return 0;  // continue emittion process
186
       };
187
 
188
     FastMarshal()
189
#ifdef SIGC_CXX_INT_CTOR
190
       :value_()
191
       {}
192
#else
193
       {new (&value_) R();}
194
#endif
195
     ~FastMarshal()
196
       {}
197
  };
198
 
199
 
200
 
201
#ifdef SIGC_CXX_NAMESPACES
202
} // namespace sigc
203
#endif
204
 
205
#endif