File diff r18636:c90444debac9 → r18637:6db0bce1fa51
src/newgrf_config.cpp
Show inline comments
 
@@ -41,28 +41,31 @@ GRFTextWrapper::~GRFTextWrapper()
 
 * @param filename Set the filename of this GRFConfig to filename. The argument
 
 *   is copied so the original string isn't needed after the constructor.
 
 */
 
GRFConfig::GRFConfig(const char *filename) :
 
	name(new GRFTextWrapper()),
 
	info(new GRFTextWrapper()),
 
	url(new GRFTextWrapper()),
 
	num_valid_params(lengthof(param))
 
{
 
	if (filename != NULL) this->filename = strdup(filename);
 
	this->name->AddRef();
 
	this->info->AddRef();
 
	this->url->AddRef();
 
}
 

	
 
/**
 
 * Create a new GRFConfig that is a deep copy of an existing config.
 
 * @param config The GRFConfig object to make a copy of.
 
 */
 
GRFConfig::GRFConfig(const GRFConfig &config) :
 
	ZeroedMemoryAllocator(),
 
	ident(config.ident),
 
	name(config.name),
 
	info(config.info),
 
	url(config.url),
 
	version(config.version),
 
	min_loadable_version(config.min_loadable_version),
 
	flags(config.flags & ~(1 << GCF_COPY)),
 
	status(config.status),
 
	grf_bugs(config.grf_bugs),
 
	num_params(config.num_params),
 
@@ -72,12 +75,13 @@ GRFConfig::GRFConfig(const GRFConfig &co
 
{
 
	MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
 
	MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
 
	if (config.filename != NULL) this->filename = strdup(config.filename);
 
	this->name->AddRef();
 
	this->info->AddRef();
 
	this->url->AddRef();
 
	if (config.error    != NULL) this->error    = new GRFError(*config.error);
 
	for (uint i = 0; i < config.param_info.Length(); i++) {
 
		if (config.param_info[i] == NULL) {
 
			*this->param_info.Append() = NULL;
 
		} else {
 
			*this->param_info.Append() = new GRFParameterInfo(*config.param_info[i]);
 
@@ -92,12 +96,13 @@ GRFConfig::~GRFConfig()
 
	if (!HasBit(this->flags, GCF_COPY)) {
 
		free(this->filename);
 
		delete this->error;
 
	}
 
	this->name->Release();
 
	this->info->Release();
 
	this->url->Release();
 

	
 
	for (uint i = 0; i < this->param_info.Length(); i++) delete this->param_info[i];
 
}
 

	
 
/**
 
 * Get the name of this grf. In case the name isn't known
 
@@ -116,12 +121,21 @@ const char *GRFConfig::GetName() const
 
 */
 
const char *GRFConfig::GetDescription() const
 
{
 
	return GetGRFStringFromGRFText(this->info->text);
 
}
 

	
 
/**
 
 * Get the grf url.
 
 * @return A string with an url of this grf.
 
 */
 
const char *GRFConfig::GetURL() const
 
{
 
	return GetGRFStringFromGRFText(this->url->text);
 
}
 

	
 
/** Set the default value for all parameters as specified by action14. */
 
void GRFConfig::SetParameterDefaults()
 
{
 
	this->num_params = 0;
 
	MemSetT<uint32>(this->param, 0, lengthof(this->param));