All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
26 {
27  m_safeValue = std::make_shared<const T>();
28 }
29 
30 template <class T>
32  m_value(value)
33 {
34  m_safeValue = std::make_shared<const T>(m_value);
35 }
36 
37 template <class T>
39 {
40 }
41 
42 template <class T>
44 {
45  UniqueLock lock(m_mutex);
46  m_safeValue = std::make_shared<const T>(m_value);
47 }
48 
49 template <class T>
51 {
52  return m_value;
53 }
54 
55 template <class T>
56 std::shared_ptr<const T> BufferedValue<T>::safeGet() const
57 {
58  SharedLock lock(m_mutex);
59  return m_safeValue;
60 }
61 
62 } // DataStructures
63 } // SurgSim
64 
65 #endif
std::shared_ptr< const T > m_safeValue
The buffered value.
Definition: BufferedValue.h:66
~BufferedValue()
Destructor.
Definition: BufferedValue-inl.h:38
T & unsafeGet()
Get the value.
Definition: BufferedValue-inl.h:50
std::shared_ptr< const T > safeGet() const
Get the buffered value.
Definition: BufferedValue-inl.h:56
boost::unique_lock< boost::shared_mutex > UniqueLock
Definition: BufferedValue.h:60
BufferedValue()
Definition: BufferedValue-inl.h:25
boost::shared_lock< boost::shared_mutex > SharedLock
Definition: BufferedValue.h:59
void publish()
Make the current value the one returned by calls to safeGet.
Definition: BufferedValue-inl.h:43
T m_value
The raw value.
Definition: BufferedValue.h:63