11 template <
typename TYPE,
typename ORIGIN_TYPE >
24 m_pfree = pNew->m_pnext;
34 return factory_item < TYPE, ORIGIN_TYPE >::__callallocateø();
39 template <
typename TYPE,
typename ORIGIN_TYPE >
40 inline void reusable_factory_item < TYPE, ORIGIN_TYPE >::return_back(ORIGIN_TYPE * p)
52 template <
typename ORIGIN_TYPE >
53 inline ::pointer<ORIGIN_TYPE>factory::__call__create(
::particle * pparticle)
56 auto pfactoryinterface = get_factory_item < ORIGIN_TYPE >();
58 if (!pfactoryinterface)
61 throw_exception(error_no_factory);
65 auto p = pfactoryinterface->__call__create_particle();
67 p->initialize(pparticle);
74 template <
typename TYPE,
typename ORIGIN_TYPE>
75 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > factory::add_factory_item()
78 critical_section_lock lock(&m_criticalsection);
80 auto pfactory = allocateø ::factory::factory_item< TYPE, ORIGIN_TYPE > ();
82 auto typeindex = ::type_index < ORIGIN_TYPE >();
84 m_mapByTypeIndex[typeindex] = pfactory;
86 auto strTypeName = ::type_name < ORIGIN_TYPE >();
88 m_mapByTypeName[strTypeName] = pfactory;
95 template <
typename ORIGIN_TYPE >
96 inline void factory::__call__construct(::particle * pparticleInitializer, ::pointer < ORIGIN_TYPE > & p)
99 __call__raw_construct(p);
101 p->initialize(pparticleInitializer);
106 template <
typename ORIGIN_TYPE >
107 inline void factory::__call__raw_construct(::pointer<ORIGIN_TYPE> & p)
116 auto pfactoryitem = get_factory_item < ORIGIN_TYPE >();
123 strMessage =
"Factory hasn't creator for type \"" + ::platform::type(::type<ORIGIN_TYPE>()).name() +
"\"";
125 warningf(strMessage);
127 throw_exception(error_no_factory, strMessage);
131 auto pparticle = ::transfer(pfactoryitem->__call__create_particle());
138 strMessage =
"Couldn't __call__create_particle for type \"" + ::platform::type(::type<ORIGIN_TYPE>()).name() +
"\"";
140 warningf(strMessage);
142 throw_exception(error_no_memory, strMessage);
153 strMessage =
"Created element is not of the base type \"" + ::platform::type(::type<ORIGIN_TYPE>()).name() +
"\"";
155 warningf(strMessage);
157 throw_exception(error_wrong_type, strMessage);
166 template <
typename ORIGIN_TYPE >
167 inline ::factory::factory_item_interface * factory::get_factory_item()
const
170 auto typeindex = ::std::type_index(
typeid(ORIGIN_TYPE));
172 return _find_factory_item_by_type_index(typeindex);
287 template <
typename BASE_TYPE >
288 inline bool factory::__call__defer_construct(::particle * pparticle, ::pointer<BASE_TYPE> & ptype)
294#if REFERENCING_DEBUGGING
296 ::allocator::defer_erase_referer();
304 pparticle->__call__construct(ptype,
this);
314template <
typename TYPE >
315inline void particle__call__raw_construct2( ::pointer<TYPE> & p,
::factory::factory * pfactory COMMA_REFERENCING_DEBUGGING_PARAMETERS_DECLARATION)
318#if REFERENCING_DEBUGGING
320 ::allocator::push_referer(REFERENCING_DEBUGGING_ARGUMENTS);
324 __call_raw_construct(p, pfactory);
329template <
typename TYPE >
330inline void particle::__call__raw_construct(::pointer<TYPE>&p,
::factory::factory * pfactory COMMA_REFERENCING_DEBUGGING_PARAMETERS_DEFINITION)
334 if (::is_null(pfactory))
337 pfactory = this->factory();
341 auto pfactoryitem = pfactory->get_factory_item< TYPE >();
348 strMessage.formatf(
"matter::constructø has failed to find factory_item for type \"%s\"", ::platform::type(::type<TYPE>()).c_str());
350 throw_exception(::error_not_implemented, strMessage);
354 auto pparticleNew = pfactoryitem->__call__create_particle();
361 strMessage.formatf(
"matter::constructø no memory to allocate implementation of type \"%s\"", ::platform::type(::type<TYPE>()).c_str());
363 throw_exception(::error_no_memory, strMessage);
367 p = ::transfer(pparticleNew);
374 strMessage.formatf(
"matter::constructø object(%s) is not of type \"%s\"", ::platform::type(
typeid(*pparticleNew)).c_str(), ::platform::type(::type<TYPE>()).c_str());
376 throw_exception(::error_wrong_type, strMessage);
438template <
typename BASE_TYPE >
442 ::pointer<BASE_TYPE> p;
444 øraw_construct(p, pfactory);
446 return ::transfer(p);
477template <
typename TYPE >
478inline bool particle::__call__defer_construct(::pointer<TYPE>& p,
::factory::factory* pfactory)
484#if REFERENCING_DEBUGGING
486 ::allocator::defer_erase_referer();
493 __call__construct(p, pfactory);
518template <
typename TYPE >
519inline void particle::__call__construct_by_type(::pointer<TYPE> &p, const ::platform::type & type,
::factory::factory *pfactory)
522 if (::is_null(pfactory))
525 pfactory = this->factory();
529 auto pfactoryitem = pfactory->_find_factory_item(type);
531 if (::is_null(pfactoryitem))
536 strError.format(
"Factory item not found for type \"{}\"", type.as_string());
538 throw ::exception(error_not_found, strError);
542 auto pparticleNew = pfactoryitem->__call__create_particle();
556 throw_exception(error_wrong_type);
560 p->set_flag(e_flag_factory);
Definition critical_section.h:29
::pointer< ORIGIN_TYPE > __call__create() override
consumes a referer
Definition _impl_factory.h:12