acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_impl.h
1#pragma once
2
3
4
5
6//template < typename TYPE >
7//inline void __string_exchange(::binary_stream & s, TYPE & t)
8//{
9//
10// // __string_exchange and __exchange may mutually call each other, causing infinite recursion
11// // if a certain TYPE causes infinite recursion, either a customized __string_exchange
12// // or __exchange function for that type should be declared and implemented.
13// __exchange(s, t);
14//
15//}
16//
17
18//template < typename TYPE >
19//inline void operator(::string & s, TYPE & t)
20//{
21//
22// if (s.is_storing())
23// {
24//
25// t.to_string(str);
26//
27// }
28// else
29// {
30//
31// t.from_string(str);
32//
33// }
34//
35//}
36
37
38//inline void __string_exchange(binary_stream & s, ::payload & payload) { s.default_exchange(payload.string_reference()); }
39
40
41//template < typename BLOCK_TYPE >
42//inline void __exchange(binary_stream & s, memory_template < BLOCK_TYPE > & memorytemplate)
43//{
44//
45// auto block = memorytemplate.block();
46//
47// if(s.is_loading())
48// {
49//
50// s.read(block);
51//
52// }
53// else
54// {
55//
56// s.write(block);
57//
58// }
59//
60//}
61//
62//inline void __exchange(binary_stream & s, memory_base & memory)
63//{
64// s.is_loading() ? s.read(memory) : s.write(memory);
65//}
66//
72//
73
74
75
76//
77//
78//
87//
88//
91//
92//
96//
98//
100//
102//
104//
106//
107//
111//
130//
132//
134//
135//
149//
150//
168//
169//
170//template < class STREAM, class KEY, class ARG_KEY, class PAYLOAD, class ARG_VALUE, class PAIR >
171//inline void __exchange(STREAM & s, map_base < KEY, ARG_KEY, PAYLOAD, ARG_VALUE, PAIR > & m)
172//{
173//
174// if (s.is_storing())
175// {
176//
177// ::collection::count c = m.get_count();
178//
179// s << c;
180//
181// for (auto& pair : m)
182// {
183//
184// s << pair.element1();
185//
186// //if (s.fail())
187// // break;
188//
189// s << pair.element2();
190//
191// //if (s.fail())
192// // break;
193//
194// }
195//
196// }
197// else
198// {
199//
200// ::collection::count c = 0;
201//
202// s >> c;
203//
204// while (c > 0)
205// {
206//
207// c--;
208// typename map_base < KEY, ARG_KEY, PAYLOAD, ARG_VALUE, PAIR >::BASE_KEY element1;
209// //typename map_base < KEY, ARG_KEY, PAYLOAD, ARG_VALUE, PAIR >::BASE_VALUE element2;
210// s >> element1;
211// //if (s.fail())
212// // break;
213// s >> m[element1];
214// //if (s.fail())
215// // break;
216// //m.set_at(element1, element2);
217// }
218//
219// }
220//
221//
222//}
223//template < typename TYPE >
224//inline binary_stream & operator <<(binary_stream & s, const pointer_array < TYPE > & a)
225//{
226//
227// ::collection::count c = a.get_count();
228//
229// s << c;
230//
231// for (auto & matter : a.ptra())
232// {
233//
234// if (matter.is_null())
235// {
236//
237// throw ::exception(error_io);
238//
239// return s;
240//
241// }
242//
243// __save_object(s, matter);
244//
245// //if (s.fail())
246// //{
247//
248// // s.set_fail_bit();
249//
250// //}
251//
252// }
253//
254// return s;
255//
256//}
257//
258//
259//template < typename TYPE >
260//inline binary_stream & operator >>(binary_stream & s, pointer_array < TYPE > & a)
261//{
262//
263// ::collection::count c = 0;
264//
265// s >> c;
266//
267// if (c < 0)
268// {
269//
270// throw ::exception(error_io);
271//
272// }
273//
274// ::collection::index i = 0;
275//
276// for (; i < c; i++)
277// {
278//
279// auto pmatter = __load_object < TYPE >(s);
280//
281// if (!pmatter)
282// {
283//
284// throw ::exception(error_io);
285//
286// break;
287//
288// }
289//
290// a.add(pmatter);
291//
292// }
293//
294// return s;
295//
296//}
297//
298//
396
397
398
400//inline binary_stream & operator <<(binary_stream & s, const ::earth::time & time)
401//{
402//
403// s << time.m_i32;
404//
405// return s;
406//
407//}
408
409
411//inline binary_stream & operator >>(binary_stream & s, ::earth::time & time)
412//{
413//
414// s >> time.m_i32;
415//
416// return s;
417//
418//}
419
420//
421//
422//inline binary_stream & operator <<(binary_stream & s, const ::memory_base & memory)
423//{
424//
425// s.write(memory);
426//
427// return s;
428//
429//}
430//
431//
432//
433//inline binary_stream & operator >>(binary_stream & s, ::memory_base & memory)
434//{
435//
436// s.read(memory);
437//
438// return s;
439//
440//}
441//
442//
443
444//
445//inline binary_stream & operator << (binary_stream & s, ::file::file * pfile)
446//{
447//
448// memory m;
449//
450// m.set_size(minimum((memsize)pfile->get_remaining_byte_count(), (memsize)1024 * 1024));
451//
452// memsize sizeRead;
453//
454// while ((sizeRead = pfile->read(m.get_data(), m.get_size())) > 0)
455// {
456//
457// s.write((const void *) m.get_data(), sizeRead);
458//
459// }
460//
461// return s;
462//
463//}
464//
465//
466//template < typename BASE_TYPE >
467//::pointer<BASE_TYPE>__load_object(binary_stream & binary_stream)
468//{
469//
470// string strText;
471//
472// binary_stream >> strText;
473//
474// if (strText.is_empty())
475// {
476//
477// //binary_stream.setstate(::file::failbit);
478//
479// throw ::exception(error_io);
480//
481// return nullptr;
482//
483// }
484//
485// //auto atom = binary_stream.text_to_factory_id(strText);
486//
487// if (!strText.case_insensitive_begins_eat("factoryless://"))
488// {
489//
490// strText = as_string(binary_stream.text_to_factory_id(strText));
491//
492// }
493//
494// ::pointer<matter>p = binary_stream.create_object_from_text(strText);
495//
496// if (!p)
497// {
498//
499// throw ::exception(error_io);
500//
501// return nullptr;
502//
503// }
504//
505// p->exchange(binary_stream);
506//
507// return p;
508//
509//}
510//
511//
512//
513//template < typename BASE_TYPE >
514//inline binary_stream & __save_object(binary_stream & binary_stream, BASE_TYPE * p)
515//{
516//
517// string strText;
518//
519// auto type = ::platform::type(p).name();
520//
521// if (p->has(e_flag_factory))
522// {
523//
524// strText = binary_stream.factory_id_to_text(type);
525//
526// }
527// else
528// {
529//
530// strText = "factoryless://" + type;
531//
532// }
533//
534// binary_stream << strText;
535//
536// p->exchange(binary_stream);
537//
538// return binary_stream;
539//
540//}
541//
542//
552//
624//
625//template < typename ARRAY >
626//inline void __exchange_save_array(::binary_stream & binary_stream, ARRAY & array)
627//{
628//
629// auto c = array.get_count();
630//
631// binary_stream.exchange(e_property_count, c);
632//
633// //if (binary_stream.fail())
634// //{
635//
636// // return;
637//
638// //}
639//
640// for (::collection::index i = 0; i < c; i++)
641// {
642//
643// binary_stream.stream_exchange(i, __typed(array.element_at(i)));
644//
645// //if (binary_stream.fail())
646// //{
647//
648// // return;
649//
650// //}
651//
652// }
653//
654//}
655//
656//
657//template < typename ARRAY >
658//inline void __exchange_load_array(::binary_stream & binary_stream, ARRAY & array)
659//{
660//
661// auto c = array.get_count();
662//
663// binary_stream.exchange(e_property_count, c);
664//
665// //if (binary_stream.fail())
666// //{
667//
668// // return;
669//
670// //}
671//
672// array.set_size(c);
673//
674// for (::collection::index i = 0; i < c; i++)
675// {
676//
677// auto& t = __typed_defer_new(array.element_at(i));
678//
679// binary_stream.stream_exchange(i, t);
680//
681// //if (binary_stream.fail())
682// //{
683//
684// // array.set_size(i);
685//
686// // return;
687//
688// //}
689//
690// }
691//
692//}
693//
694//
695//template < typename TYPE, typename ARG_TYPE, typename ALLOCATOR, ::enum_type t_etypeContainer >
696//inline void __exchange(::binary_stream & binary_stream, ::base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > & array)
697//{
698// __exchange_array(binary_stream, array);
699//}
700//
701//
702//template < typename TYPE, typename ARG_TYPE, typename ALLOCATOR, ::enum_type t_etypeContainer >
703//inline void __exchange(::binary_stream & binary_stream, ::raw_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer > & array)
704//{
705// __exchange_array(binary_stream, array);
706//}
707//
708//
709//template < typename TYPE, ::enum_type t_etypeContainer >
710//inline void __exchange(::binary_stream & binary_stream, ::numeric_array < TYPE, t_etypeContainer > & array)
711//{
712// __exchange_array(binary_stream, array);
713//}
714//
715//
716//template < typename Type, typename RawType, ::enum_type t_etypeContainer >
717//inline void __exchange(::binary_stream & binary_stream, ::string_base_array < Type, RawType, t_etypeContainer > & array)
718//{
719// __exchange_array(binary_stream, array);
720//}
721//
722//
723//template < class ARRAY >
724//inline void __exchange_array(::binary_stream & binary_stream, ARRAY & array)
725//{
726//
727// if (binary_stream.is_storing())
728// {
729//
730// __exchange_save_array(binary_stream, array);
731//
732// }
733// else
734// {
735//
736// __exchange_load_array(binary_stream, array);
737// }
738//
739//}
740//
741//
742//inline payload_stream::payload_stream() : m_ppayload(aaa_memory_new ::payload) {}
743//inline payload_stream::payload_stream(::payload * pvar) : m_ppayload(pvar) {}
744//
745//inline ::payload & payload_stream::payload() { return *m_ppayload; }
746//inline const ::payload & payload_stream::payload() const { return *m_ppayload; }
747//
754//
765//
766//
767//inline void binary_stream::exchange(const ::atom & atom, void * pdata, memsize s)
768//{
769// if (is_storing())
770// {
771// ::memory mem(pdata, s);
772// write(mem);
773// }
774// else
775// {
776// ::memory mem;
777// read(mem);
778// mem.copy_to(pdata, s);
779// }
780//}
781//
782//inline void __exchange(::binary_stream & s, ::i8 & ch) { s.default_exchange(ch); }
783//
784//#ifdef WINDOWS
785//inline void __exchange(::binary_stream& s, unichar& wch) { s.default_exchange(wch); }
786//#endif
787//
788//
789//inline void __exchange(::binary_stream & s, bool & b) { s.default_exchange(b); }
790//
791//
792//
793//inline void __exchange(::binary_stream & s, ::i8 & i) { s.default_exchange(i); }
794//inline void __exchange(::binary_stream & s, ::i16 & i) { s.default_exchange(i); }
795//inline void __exchange(::binary_stream & s, ::i32 & i) { s.default_exchange(i); }
796//inline void __exchange(::binary_stream & s, ::i64 & i) { s.default_exchange(i); }
797//
798//#if defined(__APPLE__) || defined(__ANDROID__) || defined(RASPBERRYPIOS) || defined(WINDOWS)
799//inline void __exchange(::binary_stream & s, long & l) { s.default_exchange(l); }
800//#endif
801//
802//#if defined(__APPLE__) || defined(__ANDROID__) || defined(WINDOWS) || defined(RASPBERRYPIOS)
803//inline void __exchange(::binary_stream& s, ulong& ul) { s.default_exchange(ul); }
806//#endif
807//
808//
809//inline void __exchange(::binary_stream & s, ::u8 & u) { s.default_exchange(u); }
810//inline void __exchange(::binary_stream & s, ::u16 & u) { s.default_exchange(u); }
811//inline void __exchange(::binary_stream & s, ::u32 & u) { s.default_exchange(u); }
812//inline void __exchange(::binary_stream & s, ::u64 & u) { s.default_exchange(u); }
813//inline void __exchange(::binary_stream & s, ::f32 & f) { s.default_exchange(f); }
814//inline void __exchange(::binary_stream & s, ::f64 & d) { s.default_exchange(d); }
815//inline void __exchange(::binary_stream & s, ::earth::time & time) { s.default_exchange(time.m_i32); }
816//inline void __exchange(::binary_stream & s, class ::time & time) { s.default_exchange(time.m_iSecond); s.default_exchange(time.m_iNanosecond); }
817//inline void __exchange(::binary_stream & s, const ::scoped_string & scopedstr) { s.write_only(scopedstr); }
818//inline void __exchange(::binary_stream & s, string & str) { s.default_exchange(str); }
819//inline void __exchange(::binary_stream & s, ::file::path & path) { s.default_exchange(path); }
820//inline void __exchange(::binary_stream & s, ::atom & atom) { s.default_exchange(atom); }
821//inline void __exchange(::binary_stream & s, ::payload & payload) { s.default_exchange(payload); }
822//inline void __exchange(::binary_stream & s, ::property & property) { s.default_exchange(property); }
823//inline void __exchange(::binary_stream & s, ::property_set & set) { s.default_exchange(set); }
824//
825//
826//inline void __exchange(::binary_stream & s, ::block & block)
827//{
828//
829// s.default_exchange(block);
830//
831//}
832//
833//
834//inline void __exchange(::binary_stream & s, ::matter & matter)
835//{
836//
837// matter.exchange(s);
838//
839//}
840//
841//
842//template < typename TYPE >
843//inline payload_stream & operator >> (payload_stream & binary_stream, TYPE & t)
844//{
845//
846// binary_stream.defer_set_loading(); binary_stream.exchange(::atom::e_type_null, t);
847//
848// return binary_stream;
849//
850//}
851//
852//
853//template < typename TYPE >
854//inline payload_stream & operator << (payload_stream & binary_stream, const TYPE & t)
855//{
856//
857// binary_stream.defer_set_storing(); binary_stream.exchange(::atom::e_type_null, (TYPE &)t);
858//
859// return binary_stream;
860//
861//
862//}
863//
864//
865//template < typename TYPE >
866//inline text_stream & operator >> (text_stream & binary_stream, TYPE & t)
867//{
868//
869// binary_stream.defer_set_loading(); binary_stream.exchange(::atom::e_type_null, t);
870//
871// return binary_stream;
872//
873//}
874//
875//
876//template < typename TYPE >
877//inline text_stream & operator << (text_stream & binary_stream, const TYPE & t)
878//{
879//
880// binary_stream.defer_set_storing(); binary_stream.exchange(::atom::e_type_null, (TYPE &)t); return binary_stream;
881//
882//}
883//
884//
885//inline text_stream & operator << (text_stream & binary_stream, const file_pointer & pfile)
886//{
887//
888// binary_stream.defer_set_storing();
889//
890// binary_stream.m_p->from(pfile);
891//
892// return binary_stream;
893//
894//}
895//
896//
897//inline void __exchange(::binary_stream & s, ::i32_rectangle & rectangle)
898//{
899//
900// s.exchange("left", rectangle.left); s.exchange("top", rectangle.top); s.exchange("right", rectangle.right); s.exchange("bottom", rectangle.bottom);
901//
902//}
903//
904//inline void __exchange(::binary_stream & s, ::i64_rectangle & rectangle)
905//{
906//
907// s.exchange("left", rectangle.left); s.exchange("top", rectangle.top); s.exchange("right", rectangle.right); s.exchange("bottom", rectangle.bottom);
908//
909//}
910//
911//
912//
913//inline void __exchange(::binary_stream & s, ::f32_rectangle & rectangle)
914//{
915// s.exchange("left", rectangle.left); s.exchange("top", rectangle.top); s.exchange("right", rectangle.right); s.exchange("bottom", rectangle.bottom);
916//}
917//
918//
919//
920//inline void __exchange(::binary_stream & s, ::f64_rectangle & rectangle)
921//{
922// s.exchange("left", rectangle.left); s.exchange("top", rectangle.top); s.exchange("right", rectangle.right); s.exchange("bottom", rectangle.bottom);
923//}
924//
925//inline void __exchange(::binary_stream & s, ::i32_size & size)
926//{
927// s.exchange("cx", size.cx); s.exchange("cy", size.cy);
928//}
929//
930//
938//{
939//
940// s.exchange("cx", size.cx); s.exchange("cy", size.cy);
941//
942//}
943//
944//
945//
946//inline void __exchange(::binary_stream & s, ::f64_size & size)
947//{
948// s.exchange("cx", size.cx); s.exchange("cy", size.cy);
949//}
950//
951//inline void __exchange(::binary_stream & s, ::i32_point & point)
952//{
953// s.exchange("x", point.x); s.exchange("y", point.y);
954//}
955//
956//
957//
958//inline void __exchange(::binary_stream & s, ::i64_point & point)
959//{
960// s.exchange("x", point.x); s.exchange("y", point.y);
961//}
962//
963//
964//
965//inline void __exchange(::binary_stream & s, ::f32_point & point)
966//{
967// s.exchange("x", point.x); s.exchange("y", point.y);
968//}
969//
970//
971//
972//inline void __exchange(::binary_stream & s, ::f64_point & point)
973//{
974// s.exchange("x", point.x); s.exchange("y", point.y);
975//}
976//
977//template < typename TYPE >
978//inline binary_stream & operator >> (binary_stream & binary_stream, TYPE & t);
979//
980//template < typename TYPE >
981//inline binary_stream & operator << (binary_stream & binary_stream, const TYPE & t);
982//
983//template < typename TYPE >
984//inline binary_stream & operator >> (binary_stream & binary_stream, TYPE & t)
985//{
986//
987// binary_stream.defer_set_loading();
988//
989// binary_stream.stream_exchange(::atom::e_type_null, t);
990//
991// return binary_stream;
992//
993//}
994//
995//
996//template < typename TYPE >
997//inline binary_stream & operator << (binary_stream & binary_stream, const TYPE & t)
998//{
999//
1000// binary_stream.defer_set_storing();
1001//
1002// binary_stream.stream_exchange(::atom::e_type_null, (TYPE &)t);
1003//
1004// return binary_stream;
1005//
1006//}
1007//
1008//template < typename TYPE >
1009//inline ::file::file & operator >> (::file::file & file, TYPE & t)
1010//{
1011//
1012// if (::is_null(file))
1013// {
1014//
1015// throw ::exception(error_io);
1016//
1017// }
1018//
1019// binary_stream binary_stream(&file);
1020//
1021// binary_stream >> t;
1022//
1023// return file;
1024//
1025//}
1026//
1027//
1028//template < typename TYPE >
1029//inline ::file::file & operator << (::file::file & file, const TYPE & t)
1030//{
1031//
1032// binary_stream binary_stream(&file);
1033//
1034// binary_stream << t;
1035//
1036// return file;
1037//
1038//}
1039//
1040//inline void assign(::memory & memory, const ::payload & payload)
1041//{
1042//
1043// memory = (const ::memory &) payload;
1044//
1045//}
1046//
1047//
1048//template < typename TYPE >
1049//void payload_stream::default_exchange(TYPE & t)
1050//{
1051//
1052// try
1053// {
1054//
1055// if(is_loading())
1056// {
1057//
1058// ::assign(t, *this->m_ppayload);
1059//
1060// }
1061// else
1062// {
1063//
1064// ::assign(*this->m_ppayload, t);
1065//
1066// }
1067//
1068// }
1069// catch(const ::exception & e)
1070// {
1071//
1072// add_exception(e);
1073//
1074// }
1075// catch (...)
1076// {
1077//
1078// on_catch_all_exception();
1079//
1080// }
1081//
1082//}
1083//
1084//
1085//template < typename TYPE >
1086//void payload_stream::write_only(TYPE & t)
1087//{
1088//
1089// if (is_loading())
1090// {
1091//
1092// throw ::exception(error_io);
1093//
1094// }
1095// else
1096// {
1097//
1098// m_ppayload->operator =(t);
1099//
1100// }
1101//
1102//}
1103//template < typename TYPE >
1104//inline void payload_stream::var_exchange(const ::atom & atom, TYPE & t)
1105//{
1106//
1107// ::payload * pvar = m_ppayload;
1108//
1109// if (atom.m_etype != atom::e_type_null)
1110// {
1111//
1112// m_ppayload = &m_ppayload->operator[](atom);
1113//
1114// }
1115//
1116// __exchange(*this, t);
1117//
1118// m_ppayload = pvar;
1119//
1120//}
1121//
1122//
1123//#include "_payload_stream_impl.h"
1124//
1125//
1126//