1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Added ObjectTemplate copy constructor and assignment operator

This commit is contained in:
AlexVinS 2016-09-08 17:02:59 +03:00
parent 42e7128acc
commit 114dac7e81
2 changed files with 35 additions and 0 deletions

View File

@ -58,6 +58,37 @@ ObjectTemplate::ObjectTemplate():
{
}
ObjectTemplate::ObjectTemplate(const ObjectTemplate& other):
visitDir(other.visitDir),
allowedTerrains(other.allowedTerrains),
id(other.id),
subid(other.subid),
printPriority(other.printPriority),
animationFile(other.animationFile)
{
//default copy constructor is failing with usedTiles this for unknown reason
usedTiles.resize(other.usedTiles.size());
for(size_t i = 0; i < usedTiles.size(); i++)
std::copy(other.usedTiles[i].begin(), other.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
}
ObjectTemplate & ObjectTemplate::operator=(const ObjectTemplate & rhs)
{
visitDir = rhs.visitDir;
allowedTerrains = rhs.allowedTerrains;
id = rhs.id;
subid = rhs.subid;
printPriority = rhs.printPriority;
animationFile = rhs.animationFile;
usedTiles.clear();
usedTiles.resize(rhs.usedTiles.size());
for(size_t i = 0; i < usedTiles.size(); i++)
std::copy(rhs.usedTiles[i].begin(), rhs.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
return *this;
}
void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
{
std::string data = parser.readString();

View File

@ -69,6 +69,10 @@ public:
bool canBePlacedAt(ETerrainType terrain) const;
ObjectTemplate();
//custom copy constructor is required
ObjectTemplate(const ObjectTemplate & other);
ObjectTemplate& operator=(const ObjectTemplate & rhs);
void readTxt(CLegacyConfigParser & parser);
void readMsk();