SurgSim
DataStructures
BufferedValue-inl.h
Go to the documentation of this file.
1
// This file is a part of the OpenSurgSim project.
2
// Copyright 2013, SimQuest Solutions Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
// you may not use this file except in compliance with the License.
6
// You may obtain a copy of the License at
7
//
8
// http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
16
#ifndef SURGSIM_DATASTRUCTURES_BUFFEREDVALUE_INL_H
17
#define SURGSIM_DATASTRUCTURES_BUFFEREDVALUE_INL_H
18
19
namespace
SurgSim
20
{
21
namespace
DataStructures
22
{
23
24
template
<
class
T>
25
BufferedValue<T>::BufferedValue
()
26
{
27
m_safeValue = std::make_shared<const T>();
28
}
29
30
template
<
class
T>
31
BufferedValue<T>::BufferedValue
(
const
T& value) :
32
m_value(value)
33
{
34
m_safeValue = std::make_shared<const T>(m_value);
35
}
36
37
template
<
class
T>
38
BufferedValue<T>::~BufferedValue
()
39
{
40
}
41
42
template
<
class
T>
43
void
BufferedValue<T>::publish
()
44
{
45
auto
newSafeValue = std::make_shared<const T>(m_value);
46
{
47
UniqueLock
lock(m_mutex);
48
std::swap(newSafeValue, m_safeValue);
49
}
50
}
51
52
template
<
class
T>
53
T&
BufferedValue<T>::unsafeGet
()
54
{
55
return
m_value;
56
}
57
58
template
<
class
T>
59
std::shared_ptr<const T>
BufferedValue<T>::safeGet
()
const
60
{
61
SharedLock
lock(m_mutex);
62
return
m_safeValue;
63
}
64
65
}
// DataStructures
66
}
// SurgSim
67
68
#endif
SurgSim
Definition:
CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::BufferedValue< SurgSim::Math::Vector6d >::UniqueLock
boost::unique_lock< boost::shared_mutex > UniqueLock
Definition:
BufferedValue.h:60
SurgSim::DataStructures::BufferedValue< SurgSim::Math::Vector6d >::SharedLock
boost::shared_lock< boost::shared_mutex > SharedLock
Definition:
BufferedValue.h:59
SurgSim::DataStructures::BufferedValue
BufferedValue is a class to enable a representation of two values for one variable,...
Definition:
BufferedValue.h:33
SurgSim::DataStructures::BufferedValue::BufferedValue
BufferedValue()
Definition:
BufferedValue-inl.h:25
Generated on Tue Jun 2 2020 12:47:05 for OpenSurgSim by
1.8.17