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__PGL_PGLSTRBLOCKS_H 7 #define POLYGRAPH__PGL_PGLSTRBLOCKS_H 8 9 10 // represents one "block" of a string [range] 11 class PglStrBlock { 12 public: 13 enum Type { sbtNone = 0, sbtPoint, sbtRange, sbtEnd }; 14 15 public: PglStrBlock(Type aType)16 PglStrBlock(Type aType): theType(aType) {} ~PglStrBlock()17 virtual ~PglStrBlock() {} 18 type()19 int type() const { return theType; } 20 21 virtual int count() const = 0; 22 virtual PglStrBlock *clone() const = 0; 23 24 int diffCount(const PglStrBlock &b) const; 25 void merge(PglStrBlock &b); 26 27 virtual bool atLast() const = 0; 28 virtual int pos() const = 0; 29 30 virtual void start() = 0; 31 virtual void next() = 0; 32 virtual void pos(int aPos) = 0; 33 34 virtual void print(ostream &os) const = 0; 35 virtual void printCur(ostream &os) const = 0; 36 37 protected: 38 int theType; 39 }; 40 41 class PglStrPointBlock: public PglStrBlock { 42 public: 43 PglStrPointBlock(const char *aStart, const char *aStop); 44 45 virtual int count() const; 46 virtual PglStrBlock *clone() const; 47 48 int countDiffs(const PglStrPointBlock &b) const; 49 void mergeWith(const PglStrPointBlock &b); 50 51 virtual bool atLast() const; 52 virtual int pos() const; 53 54 virtual void start(); 55 virtual void next(); 56 virtual void pos(int aPos); 57 58 virtual void print(ostream &os) const; 59 virtual void printCur(ostream &os) const; 60 61 protected: 62 const char *theStart; 63 const char *theStop; 64 }; 65 66 class PglStrRangeBlock: public PglStrBlock { 67 public: 68 PglStrRangeBlock(int aStart, int aStop, bool beIsolated); 69 70 virtual int count() const; 71 virtual PglStrBlock *clone() const; 72 73 int countDiffs(const PglStrRangeBlock &b) const; 74 void mergeWith(const PglStrRangeBlock &b); 75 76 virtual bool atLast() const; 77 virtual int pos() const; 78 79 virtual void start(); 80 virtual void next(); 81 virtual void pos(int aPos); 82 83 virtual void print(ostream &os) const; 84 virtual void printCur(ostream &os) const; 85 86 protected: 87 bool contains(int pos) const; 88 89 protected: 90 int theStart; 91 int theStop; 92 93 int thePos; 94 95 bool isIsolated; 96 }; 97 98 #endif 99