So far the thrift compiler doesn't depend on boost -- only the
generated bindings do. (Correct?)
I'm hoping to refactor the haskell code generator to something more
readable once 0.5 is safely out. I'd like to use sprintf-like template
strings to make the haskell code inside the generator looks as much
like the one that comes out, instead of a series of << operators,
which become unreadable with more than one or two vars to replace.
Two choices: boost::format, or roll my own:
class strtmpl : public string {
string tmpl_;
public:
strtmpl(const char* tmpl)
: tmpl_(tmpl) { }
strtmpl(const string& tmpl)
: tmpl_(tmpl) { }
string convert() const {
return tmpl_;
}
strtmpl replace(const char* var, int value) {
ostringstream ss;
ss << value;
return replace(var, ss.str());
}
strtmpl replace(const char* var, const char* replacement) {
return replace(var, string(replacement));
}
strtmpl replace(const char* var, const string& replacement) {
string retval = tmpl_;
size_t idx = retval.find(var);
while (string::npos != idx) {
retval = retval.replace(idx, strlen(var), replacement);
idx = retval.find(var);
}
return strtmpl(retval);
}
};
And use it thusly:
f_types_ << strtmpl("$PRAGMAS"
"\n"
"$AUTOGEN_COMMENTS"
"\n"
"module $PNAME_Types where\n"
"\n"
"\n"
"$IMPORTS\n"
"\n")
.replace("$PRAGMAS", hs_language_pragma())
.replace("$AUTOGEN_COMMENTS", hs_autogen_comment())
.replace("$PNAME", pname)
.replace("$IMPORTS", hs_imports())
.convert();
I'd much rather use boost, but it's an extra dependency that isn't
needed yet at compile time (it is if you want to use the generated cpp
bindings). Thoughts?
--
Have fun, Christian
http://linkedin.christianlavoie.net
"I won't let you fall apart."