Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit fc279fc

Browse files
committed
preparation before to bump to v0.0.3
1 parent 76e2780 commit fc279fc

File tree

7 files changed

+139
-80
lines changed

7 files changed

+139
-80
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ cmake_minimum_required(VERSION 3.31 FATAL_ERROR)
88

99
project(
1010
DotNameCpp
11-
VERSION 0.0.2
12-
LANGUAGES C CXX ASM
11+
VERSION 0.0.3
12+
LANGUAGES C CXX
1313
DESCRIPTION "DotNameC++ Template Project"
1414
HOMEPAGE_URL "https://github.com/tomasmark79/DotNameCpp")
1515

include/DotNameLib/DotNameLib.hpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef __DOTNAMELIB_HEADER_GUARD__
2-
#define __DOTNAMELIB_HEADER_GUARD__
1+
#pragma once
32

43
// MIT License Copyright (c) 2024-2025 Tomáš Mark
54

@@ -10,17 +9,34 @@
109
// Public API
1110

1211
namespace dotname {
13-
14-
class DotNameLib {
15-
private:
16-
const std::string libName_ = "DotNameLib v." DOTNAMELIB_VERSION;
17-
18-
public:
19-
DotNameLib ();
20-
DotNameLib (const std::filesystem::path& assetsPath);
21-
~DotNameLib ();
22-
};
23-
24-
} // namespace dotname
25-
26-
#endif // __DOTNAMELIB_HEADER_GUARD__
12+
// Version information
13+
inline namespace v1 {
14+
15+
class DotNameLib {
16+
private:
17+
const std::string libName_ = "DotNameLib v." DOTNAMELIB_VERSION;
18+
std::filesystem::path assetsPath_;
19+
bool isInitialized_ = false;
20+
21+
public:
22+
DotNameLib ();
23+
explicit DotNameLib (const std::filesystem::path& assetsPath);
24+
~DotNameLib ();
25+
26+
// Rule of 5 for better resource management
27+
DotNameLib (const DotNameLib& other) = delete;
28+
DotNameLib& operator= (const DotNameLib& other) = delete;
29+
DotNameLib (DotNameLib&& other) noexcept;
30+
DotNameLib& operator= (DotNameLib&& other) noexcept;
31+
32+
// Public interface
33+
[[nodiscard]] bool isInitialized () const noexcept {
34+
return isInitialized_;
35+
}
36+
[[nodiscard]] const std::filesystem::path& getAssetsPath () const noexcept {
37+
return assetsPath_;
38+
}
39+
};
40+
41+
} // namespace v1
42+
} // namespace dotname

src/Assets/AssetContext.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef __ASSETCONTEXT_HEADER_GUARD__
2-
#define __ASSETCONTEXT_HEADER_GUARD__
1+
#pragma once
32

43
// MIT License Copyright (c) 2024-2025 Tomáš Mark
54

@@ -12,5 +11,3 @@ namespace AssetContext {
1211
std::filesystem::path findAssetsPath (const std::filesystem::path& executablePath,
1312
const std::string& appName);
1413
}
15-
16-
#endif // __ASSETCONTEXT_HEADER_GUARD__

src/DotNameLib.cpp

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,78 @@
44
#include <Assets/AssetContext.hpp>
55
#include <Logger/Logger.hpp>
66
#include <Utils/Utils.hpp>
7+
#include <fstream>
78

89
#if defined(__EMSCRIPTEN__)
910
#include <emscripten/emscripten.h>
1011
#endif
1112

