Overview
様々なファイルタイプを判別するための関数群です.現在のところ,BMP, PNG, GIF, JPEG, WMF, EMF, PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX の 13 種類を実装しています.
尚,DOCX, XLSX, PPTX の判別関数を利用するためには zlib を用意する必要があります.
Example
#include <cstdlib>
#include <iostream>
#include "clx/filetype.h"
int main(int argc, char* argv[]) {
if (argc < 2) std::exit(-1);
std::string path(argv[1]);
std::string type;
if (clx::is_bmp(path, clx::bmptype::os2)) type = "BMP (OS/2 1.x)";
else if (clx::is_bmp(path, clx::bmptype::win)) type = "BMP (Windows)";
else if (clx::is_png(path)) type = "PNG";
else if (clx::is_gif(path)) type = "GIF";
else if (clx::is_jpg(path)) type = "JPEG";
else if (clx::is_wmf(path)) type = "WMF (APM)";
else if (clx::is_wmf(path, false)) type = "WMF (Windows)";
else if (clx::is_emf(path)) type = "EMF";
else if (clx::is_pdf(path)) type = "PDF";
else if (clx::is_doc(path)) type = "DOC (Binary)";
else if (clx::is_xls(path)) type = "XLS (Binary)";
else if (clx::is_ppt(path)) type = "PPT (Binary)";
else if (clx::is_docx(path)) type = "DOCX (OpenXML)";
else if (clx::is_xlsx(path)) type = "XLSX (OpenXML)";
else if (clx::is_pptx(path)) type = "PPTX (OpenXML)";
else type = "unknown file type";
std::cout << argv[1] << ": " << type << std::endl;
return 0;
}
Functions
namespace bmptype {
enum { both = 0, os2, win };
}
bool is_bmp(std::basic_istream<char>& in, int which = bmptype::both);
bool is_bmp(const char* path, int which = bmptype::both);
bool is_bmp(const std::basic_string<char>& path, int which = bmptype::both);
bool is_png(std::basic_istream<char>& in);
bool is_png(const char* path);
bool is_png(const std::basic_string<char>& path);
bool is_gif(std::basic_istream<char>& in);
bool is_gif(const char* path);
bool is_gif(const std::basic_string<char>& path);
bool is_jpg(std::basic_istream<char>& in);
bool is_jpg(const char* path);
bool is_jpg(const std::basic_string<char>& path);
ビットマップ型の各種画像ファイルのための判別関数です.尚,ビットマップファイル (*.bmp) は,OS/2 1.x と Windows 版でヘッダ形式が異なるため,どちらのファイルとして判別するかを第 2 引数で指定します.
bool is_wmf(std::basic_istream<char>& in, bool apm = true); bool is_wmf(const char* path, bool apm = true); bool is_wmf(const std::basic_string<char>& path, bool apm = true); bool is_emf(std::basic_istream<char>& in); bool is_emf(const char* path); bool is_emf(const std::basic_string<char>& path);
Windows で使用されるベクター型の画像ファイルのための判別関数です.尚,WMF は 通常 22Byte Placeable ヘッダ + 18Byte WMF ヘッダと言う形を取りますが, 稀に 18Byte WMF ヘッダのみのファイルも存在します.第 2 引数を true に指定すると, Placeable ヘッダを持つ WMF ファイルの場合のみ true を返します.
bool is_pdf(std::basic_istream<char>& in); bool is_pdf(const char* path); bool is_pdf(const std::basic_string<char>& path);
PDF ファイルかどうかを判別するための関数です.
bool is_ole2(std::basic_istream<char>& in); bool is_ole2(const char* path); bool is_ole2(const std::basic_string<char>& path); bool is_doc(std::basic_istream<char>& in); bool is_doc(const char* path); bool is_doc(const std::basic_string<char>& path); bool is_xls(std::basic_istream<char>& in); bool is_xls(const char* path); bool is_xls(const std::basic_string<char>& path); bool is_ppt(std::basic_istream<char>& in); bool is_ppt(const char* path); bool is_ppt(const std::basic_string<char>& path);
Microsoft Office(2003 以前)の各種ファイルのための判別関数です. Office 2003 以前のファイルは全て OLE2 形式のバイナリファイルなので, DOC (Microsoft Word), XLS (Microsoft Excel), PPT (Microsoft PowerPoint) の判別関数に加えて,OLE2 形式のバイナリファイルかどうかを判別する関数も定義してあります.
bool is_docx(const std::basic_string<char>& path); bool is_docx(const char* path); bool is_xlsx(const std::basic_string<char>& path); bool is_xlsx(const char* path); bool is_pptx(const std::basic_string<char>& path); bool is_pptx(const char* path);
Microsoft Office 2007 の各種ファイルのための判別関数です. これらの関数は,現在のところファイル名を受け取る形しか提供していません. 尚,is_docx(), is_xlsx(), is_pptx() を使用するためにはzlib を用意する必要があります.