AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
GuardedValue.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_GUARDEDVALUE_H_
16 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_GUARDEDVALUE_H_
17 
18 #include <mutex>
19 
20 namespace alexaClientSDK {
21 namespace avsCommon {
22 namespace utils {
23 
27 template <typename ValueT>
28 class GuardedValue {
29 public:
33  operator ValueT() const;
34 
40  ValueT operator=(const ValueT& value);
41 
47  GuardedValue(const ValueT& value);
48 
49 private:
51  mutable std::mutex m_mutex;
52 
54  ValueT m_value;
55 };
56 
57 template <typename ValueT>
58 ValueT GuardedValue<ValueT>::operator=(const ValueT& value) {
59  std::lock_guard<std::mutex> lock{m_mutex};
60  m_value = value;
61  return m_value;
62 }
63 
64 template <typename ValueT>
66  std::lock_guard<std::mutex> lock{m_mutex};
67  return m_value;
68 }
69 
70 template <typename ValueT>
71 GuardedValue<ValueT>::GuardedValue(const ValueT& value) : m_value{value} {
72 }
73 
74 } // namespace utils
75 } // namespace avsCommon
76 } // namespace alexaClientSDK
77 
78 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_GUARDEDVALUE_H_
ValueT operator=(const ValueT &value)
Definition: GuardedValue.h:58
GuardedValue(const ValueT &value)
Definition: GuardedValue.h:71
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0