-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNixonCppLib.cpp
More file actions
65 lines (56 loc) · 2.39 KB
/
Copy pathNixonCppLib.cpp
File metadata and controls
65 lines (56 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <NixonCppLib/NixonCppLib.hpp>
namespace nixoncpp::v1 {
/**
* @brief Constructs a NixonCppLib instance from the given application context.
*
* Initializes the library by setting up the logger and asset manager from the
* provided application context. If no logger is supplied in the context, a
* NullLogger is used as a fallback. The constructor validates the asset manager
* and sets the initialization flag accordingly.
*
* @param context The application context containing the logger and asset manager
* dependencies required for library initialization.
*
* @note If the asset manager is null or fails validation, an error is logged
* and the library remains uninitialized (isInitialized_ will be false).
*/
NixonCppLib::NixonCppLib(const UtilsFactory::ApplicationContext &context)
: logger_(context.logger ? context.logger
: std::make_shared<nixoncpp::logging::NullLogger>()),
assetManager_(context.assetManager) {
if (!assetManager_ || !assetManager_->validate()) {
logger_->errorStream() << "Invalid or missing asset manager";
return;
}
logger_->infoStream() << libName_ << " initialized ...";
isInitialized_ = true;
}
NixonCppLib::~NixonCppLib() {
if (isInitialized_) {
logger_->infoStream() << libName_ << " ... destructed";
} else {
logger_->infoStream() << libName_ << " ... (not initialized) destructed";
}
}
bool NixonCppLib::isInitialized() const noexcept { return isInitialized_; }
const std::shared_ptr<nixoncpp::assets::IAssetManager> &
NixonCppLib::getAssetManager() const noexcept {
return assetManager_;
}
// Example method to demonstrate library functionality
void NixonCppLib::performLibraryTask() {
if (!isInitialized_) {
logger_->errorStream() << "Cannot perform task: " << libName_ << " is not initialized";
return;
}
logger_->infoStream() << "Performing a task in " << libName_ << " using the asset manager";
// Example usage of the asset manager
const char *assetName = "NixonCppLogo.svg";
auto asset = assetManager_->getAssetsPath() / assetName;
if (std::filesystem::exists(asset)) {
logger_->infoStream() << "Successfully loaded asset: " << assetName;
} else {
logger_->errorStream() << "Failed to load asset: " << assetName;
}
}
} // namespace nixoncpp::v1