19 #ifndef OST_IO_STAR_PARSER_HH
20 #define OST_IO_STAR_PARSER_HH
26 #include <boost/iostreams/filtering_stream.hpp>
35 namespace ost {
namespace io {
48 category_(category), name_(name), value_(value)
65 int GetIndex(
const String& name)
const
67 std::map<String, int>::const_iterator i=index_map_.find(name);
68 return i==index_map_.end() ? -1 : i->second;
73 category_=category.
str();
78 index_map_.insert(std::make_pair(name.
str(), index_map_.size()));
80 size_t GetSize()
const
82 return index_map_.size();
93 std::map<String, int> index_map_;
120 explicit StarParser(std::istream& stream,
bool items_as_row=
false);
138 const std::vector<StringRef>& columns)
176 std::pair<bool, float> TryGetFloat(
const StringRef& data,
178 bool may_fail)
const;
195 std::pair<bool, int> TryGetInt(
const StringRef& data,
197 bool may_fail)
const;
213 filename_ = filename;
217 int GetCurrentLinenum()
const
225 static bool SplitLine(
const StringRef& line,
226 std::vector<StringRef>& parts,
bool clear=
true);
231 void ParseLastDataItemRow();
236 void ParseEndDataItemRow();
241 if (std::getline(stream_, current_line_)) {
242 str=
StringRef(current_line_.data(), current_line_.length());
244 has_current_line_=
true;
250 bool GetLine(StringRef& ref)
252 if (has_current_line_) {
253 ref=StringRef(current_line_.data(), current_line_.size());
256 return this->NextLine(ref);
261 assert(has_current_line_);
262 has_current_line_=
false;
265 void ParseDataItemIdent(
const StringRef ident,
266 StringRef& cat, StringRef& name);
269 void ParseDataItem();
270 void DiagnoseUnknown();
271 bool ParseMultilineValue(
String& value,
bool skip=
false);
272 std::ifstream fstream_;
273 boost::iostreams::filtering_stream<boost::iostreams::input> stream_;
276 bool has_current_line_;
279 StarLoopDesc items_row_header_;
281 std::vector<StringRef> items_row_columns_;
282 std::vector<String> items_row_values_;