1 #ifndef IMAGE_IO_BASE_DATA_LINE_MAP_H_ // NOLINT 2 #define IMAGE_IO_BASE_DATA_LINE_MAP_H_ // NOLINT 3 4 #include <vector> 5 6 #include "image_io/base/data_range.h" 7 #include "image_io/base/data_segment.h" 8 9 namespace photos_editing_formats { 10 namespace image_io { 11 12 /// The line number and range of a text line in a data source. The range does 13 /// not include the terminating new line. Valid line numbers are greater than 0. 14 struct DataLine { DataLineDataLine15 DataLine() : number(0) {} DataLineDataLine16 DataLine(size_t a_number, const DataRange& a_range) 17 : number(a_number), range(a_range) {} 18 size_t number; 19 DataRange range; 20 }; 21 22 /// A class that maps a data source location to a data line structure that has 23 /// the line number and data range of the line. 24 class DataLineMap { 25 public: DataLineMap()26 DataLineMap() : last_line_incomplete_(false) {} 27 28 /// Returns the number of data lines in the map. 29 size_t GetDataLineCount() const; 30 31 /// Returns the data line assocated with the location, or one the number of 32 /// which is zero and the range of which is invalid. 33 DataLine GetDataLine(size_t location) const; 34 35 /// Finds the next set of data line numbers and ranges in the segment and adds 36 /// them to the map. If the map is empty, the line numbers will start at 1; 37 /// otherwise the numbering of the new lines will start at the next line 38 /// number indicated in the map. 39 void FindDataLines(const DataRange& range, const DataSegment& segment); 40 41 /// Clears the map and returns it to its startup state. 42 void Clear(); 43 44 private: 45 /// The data lines in the map, sorted by ascending range.GetBegin() value. 46 std::vector<DataLine> data_lines_; 47 48 /// Whether the last data line in the vector is complete (ended in a newline). 49 bool last_line_incomplete_; 50 }; 51 52 } // namespace image_io 53 } // namespace photos_editing_formats 54 55 #endif // IMAGE_IO_ BASE_DATA_LINE_MAP_H_ // NOLINT 56