From 3b98f3439e33b15bba2036c402f9925340fdb2b9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 29 Jun 2013 23:23:43 -0700 Subject: Poison std::string and use the various string classes --- src/map/grfio.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/map/grfio.cpp') diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp index a190d1b..cbb5a86 100644 --- a/src/map/grfio.cpp +++ b/src/map/grfio.cpp @@ -15,11 +15,12 @@ #include "../common/cxxstdio.hpp" #include "../common/extract.hpp" +#include "../common/io.hpp" #include "../poison.hpp" static -std::map load_resnametable() +std::map load_resnametable() { std::ifstream in("data/resnametable.txt"); if (!in.is_open()) @@ -27,12 +28,13 @@ std::map load_resnametable() fprintf(stderr, "Missing data/resnametable.txt"); abort(); } - std::map out; + std::map out; - std::string line; - while (std::getline(in, line)) + FString line; + while (io::getline(in, line)) { - std::string key, value; + MapName key; + FString value; if (!extract(line, record<'#'>(&key, &value))) continue; @@ -43,29 +45,32 @@ std::map load_resnametable() /// Change *.gat to *.wlk static -std::string grfio_resnametable(const_string rname) +FString grfio_resnametable(MapName rname) { static - std::map resnametable = load_resnametable(); + std::map resnametable = load_resnametable(); - return resnametable.at(std::string(rname.begin(), rname.end())); + return resnametable.at(rname); } -std::vector grfio_reads(const_string rname) +std::vector grfio_reads(MapName rname) { - std::string lfname = "data/" + grfio_resnametable(rname); + MString lfname_; + lfname_ += "data/"; + lfname_ += grfio_resnametable(rname); + FString lfname = FString(lfname_); int fd = open(lfname.c_str(), O_RDONLY); if (fd == -1) { FPRINTF(stderr, "Resource %s (file %s) not found\n", - std::string(rname.begin(), rname.end()), lfname); + rname, lfname); return {}; } off_t len = lseek(fd, 0, SEEK_END); assert (len != -1); std::vector buffer(len); - int err = pread(fd, buffer.data(), len, 0); + ssize_t err = pread(fd, buffer.data(), len, 0); assert (err == len); close(fd); return buffer; -- cgit v1.2.3-60-g2f50