16 #ifndef ACSDKMANUFACTORY_INTERNAL_COOKBOOK_H_ 17 #define ACSDKMANUFACTORY_INTERNAL_COOKBOOK_H_ 22 #include <unordered_map> 23 #include <unordered_set> 33 namespace acsdkManufactory {
37 class RuntimeManufactory;
57 template <
typename Type,
typename... Dependencies>
68 template <
typename Type,
typename... Dependencies>
82 template <
typename Type,
typename... Dependencies>
97 template <
typename Annotation,
typename Type,
typename... Dependencies>
111 template <
typename Type,
typename... Dependencies>
126 template <
typename Annotation,
typename Type,
typename... Dependencies>
138 template <
typename Type,
typename... Dependencies>
151 template <
typename Annotation,
typename Type,
typename... Dependencies>
163 template <
typename Type,
typename... Dependencies>
176 template <
typename Annotation,
typename Type,
typename... Dependencies>
188 template <
typename Type,
typename... Dependencies>
201 template <
typename Annotation,
typename Type,
typename... Dependencies>
213 template <
typename Type,
typename... Dependencies>
226 template <
typename Annotation,
typename Type,
typename... Dependencies>
238 template <
typename Type,
typename... Dependencies>
251 template <
typename Annotation,
typename Type,
typename... Dependencies>
263 template <
typename Type,
typename... Dependencies>
276 template <
typename Annotation,
typename Type,
typename... Dependencies>
287 template <
typename Type>
325 template <
typename Type>
334 template <
typename Type>
344 using Factory =
void* (*)();
356 CachedInstanceLifecycle lifecycle,
357 std::vector<avsCommon::utils::TypeIndex> dependencies,
358 ProduceInstanceFunction produceFunction,
359 DeleteInstanceFunction deleteFunction);
364 ~FactoryRecipe() =
default;
370 Factory getFactory()
const;
374 bool isEquivalent(
const std::shared_ptr<AbstractRecipe>& recipe)
const override;
389 using Function =
void*;
393 using DeleteRecipeFunction = void (*)(
void*);
406 CachedInstanceLifecycle lifecycle,
407 std::vector<avsCommon::utils::TypeIndex> dependencies,
408 ProduceInstanceFunction produceFunction,
409 DeleteInstanceFunction deleteFunction,
410 DeleteRecipeFunction deleteRecipeFunction);
421 Function getFunction()
const;
425 bool isEquivalent(
const std::shared_ptr<AbstractRecipe>& recipe)
const override;
432 DeleteRecipeFunction m_deleteRecipeFunction;
448 std::shared_ptr<void> instance,
449 ProduceInstanceFunction produceFunction,
450 DeleteInstanceFunction deleteFunction);
455 ~InstanceRecipe() =
default;
461 std::shared_ptr<void> getInstance()
const;
465 bool isEquivalent(
const std::shared_ptr<AbstractRecipe>& recipe)
const override;
468 std::shared_ptr<void> m_instance;
484 template <
typename Type,
typename... Dependencies>
485 static void* produceFromSharedFactoryRecipe(
486 std::shared_ptr<AbstractRecipe> recipe,
504 template <
typename Type,
typename Annotation,
typename... Dependencies>
505 static void* produceFromAnnotatedSharedFactoryRecipe(
506 std::shared_ptr<AbstractRecipe> recipe,
523 template <
typename Type,
typename... Dependencies>
524 static void* produceFromSharedFunctionRecipe(
525 std::shared_ptr<AbstractRecipe> recipe,
543 template <
typename Type,
typename Annotation,
typename... Dependencies>
544 static void* produceFromAnnotatedSharedFunctionRecipe(
545 std::shared_ptr<AbstractRecipe> recipe,
555 template <
typename Type>
556 static void deleteFunctionForSharedRecipe(
void* cachedValue);
565 template <
typename Type,
typename... Dependencies>
566 static void deleteFunctionForFunctionRecipeFunction(
void*
function);
581 template <
typename Type,
typename... Dependencies>
582 static void* produceFromWeakFactoryRecipe(
583 std::shared_ptr<AbstractRecipe> recipe,
601 template <
typename Type,
typename Annotation,
typename... Dependencies>
602 static void* produceFromAnnotatedWeakFactoryRecipe(
603 std::shared_ptr<AbstractRecipe> recipe,
620 template <
typename Type,
typename... Dependencies>
621 static void* produceFromWeakFunctionRecipe(
622 std::shared_ptr<AbstractRecipe> recipe,
640 template <
typename Type,
typename Annotation,
typename... Dependencies>
641 static void* produceFromAnnotatedWeakFunctionRecipe(
642 std::shared_ptr<AbstractRecipe> recipe,
658 template <
typename Type,
typename... Dependencies>
659 static void* produceFromUniqueFactoryRecipe(
660 std::shared_ptr<AbstractRecipe> recipe,
676 template <
typename Type,
typename... Dependencies>
677 static void* produceFromUniqueFunctionRecipe(
678 std::shared_ptr<AbstractRecipe> recipe,
687 static void deleteFunctionForUniqueRecipe(
void* cachedValue);
697 static void* produceFromInstanceRecipe(
698 std::shared_ptr<AbstractRecipe> recipe,
707 static void deleteFunctionForInstanceRecipe(
void* cachedValue);
719 class GetWrapperCollection {
726 using GetWrapperIterator =
727 std::vector<bool (*)(RuntimeManufactory&), std::allocator<bool (*)(RuntimeManufactory&)>>::iterator;
728 using ConstGetWrapperIterator =
729 std::vector<bool (*)(RuntimeManufactory&), std::allocator<bool (*)(RuntimeManufactory&)>>::const_iterator;
739 template <
typename Type>
740 bool append(GetWrapper getWrapper);
747 void append(
const std::shared_ptr<GetWrapperCollection>& collection);
753 GetWrapperIterator begin();
759 GetWrapperIterator end();
765 ConstGetWrapperIterator cbegin()
const;
771 ConstGetWrapperIterator cend()
const;
777 ConstGetWrapperIterator begin()
const;
783 ConstGetWrapperIterator end()
const;
787 std::unordered_map<avsCommon::utils::TypeIndex, std::size_t> m_types;
790 std::vector<GetWrapper> m_orderedGetWrappers;
796 template <
typename Type,
typename... Dependencies>
797 using InstanceGetter = std::function<
Type(Dependencies...)>;
822 bool checkForCyclicDependencies();
830 bool checkIsValid(
const char* functionName)
const;
844 void logDependencies()
const;
855 template <
typename Type,
typename... Dependencies>
856 static Type invokeWithDependencies(
858 std::function<
Type(Dependencies...)>
function);
870 template <
typename Type,
typename FunctionType,
typename... Dependencies>
871 static Type innerInvokeWithDependencies(FunctionType
function, Dependencies... dependencies);
882 std::unordered_map<avsCommon::utils::TypeIndex, std::shared_ptr<AbstractRecipe>> m_recipes;
886 std::shared_ptr<GetWrapperCollection> m_primaryGets;
890 std::shared_ptr<GetWrapperCollection> m_requiredGets;
899 #endif // ACSDKMANUFACTORY_INTERNAL_COOKBOOK_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
bool checkCompleteness()
Definition: CookBook_imp.h:700
Definition: RuntimeManufactory.h:39
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
std::unique_ptr< Type > createUniquePointer(RuntimeManufactory &runtimeManufactory)
Definition: CookBook_imp.h:630
Definition: AbstractRecipe.h:31
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
Type
Definition: Type.h:26
CookBook & addInstance(const Type &instance)
Definition: CookBook_imp.h:533