Exemplo n.º 1
0
std::tr1::shared_ptr<std::vector<char> > ImageServer::GetImage(std::string& category, uint32 id, uint32 size)
{
    if (!ValidateCategory(category) || !ValidateSize(category, size))
        return std::tr1::shared_ptr<std::vector<char> >();

    //std::ifstream stream;
    std::string path(GetFilePath(category, id, size));
    FILE * fp = fopen(path.c_str(), "rb");
    if (fp == NULL)
        return std::tr1::shared_ptr<std::vector<char> >();
    fseek(fp, 0, SEEK_END);
    size_t length = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    //stream.open(path, std::ios::binary | std::ios::in);
    // not found or other error
    //if (stream.fail())
    //    return std::tr1::shared_ptr<std::vector<char> >();

    // get length
    //stream.seekg(0, std::ios::end);
    //int length = stream.tellg();
    //stream.seekg(0, std::ios::beg);

    std::tr1::shared_ptr<std::vector<char> > ret = std::tr1::shared_ptr<std::vector<char> >(new std::vector<char>());
    ret->resize(length);

    // HACK
    //stream.read(&((*ret)[0]), length);
    fread(&((*ret)[0]), 1, length, fp);

    return ret;
}
Exemplo n.º 2
0
std::shared_ptr<std::vector<char>> ImageServer::GetImage(std::string& category, uint32 id, uint32 size)
{
	if (!ValidateCategory(category) || !ValidateSize(category, size))
		return std::shared_ptr<std::vector<char>>();

	std::ifstream stream;
	std::string path(GetFilePath(category, id, size));
	stream.open(path, std::ios::binary | std::ios::in);
	// not found or other error
	if (stream.fail())
		return std::shared_ptr<std::vector<char>>();

	// get length
	stream.seekg(0, std::ios::end);
	int length = stream.tellg();
	stream.seekg(0, std::ios::beg);

	auto ret = std::shared_ptr<std::vector<char>>(new std::vector<char>());
	ret->resize(length);

	// HACK
	stream.read(&((*ret)[0]), length);

	return ret;
}