rtti

Delphi 2010 RTTI : Use TValue to store data

戏子无情 提交于 2019-12-07 18:11:44
问题 I would like to be able to use TValue to store Data in a TList<>. Like in : type TXmlBuilder = class type TXmlAttribute = class Name: String; Value: TValue; // TValue comes from Rtti end; TXmlNode = class Name: String; Parent: TXmlNode; Value: TXmlNode; Attributes: TList<TXmlAttribute>; Nodes: TList<TXmlNode>; function AsString(Indent: Integer): String; end; ... public ... function N(const Name: String): TXmlBuilder; function V(const Value: String): TXmlBuilder; function A(const Name: String;

isMemberOfClass vs comparing classes with ==

十年热恋 提交于 2019-12-07 17:49:06
问题 Is there any real difference between: id value; BOOL compare1 = [value isMemberOfClass:[SomeClass class]]; BOOL compare2 = [value class] == [SomeClass class]; to check if value is a SomeClass object? 回答1: If value is an NSProxy , isMemberOfClass: will properly check the proxied object, the other construct, I believe, won't (I think it will clumsily duplicate isProxy: ). 来源: https://stackoverflow.com/questions/3126476/ismemberofclass-vs-comparing-classes-with

Find all Class Helpers in Delphi at runtime using RTTI?

五迷三道 提交于 2019-12-07 05:42:18
问题 Does the extended RTTI in Delphi 2010 offer a way to list defined Class and Record Helpers at run time? As far as I know Delphi does not show a hint or warning when more than one class helper is defined for a class, class helper detection might be a helpful routine in 'quality assurance'. p.s. of course I know I should never ever use third party components or libraries without source code, which would make it easy to grep class helpers. 回答1: Since class helpers only apply to a class based on

C++: is a class with virtual base but without virtual functions polymorphic and has VTable?

三世轮回 提交于 2019-12-07 03:13:09
问题 Consider the following code: #include <iostream> #include <typeinfo> #include <type_traits> using namespace std; struct A { int data; }; struct B1 : A {}; struct B2 : virtual A {}; struct Base1 : virtual A {}; struct Base2 : virtual A {}; struct Derived : Base1, Base2 {}; int main() { cout << sizeof(B1) << endl; cout << sizeof(B2) << endl; cout << sizeof(Derived) << endl; cout << std::is_polymorphic<B1>::value << endl; cout << std::is_polymorphic<B2>::value << endl; cout << std::is

Is type_info not a part of RTTI?

左心房为你撑大大i 提交于 2019-12-07 01:05:52
问题 I had asked a question Do C++ POD types have RTTI? and someone told me in the comments: POD types do have type_info, but don't have RTTI, and that's possible because type_info isn't always RTTI. and it seems right as i could get the type_info of a POD ( non-polymorphic ) type. But while I compile this simple program: #include <iostream> struct X { int a; }; int main() { using namespace std; std::cout << typeid(X) << std::endl; return 0; } with flag -fno-rtti of GCC: $ g++ -fno-rtti main.cpp &

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

孤者浪人 提交于 2019-12-06 23:47:39
问题 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".

How can I detect if a Delphi class has a virtual constructor?

情到浓时终转凉″ 提交于 2019-12-06 14:10:38
For example, is there a way to find out that this class has a virtual constructor (at runtime)? TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; For example, in this code I would like to test if the class referenced by Clazz has a virtual constructor: procedure Test; var Clazz: TClass; Instance: TObject; begin Clazz := TMyClass; Instance := Clazz.Create; end; Is there a simple solution, for example using RTTI, which works in Delphi 6 to 2009? Mason Wheeler Looking through the TypInfo unit, it doesn't look like there's any way to tell if a method is virtual using

Custom RTTI for use in script-defined types

笑着哭i 提交于 2019-12-06 14:04:00
问题 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

Boost Serialization of simple class with RTTI turned Off (-fno-rtti)

半世苍凉 提交于 2019-12-06 12:26:49
I am trying to serialize a simple class with Plain-old-Data types using boost serialization. However, my only requirement is that I cannot use RTTI. Thus I am compiling with -fno-rtti using gcc 4.4.1 for ARM Linux with latest Boost 1.47 library. So here is my class: #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> class libNemoMemento { friend class boost::serialization::access; private: template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(temperature); ar & BOOST_SERIALIZATION_NVP(voltage); ar &

C++ object lifetime profiling

大兔子大兔子 提交于 2019-12-06 09:35:45
问题 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