33 load_status_ = DIMENSION_SECTION;
35 if (load_status_ == ERROR_FOUND)
break;
40 if (load_status_ == ERROR_FOUND) {
44 return vbp_.item_size() == num_declared_items_;
47void VbpParser::ReportError(
const std::string&
line) {
48 LOG(ERROR) <<
"Error: status = " << load_status_ <<
", line = " <<
line;
49 load_status_ = ERROR_FOUND;
52void VbpParser::ProcessLine(
const std::string&
line) {
53 const std::vector<std::string> words =
54 absl::StrSplit(
line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
56 if (words.empty())
return;
58 switch (load_status_) {
60 LOG(FATAL) <<
"Should not be here";
62 case DIMENSION_SECTION: {
63 if (words.size() != 1) {
67 num_resources_ = strtoint32(words[0]);
68 load_status_ = BIN_SECTION;
72 if (words.size() != num_resources_) {
76 for (
const std::string& dim_str : words) {
77 vbp_.add_resource_capacity(strtoint64(dim_str));
79 load_status_ = NUMBER_OF_ITEMS_SECTION;
82 case NUMBER_OF_ITEMS_SECTION: {
83 if (words.size() != 1) {
87 num_declared_items_ = strtoint32(words[0]);
88 load_status_ = ITEM_SECTION;
92 if (words.size() != num_resources_ + 1) {
96 Item*
const item = vbp_.add_item();
97 for (
int i = 0;
i < num_resources_; ++
i) {
98 item->add_resource_usage(strtoint64(words[i]));
100 item->set_num_copies(strtoint32(words[num_resources_]));
101 item->set_max_number_of_copies_per_bin(item->num_copies());
110int VbpParser::strtoint32(absl::string_view word) {
112 CHECK(absl::SimpleAtoi(word, &result));
116int64_t VbpParser::strtoint64(absl::string_view word) {
118 CHECK(absl::SimpleAtoi(word, &result));