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__RUNTIME_ADDRSUBSTS_H 7 #define POLYGRAPH__RUNTIME_ADDRSUBSTS_H 8 9 #include "xstd/Array.h" 10 #include "xstd/NetAddr.h" 11 12 class AddrSubsts; 13 class ContainerSym; 14 15 16 // addr iterator for the map below 17 class AddrSubstsIter { 18 public: 19 AddrSubstsIter(const AddrSubsts &aSubs, const NetAddr &orig); 20 21 operator void *() const { return atEnd() ? 0 : (void*)-1; } 22 AddrSubstsIter &operator ++() { ++theAddrIdx; sync(); return *this; } 23 24 const NetAddr &addr(); 25 26 protected: 27 bool atEnd() const; 28 void sync(); 29 30 protected: 31 const AddrSubsts &theSubs; 32 NetAddr theOrig; 33 int theGroupIdx; 34 int theAddrIdx; 35 bool checkMemb; 36 }; 37 38 // one substitute group (addresses than can substitute each other) 39 class AddrSubstGroup: public Array<NetAddr*> { 40 public: 41 typedef Array<NetAddr*> Addrs; 42 43 public: 44 AddrSubstGroup(int aCap); 45 void configure(const ContainerSym &group); 46 47 bool member(const NetAddr &addr) const; 48 }; 49 50 // all substitute groups 51 class AddrSubsts { 52 public: 53 friend class AddrSubstsIter; 54 typedef AddrSubstGroup Group; 55 typedef Array<Group*> Groups; 56 typedef AddrSubstsIter Iterator; 57 58 public: 59 AddrSubsts(); 60 ~AddrSubsts(); 61 62 void configure(const Array<ContainerSym*> &groups); 63 count()64 int count() const { return theCount; } 65 66 Iterator iterator(const NetAddr &orig) const; 67 68 protected: 69 const NetAddr &at(int group, int idx) const; 70 71 protected: 72 Groups theGroups; 73 int theCount; // all addresses in all groups 74 }; 75 76 extern AddrSubsts *TheAddrSubsts; 77 78 #endif 79