Skip to content

Commit 2a1db00

Browse files
author
tomasmark79
committed
fixed namespaces names
1 parent 1023a13 commit 2a1db00

File tree

10 files changed

+113
-103
lines changed

10 files changed

+113
-103
lines changed

include/DotNameLib/DotNameLib.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ namespace dotnamecpp::v1 {
1515
private:
1616
const std::string libName_ = "DotNameLib v." DOTNAMELIB_VERSION;
1717
std::shared_ptr<dotnamecpp::logging::ILogger> logger_;
18-
std::shared_ptr<dotnamecpp::IAssetManager> assetManager_;
18+
std::shared_ptr<dotnamecpp::assets::IAssetManager> assetManager_;
1919
std::filesystem::path assetsPath_;
2020
bool isInitialized_ = false;
2121

2222
[[nodiscard]]
23-
std::shared_ptr<dotnamecpp::IAssetManager> getAssetManager () const noexcept {
23+
std::shared_ptr<dotnamecpp::assets::IAssetManager> getAssetManager () const noexcept {
2424
return assetManager_;
2525
}
2626

2727
public:
2828
DotNameLib (std::shared_ptr<logging::ILogger> logger,
29-
std::shared_ptr<dotnamecpp::IAssetManager> assetManager)
29+
std::shared_ptr<dotnamecpp::assets::IAssetManager> assetManager)
3030
: logger_ (logger ? std::move (logger) : std::make_shared<logging::NullLogger> ()),
3131
assetManager_ (std::move (assetManager)) {
3232
if (assetManager_ && assetManager_->validate ()) {

src/Assets/AssetManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <vector>
33

44
namespace dotnamecpp {
5+
namespace assets {
56

67
AssetManager::AssetManager (std::filesystem::path assetsPath)
78
: assetsPath_ (std::move (assetsPath)) {
@@ -61,8 +62,10 @@ namespace dotnamecpp {
6162
}
6263
}
6364

65+
6466
// Fallback to first candidate if none found
6567
return candidatePaths[0];
6668
}
6769

68-
} // namespace dotname
70+
} // namespace assets
71+
} // namespace dotnamecpp

src/Assets/AssetManager.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <memory>
66

77
namespace dotnamecpp {
8+
namespace assets {
89

910
/**
1011
* @brief Concrete implementation of IAssetManager
@@ -50,4 +51,5 @@ namespace dotnamecpp {
5051
const std::string& appName);
5152
};
5253

53-
} // namespace dotname
54+
} // namespace assets
55+
} // namespace dotnamecpp

src/Assets/AssetManagerFactory.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88

99
namespace dotnamecpp {
10+
namespace assets {
1011

1112
/**
1213
* @brief Factory for creating IAssetManager instances
@@ -34,4 +35,5 @@ namespace dotnamecpp {
3435
}
3536
};
3637

38+
} // namespace assets
3739
} // namespace dotnamecpp

src/Assets/IAssetManager.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <filesystem>
44

55
namespace dotnamecpp {
6+
namespace assets {
67

78
/**
89
* @brief Interface for managing application assets
@@ -43,4 +44,5 @@ namespace dotnamecpp {
4344
[[nodiscard]] virtual bool validate () const = 0;
4445
};
4546

46-
} // namespace dotname
47+
} // namespace assets
48+
} // namespace dotnamecpp

src/Utils/Utils.hpp

Lines changed: 89 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -37,99 +37,94 @@
3737
#include <unistd.h>
3838
#endif
3939

40-
namespace DotNameUtils {
40+
namespace dotnamecpp {
41+
namespace utils {
4142

4243
// Core filesystem operations
4344
namespace fs {
44-
namespace io {
45-
inline std::string readFile (const std::filesystem::path& filePath) {
46-
std::ifstream file (filePath, std::ios::in);
47-
if (!file.is_open ()) {
48-
throw std::ios_base::failure ("Failed to open file: " + filePath.string ());
49-
}
50-
std::stringstream buffer;
51-
buffer << file.rdbuf ();
52-
return buffer.str ();
45+
inline std::string readFile (const std::filesystem::path& filePath) {
46+
std::ifstream file (filePath, std::ios::in);
47+
if (!file.is_open ()) {
48+
throw std::ios_base::failure ("Failed to open file: " + filePath.string ());
5349
}
50+
std::stringstream buffer;
51+
buffer << file.rdbuf ();
52+
return buffer.str ();
53+
}
5454

55-
inline void writeFile (const std::filesystem::path& filePath, const std::string& content) {
56-
std::ofstream file (filePath, std::ios::out | std::ios::trunc);
57-
if (!file.is_open ()) {
58-
throw std::ios_base::failure ("Failed to open file: " + filePath.string ());
59-
}
60-
file << content;
55+
inline void writeFile (const std::filesystem::path& filePath, const std::string& content) {
56+
std::ofstream file (filePath, std::ios::out | std::ios::trunc);
57+
if (!file.is_open ()) {
58+
throw std::ios_base::failure ("Failed to open file: " + filePath.string ());
6159
}
62-
} // namespace io
60+
file << content;
61+
}
6362

64-
namespace path {
65-
inline std::filesystem::path getParentPath (const std::filesystem::path& filePath) {
66-
return filePath.parent_path ();
67-
}
63+
inline std::filesystem::path getParentPath (const std::filesystem::path& filePath) {
64+
return filePath.parent_path ();
65+
}
6866

69-
inline std::string getFileName (const std::filesystem::path& filePath) {
70-
return filePath.filename ().string ();
71-
}
67+
inline std::string getFileName (const std::filesystem::path& filePath) {
68+
return filePath.filename ().string ();
69+
}
7270

73-
inline bool fileExists (const std::filesystem::path& filePath) {
74-
return std::filesystem::exists (filePath);
75-
}
71+
inline bool fileExists (const std::filesystem::path& filePath) {
72+
return std::filesystem::exists (filePath);
73+
}
7674

77-
inline std::filesystem::path getStandalonePath () {
78-
std::filesystem::path path;
75+
inline std::filesystem::path getExecutablePath () {
76+
std::filesystem::path path;
7977

8078
#ifdef _WIN32
81-
// C-Like is intended here for cross-platform compatibility
82-
char buffer[MAX_PATH];
83-
GetModuleFileNameA (NULL, buffer, MAX_PATH);
84-
path = buffer;
79+
// C-Like is intended here for cross-platform compatibility
80+
char buffer[MAX_PATH];
81+
GetModuleFileNameA (NULL, buffer, MAX_PATH);
82+
path = buffer;
8583
#elif defined(__APPLE__)
86-
// C-Like is intended here for cross-platform compatibility
87-
char buffer[PATH_MAX];
88-
uint32_t bufferSize = PATH_MAX;
89-
if (_NSGetExecutablePath (buffer, &bufferSize) == 0) {
90-
path = buffer;
91-
}
84+
// C-Like is intended here for cross-platform compatibility
85+
char buffer[PATH_MAX];
86+
uint32_t bufferSize = PATH_MAX;
87+
if (_NSGetExecutablePath (buffer, &bufferSize) == 0) {
88+
path = buffer;
89+
}
9290
#elif defined(__EMSCRIPTEN__)
93-
// Emscripten doesn't have readlink, use current directory
94-
path = std::filesystem::current_path ().string ();
91+
// Emscripten doesn't have readlink, use current directory
92+
path = std::filesystem::current_path ().string ();
9593
#elif defined(__linux__)
96-
// C-Like is intended here for cross-platform compatibility
97-
char buffer[4096];
98-
ssize_t len = readlink ("/proc/self/exe", buffer, sizeof (buffer) - 1);
99-
if (len != -1) {
100-
buffer[len] = '\0';
101-
path = buffer;
102-
}
103-
#endif
104-
return path;
94+
// C-Like is intended here for cross-platform compatibility
95+
char buffer[4096];
96+
ssize_t len = readlink ("/proc/self/exe", buffer, sizeof (buffer) - 1);
97+
if (len != -1) {
98+
buffer[len] = '\0';
99+
path = buffer;
105100
}
106-
} // namespace path
101+
#endif
102+
return path;
103+
}
107104

108-
namespace mgmt {
109-
inline void createDirectory (const std::filesystem::path& dirPath) {
110-
if (!std::filesystem::exists (dirPath)) {
111-
std::filesystem::create_directories (dirPath);
112-
}
105+
inline void createDirectory (const std::filesystem::path& dirPath) {
106+
if (!std::filesystem::exists (dirPath)) {
107+
std::filesystem::create_directories (dirPath);
113108
}
109+
}
114110

115-
inline void remove (const std::filesystem::path& path) {
116-
if (std::filesystem::exists (path)) {
117-
std::filesystem::remove_all (path);
118-
}
111+
inline void remove (const std::filesystem::path& path) {
112+
if (std::filesystem::exists (path)) {
113+
std::filesystem::remove_all (path);
119114
}
115+
}
120116

121-
inline std::vector<std::filesystem::path> listFiles (const std::filesystem::path& dirPath) {
122-
std::vector<std::filesystem::path> files;
123-
for (const auto& entry : std::filesystem::directory_iterator (dirPath)) {
124-
files.push_back (entry.path ());
125-
}
126-
return files;
117+
inline std::vector<std::filesystem::path> listFiles (const std::filesystem::path& dirPath) {
118+
std::vector<std::filesystem::path> files;
119+
for (const auto& entry : std::filesystem::directory_iterator (dirPath)) {
120+
files.push_back (entry.path ());
127121
}
128-
} // namespace mgmt
122+
return files;
123+
}
129124
} // namespace fs
130125

131126
// String utilities
132-
namespace str {
127+
namespace string {
133128
inline std::string addDots (const std::string& str) {
134129
std::string result;
135130
for (size_t i = 0; i < str.length (); ++i) {
@@ -150,36 +145,36 @@ namespace DotNameUtils {
150145
}
151146
return result;
152147
}
153-
} // namespace str
148+
} // namespace string
154149

155150
// JSON utilities
156151
namespace json {
157-
// Load JSON from file
158-
inline nlohmann::json loadFromFile (const std::filesystem::path& filePath) {
159-
if (!fs::path::fileExists (filePath)) {
160-
throw std::ios_base::failure ("JSON file does not exist: " + filePath.string ());
161-
}
152+
// Load JSON from file
153+
inline nlohmann::json loadFromFile (const std::filesystem::path& filePath) {
154+
if (!utils::fs::fileExists (filePath)) {
155+
throw std::ios_base::failure ("JSON file does not exist: " + filePath.string ());
156+
}
162157

163-
try {
164-
std::string content = fs::io::readFile (filePath);
165-
return nlohmann::json::parse (content);
166-
} catch (const nlohmann::json::parse_error& e) {
167-
throw std::runtime_error (
168-
"JSON parse error in file " + filePath.string () + ": " + e.what ());
158+
try {
159+
std::string content = utils::fs::readFile (filePath);
160+
return nlohmann::json::parse (content);
161+
} catch (const nlohmann::json::parse_error& e) {
162+
throw std::runtime_error (
163+
"JSON parse error in file " + filePath.string () + ": " + e.what ());
164+
}
169165
}
170-
}
171166

172-
// Save JSON to file
173-
inline void saveToFile (const std::filesystem::path& filePath, const nlohmann::json& jsonData,
174-
int indent = 2) {
175-
try {
176-
std::string jsonString = jsonData.dump (indent);
177-
fs::io::writeFile (filePath, jsonString);
178-
} catch (const std::exception& e) {
179-
throw std::runtime_error (
180-
"Failed to save JSON to file " + filePath.string () + ": " + e.what ());
167+
// Save JSON to file
168+
inline void saveToFile (const std::filesystem::path& filePath, const nlohmann::json& jsonData,
169+
int indent = 2) {
170+
try {
171+
std::string jsonString = jsonData.dump (indent);
172+
utils::fs::writeFile (filePath, jsonString);
173+
} catch (const std::exception& e) {
174+
throw std::runtime_error (
175+
"Failed to save JSON to file " + filePath.string () + ": " + e.what ());
176+
}
181177
}
182-
}
183178

184179
// Get value with default fallback
185180
template <typename T>
@@ -362,6 +357,8 @@ namespace DotNameUtils {
362357
}
363358

364359
} // namespace json
365-
} // namespace DotNameUtils
360+
361+
} // namespace utils
362+
} // namespace dotnamecpp
366363

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

standalone/src/Main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include <cxxopts.hpp>
55
#include <iostream>
66

7+
// Main.cpp ->
8+
// Standalone.hpp -> [Standalone.cpp (All implementations are inline)]
9+
// DotNameLib.hpp -> [DotNameLib.cpp (All implementations are inline)]
10+
711
std::filesystem::path getStandalonePath () {
8-
return DotNameUtils::fs::path::getStandalonePath ();
12+
return dotnamecpp::utils::fs::getExecutablePath ();
913
}
1014

1115
int main (int argc, char** argv) {

standalone/src/Standalone.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace dotnamecpp::app {
1313
bool initialized_ = false;
1414
std::string appName_ = "DotNameStandalone";
1515
std::shared_ptr<logging::ILogger> logger_;
16-
std::shared_ptr<dotnamecpp::IAssetManager> assetManager_;
16+
std::shared_ptr<dotnamecpp::assets::IAssetManager> assetManager_;
1717
std::unique_ptr<dotnamecpp::v1::DotNameLib> library_;
1818

1919
bool initializeLogger (const logging::LoggerConfig& loggerConfig) {
@@ -23,7 +23,7 @@ namespace dotnamecpp::app {
2323

2424
bool initializeAssets (const std::filesystem::path& executablePath) {
2525
try {
26-
assetManager_ = dotnamecpp::AssetManagerFactory::createDefault (executablePath, appName_);
26+
assetManager_ = dotnamecpp::assets::AssetManagerFactory::createDefault (executablePath, appName_);
2727
if (!assetManager_->validate ()) {
2828
logger_->errorStream () << "Failed to validate assets path: "
2929
<< assetManager_->getAssetsPath ();

standalone/tests/AssetManagerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <filesystem>
66
#include <fstream>
77

8-
using namespace dotnamecpp;
8+
using namespace dotnamecpp::assets;
99

1010
class AssetManagerTest : public ::testing::Test {
1111
protected:

standalone/tests/MockAssetManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Allows controlling behavior for test scenarios without filesystem dependencies.
1010
*/
11-
class MockAssetManager : public dotnamecpp::IAssetManager {
11+
class MockAssetManager : public dotnamecpp::assets::IAssetManager {
1212
public:
1313
explicit MockAssetManager (std::filesystem::path mockPath)
1414
: mockPath_ (std::move (mockPath)), mockExists_ (true), mockValid_ (true) {

0 commit comments

Comments
 (0)