rtti

Delphi Rtti: how to get objects from TObjectList<T>

谁都会走 提交于 2019-12-05 04:34:55
问题 I am working a custom class to xml converter and one of the requirements is the ability to stream TObjectList<T> fields. I am trying to invoke the ToArray() method to get hold of the TObjectlist's objects, but I get 'Invalid class typecast' because the types obviously don't match. take this class for example: type TSite = class Name : String; Address : String; end; TSites = class Sites : TObjecList<TSite>; end; I just need to get the Site Objects from the Sites TObjectList. Please keep in

Does C++11 provide hashing functions for std::type_info?

一曲冷凌霜 提交于 2019-12-05 04:11:34
I'm still working on a good solution to my One-Of-A-Type Container Problem -- and upon reflection I think it would be nice to be able to just use something like a std::map<std::type_info, boost::any> . Unfortunately, std::type_info does not define an operator< , and I think it'd be unreasonable for it to define one. However, it does seem reasonable to define a hash function for it, because you could simply use the singleton address of the std::type_info object as a reasonable "hash". Therefore, you'd be able to put a std::type_info into a std::unordered_map as the key. Does C++11 provide such

Howto set event handlers with arbitrary type with RTTI in Delphi 2010?

℡╲_俬逩灬. 提交于 2019-12-05 04:02:21
问题 after reading the post How to set event handlers via new RTTI?, I wonder if it is possible to solve this more dynamically. For example I want to set ALL event handlers of any component to nil. Using TValue.From <TNotifyEvent> (SomeMethod) does not work for two reasons: 1. The type is unknown (could be TNotifyEvent, TMouseEvent etc.) 2. I cannot set 'SomeMethod' to nil (invalid cast) In old RTTI style I would do something like: var NilMethod: TMethod; begin [...] NilMethod.Data := nil;

Can RTTI interrogate types from project code at designtime?

不羁的心 提交于 2019-12-05 02:53:33
I would like to use RTTI to examine the types contained within project source files at designtime rather than runtime. To the best of my knowledge this is unsupported but the discussion in the comments of this question indicate that it is possible and has been for several Delphi versions. This is the first time I have heard of this functionality being available though and as yet I have been unable to reproduce it for myself. Here is my test example. It uses a simple TListBox descendant TMyListBox which has a string property TypeToExplore which when set fills the list box with the properties of

Enable Delphi XE RTTI only for some classes

无人久伴 提交于 2019-12-05 02:33:39
I'm trying to have RTTI enabled only for a subset of my classes. The reason is that for those classes for which I want RTTI, I want RTTI on public methods too, but if that is enabled project-wide, then all public methods from all classes get into the final executable. This basically turns off the smart-linking, as the compiler considers that every public method could be called at runtime, and thus ends up compiling pretty much everything and the kitchen sink into the executable... I've tried several things: Turning off RTTI at the project level with {$RTTI EXPLICIT METHODS([]) PROPERTIES([])

Is an object allowed to legally change its type during its lifetime in C++?

孤者浪人 提交于 2019-12-05 02:14:19
I have this code: class Class { public: virtual void first() {}; virtual void second() {}; }; Class* object = new Class(); object->first(); object->second(); delete object; that I compile with Visual C++ 10 with /O2 and have this disassembly: 282: Class* object = new Class(); 00403953 push 4 00403955 call dword ptr [__imp_operator new (4050BCh)] 0040395B add esp,4 0040395E test eax,eax 00403960 je wmain+1Ch (40396Ch) 00403962 mov dword ptr [eax],offset Class::`vftable' (4056A4h) 00403968 mov esi,eax 0040396A jmp wmain+1Eh (40396Eh) 0040396C xor esi,esi 283: object->first(); 0040396E mov eax

std::type_info::hash_code() uniqueness and the meaning of “should”

怎甘沉沦 提交于 2019-12-05 01:20:25
Is it meant to be guaranteed that same std::type_info::hash_code() values imply same types? Cplusplus.com seems to claim so: This function returns the same value for any two type_info objects that compare equal, and different values for distinct types that do not. [Emphasis mine] Cppreference seems to claim otherwise: Returns an unspecified value, which is identical for objects, referring to the same type. No other guarantees are given , in particular, the value can change between invocations of the same program. [Emphasis mine] The relevant standards paragraphs are: § p18.7.1 p7-8 size_t hash

Difference between RTTI and reflection in Java

做~自己de王妃 提交于 2019-12-04 23:00:19
问题 My question is when how does the class info gets loaded during runtime? When someone calls instanceof is that considered RTTI or reflection? Or it depends on the actual situation? 回答1: The term "RTTI" is a C++-specific term referring to the functionality of the core language that allows the program to determine the dynamic types of various objects at runtime. It usually refers to the dynamic_cast or typeid operators, along with the associated std::type_info object produced by typeid . The

Custom RTTI for use in script-defined types

旧街凉风 提交于 2019-12-04 19:36:33
I'm developing a game engine in C++ that allows Python scripting. Here's an example of how functions can be defined in Python that are then called by the an event manager whenever a certain event occurs: # Import some classes defined in C++ from cpp.event import PlayerDiesEvent, EventManager def onPlayerDeath(event): pass em = EventManager() em.connect(PlayerDiesEvent, onPlayerDeath) em.post(PlayerDiesEvent(...)) # Will call `onPlayerDeath` The user can also define new types of events: from cpp.event import Event, EventManager class CustomEvent(Event): pass def onCustomEvent(event): pass em =

C++ object lifetime profiling

▼魔方 西西 提交于 2019-12-04 16:57:39
ObjectInfo class is a diagnostic class intended to track statistical data such as life time and number of objects. A specific class inherits from ObjectInfo as shown. A member of that specific class is then declared in the body of a profiled class. Although the solution works it is hard to maintain as it requires the profiling class to be keep in sync with the profiled class as the class name is used to identify the later. It would also be hard to extend the profiling class to gather different information such as the size of object. Propose a better solution where the dependencies between the