1 // $Id$ 2 // Copyright (c) 2001,2002 RIPE NCC 3 // 4 // All Rights Reserved 5 // 6 // Permission to use, copy, modify, and distribute this software and its 7 // documentation for any purpose and without fee is hereby granted, 8 // provided that the above copyright notice appear in all copies and that 9 // both that copyright notice and this permission notice appear in 10 // supporting documentation, and that the name of the author not be 11 // used in advertising or publicity pertaining to distribution of the 12 // software without specific, written prior permission. 13 // 14 // THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15 // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 16 // AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 17 // DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 18 // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 // 21 // 22 // Copyright (c) 1994 by the University of Southern California 23 // All rights reserved. 24 // 25 // Permission is hereby granted, free of charge, to any person obtaining a copy 26 // of this software and associated documentation files (the "Software"), to deal 27 // in the Software without restriction, including without limitation the rights 28 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 // copies of the Software, and to permit persons to whom the Software is 30 // furnished to do so, subject to the following conditions: 31 // 32 // The above copyright notice and this permission notice shall be included in 33 // all copies or substantial portions of the Software. 34 // 35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 // THE SOFTWARE. 42 // 43 // Questions concerning this software should be directed to 44 // irrtoolset@cs.usc.edu. 45 // 46 // Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU> 47 48 #ifndef FilterOfASPath_H 49 #define FilterOfASPath_H 50 51 #include "config.h" 52 #include "Filter.hh" 53 #include "re2dfa/regexp_nf.hh" 54 55 #ifndef TRUE 56 #define TRUE 1 57 #define FALSE 0 58 #endif // TRUE 59 60 class FilterOfASPath : public NEFilter { 61 public: 62 friend class JunosConfig; 63 FilterOfASPath()64 FilterOfASPath() { 65 re = new regexp_nf(new regexp_empty_set); 66 }; ~FilterOfASPath()67 ~FilterOfASPath() { 68 if (re) 69 delete re; 70 } FilterOfASPath(const FilterOfASPath & other)71 FilterOfASPath(const FilterOfASPath& other) { 72 re = other.re->dup_nf(); 73 } 74 isEmpty()75 virtual int isEmpty() { 76 return re->isEmpty(); 77 } 78 is_universal()79 virtual int is_universal() { 80 return re->is_universal(); 81 } 82 is_empty()83 virtual int is_empty() { 84 return re->isEmpty(); 85 } 86 is_empty_str()87 virtual int is_empty_str() { 88 return re->isEmptyStr(); 89 } 90 make_universal()91 virtual void make_universal() { 92 re->become_universal(); 93 } 94 make_empty()95 virtual void make_empty() { 96 re->become_empty(); 97 } 98 compile(regexp * r,ASt peerAS)99 void compile(regexp *r, ASt peerAS) { 100 delete re; 101 re = new regexp_nf(r->dup(), peerAS); 102 } 103 operator ~()104 virtual void operator ~ () { // complement 105 re->do_not(); 106 } 107 operator |=(FilterOfASPath & b)108 void operator |= (FilterOfASPath& b) { // union 109 re->do_or(*b.re); // makes b empty 110 } 111 operator &=(FilterOfASPath & b)112 void operator &= (FilterOfASPath& b) { // intersection 113 re->do_and(*b.re); // makes b empty 114 } 115 operator ==(FilterOfASPath & b)116 int operator == (FilterOfASPath& b) { // equivalance 117 return *re == *b.re; 118 } 119 operator =(FilterOfASPath & b)120 void operator = (FilterOfASPath& b) { // assignment 121 delete re; 122 re = b.re->dup_nf(); 123 } 124 125 // below is an ugly trick operator |=(NEFilter & b)126 virtual void operator |= (NEFilter& b) { 127 *this |= (FilterOfASPath&) b; 128 } operator &=(NEFilter & b)129 virtual void operator &= (NEFilter& b) { 130 *this &= (FilterOfASPath&) b; 131 } operator ==(NEFilter & b)132 virtual int operator == (NEFilter& b) { 133 return (*this == (FilterOfASPath&) b); 134 } operator =(NEFilter & b)135 virtual void operator = (NEFilter& b) { 136 *this = (FilterOfASPath&) b; 137 } 138 139 virtual void do_print (std::ostream& stream); 140 141 CLASS_DEBUG_MEMORY_HH(FilterOfASPath); 142 operator regexp_nf&()143 operator regexp_nf&() { 144 return *re; 145 } 146 147 private: 148 regexp_nf *re; 149 }; 150 151 152 #endif // FilterOfASPath_H 153