2023-08-22 15:30:26 +08:00
# pragma once
2023-09-16 18:31:25 +08:00
# include "CKTypes.hpp"
# include "../XContainer/XTypes.hpp"
# include <functional>
2023-08-22 15:30:26 +08:00
namespace LibCmo : : CK2 {
// ========== Compression utilities ==========
/**
* @ brief Compress a buffer
* @ param [ in ] Data A pointer to the buffer to coompress
* @ param [ in ] size Size of the source buffer .
* @ param [ out ] NewSize A reference that will be filled with the size of the compressed buffer . 0 if failed .
* @ param [ in ] compressionlevel 0 - 9
* @ return
* A pointer to the compressed buffer . nullptr if failed .
* The return pointer should be freed by ` delete [ ] ` manually .
* @ remark
* The size of allocated return value may greater than the passed value of NewSize .
* NewSize only indicate the size of the part storing useful data in return value .
* @ see CKUnPackData , CKComputeDataCRC
*/
2023-08-28 21:21:40 +08:00
void * CKPackData ( const void * Data , CKDWORD size , CKDWORD & NewSize , CKINT compressionlevel ) ;
2023-08-22 15:30:26 +08:00
/**
* @ brief Decompress a buffer
* @ param [ in ] DestSize Expected size of the decompressed buffer .
* @ param [ in ] SrcBuffer Compressed buffer .
* @ param [ in ] SrcSize Size of the compressed buffer .
* @ return
* A pointer to the decompressed buffer or nullptr if there was a error .
* The return pointer should be freed by ` delete [ ] ` manually .
* @ see CKPackData , CKComputeDataCRC
*/
2023-08-28 21:21:40 +08:00
void * CKUnPackData ( CKDWORD DestSize , const void * SrcBuffer , CKDWORD SrcSize ) ;
2023-08-22 15:30:26 +08:00
/**
* @ brief Computes a CRC for a buffer .
* @ param [ in ] data A pointer to the buffer to create a CRC for .
* @ param [ in ] size Size of the source buffer .
* @ param [ in ] PreviousCRC
* The first time a CRC is computed this value should be 0 ,
* but it can be use to compute a single CRC for a several buffers
* by using the currently computed CRC for previous buffers in this value .
* @ return CRC of the buffer .
* @ see CKPackData , CKUnPackData
*/
2023-08-29 14:00:34 +08:00
CKDWORD CKComputeDataCRC ( const void * data , CKDWORD size , CKDWORD PreviousCRC = 0 ) ;
2023-09-04 22:58:53 +08:00
// ========== String Utilities ==========
2023-09-07 21:57:48 +08:00
/**
* @ brief Check whether 2 string is equal . Case senstive .
* @ param str1 [ in ] String 1
* @ param str2 [ in ] String 2
* @ return True if 2 string is equal .
* @ see CKStrIEqual
*/
2023-09-04 22:58:53 +08:00
bool CKStrEqual ( CKSTRING str1 , CKSTRING str2 ) ;
2023-09-07 21:57:48 +08:00
/**
* @ brief Check whther 2 string is equal . Case insenstive .
* @ param str1
* @ param str2
* @ return True if 2 string is equal .
* @ see CKStrEqual
*/
bool CKStrEqualI ( CKSTRING str1 , CKSTRING str2 ) ;
/**
* @ brief Check whether string is empty
* @ param strl
* @ return True if string is empty .
*/
bool CKStrEmpty ( CKSTRING strl ) ;
2023-09-04 22:58:53 +08:00
2023-09-16 18:31:25 +08:00
// ========== Class registration utilities ==========
2023-08-29 14:00:34 +08:00
2023-09-17 12:39:21 +08:00
using CKClassRegisterFct = std : : function < void ( ) > ;
2023-09-16 18:31:25 +08:00
using CKClassCreationFct = std : : function < ObjImpls : : CKObject * ( CKContext * , CK_ID , CKSTRING ) > ;
using CKClassReleaseFct = std : : function < void ( CKContext * , ObjImpls : : CKObject * ) > ;
using CKClassNameFct = std : : function < CKSTRING ( ) > ;
//using CKClassDependenciesFct = std::function<CKSTRING(CKINT, CKINT)>;
//using CKClassDependenciesCountFct = std::function<CKINT(CKINT)>;
struct CKClassDesc {
bool IsValid ; /**< True if this CKClassDesc is a valid one. Because CK_CLASSID may not be consecutive. */
bool Done ;
// Initialized upon class registration
CK_CLASSID Self ;
CK_CLASSID Parent ; // Class Identifier of parent class
2023-09-17 12:39:21 +08:00
CKClassRegisterFct RegisterFct ; // Pointer to Class Specific Registration function
2023-09-16 18:31:25 +08:00
CKClassCreationFct CreationFct ; // Pointer to Class instance creation function
CKClassReleaseFct ReleaseFct ; // Pointer to Class instance release function
CKClassNameFct NameFct ; // Pointer to Class name function
//CKClassDependenciesFct DependsFct; // Pointer to Class dependencies function (Copy,delete,replace...)
//CKClassDependenciesCountFct DependsCountFct; // Pointer to Class dependencies Count function (Copy,delete,replace...)
//// Initialized by class specific registration function
//CKDWORD DefaultOptions; // Default options for this class
//CKDWORD DefaultCopyDependencies;
//CKDWORD DefaultDeleteDependencies;
//CKDWORD DefaultReplaceDependencies;
//CKDWORD DefaultSaveDependencies;
//CKGUID Parameter; // Associated parameter GUID
// Initialized when building class hierarchy table
CKINT DerivationLevel ; // O => CKObject , etc..
XContainer : : XBitArray Parents ; // Bit Mask of parents classes
XContainer : : XBitArray Children ; // Bit Mask of children classes
2023-09-17 14:41:58 +08:00
XContainer : : XBitArray ToBeNotify ; // User specified notify list, only for current class. If any deleted objects match class id in this XBitArray, notify the host of this XBitArray.
2023-09-17 12:39:21 +08:00
XContainer : : XBitArray CommonToBeNotify ; // Same as ToBeNotify, but merging all parents' notify list.
XContainer : : XBitArray ToNotify ; // The ClassID to notify when an object of this class is deleted (inverse of ToBeNotify)
2023-09-16 18:31:25 +08:00
CKClassDesc ( ) :
IsValid ( false ) ,
Done ( false ) ,
Self ( CK_CLASSID : : CKCID_OBJECT ) , Parent ( CK_CLASSID : : CKCID_OBJECT ) ,
2023-09-17 12:39:21 +08:00
RegisterFct ( nullptr ) , CreationFct ( nullptr ) , ReleaseFct ( nullptr ) , NameFct ( nullptr ) ,
2023-09-16 18:31:25 +08:00
DerivationLevel ( 0 ) ,
2023-09-17 12:39:21 +08:00
Parents ( ) , Children ( ) , ToBeNotify ( ) , CommonToBeNotify ( )
2023-09-16 18:31:25 +08:00
{ }
2024-08-17 20:43:27 +08:00
YYCC_DEF_CLS_COPY_MOVE ( CKClassDesc ) ;
2023-09-16 18:31:25 +08:00
} ;
2023-08-23 16:04:58 +08:00
// ========== CKClass Registration ==========
2023-08-28 17:04:28 +08:00
2023-09-17 12:39:21 +08:00
void CKClassNeedNotificationFrom ( CK_CLASSID listener , CK_CLASSID listenTo ) ;
2023-09-01 12:19:06 +08:00
CK_CLASSID CKClassGetNewIdentifier ( ) ;
2023-08-23 16:04:58 +08:00
void CKClassRegister ( CK_CLASSID cid , CK_CLASSID parentCid ,
2023-09-17 12:39:21 +08:00
CKClassRegisterFct regFct , CKClassCreationFct createFct , CKClassReleaseFct relFct , CKClassNameFct nameFct ) ;
2023-08-23 16:04:58 +08:00
// ========== Class Hierarchy Management ==========
2023-08-28 17:04:28 +08:00
2023-09-01 12:19:06 +08:00
CKDWORD CKGetClassCount ( ) ;
2023-08-23 16:04:58 +08:00
const CKClassDesc * CKGetClassDesc ( CK_CLASSID cid ) ;
CKSTRING CKClassIDToString ( CK_CLASSID cid ) ;
2023-08-29 14:00:34 +08:00
bool CKIsChildClassOf ( CK_CLASSID child , CK_CLASSID parent ) ;
2023-08-23 16:04:58 +08:00
CK_CLASSID CKGetParentClassID ( CK_CLASSID child ) ;
CK_CLASSID CKGetCommonParent ( CK_CLASSID cid1 , CK_CLASSID cid2 ) ;
2023-09-17 12:39:21 +08:00
/**
* @ brief Check whether ' listener ' need notified by the deletion of ' deletedObjCid '
* @ param listener
* @ param deletedObjCid
* @ return true if need notify
*/
bool CKIsNeedNotify ( CK_CLASSID listener , CK_CLASSID deletedObjCid ) ;
/**
* @ brief Get all object cid need to be notified when ' delObjCids ' matched objects are deleting .
* @ param delObjCids
* @ param cidCount
* @ return
*/
XContainer : : XBitArray CKGetAllNotifyClassID ( const XContainer : : XBitArray & delObjCids ) ;
2023-08-23 16:04:58 +08:00
// ========== Initializations functions ==========
2023-09-23 15:55:57 +08:00
2023-08-23 16:04:58 +08:00
CKERROR CKStartUp ( ) ;
CKERROR CKShutdown ( ) ;
2023-08-22 15:30:26 +08:00
}