stringfilter_type.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef STRINGFILTER_TYPE_H
00013 #define STRINGFILTER_TYPE_H
00014 
00015 #include "core/smallvec_type.hpp"
00016 
00032 struct StringFilter {
00033 private:
00035   struct WordState {
00036     const char *start;                         
00037     bool match;                                
00038   };
00039 
00040   const char *filter_buffer;                     
00041   SmallVector<WordState, 4> word_index;          
00042   uint word_matches;                             
00043 
00044   const bool *case_sensitive;                    
00045 
00046 public:
00051   StringFilter(const bool *case_sensitive = NULL) : filter_buffer(NULL), word_matches(0), case_sensitive(case_sensitive) {}
00052   ~StringFilter() { free(this->filter_buffer); }
00053 
00054   void SetFilterTerm(const char *str);
00055 
00060   bool IsEmpty() const { return this->word_index.Length() == 0; }
00061 
00062   void ResetState();
00063   void AddLine(const char *str);
00064 
00069   bool GetState() const { return this->word_matches == this->word_index.Length(); }
00070 };
00071 
00072 #endif /* STRINGFILTER_TYPE_H */