void load_file2(std::wstring& wstrOut, std::wistream& wistreamIn)
{
	wstrOut.erase();
	//bad() 如果出现错误则返回true 
	if(wistreamIn.bad()) 
		return;
	wstrOut.reserve(wistreamIn.rdbuf()->in_avail());
	wchar_t c;
	//get() 读取字符 
	while(wistreamIn.get(c))
	{
		if(wstrOut.capacity() == wstrOut.size())
			wstrOut.reserve(wstrOut.capacity() * 3);
		wstrOut.append(1, c);
	}
}
Beispiel #2
0
int bmc2ly( std::wistream &wistream
          , bool lilypond, bool musicxml
          , bool include_locations, std::string instrument, bool no_tagline
          ) {
  std::istreambuf_iterator<wchar_t> wcin_begin(wistream.rdbuf()), wcin_end;
  std::wstring source(wcin_begin, wcin_end);
  typedef std::wstring::const_iterator iterator_type;

  iterator_type iter = source.begin();
  iterator_type const end = source.end();
  typedef ::bmc::braille::error_handler<iterator_type> error_handler_type;
  error_handler_type error_handler(iter, end);
  typedef ::bmc::braille::score_grammar<iterator_type> parser_type;
  parser_type parser(error_handler);
  boost::spirit::traits::attribute_of<parser_type>::type score;

  bool const success = parse(iter, end, parser, score);

  if (success and iter == end) {
    ::bmc::braille::compiler<error_handler_type> compile(error_handler);
    if (compile(score)) {
      std::wcerr << error_handler;
      if (lilypond) {
        ::bmc::lilypond::generator generate(std::cout, true, true, include_locations);
        if (not instrument.empty()) generate.instrument(instrument);
        if (no_tagline) generate.remove_tagline();
        generate(score);
      }
      if (musicxml) {
        ::bmc::musicxml(std::cout, score);
      }
      return EXIT_SUCCESS;
    } else {
      std::wcerr << "Failed to compile:" << std::endl << error_handler << std::endl;
    }
  } else {
    std::wcerr << "Failed to Parse:" << std::endl << source << std::endl;
  }

  return EXIT_FAILURE;
}