#include <boost/function.hpp>
#include <list>
#include <set>
+#include <memory>
#include "include/assert.h"
#include "include/memory.h"
public:
GenContext() {}
virtual ~GenContext() {} // we want a virtual destructor!!!
- virtual void complete(T t) {
- finish(t);
+
+ template <typename C>
+ void complete(C &&t) {
+ finish(std::forward<C>(t));
delete this;
}
};
+template <typename T>
+using GenContextURef = std::unique_ptr<GenContext<T> >;
+
/*
* Context - abstract callback class
*/
ContainerContext(T &obj) : obj(obj) {}
void finish(int r) {}
};
+template <typename T>
+ContainerContext<T> *make_container_context(T &&t) {
+ return new ContainerContext<T>(std::forward<T>(t));
+}
template <class T>
struct Wrapper : public Context {
};
typedef ceph::shared_ptr<RunOnDelete> RunOnDeleteRef;
+template <typename T>
+struct LambdaContext : public Context {
+ T t;
+ LambdaContext(T &&t) : t(std::forward<T>(t)) {}
+ void finish(int) {
+ t();
+ }
+};
+template <typename T>
+LambdaContext<T> *make_lambda_context(T &&t) {
+ return new LambdaContext<T>(std::move(t));
+}
+
+template <typename F, typename T>
+struct LambdaGenContext : GenContext<T> {
+ F f;
+ LambdaGenContext(F &&f) : f(std::forward<F>(f)) {}
+ void finish(T t) {
+ f(std::forward<T>(t));
+ }
+};
+template <typename T, typename F>
+GenContextURef<T> make_gen_lambda_context(F &&f) {
+ return GenContextURef<T>(new LambdaGenContext<F, T>(std::move(f)));
+}
+
/*
* finish and destroy a list of Contexts
*/