7#include "BaseClassIO.h"
55struct BaseClassElement {
80 unsigned short CachedIndex;
82 void fill(
void* _Ptr,
void* _Extra,
bool _vis,
bool _ui,
bool OnlyPointersMode);
84 void reset(
bool initmask=
true);
89typedef void (*voidFunc)();
102 friend BaseClassElement;
119 DWORD& ClassMask() {
return _ClassMask; }
121 void runFunction(voidFunc func) { func(); }
139 virtual void CountObjects(
int& required_index,
int* counter, HashSummator* hash, BaseClassElement* result,
const std::function<
bool(BaseClassElement*)>* ForEachElem =
nullptr,
bool OnlyPointersMode =
false) { }
146 void ForEach(
const std::function<
bool(BaseClassElement* el)>& fn,
bool OnlyPointsers =
false);
182 virtual bool FullCopy(
const void* SrcData,
const void* SrcDataExtra,
BaseClass* Dest,
void* DestData,
void* DstDataExtra, CECopyContext* C);
191 virtual void SaveBin(
void* Data,
void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList);
199 virtual void LoadBin(
void* Data,
void* Extra, BinStream* In, Enumerator* ExDictionary);
207 virtual void UpdateHash(HashSummator& S,
void* data =
nullptr,
void* extra =
nullptr);
255 virtual bool GetElement(BaseClassElement& res,
int idx,
const void* Ptr =
nullptr,
const void* Extra =
nullptr);
264 bool GetElementByName(
const char* Name,
void* Ptr,
void* Extra, BaseClassElement& res,
bool UI =
false,
bool Serialize =
true);
265 bool GetElementByNameAndType(
const char* Name,
const char* Type,
void* Ptr,
void* Extra, BaseClassElement& res,
bool UI =
false,
bool Serialize =
true);
277 virtual int ExpandWith(
const char* ElmName,
void* base){
return -1; }
285 template<
class Type = BaseClass>
288 bool valid<BaseClass>()
const;
315 virtual bool ReadFromFile (
const char* Name,
bool very_safe_with_backup =
false);
316 virtual bool WriteToFile (
const char* Name);
317 virtual bool WriteToFileIfChanged (
const char* Name);
320 virtual void ToBS(BinStream& bs,
bool IncludeLength);
321 virtual void FromBS(BinStream& bs);
322 virtual void ToBS(BinStream& bs,
void* data,
void* extra,
bool IncludeLength);
323 virtual void FromBS(BinStream& bs,
void* data,
void* extra);
325 virtual void ToStr(comms::cStr& bs);
336 virtual BaseClass* GetParent()
const {
return ParentBC;}
337 template <
typename type> type* FindParent();
343 virtual bool MayBeParent() {
return true; }
375 virtual int GetElementLevel(
const char* EName){
return 0;}
396 virtual void OnModifyControl(
const char* FieldName, BaseWidget* W, ClassEditorContext& Context){};
402 virtual bool CanBeDragged(
const char* MemberID,
int& dx,
int& dy){
return false;}
408 virtual bool OnEndDrag(
const char* MemberID ){
return false; }
410 virtual bool OnAcceptDrag(
BaseClass* DraggedItemParent,
const char* DraggedMemberID,
const char* AcceptorMemberID, iRct MyRect ){
return false; }
411 virtual bool UsePointerInHashCalculation() {
return false; }
412 virtual bool SkipHash(){
return false;}
413 virtual bool IsArray()
const {
return false; }
414 virtual const char* GetCmdID(){
return NULL;}
421 static const char* GetCurrentSaveFile();
426 virtual void UpdateClassMembersAndMask(
bool recursive );
428 static bool SaveInShortForm;
430 virtual bool CallFromScript()
const {
return bCallFromScript; }
431 virtual void CallFromScript(
const bool& b) { bCallFromScript = b; }
433 static bool& UI_definition();
434 static bool& Serialization();
436 bool bCallFromScript;
437 void test_presence_integrity();
441 static uni_hash<_empty, cPtrDiff, (1 << 18), 2048>&
presence();
442 void register_this();
446 SG::SG_Object* sgObj;
448 template <
class T> T* toCastSGObj()
const {
449 return static_cast<T*
>(sgObj);
452 SG::SG_Object* GetSGObj()
const {
return sgObj; }
453 virtual void SetSGObj(SG::SG_Object* obj,
bool bInit =
false);
454 virtual void OnSetupSG() { ; }
455 virtual bool OnScriptRecorder(
BaseClass* MembClass,
void* MembPtr,
void* MembExtra,
const char* MembName);
460inline void HashSummator::operator+=(
BaseClass* value) {
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition BaseClass.h:94
virtual bool CheckIfFunction() const
Special function for integrating in editor.
Definition BaseClass.h:332
bool valid() const
call it to check if this BaseClass pointer is valid
static std::mutex & get_bc_mutex()
mutex for register_this / remove_this
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary)
Load the class from the memory. Use only for temporary storage in memory!!!
virtual bool HandleKey(int code)
Editor will call next function when key pressed.
Definition BaseClass.h:362
virtual bool CopyBaseClass(BaseClass *Dest, bool Add=false)
Copy base class to other class uning names correspondence.
virtual bool ProcessInEditor(BaseClass *Parent)
Editor will call next function always when it is visible in tree. Return true if overriden.
Definition BaseClass.h:352
virtual BaseWidget * OnCreateControlFromScratch(const ClassEditorContext &Context, Rct &Rect)
Create completely own control for ClassEditor.
Definition BaseClass.h:386
virtual bool OnStartDrag(const char *MemberID)
Definition BaseClass.h:406
virtual bool CheckCompartabilityWith(const char *TypeName, int TypeSize)
Checking for errors of registration.
Definition BaseClass.h:346
virtual DWORD GetClassMask()
Masking elements of class. Each member has mask. Element is serializable/visible only if (it's_mask &...
Definition BaseClass.h:118
void SetParents()
set parents to this for all child members
bool GetElementByName(const char *Name, void *Ptr, void *Extra, BaseClassElement &res, bool UI=false, bool Serialize=true)
The function returns complete information about the member by it's name.
static const char * CurrentSaveFile
If user triggers saving class to file, last filename stored there.
Definition BaseClass.h:424
void DeleteDefaultSubFields(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Short form saving. Fields that are unchanged in comparison to default will be skipped in XML.
virtual bool OnAcceptDrag(BaseClass *DraggedItemParent, const char *DraggedMemberID, const char *AcceptorMemberID, iRct MyRect)
Definition BaseClass.h:410
static uni_hash< _empty, cPtrDiff,(1<< 18), 2048 > & presence()
each BaseClass registered in this list
virtual bool ReadFromFile(const char *Name, bool very_safe_with_backup=false)
Save the object to file or binary stream. Example.
virtual int GetAmountOfElementsInUI()
return amount of elements represented in UI
virtual void FromStr(const comms::cStr &bs)
virtual bool DelElement(int Index)
removes element if the operation supported
Definition BaseClass.h:279
virtual cStruct * pySerialize()
returns a list of python-generated properties for serialization and UI
Definition BaseClass.h:217
virtual int GetClassSize() const
return actual size of this class
virtual bool OnChangeMember(BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
Editor will call it every time when member changes and editor is able to recognise it.
Definition BaseClass.h:368
void ForEach(const std::function< bool(BaseClassElement *el)> &fn, bool OnlyPointsers=false)
Calls function for each class member. This function used in _EACH ... _EACH_END cycle.
BaseClass * GetRoot()
BaseClass is like a tree, and you always can get the root of the tree using this function.
virtual void BeforeChangeMember(BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
Editor will call it every time before the changes.
Definition BaseClass.h:374
virtual BaseClass * new_element() const
construct pointer to class of the same type like this. Elements will not be copied into the new place
virtual bool Load(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Load the class from the XML structure.
virtual bool ShouldSaveInShortForm()
Return true if class should be saved in short form mandatory.
Definition BaseClass.h:272
virtual bool CanBeDragged(const char *MemberID, int &dx, int &dy)
Use it for build a Drag & Drop element.
Definition BaseClass.h:402
virtual void reset_class(void *DataPtr=nullptr)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
virtual void OnModifyControl(const char *FieldName, BaseWidget *W, ClassEditorContext &Context)
Call for every member of registered class registered class.
Definition BaseClass.h:396
virtual void SetParent(BaseClass *Parent)
set parent recursively
virtual const char * GetClassName() const
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList)
Save in binaly form. Use only for temporary storage in memory!!!
virtual int GetAmountOfElements()
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
virtual bool CanAcceptDrag(const char *MemberID)
Definition BaseClass.h:404
virtual void Save(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Save class to the XML structure.
DWORD _ClassMask
Result of GetClassMask() written there. GetClassMask() is not const, so can't use it in const functio...
Definition BaseClass.h:99
virtual ~BaseClass()
virtual destructor
virtual int GetAmountOfElementsInXML()
return amount of elements taht will be stored in XML
virtual bool RenderInScene(BaseClass *Parent)
Editor will call next function to render in-scene controls always when it is visible in tree....
Definition BaseClass.h:356
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem=nullptr, bool OnlyPointersMode=false)
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition BaseClass.h:139
virtual bool GetElement(BaseClassElement &res, int idx, const void *Ptr=nullptr, const void *Extra=nullptr)
virtual void SimplySetParent(BaseClass *Parent)
set parent directly to this, not affecting members
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DstDataExtra, CECopyContext *C)
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
void SetParentsSafe()
set parents to this for all child members, each child will be tested for validity
BaseClass * auto_cast(void *ptr) const
if class is directly castable the function returns ptr cased to BaseClass, othervice this pointrer re...
virtual bool OnEndDrag(const char *MemberID)
Definition BaseClass.h:408
virtual bool CheckDirectCasting() const
Definition BaseClass.h:234
BaseClass * ParentBC
pointer to the parent class in the tree
Definition BaseClass.h:97
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition BaseClass.h:277
virtual void UpdateHash(HashSummator &S, void *data=nullptr, void *extra=nullptr)
returns hash value dependent on data fields of this class
virtual int condition_call(void *ptr)
return -1 to do nothing, 0 if you want to hide everything after this registered member,...
Definition BaseClass.h:334
virtual void RegisterMembers()
Reload this function to register members. Usually you don't need to do this if you are using any of S...
The pointer to the allocated class derived from the BaseClass. It allows serialization/presentation i...
Definition classlist.h:565