嗨,他有一个外部库函数,该函数具有以下功能:
log_bin_trust_function_creators = 1
调用此函数后进行一些处理时,我需要一种方法来说明什么是“空ImageData”,类似于:
struct ImageData {
int rows;
int cols;
int max_val;
std::vector<int> data;
};
/// Reads from a pgm image from ascii file. Returns empty ImageData if the path
/// is not found or any errors have occured while reading.
ImageData ReadFromPgm(const std::string& file_name);
答案 0 :(得分:1)
由于没有更多的API文档,我们只能做一个假设。 空ImageData 最有可能表示ImageData
类型(ImageData id = { }
);的默认(初始化)值。这意味着其所有字段的默认值。在这种情况下,您可以做一个简单的检查:
ImageData read_from_pgm = ReadFromPgm(some_file);
if (read_from_pgm.rows == 0
&& read_from_pgm.cols == 0
&& read_from_pgm.max_val == 0
&& read_from_pgm.data.size() == 0)
{ //Image is empty }
请注意,检查所有字段并非绝对必要。我认为只检查rows
或data.size()
也是可以的,因为有效的图像应始终包含一些行或数据。