Skip to content

Instantly share code, notes, and snippets.

@ark-tik
Created July 19, 2022 15:44
Show Gist options
  • Save ark-tik/78e41944cce789493f970ff9cf2370f7 to your computer and use it in GitHub Desktop.
Save ark-tik/78e41944cce789493f970ff9cf2370f7 to your computer and use it in GitHub Desktop.
bool LoadCsvLayerData(const pugi::xml_node &layerNode, const std::string &dataStr, buffers::TreeNode *resNode,
const int& tileWidth, const int& tileHeight) {
std::vector<unsigned int> globalTileIds;
std::istringstream istr(dataStr);
std::string line;
while(std::getline(istr, line)) {
std::stringstream lineStream(line);
std::string globalId;
while(std::getline(lineStream, globalId, ',')) {
// get the global tile ids into unsigned long, as stoui does not exist(it is guranteed to not overflow uint)
unsigned long gidULong = std::stoul(globalId);
if(gidULong > std::numeric_limits<unsigned int>::max()) {
errStream << "Error laoding tiles, global id out of range." << std::endl;
return false;
}
unsigned int gidUInt = static_cast<unsigned int>(gidULong);
globalTileIds.push_back(gidUInt);
}
}
// code truncated...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment