Codechange: use std::string for script info/library finding
This commit is contained in:
@@ -19,8 +19,7 @@
|
||||
|
||||
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
|
||||
{
|
||||
free(this->name);
|
||||
this->name = (name == nullptr) ? nullptr : stredup(name);
|
||||
this->name = (name == nullptr) ? "" : name;
|
||||
this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match);
|
||||
this->version = (info == nullptr) ? -1 : info->GetVersion();
|
||||
this->is_random = is_random;
|
||||
@@ -44,7 +43,7 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
|
||||
|
||||
ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
||||
{
|
||||
this->name = (config->name == nullptr) ? nullptr : stredup(config->name);
|
||||
this->name = config->name;
|
||||
this->info = config->info;
|
||||
this->version = config->version;
|
||||
this->is_random = config->is_random;
|
||||
@@ -60,7 +59,6 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
||||
|
||||
ScriptConfig::~ScriptConfig()
|
||||
{
|
||||
free(this->name);
|
||||
this->ResetSettings();
|
||||
this->to_load_data.reset();
|
||||
}
|
||||
@@ -156,7 +154,7 @@ bool ScriptConfig::IsRandom() const
|
||||
return this->is_random;
|
||||
}
|
||||
|
||||
const char *ScriptConfig::GetName() const
|
||||
const std::string &ScriptConfig::GetName() const
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
@@ -60,7 +60,6 @@ protected:
|
||||
|
||||
public:
|
||||
ScriptConfig() :
|
||||
name(nullptr),
|
||||
version(-1),
|
||||
info(nullptr),
|
||||
is_random(false),
|
||||
@@ -159,7 +158,7 @@ public:
|
||||
/**
|
||||
* Get the name of the Script.
|
||||
*/
|
||||
const char *GetName() const;
|
||||
const std::string &GetName() const;
|
||||
|
||||
/**
|
||||
* Get the version of the Script.
|
||||
@@ -190,7 +189,7 @@ public:
|
||||
ScriptInstance::ScriptData *GetToLoadData();
|
||||
|
||||
protected:
|
||||
const char *name; ///< Name of the Script
|
||||
std::string name; ///< Name of the Script
|
||||
int version; ///< Version of the Script
|
||||
class ScriptInfo *info; ///< ScriptInfo object for related to this Script version
|
||||
SettingValueList settings; ///< List with all setting=>value pairs that are configure for this Script
|
||||
@@ -207,7 +206,7 @@ protected:
|
||||
* This function should call back to the Scanner in charge of this Config,
|
||||
* to find the ScriptInfo belonging to a name+version.
|
||||
*/
|
||||
virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
|
||||
virtual ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) = 0;
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_CONFIG_HPP */
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
* @param version The version the library should have.
|
||||
* @return The library if found, nullptr otherwise.
|
||||
*/
|
||||
virtual class ScriptInfo *FindLibrary(const char *library, int version) = 0;
|
||||
virtual class ScriptInfo *FindLibrary(const std::string &library, int version) = 0;
|
||||
|
||||
/**
|
||||
* A script in multiplayer waits for the server to handle its DoCommand.
|
||||
|
Reference in New Issue
Block a user