fix by revier comments

This commit is contained in:
Tomonobu Saito 2019-11-06 11:06:29 +09:00
parent 9c1c842b79
commit fd0f1b60bb
2 changed files with 9 additions and 14 deletions

View File

@ -54,22 +54,21 @@ class RasterGrid
// Construct FileReader // Construct FileReader
storage::io::FileReader file_reader(filepath, storage::io::FileReader::HasNoFingerprint); storage::io::FileReader file_reader(filepath, storage::io::FileReader::HasNoFingerprint);
std::string buf; std::string buffer;
buf.resize(xdim * 11); // INT32_MAX = 2147483647 = 10 chars + 1 white space = 11 buffer.resize(xdim * 11); // INT32_MAX = 2147483647 = 10 chars + 1 white space = 11
BOOST_ASSERT(xdim * 11 <= buf.size()); BOOST_ASSERT(xdim * 11 <= buffer.size());
for (unsigned int y = 0; y < ydim; y++) for (unsigned int y = 0; y < ydim; y++)
{ {
// read one line from file. // read one line from file.
file_reader.ReadLine(&buf[0], xdim * 11); file_reader.ReadLine(&buffer[0], xdim * 11);
boost::algorithm::trim(buf); boost::algorithm::trim(buffer);
std::vector<std::string> result; std::vector<std::string> result;
boost::split( boost::split(
result, buf, boost::is_any_of(" \r\n\0"), boost::algorithm::token_compress_on); result, buffer, boost::is_any_of(" \r\n\0"), boost::algorithm::token_compress_on);
// boost::split(result, buf, boost::is_any_of(" \r\n\0"));
unsigned int x = 0; unsigned int x = 0;
BOOST_FOREACH (std::string s, result) for (const auto &s : result)
{ {
if (x < xdim) if (x < xdim)
_data[(y * xdim) + x] = atoi(s.c_str()); _data[(y * xdim) + x] = atoi(s.c_str());

8
include/storage/io.hpp Normal file → Executable file
View File

@ -80,12 +80,8 @@ class FileReader
{ {
if (0 < count) if (0 < count)
{ {
const auto &ios = memset(dest, 0, count * sizeof(T));
input_stream.getline(reinterpret_cast<char *>(dest), count * sizeof(T)); input_stream.getline(reinterpret_cast<char *>(dest), count * sizeof(T));
for (std::size_t n = ios.gcount(); n < count; ++n)
{
reinterpret_cast<char *>(dest)[n] = '\0';
}
} }
} }