📄 icecell.h
字号:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Contains the base class.
* \file IceCell.h
* \author Pierre Terdiman
* \date February, 5, 2000
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __ICECELL_H__
#define __ICECELL_H__
// Loop through all owners
#define FOREACH_OWNER(cell, owner) \
{for(udword __idx=0;__idx<cell->GetNbOwners();__idx++){ \
owner = cell->GetOwner(__idx); \
if(owner){ \
// Loop through all references
#define FOREACH_REF(cell, ref) \
{for(udword __idx=0;__idx<cell->GetNbRefs();__idx++){ \
ref = cell->GetRef(__idx); \
if(ref){ \
// Loop through all typed references
#define FOREACH_TREF(cell, ref, type) \
{for(udword __idx=0;__idx<cell->GetNbRefs();__idx++){ \
ref = cell->GetRef(__idx); \
if(ref && ref->GetType()==type){ \
// Loop through all registered cells
#define FOREACH_CELL(cell, type) \
{for(udword __idx=0;__idx<GetKernel()->GetNbEntries();__idx++){ \
cell = GetKernel()->GetEntries()[__idx]; \
if(cell && cell->GetType()==type){ \
// End loop
#define END_FOREACH }}}
//! Cell flags
enum CellFlag
{
CF_VALID = (1<<0), //!< Cell has successfully been initialized
CF_KERNEL_MODIF = (1<<1), //!< Kernel control: enable direct cell members modifications by the kernel
CF_KERNEL_DESTRUCT = (1<<2), //!< Kernel control: enable direct cell destruction by the kernel
CF_KERNEL_MSGS = (1<<3), //!< Enable kernel messages
CF_KERNEL_INVALIDREF = (1<<4), //!< Enable OnInvalidReference calls
CF_SERIALIZE = (1<<5), //!< Enable serialization
CF_LOCKED = (1<<6), //!< The cell has been locked and shouldn't be modified
CF_FORCE_DWORD = 0x7fffffff
};
//! Request types
enum KernelRequest
{
KR_FIELDSIZE = 1, //!< Request the size of a dynamic field
KR_FORCE_DWORD = 0x7fffffff
};
// Forward declarations
class Cell;
class Kernel;
class DataBlock;
class SmartContainer;
class IceMsg;
class ICECORE_API CellsContainer : private Container
{
public:
// Constructor / Destructor
CellsContainer(const SmartContainer& container);
CellsContainer() {}
~CellsContainer() {}
inline_ udword GetNbCells() const { return GetNbEntries(); }
inline_ Cell** GetCells() const { return (Cell**)GetEntries(); }
inline_ Cell* GetCell(udword i) const { return (Cell*)GetEntry(i); }
inline_ CellsContainer& AddCell(const Cell* cell) { Add(udword(cell)); return *this; }
//! Operator for "Container A = SmartContainer B"
void operator=(const SmartContainer& container);
PREVENT_COPY(CellsContainer)
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Notification-callback, called by the system each time a registered notification is hit.
* \param owner [in] object to notify
* \param param [in] a parameter transfered from the ExecNotif call
* \param bit_mask [in] notification bitmask
* \param user_data [in] registered user-defined data for this callback
* \return usually, true to override a possible default behaviour
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef bool (*NotifCallback)(Cell* owner, udword param, udword bit_mask, udword user_data);
struct ICECORE_API NotifBundle
{
inline_ NotifBundle() : mCB(null), mUserData(0), mBitmask(0) {}
NotifCallback mCB; //!< Notification callback
udword mUserData; //!< User-defined data
udword mBitmask; //!< Event bitmask
};
class ICECORE_API Cell
{
_DECLARE_PROTECTED_CLASS(Cell)
DECLARE_FIELDS
DECLARE_RTTI_BASE(Cell)
PREVENT_COPY(Cell)
public:
//! TO BE DOCUMENTED
virtual udword Import(ImportContext& ic);
//! TO BE DOCUMENTED
virtual udword Export(ExportContext& ec);
//! TO BE DOCUMENTED
virtual bool GetFields(FieldDescriptors& edit, udword flags) const;
virtual bool GetFields(FieldDescriptors& edit, FieldType type) const;
virtual bool GetFields(FieldDescriptors& edit, FieldType type, udword user) const;
virtual bool GetFields(FieldDescriptors& edit) const;
virtual const FieldDescriptor* GetFieldDescriptor(FieldType type, udword user) const;
virtual const FieldDescriptor* GetFieldDescriptor(const char* name) const;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* This method is called by the kernel after a declared field has been modified.
* \param field [in] descriptor for the modified field
* \return true if the method has been overriden
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual bool OnModifiedField(const FieldDescriptor& field) { return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* This method is called by the kernel to request various dynamic information.
* \param kr [in] kernel request code
* \param context [in] request context - depends on kr
* \param data [out] a place for the user to answer the request
* \return true if the method has been overriden
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual bool OnKernelRequest(KernelRequest kr, udword context, udword& data) { return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* This method is called by the kernel after a referenced cell has been dereferenced or deleted.
* \param invalidref [in] the now invalid referenced cell
* \return true if the method has been overriden
* \warning Only called if CF_KERNEL_INVALIDREF is enabled
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual bool OnInvalidReference(const Cell* invalidref) { return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* This method is called by the kernel to send a message to a given cell.
* \param msg [in] the message structure
* \return true if the message has been caught
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual bool Message(const IceMsg& msg);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Sends a message to all cell owners whose type is given.
* \param msg [in] the message structure
* \param type [in] pointer to the type, or null to send the message to all owners
* \return true if success
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool SendMsgToOwners(const IceMsg& msg, const char** type=null);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Sends a message to all cell references whose type is given.
* \param msg [in] the message structure
* \param type [in] pointer to the type, or null to send the message to all references
* \return true if success
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool SendMsgToRefs(const IceMsg& msg, const char** type=null);
//! TO BE DOCUMENTED
bool CreateRef(Cell* ref);
bool DeleteRef(Cell* ref);
bool CreateRef(KID kid);
bool DeleteRef(KID kid);
bool CreateTypedRef(Cell* ref, RTYPE type);
//! TO BE DOCUMENTED
bool ReplaceRef(Cell* oldref, Cell* newref);
//! TO BE DOCUMENTED
udword GetNbRefs() const;
udword GetNbOwners() const;
Cell* GetOwner(udword i=0) const;
Cell* GetRef(udword i=0) const;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Gets the cell dependencies, i.e. its references whose type is given.
* \param dependencies [out] referenced cells whose type matches
* \param type [in] wanted type, or null to dump all dependencies
* \return number of cells added to the container
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
udword GetDependencies(CellsContainer& dependencies, const char* type=null);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Gets the cell's kernel ID.
* \return kernel ID
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline_ KID GetKernelID() const { return m__KernelID; }
//! High-speed KernelID-to-cell translation
Cell* KIDToCell(KID kid) const;
// Type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Sets the cell's type. Despite it's a const char, you can use it as an ID by supplying addresses of fixed strings in memory.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -