acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
factory.h
1#pragma once
2
3
4#include <typeindex>
5
6#include "acme/exception/exception.h"
7#include "acme/parallelization/critical_section.h"
8#include "acme/prototype/collection/atom_map.h"
9#include "acme/prototype/collection/integer_map.h"
10#include "acme/prototype/collection/string_map.h"
11
12#include "acme/prototype/prototype/type.h"
13#include "acme/prototype/collection/list_iterator.h"
15//#include "acme/platform/library.h"
16
17
18template < typename TYPE >
19using pointer_key_map_base = ::map_base < pointer_key, TYPE >;
20
21
22//CLASS_DECL_ACME ::string demangle_name(const ::std::type_index & typeindex);
23
24
25CLASS_DECL_ACME string type_name(const ::std::type_info& typeinfo);
26
27
28//CLASS_DECL_ACME ::critical_section * factory_critical_section();
29//
30//template < typename TYPE >
31//inline void defer_constructø(::particle* pparticle, ::pointer<TYPE>& p, ::factory::factory * pfactory = nullptr);
32
33namespace factory
34{
35
36
37 class CLASS_DECL_ACME factory_item_interface :
38 virtual public ::particle
39 {
40 public:
41
42
43 factory_item_interface();
44 ~factory_item_interface() override;
45
46
47 virtual string base_type_raw_name() const;
48
49 virtual string base_type_name() const;
50
51 virtual string type_raw_name() const;
52
53 virtual string type_name() const;
54
55 virtual ::pointer < ::subparticle > __call__create_particle();
56
57 virtual void return_back(::subparticle * pelement);
58
59
60 };
61
62
63 template < typename ORIGIN_TYPE >
64 class factory_item_base :
65 public factory_item_interface
66 {
67 public:
68
69
70 factory_item_base()
71 {
72
73
74 }
75
76 ~factory_item_base() override
77 {
78
79
80 }
81
82 string base_type_raw_name() const override { return ::type_raw_name(typeid(ORIGIN_TYPE)); }
83 string base_type_name() const override { return ::type_name(typeid(ORIGIN_TYPE)); }
84
85 virtual ::pointer<ORIGIN_TYPE> __call__create() = 0;
86
87
89 virtual ::pointer < ::subparticle > __call__create_particle() override
90 {
91
92 return __call__create();
93
94 }
95
96
97 virtual void return_back(::subparticle * pelement) override
98 {
99
100 delete pelement;
101
102 }
103
104
105 };
106
107
108 template < typename TYPE, typename ORIGIN_TYPE >
109 class factory_item :
110 public factory_item_base < ORIGIN_TYPE >
111 {
112 public:
113
114
115 factory_item()
116 {
117
118
119 }
120
121 ~factory_item() override
122 {
123
124
125 }
126
127
128 string type_raw_name() const override { return ::type_raw_name(typeid(TYPE)); }
129 string type_name() const override { return ::type_name(typeid(TYPE)); }
130
131
133 ::pointer<ORIGIN_TYPE>__call__create() override
134 {
135
136 return { place_t{}, __new_refdbg_continuation TYPE() };
137
138 }
139
140
141 };
142
143
144 template < typename TYPE, typename ORIGIN_TYPE >
146 public factory_item < TYPE, ORIGIN_TYPE >
147 {
148 public:
149
150 critical_section m_criticalsection;
151
152 ORIGIN_TYPE * m_pfree;
153
155 {
156
157 free_all();
158
159 }
160
161 ::pointer<ORIGIN_TYPE>__call__create() override;
162
163 void return_back(ORIGIN_TYPE * p);
164
165 void free_all()
166 {
167
168 while (m_pfree)
169 {
170
171 auto p = m_pfree;
172
173 m_pfree = m_pfree->m_pnext;
174
175 try
176 {
177
178 delete p;
179
180 }
181 catch (...)
182 {
183
184 }
185
186 }
187
188 }
189
190 };
191
192
193 //using factory_base_by_type_index_pointer = ::pointer_key_map_base < ::pointer < factory_item_interface > >;
194 using factory_base_by_string = ::string_map_base<::pointer<factory_item_interface>>;
195 using factory_base_by_type_index = ::map < ::std::type_index, ::pointer < factory_item_interface > >;
196 using factory_base_by_custom_ipair_id = ::map_base<type_iptr_pair, ::pointer<factory_item_interface>>;
197
198
199 class CLASS_DECL_ACME factory :
200 virtual public ::particle
201 {
202 public:
203
204
205 //factory_base_by_type_index_pointer m_mapByRawNamePointer;
206 factory_base_by_string m_mapByTypeName;
207 factory_base_by_string m_mapByCustomNameId2;
208 factory_base_by_type_index m_mapByTypeIndex;
209 factory_base_by_custom_ipair_id m_mapByCustomIpairId;
210 ::atom m_atomSource;
211 ::pointer<::acme::library> m_plibrary;
212 ::critical_section m_criticalsection;
213 ::string m_strArgument;
214
215
216 factory();
217 ~factory();
218
219
220 //::pointer<::factory::factory_item_interface>& get_factory_item_by_type_index(const ::std::type_index & typeindex);
221 //::pointer<::factory::factory_item_interface>& get_factory_item_by_custom_id(const ::platform::type & type);
222
223 //inline ::pointer<::factory::factory_item_interface>& get_factory_item_from(const ::platform::type & type, const ::platform::type & typeSource);
224
225 //inline ::factory::factory_item_interface * _find_factory_item_by_type_index(const ::std::type_index & typeindex) const;
226
227 ::factory::factory_item_interface * _find_factory_item_by_type_index(const ::std::type_index & typeindex) const;
228 ::factory::factory_item_interface * _find_factory_item_by_type_name(const ::scoped_string & scopedstrTypeName) const;
229 ::factory::factory_item_interface * _find_factory_item_by_type_id(const ::type_id & type_id) const;
230 ::factory::factory_item_interface * _find_factory_item_by_custom_id(const ::type_custom_id & typecustomid) const;
231 ::factory::factory_item_interface * _find_factory_item_by_ipair(const ::type_iptr_pair& ipair) const;
232 ::factory::factory_item_interface * _find_factory_item(const ::platform::type & type) const;
233
234 //::factory::factory_item_interface * get_factory_item_by_type_index(const ::std::type_index & typeindex) const;
235 //::factory::factory_item_interface * get_factory_item_by_type_name(const ::scoped_string & scopedstrTypeName) const;
236 //::factory::factory_item_interface * get_factory_item_by_type_id(const ::type_id & type_id) const;
237 //::factory::factory_item_interface * get_factory_item_by_custom_id(const ::type_custom_id & typecustomid) const;
238
239
240 bool has_factory_item_by_type_index(const ::std::type_index & typeindex) const;
241 bool has_factory_item_by_type_name(const ::scoped_string & scopedstrTypeName) const;
242 bool has_factory_item_by_custom_id(const ::type_custom_id & typecustomid) const;
243 bool has_factory_item(const ::platform::type & type) const;
244
245
246 template<typename ORIGIN_TYPE>
247 bool has_factory_item() const
248 {
249
250 auto typeindex = ::std::type_index(typeid(ORIGIN_TYPE));
251
252 return this->has_factory_item_by_type_index(typeindex);
253
254 }
255
256
257 template<typename ORIGIN_TYPE>
258 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > find_factory_item() const
259 {
260
261 auto typeindex = ::std::type_index(typeid(ORIGIN_TYPE));
262
263 auto pfactoryiteminterface = this->_find_factory_item_by_type_index(typeindex);
264
265 pointer< ::factory::factory_item_base < ORIGIN_TYPE > > pfactoryitembase;
266
267 pfactoryitembase = pfactoryiteminterface;
268
269 return pfactoryitembase;
270
271 }
272
273
274 //inline ::factory::factory_item_interface * get_factory_item_from(const ::platform::type & type, const ::platform::type & typeSource) const;
275
276 template < typename ORIGIN_TYPE >
277 inline ::factory::factory_item_interface * get_factory_item() const;
278
279 //template < typename ORIGIN_TYPE >
280 //inline ::factory::factory_item_interface * get_factory_item(const ::platform::type & type);
281 //inline ::pointer<factory_item_interface>& get_factory_item(const ::platform::type & type)
282
283 template < typename BASE_TYPE >
284 inline bool __call__defer_construct(::particle * pparticle, ::pointer<BASE_TYPE> & ptype);
285 template < typename TYPE, typename ORIGIN_TYPE>
286 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > _add_factory_item_from(const ::platform::type & typeSource);
287
288
289#if REFERENCING_DEBUGGING
290
291
292 factory * __call__add_referer2(const ::reference_referer & referer) const;
293
294#endif
295
296 //template < typename ORIGIN_TYPE >
297 //inline ::pointer<::factory::factory_item_interface>& get_factory_item_from(const ::platform::type & typeSource);
298
299 template < typename TYPE, typename ORIGIN_TYPE = TYPE >
300 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item();
301
302 template < typename TYPE, typename ORIGIN_TYPE = TYPE >
303 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > defer_add_factory_item()
304 {
305
306 auto pfactoryitem = this->find_factory_item<ORIGIN_TYPE>();
307
308 if (!pfactoryitem)
309 {
310
311 pfactoryitem = add_factory_item<TYPE, ORIGIN_TYPE>();
312
313 }
314
315 return pfactoryitem;
316
317 }
318
319
320 template < typename ORIGIN_TYPE >
321 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item_with_custom_id(const ::type_custom_id & typecustomid);
322 //template < typename TYPE, typename ORIGIN_TYPE >
323 //inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item_from(const ::platform::type & typeSource);
324 virtual void set_factory_item_by_custom_id(const ::type_custom_id & typecustomid, const ::pointer<::factory::factory_item_interface> & pfactoryitem);
325 virtual void set_factory_item_by_type(const ::platform::type & type, const ::pointer<::factory::factory_item_interface> & pfactoryitem);
326
327 template < typename TYPE, typename ORIGIN_TYPE>
328 inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > create_reusable_factory_item();
329
330 template < typename ORIGIN_TYPE >
331 inline ::pointer<ORIGIN_TYPE>__call__create(::particle * pparticle);
332
333 void merge(const ::factory::factory* pfactory);
334
335 void merge_to_global_factory() const;
336
337 void set_currently_loading_library();
338
339 void terminate();
340
341 template < typename ORIGIN_TYPE >
342 inline void __defer_raw_construct( ::pointer<ORIGIN_TYPE> & p)
343 {
344
345 if (::is_null(p))
346 {
347
348 this->øraw_construct(p);
349
350 }
351
352 }
353
354
355 template < typename ORIGIN_TYPE >
356 inline void __call__construct(::particle * pparticleInitializer, ::pointer<ORIGIN_TYPE> & p);
357
358
359 template < typename ORIGIN_TYPE >
360 inline void __call__raw_construct(::pointer<ORIGIN_TYPE> & p);
361
362
363 //virtual ::particle_pointer __call__create_by_type_index(const ::std::type_index & typeindex, ::particle * pparticle);
364 //virtual ::particle_pointer __call__create_by_type_name(const ::scoped_string & scopedstrTypeName, ::particle * pparticle);
365 virtual ::particle_pointer __call__create_by_custom_id(const ::type_custom_id & typecustomid, ::particle* pparticle);
366 //virtual ::particle_pointer __call__create_by_type(const ::platform::type & type, ::particle* pparticle);
367
368
369 //virtual bool has_by_type_index(const ::std::type_index & typeindex) const;
370 //virtual bool has_by_type_name(const ::scoped_string & scopedstrTypeName) const;
371 //virtual bool has_by_custom_id(const ::type_custom_id & typecustomid) const;
372 //virtual bool has(const ::platform::type & type) const;
373
374
375 // template < typename TYPE >
376 // bool has() const
377 // {
378 //
379 // return this->has_by_type_index(::std::type_index(typeid(TYPE)));
380 //
381 // }
382
383
384 };
385
386
387
388 using factory_array = pointer_array < factory_item_interface >;
389
390// //CLASS_DECL_ACME factory * get_factory();
391//
392// ///CLASS_DECL_ACME factory * get_factory(const ::platform::type & typeSource);
393// ///
394//
395//
396// //CLASS_DECL_ACME factory_item_interface * get_factory_item_by_type_index(const ::std::type_index & typeindex);
397// //CLASS_DECL_ACME factory_item_interface * get_factory_item_by_custom_id(const ::type_custom_id & typecustomid);
398//
399//
400// //CLASS_DECL_ACME factory_item_interface * get_existing_factory_item_by_type_index(const ::std::type_index & typeindex);
401// //CLASS_DECL_ACME factory_item_interface * get_existing_factory_item_by_custom_id(const ::type_custom_id & typecustomid);
402//
403//
404// //CLASS_DECL_ACME factory_item_interface * get_factory_item_by_type_index(const ::std::type_index & typeindex, const ::atom & atomFactory);
405// //CLASS_DECL_ACME factory_item_interface * get_factory_item_by_custom_id(const ::platform::type & type, const ::atom & atomFactory);
406//
407//
408// //CLASS_DECL_ACME bool has_by_type_index(const ::std::type_index & typeindex);
409// //CLASS_DECL_ACME bool has_by_custom_id(const ::type_custom_id & typecustomid);
410//
411//
412//
413// //CLASS_DECL_ACME void set_factory_item_by_type(const ::platform::type & type, const ::pointer<factory_item_interface>& pfactory);
414//
415// template < typename ORIGIN_TYPE >
416// inline ::atom get_id();
417// // {
418// //
419// // auto pszTypename = ::type<ORIGIN_TYPE>().name();
420// //
421// //#ifdef WINDOWS
422// //
423// // pszTypename = c_demangle(scopedstrTypename);
424// //
425// // return pszTypename;
426// //
427// //#else
428// //
429// // auto strTypename = ::transfer(demangle(scopedstrTypename));
430// //
431// // return strTypename;
432// //
433// //
434// //#endif
435// //
436// // }
437//
438//
439// //template < typename ORIGIN_TYPE >
440// //inline ::pointer<factory_item_interface>& get_factory_item();
441// // {
442// //
443// // //static auto atom = get_atom<ORIGIN_TYPE>();
444// //
445// // //return get_factory_item(atom);
446// //
447// // return get_factory_item(get_atom<ORIGIN_TYPE>());
448// //
449// // }
450//
451//
452// //template < typename ORIGIN_TYPE >
453// //inline ::pointer<factory_item_interface> get_factory_item_by_type_index(const ::std::type_index & typeindex);
454//
455// //template < typename ORIGIN_TYPE >
456// //inline ::pointer<factory_item_interface> get_factory_item_by_custom_id(const ::type_custom_id & typecustomid);
457//
458//
459// // {
460// //
461// // //static auto atom = get_atom<ORIGIN_TYPE>();
462// //
463// // //return get_factory_item(atom, atomSource);
464// //
465// // ///static auto atom = get_atom<ORIGIN_TYPE>();
466// //
467// // return get_factory_item(atomSource, get_atom<ORIGIN_TYPE>());
468// //
469// // }
470
471
472} // namespace factory
473
474
475// using factory_pointer = ::pointer<::factory::factory>;
476
477
478// namespace factory
479// {
480
481
482// template < typename TYPE, typename ORIGIN_TYPE = TYPE >
483// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item();
484
485
486// template < typename TYPE, typename ORIGIN_TYPE = TYPE >
487// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item(const ::platform::type & type);
488
489
490// template < typename TYPE, typename ORIGIN_TYPE = TYPE >
491// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item_from(const ::platform::type & typeSource);
492
493
494// template < typename TYPE, typename ORIGIN_TYPE = TYPE >
495// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > create_reusable_factory();
496
497
498// template < typename TYPE >
499// ::pointer<TYPE>__call__create();
500
501
502// } // namespace factory
503
504
505
506
507
508
509namespace factory
510{
511
512
513 //CLASS_DECL_ACME critical_section * &m_criticalsection;
514
515
516 template < typename TYPE >
517 inline pointer< ::factory::factory_item_base < TYPE > > factory::add_factory_item_with_custom_id(const ::type_custom_id & typecustomid)
518 {
519
520 if (typecustomid.is_empty())
521 {
522
523 throw ::exception(error_bad_argument, "type custom id is not set");
524
525 }
526
527 critical_section_lock lock(&m_criticalsection);
528
529 auto pfactoryitem = allocateø ::factory::factory_item< TYPE, TYPE > ();
530
531 set_factory_item_by_custom_id(typecustomid, pfactoryitem);
532
533 return pfactoryitem;
534
535 }
536
537
538 CLASS_DECL_ACME::factory::factory * loading_library_factory();
539
540//
541// template < typename TYPE, typename ORIGIN_TYPE>
542// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > factory::_add_factory_item_from(const ::platform::type & typeSource)
543// {
544//
546//
547// auto pfactory = ::factory::loading_library_factory();
548//
549// if (::is_set(pfactory))
550// {
551//
552// return pfactory->add_factory_item < TYPE, ORIGIN_TYPE >();
553//
554// }
555//
556// critical_section_lock lock(&m_criticalsection);
557//
558// auto pfactoryitem = allocateø ::factory::factory_item< TYPE, ORIGIN_TYPE > ();
559//
560// get_factory_item < ORIGIN_TYPE >(atomSource) = pfactoryitem;
561//
562// return pfactoryitem;
563//
564// }
565//
566
567 //template < typename TYPE, typename ORIGIN_TYPE>
568 //inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > add_factory_item()
569 //{
570
571 // critical_section_lock lock(&m_criticalsection);
572
573 // auto pfactory = allocateø ::factory::factory_item< TYPE, ORIGIN_TYPE > ();
574
575 // factory_item < ORIGIN_TYPE >() = pfactory;
576
577 // return pfactory;
578
579 //}
580
581
582// template < typename TYPE, typename ORIGIN_TYPE>
583// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > factory::create_reusable_factory_item()
584// {
585//
586// critical_section_lock lock(&m_criticalsection);
587//
588// auto pfactory = allocateø ::factory::reusable_factory_item< TYPE, ORIGIN_TYPE > ();
589//
590// factory_item < TYPE, ORIGIN_TYPE >() = pfactory;
591//
592// return pfactory;
593//
594// }
595
596
597} // namespace factory
598
599
600
601
602namespace factory
603{
604
605//
606// template < typename TYPE, typename ORIGIN_TYPE >
607// inline ::pointer<ORIGIN_TYPE>reusable_factory_item < TYPE, ORIGIN_TYPE >::__call__create()
608// {
609//
610// {
611//
612// critical_section_lock lock(&m_criticalsection);
613//
614// if (m_pfree)
615// {
616//
617// auto pNew = m_pfree;
618//
619// m_pfree = pNew->m_pnext;
620//
621// pNew->reuse();
622//
623// return pNew;
624//
625// }
626//
627// }
628//
629// return factory_item < TYPE, ORIGIN_TYPE >::_call_new();
630//
631// }
632
633//
634// template < typename TYPE, typename ORIGIN_TYPE >
635// inline void reusable_factory_item < TYPE, ORIGIN_TYPE >::return_back(ORIGIN_TYPE * p)
636// {
637//
638// critical_section_lock lock(&m_criticalsection);
639//
640// p->m_pnext = m_pfree;
641//
642// m_pfree = p;
643//
644// }
645
646
647// template < typename ORIGIN_TYPE >
648// inline ::pointer<ORIGIN_TYPE>factory::__call__create()
649// {
650//
651// auto pfactoryinterface = get_factory_item < ORIGIN_TYPE >();
652//
653// if (!pfactoryinterface)
654// {
655//
656// throw_exception(error_no_factory);
657//
658// }
659//
660// return pfactoryinterface->__call__create_particle();
661//
662// }
663
664//
665// template < typename TYPE, typename ORIGIN_TYPE>
666// inline pointer< ::factory::factory_item_base < ORIGIN_TYPE > > factory::add_factory_item()
667// {
668//
669// critical_section_lock lock(&m_criticalsection);
670//
671// auto pfactory = allocateø ::factory::factory_item< TYPE, ORIGIN_TYPE > ();
672//
673// this->get_factory_item < ORIGIN_TYPE >() = pfactory;
674//
675// return pfactory;
676//
677// }
678
679//
680// template < typename ORIGIN_TYPE >
681// inline void factory::constructø(::particle * pparticleInitializer, ::pointer < ORIGIN_TYPE > & p)
682// {
683//
684// øraw_construct(p);
685//
686// p->initialize(pparticleInitializer);
687//
688// }
689//
690
691// template < typename ORIGIN_TYPE >
692// inline void factory::øraw_construct(::pointer<ORIGIN_TYPE> & p)
693// {
694//
695// auto & pfactoryitem = get_factory_item < ORIGIN_TYPE >();
696//
697// if (!pfactoryitem)
698// {
699//
700// throw_exception(error_no_factory, "Factory hasn't creator for type \"" + __type_name<ORIGIN_TYPE>() + "\"");
701//
702// }
703//
704// auto pparticle = ::transfer(pfactoryitem->__call__create_particle());
705//
706// if (!pparticle)
707// {
708//
709// throw_exception(error_no_memory, "Couldn't __call__create_particle for type \"" + __type_name<ORIGIN_TYPE>() + "\"");
710//
711// }
712//
713// p = pparticle;
714//
715// if (!p)
716// {
717//
718// throw_exception(error_wrong_type, "Created element is not of the base type \"" + __type_name<ORIGIN_TYPE>() + "\"");
719//
720// }
721//
722// }
723//
724
725
726// inline ::factory::factory_item_interface * factory::get_factory_item(const ::platform::type & type) const
727// {
728//
729// critical_section_lock cs(&((factory*)this)->m_criticalsection);
730//
731// auto iterator = this->find(atom);
732//
733// if (iterator.is_null())
734// {
735//
736// return nullptr;
737//
738// }
739//
740// return iterator->m_element2;
741//
742// }
743
744
745// template < typename ORIGIN_TYPE >
746// inline ::pointer<::factory::factory_item_interface> & factory::get_factory_item()
747// {
748//
749// string strTypename(::type<ORIGIN_TYPE>().name());
750//
751// strTypename = ::demangle(strTypename);
752//
753// return get_factory_item(strTypename);
754//
755// }
756
757
758 //inline ::pointer<::factory::factory_item_interface> & factory::get_factory_item(const ::platform::type & type);
759// {
760//
761// critical_section_lock cs(&m_criticalsection);
762//
763//
764// return this->operator[](atom);
765//
766// }
767
768
769 //inline ::pointer<factory_item_interface> & factory::get_factory_item(const ::platform::type & type)
770 //{
771
772 // critical_section_lock cs(&m_criticalsection);
773
774 // return (*get_factory())[atom];
775
776 //}
777
778
779 inline ::pointer<factory_item_interface> & get_existing_factory_item(const ::platform::type & type);
780// {
781//
782// auto & pfactoryitem = get_factory_item(atom);
783//
784// if (!pfactoryitem)
785// {
786//
787// throw_exception(error_no_factory, "No factory for \"" + atom + "\"");
788//
789// }
790//
791// return pfactoryitem;
792//
793// }
794//
795
796
797
798 //template < typename TYPE >
799 //inline stream & load_object(stream & stream, ::pointer<TYPE>& p)
800 //{
801
802 // string strText;
803
804 // stream >> strText;
805
806 // if (strText.is_empty() || strText.case_insensitive_begins_eat("factoryless://"))
807 // {
808
809 // if (p && ::platform::type(p).name()) == strText
810 // {
811
812 // informationf("loading into existing matter of same class type (1)");
813
814 // }
815 // else
816 // {
817
818 // p.defer_create_new();
819
820 // if (!p)
821 // {
822
823 // informationf("defer_new failed (1.1)");
824
825 // stream.set_fail_bit();
826
827 // }
828 // else if (::platform::type(p).name()) != strText
829 // {
830
831 // informationf("allocated matter type is different from streamed matter type (1.2)");
832
833 // stream.set_fail_bit();
834
835 // }
836
837 // }
838
839 // }
840 // else
841 // {
842
843 // auto atom = stream.text_to_factory_id(strText);
844
845 // if (p && atom == ::platform::type(p).name())
846 // {
847
848 // informationf("loading into existing matter of same class type (2)");
849
850 // }
851 // else
852 // {
853
854 // p = stream.create_object_from_text(strText);
855
856 // if (!p)
857 // {
858
859 // informationf("stream::alloc_object_from_text failed (2.1)");
860
861 // }
862 // else if (::platform::type(p).name()) != atom.to_string()
863 // {
864
865 // informationf("allocated matter type is different from streamed matter type (2.2)");
866
867 // stream.set_fail_bit();
868
869 // }
870
871 // }
872
873 // }
874
875 // if (!stream.fail())
876 // {
877
878 // if (p->has(e_object_factory))
879 // {
880
881 // p->read(stream);
882
883 // }
884 // else
885 // {
886
887 // stream >> *p;
888
889 // }
890
891 // }
892
893 // return stream;
894
895 //}
896
897
898} // namespace factory
899
900
901//#include "_factory.h"
902//
903//
904//namespace factory
905//{
906//
907//
908// template < typename BASE_TYPE >
909// inline void factory::defer_constructø(::particle * pparticle, ::pointer<BASE_TYPE> & ptype)
910// {
911//
912// ::defer_constructø(pparticle, ptype, this);
913//
914// }
915//
916//
917//} // namespace factory
918//
919//
920//template < typename TYPE >
921//inline void øraw_construct(::pointer<TYPE>& p, ::factory::factory * pfactory = nullptr);
922//{
923//
924// auto& pfactoryitem = pfactory->get_factory_item< TYPE >();
925//
926// if (!pfactoryitem)
927// {
928//
929// string strMessage;
930//
931// strMessage.formatf("matter::constructø has failed to find factory_item for type \"%s\"", __type_name < TYPE >().c_str());
932//
933// throw_exception(::error_not_implemented, strMessage);
934//
935// }
936//
937// auto pparticleNew = pfactoryitem->__call__create_particle();
938//
939// if (!pparticleNew)
940// {
941//
942// string strMessage;
943//
944// strMessage.formatf("matter::constructø no memory to allocate implementation of type \"%ss\"", __type_name < TYPE >().c_str());
945//
946// throw_exception(::error_no_memory, strMessage);
947//
948// }
949//
950// p.release();
951//
952// p = pparticleNew;
953//
954// if (!p)
955// {
956//
957// string strMessage;
958//
959// strMessage.formatf("matter::constructø object(%s) is not of type \"%s\"", ::platform::type(pparticleNew).name().c_str(), __type_name < TYPE >().c_str());
960//
961// throw_exception(::error_wrong_type, strMessage);
962//
963// }
964//
965//}
966
967
968template < typename BASE_TYPE >
969inline ::pointer<BASE_TYPE> __raw_create(::factory::factory* pfactory);
970//{
971//
972// ::pointer<BASE_TYPE> p;
973//
974// øraw_construct(p, pfactory);
975//
976// return ::transfer(p);
977//
978//}
979
980
981//template < typename TYPE >
982//inline void constructø(::particle* pparticle, ::pointer<TYPE>& p, ::factory::factory * pfactory = nullptr);
983//{
984//
985// øraw_construct(p, pfactory);
986//
987// p->initialize(pparticle);
988//
989//}
990//
991
992//template < typename BASE_TYPE >
993//inline ::pointer < BASE_TYPE > createø(::particle* pparticle, ::factory::factory * pfactory = nullptr);
994//{
995//
996// ::pointer < BASE_TYPE > p;
997//
998// constructø(pparticle, p, pfactory);
999//
1000// return p;
1001//
1002//}
1003
1004
1005//template < typename TYPE >
1006//inline void __call__defer_construct(::particle* pparticle, ::pointer<TYPE>& p, ::factory::factory* pfactory);
1007//{
1008//
1009// if (!p)
1010// {
1011//
1012// constructø(pparticle, p, pfactory);
1013//
1014// }
1015//
1016//
1017//}
1018
1019
1020
1021
1022
1023//template < typename TYPE >
1024//inline void øconstruct_by_custom_id(particle* pparticle, ::pointer<TYPE>& p, const ::platform::type & type, ::factory::factory * pfactory = nullptr);
1025//{
1026//
1027// auto& pfactoryitem = pfactory->get_factory_item(atom);
1028//
1029// auto pparticleNew = pfactoryitem->__call__create_particle();
1030//
1031// //if (!pparticleNew)
1032// //{
1033//
1034// // return error_no_memory;
1035//
1036// //}
1037//
1038// p = pparticleNew;
1039//
1040// if (!p)
1041// {
1042//
1043// throw_exception(error_wrong_type);
1044//
1045// }
1046//
1047// p->set_flag(e_flag_factory);
1048//
1049// //auto estatus =
1050//
1051// p->initialize(pparticle);
1052//
1053// //if (!estatus)
1054// //{
1055//
1056// // return estatus;
1057//
1058// //}
1059//
1060// //return estatus;
1061//
1062//}
1063
1064
1065//template < typename TYPE >
1066//inline ::pointer < TYPE > øcreate_by_custom_id(particle* pparticle, const ::platform::type & type, ::factory::factory * pfactory = nullptr);
1067//{
1068//
1069// auto& pfactoryitem = pfactory->get_factory_item(atom);
1070//
1071// auto pparticleNew = pfactoryitem->__call__create_particle();
1072//
1073// //if (!pparticleNew)
1074// //{
1075//
1076// // return error_no_memory;
1077//
1078// //}
1079//
1080//
1081//
1082// ::pointer < TYPE > p = pparticleNew;
1083//
1084// if (!p)
1085// {
1086//
1087// throw_exception(error_wrong_type);
1088//
1089// }
1090//
1091// p->set_flag(e_flag_factory);
1092//
1093// //auto estatus =
1094//
1095// p->initialize(pparticle);
1096//
1097// //if (!estatus)
1098// //{
1099//
1100// // return estatus;
1101//
1102// //}
1103//
1104// //return estatus;
1105//
1106// return p;
1107//
1108//}
1109
1110//
1111//template < class T >
1112//template < typename PARTICLE >
1113//inline pointer < T >& pointer < T >::__call__create(PARTICLE* pparticle, ::factory::factory* pfactory)
1114//{
1115//
1116// auto p = ::createø < T >(pparticle);
1117//
1118// return operator =(p);
1119//
1120//}
1121
1122
1123
Definition atom.h:237
Definition critical_section.h:9
virtual ::pointer< ::subparticle > __call__create_particle() override
consumes a referer
Definition factory.h:89
Definition factory.h:39
::pointer< ORIGIN_TYPE > __call__create() override
consumes a referer
Definition factory.h:133
Definition factory.h:201
Definition factory.h:147
::pointer< ORIGIN_TYPE > __call__create() override
consumes a referer
Definition _impl_factory.h:12
Definition string_map.h:10
Definition subparticle.h:78
Definition type.h:46
Definition pointer.h:9