fill WFObj::loadfile(), add Buffer allocation
This commit is contained in:
parent
ffe2fe1d92
commit
a46b5baa05
17
WFObj.cc
17
WFObj.cc
@ -415,7 +415,22 @@ void WFObj::loadMaterial(const std::string & name)
|
||||
|
||||
bool WFObj::loadfile(const char *path, Buffer *buff)
|
||||
{
|
||||
/* TODO */
|
||||
struct stat st;
|
||||
|
||||
if ( (stat(path, &st) == 0) && (st.st_size > 0) )
|
||||
{
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd > 0)
|
||||
{
|
||||
buff->alloc(st.st_size);
|
||||
int num_read = read(fd, buff->data, st.st_size);
|
||||
close(fd);
|
||||
if (num_read > 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WFObj::VertexRef::operator<(const VertexRef & other)
|
||||
|
10
WFObj.h
10
WFObj.h
@ -14,8 +14,18 @@ public:
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer() : m_alloc(false) {}
|
||||
~Buffer() { if (m_alloc) delete data; }
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
void alloc(size_t sz)
|
||||
{
|
||||
length = sz;
|
||||
data = new uint8_t[sz];
|
||||
m_alloc = true;
|
||||
}
|
||||
protected:
|
||||
bool m_alloc;
|
||||
};
|
||||
|
||||
typedef bool (*loadfile_t)(const char *fname, Buffer *buff);
|
||||
|
Loading…
x
Reference in New Issue
Block a user