forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactiveBase.h
More file actions
71 lines (54 loc) · 1.72 KB
/
ReactiveBase.h
File metadata and controls
71 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Sebastian Jeckel 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include "react/detail/Defs.h"
#include <functional>
#include <memory>
/*****************************************/ REACT_BEGIN /*****************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Reactive
///////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
class Reactive
{
public:
using Domain = typename T::Domain;
using DomainT = typename T::Domain;
Reactive() :
ptr_{ nullptr }
{
}
explicit Reactive(const std::shared_ptr<T>& ptr) :
ptr_{ ptr }
{
}
explicit Reactive(std::shared_ptr<T>&& ptr) :
ptr_{ std::move(ptr) }
{
}
const std::shared_ptr<T>& GetPtr() const
{
return ptr_;
}
bool Equals(const Reactive& other) const
{
return ptr_ == other.ptr_;
}
protected:
std::shared_ptr<T> ptr_;
};
/******************************************/ REACT_END /******************************************/
/***************************************/ REACT_IMPL_BEGIN /**************************************/
template <typename L, typename R>
bool Equals(const L& lhs, const R& rhs)
{
return lhs == rhs;
}
template <typename L, typename R>
bool Equals(const std::reference_wrapper<L>& lhs, const std::reference_wrapper<R>& rhs)
{
return lhs.get() == rhs.get();
}
/****************************************/ REACT_IMPL_END /***************************************/