<commit_before>/* BZWorkbench
 * Copyright (c) 1993 - 2008 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "objects/waterLevel.h"

#include "objects/material.h"

waterLevel::waterLevel() : DataEntry("waterLevel", "<name><height><matref>") {
	name = string("");
	waterMaterial = NULL;
	height = -1.0f;
}

// get method
string waterLevel::get(void) {
	return toString();
}

// bzw methods
bool waterLevel::parse( std::string& line ) {
	// check if we reached the end of the section
	if ( line == "end" )
		return false;

	string key = BZWParser::key( line.c_str() );
	string value = BZWParser::value( key.c_str(), line.c_str() );

	if ( key == "name" ) {
		name = value;
	}
	else if ( key == "matref" ) {
		material* mat = (material*)Model::command( MODEL_GET, "material", value );
		if( mat )
			waterMaterial = mat;
		else
			throw BZWReadError( this, string( "Couldn't find material, " ) + value );

	}
	else if ( key == "height" ) {
		height = atof( value.c_str() );
	}
	else {
		throw BZWReadError( this, string( "Unknown key, " ) + key );
	}

	return true;
}

void waterLevel::finalize() {

}

// toString method
string waterLevel::toString(void) {
	string waterLevelStr = string(ftoa(height));
		
	return string(string("waterLevel\n") +
						 "  name " + name + "\n" +
						 "  height " + waterLevelStr + "\n" +
						 waterMaterial->getName() +
						 getUnusedText() + 
						 "end\n");
}


waterLevel::~waterLevel() { }<commit_msg>- fixed crash when calling waterLevel::toString: added test if waterMaterial is null before trying to getName() - fixed output of waterLevel::toString - added default waterLevel name = "water"<commit_after>/* BZWorkbench
 * Copyright (c) 1993 - 2008 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "objects/waterLevel.h"

#include "objects/material.h"

waterLevel::waterLevel() : DataEntry("waterLevel", "<name><height><matref>") {
	name = string("water");
	waterMaterial = NULL;
	height = -1.0f;
}

// get method
string waterLevel::get(void) {
	return toString();
}

// bzw methods
bool waterLevel::parse( std::string& line ) {
	// check if we reached the end of the section
	if ( line == "end" )
		return false;

	string key = BZWParser::key( line.c_str() );
	string value = BZWParser::value( key.c_str(), line.c_str() );

	if ( key == "name" ) {
		name = value;
	}
	else if ( key == "matref" ) {
		material* mat = (material*)Model::command( MODEL_GET, "material", value );
		if( mat )
			waterMaterial = mat;
		else
			throw BZWReadError( this, string( "Couldn't find material, " ) + value );

	}
	else if ( key == "height" ) {
		height = atof( value.c_str() );
	}
	else {
		throw BZWReadError( this, string( "Unknown key, " ) + key );
	}

	return true;
}

void waterLevel::finalize() {

}

// toString method
string waterLevel::toString(void) {
	string waterLevelHeightStr = string("  height " + ftoa(height) + "\n" );
	string waterLevelMatStr = string("");
	if(waterMaterial != NULL){
		waterLevelMatStr = string("  matref " + waterMaterial->getName() + "\n" );
	}
		
	return string(string("waterLevel\n") +
						 "  name " + name + "\n" +
						 waterLevelHeightStr +
						 waterLevelMatStr +
						 getUnusedText() + "\n" +
						 "end\n");
}


waterLevel::~waterLevel() { }
{'fraction_non_alphanumeric': 0.14408493427704752, 'fraction_numerical': 0.005055611729019211, 'mean_word_length': 3.6498237367802586, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7361076', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1264, 'n_words': 392}