- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trackable.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 * Copyright (c) 2013 Aldebaran Robotics. All rights reserved.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the COPYING file.
6 */
7
8
9 #ifndef _QI_TRACKABLE_HPP_
10 # define _QI_TRACKABLE_HPP_
11
12 # include <boost/thread/mutex.hpp>
13 # include <boost/shared_ptr.hpp>
14 # include <boost/thread/condition_variable.hpp>
15 # include <boost/function.hpp>
16
17 # include <ka/typetraits.hpp>
18 # include <qi/macro.hpp>
19 # include <ka/macroregular.hpp>
20 # include <qi/log.hpp>
21
22 namespace qi
23 {
24
26 class TrackableBase {};
27
44 template<typename T>
45 class Trackable: public TrackableBase
46 {
47 public:
49 Trackable();
51 QI_API_DEPRECATED_MSG(Use default constructor instead) Trackable(T* ptr);
52 ~Trackable();
53
59 boost::weak_ptr<T> weakPtr() const;
60
65 void wait();
66 protected:
71 void destroy();
72 private:
73 void _destroyed();
74
75 boost::shared_ptr<T> _ptr;
76 boost::condition_variable _cond;
77 boost::mutex _mutex;
78 bool _wasDestroyed;
79 };
80
81 class QI_API PointerLockException: public std::exception
82 {
83 public:
84 virtual const char* what() const throw()
85 {
86 return "Pointer Lock failed";
87 }
88 };
89
90 #ifdef DOXYGEN
91
96 template<typename RF, typename AF> boost::function<RF> bind(const AF& fun, ...);
97 #endif
98
106 template<typename F, typename ARG0>
107 boost::function<F> track(boost::function<F> f, const ARG0& arg0);
115 template<typename F, typename ARG0>
116 boost::function<F> trackWithFallback(boost::function<void()> onFail, boost::function<F> f, const ARG0& arg0);
117
123 template<typename Proc, typename T>
124 struct TrackWithFallbackTransfo
125 {
126 Proc _fallback;
127 T* _trackable;
128 // Regular:
129 KA_GENERATE_FRIEND_REGULAR_OPS_2(TrackWithFallbackTransfo, _fallback, _trackable)
130 // PolymorphicTransformation:
131 template<typename F>
132 auto operator()(F&& f) const -> decltype(
133 trackWithFallback(_fallback, std::forward<F>(f), _trackable))
134 {
135 return trackWithFallback(_fallback, std::forward<F>(f), _trackable);
136 }
137 };
138
142 template<typename Proc, typename T>
143 TrackWithFallbackTransfo<ka::Decay<Proc>, T> trackWithFallbackTransfo(Proc&& fallback, T* t)
144 {
145 return {std::forward<Proc>(fallback), t};
146 }
147
153 template<typename T>
154 struct TrackSilentTransfo
155 {
156 T* _trackable;
157 // Regular:
158 KA_GENERATE_FRIEND_REGULAR_OPS_1(TrackSilentTransfo, _trackable)
159 // PolymorphicTransformation:
160 template<typename F>
161 auto operator()(F&& f) const -> decltype(
162 trackSilent(std::forward<F>(f), _trackable))
163 {
164 return trackSilent(std::forward<F>(f), _trackable);
165 }
166 };
167
171 template<typename T>
172 TrackSilentTransfo<T> trackSilentTransfo(T* t)
173 {
174 return {t};
175 }
176 }
177
178 # include <qi/detail/trackable.hxx>
179 #endif // _QI_TRACKABLE_HPP_
qi::trackWithFallback
auto trackWithFallback(boost::function< void()> onFail, F &&f, T &&toTrack) -> decltype(detail::BindTransform< T >::wrap(std::forward< T >(toTrack), std::forward< F >(f), std::move(onFail)))
Definition: trackable.hxx:413
QI_API
#define QI_API
Definition: api.hpp:33
qi::track
auto track(F &&f, T &&toTrack) -> decltype(trackWithFallback(detail::throwPointerLockException, std::forward< F >(f), std::forward< T >(toTrack)))
Definition: trackable.hxx:420
qi::TrackSilentTransfo::_trackable
T * _trackable
Definition: trackable.hpp:156
qi::TrackSilentTransfo
Definition: trackable.hpp:154
qi::Trackable::wait
void wait()
Definition: trackable.hxx:44
qi::Trackable::QI_API_DEPRECATED_MSG
QI_API_DEPRECATED_MSG(Use default constructor instead) Trackable(T *ptr)
qi::TrackWithFallbackTransfo::_fallback
Proc _fallback
Definition: trackable.hpp:126
trackable.hxx
qi::trackWithFallbackTransfo
TrackWithFallbackTransfo< ka::Decay< Proc >, T > trackWithFallbackTransfo(Proc &&fallback, T *t)
Definition: trackable.hpp:143
qi::TrackWithFallbackTransfo
Definition: trackable.hpp:124
qi::TrackWithFallbackTransfo::_trackable
T * _trackable
Definition: trackable.hpp:127
qi::trackSilentTransfo
TrackSilentTransfo< T > trackSilentTransfo(T *t)
Definition: trackable.hpp:172
qi::Trackable::destroy
void destroy()
Definition: trackable.hxx:37
macro.hpp
Various macros for qi. (deprecated, export API, disallow copy, ..) <includename>qi/macro.hpp</includename> .
qi::Trackable::weakPtr
boost::weak_ptr< T > weakPtr() const
Definition: trackable.hxx:76
qi::Trackable::~Trackable
~Trackable()
Definition: trackable.hxx:63
qi::Trackable
Object tracking by blocking destruction while shared pointers are present.
Definition: trackable.hpp:45
log.hpp
Convenient log macro.
qi::PointerLockException::what
virtual const char * what() const
Definition: trackable.hpp:84
qi::trackSilent
auto trackSilent(F &&f, T &&toTrack) -> decltype(trackWithFallback(
Definition: trackable.hxx:427
qi::bind
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
Definition: trackable.hxx:308
qi::PointerLockException
Definition: trackable.hpp:81
qi::Trackable::Trackable
Trackable()
Default constructor.
Definition: trackable.hxx:22
qi::TrackableBase
Common base class to templates Trackable for compile-time detection.
Definition: trackable.hpp:26