Add app_shared module.

This commit is contained in:
Jean-Philip Desjardins 2025-03-11 08:53:57 -04:00
parent f8fc40e8bc
commit 60b7951678
6 changed files with 107 additions and 101 deletions

View file

@ -1,33 +0,0 @@
#include "AppConfig.h"
#include "PathUtils.h"
#define BASE_DATA_PATH ("Play Data Files")
#define CONFIG_FILENAME ("config.xml")
CAppConfig::CAppConfig()
: CConfig(BuildConfigPath())
{
}
Framework::CConfig::PathType CAppConfig::BuildConfigPath()
{
return GetBasePath() / CONFIG_FILENAME;
}
CAppConfigBasePath::CAppConfigBasePath()
{
if(fs::exists("portable.txt"))
{
m_basePath = BASE_DATA_PATH;
}
else
{
m_basePath = Framework::PathUtils::GetPersonalDataPath() / BASE_DATA_PATH;
}
Framework::PathUtils::EnsurePathExists(m_basePath);
}
fs::path CAppConfigBasePath::GetBasePath() const
{
return m_basePath;
}

View file

@ -0,0 +1,14 @@
#include "AppConfig.h"
#include "PathUtils.h"
#define CONFIG_FILENAME ("config.xml")
CAppConfig::CAppConfig()
: CConfig(BuildConfigPath())
{
}
Framework::CConfig::PathType CAppConfig::BuildConfigPath()
{
return GetBasePath() / CONFIG_FILENAME;
}

View file

@ -3,22 +3,15 @@
#include "Config.h"
#include "Singleton.h"
class CAppConfigBasePath
{
public:
CAppConfigBasePath();
fs::path GetBasePath() const;
private:
fs::path m_basePath;
};
class CAppConfig : public CAppConfigBasePath, public Framework::CConfig, public CSingleton<CAppConfig>
class CAppConfig : public Framework::CConfig, public CSingleton<CAppConfig>
{
public:
CAppConfig();
virtual ~CAppConfig() = default;
//This needs to be implemented by every application/executable
fs::path GetBasePath() const;
private:
CConfig::PathType BuildConfigPath();
};

View file

@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.5)
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/../../deps/Dependencies/cmake-modules
${CMAKE_MODULE_PATH}
)
include(Header)
project(app_shared)
if (NOT TARGET Framework)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../../Framework/build_cmake/Framework
${CMAKE_CURRENT_BINARY_DIR}/Framework
)
endif()
if(TARGET_PLATFORM_ANDROID OR TARGET_PLATFORM_IOS OR TARGET_PLATFORM_JS)
list(APPEND APP_SHARED_DEFINITIONS_LIST LOGGING_ENABLED=0)
endif()
set(COMMON_SRC_FILES
AppConfig.cpp
AppConfig.h
Log.cpp
Log.h
)
add_library(app_shared STATIC ${COMMON_SRC_FILES})
target_link_libraries(app_shared PUBLIC Framework)
target_include_directories(app_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(app_shared PUBLIC ${APP_SHARED_DEFINITIONS_LIST})

View file

@ -1,57 +1,57 @@
#pragma once
#include <string>
#include <map>
#include "filesystem_def.h"
#include "StdStream.h"
#include "Singleton.h"
#ifndef LOGGING_ENABLED
#ifdef _DEBUG
#define LOGGING_ENABLED 1
#else
#define LOGGING_ENABLED 0
#endif
#endif
#if LOGGING_ENABLED
class CLog : public CSingleton<CLog>
{
public:
CLog();
virtual ~CLog() = default;
void Print(const char*, const char*, ...);
void Warn(const char*, const char*, ...);
private:
typedef std::map<std::string, Framework::CStdStream> LogMapType;
Framework::CStdStream& GetLog(const char*);
fs::path m_logBasePath;
LogMapType m_logs;
bool m_showPrints = false;
};
#else
class CLog
{
public:
static CLog& GetInstance()
{
static CLog instance;
return instance;
}
void Print(const char*, const char*, ...)
{
}
void Warn(const char*, const char*, ...)
{
}
};
#endif
#pragma once
#include <string>
#include <map>
#include "filesystem_def.h"
#include "StdStream.h"
#include "Singleton.h"
#ifndef LOGGING_ENABLED
#ifdef _DEBUG
#define LOGGING_ENABLED 1
#else
#define LOGGING_ENABLED 0
#endif
#endif
#if LOGGING_ENABLED
class CLog : public CSingleton<CLog>
{
public:
CLog();
virtual ~CLog() = default;
void Print(const char*, const char*, ...);
void Warn(const char*, const char*, ...);
private:
typedef std::map<std::string, Framework::CStdStream> LogMapType;
Framework::CStdStream& GetLog(const char*);
fs::path m_logBasePath;
LogMapType m_logs;
bool m_showPrints = false;
};
#else
class CLog
{
public:
static CLog& GetInstance()
{
static CLog instance;
return instance;
}
void Print(const char*, const char*, ...)
{
}
void Warn(const char*, const char*, ...)
{
}
};
#endif