This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct GLFunc | |
{ | |
GLFunc(){} | |
GLFunc(const GLFunc& r) { | |
*this = r; | |
} | |
const GLFunc& operator=(const GLFunc& r) { | |
name = r.name; | |
decl = r.decl; | |
caster = r.caster; | |
return *this; | |
} | |
std::string name; | |
std::string decl; | |
std::string caster; | |
}; | |
std::vector<GLFunc> glFuncs; | |
void ParseHeader(const char* healderFileName, const char* regExp, const char* conventions) | |
{ | |
char* h = (char*)LoadFile(healderFileName); | |
std::string str = h; | |
std::regex pattern(regExp); | |
auto funcBegin = std::sregex_iterator(str.begin(), str.end(), pattern); | |
auto End = std::sregex_iterator(); | |
int dist = std::distance(funcBegin, End); | |
printf("%d functions found in %s\n", dist, healderFileName); | |
int i = 0; | |
for (auto it = funcBegin; it != End; it++) { | |
std::smatch m = *it; | |
if (m.size() < 4) { | |
continue; | |
} | |
GLFunc func; | |
func.name = m[2].str(); | |
func.decl = m[1].str() + "(" + conventions + "*" + m[2].str() + ")" + m[3].str(); | |
func.caster = m[1].str() + "(" + conventions + "*)" + m[3].str(); | |
glFuncs.push_back(func); | |
printf("\r%d/%d", ++i, dist); | |
} | |
printf("\n"); | |
free(h); | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
ParseHeader("glheaders/glcorearb.h", "^GLAPI\\s+([\\w\\s\\*]+)APIENTRY\\s+(gl\\w+)\\s*(\\(.*\\))", "APIENTRY"); | |
ParseHeader("glheaders/wglext.h", "^(\\w+(?:\\s+\\w+)*\\s+)WINAPI\\s+(wgl\\w+)\\s*(\\(.*\\))", "WINAPI"); | |
return 0; | |
} |
STLに慣れているとstd::sregex_iteratorが奇妙に見えますが、これで複数のOpenGL関数定義を巡回させます。std::regex_matchでも正規表現を実行できますが、こちらは最初の一回しかマッチさせられません。マッチ結果はstd::smatchを使って戻り値、関数名、引数リストを取り出します。
GitHubはここです。
No comments:
Post a Comment