AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
RuntimeManufactory_imp.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 
16 #ifndef ACSDKMANUFACTORY_INTERNAL_RUNTIMEMANUFACTORY_IMP_H_
17 #define ACSDKMANUFACTORY_INTERNAL_RUNTIMEMANUFACTORY_IMP_H_
18 
20 
24 
25 namespace alexaClientSDK {
26 namespace acsdkManufactory {
27 namespace internal {
28 
29 inline RuntimeManufactory::RuntimeManufactory(const CookBook& cookBook) : m_cookBook{new CookBook{cookBook}} {
30  m_cookBook->doRequiredGets(*this);
31 }
32 
33 template <typename Type>
35  Type* TypedPointer = nullptr;
36  return innerGet(TypedPointer);
37 }
38 
39 template <typename Type>
40 inline std::unique_ptr<Type> RuntimeManufactory::innerGet(std::unique_ptr<Type>*) {
41  return m_cookBook->createUniquePointer<Type>(*this);
42 }
43 
44 template <typename Type>
45 inline std::shared_ptr<Type> RuntimeManufactory::innerGet(std::shared_ptr<Type>*) {
46  using ResultType = std::shared_ptr<Type>;
47  ResultType ret;
48 
49  auto resultTypeIndex = avsCommon::utils::getTypeIndex<ResultType>();
50 
51  auto it = m_values.find(resultTypeIndex);
52  if (m_values.end() == it || !it->second) {
53  std::shared_ptr<AbstractPointerCache> cache(std::move(m_cookBook->createPointerCache<ResultType>()));
54  m_values[resultTypeIndex] = cache;
55  ret = *static_cast<ResultType*>(cache->get(*this));
56  cache->cleanup();
57  } else {
58  auto cache = static_cast<AbstractPointerCache*>(it->second.get());
59  ret = *static_cast<ResultType*>(cache->get(*this));
60  cache->cleanup();
61  }
62 
63  return ret;
64 }
65 
66 template <typename Annotation, typename Type>
67 inline Annotated<Annotation, Type> RuntimeManufactory::innerGet(Annotated<Annotation, Type>*) {
68  using ResultType = Annotated<Annotation, Type>;
69  ResultType ret;
70 
71  auto resultTypeIndex = avsCommon::utils::getTypeIndex<ResultType>();
72 
73  auto it = m_values.find(resultTypeIndex);
74  if (m_values.end() == it || !it->second) {
75  std::shared_ptr<AbstractPointerCache> cache(std::move(m_cookBook->createPointerCache<ResultType>()));
76  m_values[resultTypeIndex] = cache;
77  ret = *static_cast<std::shared_ptr<Type>*>(cache->get(*this));
78  cache->cleanup();
79  } else {
80  auto cache = static_cast<AbstractPointerCache*>(it->second.get());
81  ret = *static_cast<std::shared_ptr<Type>*>(cache->get(*this));
82  cache->cleanup();
83  }
84 
85  return ret;
86 }
87 
88 } // namespace internal
89 } // namespace acsdkManufactory
90 } // namespace alexaClientSDK
91 
92 #endif // ACSDKMANUFACTORY_INTERNAL_RUNTIMEMANUFACTORY_IMP_H_
RuntimeManufactory(const CookBook &cookBook)
Definition: RuntimeManufactory_imp.h:29
Type get()
Definition: RuntimeManufactory_imp.h:34
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
const T & move(const T &t)
Definition: gtest-port.h:1317

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