![]() |
Olympe Engine 2.0
2D Game Engine with ECS Architecture
|
Loads and parses a JSON file on a background thread. More...
#include <AsyncJSONLoader.h>
Collaboration diagram for Olympe::AsyncJSONLoader:Public Member Functions | |
| AsyncJSONLoader () | |
| void | LoadAsync (const std::string &path) |
Starts loading path on a background thread. | |
| AsyncLoadState | GetState () const |
| Returns the current state of the loader. | |
| bool | IsReady () const |
| Returns true if the result is available (state == Ready). | |
| bool | HasFailed () const |
| Returns true if the load failed (state == Failed). | |
| nlohmann::json | GetResult () |
| Returns the parsed JSON if ready; returns an empty object otherwise. | |
| void | Reset () |
| Resets state to Idle and clears the result / error. | |
| const std::string & | GetLastError () const |
| Returns the last error message (non-empty when state == Failed). | |
Static Private Member Functions | |
| static nlohmann::json | LoadFile (const std::string &path) |
| Opens, reads, and parses the JSON file; called on the background thread. | |
Private Attributes | |
| AsyncLoadState | m_State |
| std::string | m_LastError |
| nlohmann::json | m_Result |
| std::future< nlohmann::json > | m_Future |
Loads and parses a JSON file on a background thread.
Typical usage:
Definition at line 59 of file AsyncJSONLoader.h.
| Olympe::AsyncJSONLoader::AsyncJSONLoader | ( | ) |
Definition at line 21 of file AsyncJSONLoader.cpp.
| const std::string & Olympe::AsyncJSONLoader::GetLastError | ( | ) | const |
Returns the last error message (non-empty when state == Failed).
Definition at line 134 of file AsyncJSONLoader.cpp.
References m_LastError.
| nlohmann::json Olympe::AsyncJSONLoader::GetResult | ( | ) |
Returns the parsed JSON if ready; returns an empty object otherwise.
Definition at line 109 of file AsyncJSONLoader.cpp.
References GetState(), m_Result, and Olympe::Ready.
Here is the call graph for this function:| AsyncLoadState Olympe::AsyncJSONLoader::GetState | ( | ) | const |
Returns the current state of the loader.
Transitions: Idle -> Loading -> Ready | Failed.
Definition at line 50 of file AsyncJSONLoader.cpp.
References Olympe::Failed, GetComponentTypeID_Static(), Olympe::Loading, m_Future, m_Result, m_State, Olympe::Ready, and SYSTEM_LOG.
Referenced by GetResult(), HasFailed(), and IsReady().
Here is the call graph for this function:
Here is the caller graph for this function:| bool Olympe::AsyncJSONLoader::HasFailed | ( | ) | const |
Returns true if the load failed (state == Failed).
Definition at line 100 of file AsyncJSONLoader.cpp.
References Olympe::Failed, and GetState().
Here is the call graph for this function:| bool Olympe::AsyncJSONLoader::IsReady | ( | ) | const |
Returns true if the result is available (state == Ready).
Definition at line 95 of file AsyncJSONLoader.cpp.
References GetState(), and Olympe::Ready.
Here is the call graph for this function:Starts loading path on a background thread.
Any previous result is discarded.
Definition at line 30 of file AsyncJSONLoader.cpp.
References LoadFile(), Olympe::Loading, m_Future, m_LastError, m_Result, and m_State.
Here is the call graph for this function:
|
staticprivate |
Opens, reads, and parses the JSON file; called on the background thread.
Definition at line 143 of file AsyncJSONLoader.cpp.
References GetComponentTypeID_Static().
Referenced by LoadAsync().
Here is the call graph for this function:
Here is the caller graph for this function:| void Olympe::AsyncJSONLoader::Reset | ( | ) |
Resets state to Idle and clears the result / error.
Definition at line 120 of file AsyncJSONLoader.cpp.
References Olympe::Idle, m_Future, m_LastError, m_Result, and m_State.
|
mutableprivate |
Definition at line 120 of file AsyncJSONLoader.h.
Referenced by GetState(), LoadAsync(), and Reset().
|
private |
Definition at line 118 of file AsyncJSONLoader.h.
Referenced by GetLastError(), LoadAsync(), and Reset().
|
private |
Definition at line 119 of file AsyncJSONLoader.h.
Referenced by GetResult(), GetState(), LoadAsync(), and Reset().
|
mutableprivate |
Definition at line 117 of file AsyncJSONLoader.h.
Referenced by GetState(), LoadAsync(), and Reset().