| 462 | {} |
| 463 | |
| 464 | int Variable::dump_exposed(Dumper* dumper, const DumpOptions* poptions) { |
| 465 | if (NULL == dumper) { |
| 466 | LOG(ERROR) << "Parameter[dumper] is NULL"; |
| 467 | return -1; |
| 468 | } |
| 469 | DumpOptions opt; |
| 470 | if (poptions) { |
| 471 | opt = *poptions; |
| 472 | } |
| 473 | CharArrayStreamBuf streambuf; |
| 474 | std::ostream os(&streambuf); |
| 475 | int count = 0; |
| 476 | WildcardMatcher black_matcher(opt.black_wildcards, |
| 477 | opt.question_mark, |
| 478 | false); |
| 479 | WildcardMatcher white_matcher(opt.white_wildcards, |
| 480 | opt.question_mark, |
| 481 | true); |
| 482 | |
| 483 | std::ostringstream dumpped_info; |
| 484 | const bool log_dummped = FLAGS_bvar_log_dumpped; |
| 485 | |
| 486 | if (white_matcher.wildcards().empty() && |
| 487 | !white_matcher.exact_names().empty()) { |
| 488 | for (std::set<std::string>::const_iterator |
| 489 | it = white_matcher.exact_names().begin(); |
| 490 | it != white_matcher.exact_names().end(); ++it) { |
| 491 | const std::string& name = *it; |
| 492 | if (!black_matcher.match(name)) { |
| 493 | if (bvar::Variable::describe_exposed( |
| 494 | name, os, opt.quote_string, opt.display_filter) != 0) { |
| 495 | continue; |
| 496 | } |
| 497 | if (log_dummped) { |
| 498 | dumpped_info << '\n' << name << ": " << streambuf.data(); |
| 499 | } |
| 500 | if (!dumper->dump(name, streambuf.data())) { |
| 501 | return -1; |
| 502 | } |
| 503 | streambuf.reset(); |
| 504 | ++count; |
| 505 | } |
| 506 | } |
| 507 | } else { |
| 508 | // Have to iterate all variables. |
| 509 | std::vector<std::string> varnames; |
| 510 | bvar::Variable::list_exposed(&varnames, opt.display_filter); |
| 511 | // Sort the names to make them more readable. |
| 512 | std::sort(varnames.begin(), varnames.end()); |
| 513 | for (std::vector<std::string>::const_iterator |
| 514 | it = varnames.begin(); it != varnames.end(); ++it) { |
| 515 | const std::string& name = *it; |
| 516 | if (white_matcher.match(name) && !black_matcher.match(name)) { |
| 517 | if (bvar::Variable::describe_exposed( |
| 518 | name, os, opt.quote_string, opt.display_filter) != 0) { |
| 519 | continue; |
| 520 | } |
| 521 | if (log_dummped) { |