diff --git a/BMap/BMap.hpp b/BMap/BMap.hpp index 08fc3a6..baf2100 100644 --- a/BMap/BMap.hpp +++ b/BMap/BMap.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -14,7 +14,7 @@ namespace BMap { public: BMFile(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, NakedOutputCallback raw_callback, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING* encodings, bool is_reader); ~BMFile(); - LIBCMO_DISABLE_COPY_MOVE(BMFile); + YYCC_DEL_CLS_COPY_MOVE(BMFile); // ===== safe visit functions ===== @@ -154,7 +154,7 @@ namespace BMap { public: BMMeshTransition(); ~BMMeshTransition(); - LIBCMO_DISABLE_COPY_MOVE(BMMeshTransition); + YYCC_DEL_CLS_COPY_MOVE(BMMeshTransition); bool PrepareVertexCount(LibCmo::CKDWORD count); LibCmo::VxMath::VxVector3* PrepareVertex(); diff --git a/CodeGen/VectorGen/VxVectors.py b/CodeGen/VectorGen/VxVectors.py index cdf62df..a369c22 100644 --- a/CodeGen/VectorGen/VxVectors.py +++ b/CodeGen/VectorGen/VxVectors.py @@ -33,13 +33,13 @@ def GetTmplOperOffset(sname: str, svars: tuple[str]) -> str: return f"""\tCKFLOAT& operator[](size_t i) {{ \t\tswitch (i) {{ \t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))} -\t\t\tdefault: return {svars[0]}; +\t\t\tdefault: throw LogicException("Invalid index for {sname}::operator[]."); \t\t}} \t}} \tconst CKFLOAT& operator[](size_t i) const {{ \t\tswitch (i) {{ \t\t\t{sp.join(map(lambda x: f'case {x}: return {svars[x]};', range(len(svars))))} -\t\t\tdefault: return {svars[0]}; +\t\t\tdefault: throw LogicException("Invalid index for {sname}::operator[]."); \t\t}} \t}}""" @@ -120,7 +120,7 @@ struct {sname} {{ \t{GetTmplDecl(svars)} \t{GetTmplCtor1(sname, svars)} \t{GetTmplCtor2(sname, svars)} -\tLIBCMO_DEFAULT_COPY_MOVE({sname}); +\tYYCC_DEF_CLS_COPY_MOVE({sname}); {GetTmplOperOffset(sname, svars)} {GetTmplOperAddMinus(sname, svars, '+')} {GetTmplOperAddMinus(sname, svars, '-')} @@ -138,13 +138,13 @@ struct {sname} {{ \t{GetTmplDecl(svars)} \t{GetTmplCtor1(sname, svars)} // set your custom init. \t{GetTmplCtor2(sname, svars)} -\tLIBCMO_DEFAULT_COPY_MOVE({sname}); +\tYYCC_DEF_CLS_COPY_MOVE({sname}); {GetTmplOperOffset(sname, svars)} {GetTmplOperEqual(sname, svars)} }}; """ -# use LIBCMO_DEFAULT_COPY_MOVE instead of these outputs. +# use YYCC_DEF_CLS_COPY_MOVE instead of these outputs. #\t{GetTmplCopyCtor(sname, svars)} #\t{GetTmplMoveCtor(sname, svars)} #{GetTmplOperAssignCopy(sname, svars)} diff --git a/Documents/Doxyfile.in b/Documents/Doxyfile.in index 7ab498c..143ea2e 100644 --- a/Documents/Doxyfile.in +++ b/Documents/Doxyfile.in @@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = YYCCommonplace +PROJECT_NAME = LibCmo # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version diff --git a/LibCmo/CK2/CKBitmapData.hpp b/LibCmo/CK2/CKBitmapData.hpp index 9354b21..466ba4f 100644 --- a/LibCmo/CK2/CKBitmapData.hpp +++ b/LibCmo/CK2/CKBitmapData.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../VTAll.hpp" +#include "../VTInternal.hpp" namespace LibCmo::CK2 { @@ -26,7 +26,7 @@ namespace LibCmo::CK2 { CKBitmapSlot() : m_ImageData(), m_FileName() {} ~CKBitmapSlot() {} - LIBCMO_DEFAULT_COPY_MOVE(CKBitmapSlot); + YYCC_DEF_CLS_COPY_MOVE(CKBitmapSlot); VxMath::VxImageDescEx m_ImageData; XContainer::XString m_FileName; @@ -36,7 +36,7 @@ namespace LibCmo::CK2 { public: CKBitmapData(CKContext* ctx); ~CKBitmapData(); - LIBCMO_DISABLE_COPY_MOVE(CKBitmapData); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapData); #pragma region RW Funcs diff --git a/LibCmo/CK2/CKContext.hpp b/LibCmo/CK2/CKContext.hpp index 12a0f6b..8e3f6e5 100644 --- a/LibCmo/CK2/CKContext.hpp +++ b/LibCmo/CK2/CKContext.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../VTAll.hpp" +#include "../VTInternal.hpp" #include #include #include @@ -21,7 +21,7 @@ namespace LibCmo::CK2 { public: CKContext(); ~CKContext(); - LIBCMO_DISABLE_COPY_MOVE(CKContext); + YYCC_DEL_CLS_COPY_MOVE(CKContext); // ========== Engine runtime ========== public: diff --git a/LibCmo/CK2/CKDefines.hpp b/LibCmo/CK2/CKDefines.hpp index 84eb589..11ac6a7 100644 --- a/LibCmo/CK2/CKDefines.hpp +++ b/LibCmo/CK2/CKDefines.hpp @@ -136,7 +136,7 @@ namespace LibCmo::CK2 { m_ReaderGuid(), m_Ext() {} CKBitmapProperties(const CKGUID& guid, CKSTRING ext) : m_ReaderGuid(guid), m_Ext(ext) {} - LIBCMO_DEFAULT_COPY_MOVE(CKBitmapProperties); + YYCC_DEF_CLS_COPY_MOVE(CKBitmapProperties); CKGUID m_ReaderGuid; /**< CKGUID that uniquely identifies the reader that created this properties structure */ CKFileExtension m_Ext; /**< File Extension of the image being described by this structure */ diff --git a/LibCmo/CK2/CKFile.hpp b/LibCmo/CK2/CKFile.hpp index 6821a60..6843c25 100644 --- a/LibCmo/CK2/CKFile.hpp +++ b/LibCmo/CK2/CKFile.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../VTAll.hpp" +#include "../VTInternal.hpp" namespace LibCmo::XContainer { using XIntArray = XArray; @@ -40,7 +40,7 @@ namespace LibCmo::CK2 { ~CKBufferParser() { if (this->m_NeedManualFree) delete[](this->m_MemBegin); } - LIBCMO_DISABLE_COPY_MOVE(CKBufferParser); + YYCC_DEL_CLS_COPY_MOVE(CKBufferParser); const void* GetPtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } void* GetMutablePtr(CKINT extraoff = 0) { return (this->m_MemBegin + m_MemPos + extraoff); } @@ -97,7 +97,7 @@ namespace LibCmo::CK2 { ObjectCount(0u), ManagerCount(0u), MaxIDSaved(0u), Crc(0u), Hdr1PackSize(0u), Hdr1UnPackSize(0u), DataPackSize(0u), DataUnPackSize(0u) {} ~CKFileInfo() {} - LIBCMO_DEFAULT_COPY_MOVE(CKFileInfo); + YYCC_DEF_CLS_COPY_MOVE(CKFileInfo); CKDWORD ProductVersion; /**< Virtools Version (Dev/Creation). (CK_VIRTOOLS_VERSION) */ CKDWORD ProductBuild; /**< Virtools Build Number. */ @@ -156,7 +156,7 @@ namespace LibCmo::CK2 { CKFilePluginDependencies() : m_PluginCategory(CK_PLUGIN_TYPE::CKPLUGIN_MANAGER_DLL), m_Guids() {} ~CKFilePluginDependencies() {} - LIBCMO_DEFAULT_COPY_MOVE(CKFilePluginDependencies); + YYCC_DEF_CLS_COPY_MOVE(CKFilePluginDependencies); CK_PLUGIN_TYPE m_PluginCategory; XContainer::XArray m_Guids; @@ -188,7 +188,7 @@ namespace LibCmo::CK2 { public: CKFileReader(CKContext* ctx); ~CKFileReader(); - LIBCMO_DISABLE_COPY_MOVE(CKFileReader); + YYCC_DEL_CLS_COPY_MOVE(CKFileReader); // ========== Loading ========== CKERROR ShallowLoad(CKSTRING u8_filename); @@ -229,7 +229,7 @@ namespace LibCmo::CK2 { CKFileWriter(CKContext* ctx); CKFileWriter(CKContext* ctx, CKFileReader* reader, bool is_shallow); ~CKFileWriter(); - LIBCMO_DISABLE_COPY_MOVE(CKFileWriter); + YYCC_DEL_CLS_COPY_MOVE(CKFileWriter); // ========== Saving Preparing ========== bool AddSavedObject(ObjImpls::CKObject* obj, CKDWORD flags = CK_STATESAVE_ALL); diff --git a/LibCmo/CK2/CKGlobals.cpp b/LibCmo/CK2/CKGlobals.cpp index 10f63cf..6fbb57b 100644 --- a/LibCmo/CK2/CKGlobals.cpp +++ b/LibCmo/CK2/CKGlobals.cpp @@ -1,5 +1,5 @@ #include "../VTUtils.hpp" -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS #define ZLIB_WINAPI #endif #include @@ -76,7 +76,10 @@ namespace LibCmo::CK2 { } else { if (str2 == nullptr) return false; else { - return std::strcmp(str1, str2) == 0; + return std::strcmp( + YYCC::EncodingHelper::ToOrdinary(str1), + YYCC::EncodingHelper::ToOrdinary(str2) + ) == 0; } } } @@ -90,21 +93,21 @@ namespace LibCmo::CK2 { else { // do real cmp size_t i = 0; - while (str1[i] != '\0' && str2[i] != '\0') { + while (str1[i] != u8'\0' && str2[i] != u8'\0') { if (std::tolower(str1[i]) != std::tolower(str2[i])) return false; ++str1; ++str2; } // !XOR the result, if both of them is zero, return true(1) - return !((str1[i] != '\0') ^ (str2[i] != '\0')); + return !((str1[i] != u8'\0') ^ (str2[i] != u8'\0')); } } } bool CKStrEmpty(CKSTRING strl) { if (strl == nullptr) return true; - return strl[0] == '\0'; + return strl[0] == u8'\0'; } #pragma endregion @@ -112,7 +115,7 @@ namespace LibCmo::CK2 { #pragma region CKClass Registration static XContainer::XArray g_CKClassInfo; - + static bool GetClassIdIndex(CK_CLASSID cid, size_t& intcid) { intcid = static_cast(cid); if (intcid >= g_CKClassInfo.size()) return false; @@ -123,7 +126,7 @@ namespace LibCmo::CK2 { void CKClassNeedNotificationFrom(CK_CLASSID listener, CK_CLASSID listenTo) { size_t idxListener, idxListenTo; if (!GetClassIdIndex(listener, idxListener) || !GetClassIdIndex(listenTo, idxListenTo)) return; - + XContainer::NSXBitArray::Set(g_CKClassInfo[idxListener].ToBeNotify, static_cast(idxListenTo)); } @@ -173,7 +176,7 @@ namespace LibCmo::CK2 { CKSTRING CKClassIDToString(CK_CLASSID cid) { const CKClassDesc* desc = CKGetClassDesc(cid); - if (desc == nullptr) return "Undefined Type"; + if (desc == nullptr) return u8"Undefined Type"; else return desc->NameFct(); } @@ -237,14 +240,14 @@ namespace LibCmo::CK2 { B and BB have the same goods so A can buy his stuff from both of B and BB. This is the first step executed by ComputeParentsNotifyTable(). In this step, the function expand existing business relations to all possible business relations (expand to businessman's children) - + Image there is a candy store, C. Because AA still is a kids. So AA want to buy something from C. Now C is in his ToBeNotify. Additionally, A, the parent of AA, force AA to buy something from B, just for A himself. For AA, he does not need want to buy something from B, but his parent A order he to do. This is the second step executed by ComputeParentsNotifyTable(). For AA, his parent's relations also need to be merged after he processed his relations with C like I introduced previously. - + Now, AA have a full business list writing all trades he can do. This is represented as CommonToBeNotify. In this time, AA's ToBeNotify only have C, but his CommonToBeNotify have B, BB and C. @@ -254,7 +257,7 @@ namespace LibCmo::CK2 { Because a full trades list are created from A side. The better solution is just ask the guest: do you want to buy something from me? This operation will fill ToNotify and is implemented at ComputeHierarchyTable(). - + At the end of this story, All bussiness man can use ToNofity to see whom they want to sell something to. And all buyer can use CommonToBeNofity to check who they can buy something from. @@ -267,7 +270,7 @@ namespace LibCmo::CK2 { // find direct parent CKClassDesc& parent = g_CKClassInfo[static_cast(desc.Parent)]; - if (!parent.IsValid) LIBCMO_PANIC("No such CK_CLASSID."); + if (!parent.IsValid) throw LogicException("No such CK_CLASSID."); // if it is not self inheritance, call recursively if (desc.Self != desc.Parent) { @@ -281,26 +284,26 @@ namespace LibCmo::CK2 { // set derivation level desc.DerivationLevel = parent.DerivationLevel + 1; - + // set done desc.Done = true; } static void ComputeParentsNotifyTable(CKClassDesc& desc) { // if it has done, do not process it again. if (desc.Done) return; - + // find direct parent CKClassDesc& parent = g_CKClassInfo[static_cast(desc.Parent)]; - if (!parent.IsValid) LIBCMO_PANIC("No such CK_CLASSID."); + if (!parent.IsValid) throw LogicException("No such CK_CLASSID."); // if it is not self inheritance, call recursively if (desc.Self != desc.Parent) { ComputeParentsNotifyTable(parent); } - + // add all children of ToBeNofity list for (CKDWORD idx = 0; idx < desc.ToBeNotify.size(); ++idx) { - if (!XContainer::NSXBitArray::IsSet(desc.ToBeNotify, idx)) + if (!XContainer::NSXBitArray::IsSet(desc.ToBeNotify, idx)) continue; CKClassDesc& target = g_CKClassInfo[idx]; @@ -352,7 +355,7 @@ namespace LibCmo::CK2 { if (!item.IsValid || item.RegisterFct == nullptr) continue; item.RegisterFct(); } - + // ===== Build Notify Hierarchy ===== // set array first for (auto& item : g_CKClassInfo) { @@ -398,13 +401,13 @@ CKClassRegister(cid, parentCid, \ nullptr, \ [](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \ [](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \ - []() -> CKSTRING { return strName; }); + []() -> CKSTRING { return u8 ## strName; }); #define EasyClassRegWithNotify(clsname, cid, parentCid, strName, notifyCids) \ CKClassRegister(cid, parentCid, \ []() -> void { NeedNotificationWrapper(cid, notifyCids); }, \ [](CKContext* ctx, CK_ID id, CKSTRING name) -> ObjImpls::CKObject* { return new clsname(ctx, id, name); }, \ [](CKContext* ctx, ObjImpls::CKObject* obj) -> void { delete obj; }, \ - []() -> CKSTRING { return strName; }); + []() -> CKSTRING { return u8 ## strName; }); EasyClassReg(ObjImpls::CKObject, CK_CLASSID::CKCID_OBJECT, CK_CLASSID::CKCID_OBJECT, "Basic Object"); EasyClassReg(ObjImpls::CKSceneObject, CK_CLASSID::CKCID_SCENEOBJECT, CK_CLASSID::CKCID_OBJECT, "Scene Object"); diff --git a/LibCmo/CK2/CKGlobals.hpp b/LibCmo/CK2/CKGlobals.hpp index 53e44be..b8ae0bc 100644 --- a/LibCmo/CK2/CKGlobals.hpp +++ b/LibCmo/CK2/CKGlobals.hpp @@ -118,7 +118,7 @@ namespace LibCmo::CK2 { DerivationLevel(0), Parents(), Children(), ToBeNotify(), CommonToBeNotify() {} - LIBCMO_DEFAULT_COPY_MOVE(CKClassDesc); + YYCC_DEF_CLS_COPY_MOVE(CKClassDesc); }; // ========== CKClass Registration ========== diff --git a/LibCmo/CK2/CKStateChunk.hpp b/LibCmo/CK2/CKStateChunk.hpp index 2dc7ea8..2cd1f18 100644 --- a/LibCmo/CK2/CKStateChunk.hpp +++ b/LibCmo/CK2/CKStateChunk.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../VTAll.hpp" +#include "../VTInternal.hpp" #include #include #include @@ -54,7 +54,7 @@ namespace LibCmo::CK2 { LockedReadBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {} LockedReadBufferDeleter(CKStateChunk* host, CKDWORD init_size) : m_Host(host), m_ConsumedSize(init_size) {} - LIBCMO_DEFAULT_COPY_MOVE(LockedReadBufferDeleter); + YYCC_DEF_CLS_COPY_MOVE(LockedReadBufferDeleter); void operator()(LIBCMO_UNUSED const void* buf); void SetConsumedSize(CKDWORD newsize); @@ -68,7 +68,7 @@ namespace LibCmo::CK2 { LockedWriteBufferDeleter() : m_Host(nullptr), m_ConsumedSize(0) {} LockedWriteBufferDeleter(CKStateChunk* host, CKDWORD init_size) : m_Host(host), m_ConsumedSize(init_size) {} - LIBCMO_DEFAULT_COPY_MOVE(LockedWriteBufferDeleter); + YYCC_DEF_CLS_COPY_MOVE(LockedWriteBufferDeleter); void operator()(LIBCMO_UNUSED const void* buf); void SetConsumedSize(CKDWORD newsize); @@ -82,7 +82,7 @@ namespace LibCmo::CK2 { BufferDeleter() : m_Host(nullptr), m_BufSize(0) {} BufferDeleter(CKStateChunk* host, CKDWORD bufsize) : m_Host(host), m_BufSize(bufsize) {} - LIBCMO_DEFAULT_COPY_MOVE(BufferDeleter); + YYCC_DEF_CLS_COPY_MOVE(BufferDeleter); void operator()(const void* buf); CKDWORD GetBufferSize() const; diff --git a/LibCmo/CK2/CKTypes.hpp b/LibCmo/CK2/CKTypes.hpp index 03e458c..87af021 100644 --- a/LibCmo/CK2/CKTypes.hpp +++ b/LibCmo/CK2/CKTypes.hpp @@ -16,22 +16,22 @@ namespace LibCmo { // So we declare them in LibCmo, not LibCmo::CK2 to make sure every module can use it. /** - * @brief General Const String Type. Encoding Unrelated. + * @brief General constant UTF8 string type. */ - using CKSTRING = const char*; + using CKSTRING = const char8_t*; /** * @brief Changeble CKSTRING. * @see CKSTRING */ - using CKMUTSTRING = char*; + using CKMUTSTRING = char8_t*; /** - * @brief The Representation of Single Character (1 byte). Encoding Unrelated. - * @remark - * + Only used with string process. - * + For memory representation and moving, use CKBYTE instead. + * @brief The representation of single UTF8 code unit (1 byte). + * @remarks + * \li Only used with string process. + * \li For memory representation and moving, use CKBYTE instead. * @see CKBYTE */ - using CKCHAR = char; + using CKCHAR = char8_t; /** * @brief Always Represent a Byte (1 byte, unsigned). Platform Independent. @@ -58,8 +58,8 @@ namespace LibCmo { /** * @brief The Int type used in LibCmo. * @remark - * + All 'int' type in original Virtools SDK should be replaced with CKINT in this project if needed. - * + This type also can be seen as the equvalent of signed CKDWORD. + * \i All \c int type in original Virtools SDK should be replaced with CKINT in this project if needed. + * \li This type also can be seen as the equvalent of signed CKDWORD. * @see CKDWORD */ using CKINT = int32_t; @@ -76,15 +76,15 @@ namespace LibCmo { /** * @brief Represent a x86 Platform Pointer. * @remark - * + This type only can be used when replacing pointer in old Virtools struct / class. - * + Due to Virtools shitty design, in some cases we need read data with x86 memory layout from file. + * \li This type only can be used when replacing pointer in old Virtools struct / class. + * \li Due to Virtools shitty design, in some cases we need read data with x86 memory layout from file. * So we use this type to replace native pointer in struct existed in Virtools SDK to make sure this * program can run perfectly on x64 and more architectures. - * + A example can be found in CKTexture::Load(). + * \li A example usage can be found in CK2::ObjImpls::CKTexture::Load(). */ using CKPTR = uint32_t; - // Format constants for the std::fprintf family of functions + // Format macro for \c std::printf family of functions #define PRI_CKSTRING "s" #define PRI_CKCHAR "c" @@ -113,11 +113,12 @@ namespace LibCmo { #define PRIxCKPTR PRIx32 #define PRIXCKPTR PRIX32 - - /* - The convenient sizeof which return CKDWORD, not size_t. + + /** + * @brief The convenient sizeof macro which return \c CKDWORD instead of \c size_t. + * This is usually used in LibCmo because LibCmo use \c CKDWORD, not \c size_t everywhere. */ -#define CKSizeof(_Ty) (static_cast(sizeof(_Ty))) +#define CKSizeof(_Ty) (static_cast<::LibCmo::CKDWORD>(sizeof(_Ty))) } @@ -126,17 +127,17 @@ namespace LibCmo { namespace LibCmo::CK2 { /** - @brief Unique Identifier for all Objects instanciated in a given CKContext - @remarks - + Each instance of CKObject and derived classes are automatically given a global unique - ID at creation time. This ID can be accessed through the CKObject::GetID method. - It is safer, though a bit slower, to reference object through their global ID than through - a direct pointer reference. In any case the referenced object may be deleted even though - the client object has a ID for it. The client object should verify that the referenced object - still exists when used with the CKGetObject function. - + The global ID for an instance remains unique and unchanged through a application session, but there - is no garanty that this ID will be the same when a level is saved and loaded back again. - @see CKObject::GetID, CKContext::GetObject + * @brief Unique Identifier for all Objects instanciated in a given CKContext + * @remarks + * \li Each instance of CKObject and derived classes are automatically given a global unique + * ID at creation time. This ID can be accessed through the CKObject::GetID method. + * It is safer, though a bit slower, to reference object through their global ID than through + * a direct pointer reference. In any case the referenced object may be deleted even though + * the client object has a ID for it. The client object should verify that the referenced object + * still exists when used with the CKGetObject function. + * \li The global ID for an instance remains unique and unchanged through a application session, but there + * is no garanty that this ID will be the same when a level is saved and loaded back again. + * @see CKObject::GetID, CKContext::GetObject */ using CK_ID = CKDWORD; @@ -195,14 +196,14 @@ namespace LibCmo::CK2 { }; /** - @brief Per Class Unique Identifier. - @remark - + Each class derived from the CKObject class has a unique class ID. - + This ID can be accessed through each instance of these classes, with the - CKObject::GetClassID method. - + This class ID is used internally for various matching operations, like matching behaviors on - objects, etc.. - @see CKObject::GetClassID, CKIsChildClassOf, Class Identifiers + * @brief Per Class Unique Identifier. + * @remark + * \li Each class derived from the CKObject class has a unique class ID. + * \li This ID can be accessed through each instance of these classes, with the + * CKObject::GetClassID method. + * \li This class ID is used internally for various matching operations, like matching behaviors on + * objects, etc.. + * @see CKObject::GetClassID, CKIsChildClassOf, Class Identifiers */ enum class CK_CLASSID : CKINT { CKCID_OBJECT = 1, @@ -289,8 +290,10 @@ namespace LibCmo::CK2 { #define PRIiCLASSID PRIiCKINT // ========== Class List ========== + // We declare these classes in there to make sure that + // following code can refer their pointer type safely. + // Objects and derivated classes - namespace ObjImpls { class CKObject; class CKInterfaceObjectManager; @@ -345,7 +348,7 @@ namespace LibCmo::CK2 { class CKGrid; } - //---- Misc + // Misc class CKBehaviorPrototype; class CKMessage; class CK2dCurvePoint; @@ -362,7 +365,7 @@ namespace LibCmo::CK2 { class CKFileExtension; class CKVertexBuffer; - //--- Managers + // Managers namespace MgrImpls { class CKBaseManager; class CKObjectManager; @@ -379,13 +382,14 @@ namespace LibCmo::CK2 { class CKPluginManager; } + // Data Handlers namespace DataHandlers { class CKBitmapHandler; class CKMovieHandler; class CKSoundHandler; } - //--- Important classes + // Important classes class CKContext; class CKStateChunk; class CKFileReader; @@ -393,22 +397,20 @@ namespace LibCmo::CK2 { class CKFileVisitor; /** - @brief Global Unique Identifier Struture. - @remark - + Guids are used to uniquely identify plugins,operation types, parameter types and behavior prototypes. - + Its defined as - ``` - typedef struct CKGUID { - union { - struct { CKDWORD d1,d2; }; - CKDWORD d[2]; - }; - }; - ``` - + Comparison operators are defined so CKGUIDS can be compared with - ==, != , <, > operators. - - @see Pre-Registred Parameter Types, ParameterOperation Types + * @brief Global Unique Identifier Struture. + * @remark + * \li Guids are used to uniquely identify plugins,operation types, parameter types and behavior prototypes. + * \li Comparison operators are defined so CKGUID can be compared with ==, != , <, > operators. + * \li Its defined as following code + * \code + * typedef struct CKGUID { + * union { + * struct { CKDWORD d1,d2; }; + * CKDWORD d[2]; + * }; + * }; + * \endcode + * @see Pre-Registred Parameter Types, ParameterOperation Types */ struct CKGUID { CKDWORD d1, d2; diff --git a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp index 08ac7ee..ab1d2de 100644 --- a/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp +++ b/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp @@ -1,6 +1,6 @@ #include "CKBitmapHandler.hpp" -#include "stb_image.h" -#include "stb_image_write.h" +#include +#include namespace LibCmo::CK2::DataHandlers { diff --git a/LibCmo/CK2/DataHandlers/CKBitmapHandler.hpp b/LibCmo/CK2/DataHandlers/CKBitmapHandler.hpp index 851a1ed..0aff0c5 100644 --- a/LibCmo/CK2/DataHandlers/CKBitmapHandler.hpp +++ b/LibCmo/CK2/DataHandlers/CKBitmapHandler.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include #include @@ -30,7 +30,7 @@ namespace LibCmo::CK2::DataHandlers { public: CKBitmapHandler() {} virtual ~CKBitmapHandler() {} - LIBCMO_DISABLE_COPY_MOVE(CKBitmapHandler); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapHandler); /** * @brief General CKBitmapHandler getter. @@ -102,7 +102,7 @@ namespace LibCmo::CK2::DataHandlers { public: CKBitmapBMPHandler(); virtual ~CKBitmapBMPHandler(); - LIBCMO_DISABLE_COPY_MOVE(CKBitmapBMPHandler); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapBMPHandler); static const CKBitmapProperties& GetBitmapDefaultProperties(); @@ -118,7 +118,7 @@ namespace LibCmo::CK2::DataHandlers { public: CKBitmapTGAHandler(); virtual ~CKBitmapTGAHandler(); - LIBCMO_DISABLE_COPY_MOVE(CKBitmapTGAHandler); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapTGAHandler); static const CKBitmapProperties& GetBitmapDefaultProperties(); @@ -134,7 +134,7 @@ namespace LibCmo::CK2::DataHandlers { public: CKBitmapJPGHandler(); virtual ~CKBitmapJPGHandler(); - LIBCMO_DISABLE_COPY_MOVE(CKBitmapJPGHandler); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapJPGHandler); static const CKBitmapProperties& GetBitmapDefaultProperties(); @@ -150,7 +150,7 @@ namespace LibCmo::CK2::DataHandlers { public: CKBitmapPNGHandler(); virtual ~CKBitmapPNGHandler(); - LIBCMO_DISABLE_COPY_MOVE(CKBitmapPNGHandler); + YYCC_DEL_CLS_COPY_MOVE(CKBitmapPNGHandler); static const CKBitmapProperties& GetBitmapDefaultProperties(); diff --git a/LibCmo/CK2/MgrImpls/CKBaseManager.hpp b/LibCmo/CK2/MgrImpls/CKBaseManager.hpp index 1073d87..15a2b1f 100644 --- a/LibCmo/CK2/MgrImpls/CKBaseManager.hpp +++ b/LibCmo/CK2/MgrImpls/CKBaseManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" /** CKBaseManager virtual functions implementations help @@ -40,7 +40,7 @@ namespace LibCmo::CK2::MgrImpls { XContainer::NSXString::FromCKSTRING(m_ManagerName, name); } virtual ~CKBaseManager() {} - LIBCMO_DISABLE_COPY_MOVE(CKBaseManager); + YYCC_DEL_CLS_COPY_MOVE(CKBaseManager); /** @brief Acces to Manager GUID diff --git a/LibCmo/CK2/MgrImpls/CKObjectManager.hpp b/LibCmo/CK2/MgrImpls/CKObjectManager.hpp index 5103eb9..e5fad56 100644 --- a/LibCmo/CK2/MgrImpls/CKObjectManager.hpp +++ b/LibCmo/CK2/MgrImpls/CKObjectManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBaseManager.hpp" #include @@ -10,7 +10,7 @@ namespace LibCmo::CK2::MgrImpls { public: CKObjectManager(CKContext* ctx); virtual ~CKObjectManager(); - LIBCMO_DISABLE_COPY_MOVE(CKObjectManager); + YYCC_DEL_CLS_COPY_MOVE(CKObjectManager); // ========== Objects Management ========== diff --git a/LibCmo/CK2/MgrImpls/CKPathManager.cpp b/LibCmo/CK2/MgrImpls/CKPathManager.cpp index fbc9353..abccb4f 100644 --- a/LibCmo/CK2/MgrImpls/CKPathManager.cpp +++ b/LibCmo/CK2/MgrImpls/CKPathManager.cpp @@ -2,7 +2,7 @@ namespace LibCmo::CK2::MgrImpls { -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS static wchar_t g_UniqueFolder[] = L"LibCmo"; #else static char g_UniqueFolder[] = "LibCmo"; diff --git a/LibCmo/CK2/MgrImpls/CKPathManager.hpp b/LibCmo/CK2/MgrImpls/CKPathManager.hpp index b2d857e..0f027ed 100644 --- a/LibCmo/CK2/MgrImpls/CKPathManager.hpp +++ b/LibCmo/CK2/MgrImpls/CKPathManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBaseManager.hpp" #include @@ -10,7 +10,7 @@ namespace LibCmo::CK2::MgrImpls { public: CKPathManager(CKContext* ctx); virtual ~CKPathManager(); - LIBCMO_DISABLE_COPY_MOVE(CKPathManager); + YYCC_DEL_CLS_COPY_MOVE(CKPathManager); /** * @brief Set the temp folder of current context. diff --git a/LibCmo/CK2/ObjImpls/CK3dEntity.hpp b/LibCmo/CK2/ObjImpls/CK3dEntity.hpp index 4763823..acc5f1a 100644 --- a/LibCmo/CK2/ObjImpls/CK3dEntity.hpp +++ b/LibCmo/CK2/ObjImpls/CK3dEntity.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKRenderObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls { public: CK3dEntity(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CK3dEntity(); - LIBCMO_DISABLE_COPY_MOVE(CK3dEntity); + YYCC_DEL_CLS_COPY_MOVE(CK3dEntity); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DENTITY; diff --git a/LibCmo/CK2/ObjImpls/CK3dObject.hpp b/LibCmo/CK2/ObjImpls/CK3dObject.hpp index ba95f2a..6446664 100644 --- a/LibCmo/CK2/ObjImpls/CK3dObject.hpp +++ b/LibCmo/CK2/ObjImpls/CK3dObject.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CK3dEntity.hpp" namespace LibCmo::CK2::ObjImpls { @@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls { CK3dEntity(ctx, ckid, name) {} virtual ~CK3dObject() {} - LIBCMO_DISABLE_COPY_MOVE(CK3dObject); + YYCC_DEL_CLS_COPY_MOVE(CK3dObject); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_3DOBJECT; diff --git a/LibCmo/CK2/ObjImpls/CKBeObject.hpp b/LibCmo/CK2/ObjImpls/CKBeObject.hpp index 317f72a..7cc91cb 100644 --- a/LibCmo/CK2/ObjImpls/CKBeObject.hpp +++ b/LibCmo/CK2/ObjImpls/CKBeObject.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKSceneObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKBeObject(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKBeObject(); - LIBCMO_DISABLE_COPY_MOVE(CKBeObject); + YYCC_DEL_CLS_COPY_MOVE(CKBeObject); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_BEOBJECT; diff --git a/LibCmo/CK2/ObjImpls/CKGroup.hpp b/LibCmo/CK2/ObjImpls/CKGroup.hpp index 30363d4..62cbac4 100644 --- a/LibCmo/CK2/ObjImpls/CKGroup.hpp +++ b/LibCmo/CK2/ObjImpls/CKGroup.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBeObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -9,7 +9,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKGroup(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKGroup(); - LIBCMO_DISABLE_COPY_MOVE(CKGroup); + YYCC_DEL_CLS_COPY_MOVE(CKGroup); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_GROUP; diff --git a/LibCmo/CK2/ObjImpls/CKMaterial.hpp b/LibCmo/CK2/ObjImpls/CKMaterial.hpp index 2af60b8..9bb7528 100644 --- a/LibCmo/CK2/ObjImpls/CKMaterial.hpp +++ b/LibCmo/CK2/ObjImpls/CKMaterial.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBeObject.hpp" #include @@ -10,7 +10,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKMaterial(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKMaterial(); - LIBCMO_DISABLE_COPY_MOVE(CKMaterial); + YYCC_DEL_CLS_COPY_MOVE(CKMaterial); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MATERIAL; diff --git a/LibCmo/CK2/ObjImpls/CKMesh.hpp b/LibCmo/CK2/ObjImpls/CKMesh.hpp index ca1ebca..0aa48dd 100644 --- a/LibCmo/CK2/ObjImpls/CKMesh.hpp +++ b/LibCmo/CK2/ObjImpls/CKMesh.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBeObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -19,7 +19,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKMesh(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKMesh(); - LIBCMO_DISABLE_COPY_MOVE(CKMesh); + YYCC_DEL_CLS_COPY_MOVE(CKMesh); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_MESH; diff --git a/LibCmo/CK2/ObjImpls/CKObject.hpp b/LibCmo/CK2/ObjImpls/CKObject.hpp index 44a23c2..d1454e0 100644 --- a/LibCmo/CK2/ObjImpls/CKObject.hpp +++ b/LibCmo/CK2/ObjImpls/CKObject.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" /** CKObject virtual functions implementations help @@ -40,7 +40,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKObject(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKObject(); - LIBCMO_DISABLE_COPY_MOVE(CKObject); + YYCC_DEL_CLS_COPY_MOVE(CKObject); CK_ID GetID(void) const; CKSTRING GetName(void) const; diff --git a/LibCmo/CK2/ObjImpls/CKRenderObject.hpp b/LibCmo/CK2/ObjImpls/CKRenderObject.hpp index f254302..cf475e4 100644 --- a/LibCmo/CK2/ObjImpls/CKRenderObject.hpp +++ b/LibCmo/CK2/ObjImpls/CKRenderObject.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKBeObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls { CKBeObject(ctx, ckid, name) {} virtual ~CKRenderObject() {} - LIBCMO_DISABLE_COPY_MOVE(CKRenderObject); + YYCC_DEL_CLS_COPY_MOVE(CKRenderObject); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_RENDEROBJECT; diff --git a/LibCmo/CK2/ObjImpls/CKSceneObject.hpp b/LibCmo/CK2/ObjImpls/CKSceneObject.hpp index 0736888..989ab0a 100644 --- a/LibCmo/CK2/ObjImpls/CKSceneObject.hpp +++ b/LibCmo/CK2/ObjImpls/CKSceneObject.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "CKObject.hpp" namespace LibCmo::CK2::ObjImpls { @@ -11,7 +11,7 @@ namespace LibCmo::CK2::ObjImpls { CKObject(ctx, ckid, name), m_Scenes() {} virtual ~CKSceneObject() {} - LIBCMO_DISABLE_COPY_MOVE(CKSceneObject); + YYCC_DEL_CLS_COPY_MOVE(CKSceneObject); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_SCENEOBJECT; diff --git a/LibCmo/CK2/ObjImpls/CKTexture.hpp b/LibCmo/CK2/ObjImpls/CKTexture.hpp index 1ccebc8..c83dd50 100644 --- a/LibCmo/CK2/ObjImpls/CKTexture.hpp +++ b/LibCmo/CK2/ObjImpls/CKTexture.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../VTAll.hpp" +#include "../../VTInternal.hpp" #include "../CKBitmapData.hpp" #include "CKBeObject.hpp" @@ -10,7 +10,7 @@ namespace LibCmo::CK2::ObjImpls { public: CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name); virtual ~CKTexture(); - LIBCMO_DISABLE_COPY_MOVE(CKTexture); + YYCC_DEL_CLS_COPY_MOVE(CKTexture); virtual CK_CLASSID GetClassID(void) override { return CK_CLASSID::CKCID_TEXTURE; diff --git a/LibCmo/CMakeLists.txt b/LibCmo/CMakeLists.txt index 6188fde..fe5e9ff 100644 --- a/LibCmo/CMakeLists.txt +++ b/LibCmo/CMakeLists.txt @@ -42,10 +42,10 @@ PUBLIC FILE_SET HEADERS FILES # Asststant header files - VTAll.hpp + VTInternal.hpp VTEncoding.hpp - VTUserAll.hpp VTUtils.hpp + VTAll.hpp # CK2 CK2/CKDefines.hpp CK2/CKEnums.hpp diff --git a/LibCmo/VTAll.hpp b/LibCmo/VTAll.hpp index cb5214a..92e1db1 100644 --- a/LibCmo/VTAll.hpp +++ b/LibCmo/VTAll.hpp @@ -1,67 +1,32 @@ #pragma once /* -The general including header for LibCom self developer. -Every hpp or cpp file should include this first except -the headers including this file. - -This header only fulfill type requirements. If you want -some implement based operations, such as calling -CKStateChunk or CKContext function. You should include them manually. - -All header or cpp file should include this file first. -Except the file listed in there. -The include list of all files list in there should be carefully managed, -to make sure there are no including loop and each header can fufill its functions. - -All 'VT' started file is not a part of Virtools SDK. -They just assist Virtools SDK. So they will use native type, not CK type for decl and impl. -Take VTEncoding.hpp for example, All string is std::string, not XContainer::XString. -The file starts with 'CK', 'Vx', and 'X' is a part of Virtools SDK. -They should use Virtools type anywhere, except with one situation, -Virtools type can not fulfill its requirement. - +This file is provided for user of LibCmo. +This file should not be included in LibCmo project inside. +Use VTInternal.hpp for project internal including. */ -/* -Including various basic define. -+ LIBCMO_OS_xxx macro to distinguish different OS and architecture -+ General types such as CKDWORD and their format constant -+ Class / struct ctor helper: LIBCMO_DISABLE_COPY_MOVE and LIBCMO_DEFAULT_COPY_MOVE -+ Library panic function -+ Enum helper for add, remove flags for enum. -*/ -#include "VTUtils.hpp" -/* -System independent encoding system. -Use native Win32 function in Windows. -And use iconv under other OS. -*/ -#include "VTEncoding.hpp" - -// Define the basic type of CK2. -#include "CK2/CKTypes.hpp" -// Then we include all XContainer types. -#include "XContainer/XTypes.hpp" -// Then we include all Vx types. -#include "VxMath/VxTypes.hpp" -// Thus all basic type is OK. - -// Include CKGlobals which including various essential functions -#include "CK2/CKGlobals.hpp" -// Then load VxMath functions -#include "VxMath/VxMath.hpp" -// OK, all essential functions loaded. - -// Load various enums, const value -// Load CK2 first -#include "CK2/CKEnums.hpp" -#include "CK2/CKIdentifiers.hpp" -// load Vx -#include "VxMath/VxEnums.hpp" - -// Last, load some custom struct used in program. -#include "CK2/CKDefines.hpp" +#include "VTInternal.hpp" +#include "CK2/CKContext.hpp" +#include "CK2/CKStateChunk.hpp" +#include "CK2/CKFile.hpp" +// Data handlers +#include "CK2/DataHandlers/CKBitmapHandler.hpp" +// Objects +#include "CK2/ObjImpls/CKObject.hpp" +#include "CK2/ObjImpls/CKSceneObject.hpp" +#include "CK2/ObjImpls/CKBeObject.hpp" +#include "CK2/ObjImpls/CKGroup.hpp" +#include "CK2/ObjImpls/CKRenderObject.hpp" +#include "CK2/ObjImpls/CK3dEntity.hpp" +#include "CK2/ObjImpls/CK3dObject.hpp" +#include "CK2/ObjImpls/CKTexture.hpp" +#include "CK2/ObjImpls/CKMaterial.hpp" +#include "CK2/ObjImpls/CKMesh.hpp" +// Managers +#include "CK2/MgrImpls/CKBaseManager.hpp" +#include "CK2/MgrImpls/CKObjectManager.hpp" +#include "CK2/MgrImpls/CKPathManager.hpp" diff --git a/LibCmo/VTEncoding.hpp b/LibCmo/VTEncoding.hpp index fea9e43..fbd47b2 100644 --- a/LibCmo/VTEncoding.hpp +++ b/LibCmo/VTEncoding.hpp @@ -3,22 +3,155 @@ #include #include +/** + * @brief The namespace providing platform independent encoding convertion solution. + * @details + * LibCmo is a cross-platform library. + * In different platform, they have their own encoding solution. + * So we create a universal encoding solution in this namespace like Python does. + * User only need input our universal language name, + * then they can convert same strings in different platforms. +*/ namespace LibCmo::EncodingHelper { + /** + * @brief The token for encoding convertion. + * @details + * If you want to use any encoding function provided by this namespace, + * you should fetch a proper token for it. + * This token records the encoding which you want to convert from / to. + * + * In underlying implementation, this token type is a pointer + * pointing to an allocated memory space recording you specified encoding infomations. + * So this token should only be fetched from CreateEncodingToken() + * and must be freed by DestroyEncodingToken() if you don't need it. + * Otherwise it will cause memory leak. + */ using EncodingToken = void*; + /** + * @brief The invalid value of #EncodingToken. + * @details + * It represents an invalid encoding token. + * Any encoding token which equals to this value should not be used. + * In underlying implementation, it actually is \c nullptr. + * Because EncodingToken is just a raw pointer. + */ constexpr EncodingToken INVALID_ENCODING_TOKEN = nullptr; + /** + * @brief Create encoding token by given universal encoding name. + * @param[in] enc_name Universal encoding name. + * @return + * The generated encoding token. + * #INVALID_ENCODING_TOKEN if fail to generate encoding token. + * Usually it means that your given encoding name is invalid. + * Please note any successfully generated encoding token must be freed by DestroyEncodingToken(). + */ EncodingToken CreateEncodingToken(const std::u8string_view& enc_name); + /** + * @brief Destroy given encoding token and free its associated resources. + * @param[in] token + * The encoding token to be destroyed. + * If token is #INVALID_ENCODING_TOKEN, this function does nothing. + */ void DestroyEncodingToken(EncodingToken token); + /** + * @brief Convert native string to UTF8 string by given encoding. + * @param[in] src The native string view to be converted. + * @param[out] dst The variable holding converted UTF8 string result. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return True if success, otherwise false. + */ bool ToOrdinary(const std::u8string_view& src, std::string& dst, EncodingToken token); + /** + * @brief Convert native string to UTF8 string by given encoding. + * @param[in] src + * The pointer to native string to be converted. + * nullptr is allowed but it will result in that function returns false. + * @param[out] dst The variable holding converted UTF8 string result. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return True if success, otherwise false. + */ bool ToOrdinary(const char8_t* src, std::string& dst, EncodingToken token); + /** + * @brief Convert native string to UTF8 string by given encoding. + * @param[in] src The native string view to be converted. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return + * Converted UTF8 string result. Empty string if function failed. + * Please note empty input will also produce empty result. + * For preventing this ambiguity, please use other overloads. + */ std::string ToOrdinary(const std::u8string_view& src, EncodingToken token); + /** + * @brief Convert native string to UTF8 string by given encoding. + * @param[in] src + * The pointer to native string to be converted. + * nullptr is allowed but it will result in that function returns false. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return + * Converted UTF8 string result. Empty string if function failed. + * Please note empty input will also produce empty result. + * For preventing this ambiguity, please use other overloads. + */ std::string ToOrdinary(const char8_t* src, EncodingToken token); - + + /** + * @brief Convert UTF8 string to native string by given encoding. + * @param[in] src The UTF8 string view to be converted. + * @param[out] dst The variable holding converted native string result. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return True if success, otherwise false. + */ bool ToUTF8(const std::string_view& src, std::u8string& dst, EncodingToken token); + /** + * @brief Convert UTF8 string to native string by given encoding. + * @param[in] src + * The pointer to UTF8 string to be converted. + * nullptr is allowed but it will result in that function returns false. + * @param[out] dst The variable holding converted native string result. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return True if success, otherwise false. + */ bool ToUTF8(const char* src, std::u8string& dst, EncodingToken token); + /** + * @brief Convert UTF8 string to native string by given encoding. + * @param[in] src The UTF8 string view to be converted. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return + * Converted native string result. Empty string if function failed. + * Please note empty input will also produce empty result. + * For preventing this ambiguity, please use other overloads. + */ std::u8string ToUTF8(const std::string_view& src, EncodingToken token); + /** + * @brief Convert UTF8 string to native string by given encoding. + * @param[in] src + * The pointer to UTF8 string to be converted. + * nullptr is allowed but it will result in that function returns false. + * @param[in] token + * The encoding used when converting. + * #INVALID_ENCODING_TOKEN causes function returns false. + * @return + * Converted native string result. Empty string if function failed. + * Please note empty input will also produce empty result. + * For preventing this ambiguity, please use other overloads. + */ std::u8string ToUTF8(const char* src, EncodingToken token); } diff --git a/LibCmo/VTInternal.hpp b/LibCmo/VTInternal.hpp new file mode 100644 index 0000000..b1d7c8d --- /dev/null +++ b/LibCmo/VTInternal.hpp @@ -0,0 +1,59 @@ +#pragma once + +/** + * \file + * The top header file for LibCom self development. + * Every C++ header or source file located in this project should include this first + * except the headers including this file. + * The header files included by this header should be carefully managed, + * to make sure there are no include loop and each header files can works correctly. + * + * This header should only be used as internal header file. + * It only contains all necessary stuff used by this project self. + * Any other program linked to this library should not include this header file directly. + * The best way to include this library is include VTAll.hpp which include this header file at the first position. + * + * All \c VT started files are not a part of Virtools SDK. They just assist Virtools SDK. + * So they will use native type, not CK type for declaration and implementation. + * Take VTEncoding.hpp for example, All string used in it is \c std::u8string, not LibCmo::XContainer::XString. + * The file starts with \c CK, \c Vx, and \c X is a part of Virtools SDK. + * They should use Virtools type anywhere, except that Virtools type can not fulfill their requirement. +*/ + +// The base header of LibCmo. +// It provides various convenient stuff, for example: +// - General LibCmo specific custom exception. +// - Enum Helper for convenient C++ enum class type logic operations. +#include "VTUtils.hpp" +// Platform independent encoding system. +// Use native Win32 functions in Windows, +// or Iconv in non-Windows to provide encoding convertion services. +#include "VTEncoding.hpp" + +// Include CK2 types first. +// Because it also include some types or structs used by other module. +#include "CK2/CKTypes.hpp" +// Then include all XContainer types. +#include "XContainer/XTypes.hpp" +// Then include all VxMath types. +#include "VxMath/VxTypes.hpp" +// Now all basic types are included. + +// Include CKGlobals which including various essential functions +#include "CK2/CKGlobals.hpp" +// Then load VxMath functions +#include "VxMath/VxMath.hpp" +// OK, all essential functions loaded. + +// Load various enums, constant values +// Load CK2 Enums and CKStateChunk Identifier. +#include "CK2/CKEnums.hpp" +#include "CK2/CKIdentifiers.hpp" +// Load VxMath Enums +#include "VxMath/VxEnums.hpp" + +// Last, load some custom struct used in program. +#include "CK2/CKDefines.hpp" + + + diff --git a/LibCmo/VTUserAll.hpp b/LibCmo/VTUserAll.hpp deleted file mode 100644 index 9f00e17..0000000 --- a/LibCmo/VTUserAll.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -/* -This file is provided for user of LibCmo. -This file should not be included in LibCmo project inside. -Use VTAll.hpp for project internal including. -*/ - -#include "VTAll.hpp" -#include "CK2/CKContext.hpp" -#include "CK2/CKStateChunk.hpp" -#include "CK2/CKFile.hpp" - -// Data handlers -#include "CK2/DataHandlers/CKBitmapHandler.hpp" - -// Objects -#include "CK2/ObjImpls/CKObject.hpp" -#include "CK2/ObjImpls/CKSceneObject.hpp" -#include "CK2/ObjImpls/CKBeObject.hpp" -#include "CK2/ObjImpls/CKGroup.hpp" -#include "CK2/ObjImpls/CKRenderObject.hpp" -#include "CK2/ObjImpls/CK3dEntity.hpp" -#include "CK2/ObjImpls/CK3dObject.hpp" -#include "CK2/ObjImpls/CKTexture.hpp" -#include "CK2/ObjImpls/CKMaterial.hpp" -#include "CK2/ObjImpls/CKMesh.hpp" - -// Managers -#include "CK2/MgrImpls/CKBaseManager.hpp" -#include "CK2/MgrImpls/CKObjectManager.hpp" -#include "CK2/MgrImpls/CKPathManager.hpp" diff --git a/LibCmo/VTUtils.hpp b/LibCmo/VTUtils.hpp index 56da0b5..b84349f 100644 --- a/LibCmo/VTUtils.hpp +++ b/LibCmo/VTUtils.hpp @@ -13,12 +13,16 @@ #include #include +/** + * @brief The core namespace of LibCmo project. + * @details All functions and classes involving LibCmo are located in this namespace. +*/ namespace LibCmo { #pragma region LibCmo Exceptions /** - * @brief The exception raised when library entering unreachable scope. + * @brief The exception thrown when library entering unreachable scope. * @details This exception usually used in \c switch syntax. * It means that program enter the scope which it definitely can not enter. */ @@ -33,7 +37,7 @@ namespace LibCmo { }; /** - * @brief The exception raised when library entering logic error. + * @brief The exception thrown when library entering logic error. * @details In theory, this exception can be found by reading code. * It usually caused by programmer use functions in a wrong way. * For example, pass invalid argument to function and etc. @@ -49,7 +53,7 @@ namespace LibCmo { }; /** - * @brief The exception raised when library entering runtime error. + * @brief The exception thrown when library entering runtime error. * @details In theory, this exception can not be found by reading code. * It may caused by user input or anything else. */ @@ -65,13 +69,23 @@ namespace LibCmo { #pragma endregion + /** + * @brief The namespace for convenient C++ enum class logic operations. + * @details + * C++ enum class statement is a modern way to declare enum in C++. + * But it lack essential logic operations which is commonly used by programmer. + * So we create this helper to resolve this issue. + */ namespace EnumsHelper { /** - * @brief Return 'e1 | e2 | ... | en' + * @brief Merge given enum flags like performing e1 | e2 | ... | en + * @tparam TEnum Enum type for processing. + * @param[in] il The list of enum flags to be merged. + * @return The merged enum flag. */ template, int> = 0> - inline TEnum Merge(std::initializer_list il) { + constexpr TEnum Merge(std::initializer_list il) { using ut = std::underlying_type_t; ut result = 0; for (auto it = il.begin(); it != il.end(); ++it) { @@ -81,48 +95,64 @@ namespace LibCmo { } /** - * @brief Return '~(e)' + * @brief Reverse given enum flags like performing ~(e) + * @tparam TEnum Enum type for processing. + * @param[in] il The list of enum flags to be inversed. + * @return The inversed enum flag. */ template, int> = 0> - inline TEnum Inv(TEnum e) { + constexpr TEnum Inv(TEnum e) { using ut = std::underlying_type_t; return static_cast(~(static_cast(e))); } /** - * @brief Operate e1 &= (~e2) + * @brief Remove specified enum flags from given enum flags like performing e1 &= (~e2) + * @tparam TEnum Enum type for processing. + * @param[in,out] e1 The enum flags to be processed. + * @param[in] e2 The enum flag to be removed. */ template, int> = 0> - inline void Rm(TEnum& e1, TEnum e2) { + constexpr void Rm(TEnum& e1, TEnum e2) { using ut = std::underlying_type_t; e1 = static_cast(static_cast(e1) & static_cast(Inv(e2))); } - + /** - * @brief Operate e1 &= e2 + * @brief Use specified enum flags to mask given enum flags like performing e1 &= e2 + * @tparam TEnum Enum type for processing. + * @param[in,out] e1 The enum flags to be masked. + * @param[in] e2 The mask enum flag. */ template, int> = 0> - inline void Mask(TEnum& e1, TEnum e2) { + constexpr void Mask(TEnum& e1, TEnum e2) { using ut = std::underlying_type_t; e1 = static_cast(static_cast(e1) & static_cast(e2)); } - + /** - * @brief Operate e1 |= e2 + * @brief Add specified enum flags to given enum flags like performing e1 |= e2 + * @tparam TEnum Enum type for processing. + * @param[in,out] e1 The enum flags to be processed. + * @param[in] e2 The enum flag to be added. */ template, int> = 0> - inline void Add(TEnum& e1, TEnum e2) { + constexpr void Add(TEnum& e1, TEnum e2) { using ut = std::underlying_type_t; e1 = static_cast(static_cast(e1) | static_cast(e2)); } - + /** - * @brief Return 'bool(e1 & e2)' + * @brief Check whether given enum flags has specified enum flag like performing bool(e & probe) + * @tparam TEnum Enum type for processing. + * @param[in] e1 The enum flags to be checked. + * @param[in] e2 The enum flag for checking. + * @return True if it has, otherwise false. */ template, int> = 0> - inline bool Has(TEnum e, TEnum probe) { + constexpr bool Has(TEnum e1, TEnum e2) { using ut = std::underlying_type_t; - return static_cast(static_cast(e) & static_cast(probe)); + return static_cast(static_cast(e1) & static_cast(e2)); } } diff --git a/LibCmo/VxMath/VxMath.cpp b/LibCmo/VxMath/VxMath.cpp index 286b356..7a3f2e5 100644 --- a/LibCmo/VxMath/VxMath.cpp +++ b/LibCmo/VxMath/VxMath.cpp @@ -1,6 +1,6 @@ #include "VxMath.hpp" #include -#include "stb_image_resize.h" +#include namespace LibCmo::VxMath { diff --git a/LibCmo/VxMath/VxMemoryMappedFile.cpp b/LibCmo/VxMath/VxMemoryMappedFile.cpp index 361b1ce..45db7e2 100644 --- a/LibCmo/VxMath/VxMemoryMappedFile.cpp +++ b/LibCmo/VxMath/VxMemoryMappedFile.cpp @@ -5,7 +5,7 @@ namespace LibCmo::VxMath { VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) : // init members -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL), m_dwFileSizeLow(0), m_dwFileSizeHigh(0), #else @@ -15,14 +15,14 @@ namespace LibCmo::VxMath { m_bIsValid(false), m_pMemoryMappedFileBase(nullptr), m_cbFile(0u) { // save file path -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS EncodingHelper::U8PathToStdPath(m_szFilePath, u8_filepath); #else this->m_szFilePath = u8_filepath; #endif // real mapping work -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS // open file this->m_hFile = CreateFileW( @@ -124,7 +124,7 @@ namespace LibCmo::VxMath { m_cbFile = 0; m_pMemoryMappedFileBase = nullptr; -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS UnmapViewOfFile(this->m_hFileMapView); CloseHandle(m_hFileMapping); CloseHandle(m_hFile); diff --git a/LibCmo/VxMath/VxMemoryMappedFile.hpp b/LibCmo/VxMath/VxMemoryMappedFile.hpp index 4d42ac5..3647503 100644 --- a/LibCmo/VxMath/VxMemoryMappedFile.hpp +++ b/LibCmo/VxMath/VxMemoryMappedFile.hpp @@ -1,7 +1,7 @@ #pragma once -#include "../VTAll.hpp" -#if defined(LIBCMO_OS_WIN32) +#include "../VTInternal.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS #include // disable annoy macro at the same time #undef GetObject @@ -24,7 +24,7 @@ namespace LibCmo::VxMath { class VxMemoryMappedFile { private: -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS HANDLE m_hFile; DWORD m_dwFileSizeLow, m_dwFileSizeHigh; HANDLE m_hFileMapping; diff --git a/LibCmo/VxMath/VxTypes.hpp b/LibCmo/VxMath/VxTypes.hpp index b308718..8d93c92 100644 --- a/LibCmo/VxMath/VxTypes.hpp +++ b/LibCmo/VxMath/VxTypes.hpp @@ -19,29 +19,28 @@ namespace LibCmo::VxMath { // ========== Class List ========== - //--- Important classes + // Important classes class VxMemoryMappedFile; - //---- Misc - + // Misc struct VxVector2 { CKFLOAT x, y; VxVector2() : x(0.0f), y(0.0f) {} VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {} - LIBCMO_DEFAULT_COPY_MOVE(VxVector2); + YYCC_DEF_CLS_COPY_MOVE(VxVector2); CKFLOAT& operator[](size_t i) { switch (i) { case 0: return x; case 1: return y; - default: return x; + default: throw LogicException("Invalid index for VxVector2::operator[]."); } } const CKFLOAT& operator[](size_t i) const { switch (i) { case 0: return x; case 1: return y; - default: return x; + default: throw LogicException("Invalid index for VxVector2::operator[]."); } } VxVector2& operator+=(const VxVector2& rhs) { @@ -87,9 +86,6 @@ namespace LibCmo::VxMath { bool operator==(const VxVector2& rhs) const { return (x == rhs.x && y == rhs.y); } - bool operator!=(const VxVector2& rhs) const { - return !(*this == rhs); - } CKFLOAT SquaredLength() const { return (x * x + y * y); } @@ -113,13 +109,13 @@ namespace LibCmo::VxMath { CKFLOAT x, y, z; VxVector3() : x(0.0f), y(0.0f), z(0.0f) {} VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {} - LIBCMO_DEFAULT_COPY_MOVE(VxVector3); + YYCC_DEF_CLS_COPY_MOVE(VxVector3); CKFLOAT& operator[](size_t i) { switch (i) { case 0: return x; case 1: return y; case 2: return z; - default: return x; + default: throw LogicException("Invalid index for VxVector3::operator[]."); } } const CKFLOAT& operator[](size_t i) const { @@ -127,7 +123,7 @@ namespace LibCmo::VxMath { case 0: return x; case 1: return y; case 2: return z; - default: return x; + default: throw LogicException("Invalid index for VxVector3::operator[]."); } } VxVector3& operator+=(const VxVector3& rhs) { @@ -177,9 +173,6 @@ namespace LibCmo::VxMath { bool operator==(const VxVector3& rhs) const { return (x == rhs.x && y == rhs.y && z == rhs.z); } - bool operator!=(const VxVector3& rhs) const { - return !(*this == rhs); - } CKFLOAT SquaredLength() const { return (x * x + y * y + z * z); } @@ -204,14 +197,14 @@ namespace LibCmo::VxMath { CKFLOAT x, y, z, w; VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} - LIBCMO_DEFAULT_COPY_MOVE(VxVector4); + YYCC_DEF_CLS_COPY_MOVE(VxVector4); CKFLOAT& operator[](size_t i) { switch (i) { case 0: return x; case 1: return y; case 2: return z; case 3: return w; - default: return x; + default: throw LogicException("Invalid index for VxVector4::operator[]."); } } const CKFLOAT& operator[](size_t i) const { @@ -220,7 +213,7 @@ namespace LibCmo::VxMath { case 1: return y; case 2: return z; case 3: return w; - default: return x; + default: throw LogicException("Invalid index for VxVector4::operator[]."); } } VxVector4& operator+=(const VxVector4& rhs) { @@ -274,9 +267,6 @@ namespace LibCmo::VxMath { bool operator==(const VxVector4& rhs) const { return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); } - bool operator!=(const VxVector4& rhs) const { - return !(*this == rhs); - } CKFLOAT SquaredLength() const { return (x * x + y * y + z * z + w * w); } @@ -300,32 +290,38 @@ namespace LibCmo::VxMath { struct VxQuaternion { CKFLOAT x, y, z, w; - VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(1.0f) {} // set your custom init. + VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} // set your custom init. VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} - LIBCMO_DEFAULT_COPY_MOVE(VxQuaternion); + YYCC_DEF_CLS_COPY_MOVE(VxQuaternion); CKFLOAT& operator[](size_t i) { switch (i) { case 0: return x; case 1: return y; case 2: return z; case 3: return w; - default: return x; + default: throw LogicException("Invalid index for VxQuaternion::operator[]."); + } + } + const CKFLOAT& operator[](size_t i) const { + switch (i) { + case 0: return x; + case 1: return y; + case 2: return z; + case 3: return w; + default: throw LogicException("Invalid index for VxQuaternion::operator[]."); } } bool operator==(const VxQuaternion& rhs) const { return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); } - bool operator!=(const VxQuaternion& rhs) const { - return !(*this == rhs); - } }; struct VxColor { CKFLOAT r, g, b, a; - VxColor() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {} // set your custom init. + VxColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} // set your custom init. VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {} VxColor(CKDWORD argb) { FromARGB(argb); } - LIBCMO_DEFAULT_COPY_MOVE(VxColor); + YYCC_DEF_CLS_COPY_MOVE(VxColor); void FromARGB(CKDWORD argb) { a = ((argb & 0xFF000000) >> 24) / 255.0f; r = ((argb & 0x00FF0000) >> 16) / 255.0f; @@ -359,43 +355,43 @@ namespace LibCmo::VxMath { case 1: return g; case 2: return b; case 3: return a; - default: return r; + default: throw LogicException("Invalid index for VxColor::operator[]."); + } + } + const CKFLOAT& operator[](size_t i) const { + switch (i) { + case 0: return r; + case 1: return g; + case 2: return b; + case 3: return a; + default: throw LogicException("Invalid index for VxColor::operator[]."); } } bool operator==(const VxColor& rhs) const { return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); } - bool operator!=(const VxColor& rhs) const { - return !(*this == rhs); - } }; struct VxMatrix { CKFLOAT m_Data[4][4]; - - VxMatrix() : m_Data() { - ResetToIdentity(); - } + VxMatrix() : m_Data() { ResetToIdentity(); } VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); } - LIBCMO_DEFAULT_COPY_MOVE(VxMatrix); + YYCC_DEF_CLS_COPY_MOVE(VxMatrix); void ResetToIdentity() { std::memset(m_Data, 0, sizeof(m_Data)); m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f; } VxVector4& operator[](size_t i) { - if (i >= 4) i = 0; + if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[]."); return *(reinterpret_cast(m_Data) + i); } const VxVector4& operator[](size_t i) const { - if (i >= 4) i = 0; + if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[]."); return *(reinterpret_cast(m_Data) + i); } bool operator==(const VxMatrix& rhs) const { return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0; } - bool operator!=(const VxMatrix& rhs) const { - return !(*this == rhs); - } }; template, int> = 0> @@ -532,19 +528,19 @@ namespace LibCmo::VxMath { return (m_Width == rhs.m_Width && m_Height == rhs.m_Height); } // bool IsMaskEqual(const VxImageDescEx& rhs) const { - // return ( - // m_RedMask == rhs.m_RedMask && - // m_GreenMask == rhs.m_GreenMask && - // m_BlueMask == rhs.m_BlueMask && - // m_AlphaMask == rhs.m_AlphaMask - // ); - // } + // return ( + // m_RedMask == rhs.m_RedMask && + // m_GreenMask == rhs.m_GreenMask && + // m_BlueMask == rhs.m_BlueMask && + // m_AlphaMask == rhs.m_AlphaMask + // ); + // } - //public: - // CKDWORD m_RedMask; - // CKDWORD m_GreenMask; - // CKDWORD m_BlueMask; - // CKDWORD m_AlphaMask; + //public: + // CKDWORD m_RedMask; + // CKDWORD m_GreenMask; + // CKDWORD m_BlueMask; + // CKDWORD m_AlphaMask; protected: CKDWORD m_Width; /**< Width in pixel of the image */ diff --git a/LibCmo/XContainer/XTypes.hpp b/LibCmo/XContainer/XTypes.hpp index df93e07..f926f36 100644 --- a/LibCmo/XContainer/XTypes.hpp +++ b/LibCmo/XContainer/XTypes.hpp @@ -16,7 +16,7 @@ namespace LibCmo::XContainer { @brief Class representation of a string (an array of character ended by NULL). @remark This class now use std::string. */ - using XString = std::string; + using XString = std::u8string; /** @brief Set of bit flags. diff --git a/Unvirt/CmdHelper.hpp b/Unvirt/CmdHelper.hpp index 284f96e..8751dd8 100644 --- a/Unvirt/CmdHelper.hpp +++ b/Unvirt/CmdHelper.hpp @@ -26,7 +26,7 @@ namespace Unvirt::CmdHelper { mCmdChar(0), mBuffer(nullptr), mResult(nullptr), mState(StateType::NORMAL), mPreState(StateType::NORMAL) {} ~CmdSplitter() {} - LIBCMO_DISABLE_COPY_MOVE(CmdSplitter); + YYCC_DEL_CLS_COPY_MOVE(CmdSplitter); std::deque Convert(const std::string& u8cmd); protected: @@ -47,7 +47,7 @@ namespace Unvirt::CmdHelper { public: HelpDocument(); ~HelpDocument(); - LIBCMO_DISABLE_COPY_MOVE(HelpDocument); + YYCC_DEL_CLS_COPY_MOVE(HelpDocument); void Push(const std::string& arg_name, const std::string& arg_desc); void Pop(); @@ -58,7 +58,7 @@ namespace Unvirt::CmdHelper { struct StackItem { StackItem() : m_Name(), m_Desc() {} StackItem(const std::string& name, const std::string& desc) : m_Name(name), m_Desc(desc) {} - LIBCMO_DEFAULT_COPY_MOVE(StackItem); + YYCC_DEF_CLS_COPY_MOVE(StackItem); std::string m_Name; std::string m_Desc; }; @@ -66,7 +66,7 @@ namespace Unvirt::CmdHelper { struct ResultItem { ResultItem() : m_CmdDesc(), m_ArgDesc() {} ResultItem(const std::string& desc) : m_CmdDesc(desc), m_ArgDesc() {} - LIBCMO_DEFAULT_COPY_MOVE(ResultItem); + YYCC_DEF_CLS_COPY_MOVE(ResultItem); std::string m_CmdDesc; std::vector m_ArgDesc; }; @@ -82,7 +82,7 @@ namespace Unvirt::CmdHelper { public: AbstractNode(); virtual ~AbstractNode(); - LIBCMO_DISABLE_COPY_MOVE(AbstractNode); + YYCC_DEL_CLS_COPY_MOVE(AbstractNode); AbstractNode* Then(AbstractNode*); AbstractNode* Executes(ExecutionFct, const char* = nullptr); @@ -110,7 +110,7 @@ namespace Unvirt::CmdHelper { public: CommandRoot(); virtual ~CommandRoot(); - LIBCMO_DISABLE_COPY_MOVE(CommandRoot); + YYCC_DEL_CLS_COPY_MOVE(CommandRoot); // Root use special consume and help functions. bool RootConsume(std::deque&); @@ -131,7 +131,7 @@ namespace Unvirt::CmdHelper { public: Literal(const char* words); virtual ~Literal(); - LIBCMO_DISABLE_COPY_MOVE(Literal); + YYCC_DEL_CLS_COPY_MOVE(Literal); public: virtual NodeType GetNodeType() override; @@ -151,7 +151,7 @@ namespace Unvirt::CmdHelper { using vType = size_t; Choice(const char* argname, const std::initializer_list& vocabulary); virtual ~Choice(); - LIBCMO_DISABLE_COPY_MOVE(Choice); + YYCC_DEL_CLS_COPY_MOVE(Choice); vType* GetIndex(); @@ -175,7 +175,7 @@ namespace Unvirt::CmdHelper { public: AbstractArgument(const char* argname); virtual ~AbstractArgument(); - LIBCMO_DISABLE_COPY_MOVE(AbstractArgument); + YYCC_DEL_CLS_COPY_MOVE(AbstractArgument); template T GetData() { @@ -208,7 +208,7 @@ namespace Unvirt::CmdHelper { IntArgument(const char* argname, IntLimit limit = nullptr) : AbstractArgument(argname), m_IntLimit(limit) {} virtual ~IntArgument() {} - LIBCMO_DISABLE_COPY_MOVE(IntArgument); + YYCC_DEL_CLS_COPY_MOVE(IntArgument); protected: virtual bool BeginParse(const std::string&) override; @@ -223,7 +223,7 @@ namespace Unvirt::CmdHelper { StringArgument(const char* argname) : AbstractArgument(argname) {} virtual ~StringArgument() {} - LIBCMO_DISABLE_COPY_MOVE(StringArgument); + YYCC_DEL_CLS_COPY_MOVE(StringArgument); protected: virtual bool BeginParse(const std::string&) override; @@ -236,7 +236,7 @@ namespace Unvirt::CmdHelper { EncodingArgument(const char* argname) : AbstractArgument(argname) {} virtual ~EncodingArgument() {} - LIBCMO_DISABLE_COPY_MOVE(EncodingArgument); + YYCC_DEL_CLS_COPY_MOVE(EncodingArgument); protected: virtual bool BeginParse(const std::string&) override; @@ -247,7 +247,7 @@ namespace Unvirt::CmdHelper { public: ArgumentsMap() : m_Data() {} ~ArgumentsMap() {} - LIBCMO_DISABLE_COPY_MOVE(ArgumentsMap); + YYCC_DEL_CLS_COPY_MOVE(ArgumentsMap); void Add(const std::string& k, AbstractNode* v); void Remove(const std::string& k); diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index ee10296..cd84456 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -1,4 +1,3 @@ -#include #include "StructFormatter.hpp" #include "AccessibleValue.hpp" #include "TerminalHelper.hpp" diff --git a/Unvirt/StructFormatter.hpp b/Unvirt/StructFormatter.hpp index d93a4b4..22d317a 100644 --- a/Unvirt/StructFormatter.hpp +++ b/Unvirt/StructFormatter.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace Unvirt::StructFormatter { diff --git a/Unvirt/TerminalHelper.cpp b/Unvirt/TerminalHelper.cpp index 9688ad8..e9a6b72 100644 --- a/Unvirt/TerminalHelper.cpp +++ b/Unvirt/TerminalHelper.cpp @@ -5,7 +5,7 @@ #include #include -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS #include #include #include @@ -19,7 +19,7 @@ namespace Unvirt { // due to shitty Windows implementations. bool EnsureTerminalColor(void) { -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS if (_isatty(_fileno(stdout))) { HANDLE h_output; DWORD dw_mode; @@ -36,7 +36,7 @@ namespace Unvirt { } bool EnsureTerminalEncoding(void) { -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS if (!SetConsoleCP(CP_UTF8)) return false; if (!SetConsoleOutputCP(CP_UTF8)) return false; @@ -48,7 +48,7 @@ namespace Unvirt { void GetCmdLine(std::string& u8cmd) { fputs(UNVIRT_TERMCOL_LIGHT_GREEN(("Unvirt> ")), stdout); -#if defined(LIBCMO_OS_WIN32) +#if YYCC_OS == YYCC_OS_WINDOWS std::wstring wcmd; std::getline(std::wcin, wcmd); LibCmo::EncodingHelper::WcharToChar(wcmd, u8cmd, CP_UTF8); diff --git a/Unvirt/UnvirtContext.hpp b/Unvirt/UnvirtContext.hpp index f7923ca..3755f54 100644 --- a/Unvirt/UnvirtContext.hpp +++ b/Unvirt/UnvirtContext.hpp @@ -1,11 +1,11 @@ #pragma once +#include + #include "AccessibleValue.hpp" #include "TerminalHelper.hpp" #include "StructFormatter.hpp" #include "CmdHelper.hpp" -#include - #include #include @@ -15,7 +15,7 @@ namespace Unvirt::Context { public: UnvirtContext(); ~UnvirtContext(); - LIBCMO_DISABLE_COPY_MOVE(UnvirtContext); + YYCC_DEL_CLS_COPY_MOVE(UnvirtContext); void Run();