|
17 | 17 | #define BOOST_FUNCTION_BASE_HEADER |
18 | 18 |
|
19 | 19 | #include <stdexcept> |
| 20 | +#include <string> |
20 | 21 | #include <memory> |
21 | 22 | #include <new> |
22 | 23 | #include <boost/config.hpp> |
@@ -255,52 +256,62 @@ namespace boost { |
255 | 256 | } // end namespace function |
256 | 257 | } // end namespace detail |
257 | 258 |
|
258 | | - /** |
259 | | - * The function_base class contains the basic elements needed for the |
260 | | - * function1, function2, function3, etc. classes. It is common to all |
261 | | - * functions (and as such can be used to tell if we have one of the |
262 | | - * functionN objects). |
263 | | - */ |
264 | | - class function_base |
| 259 | +/** |
| 260 | + * The function_base class contains the basic elements needed for the |
| 261 | + * function1, function2, function3, etc. classes. It is common to all |
| 262 | + * functions (and as such can be used to tell if we have one of the |
| 263 | + * functionN objects). |
| 264 | + */ |
| 265 | +class function_base |
| 266 | +{ |
| 267 | +public: |
| 268 | + function_base() : manager(0) |
265 | 269 | { |
266 | | - public: |
267 | | - function_base() : manager(0) |
| 270 | + functor.obj_ptr = 0; |
| 271 | + } |
| 272 | + |
| 273 | + // Is this function empty? |
| 274 | + bool empty() const { return !manager; } |
| 275 | + |
| 276 | +public: // should be protected, but GCC 2.95.3 will fail to allow access |
| 277 | + detail::function::any_pointer (*manager)( |
| 278 | + detail::function::any_pointer, |
| 279 | + detail::function::functor_manager_operation_type); |
| 280 | + detail::function::any_pointer functor; |
| 281 | +}; |
| 282 | + |
| 283 | +/** |
| 284 | + * The bad_function_call exception class is thrown when a boost::function |
| 285 | + * object is invoked |
| 286 | + */ |
| 287 | +class bad_function_call : public std::runtime_error |
| 288 | +{ |
| 289 | +public: |
| 290 | + bad_function_call() : std::runtime_error("call to empty boost::function") {} |
| 291 | +}; |
| 292 | + |
| 293 | +/* Poison comparison between Boost.Function objects (because it is |
| 294 | + * meaningless). The comparisons would otherwise be allowed because of the |
| 295 | + * conversion required to allow syntax such as: |
| 296 | + * boost::function<int, int> f; |
| 297 | + * if (f) { f(5); } |
| 298 | + */ |
| 299 | +void operator==(const function_base&, const function_base&); |
| 300 | +void operator!=(const function_base&, const function_base&); |
| 301 | + |
| 302 | +namespace detail { |
| 303 | + namespace function { |
| 304 | + inline bool has_empty_target(const function_base* f) |
268 | 305 | { |
269 | | - functor.obj_ptr = 0; |
| 306 | + return f->empty(); |
270 | 307 | } |
271 | 308 |
|
272 | | - // Is this function empty? |
273 | | - bool empty() const { return !manager; } |
274 | | - |
275 | | - public: // should be protected, but GCC 2.95.3 will fail to allow access |
276 | | - detail::function::any_pointer (*manager)( |
277 | | - detail::function::any_pointer, |
278 | | - detail::function::functor_manager_operation_type); |
279 | | - detail::function::any_pointer functor; |
280 | | - }; |
281 | | - |
282 | | - /* Poison comparison between Boost.Function objects (because it is |
283 | | - * meaningless). The comparisons would otherwise be allowed because of the |
284 | | - * conversion required to allow syntax such as: |
285 | | - * boost::function<int, int> f; |
286 | | - * if (f) { f(5); } |
287 | | - */ |
288 | | - void operator==(const function_base&, const function_base&); |
289 | | - void operator!=(const function_base&, const function_base&); |
290 | | - |
291 | | - namespace detail { |
292 | | - namespace function { |
293 | | - inline bool has_empty_target(const function_base* f) |
294 | | - { |
295 | | - return f->empty(); |
296 | | - } |
297 | | - |
298 | | - inline bool has_empty_target(...) |
299 | | - { |
300 | | - return false; |
301 | | - } |
302 | | - } // end namespace function |
303 | | - } // end namespace detail |
304 | | -} |
| 309 | + inline bool has_empty_target(...) |
| 310 | + { |
| 311 | + return false; |
| 312 | + } |
| 313 | + } // end namespace function |
| 314 | +} // end namespace detail |
| 315 | +} // end namespace boost |
305 | 316 |
|
306 | 317 | #endif // BOOST_FUNCTION_BASE_HEADER |
0 commit comments