Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
StructFieldMetaInfo.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_StructFieldMetaInfo_h_
5#define _Stroika_Foundation_DataExchange_StructFieldMetaInfo_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <compare>
10#include <type_traits>
11#include <typeindex>
12
15
16/**
17 *
18 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
19 *
20 */
21
23
24 /**
25 * \note This class is just a utility to capture information about fields relative to
26 * a class for the purpose of serialization.
27 */
29 public:
30 /**
31 * Grab the meta info associated with a pointer to member - its type info, and its pointer to member address.
32 *
33 * \note - unlike earlier versions of Stroika which used std::offsetof() (or similar) - and therefore only
34 * worked (guaranteed) on std-layout objects, this should always work portably.
35 */
36 template <typename FIELD_VALUE_TYPE, typename OWNING_OBJECT>
37 StructFieldMetaInfo (FIELD_VALUE_TYPE OWNING_OBJECT::* member);
38
39 public:
40 /**
41 * returns typeid (constructed FIELD_VALUE_TYPE)
42 */
43 nonvirtual type_index GetTypeInfo () const;
44
45 public:
46 /**
47 * Given an object of the same type as the StructFieldMetaInfo was constructed with (or a subclass), return a pointer
48 * to the field value corresponding to the field this StructFieldMetaInfo was constructed with. Note this is not checked
49 * since no way to check subclass-of from type_index.
50 *
51 * Respect const of the OWNING_OBJECT, propagating that to this functions result.
52 *
53 * If the FIELD_VALUE_TYPE is not known by the caller the actual address will be statically cast to byte* (or const of that).
54 *
55 * \note - doing THAT PROBABLY INVOKES C++ UNDEFINED BEHAVIOR - so just moves the 'hole' / 'issue' we had before Stroika v3.0
56 * to this 'cast' (https://stackoverflow.com/questions/12141446/offset-from-member-pointer-without-temporary-instance).
57 * Still hunting for a good way around that. But where this is used in ObjectVariantMapper, we don't really
58 * know those types. --LGP 2023-09=25
59 */
60 template <typename FIELD_VALUE_TYPE, typename OWNING_OBJECT>
61 nonvirtual const FIELD_VALUE_TYPE* GetAddressOfMember (const OWNING_OBJECT* object) const;
62 template <typename FIELD_VALUE_TYPE, typename OWNING_OBJECT>
63 nonvirtual FIELD_VALUE_TYPE* GetAddressOfMember (OWNING_OBJECT* object) const;
64 template <typename OWNING_OBJECT>
65 nonvirtual const byte* GetAddressOfMember (const OWNING_OBJECT* object) const;
66 template <typename OWNING_OBJECT>
67 nonvirtual byte* GetAddressOfMember (OWNING_OBJECT* object) const;
68
69 public:
70 /**
71 */
72 nonvirtual strong_ordering operator<=> (const StructFieldMetaInfo& rhs) const;
73
74 public:
75 /**
76 */
77 nonvirtual bool operator== (const StructFieldMetaInfo& rhs) const;
78
79 public:
80 /**
81 * @see Characters::ToString ()
82 */
83 nonvirtual Characters::String ToString () const;
84
85 private:
86 type_index fTypeInfo_; // type of FIELD_VALUE_TYPE
87 Memory::InlineBuffer<byte, 2 * sizeof (void*)> fPTR2MEM_; // type-erased FIELD_VALUE_TYPE OWNING_OBJECT::*fMember;
88
89 private:
90 template <typename FIELD_VALUE_TYPE, typename OWNING_OBJECT>
91 inline FIELD_VALUE_TYPE OWNING_OBJECT::* const GetP2M_ () const;
92 };
93
94}
95
96/*
97 ********************************************************************************
98 ***************************** Implementation Details ***************************
99 ********************************************************************************
100 */
101#include "StructFieldMetaInfo.inl"
102
103#endif /*_Stroika_Foundation_DataExchange_StructFieldMetaInfo_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
nonvirtual const FIELD_VALUE_TYPE * GetAddressOfMember(const OWNING_OBJECT *object) const