Use std::getline() to read arbitrary size of line data.

This commit is contained in:
Syoyo Fujita
2016-07-24 15:53:05 +09:00
parent 5ef400882a
commit e3a56816d6

View File

@@ -62,9 +62,9 @@ THE SOFTWARE.
#ifndef TINY_OBJ_LOADER_H_
#define TINY_OBJ_LOADER_H_
#include <map>
#include <string>
#include <vector>
#include <map>
namespace tinyobj {
@@ -112,8 +112,9 @@ typedef struct {
typedef struct {
std::vector<index_t> indices;
std::vector<unsigned char>
num_face_vertices; // The number of vertices per face. 3 = polygon, 4 = quad, ... Up to 255.
std::vector<unsigned char> num_face_vertices; // The number of vertices per
// face. 3 = polygon, 4 = quad,
// ... Up to 255.
std::vector<int> material_ids; // per-face material ID
std::vector<tag_t> tags; // SubD tag
} mesh_t;
@@ -223,12 +224,12 @@ void LoadMtl(std::map<std::string, int> *material_map,
} // namespace tinyobj
#ifdef TINYOBJLOADER_IMPLEMENTATION
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <fstream>
@@ -616,7 +617,8 @@ static bool exportFaceGroupToShape(
shape->mesh.indices.push_back(idx);
}
shape->mesh.num_face_vertices.push_back(static_cast<unsigned char>(npolys));
shape->mesh.num_face_vertices.push_back(
static_cast<unsigned char>(npolys));
shape->mesh.material_ids.push_back(material_id); // per face
}
}
@@ -926,12 +928,9 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
shape_t shape;
int maxchars = 8192; // Alloc enough size.
std::vector<char> buf(static_cast<size_t>(maxchars)); // Alloc enough size.
while (inStream->peek() != -1) {
inStream->getline(&buf[0], maxchars);
std::string linebuf(&buf[0]);
std::string linebuf;
std::getline((*inStream), linebuf);
// Trim newline '\r\n' or '\n'
if (linebuf.size() > 0) {
@@ -1374,7 +1373,6 @@ bool LoadObjWithCallback(void *user_data, const callback_t &callback,
} else {
callback.group_cb(user_data, NULL, 0);
}
}
continue;