「残り」(つまり、非バイナリ データ) が PEG パーサー ジェネレーターの使用を正当化するかどうかは判断できません。
ただし、最初に何かを提供するだけです。
使用する
qi::bin_float
、qi::little_bin_float
またはqi::big_bin_float
qi::bin_double
、qi::little_bin_double
またはqi::big_bin_double
の動作を正確に複製する 17 行のサンプル プログラムを次に示します。
od -w8 -A none -t f8 -v input.dat
私の箱に:
#include <boost/spirit/include/qi.hpp>
#include <fstream>
#include <iomanip>
namespace qi = boost::spirit::qi;
int main() {
using namespace std;
// read file
ifstream ifs("input.dat", ios::binary);
string const input { istreambuf_iterator<char>(ifs), {} };
// parse
vector<double> result;
bool ret = qi::parse(begin(input), end(input), *qi::bin_double, result);
// print
if (ret) for (auto v : result)
cout << setw(28) << setprecision(16) << right << v << "\n";
}
Coliruでライブを見る
使用するコマンド:
clang++ -Os -std=c++11 -Wall -pedantic main.cpp # compile
dd if=/dev/urandom count=32 bs=1 2>/dev/null > input.dat # generate input
./a.out # spirit demo
echo 'And `od` output:'
od -w8 -A none -t f8 -v /tmp/input.dat # compare to `od`
免責事項これは、Spirit がバイナリ入力をどのように処理するかを理解するのに役立つ場合に備えて意図したものです。