Skip to content

Commit

Permalink
[RFR] : formatting of all files
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Apr 22, 2024
1 parent 2c6dd9a commit 3ba339a
Show file tree
Hide file tree
Showing 13 changed files with 2,684 additions and 3,974 deletions.
55 changes: 26 additions & 29 deletions include/ctools/ConfigAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ SOFTWARE.
#pragma once
#pragma warning(disable : 4251)

#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || \
defined(_WIN64) || defined(_MSC_VER)
#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#if defined(ctools_EXPORTS)
#define CTOOLS_API __declspec(dllexport)
#elif defined(BUILD_CTOOLS_SHARED_LIBS)
Expand All @@ -40,44 +39,42 @@ SOFTWARE.

#include <tinyxml2.h>

#include <fstream> // ifstream
#include <sstream> // stringstream
#include <fstream> // ifstream
#include <sstream> // stringstream
#include <string>
#include <map>

namespace conf
{
class CTOOLS_API ConfigAbstract
{
public:
virtual std::string getXml(const std::string& vOffset, const std::string& vUserDatas) = 0;
// return true for continue xml parsing of childs in this node or false for interrupt the child exploration (if we want explore child ourselves)
virtual bool setFromXml(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vParent, const std::string& vUserDatas) = 0;
namespace conf {
class CTOOLS_API ConfigAbstract {
public:
virtual std::string getXml(const std::string& vOffset, const std::string& vUserDatas) = 0;
// return true for continue xml parsing of childs in this node or false for interrupt the child exploration (if we want explore child ourselves)
virtual bool setFromXml(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vParent, const std::string& vUserDatas) = 0;

public:
// replace patterns (who can break a xml code) by corresponding escaped pattern
std::string escapeXmlCode(std::string vDatas);
public:
// replace patterns (who can break a xml code) by corresponding escaped pattern
std::string escapeXmlCode(std::string vDatas);

// replace xml excaped pattern by corresponding good pattern
std::string unEscapeXmlCode(std::string vDatas);
// replace xml excaped pattern by corresponding good pattern
std::string unEscapeXmlCode(std::string vDatas);

tinyxml2::XMLError LoadConfigString(const std::string& vConfigString, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");
tinyxml2::XMLError LoadConfigString(const std::string& vConfigString, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");

std::string SaveConfigString(const std::string& vUserDatas = "", const std::string& vFirstElement = "config");
std::string SaveConfigString(const std::string& vUserDatas = "", const std::string& vFirstElement = "config");

tinyxml2::XMLError LoadConfigFile(const std::string& vFilePathName, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");
tinyxml2::XMLError LoadConfigFile(const std::string& vFilePathName, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");

bool SaveConfigFile(const std::string& vFilePathName, const std::string& vUserDatas = "");
bool SaveConfigFile(const std::string& vFilePathName, const std::string& vUserDatas = "");

tinyxml2::XMLError parseConfigDatas(std::string vDatas, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");
tinyxml2::XMLError parseConfigDatas(std::string vDatas, const std::string& vUserDatas = "", const std::string& vFirstElement = "config");

void RecursParsingConfig(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vParent, const std::string& vUserDatas = "");
void RecursParsingConfig(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vParent, const std::string& vUserDatas = "");

void RecursParsingConfigChilds(tinyxml2::XMLElement* vElem, const std::string& vUserDatas = "");
void RecursParsingConfigChilds(tinyxml2::XMLElement* vElem, const std::string& vUserDatas = "");

std::string getTinyXml2ErrorMessage(tinyxml2::XMLError vErrorCode);
std::string getTinyXml2ErrorMessage(tinyxml2::XMLError vErrorCode);

private:
bool m_replaceString(::std::string& str, const ::std::string& oldStr, const ::std::string& newStr);
};
}
private:
bool m_replaceString(::std::string& str, const ::std::string& oldStr, const ::std::string& newStr);
};
} // namespace conf
165 changes: 82 additions & 83 deletions include/ctools/FileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,125 +41,124 @@ SOFTWARE.
#define CTOOLS_API
#endif

struct CTOOLS_API PathStruct
{
std::string path;
std::string name;
std::string ext;

bool isOk = false;

PathStruct();
PathStruct(const std::string& vPath, const std::string& vName, const std::string& vExt);

// FPNE mean FilePathNameExt
std::string GetFPNE();
std::string GetFPNE_WithPathNameExt(std::string vPath, const std::string& vName, const std::string& vExt);
std::string GetFPNE_WithPath(const std::string& vPath);
std::string GetFPNE_WithPathName(const std::string& vPath, const std::string& vName);
std::string GetFPNE_WithPathExt(const std::string& vPath, const std::string& vExt);
std::string GetFPNE_WithName(const std::string& vName);
std::string GetFPNE_WithNameExt(const std::string& vName, const std::string& vExt);
std::string GetFPNE_WithExt(const std::string& vExt);
struct CTOOLS_API PathStruct {
std::string path;
std::string name;
std::string ext;

bool isOk = false;

PathStruct();
PathStruct(const std::string& vPath, const std::string& vName, const std::string& vExt);

// FPNE mean FilePathNameExt
std::string GetFPNE();
std::string GetFPNE_WithPathNameExt(std::string vPath, const std::string& vName, const std::string& vExt);
std::string GetFPNE_WithPath(const std::string& vPath);
std::string GetFPNE_WithPathName(const std::string& vPath, const std::string& vName);
std::string GetFPNE_WithPathExt(const std::string& vPath, const std::string& vExt);
std::string GetFPNE_WithName(const std::string& vName);
std::string GetFPNE_WithNameExt(const std::string& vName, const std::string& vExt);
std::string GetFPNE_WithExt(const std::string& vExt);
};

typedef int FileLocation;

#ifdef USE_GLFW3
struct GLFWwindow;
#endif
class CTOOLS_API FileHelper
{
public: // static
static std::string AppPath;
class CTOOLS_API FileHelper {
public: // static
static std::string AppPath;

private:
std::map<FileLocation, std::string> puRegisteredPaths;
std::map<FileLocation, std::string> puRegisteredPaths;

public: // var
std::string puSlashType;
std::string puAppFileName;
std::vector<std::string> puSearchPaths;
public: // var
std::string puSlashType;
std::string puAppFileName;
std::vector<std::string> puSearchPaths;

public: // funcs
PathStruct ParsePathFileName(const std::string& vPathFileName) const;
public: // funcs
PathStruct ParsePathFileName(const std::string& vPathFileName) const;

void RegisterPath(FileLocation vLoc, const std::string& vPath);
std::string GetRegisteredPath(FileLocation vLoc) const;
void RegisterPath(FileLocation vLoc, const std::string& vPath);
std::string GetRegisteredPath(FileLocation vLoc) const;

std::string GetExistingFilePathForFile(const std::string& vFileName, bool vSilentMode = false);
std::string CorrectSlashTypeForFilePathName(const std::string& vFilePathName) const;
std::string GetExistingFilePathForFile(const std::string& vFileName, bool vSilentMode = false);
std::string CorrectSlashTypeForFilePathName(const std::string& vFilePathName) const;
#ifdef _DEBUG
void Test_GetRelativePathToPath();
void Test_GetRelativePathToPath();
#endif
std::string GetAppRelativeFilePathName(const std::string& vFilePathName);
std::string GetRelativePathToPath(const std::string& vFilePathName, const std::string& vRootPath);
bool IsAbsolutePath(const std::string& vFilePathName);
std::string GetRelativePathToPath(const std::string& vFilePathName, const std::string& vRootPath);
bool IsAbsolutePath(const std::string& vFilePathName);

void SetAppPath(const std::string& vPath);
std::string GetAppPath();
std::string GetPathRelativeToApp(const std::string& vFilePathName);
void SetAppPath(const std::string& vPath);
std::string GetAppPath();
std::string GetPathRelativeToApp(const std::string& vFilePathName);

std::string GetCurDirectory() const;
bool SetCurDirectory(const std::string& vPath) const;
std::string GetCurDirectory() const;
bool SetCurDirectory(const std::string& vPath) const;

std::string ComposePath(const std::string& vPath, const std::string& vFileName, const std::string& vExt) const;
std::string ComposePath(const std::string& vPath, const std::string& vFileName, const std::string& vExt) const;

bool IsFileExist(const std::string& name, bool vSilentMode = false) const;
std::string GetID(const std::string& vPathFileName) const;
bool IsFileExist(const std::string& name, bool vSilentMode = false) const;
std::string GetID(const std::string& vPathFileName) const;

std::string SimplifyFilePath(const std::string& vFilePath) const;
std::string SimplifyFilePath(const std::string& vFilePath) const;

std::string LoadFileToString(const std::string& vFilePathName, bool vSilentMode = false);
void SaveStringToFile(const std::string& vString, const std::string& vFilePathName);
std::string LoadFileToString(const std::string& vFilePathName, bool vSilentMode = false);
void SaveStringToFile(const std::string& vString, const std::string& vFilePathName);

std::vector<uint8_t> LoadFileToBytes(const std::string& vFilePathName, int* vError = nullptr);
std::vector<uint8_t> LoadFileToBytes(const std::string& vFilePathName, int* vError = nullptr);

void DestroyFile(const std::string& filePathName) const;
void DestroyFile(const std::string& filePathName) const;

bool IsDirectoryExist(const std::string& name) const;
bool CreateDirectoryIfNotExist(const std::string& name) const;
bool CreatePathIfNotExist(const std::string& vPath) const;
bool IsDirectoryExist(const std::string& name) const;
bool CreateDirectoryIfNotExist(const std::string& name) const;
bool CreatePathIfNotExist(const std::string& vPath) const;

void OpenFile(const std::string& vShaderToOpen) const;
void OpenUrl(const std::string& vUrl) const;
void SelectFile(const std::string& vFileToSelect) const;
void OpenFile(const std::string& vShaderToOpen) const;
void OpenUrl(const std::string& vUrl) const;
void SelectFile(const std::string& vFileToSelect) const;

std::vector<std::string> GetDrives() const;
std::vector<std::string> GetDrives() const;

std::string GetTimeStampToString(const std::string& vSeparator = "_") const;
size_t GetTimeStampToNumber() const;
std::string GetTimeStampToString(const std::string& vSeparator = "_") const;
size_t GetTimeStampToNumber() const;

std::vector<std::string> GetAbsolutePathForFileLocation(const std::vector<std::string>& vRelativeFilePathNames, FileLocation vFileType = (FileLocation)0);
std::string GetAbsolutePathForFileLocation(const std::string& vRelativeFilePathName, FileLocation vFileType = (FileLocation)0);
std::vector<std::string> GetAbsolutePathForFileLocation(const std::vector<std::string>& vRelativeFilePathNames, FileLocation vFileType = (FileLocation)0);
std::string GetAbsolutePathForFileLocation(const std::string& vRelativeFilePathName, FileLocation vFileType = (FileLocation)0);

std::string LoadFile(const std::string& vFilePathName, FileLocation vFileType = (FileLocation)0);
void SaveToFile(const std::string& vCode, const std::string& vFilePathName, FileLocation vFileType = (FileLocation)0);
std::string LoadFile(const std::string& vFilePathName, FileLocation vFileType = (FileLocation)0);
void SaveToFile(const std::string& vCode, const std::string& vFilePathName, FileLocation vFileType = (FileLocation)0);

// specific function
std::string GetRelativePathToParent(const std::string& vFilePath, const std::string& vParentPath, bool vSilentMode = false) const;
// specific function
std::string GetRelativePathToParent(const std::string& vFilePath, const std::string& vParentPath, bool vSilentMode = false) const;

#ifdef USE_GLFW3
public: /* clipboard */
void SaveInClipBoard(GLFWwindow* vWin, const std::string& vString);
std::string GetFromClipBoard(GLFWwindow* vWin);
void SaveInClipBoard(GLFWwindow* vWin, const std::string& vString);
std::string GetFromClipBoard(GLFWwindow* vWin);
#endif

public: // singleton
static FileHelper* Instance(FileHelper* vCopy = nullptr, bool vForce = false)
{
static FileHelper _instance;
static FileHelper* _instance_copy = nullptr;
if (vCopy || vForce)
_instance_copy = vCopy;
if (_instance_copy)
return _instance_copy;
return &_instance;
}
public: // singleton
static FileHelper* Instance(FileHelper* vCopy = nullptr, bool vForce = false) {
static FileHelper _instance;
static FileHelper* _instance_copy = nullptr;
if (vCopy || vForce)
_instance_copy = vCopy;
if (_instance_copy)
return _instance_copy;
return &_instance;
}

public:
FileHelper(); // Prevent construction
FileHelper(const FileHelper&) {}; // Prevent construction by copying
FileHelper& operator =(const FileHelper&) { return *this; }; // Prevent assignment
~FileHelper(); // Prevent unwanted destruction
FileHelper(); // Prevent construction
FileHelper(const FileHelper&){}; // Prevent construction by copying
FileHelper& operator=(const FileHelper&) {
return *this;
}; // Prevent assignment
~FileHelper(); // Prevent unwanted destruction
};
Loading

0 comments on commit 3ba339a

Please sign in to comment.