3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BaseClass Class Reference

Use this class for build a class for UI or serialization. see class_reg.h for details about the class registration. More...

#include <BaseClass.h>

Inheritance diagram for BaseClass:
ClassArray< X > ClassPtr< X > ClassRef< X > StringsList __state

Public Member Functions

BaseClassGetRoot ()
 BaseClass is like a tree, and you always can get the root of the tree using this function.
 
 BaseClass (const BaseClass &)
 
virtual ~BaseClass ()
 virtual destructor
 
virtual DWORD GetClassMask ()
 Masking elements of class. Each member has mask. Element is serializable/visible only if (it's_mask & hosting_class_mask) != 0.
 
DWORD & ClassMask ()
 
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 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 creates this function automatically.
It may count members, return hash, give element-wise access to any member. Instead of keeping registered fields that routine gives fast dynamic access to any member.
If you making own container, you should create this function as well, othervice your class will not be serialized correctly even if you will make GetElement(...) function.
 
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.
 
virtual bool CopyBaseClass (BaseClass *Dest, bool Add=false)
 Copy base class to other class uning names correspondence.
 
virtual void Save (TagsList &xml, void *ClassPtr, void *Extra=NULL)
 Save class to the XML structure.
 
virtual bool Load (TagsList &xml, void *ClassPtr, void *Extra=NULL)
 Load the class from the XML structure.
 
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.
 
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 void LoadBin (void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary)
 Load the class from the memory. Use only for temporary storage in memory!!!
 
virtual void UpdateHash (HashSummator &S, void *data=nullptr, void *extra=nullptr)
 returns hash value dependent on data fields of this class
 
virtual int GetAmountOfElementsInUI ()
 return amount of elements represented in UI
 
virtual int GetAmountOfElementsInXML ()
 return amount of elements taht will be stored in XML
 
virtual cStruct * pySerialize ()
 returns a list of python-generated properties for serialization and UI
 
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 RegisterMembers ()
 Reload this function to register members. Usually you don't need to do this if you are using any of SERIALIZE methods of registration.
 
virtual int GetAmountOfElements ()
 return complete amount of elements. Even invisible, masked and non-serialized elements will be counted
 
virtual bool CheckDirectCasting () const
 
virtual int GetClassSize () const
 return actual size of this class
 
virtual BaseClassnew_element () const
 construct pointer to class of the same type like this. Elements will not be copied into the new place
 
virtual bool GetElement (BaseClassElement &res, int idx, const void *Ptr=nullptr, const void *Extra=nullptr)
 
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.
 
bool GetElementByNameAndType (const char *Name, const char *Type, void *Ptr, void *Extra, BaseClassElement &res, bool UI=false, bool Serialize=true)
 
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 ShouldSaveInShortForm ()
 Return true if class should be saved in short form mandatory.
 
virtual int ExpandWith (const char *ElmName, void *base)
 Expand array with class ElmName.
 
virtual bool DelElement (int Index)
 removes element if the operation supported
 
template<class Type = BaseClass>
bool valid () const
 call it to check if this BaseClass pointer is valid
 
template<>
bool valid () const
 
BaseClassauto_cast (void *ptr) const
 if class is directly castable the function returns ptr cased to BaseClass, othervice this pointrer returned. If NULL returned - something is wrong.
 
virtual bool ReadFromFile (const char *Name, bool very_safe_with_backup=false)
 Save the object to file or binary stream. Example.
 
virtual bool WriteToFile (const char *Name)
 
virtual bool WriteToFileIfChanged (const char *Name)
 
virtual void ToBS (BinStream &bs, bool IncludeLength)
 
virtual void FromBS (BinStream &bs)
 
virtual void ToBS (BinStream &bs, void *data, void *extra, bool IncludeLength)
 
virtual void FromBS (BinStream &bs, void *data, void *extra)
 
virtual void ToStr (comms::cStr &bs)
 
virtual void FromStr (const comms::cStr &bs)
 
virtual bool CheckIfFunction () const
 Special function for integrating in editor.
 
virtual int condition_call (void *ptr)
 return -1 to do nothing, 0 if you want to hide everything after this registered member, 1 if you want to show
 
virtual BaseClassGetParent () const
 
template<typename type >
type * FindParent ()
 
virtual void SetParent (BaseClass *Parent)
 set parent recursively
 
virtual void SimplySetParent (BaseClass *Parent)
 set parent directly to this, not affecting members
 
virtual bool MayBeParent ()
 
virtual bool CheckCompartabilityWith (const char *TypeName, int TypeSize)
 Checking for errors of registration.
 
virtual bool ProcessInEditor (BaseClass *Parent)
 Editor will call next function always when it is visible in tree. Return true if overriden.
 
virtual bool RenderInScene (BaseClass *Parent)
 Editor will call next function to render in-scene controls always when it is visible in tree. Return true if overriden.
 
virtual bool HandleKey (int code)
 Editor will call next function when key pressed.
 
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.
 
virtual void BeforeChangeMember (BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
 Editor will call it every time before the changes.
 
virtual int GetElementLevel (const char *EName)
 
virtual BaseWidget * OnCreateControlFromScratch (const ClassEditorContext &Context, Rct &Rect)
 Create completely own control for ClassEditor.
 
virtual void OnModifyControl (const char *FieldName, BaseWidget *W, ClassEditorContext &Context)
 Call for every member of registered class registered class.
 
virtual bool CanBeDragged (const char *MemberID, int &dx, int &dy)
 Use it for build a Drag & Drop element.
 
virtual bool CanAcceptDrag (const char *MemberID)
 
virtual bool OnStartDrag (const char *MemberID)
 
virtual bool OnEndDrag (const char *MemberID)
 
virtual bool OnAcceptDrag (BaseClass *DraggedItemParent, const char *DraggedMemberID, const char *AcceptorMemberID, iRct MyRect)
 
virtual bool UsePointerInHashCalculation ()
 
virtual bool SkipHash ()
 
virtual bool IsArray () const
 
virtual const char * GetCmdID ()
 
void SetParents ()
 set parents to this for all child members
 
void SetParentsSafe ()
 set parents to this for all child members, each child will be tested for validity
 
virtual void UpdateClassMembersAndMask (bool recursive)
 
virtual bool CallFromScript () const
 
virtual void CallFromScript (const bool &b)
 

Static Public Member Functions

static const char * GetCurrentSaveFile ()
 
static bool & UI_definition ()
 
static bool & Serialization ()
 

Static Public Attributes

static const char * CurrentSaveFile
 If user triggers saving class to file, last filename stored there.
 
static bool SaveInShortForm
 

Protected Member Functions

void test_presence_integrity ()
 
void register_this ()
 
void remove_this ()
 

Protected Attributes

BaseClassParentBC
 pointer to the parent class in the tree
 
DWORD _ClassMask
 Result of GetClassMask() written there. GetClassMask() is not const, so can't use it in const functions. The field introduced to use masking in const functions.
 
bool bCallFromScript
 

Static Protected Attributes

static std::mutex * pmutex
 mutex for register_this / remove_this
 
static uni_hash< _empty, cPtrDiff,(1<< 18), 2048 > * presence
 each BaseClass registered in this list
 

Detailed Description

Use this class for build a class for UI or serialization. see class_reg.h for details about the class registration.

Examples
HoneyComb.cpp, capsule.cpp, dialogs.cpp, ellipses.cpp, ffCube.cpp, ffCylinder.cpp, gear.cpp, meshes.cpp, meshes_surface_merge.cpp, metaballs.cpp, spheres.cpp, spiral.cpp, square_volume.cpp, thread.cpp, threadStud.cpp, and tube.cpp.

Member Function Documentation

◆ BeforeChangeMember()

virtual void BaseClass::BeforeChangeMember ( BaseClass MembClass,
void *  MembPtr,
void *  MembExtra,
const char *  MembName 
)
inlinevirtual

Editor will call it every time before the changes.

See also
OnChangeMember()

◆ CanAcceptDrag()

virtual bool BaseClass::CanAcceptDrag ( const char *  MemberID)
inlinevirtual

◆ CanBeDragged()

virtual bool BaseClass::CanBeDragged ( const char *  MemberID,
int &  dx,
int &  dy 
)
inlinevirtual

Use it for build a Drag & Drop element.

See also
CanAcceptDrag(), OnStartDrag(), OnEndDrag(), OnAcceptDrag()

◆ CheckDirectCasting()

virtual bool BaseClass::CheckDirectCasting ( ) const
inlinevirtual

BaseClass corresponds to some other data type. For example _int correctonds to int, etc... In this case you can't cast pointer to data to BaseClass*. But in some cases BaseClass may be directlt castable, for example if it has registered members, or it is ClassArray. This function is to define if class is directly castable.

Returns
Return true if void* ClassPtr may be directly casted to BaseClass*

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ CopyBaseClass()

virtual bool BaseClass::CopyBaseClass ( BaseClass Dest,
bool  Add = false 
)
virtual

Copy base class to other class uning names correspondence.

Parameters
DestThe destination object
AddAdd members to class arrays or replace
Returns
true if successful

◆ CountObjects()

virtual void BaseClass::CountObjects ( int &  required_index,
int *  counter,
HashSummator *  hash,
BaseClassElement *  result,
const std::function< bool(BaseClassElement *)> *  ForEachElem = nullptr,
bool  OnlyPointersMode = false 
)
inlinevirtual

This is the main function used for the access to class members. Each class that has SERIALIZE section creates this function automatically.
It may count members, return hash, give element-wise access to any member. Instead of keeping registered fields that routine gives fast dynamic access to any member.
If you making own container, you should create this function as well, othervice your class will not be serialized correctly even if you will make GetElement(...) function.

Parameters
required_indexIndex of required element if result != nullptr
counterif nonzero, the elements count returned there.
hashif nonzero, returns hash value for this class.
resultif nonzero, gives access to the member with index required_index.
ForEachElemif nonzero, the function will be called for each class element.
OnlyPointersModeIf true, the field name will not be filled for speed purposes.

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ DelElement()

virtual bool BaseClass::DelElement ( int  Index)
inlinevirtual

removes element if the operation supported

Reimplemented in ClassArray< X >, ClassPtr< X >, ClassRef< X >, and StringsList.

◆ ExpandWith()

virtual int BaseClass::ExpandWith ( const char *  ElmName,
void *  base 
)
inlinevirtual

Expand array with class ElmName.

Reimplemented in ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ ForEach()

void BaseClass::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.

Parameters
fnFunction to call, usually lambda
OnlyPointsersIf true, stringual ID field of BaseClassElement will not be filled (for speed purposes).

◆ FromStr()

virtual void BaseClass::FromStr ( const comms::cStr &  bs)
virtual
See also
ToBS()

◆ FullCopy()

virtual bool BaseClass::FullCopy ( const void *  SrcData,
const void *  SrcDataExtra,
BaseClass Dest,
void *  DestData,
void *  DstDataExtra,
CECopyContext *  C 
)
virtual

Fast copy from one BaseClass to another. Names and types correspondence used to copy.

Parameters
SrcDataData data pointer
SrcDataExtraSrc extra
DestDestination class
DestDataDestination data
DstDataExtraDestination extra
Ccopy context
Returns
true if successful

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ GetAmountOfElements()

virtual int BaseClass::GetAmountOfElements ( )
virtual

return complete amount of elements. Even invisible, masked and non-serialized elements will be counted

Reimplemented in ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ GetClassName()

virtual const char * BaseClass::GetClassName ( ) const
virtual

return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ GetElement()

virtual bool BaseClass::GetElement ( BaseClassElement &  res,
int  idx,
const void *  Ptr = nullptr,
const void *  Extra = nullptr 
)
virtual

\briefThe The function returns complete information about the member by it's index. If you want to walk through all members use _EACH ... _EACH_END loop.

Parameters
resAll data gathered there
idxIndex of the member
PtrPointer to data (if class is direcly castable it is equal to this, othervice it points to placement of data in memory). If NULL passed, this will be used
ExtraExtra data, used for enumerators and sliders (mostly)
Returns
return true if element exists and visible

Reimplemented in ClassPtr< X >, and ClassRef< X >.

◆ GetElementByName()

bool BaseClass::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.

Parameters
NameName of the member
PtrData ptr
ExtraExtra
resAll data gathered there
Returns
return true if element exists and visible

◆ HandleKey()

virtual bool BaseClass::HandleKey ( int  code)
inlinevirtual

Editor will call next function when key pressed.

Returns
true if key handled, false if not.Return true if code == -1 (othervice callback will never be called later).

◆ Load()

virtual bool BaseClass::Load ( TagsList xml,
void *  ClassPtr,
void *  Extra = NULL 
)
virtual

Load the class from the XML structure.

Parameters
xmlThe source XML
ClassPtrThe pointer to the data, equals to this if class is directly castable
ExtraExtra data pointer
Returns
true if successful

Reimplemented in StringsList, and ClassArray< X >.

◆ LoadBin()

virtual void BaseClass::LoadBin ( void *  Data,
void *  Extra,
BinStream *  In,
Enumerator *  ExDictionary 
)
virtual

Load the class from the memory. Use only for temporary storage in memory!!!

Parameters
DataPointer to the class data
ExtraExtra data
Inbinary stream to read data from
ExDictionaryAdditional dictionary

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ OnAcceptDrag()

virtual bool BaseClass::OnAcceptDrag ( BaseClass DraggedItemParent,
const char *  DraggedMemberID,
const char *  AcceptorMemberID,
iRct  MyRect 
)
inlinevirtual

◆ OnChangeMember()

virtual bool BaseClass::OnChangeMember ( BaseClass MembClass,
void *  MembPtr,
void *  MembExtra,
const char *  MembName 
)
inlinevirtual

Editor will call it every time when member changes and editor is able to recognise it.

Returns
The value doesn't matter.
See also
BeforeChangeMember()

◆ OnCreateControlFromScratch()

virtual BaseWidget * BaseClass::OnCreateControlFromScratch ( const ClassEditorContext &  Context,
Rct &  Rect 
)
inlinevirtual

Create completely own control for ClassEditor.

Override it when need to create completely own class editor control.

Parameters
[in]FieldNameis how the object registered.
[out]Rectis rectangle to place control, may be modified by this function if need.
[in]Ptris pointer to data, if class suports direct casting it is equal to "this".
Returns
The function should return control (BaseWidget*) to place in UI
See also
One2DCurve::OnModifyControl()

Reimplemented in __state.

◆ OnEndDrag()

virtual bool BaseClass::OnEndDrag ( const char *  MemberID)
inlinevirtual

◆ OnModifyControl()

virtual void BaseClass::OnModifyControl ( const char *  FieldName,
BaseWidget *  W,
ClassEditorContext &  Context 
)
inlinevirtual

Call for every member of registered class registered class.

Override it when you need to modify default class editor control. This routine allows to modify class editor controls without rewriting from scratch. Build controls in the W.

See also
MultiMtlLayer::OnModifyControl()
RetopoGroup::OnModifyControl()
VoxTreeBranch::OnModifyControl()

◆ OnStartDrag()

virtual bool BaseClass::OnStartDrag ( const char *  MemberID)
inlinevirtual

◆ ReadFromFile()

virtual bool BaseClass::ReadFromFile ( const char *  Name,
bool  very_safe_with_backup = false 
)
virtual

Save the object to file or binary stream. Example.

MyClass C;
MyClass C1;
// to stream
MemoryBinStream BS;
C.ToBS(BS, true);
// copy from C to C1
C1.FromBS(BS);
// to file
C.WriteToFile("file.xml");
C1.ReadFromFile("file.xml");
// to string
cStr s;
C.ToStr(s);
C1.FromStr(s);
Definition cStr.h:6

◆ reset_class()

virtual void BaseClass::reset_class ( void *  DataPtr = nullptr)
virtual

Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.

Reimplemented in ClassPtr< X >, ClassRef< X >, StringsList, and ClassArray< X >.

◆ Save()

virtual void BaseClass::Save ( TagsList xml,
void *  ClassPtr,
void *  Extra = NULL 
)
virtual

Save class to the XML structure.

Parameters
xmlThe result
ClassPtrThe pointer to the data, equals to this if class is directly castable
ExtraExtra data pointer

Reimplemented in StringsList.

◆ SaveBin()

virtual void BaseClass::SaveBin ( void *  Data,
void *  Extra,
BinStream *  Out,
Enumerator *  ExDictionary,
Enumerator *  SkipList 
)
virtual

Save in binaly form. Use only for temporary storage in memory!!!

Parameters
Datadata pointer
Extraextra pointer
OutOutput stream
ExDictionaryDictionary for enumerators
SkipListSkip list for enumerators

Reimplemented in StringsList, ClassArray< X >, ClassPtr< X >, and ClassRef< X >.

◆ UpdateHash()

virtual void BaseClass::UpdateHash ( HashSummator &  S,
void *  data = nullptr,
void *  extra = nullptr 
)
virtual

returns hash value dependent on data fields of this class

Parameters
dataData ptr pointer to data
extraExtra ptr pointer to methadata
Returns
Hash value returns some value dependent on the class inner data. Usually only serializable data influences on th return value.

Reimplemented in StringsList.


The documentation for this class was generated from the following file: