@@ -106,4 +106,83 @@ bool FromXml( T* pclass, const wchar_t* xml, CStringW& error )
106106 return FromXml (pclass, type, xml, error);
107107}
108108
109+ class ReflectClass ;
110+
111+ //
112+ // Path to highlight property set / get.
113+ //
114+ // instances collects <this> pointers converted to ReflectClass. Restore original pointer by calling instance[x]->ReflectGetInstance().
115+ // fields collects field names
116+ // types collects class Types.
117+ //
118+ class ReflectPath
119+ {
120+ public:
121+ ReflectPath (CppTypeInfo& type, const char * field);
122+
123+ void Init (ReflectClass* instance);
124+
125+ std::vector<ReflectClass*> instances;
126+ std::vector<const char *> fields;
127+ std::vector<CppTypeInfo> types;
128+ };
129+
130+
131+ //
132+ // All classes which use C++ reflection should inherit from this base class.
133+ //
134+ class ReflectClass
135+ {
136+ protected:
137+ // Parent class, nullptr if don't have parent class.
138+ ReflectClass* _parent;
139+
140+ // Field name under assignment.
141+ std::string _fieldName;
142+
143+ public:
144+ // Default constructor - this class does not have parent class.
145+ ReflectClass ():
146+ ReflectClass (nullptr )
147+ {
148+ }
149+
150+ ReflectClass (ReflectClass* parent, const char * fieldName = " " );
151+ ReflectClass (const ReflectClass& clone);
152+
153+ virtual CppTypeInfo& GetType () = 0;
154+ virtual void * ReflectGetInstance () = 0;
155+
156+ // By default set / get property rebroadcats event to parent class
157+ virtual void OnBeforeGetProperty (ReflectPath& path);
158+ virtual void OnAfterSetProperty (ReflectPath& path);
159+
160+ private:
161+ };
162+
163+ template <class T >
164+ class ReflectClassT : public ReflectClass
165+ {
166+ public:
167+ // Default constructor - this class does not have parent class.
168+ ReflectClassT () :
169+ ReflectClassT (nullptr )
170+ {
171+ }
172+
173+ ReflectClassT (ReflectClass* parent, const char * fieldName = " " ) :
174+ ReflectClass (parent, fieldName)
175+ {
176+ }
177+
178+ virtual CppTypeInfo& GetType ()
179+ {
180+ return T::GetType ();
181+ }
182+
183+ virtual void * ReflectGetInstance ()
184+ {
185+ return (T*) this ;
186+ }
187+ };
109188
0 commit comments