AtomicWrapper.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::RobotUnit
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22#pragma once
23
24#include <atomic>
25
26namespace armarx
27{
28 template <typename T>
30 {
31 std::atomic<T> atom;
32
34 {
35 }
36
37 AtomicWrapper(const T& v) : atom{v}
38 {
39 }
40
41 AtomicWrapper(const std::atomic<T>& a) : atom{a.load()}
42 {
43 }
44
45 AtomicWrapper(const AtomicWrapper& other) : atom{other.atom.load()}
46 {
47 }
48
50
52 operator=(const T& v)
53 {
54 atom.store(v);
55 return *this;
56 }
57
59 operator=(const std::atomic<T>& a)
60 {
61 atom.store(a.load());
62 return *this;
63 }
64
67 {
68 atom.store(other.atom.load());
69 return *this;
70 }
71
73
74 operator T() const
75 {
76 return atom.load();
77 }
78 };
79} // namespace armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
AtomicWrapper & operator=(const AtomicWrapper &other)
AtomicWrapper(AtomicWrapper &&)=default
AtomicWrapper(const T &v)
AtomicWrapper & operator=(AtomicWrapper &&)=default
AtomicWrapper & operator=(const std::atomic< T > &a)
std::atomic< T > atom
AtomicWrapper(const std::atomic< T > &a)
AtomicWrapper(const AtomicWrapper &other)
AtomicWrapper & operator=(const T &v)