diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index e046e0b..b86cc4e 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -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> entities) +EntityConverter::extractMapInfo(std::queue> &entities) { if( haveMapInfo_ ) { std::cerr << "Map info already extracted, doing nothing" << std::endl; @@ -119,7 +119,7 @@ EntityConverter::extractMapInfo(std::queue> entities) std::vector -EntityConverter::convert(std::vector lines) +EntityConverter::convert(const std::vector &lines) { if ( haveMapInfo_ ) { @@ -196,7 +196,7 @@ EntityConverter::convert(std::vector lines) * PROTECTED *-----------------------------------------------------------------------------*/ std::vector -EntityConverter::convertPickup(std::vector &lines) +EntityConverter::convertPickup(const std::vector &lines) { std::vector convertedLines; //can ignore angle of pickups in xonotic format @@ -260,7 +260,7 @@ EntityConverter::convertPickup(std::vector &lines) *-------------------------------------------------------------------------------------- */ std::vector -EntityConverter::convertPlayerSpawn(std::vector &lines) +EntityConverter::convertPlayerSpawn(const std::vector &lines) { std::vector convertedLines; // Requires position coordinate @@ -349,7 +349,7 @@ EntityConverter::convertPlayerSpawn(std::vector &lines) std::vector -EntityConverter::convertJumpPad(std::vector &lines) +EntityConverter::convertJumpPad(const std::vector &lines) { std::vector convertedLines; std::string targetName; @@ -374,7 +374,7 @@ EntityConverter::convertJumpPad(std::vector &lines) std::vector -EntityConverter::convertTeleporter(std::vector &lines) +EntityConverter::convertTeleporter(const std::vector &lines) { std::vector convertedLines; std::string targetName; @@ -399,7 +399,7 @@ EntityConverter::convertTeleporter(std::vector &lines) std::vector -EntityConverter::convertTarget(std::vector &lines) +EntityConverter::convertTarget(const std::vector &lines) { std::vector convertedLines; //position and name required, angles optional @@ -485,7 +485,7 @@ EntityConverter::convertTarget(std::vector &lines) std::vector -EntityConverter::convertRaceStart(std::vector &lines) +EntityConverter::convertRaceStart(const std::vector &lines) { std::vector convertedLines; convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n"); @@ -497,7 +497,7 @@ EntityConverter::convertRaceStart(std::vector &lines) std::vector -EntityConverter::convertRaceFinish(std::vector &lines) +EntityConverter::convertRaceFinish(const std::vector &lines) { std::vector convertedLines; convertedLines.push_back ("\"classname\" \"trigger_race_checkpoint\"\n"); @@ -513,7 +513,7 @@ EntityConverter::convertRaceFinish(std::vector &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(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; diff --git a/ReflexToQ3/includes/EntityConverter.hpp b/ReflexToQ3/includes/EntityConverter.hpp index 96aabf3..2161054 100644 --- a/ReflexToQ3/includes/EntityConverter.hpp +++ b/ReflexToQ3/includes/EntityConverter.hpp @@ -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 convert(std::vector lines); + std::vector convert(const std::vector &lines); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter @@ -97,7 +97,7 @@ class EntityConverter * THROWS: runtime_error when encountering malformed entity *-------------------------------------------------------------------------------------- */ - void extractMapInfo(std::queue> entities); + void extractMapInfo(std::queue> &entities); @@ -113,13 +113,13 @@ class EntityConverter * Return: vector of strings, the converted entity *-------------------------------------------------------------------------------------- */ - std::vector convertPickup(std::vector &entity); - std::vector convertPlayerSpawn(std::vector &entity); - std::vector convertJumpPad(std::vector &entity); - std::vector convertTeleporter(std::vector &entity); - std::vector convertTarget(std::vector &entity); - std::vector convertRaceStart(std::vector &entity); - std::vector convertRaceFinish(std::vector &entity); + std::vector convertPickup(const std::vector &entity); + std::vector convertPlayerSpawn(const std::vector &entity); + std::vector convertJumpPad(const std::vector &entity); + std::vector convertTeleporter(const std::vector &entity); + std::vector convertTarget(const std::vector &entity); + std::vector convertRaceStart(const std::vector &entity); + std::vector convertRaceFinish(const std::vector &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;