1 2 /* Web Polygraph http://www.web-polygraph.org/ 3 * Copyright 2003-2011 The Measurement Factory 4 * Licensed under the Apache License, Version 2.0 */ 5 6 #ifndef POLYGRAPH__BASE_STRINGRANGE_H 7 #define POLYGRAPH__BASE_STRINGRANGE_H 8 9 #include "xstd/h/iosfwd.h" 10 #include "xstd/Array.h" 11 #include "base/StringArrayBlocks.h" 12 13 class StringRangeBlock; 14 15 // an efficient string range maintainer (e.g., "www[1-3].blah[1-100].com") 16 class StringRange: public StringArrayBlock { 17 public: 18 typedef void (*Iter)(const String &); 19 20 public: 21 StringRange(); 22 StringRange(const StringRange &r); 23 virtual ~StringRange(); 24 25 virtual StringArrayBlock *clone() const; 26 virtual void reset(); 27 28 void currentBase(int aBase); 29 int currentBase() const; 30 31 int count() const; 32 virtual bool find(const Area &member, int &idx) const; 33 34 void iterate(Iter iter) const; 35 String toStr() const; 36 void toStrs(Array<String*> &strs) const; 37 void strAt(int idx, String &str) const; 38 virtual String item(int idx) const; 39 40 virtual ostream &print(ostream &os) const; 41 42 StringRange &operator =(const StringRange &r); 43 44 protected: 45 void startIter() const; 46 bool nextIter() const; 47 bool nextIter(int level) const; 48 void skipIter(int count) const; 49 void currentIter(String &str) const; 50 int iterPos() const; 51 52 int intervalCount() const; // number of interval blocks 53 54 void append(const StringRange &r); 55 void addRangePoint(const String &point); 56 void addRangeInterval(int start, int stop, bool isolated); 57 58 virtual bool canMergeSameType(const StringArrayBlock &b) const; 59 virtual void mergeSameType(const StringArrayBlock &b); 60 61 protected: 62 Array<StringRangeBlock*> theBlocks; // range parts 63 64 private: 65 static TypeAnchor TheTypeAnchor; 66 int theCurrentBase; 67 }; 68 69 #endif 70