EC: const correct prototypes, pass by ref where possible

This commit is contained in:
suhrke 2017-07-05 20:32:49 -07:00
parent 774688180d
commit 26e287d9b4
2 changed files with 36 additions and 34 deletions

View File

@ -30,7 +30,7 @@
* PUBLIC
*-----------------------------------------------------------------------------*/
EntityConverter::EntityConverter(std::string entityMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0)
EntityConverter::EntityConverter(const std::string &entityMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0)
{
//MUST RUN extractMapInfo method after this constructor
haveMapInfo_ = false;
@ -46,7 +46,7 @@ EntityConverter::EntityConverter(std::string entityMapFile) : OFFSET_PLAYER(32.0
EntityConverter::EntityConverter(std::string entityMapFile, std::string reflexMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0)
EntityConverter::EntityConverter(const std::string &entityMapFile, const std::string &reflexMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0)
{
haveMapInfo_ = false;
// game modes default to enabled
@ -92,7 +92,7 @@ EntityConverter::EntityConverter(std::string entityMapFile, std::string reflexMa
*--------------------------------------------------------------------------------------
*/
void
EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> &entities)
{
if( haveMapInfo_ ) {
std::cerr << "Map info already extracted, doing nothing" << std::endl;
@ -119,7 +119,7 @@ EntityConverter::extractMapInfo(std::queue<std::vector<std::string>> entities)
std::vector<std::string>
EntityConverter::convert(std::vector<std::string> lines)
EntityConverter::convert(const std::vector<std::string> &lines)
{
if ( haveMapInfo_ )
{
@ -196,7 +196,7 @@ EntityConverter::convert(std::vector<std::string> lines)
* PROTECTED
*-----------------------------------------------------------------------------*/
std::vector<std::string>
EntityConverter::convertPickup(std::vector<std::string> &lines)
EntityConverter::convertPickup(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
//can ignore angle of pickups in xonotic format
@ -260,7 +260,7 @@ EntityConverter::convertPickup(std::vector<std::string> &lines)
*--------------------------------------------------------------------------------------
*/
std::vector<std::string>
EntityConverter::convertPlayerSpawn(std::vector<std::string> &lines)
EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
// Requires position coordinate
@ -349,7 +349,7 @@ EntityConverter::convertPlayerSpawn(std::vector<std::string> &lines)
std::vector<std::string>
EntityConverter::convertJumpPad(std::vector<std::string> &lines)
EntityConverter::convertJumpPad(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
std::string targetName;
@ -374,7 +374,7 @@ EntityConverter::convertJumpPad(std::vector<std::string> &lines)
std::vector<std::string>
EntityConverter::convertTeleporter(std::vector<std::string> &lines)
EntityConverter::convertTeleporter(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
std::string targetName;
@ -399,7 +399,7 @@ EntityConverter::convertTeleporter(std::vector<std::string> &lines)
std::vector<std::string>
EntityConverter::convertTarget(std::vector<std::string> &lines)
EntityConverter::convertTarget(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
//position and name required, angles optional
@ -485,7 +485,7 @@ EntityConverter::convertTarget(std::vector<std::string> &lines)
std::vector<std::string>
EntityConverter::convertRaceStart(std::vector<std::string> &lines)
EntityConverter::convertRaceStart(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
@ -497,7 +497,7 @@ EntityConverter::convertRaceStart(std::vector<std::string> &lines)
std::vector<std::string>
EntityConverter::convertRaceFinish(std::vector<std::string> &lines)
EntityConverter::convertRaceFinish(const std::vector<std::string> &lines)
{
std::vector<std::string> convertedLines;
convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n");
@ -513,7 +513,7 @@ EntityConverter::convertRaceFinish(std::vector<std::string> &lines)
* PRIVATE
*-----------------------------------------------------------------------------*/
std::string
EntityConverter::getAttributeType(std::string line)
EntityConverter::getAttributeType(const std::string &line) const
{
std::string type;
std::string dataType;
@ -528,7 +528,7 @@ EntityConverter::getAttributeType(std::string line)
void
EntityConverter::mapEntities(std::string mapFile)
EntityConverter::mapEntities(const std::string &mapFile)
{
std::ifstream fin;
fin.open(mapFile);
@ -557,21 +557,22 @@ EntityConverter::mapEntities(std::string mapFile)
void
EntityConverter::extractFromEntity(std::string &line, std::istream &is)
EntityConverter::extractFromEntity(const std::string &line, std::istream &is)
{
std::string trash;
std::string targetName;
std::string nextLine;
if ( line.find("type Teleporter") != std::string::npos) {
std::getline(is, line);
std::istringstream iss(line);
std::getline(is, nextLine);
std::istringstream iss(nextLine);
if ( ! (iss >> trash >> trash >> targetName)) {
throw std::runtime_error( "format error in .map file");
}
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "Teleporter") );
}
else if ( line.find("type JumpPad") != std::string::npos) {
std::getline(is, line);
std::istringstream iss(line);
std::getline(is, nextLine);
std::istringstream iss(nextLine);
if ( ! (iss >> trash >> trash >> targetName)) {
throw std::runtime_error( "format error in .map file");
}
@ -581,7 +582,8 @@ EntityConverter::extractFromEntity(std::string &line, std::istream &is)
std::string EntityConverter::offset(std::string value, float amount) {
std::string EntityConverter::offset(const std::string &value, const float amount) const
{
std::istringstream iss(value);
float c;
iss >> c;

View File

@ -62,7 +62,7 @@ class EntityConverter
* THROWS: std::ios::failure on IO failure
*--------------------------------------------------------------------------------------
*/
EntityConverter(std::string entityMapFile);
EntityConverter(const std::string &entityMapFile);
/* *--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: Constructor
@ -73,7 +73,7 @@ class EntityConverter
* THROWS: std::ios::failure on IO failure
*--------------------------------------------------------------------------------------
*/
EntityConverter(std::string entityMapFile, std::string reflexMapFile);
EntityConverter(const std::string &entityMapFile, const std::string &reflexMapFile);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
@ -86,7 +86,7 @@ class EntityConverter
* THROWS: runtime_error when called before map info has been extracted
*--------------------------------------------------------------------------------------
*/
std::vector<std::string> convert(std::vector<std::string> lines);
std::vector<std::string> convert(const std::vector<std::string> &lines);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
@ -97,7 +97,7 @@ class EntityConverter
* THROWS: runtime_error when encountering malformed entity
*--------------------------------------------------------------------------------------
*/
void extractMapInfo(std::queue<std::vector<std::string>> entities);
void extractMapInfo(std::queue<std::vector<std::string>> &entities);
@ -113,13 +113,13 @@ class EntityConverter
* Return: vector of strings, the converted entity
*--------------------------------------------------------------------------------------
*/
std::vector<std::string> convertPickup(std::vector<std::string> &entity);
std::vector<std::string> convertPlayerSpawn(std::vector<std::string> &entity);
std::vector<std::string> convertJumpPad(std::vector<std::string> &entity);
std::vector<std::string> convertTeleporter(std::vector<std::string> &entity);
std::vector<std::string> convertTarget(std::vector<std::string> &entity);
std::vector<std::string> convertRaceStart(std::vector<std::string> &entity);
std::vector<std::string> convertRaceFinish(std::vector<std::string> &entity);
std::vector<std::string> convertPickup(const std::vector<std::string> &entity);
std::vector<std::string> convertPlayerSpawn(const std::vector<std::string> &entity);
std::vector<std::string> convertJumpPad(const std::vector<std::string> &entity);
std::vector<std::string> convertTeleporter(const std::vector<std::string> &entity);
std::vector<std::string> convertTarget(const std::vector<std::string> &entity);
std::vector<std::string> convertRaceStart(const std::vector<std::string> &entity);
std::vector<std::string> convertRaceFinish(const std::vector<std::string> &entity);
@ -146,7 +146,7 @@ class EntityConverter
* Parameter: string "line", entity keyword followed by the type
*--------------------------------------------------------------------------------------
*/
std::string getAttributeType(std::string line);
std::string getAttributeType(const std::string &line) const;
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
@ -156,7 +156,7 @@ class EntityConverter
* Return: true if no error, false if error
*--------------------------------------------------------------------------------------
*/
void mapEntities(std::string mapFile);
void mapEntities(const std::string &mapFile);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
@ -167,7 +167,7 @@ class EntityConverter
* single entity
*--------------------------------------------------------------------------------------
*/
void extractFromEntity(std::string &line, std::istream &is);
void extractFromEntity(const std::string &line, std::istream &is);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
@ -179,7 +179,7 @@ class EntityConverter
* Return: string, float value passed as string
*--------------------------------------------------------------------------------------
*/
std::string offset(std::string value, float offset);
std::string offset(const std::string &value, const float offset) const;