acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
type.h
1#pragma once
2
3
4//#include "atom.h"
5
6
7#include "acme/template/safe_bool.h"
8
9#include <typeindex>
10
11#include "atom.h"
12
13
14constexpr ::std::strong_ordering order(bool b1, bool b2)
15{
16
17 if (!!b1)
18 {
19
20 if (!!b2)
21 {
22
23 return ::std::strong_ordering::equal;
24
25 }
26 else
27 {
28
29 return ::std::strong_ordering::greater;
30
31 }
32
33 }
34 else if (!!b2)
35 {
36
37 return ::std::strong_ordering::less;
38
39 }
40
41 return ::std::strong_ordering::equal;
42
43}
44
45class type_id
46{
47public:
48
49
51 ::std::type_index m_typeindex;
55 ::string m_strTypeName;
56
57
58 inline type_id();
59 inline type_id(const ::type_id &type_id);
60 inline type_id(const ::std::type_info &info);
61
62
63 inline bool is_set() const;
64 inline bool is_empty() const {return !this->is_set();}
65
66 inline bool operator == (const ::type_id & type_id) const;
67 inline ::std::strong_ordering operator <=> (const ::type_id & type_id) const;
68
69 ::string as_string() const;
70
71};
72
73
74template < typename TYPE >
75constexpr TYPE minus_one_or_greater(const TYPE & t)
76{
77 return t <= -1 ? -1 : t;
78}
79
80class type_iptr_pair :
81 public ::pair<::iptr, ::iptr>
82{
83public:
84
85
86 type_iptr_pair(::iptr i1 = -1, ::iptr i2 = -1):
88 {
89
90
91 }
92
93 template < typename ENUM>
94 requires(::std::is_enum_v<ENUM>)
95 type_iptr_pair(::atom::enum_type etype, const ENUM & eenum) :
96 type_iptr_pair((::iptr) etype,(::iptr) eenum)
97 {
98
99
100 }
101
102 type_iptr_pair(enum_task_tool etasktool) :
103 type_iptr_pair(::atom::e_type_task_tool, etasktool)
104 {
105
106
107 }
108
109
110 constexpr bool is_empty() const { return this->m_element1 < 0; }
111 constexpr bool is_set() const { return !this->is_empty(); }
112
113 constexpr iptr normal1() const { return (::iptr)::minus_one_or_greater(this->m_element1); }
114 constexpr iptr normal2() const { return (::iptr)::minus_one_or_greater(this->m_element2); }
115
116
117 constexpr inline bool operator == (const ::type_iptr_pair & ipair) const
118 {
119
120 return this->normal1() == ipair.normal1() && this->normal2() == ipair.normal2();
121
122 }
123
124
125 constexpr ::std::strong_ordering operator <=> (const ::type_iptr_pair & ipair) const
126 {
127
128 auto order = this->normal1() <=> ipair.normal1();
129
130 if (order != 0)
131 {
132
133 return order;
134
135 }
136
137 order = this->normal2() <=> ipair.normal2();
138
139 return order;
140
141 }
142
143
144 ::string as_string() const;
145
146
147};
148template<>
149inline ::hash32 as_hash32<type_iptr_pair>(const type_iptr_pair &pair)
150{
151 return (::hash32)abs(pair.normal1()) +
152 (::hash32)abs(pair.normal2());
153}
154
155class type_custom_id
156{
157public:
158
159 //::string m_strText;
163 ::string m_strNameId;
166
167 type_custom_id();
168 type_custom_id(const_char_pointer pszNameId);
169 type_custom_id(const ::string_literal & strliteralNameId);
170 type_custom_id(const ::scoped_string & scopedstrNameId);
171 type_custom_id(const ::type_iptr_pair & ipairId);
172 type_custom_id(const ::scoped_string & scopedstrNameId, const ::type_iptr_pair & ipairId);
173 type_custom_id(const ::atom & atom);
174 type_custom_id(enum_task_tool etasktool);
175
176
177 constexpr bool is_set() const;
178 constexpr bool is_empty() const{return !this->is_set();}
179
180
181 inline bool operator == (const ::type_custom_id & typecustomid) const;
182 inline ::std::strong_ordering operator <=> (const ::type_custom_id & typecustomid) const;
183
184 ::string as_string() const;
185
186};
187CLASS_DECL_ACME string type_name(const ::std::type_info& typeinfo);
188
189template<typename TYPE>
190inline ::std::type_index type_index() { return typeid(TYPE); }
191
192
193template<typename TYPE>
194inline ::string type_name()
195{
196 return type_name(typeid(TYPE));
197}
198
199inline ::std::type_index void_type_index()
200{
201
202 return typeid(void);
203
204}
205
206
207inline bool is_type_index_empty(const ::std::type_index & typeindex)
208{
209
210 return typeindex == ::void_type_index();
211
212}
213
214
215inline bool is_type_index_set(const ::std::type_index & typeindex)
216{
217
218 return !is_type_index_empty(typeindex);
219
220}
221
222
223inline ::std::type_index type_index(const ::std::type_info &typeinfo) { return typeinfo; }
224
225
226#ifdef WINDOWS
227
228
229#define __c_type_name(t) (c_demangle(::type<t>().name()))
230
231
232inline const_char_pointer c_demangle(const_char_pointer psz)
233{
234
235 if (psz[0] == 'c' &&
236 psz[1] == 'l' &&
237 psz[2] == 'a' &&
238 psz[3] == 's' &&
239 psz[4] == 's' &&
240 psz[5] == ' ')
241 {
242
243 return psz + 6;
244
245 }
246 else if (psz[0] == 's' &&
247 psz[1] == 't' &&
248 psz[2] == 'r' &&
249 psz[3] == 'u' &&
250 psz[4] == 'c' &&
251 psz[5] == 't' &&
252 psz[6] == ' ')
253 {
254
255 return psz + 7;
256
257 }
258 else
259 {
260
261 return psz;
262
263 }
264
265}
266#else
267//inline const_char_pointer c_demangle(const ::scoped_string & scopedstr)
268//{
269//
270// return scopedstr;
271//
272//}
273
274
275#endif
276
277
278//#define __object_type(t) ::platform::type(data_structure_t{}, t)
279//
280//
281//struct data_structure_t {};
282
283
284//class raw_literal;
285//
286//
287//template < typename OBJECT_NOT_TYPE_ATOM >
288//concept prototype_object_not_type_atom =
289// prototype_object < OBJECT_NOT_TYPE_ATOM >
290// && !std::is_same_v < OBJECT_NOT_TYPE_ATOM, raw_literal >
291// && !std::is_base_of_v < raw_literal, OBJECT_NOT_TYPE_ATOM >;
292//
293//
294//class CLASS_DECL_ACME raw_literal
295//{
296//public:
297//
298//
299// const_char_pointer m_pszRawName = nullptr;
300// //::string m_strDemangled;
301//
302//
303// //type()
304// //{
305// //
306// //}
307//
308//
309// //using atom::atom;
310//
311//
323//
324//
325// //raw_literal(const ::scoped_string & scopedstrTypeName) :
326// // atom(scopedstrTypeName)
327// //{
328// //
329// //}
330//
331//
332// raw_literal(const ::raw_literal & type)
333// {
334//
335// operator = (type);
336//
337// }
338//
339//
340// raw_literal(::raw_literal && type):
341// m_pszRawName(type.m_pszRawName),
342// m_strDemangled(::transfer(type.m_strDemangled))
343// {
344//
345// }
346//
347//
348// raw_literal(const ::std::type_info & typeinfo);
349//
350// raw_literal(const ::quantum * p);
351//
352// template < prototype_object_not_type_atom OBJECT_NOT_TYPE_ATOM >
353// raw_literal(OBJECT_NOT_TYPE_ATOM & objectnottypeatom);
354//
355// template < typename BASE >
356// raw_literal(const ::pointer<BASE>& p);
357//
358//
359// //type& operator = (const ::std::type_info& typeinfo);
360//
361//
362// //type& operator = (const ::platform::type & type);
363//
364//
365// raw_literal& operator = (const ::raw_literal& datatype)
366// {
367//
368// m_pszRawName = datatype.m_pszRawName;
369// m_strDemangled = datatype.m_strDemangled;
370//
371// return *this;
372//
373// }
374//
375//
376// const_char_pointer raw_name() const { return this->m_pszRawName; }
377// const ::string& id() const { return this->m_strDemangled; }
378//
379//
380// bool operator == (const ::std::type_info& typeinfo) const;
381//
382//
383// bool operator == (const ::raw_literal& type) const;
387//
388//
389// bool operator == (const ::atom& atom) const;
390//
391//
396//
397//
398// bool operator == (const ::quantum * p) const;
399//
400//
401// template < typename TYPE >
402// bool operator == (const ::pointer < TYPE > & p) const;
403//
404//
405// //bool operator != (const ::quantum* pparticle) const;
406//
407//
408// inline operator bool() const { return m_pszRawName || m_strDemangled.has_character(); }
409//
410// //inline operator const_char_pointer () const { return ::atom::operator const_char_pointer (); }
411//
412// //bool name_contains(const_char_pointer psz) const;
413//
414//
415//};
416//
417//
418//template < typename TYPE >
419//class typed_type_atom :
420// public ::raw_literal
421//{
422//public:
423//
424//
425// typed_type_atom() :
426// raw_literal(::type<TYPE>())
427// {
428// }
429//
430//};
431//
432//
433//template < typename TYPE >
434//inline ::typed_type_atom < TYPE > type()
435//{
436//
437// return {};
438//
439//}
440//
441//
442//inline ::raw_literal type(const ::quantum * p)
443//{
444//
445// return p;
446//
447//}
448//
449//
450//template < prototype_object OBJECT >
451//inline ::raw_literal type(OBJECT & object)
452//{
453//
454// return object;
455//
456//}
457//
458//
460//
462//
463//
464
465
466
467
468class pointer_key
469{
470public:
471
472 ::uptr m_uptr;
473
474 constexpr pointer_key() { m_uptr = 0; }
475 constexpr pointer_key(const pointer_key& pointer) :m_uptr(pointer.m_uptr) {}
476 template < typename TYPE >
477 constexpr pointer_key(const TYPE* p) : m_uptr((::uptr)(void*)p) {}
478
479
480 constexpr bool operator ==(const pointer_key& pointer) const
481 {
482
483 return this->m_uptr == pointer.m_uptr;
484
485 }
486
487
488 constexpr ::std::strong_ordering operator <=>(const pointer_key& pointer) const
489 {
490
491 return this->m_uptr <=> pointer.m_uptr;
492
493 }
494
495
496};
497
498
499
500template < >
501inline ::hash32 as_hash32 < pointer_key >(const pointer_key& key)
502{
503
504 return ::as_hash32(key.m_uptr);
505
506}
507
508
509inline ::string type_raw_name(const ::std::type_info & typeinfo)
510{
511
512#ifdef WINDOWS
513
514 return (::string_literal) typeinfo.raw_name();
515
516#else
517
518 return (::string_literal) typeinfo.name();
519
520#endif
521
522}
523
524
525template < typename TYPE >
526inline ::string type_raw_name()
527{
528
529 return type_raw_name(typeid(TYPE));
530
531}
532
533
534template < typename TYPE >
535inline ::string type_raw_name(const TYPE* p)
536{
537
538 return type_raw_name(typeid(*(TYPE*)p));
539
540}
541
542
543template < typename TYPE >
544inline ::string type_raw_name(const TYPE& t)
545{
546
547 return type_raw_name(typeid(t));
548
549}
550
551
552template < typename BASE >
553inline ::string type_raw_name(const ::pointer<BASE>& p)
554{
555
556 return type_name(typeid(*p.m_p));
557
558}
559
560
561//
562//
563//inline ::string type_name(const ::std::type_info& typeinfo)
564//{
565//
566// //#ifdef WINDOWS
567//
568// return demangle_name(typeinfo.name());
569//
570// //#else
571//
572//
573// //#endif
574//
575//
576//}
577
578
579namespace platform
580{
581
582
583 class CLASS_DECL_ACME type
584 {
585 public:
586
587
588 ::type_id m_typeid;
589 ::type_custom_id m_customid;
590
591
592 //type();
593 //explicit type(const ::std::type_info &info);
594 //type(const ::scoped_string &scopedstrTypeName);
595 //template < typename TYPE >
596 //type(const TYPE* p) : type(typeid(*(TYPE*)p)) {}
597 //template < typename TYPE >
598 //type(const TYPE& t) : type(typeid(t)) {}
599 //template < typename BASE >
600 //type(const ::pointer<BASE>& p) : type(p.m_p) {}
601
602
603 type();
604 type(const ::platform::type &type);
605 type(const ::std::type_info &info);
606 type(const ::scoped_string &scopedstrTypeName);
607 type(const ::type_iptr_pair &ipair);
608 type(const ::atom &atom);
609
610
611 template<typename TYPE>
612 type(const TYPE *p);
613 template<typename TYPE>
614 type(const TYPE &t)
615 requires (!is_raw_pointer <TYPE>);
616 template<typename BASE>
617 type(const ::pointer<BASE> &p);
618
619
620 const ::string &raw_name() const;
621 const ::string &name() const;
622 const_char_pointer c_str() const;
623 const ::string & text() const;
624 bool is_set() const;
625 bool is_empty() const;
626 explicit operator bool() const;
627
628 bool operator==(const ::platform::type &type) const;
629
630 ::std::strong_ordering operator<=>(const ::platform::type &type) const;
631
632 ::string as_string() const;
633
634
635 };
636
637
638} // namespace platform
639
640
641template<typename TYPE>
642inline ::platform::type type();
643inline ::platform::type type(const ::std::type_info &info);
644inline ::platform::type type(const ::scoped_string &scopedstrTypeName);
645
646
647template<typename TYPE>
648inline ::platform::type type(const TYPE *p);
649
650template<typename TYPE>
651inline ::platform::type type(const TYPE &t);
652
653template<typename BASE>
654inline ::platform::type type(const ::pointer<BASE> &p);
655
656
657
658
659
660
661//template < >
662//inline ::hash32 as_hash32 < type >(const ::platform::type & type)
663//{
664//
665// return ::as_hash32(name.m_strTypeName);
666//
667//}
668//
669//
670
671
672//template < typename TYPE >
673//inline ::type as_type()
674//{
675//
676// return typeid(TYPE);
677//
678//}
679
Definition atom.h:237
Definition _template_forward_declaration.h:327
Definition type.h:469
Definition type.h:156
::string m_strNameId
Definition type.h:163
::type_iptr_pair m_ipairId
m_ipair isn't empty it can be used as a key
Definition type.h:165
Definition type.h:46
::string m_strTypeName
type name as obtained from demangle(typeid().name())
Definition type.h:55
::std::type_index m_typeindex
type index as obtained from std::type_index(typeid())
Definition type.h:51
::string m_strRawTypeName
raw type name as obtained from typeid().raw_name()
Definition type.h:53
Definition type.h:82
include "thread/AutoLock.h"
Definition _forward_declaration.h:877
Definition hash32.h:14