Source-highlight Library
lineranges.h
1 /*
2  * lineranges.h
3  *
4  * Created on: Sep 17, 2008
5  * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2008
6  * Copyright: See COPYING file that comes with this distribution
7  */
8 
9 #ifndef LINERANGES_H_
10 #define LINERANGES_H_
11 
12 #include <set>
13 #include <string>
14 
15 namespace srchilite {
16 
18 enum RangeError {
19  NO_ERROR = 0, INVALID_RANGE_NUMBER
20 };
21 
24  NOT_IN_RANGE = 0, CONTEXT_RANGE, IN_RANGE
25 };
26 
38 class LineRanges {
39 public:
40  LineRanges(unsigned int contextLines = 0);
41  ~LineRanges();
42 
43  typedef int RangeElemType;
44  typedef std::pair<RangeElemType, RangeElemType> RangeType;
45 
46  typedef std::set<RangeType> LineRangeSet;
47 
60  RangeError addRange(const std::string &range);
61 
62  const LineRangeSet &getLineRangeSet() const {
63  return lineRangeSet;
64  }
65 
71  void reset() {
72  searchFromTheStart = true;
73  }
74 
82  RangeResult isInRange(const RangeElemType e);
83 
84  void setContextLines(unsigned int context) {
85  contextLines = context;
86  }
87 
88 private:
89  LineRangeSet lineRangeSet;
90 
95 
99  LineRangeSet::const_iterator currentRange;
100 
106 };
107 
108 }
109 
110 #endif /* LINERANGES_H_ */
bool searchFromTheStart
whether to perform the search from the first element of the set
Definition: lineranges.h:94
int contextLines
The number of lines making the context (i.e., the number of lines that are not part of a range but ar...
Definition: lineranges.h:105
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
RangeResult isInRange(const RangeElemType e)
Checks whether the passed element is in a range of this set.
Definition: lineranges.cpp:58
LineRangeSet::const_iterator currentRange
The current range for performing the search of isInRange.
Definition: lineranges.h:99
Functionalities for detecting whether a line is in one of the stored line ranges (or in the context o...
Definition: lineranges.h:38
RangeError
a possible error in specifying a range
Definition: lineranges.h:18
RangeResult
result for a check whether a number is in a range (or in a context)
Definition: lineranges.h:23
void reset()
The next isInRange search will start from the first element of the set.
Definition: lineranges.h:71
RangeError addRange(const std::string &range)
Adds a range to the set.
Definition: lineranges.cpp:40