• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
GetDataLineCount()29   size_t GetDataLineCount() const { return data_lines_.size(); }
30 
31   /// Returns the data lines
GetDataLines()32   const std::vector<DataLine> GetDataLines() const { return data_lines_; }
33 
34   /// Returns the data line assocated with the location, or one the number of
35   /// which is zero and the range of which is invalid.
36   DataLine GetDataLine(size_t location) const;
37 
38   /// Finds the next set of data line numbers and ranges in the segment and adds
39   /// them to the map. If the map is empty, the line numbers will start at 1;
40   /// otherwise the numbering of the new lines will start at the next line
41   /// number indicated in the map.
42   void FindDataLines(const DataRange& range, const DataSegment& segment);
43 
44   /// Clears the map and returns it to its startup state.
45   void Clear();
46 
47  private:
48   /// The data lines in the map, sorted by ascending range.GetBegin() value.
49   std::vector<DataLine> data_lines_;
50 
51   /// Whether the last data line in the vector is complete (ended in a newline).
52   bool last_line_incomplete_;
53 };
54 
55 }  // namespace image_io
56 }  // namespace photos_editing_formats
57 
58 #endif // IMAGE_IO_ BASE_DATA_LINE_MAP_H_  // NOLINT
59