mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Additional checks for invalid access to IdentifierStorage
This commit is contained in:
parent
82989e6302
commit
c8a6cd74cc
@ -20,11 +20,6 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CIdentifierStorage::CIdentifierStorage():
|
||||
state(LOADING)
|
||||
{
|
||||
}
|
||||
|
||||
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||
{
|
||||
if (boost::algorithm::ends_with(ID, "."))
|
||||
@ -52,7 +47,7 @@ void CIdentifierStorage::requestIdentifier(ObjectCallback callback) const
|
||||
|
||||
assert(!callback.localScope.empty());
|
||||
|
||||
if (state != FINISHED) // enqueue request if loading is still in progress
|
||||
if (state != ELoadingState::FINISHED) // enqueue request if loading is still in progress
|
||||
scheduledRequests.push_back(callback);
|
||||
else // execute immediately for "late" requests
|
||||
resolveIdentifier(callback);
|
||||
@ -138,6 +133,9 @@ void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const Js
|
||||
|
||||
std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent) const
|
||||
{
|
||||
//TODO: RE-ENABLE
|
||||
//assert(state != ELoadingState::LOADING);
|
||||
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(scope, type, name, std::function<void(si32)>(), silent));
|
||||
|
||||
if (idList.size() == 1)
|
||||
@ -150,6 +148,8 @@ std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope,
|
||||
|
||||
std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent) const
|
||||
{
|
||||
assert(state != ELoadingState::LOADING);
|
||||
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(name.meta, type, name.String(), std::function<void(si32)>(), silent));
|
||||
|
||||
if (idList.size() == 1)
|
||||
@ -162,6 +162,8 @@ std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type,
|
||||
|
||||
std::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, bool silent) const
|
||||
{
|
||||
assert(state != ELoadingState::LOADING);
|
||||
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(name.meta, name.String(), std::function<void(si32)>(), silent));
|
||||
|
||||
if (idList.size() == 1)
|
||||
@ -174,6 +176,8 @@ std::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, boo
|
||||
|
||||
std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent) const
|
||||
{
|
||||
assert(state != ELoadingState::LOADING);
|
||||
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(scope, fullName, std::function<void(si32)>(), silent));
|
||||
|
||||
if (idList.size() == 1)
|
||||
@ -186,6 +190,8 @@ std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope,
|
||||
|
||||
void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier)
|
||||
{
|
||||
assert(state != ELoadingState::FINISHED);
|
||||
|
||||
ObjectData data;
|
||||
data.scope = scope;
|
||||
data.id = identifier;
|
||||
@ -311,7 +317,9 @@ bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request) const
|
||||
|
||||
void CIdentifierStorage::finalize()
|
||||
{
|
||||
state = FINALIZING;
|
||||
assert(state == ELoadingState::LOADING);
|
||||
|
||||
state = ELoadingState::FINALIZING;
|
||||
bool errorsFound = false;
|
||||
|
||||
while ( !scheduledRequests.empty() )
|
||||
@ -333,7 +341,7 @@ void CIdentifierStorage::finalize()
|
||||
logMod->error("All known identifiers were dumped into log file");
|
||||
}
|
||||
assert(errorsFound == false);
|
||||
state = FINISHED;
|
||||
state = ELoadingState::FINISHED;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -17,7 +17,7 @@ class JsonNode;
|
||||
/// if possible, objects ID's should be in format <type>.<name>, camelCase e.g. "creature.grandElf"
|
||||
class DLL_LINKAGE CIdentifierStorage
|
||||
{
|
||||
enum ELoadingState
|
||||
enum class ELoadingState
|
||||
{
|
||||
LOADING,
|
||||
FINALIZING,
|
||||
@ -63,7 +63,7 @@ class DLL_LINKAGE CIdentifierStorage
|
||||
std::multimap<std::string, ObjectData> registeredObjects;
|
||||
mutable std::vector<ObjectCallback> scheduledRequests;
|
||||
|
||||
ELoadingState state;
|
||||
ELoadingState state = ELoadingState::LOADING;
|
||||
|
||||
/// Check if identifier can be valid (camelCase, point as separator)
|
||||
static void checkIdentifier(std::string & ID);
|
||||
@ -73,7 +73,7 @@ class DLL_LINKAGE CIdentifierStorage
|
||||
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback) const;
|
||||
|
||||
public:
|
||||
CIdentifierStorage();
|
||||
CIdentifierStorage() = default;
|
||||
virtual ~CIdentifierStorage() = default;
|
||||
|
||||
/// request identifier for specific object name.
|
||||
|
Loading…
Reference in New Issue
Block a user