XML 文字列を読み取り、XML ファイルの属性キーに一致する値をいくつかの構造体メンバーに入力する C++ を作成しています。現時点では、この最初のパスはキーと値のペアの stl::unordered_map を作成します。次のステップは、値の文字列を解釈し、それらを構造体に格納される目的の型として返すことです。一部の型は少し複雑ですが、それらを変換できるメソッドがあります。
私がやりたいことは、mpl::vector を使用して、get_value_* メソッドを使用してキーを構造体メンバーにマップし、値を変換することです。私はそれが少し似ていると思います:
typedef boost::mpl mpl;
using namespace std;
template<string K, typename T, T& dest, boost::function<void(MapTypePtr, string, T& dest)> >
struct MapperRow {};
struct Mapper : mpl::vector<
MapperRow < "death_star_radius", Length, death_star.radius, get_value_units >,
MapperRow < "death_star_energy", Energy, death_star.energy, get_value_units >,
MapperRow < "operational", bool, death_star.operational, get_value_simple >,
MapperRow < "num_tie_fighters", int, death_star.tie_fighers, get_value_simple >
> {};
Length および Energy タイプは、boost::units::quantities の typedef です。
これはブーストメタプログラミングで実行できますか? 正しい軌道に乗っている場合、どうすれば実行できますか? mpl::vector を繰り返す必要がありますか?