libcmo21/LibCmo/CK2/MgrImpls/CKBaseManager.hpp

175 lines
6.3 KiB
C++
Raw Normal View History

2023-02-26 21:48:03 +08:00
#pragma once
#include "../../VTInternal.hpp"
2023-02-26 21:48:03 +08:00
2023-09-04 22:58:53 +08:00
/**
CKBaseManager virtual functions implementations help
All virtual functions is not supported except we implemented.
Read/Write functions:
- SaveData()
- LoadData()
Clear functions:
- PreClearAll()
- PostClearAll()
Delete functions:
- SequenceToBeDeleted()
- SequenceDeleted()
Moved functions
- OnCKInit(): Implement in ctor
- OnCKEnd(): Implement in dtor
*/
namespace LibCmo::CK2::MgrImpls {
2023-02-26 21:48:03 +08:00
2023-08-25 17:35:45 +08:00
/**
@brief Base Class for managers.
@remark
+ This class provides virtual methods that can be override by any managers. Any manager that inherits from CKBaseManager can override function to do some processing.
+ The instances of managers may be retrieved through the global function CKContext::GetManagerByGuid()
+ Some default managers implemented in Virtools can be accessed directly: See Managers Access
*/
2023-02-26 21:48:03 +08:00
class CKBaseManager {
public:
2023-08-25 17:35:45 +08:00
CKBaseManager(CKContext* ctx, CKGUID guid, CKSTRING name) :
2023-09-16 18:31:25 +08:00
m_ManagerGuid(guid), m_ManagerName(), m_Context(ctx) {
XContainer::NSXString::FromCKSTRING(m_ManagerName, name);
}
2023-08-25 17:35:45 +08:00
virtual ~CKBaseManager() {}
YYCC_DEL_CLS_COPY_MOVE(CKBaseManager);
2023-02-26 21:48:03 +08:00
2023-08-25 17:35:45 +08:00
/**
@brief Acces to Manager GUID
@return CKGUID of this manager.
@remark
+ Each Manager is given an unique GUID. When creating a new manager it should
assign itself a GUID and name before registering itsef.
```
CKAttributeManager::CKAttributeManager(CKContext *Context) : CKBaseManager(Context, ATTRIBUTE_MANAGER_GUID, "Attribute Manager")
{
// ....
// ....
Context->RegisterNewManager(this);
}
```
@see CKContext::RegisterNewManager, GetName
*/
2023-09-04 22:58:53 +08:00
CKGUID GetGuid() {
return m_ManagerGuid;
2023-08-25 17:35:45 +08:00
}
/**
@brief Acces to Manager name
@return Name of this manager.
@remark
+ Each Manager is given an unique GUID. When creating a new manager it should
assign itself a GUID and name before registering itsef.
```
CKAttributeManager::CKAttributeManager(CKContext *Context) : CKBaseManager(Context, ATTRIBUTE_MANAGER_GUID, "Attribute Manager")
{
// ....
// ....
Context->RegisterNewManager(this);
}
```
*/
2023-09-04 22:58:53 +08:00
CKSTRING GetName() {
2023-09-16 18:31:25 +08:00
return XContainer::NSXString::ToCKSTRING(m_ManagerName);
2023-08-25 17:35:45 +08:00
}
2023-02-27 22:23:05 +08:00
2023-08-25 17:35:45 +08:00
/**
@brief Called to save manager data.
@param SavedFile A pointer to the CKFile being saved.
2023-09-04 22:58:53 +08:00
@return This function should return true or false if there is nothing to save.
2023-08-25 17:35:45 +08:00
@remark
+ During a save operation, each manager is given the opportunity to save its data in the file.
+ The file being saved is given for information only and must not be modified. It can be used to decide whether it is worth saving
data for your manager.
@see CKStateChunk, LoadData
*/
virtual bool SaveData([[maybe_unused]] CKStateChunk* chunk, [[maybe_unused]] CKFileVisitor* SavedFile) {
2023-09-04 22:58:53 +08:00
return false; // default value is false to indicate this manager do not need save any data.
2023-08-25 17:35:45 +08:00
}
/**
@brief Called to load manager data.
@param chunk A pointer to a CKStateChunk that was saved in the file.
@param LoadedFile A pointer to the CKFile being loaded.
2023-09-04 22:58:53 +08:00
@return CKERR_OK if successful or an error code otherwise.
2023-08-25 17:35:45 +08:00
@remark
+ During a load operation, each manager is automatically called if there was a chunk saved in the file with SaveData.
@see CKStateChunk, SaveData
*/
virtual CKERROR LoadData([[maybe_unused]] CKStateChunk* chunk, [[maybe_unused]] CKFileVisitor* LoadedFile) {
2023-09-04 22:58:53 +08:00
return CKERROR::CKERR_OK;
2023-08-25 17:35:45 +08:00
}
2023-09-04 22:58:53 +08:00
/**
@brief Called at the beginning of a CKContext::ClearAll operation.
@return CK_OK if successful or an error code otherwise.
@remark
+ You can override this function to add specific processing at the beginning of a CKContext::ClearAll operation.
+ You must override GetValidFunctionsMask and return a value including
CKMANAGER_FUNC_PreClearAll for this function to get called.
@see Main Virtools Events, PostClearAll, CKContext::ClearAll
*/
virtual CKERROR PreClearAll() { return CKERROR::CKERR_OK; }
/**
@brief Called at the end of a CKContext::ClearAll operation.
@return CKERR_OK if successful or an error code otherwise.
@remark
+ You can override this function to add specific processing at the end of a CKContext::ClearAll operation.
+ You must override GetValidFunctionsMask and return a value including
CKMANAGER_FUNC_PostClearAll for this function to get called.
@see Main Virtools Events, PreClearAll, CKContext::ClearAll
*/
virtual CKERROR PostClearAll() { return CKERROR::CKERR_OK; }
/**
@brief Called just before objects are deleted.
@return CK_OK if successful or an error code otherwise.
@param objids[in] A pointer to a list of CK_ID of the objects being deleted.
@param count[in] number of objects in objids list.
@remark
+ You can override this function if you need to add specific processing before objects are deleted.
+ You must override GetValidFunctionsMask and return a value including
CKMANAGER_FUNC_OnSequenceToBeDeleted for this function to get called.
@see Main Virtools Events, CKContext::DestroyObjects, SequenceDeleted
*/
virtual CKERROR SequenceToBeDeleted([[maybe_unused]] const CK_ID* objids, [[maybe_unused]] CKDWORD count) { return CKERROR::CKERR_OK; }
2023-09-04 22:58:53 +08:00
/**
@brief Called after objects have been deleted.
@return CK_OK if successful or an error code otherwise.
@param objids[in] A pointer to a list of CK_ID of the objects being deleted.
@param count[in] number of objects in objids list.
@remark
+ You can override this function if you need to add specific processing after objects have been deleted.
+ You must override GetValidFunctionsMask and return a value including
CKMANAGER_FUNC_OnSequenceDeleted for this function to get called.
@see Main Virtools Events, CKContext::DestroyObjects, SequenceToBeDeleted
*/
virtual CKERROR SequenceDeleted([[maybe_unused]] const CK_ID* objids, [[maybe_unused]] CKDWORD count) { return CKERROR::CKERR_OK; }
2023-09-04 22:58:53 +08:00
2023-08-25 17:35:45 +08:00
protected:
CKGUID m_ManagerGuid; ///> Manager GUID
2023-09-16 18:31:25 +08:00
XContainer::XString m_ManagerName; ///> Manager Name
2023-08-25 17:35:45 +08:00
CKContext* m_Context; ///> A pointer to the CKContext on which this manager is valid.
2023-02-26 21:48:03 +08:00
};
2023-08-25 17:35:45 +08:00
//class CKAttributeManager : public CKBaseManager {
//public:
// CKAttributeManager(CKContext* ctx, CK_ID ckid);
// CKAttributeManager(const CKAttributeManager&) = delete;
// CKAttributeManager& operator=(const CKAttributeManager&) = delete;
// virtual ~CKAttributeManager();
2023-02-26 21:48:03 +08:00
2023-08-25 17:35:45 +08:00
//private:
2023-02-26 21:48:03 +08:00
2023-08-25 17:35:45 +08:00
//};
2023-02-26 21:48:03 +08:00
}