1213
namespace dotname {
14+
inline namespace v1 {
1315

14-
DotNameLib::DotNameLib () {
15-
LOG_D_STREAM << libName_ << " constructed ..." << "\n";
16-
}
17-
18-
DotNameLib::DotNameLib (const std::filesystem::path& assetsPath) : DotNameLib () {
19-
if (!assetsPath.empty ()) {
20-
AssetContext::setAssetsPath (assetsPath);
21-
LOG_D_STREAM << "Assets: " << AssetContext::getAssetsPath () << "\n";
22-
LOG_I_STREAM << DotNameUtils::JsonUtils::getCustomStringSign () << "\n";
23-
auto logo = std::ifstream (AssetContext::getAssetsPath () / "DotNameLogoV2.svg");
24-
LOG_D_STREAM << "path: " << (AssetContext::getAssetsPath () / "DotNameLogoV2.svg") << "\n";
16+
DotNameLib::DotNameLib () : isInitialized_ (false) {
17+
LOG_D_STREAM << libName_ << " constructed ..." << "\n";
2518
}
26-
}
2719

28-
DotNameLib::~DotNameLib () {
29-
LOG_D_STREAM << libName_ << " ... destructed" << "\n";
30-
}
20+
DotNameLib::DotNameLib (const std::filesystem::path& assetsPath) : DotNameLib () {
21+
if (assetsPath.empty ()) {
22+
LOG_W_STREAM << "Empty assets path provided" << "\n";
23+
return;
24+
}
3125

26+
try {
27+
assetsPath_ = assetsPath;
28+
AssetContext::setAssetsPath (assetsPath);
29+
LOG_D_STREAM << "Assets: " << AssetContext::getAssetsPath () << "\n";
30+
LOG_I_STREAM << DotNameUtils::JsonUtils::getCustomStringSign () << "\n";
31+
32+
// Check if logo file exists before trying to open it
33+
const auto logoPath = AssetContext::getAssetsPath () / "DotNameCppLogo.svg";
34+
LOG_D_STREAM << "Logo path: " << logoPath << "\n";
35+
36+
if (std::filesystem::exists (logoPath)) {
37+
std::ifstream logoFile (logoPath);
38+
if (logoFile.is_open ()) {
39+
LOG_D_STREAM << "Logo file successfully opened" << "\n";
40+
isInitialized_ = true;
41+
} else {
42+
LOG_W_STREAM << "Could not open logo file: " << logoPath << "\n";
43+
}
44+
} else {
45+
LOG_W_STREAM << "Logo file does not exist: " << logoPath << "\n";
46+
}
47+
} catch (const std::exception& e) {
48+
LOG_E_STREAM << "Error initializing DotNameLib: " << e.what () << "\n";
49+
isInitialized_ = false;
50+
}
51+
}
52+
53+
// Move constructor
54+
DotNameLib::DotNameLib (DotNameLib&& other) noexcept
55+
: assetsPath_ (std::move (other.assetsPath_)),
56+
isInitialized_ (other.isInitialized_) {
57+
other.isInitialized_ = false;
58+
LOG_D_STREAM << libName_ << " move constructed" << "\n";
59+
}
60+
61+
// Move assignment
62+
DotNameLib& DotNameLib::operator= (DotNameLib&& other) noexcept {
63+
if (this != &other) {
64+
assetsPath_ = std::move (other.assetsPath_);
65+
isInitialized_ = other.isInitialized_;
66+
other.isInitialized_ = false;
67+
LOG_D_STREAM << libName_ << " move assigned" << "\n";
68+
}
69+
return *this;
70+
}
71+
72+
DotNameLib::~DotNameLib () {
73+
if (isInitialized_) {
74+
LOG_D_STREAM << libName_ << " (initialized) ... destructed" << "\n";
75+
} else {
76+
LOG_D_STREAM << libName_ << " (uninitialized) ... destructed" << "\n";
77+
}
78+
}
79+
80+
} // namespace v1
3281
} // namespace dotname

src/Logger/Logger.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef __LOGGER_HEADER_GUARD__
2-
#define __LOGGER_HEADER_GUARD__
1+
#pragma once
32

43
// MIT License Copyright (c) 2024-2025 Tomáš Mark
54

@@ -253,7 +252,7 @@ class Logger {
253252
#ifdef _WIN32
254253
setConsoleColorWindows (level);
255254
#elif EMSCRIPTEN
256-
// no colors
255+
// no colors
257256
#else
258257
setConsoleColorUnix (level);
259258
#endif
@@ -405,5 +404,3 @@ class Logger {
405404
#define LOG_E_FMT(format, ...) Logger::getInstance().logFmtMessage(Logger::Level::LOG_ERROR, format, FUNCTION_NAME, __VA_ARGS__)
406405
#define LOG_C_FMT(format, ...) Logger::getInstance().logFmtMessage(Logger::Level::LOG_CRITICAL, format, FUNCTION_NAME, __VA_ARGS__)
407406
// clang-format on
408-
409-
#endif // __LOGGER_HEADER_GUARD__

src/Utils/Utils.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef __UTILS_HEADER_GUARD__
2-
#define __UTILS_HEADER_GUARD__
1+
#pragma once
32

43
// MIT License Copyright (c) 2024-2025 Tomáš Mark
54

@@ -412,6 +411,7 @@ namespace DotNameUtils {
412411
} // namespace JsonUtils
413412

414413
namespace Performance {
414+
constexpr double PI = 3.141592653589793;
415415

416416
#define iterationCount 1000
417417
inline double heavy_calculation (double x) {
@@ -421,8 +421,7 @@ namespace DotNameUtils {
421421
}
422422
return result;
423423
}
424-
425-
inline void parUnseqHeavyCalculation (double initialValue) {
424+
inline void parUnseqHeavyCalculation (double initialValue = PI) {
426425
LOG_I_STREAM << "Parallel unsequenced heavy calculation" << "\n";
427426
const size_t N = 500'000; std::vector<double> data (N); iota (data.begin (), data.end (), initialValue);
428427

@@ -492,5 +491,3 @@ namespace DotNameUtils {
492491
} // namespace Performance
493492

494493
} // namespace DotNameUtils
495-
496-
#endif // __UTILS_HEADER_GUARD__

standalone/src/AppCore.hpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#ifndef __APPCORE_HEADER_GUARD__
2-
#define __APPCORE_HEADER_GUARD__
3-
1+
#pragma once
42
// MIT License Copyright (c) 2024-2025 Tomáš Mark
53

64
#include "DotNameLib/DotNameLib.hpp"
@@ -23,67 +21,73 @@ inline void trace () {
2321
}
2422
#endif
2523

26-
using namespace DotNameUtils;
27-
2824
constexpr int maxArguments = 128;
2925
constexpr int helpOutputWidth = 80;
30-
constexpr double constantPi = 3.14159;
3126

3227
namespace AppContext {
3328
constexpr const char* standaloneName = "DotNameStandalone";
34-
const std::filesystem::path standalonePath = PathUtils::getStandalonePath ();
35-
const std::filesystem::path assetsPath
36-
= AssetContext::findAssetsPath (standalonePath, standaloneName);
3729
constexpr std::string_view utilsFirstAssetFile = UTILS_FIRST_ASSET_FILE;
38-
const std::filesystem::path assetsPathFirstFile = assetsPath / utilsFirstAssetFile;
30+
inline const std::filesystem::path& getStandalonePath () {
31+
static const std::filesystem::path standalonePath
32+
= DotNameUtils::PathUtils::getStandalonePath ();
33+
return standalonePath;
34+
}
35+
inline const std::filesystem::path& getAssetsPath () {
36+
static const std::filesystem::path assetsPath
37+
= AssetContext::findAssetsPath (getStandalonePath (), standaloneName);
38+
return assetsPath;
39+
}
40+
inline const std::filesystem::path& getAssetsPathFirstFile () {
41+
static const std::filesystem::path assetsPathFirstFile = getAssetsPath () / utilsFirstAssetFile;
42+
return assetsPathFirstFile;
43+
}
3944
}
4045

4146
std::unique_ptr<dotname::DotNameLib> uniqueLib;
4247

4348
inline int handlesArguments (int argc, const char* argv[]) {
4449
try {
45-
auto options = std::make_unique<cxxopts::Options> (argv[0], AppContext::standaloneName);
46-
options->set_width (helpOutputWidth);
47-
options->set_tab_expansion ();
48-
options->add_options () ("h,help", "Show help");
49-
options->add_options () ("1,omit", "Omit library loading",
50-
cxxopts::value<bool> ()->default_value ("false"));
51-
options->add_options () ("2,log2file", "Log to file",
52-
cxxopts::value<bool> ()->default_value ("false"));
53-
options->add_options () ("3,cpubench", "Run single&multi core cpubench",
54-
cxxopts::value<bool> ()->default_value ("false"));
55-
56-
const auto result = options->parse (argc, argv);
50+
cxxopts::Options options (argv[0], AppContext::standaloneName);
51+
options.set_width (helpOutputWidth);
52+
options.set_tab_expansion ();
53+
options.add_options () ("h,help", "Show help");
54+
options.add_options () ("1,omit", "Omit library loading",
55+
cxxopts::value<bool> ()->default_value ("false"));
56+
options.add_options () ("2,log2file", "Log to file",
57+
cxxopts::value<bool> ()->default_value ("false"));
58+
options.add_options () ("3,cpubench", "Run single&multi core cpubench",
59+
cxxopts::value<bool> ()->default_value ("false"));
60+
61+
const auto result = options.parse (argc, argv);
5762

5863
if (result.count ("help") != 0U) {
59-
LOG_I_STREAM << options->help ({ "", "Group" }) << "\n";
64+
LOG_I_STREAM << options.help ({ "", "Group" }) << "\n";
6065
return 0;
6166
}
6267

6368
if (result["log2file"].as<bool> ()) {
64-
LOG.enableFileLogging (std::string (AppContext::standaloneName) + ".log");
69+
static const std::string logFileName = std::string (AppContext::standaloneName) + ".log";
70+
LOG.enableFileLogging (logFileName);
6571
LOG_D_STREAM << "Logging to file enabled [-2]" << "\n";
6672
}
6773

6874
if (!result["omit"].as<bool> ()) {
69-
uniqueLib = std::make_unique<dotname::DotNameLib> (AppContext::assetsPath);
75+
uniqueLib = std::make_unique<dotname::DotNameLib> (AppContext::getAssetsPath ());
7076
} else {
7177
LOG_D_STREAM << "Loading library omitted [-1]" << "\n";
7278
}
7379

7480
if (result["cpubench"].as<bool> ()) {
75-
Performance::parUnseqHeavyCalculation (
76-
constantPi); // uses parallel execution on Linux (-ltbb), fallback on other platforms
81+
DotNameUtils::Performance::parUnseqHeavyCalculation ();
7782
}
7883

7984
if (!result.unmatched ().empty ()) {
8085
for (const auto& arg : result.unmatched ()) {
8186
LOG_E_STREAM << "Unrecognized option: " << arg << "\n";
8287
}
83-
LOG_I_STREAM << options->help () << "\n";
88+
LOG_I_STREAM << options.help () << "\n";
8489
return 1;
8590
}
86-
8791
} catch (const cxxopts::exceptions::exception& e) {
8892
LOG_E_STREAM << "error parsing options: " << e.what () << "\n";
8993
return 1;
@@ -94,7 +98,7 @@ inline int handlesArguments (int argc, const char* argv[]) {
9498
// unused right now
9599
inline int printAssets (const std::filesystem::path& assetsPath) {
96100
try {
97-
auto files = FileManager::listFiles (assetsPath);
101+
auto files = DotNameUtils::FileManager::listFiles (assetsPath);
98102
if (files.empty ()) {
99103
LOG_D_STREAM << "No assets found in " << assetsPath << "\n";
100104
return 0;
@@ -136,7 +140,6 @@ inline int runApp (int argc, const char* argv[]) {
136140
LOG_E_STREAM << "This is a demo error message" << "\n";
137141

138142
// bye
139-
LOG_I_STREAM << "Sucessfully exited " << AppContext::standaloneName << "\n";
143+
LOG_I_STREAM << "Successfully exited " << AppContext::standaloneName << "\n";
140144
return 0;
141145
}
142-
#endif // __APPCORE_HEADER_GUARD__

0 commit comments

Comments
 (0)