rtti

typeid(“”) != typeid(const char*)

狂风中的少年 提交于 2021-01-26 19:25:42
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

typeid(“”) != typeid(const char*)

笑着哭i 提交于 2021-01-26 19:25:18
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

Is it possible to get the value of a GUID on an interface using RTTI?

亡梦爱人 提交于 2020-12-25 00:38:00
问题 If I have an interface such as: IPluginAPI = interface ['{590DFF0B-CA00-46CC-84B0-3848103D4C5A}'] function add (a : double; b : double) : double; function sub (a : double; b : double) : double; function mult (a : double; b : double) : double; function divide (a : double; b : double) : double; end; Is there anyway to get the value of the GUID using RTTI? I am using Delphi XE. 回答1: uses TypInfo; Guid := GetTypeData(TypeInfo(IPluginAPI))^.Guid; 来源: https://stackoverflow.com/questions/8439246/is

Is it possible to get the value of a GUID on an interface using RTTI?

三世轮回 提交于 2020-12-25 00:34:22
问题 If I have an interface such as: IPluginAPI = interface ['{590DFF0B-CA00-46CC-84B0-3848103D4C5A}'] function add (a : double; b : double) : double; function sub (a : double; b : double) : double; function mult (a : double; b : double) : double; function divide (a : double; b : double) : double; end; Is there anyway to get the value of the GUID using RTTI? I am using Delphi XE. 回答1: uses TypInfo; Guid := GetTypeData(TypeInfo(IPluginAPI))^.Guid; 来源: https://stackoverflow.com/questions/8439246/is

Setting a value in a Nullable<T> record with RTTI

旧时模样 提交于 2020-07-09 17:13:24
问题 I'm working with Serialization/Deserialization using NEON library from Paolo Rossi. i'm trying to populate this class using RTTI, with data that i get from a database. The properties on the class have the same name of the fields in the database. In the library, i have this Nullable Record : unit Neon.Core.Nullables; interface uses System.SysUtils, System.Variants, System.Classes, System.Generics.Defaults, System.Rtti, System.TypInfo, System.JSON; type ENullableException = class(Exception); {

Get object's type from pointer to base class at runtime

ぃ、小莉子 提交于 2020-06-25 17:12:28
问题 I'm working with a class library where all classes are, directly or indirectly, derived from a base class Base and have a name. The library provides a facility to search for objects by a name, which will return a Base* . Is there any way to find the type of the returned object without checking all possibilities using dynamic_cast s as I did in the following example? I'd like to avoid that, if at all possible, since the derived classes have template parameters, which makes for quite a few

Get object's type from pointer to base class at runtime

时光怂恿深爱的人放手 提交于 2020-06-25 17:11:11
问题 I'm working with a class library where all classes are, directly or indirectly, derived from a base class Base and have a name. The library provides a facility to search for objects by a name, which will return a Base* . Is there any way to find the type of the returned object without checking all possibilities using dynamic_cast s as I did in the following example? I'd like to avoid that, if at all possible, since the derived classes have template parameters, which makes for quite a few

MFC之RTTI分析(基于侯俊杰的《深入浅出MFC》)

有些话、适合烂在心里 提交于 2020-04-07 04:57:52
MFC框架早在标准C++之间提出并实现了类的运行时识别(RTTI)功能,下面记录下基于我对其的理解。 要实现RTTI必须在定义的时候记录下来类的基本信息。MFC构建了一个CRuntimeClass的结构体用以保存类的基本信息。CRun提么Class的定义如下: struct CRuntimeClass { LPCSTR m_pszClassName; //类名称 int m_nObjectSize; //类的大小 UINT m_wSchema; CObject (PASCAL * m_pfnCreateObject)(); CRuntimeClass *m_pBaseClass; //类的基类(父类) static CRuntimeClass *pFirstClass;//保存类信息的链表头指针 CRuntimeClass *m_pNextClass;//链表的下一个 }; 在定义好这样一个结构体后,在每个类中添加一个这样的成员(静态的)即可。这样的每个实例都可以通过该属性访问到类的相关信息。这样的定义是属于类的所有对象共有的,在定义类的时候就已经定义好了,所以只需要将该属性定义为静态的即可。通过这种做法每个类都保存的类的所有相关信息,但是如果要查找类的相关信息是不够的,所以通过链表的方式将这些类的CRuntimeClass静态属性组织起来,这样可以遍历程序中的所有类

Delphi: RTTI and TObjectList<TObject>

此生再无相见时 提交于 2020-02-02 04:07:56
问题 Based on one answer to an earlier post, I'm investigating the possibility of the following design TChildClass = class(TObject) private FField1: string; FField2: string; end; TMyClass = class(TObject) private FField1: TChildClass; FField2: TObjectList<TChildClass>; end; Now, in the real world, TMyClass will have 10 different lists like this, so I would like to be able to address these lists using RTTI. However, I'm not interested in the other fields of this class, so I need to check if a