Source-highlight Library
|
00001 /* 00002 * lineranges.h 00003 * 00004 * Created on: Sep 17, 2008 00005 * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2008 00006 * Copyright: See COPYING file that comes with this distribution 00007 */ 00008 00009 #ifndef LINERANGES_H_ 00010 #define LINERANGES_H_ 00011 00012 #include <set> 00013 #include <string> 00014 00015 namespace srchilite { 00016 00018 enum RangeError { 00019 NO_ERROR = 0, INVALID_RANGE_NUMBER 00020 }; 00021 00023 enum RangeResult { 00024 NOT_IN_RANGE = 0, CONTEXT_RANGE, IN_RANGE 00025 }; 00026 00038 class LineRanges { 00039 public: 00040 LineRanges(unsigned int contextLines = 0); 00041 ~LineRanges(); 00042 00043 typedef int RangeElemType; 00044 typedef std::pair<RangeElemType, RangeElemType> RangeType; 00045 00046 typedef std::set<RangeType> LineRangeSet; 00047 00060 RangeError addRange(const std::string &range); 00061 00062 const LineRangeSet &getLineRangeSet() const { 00063 return lineRangeSet; 00064 } 00065 00071 void reset() { 00072 searchFromTheStart = true; 00073 } 00074 00082 RangeResult isInRange(const RangeElemType e); 00083 00084 void setContextLines(unsigned int context) { 00085 contextLines = context; 00086 } 00087 00088 private: 00089 LineRangeSet lineRangeSet; 00090 00094 bool searchFromTheStart; 00095 00099 LineRangeSet::const_iterator currentRange; 00100 00105 int contextLines; 00106 }; 00107 00108 } 00109 00110 #endif /* LINERANGES_H_ */