libcmo21/LibCmo/CK2/CKContext.hpp

115 lines
4.0 KiB
C++
Raw Normal View History

2023-08-22 15:30:26 +08:00
#pragma once
#include "../VTAll.hpp"
#include <filesystem>
#include <map>
2023-08-23 16:04:58 +08:00
#include <deque>
2023-08-22 15:30:26 +08:00
#include <functional>
namespace LibCmo::CK2 {
/**
@brief Main Interface Object
@details
+ The CKContext object is the heart of all Virtools based applications, It is the first object that should be created in order to
use Virtools SDK. A CKContext can be simply created by calling its constructor.
+ The CKContext object act as the central interface to create/destroy objects,to access managers, to load/save files.
+ Several CKContext can be created inside a same process (in multiple threads for example) but objects created
by a specific CKContext must not be used in other contextes.
@see CKContext::CreateObject, CKContext::GetObject, CKContext::DestroyObject
*/
class CKContext {
public:
CKContext();
CKContext(const CKContext&) = delete;
CKContext& operator=(const CKContext&) = delete;
~CKContext();
2023-08-23 16:04:58 +08:00
// ========== Objects Management ==========
2023-08-22 15:30:26 +08:00
/**
* @brief Creates a CKObject or derived class instance.
* @param[in] cls Class Identifier (CK_CLASSID) of the object to create.
* @param[in] name The name of this object.
2023-08-23 16:04:58 +08:00
* @param[in] options Tell CKContext how to create this object when conflict happended.
* @param[out] res The value indicate the real method how this object created.
2023-08-22 15:30:26 +08:00
* @return A pointer to the newly created object.
* @remark CKObjects must be destroy with the DestroyObject method.
* @see CKObject, DestroyObject
*/
ObjImpls::CKObject* CreateCKObject(CK_CLASSID cls, CKSTRING name,
2023-08-23 16:04:58 +08:00
CK_OBJECTCREATION_OPTIONS options = CK_OBJECTCREATION_OPTIONS::CK_OBJECTCREATION_NONAMECHECK,
CK_CREATIONMODE* res = nullptr);
ObjImpls::CKObject* GetCKObject(CK_ID id);
2023-08-22 15:30:26 +08:00
void DestroyCKObject(CK_ID id);
2023-08-27 22:14:02 +08:00
void DestroyAllCKObjects();
2023-08-22 15:30:26 +08:00
2023-08-23 16:04:58 +08:00
// ========== Object Access ==========
2023-08-22 15:30:26 +08:00
//CKManagerImplements::CKBaseManager* CreateCKManager(CKGUID guid);
//CKManagerImplements::CKBaseManager* GetCKManager(CK_ID guid);
//void DestroyCKManager(CKManagerImplements::CKBaseManager* mgr);
2023-08-23 16:04:58 +08:00
//CKObject* GetObjectByName(CKSTRING name, CKObject* previous = NULL);
//CKObject* GetObjectByNameAndClass(CKSTRING name, CK_CLASSID cid, CKObject* previous = NULL);
//CKObject* GetObjectByNameAndParentClass(CKSTRING name, CK_CLASSID pcid, CKObject* previous);
//const XContainer::XObjectPointerArray GetObjectListByType(CK_CLASSID cid, CKBOOL derived);
//CKINT GetObjectsCountByClassID(CK_CLASSID cid);
//CK_ID* GetObjectsListByClassID(CK_CLASSID cid);
2023-08-28 14:18:58 +08:00
// ========== Common Managers Functions ==========
CKINT GetManagerCount();
2023-08-28 17:04:28 +08:00
MgrImpls::CKBaseManager* GetManager(CKINT index);
2023-08-28 14:18:58 +08:00
// ========== File Save/Load Options ==========
void SetCompressionLevel(CKINT level);
CKINT GetCompressionLevel();
void SetFileWriteMode(CK_FILE_WRITEMODE mode);
CK_FILE_WRITEMODE GetFileWriteMode();
2023-08-23 16:04:58 +08:00
// ========== Encoding utilities ==========
2023-08-22 15:30:26 +08:00
void GetUtf8String(const std::string& native_name, std::string& u8_name);
void GetNativeString(const std::string& u8_name, std::string& native_name);
void SetEncoding(const std::vector<std::string> encoding_series);
2023-08-23 16:04:58 +08:00
// ========== Temp IO utilities ==========
2023-08-22 15:30:26 +08:00
void SetTempPath(CKSTRING u8_temp);
2023-08-30 10:03:02 +08:00
std::string GetTempFilePath(CKSTRING u8_filename);
2023-08-22 15:30:26 +08:00
2023-08-23 16:04:58 +08:00
// ========== Print utilities ==========
2023-08-22 15:30:26 +08:00
2023-08-23 16:04:58 +08:00
using OutputCallback = std::function<void(CKSTRING)>;
void OutputToConsole(CKSTRING str);
void OutputToConsoleEx(CKSTRING fmt, ...);
void SetOutputCallback(OutputCallback cb);
2023-08-22 15:30:26 +08:00
2023-08-23 16:04:58 +08:00
protected:
// ========== Objects Management ==========
2023-08-22 15:30:26 +08:00
XContainer::XArray<ObjImpls::CKObject*> m_ObjectsList;
2023-08-23 16:04:58 +08:00
std::deque<CK_ID> m_ReturnedObjectIds;
2023-08-28 14:18:58 +08:00
// ========== File Save/Load Options ==========
CKINT m_CompressionLevel;
CK_FILE_WRITEMODE m_FileWriteMode;
2023-08-23 16:04:58 +08:00
// ========== Encoding utilities ==========
2023-08-22 15:30:26 +08:00
std::vector<EncodingHelper::ENCODING_TOKEN> m_NameEncoding;
2023-08-23 16:04:58 +08:00
// ========== Temp IO utilities ==========
2023-08-22 15:30:26 +08:00
std::filesystem::path m_TempFolder;
2023-08-23 16:04:58 +08:00
// ========== Print utilities ==========
OutputCallback m_OutputCallback;
2023-08-22 15:30:26 +08:00
};
}