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