16 #ifndef ACSDKMANUFACTORY_INTERNAL_COOKBOOK_IMP_H_ 17 #define ACSDKMANUFACTORY_INTERNAL_COOKBOOK_IMP_H_ 37 namespace acsdkManufactory {
40 template <
typename Type,
typename... Dependencies>
42 if (!checkIsValid(__func__)) {
46 using ResultType = std::unique_ptr<Type>;
47 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
48 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
50 auto newRecipe = std::make_shared<FunctionRecipe>(
51 reinterpret_cast<void*
>(funcPtr),
52 AbstractRecipe::CachedInstanceLifecycle::UNIQUE,
55 produceFromUniqueFunctionRecipe<Type, Dependencies...>),
56 static_cast<void (*)(
void*)
>(deleteFunctionForUniqueRecipe),
57 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
59 auto type = avsCommon::utils::getTypeIndex<ResultType>();
60 if (!addRecipe(type, newRecipe)) {
61 markInvalid(
"addUniqueFactoryFailed",
"non-isEquivalent recipe ", type.getName());
67 template <
typename Type,
typename... Dependencies>
69 if (!checkIsValid(__func__)) {
73 using ResultType = std::unique_ptr<Type>;
74 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
76 auto newRecipe = std::make_shared<FactoryRecipe>(
77 reinterpret_cast<void* (*)()
>(factory),
78 AbstractRecipe::CachedInstanceLifecycle::UNIQUE,
81 produceFromUniqueFactoryRecipe<Type, Dependencies...>),
82 static_cast<void (*)(
void*)
>(deleteFunctionForUniqueRecipe));
84 auto type = avsCommon::utils::getTypeIndex<ResultType>();
85 if (!addRecipe(
type, newRecipe)) {
86 markInvalid(
"addUniqueFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
92 template <
typename Type,
typename... Dependencies>
94 if (!checkIsValid(__func__)) {
98 using ResultType = std::shared_ptr<Type>;
99 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
100 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
102 auto newRecipe = std::make_shared<FunctionRecipe>(
103 reinterpret_cast<void*
>(funcPtr),
104 AbstractRecipe::CachedInstanceLifecycle::PRIMARY,
107 produceFromSharedFunctionRecipe<Type, Dependencies...>),
108 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
109 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
111 auto type = avsCommon::utils::getTypeIndex<ResultType>();
112 if (!addRecipe(type, newRecipe)) {
113 markInvalid(
"addPrimaryFactoryFailed",
"non-isEquivalent recipe ", type.getName());
116 m_primaryGets->append<ResultType>(
117 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
122 template <
typename Annotation,
typename Type,
typename... Dependencies>
124 if (!checkIsValid(__func__)) {
129 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
130 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
132 auto newRecipe = std::make_shared<FunctionRecipe>(
133 reinterpret_cast<void*
>(funcPtr),
134 AbstractRecipe::CachedInstanceLifecycle::PRIMARY,
137 produceFromAnnotatedSharedFunctionRecipe<Type, Annotation, Dependencies...>),
138 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
139 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
141 auto type = avsCommon::utils::getTypeIndex<ResultType>();
142 if (!addRecipe(type, newRecipe)) {
143 markInvalid(
"addPrimaryFactoryFailed",
"non-isEquivalent recipe ", type.getName());
146 m_primaryGets->append<ResultType>(
147 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
152 template <
typename Type,
typename... Dependencies>
154 if (!checkIsValid(__func__)) {
158 using ResultType = std::shared_ptr<Type>;
159 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
161 auto newRecipe = std::make_shared<FactoryRecipe>(
162 reinterpret_cast<void* (*)()
>(factory),
163 AbstractRecipe::CachedInstanceLifecycle::PRIMARY,
166 produceFromSharedFactoryRecipe<Type, Dependencies...>),
167 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
169 auto type = avsCommon::utils::getTypeIndex<ResultType>();
170 if (!addRecipe(
type, newRecipe)) {
171 markInvalid(
"addPrimaryFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
174 m_primaryGets->append<ResultType>(
175 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
180 template <
typename Annotation,
typename Type,
typename... Dependencies>
182 if (!checkIsValid(__func__)) {
187 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
189 auto newRecipe = std::make_shared<FactoryRecipe>(
190 reinterpret_cast<void* (*)()
>(factory),
191 AbstractRecipe::CachedInstanceLifecycle::PRIMARY,
194 produceFromAnnotatedSharedFactoryRecipe<Type, Annotation, Dependencies...>),
195 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
197 auto type = avsCommon::utils::getTypeIndex<ResultType>();
198 if (!addRecipe(
type, newRecipe)) {
199 markInvalid(
"addPrimaryFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
202 m_primaryGets->append<ResultType>(
203 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
208 template <
typename Type,
typename... Dependencies>
210 if (!checkIsValid(__func__)) {
214 using ResultType = std::shared_ptr<Type>;
215 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
216 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
218 auto newRecipe = std::make_shared<FunctionRecipe>(
219 reinterpret_cast<void*
>(funcPtr),
220 AbstractRecipe::CachedInstanceLifecycle::REQUIRED,
223 produceFromSharedFunctionRecipe<Type, Dependencies...>),
224 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
225 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
227 auto type = avsCommon::utils::getTypeIndex<ResultType>();
228 if (!addRecipe(type, newRecipe)) {
229 markInvalid(
"addRequiredFactoryFailed",
"non-isEquivalent recipe ", type.getName());
232 m_requiredGets->append<ResultType>(
233 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
238 template <
typename Annotation,
typename Type,
typename... Dependencies>
240 if (!checkIsValid(__func__)) {
245 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
246 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
248 auto newRecipe = std::make_shared<FunctionRecipe>(
249 reinterpret_cast<void*
>(funcPtr),
250 AbstractRecipe::CachedInstanceLifecycle::REQUIRED,
253 produceFromAnnotatedSharedFunctionRecipe<Type, Annotation, Dependencies...>),
254 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
255 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
257 auto type = avsCommon::utils::getTypeIndex<ResultType>();
258 if (!addRecipe(type, newRecipe)) {
259 markInvalid(
"addRequiredFactoryFailed",
"non-isEquivalent recipe ", type.getName());
262 m_requiredGets->append<ResultType>(
263 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
268 template <
typename Type,
typename... Dependencies>
270 if (!checkIsValid(__func__)) {
274 using ResultType = std::shared_ptr<Type>;
275 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
277 auto newRecipe = std::make_shared<FactoryRecipe>(
278 reinterpret_cast<void* (*)()
>(factory),
279 AbstractRecipe::CachedInstanceLifecycle::REQUIRED,
282 produceFromSharedFactoryRecipe<Type, Dependencies...>),
283 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
285 auto type = avsCommon::utils::getTypeIndex<ResultType>();
286 if (!addRecipe(
type, newRecipe)) {
287 markInvalid(
"addRequiredFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
290 m_requiredGets->append<ResultType>(
291 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
296 template <
typename Annotation,
typename Type,
typename... Dependencies>
298 if (!checkIsValid(__func__)) {
303 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
305 auto newRecipe = std::make_shared<FactoryRecipe>(
306 reinterpret_cast<void* (*)()
>(factory),
307 AbstractRecipe::CachedInstanceLifecycle::REQUIRED,
310 produceFromAnnotatedSharedFactoryRecipe<Type, Annotation, Dependencies...>),
311 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
313 auto type = avsCommon::utils::getTypeIndex<ResultType>();
314 if (!addRecipe(
type, newRecipe)) {
315 markInvalid(
"addRequiredFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
318 m_requiredGets->append<ResultType>(
319 [](
RuntimeManufactory& runtimeManufactory) {
return static_cast<bool>(runtimeManufactory.get<ResultType>()); });
324 template <
typename Type,
typename... Dependencies>
326 if (!checkIsValid(__func__)) {
330 using ResultType = std::shared_ptr<Type>;
331 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
332 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
334 auto newRecipe = std::make_shared<FunctionRecipe>(
335 reinterpret_cast<void*
>(funcPtr),
336 AbstractRecipe::CachedInstanceLifecycle::RETAINED,
339 produceFromSharedFunctionRecipe<Type, Dependencies...>),
340 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
341 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
343 auto type = avsCommon::utils::getTypeIndex<ResultType>();
344 if (!addRecipe(type, newRecipe)) {
345 markInvalid(
"addRetainedFactoryFailed",
"non-isEquivalent recipe ", type.getName());
351 template <
typename Annotation,
typename Type,
typename... Dependencies>
353 if (!checkIsValid(__func__)) {
358 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
359 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
361 auto newRecipe = std::make_shared<FunctionRecipe>(
362 reinterpret_cast<void*
>(funcPtr),
363 AbstractRecipe::CachedInstanceLifecycle::RETAINED,
366 produceFromAnnotatedSharedFunctionRecipe<Type, Annotation, Dependencies...>),
367 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
368 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
370 auto type = avsCommon::utils::getTypeIndex<ResultType>();
371 if (!addRecipe(type, newRecipe)) {
372 markInvalid(
"addRetainedFactoryFailed",
"non-isEquivalent recipe ", type.getName());
378 template <
typename Type,
typename... Dependencies>
380 if (!checkIsValid(__func__)) {
384 using ResultType = std::shared_ptr<Type>;
385 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
387 auto newRecipe = std::make_shared<FactoryRecipe>(
388 reinterpret_cast<void* (*)()
>(factory),
389 AbstractRecipe::CachedInstanceLifecycle::RETAINED,
392 produceFromSharedFactoryRecipe<Type, Dependencies...>),
393 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
395 auto type = avsCommon::utils::getTypeIndex<ResultType>();
396 if (!addRecipe(
type, newRecipe)) {
397 markInvalid(
"addRetainedFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
403 template <
typename Annotation,
typename Type,
typename... Dependencies>
405 if (!checkIsValid(__func__)) {
410 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
412 auto newRecipe = std::make_shared<FactoryRecipe>(
413 reinterpret_cast<void* (*)()
>(factory),
414 AbstractRecipe::CachedInstanceLifecycle::RETAINED,
417 produceFromAnnotatedSharedFactoryRecipe<Type, Annotation, Dependencies...>),
418 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
420 auto type = avsCommon::utils::getTypeIndex<ResultType>();
421 if (!addRecipe(
type, newRecipe)) {
422 markInvalid(
"addRetainedFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
428 template <
typename Type,
typename... Dependencies>
430 if (!checkIsValid(__func__)) {
434 using ResultType = std::shared_ptr<Type>;
435 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
436 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
438 auto newRecipe = std::make_shared<FunctionRecipe>(
439 reinterpret_cast<void*
>(funcPtr),
440 AbstractRecipe::CachedInstanceLifecycle::UNLOADABLE,
443 produceFromSharedFunctionRecipe<Type, Dependencies...>),
444 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
445 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
447 auto type = avsCommon::utils::getTypeIndex<ResultType>();
448 if (!addRecipe(type, newRecipe)) {
449 markInvalid(
"addUnloadableFactoryFailed",
"non-isEquivalent recipe ", type.getName());
455 template <
typename Annotation,
typename Type,
typename... Dependencies>
457 if (!checkIsValid(__func__)) {
462 auto funcPtr =
new std::function<ResultType(Dependencies...)>(
function);
463 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
465 auto newRecipe = std::make_shared<FunctionRecipe>(
466 reinterpret_cast<void*
>(funcPtr),
467 AbstractRecipe::CachedInstanceLifecycle::UNLOADABLE,
470 produceFromAnnotatedSharedFunctionRecipe<Type, Annotation, Dependencies...>),
471 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>),
472 static_cast<void (*)(
void*)
>(deleteFunctionForFunctionRecipeFunction<ResultType, Dependencies...>));
474 auto type = avsCommon::utils::getTypeIndex<ResultType>();
475 if (!addRecipe(type, newRecipe)) {
476 markInvalid(
"addUnloadableFactoryFailed",
"non-isEquivalent recipe ", type.getName());
482 template <
typename Type,
typename... Dependencies>
484 if (!checkIsValid(__func__)) {
488 using ResultType = std::shared_ptr<Type>;
489 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
491 auto newRecipe = std::make_shared<FactoryRecipe>(
492 reinterpret_cast<void* (*)()
>(factory),
493 AbstractRecipe::CachedInstanceLifecycle::UNLOADABLE,
496 produceFromSharedFactoryRecipe<Type, Dependencies...>),
497 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
499 auto type = avsCommon::utils::getTypeIndex<ResultType>();
500 if (!addRecipe(
type, newRecipe)) {
501 markInvalid(
"addUnloadableFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
507 template <
typename Annotation,
typename Type,
typename... Dependencies>
509 if (!checkIsValid(__func__)) {
514 std::vector<avsCommon::utils::TypeIndex> dependencies = {avsCommon::utils::getTypeIndex<Dependencies>()...};
516 auto newRecipe = std::make_shared<FactoryRecipe>(
517 reinterpret_cast<void* (*)()
>(factory),
518 AbstractRecipe::CachedInstanceLifecycle::UNLOADABLE,
521 produceFromAnnotatedSharedFactoryRecipe<Type, Annotation, Dependencies...>),
522 static_cast<void (*)(
void*)
>(deleteFunctionForSharedRecipe<Type>));
524 auto type = avsCommon::utils::getTypeIndex<ResultType>();
525 if (!addRecipe(
type, newRecipe)) {
526 markInvalid(
"addUnloadableFactoryFailed",
"non-isEquivalent recipe ",
type.getName());
532 template <
typename Type>
534 if (!checkIsValid(__func__)) {
538 auto newRecipe = std::make_shared<InstanceRecipe>(
540 static_cast<void* (*)(std::shared_ptr<AbstractRecipe>,
RuntimeManufactory&,
void*)
>(produceFromInstanceRecipe),
541 static_cast<void (*)(
void*)
>(deleteFunctionForInstanceRecipe));
543 auto type = avsCommon::utils::getTypeIndex<Type>();
545 markInvalid(
"addInstanceFailed",
"non-isEquivalent instance ", type.getName());
553 const std::shared_ptr<AbstractRecipe>& newInstanceRecipe) {
554 auto& RecipePtr = m_recipes[
type];
556 if (!RecipePtr->isEquivalent(newInstanceRecipe)) {
560 RecipePtr = newInstanceRecipe;
567 auto& RecipePtr = m_recipes[
type];
571 if (!RecipePtr->isEquivalent(newRecipe)) {
576 RecipePtr = newRecipe;
583 if (!checkIsValid(__func__)) {
587 if (!cookBook.checkIsValid(__func__)) {
588 markInvalid(
"addCookBookFailed",
"invalid component");
594 for (
auto item : cookBook.m_recipes) {
595 auto it = m_recipes.find(item.first);
596 if (it != m_recipes.end()) {
597 if (!it->second->isEquivalent(item.second)) {
598 markInvalid(
"addCookBookFailed",
"isEquivalentFailed");
602 m_recipes.insert(item);
606 m_primaryGets->append(cookBook.m_primaryGets);
607 m_requiredGets->append(cookBook.m_requiredGets);
614 for (
auto getFcn : *m_primaryGets) {
615 if (!getFcn || !getFcn(runtimeManufactory)) {
620 for (
auto getFcn : *m_requiredGets) {
621 if (!getFcn || !getFcn(runtimeManufactory)) {
629 template <
typename Type>
631 if (!checkIsValid(__func__)) {
632 return std::unique_ptr<Type>();
635 auto type = avsCommon::utils::getTypeIndex<std::unique_ptr<Type>>();
636 auto it = m_recipes.find(type);
637 if (it != m_recipes.end()) {
639 auto recipe = it->second;
647 auto temporaryPointerToUniquePointerOnHeap =
648 static_cast<std::unique_ptr<Type>*
>(
createUniquePointer(recipe, runtimeManufactory,
nullptr));
652 auto uniquePointerToReturn =
std::move(*temporaryPointerToUniquePointerOnHeap);
655 delete temporaryPointerToUniquePointerOnHeap;
657 return uniquePointerToReturn;
660 markInvalid(
"createUniquePointerFailed",
"null Recipe for type: ", type.getName());
661 return std::unique_ptr<Type>();
665 markInvalid(
"createUniquePointerFailed",
"no Recipe for type", type.getName());
666 return std::unique_ptr<Type>();
669 template <
typename Type>
671 if (!checkIsValid(__func__)) {
672 return std::unique_ptr<SharedPointerCache>();
675 auto type = avsCommon::utils::getTypeIndex<Type>();
676 auto it = m_recipes.find(type);
677 if (it != m_recipes.end()) {
679 auto recipe = it->second;
680 if (AbstractRecipe::CachedInstanceLifecycle::UNLOADABLE == recipe->getLifecycle()) {
685 markInvalid(
"createPointerCacheFailed",
"null Recipe for type: ", type.getName());
686 return std::unique_ptr<SharedPointerCache>();
690 markInvalid(
"createPointerCacheFailed",
"no Recipe for type", type.getName());
691 return std::unique_ptr<SharedPointerCache>();
696 m_primaryGets{std::make_shared<GetWrapperCollection>()},
697 m_requiredGets{std::make_shared<GetWrapperCollection>()} {
701 if (!checkIsValid(__func__)) {
705 return checkForCyclicDependencies();
708 inline bool CookBook::checkIsValid(
const char* functionName)
const {
722 template <
typename Type,
typename... Dependencies>
723 inline Type CookBook::invokeWithDependencies(
725 std::function<
Type(Dependencies...)>
function) {
726 using FcnType =
typename std::function<
Type(Dependencies...)>;
727 return CookBook::template innerInvokeWithDependencies<
Type, FcnType, Dependencies...>(
731 template <
typename Type,
typename FunctionType,
typename... Dependencies>
732 inline Type CookBook::innerInvokeWithDependencies(FunctionType
function, Dependencies... dependencies) {
733 return function(
std::move(dependencies)...);
736 template <
typename Type,
typename... Dependencies>
737 inline void* CookBook::produceFromSharedFactoryRecipe(
738 std::shared_ptr<AbstractRecipe> recipe,
740 void* cachedInstance) {
741 if (cachedInstance) {
742 return cachedInstance;
745 auto factoryRecipe =
reinterpret_cast<FactoryRecipe*
>(recipe.get());
746 auto factory =
reinterpret_cast<std::shared_ptr<Type> (*)(Dependencies...)
>(factoryRecipe->getFactory());
748 InstanceGetter<std::shared_ptr<Type>, Dependencies...> getter = [factory](Dependencies... dependencies) {
749 return factory(
std::move(dependencies)...);
752 return new std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory, getter));
755 template <
typename Type,
typename Annotation,
typename... Dependencies>
756 inline void* CookBook::produceFromAnnotatedSharedFactoryRecipe(
757 std::shared_ptr<AbstractRecipe> recipe,
759 void* cachedInstance) {
760 if (cachedInstance) {
761 return cachedInstance;
764 auto factoryRecipe =
reinterpret_cast<FactoryRecipe*
>(recipe.get());
767 InstanceGetter<std::shared_ptr<Type>, Dependencies...> getter = [factory](Dependencies... dependencies) {
768 return factory(
std::move(dependencies)...);
771 return new std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory, getter));
774 template <
typename Type,
typename... Dependencies>
775 inline void* CookBook::produceFromSharedFunctionRecipe(
776 std::shared_ptr<AbstractRecipe> recipe,
778 void* cachedInstance) {
779 if (cachedInstance) {
780 return cachedInstance;
782 auto functionRecipe =
reinterpret_cast<FunctionRecipe*
>(recipe.get());
783 auto function = *
static_cast<std::function<std::shared_ptr<Type>(Dependencies...)
>*>(functionRecipe->getFunction());
785 return new std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory,
function));
788 template <
typename Type,
typename Annotation,
typename... Dependencies>
789 inline void* CookBook::produceFromAnnotatedSharedFunctionRecipe(
790 std::shared_ptr<AbstractRecipe> recipe,
792 void* cachedInstance) {
793 if (cachedInstance) {
794 return cachedInstance;
796 auto functionRecipe =
reinterpret_cast<FunctionRecipe*
>(recipe.get());
798 *
static_cast<std::function<Annotated<Annotation, Type>(Dependencies...)
>*>(functionRecipe->getFunction());
800 auto temp = std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory,
function));
801 return new std::shared_ptr<void>(temp);
804 template <
typename Type,
typename... Dependencies>
805 inline void* CookBook::produceFromWeakFactoryRecipe(
806 std::shared_ptr<AbstractRecipe> recipe,
808 void* cachedInstance) {
809 auto factoryRecipe =
reinterpret_cast<FactoryRecipe*
>(recipe.get());
810 auto factory =
reinterpret_cast<std::shared_ptr<Type> (*)(Dependencies...)
>(factoryRecipe->getFactory());
812 InstanceGetter<std::shared_ptr<Type>, Dependencies...> getter = [factory](Dependencies... dependencies) {
813 return factory(
std::move(dependencies)...);
816 auto temp = std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory, getter));
817 return new std::shared_ptr<void>(temp);
820 template <
typename Type,
typename Annotation,
typename... Dependencies>
821 inline void* CookBook::produceFromAnnotatedWeakFactoryRecipe(
822 std::shared_ptr<AbstractRecipe> recipe,
824 void* cachedInstance) {
825 if (cachedInstance) {
826 return cachedInstance;
829 auto factoryRecipe =
reinterpret_cast<FactoryRecipe*
>(recipe.get());
832 InstanceGetter<std::shared_ptr<Type>, Dependencies...> getter = [factory](Dependencies... dependencies) {
833 return factory(
std::move(dependencies)...);
836 auto temp = std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory, getter));
837 return new std::shared_ptr<void>(temp);
840 template <
typename Type,
typename... Dependencies>
841 inline void* CookBook::produceFromWeakFunctionRecipe(
842 std::shared_ptr<AbstractRecipe> recipe,
844 void* cachedInstance) {
845 if (cachedInstance) {
846 return cachedInstance;
848 auto functionRecipe =
reinterpret_cast<FunctionRecipe*
>(recipe.get());
849 auto function = *
static_cast<std::function<std::shared_ptr<Type>(Dependencies...)
>*>(functionRecipe->getFunction());
851 auto temp = std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory,
function));
852 return new std::shared_ptr<void>(temp);
855 template <
typename Type,
typename Annotation,
typename... Dependencies>
856 inline void* CookBook::produceFromAnnotatedWeakFunctionRecipe(
857 std::shared_ptr<AbstractRecipe> recipe,
859 void* cachedInstance) {
860 if (cachedInstance) {
861 return cachedInstance;
863 auto functionRecipe =
reinterpret_cast<FunctionRecipe*
>(recipe.get());
865 *
static_cast<std::function<Annotated<Annotation, Type>(Dependencies...)
>*>(functionRecipe->getFunction());
867 auto temp = std::shared_ptr<Type>(invokeWithDependencies(runtimeManufactory,
function));
868 return new std::shared_ptr<void>(temp);
871 template <
typename Type>
872 inline void CookBook::deleteFunctionForSharedRecipe(
void* cachedInstance) {
873 auto objectToDelete =
static_cast<std::shared_ptr<Type>*
>(cachedInstance);
874 delete objectToDelete;
877 template <
typename Type,
typename... Dependencies>
878 inline void CookBook::deleteFunctionForFunctionRecipeFunction(
void*
function) {
879 auto objectToDelete =
static_cast<std::function<Type(Dependencies...)
>*>(
function);
880 delete objectToDelete;
883 template <
typename Type,
typename... Dependencies>
884 inline void* CookBook::produceFromUniqueFactoryRecipe(
885 std::shared_ptr<AbstractRecipe> recipe,
887 void* cachedInstance) {
888 auto factoryRecipe =
reinterpret_cast<FactoryRecipe*
>(recipe.get());
889 auto factory =
reinterpret_cast<std::unique_ptr<Type> (*)(Dependencies...)
>(factoryRecipe->getFactory());
891 InstanceGetter<std::unique_ptr<Type>, Dependencies...> getter = [factory](Dependencies... dependencies) {
892 return factory(
std::move(dependencies)...);
895 return new std::unique_ptr<Type>(invokeWithDependencies(runtimeManufactory, getter));
898 template <
typename Type,
typename... Dependencies>
899 inline void* CookBook::produceFromUniqueFunctionRecipe(
900 std::shared_ptr<AbstractRecipe> recipe,
902 void* cachedInstance) {
903 auto functionRecipe =
reinterpret_cast<FunctionRecipe*
>(recipe.get());
904 auto function = *
static_cast<std::function<std::unique_ptr<Type>(Dependencies...)
>*>(functionRecipe->getFunction());
906 return new std::unique_ptr<Type>(invokeWithDependencies(runtimeManufactory,
function));
911 template <
typename Type>
912 inline bool CookBook::GetWrapperCollection::append(GetWrapper getWrapper) {
913 auto typeIndex = avsCommon::utils::getTypeIndex<Type>();
915 if (m_types.end() == m_types.find(typeIndex)) {
916 m_orderedGetWrappers.push_back(getWrapper);
917 m_types.insert({typeIndex, m_orderedGetWrappers.size() - 1});
929 #endif // ACSDKMANUFACTORY_INTERNAL_COOKBOOK_IMP_H_ bool doRequiredGets(RuntimeManufactory &runtimeManufactory)
Definition: CookBook_imp.h:612
CookBook & addPrimaryFactory(std::function< std::shared_ptr< Type >(Dependencies...)> factory)
Definition: CookBook_imp.h:93
Definition: CookBook.h:42
CookBook & addRetainedFactory(std::function< std::shared_ptr< Type >(Dependencies...)> factory)
Definition: CookBook_imp.h:325
::std::string string
Definition: gtest-port.h:1097
Definition: TypeIndex.h:35
Definition: SharedPointerCache.h:29
bool checkCompleteness()
Definition: CookBook_imp.h:700
Definition: RuntimeManufactory.h:39
Type get()
Definition: RuntimeManufactory_imp.h:34
CookBook & addUnloadableFactory(std::function< std::shared_ptr< Type >(Dependencies...)> factory)
Definition: CookBook_imp.h:429
CookBook & addUniqueFactory(std::function< std::unique_ptr< Type >(Dependencies...)> factory)
Definition: CookBook_imp.h:41
Definition: Annotated.h:35
CookBook & addCookBook(const CookBook &cookBook)
Definition: CookBook_imp.h:582
typename RemoveCvref< Type >::type RemoveCvref_t
Definition: TypeTraitsHelper.h:40
std::unique_ptr< Type > createUniquePointer(RuntimeManufactory &runtimeManufactory)
Definition: CookBook_imp.h:630
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
CookBook()
Definition: CookBook_imp.h:694
std::unique_ptr< AbstractPointerCache > createPointerCache()
Definition: CookBook_imp.h:670
type
Definition: upload.py:443
CookBook & addRequiredFactory(std::function< std::shared_ptr< Type >(Dependencies...)> factory)
Definition: CookBook_imp.h:209
void acsdkError(const LogEntry &entry)
Type
Definition: Type.h:26
CookBook & addInstance(const Type &instance)
Definition: CookBook_imp.h:533
Definition: WeakPointerCache.h:29
const T & move(const T &t)
Definition: gtest-port.h:1317
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33