wldcrd_mtchr.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) Sergey P. Derevyago, 2008-2009.
00003  *
00004  * Permission to copy, use, modify, sell and distribute this software is granted
00005  * provided this copyright notice appears in all copies.
00006  * This software is provided "as is" without express or implied warranty, and
00007  * with no claim as to its suitability for any purpose.
00008  *
00009  */
00010 
00015 #ifndef __DERS__WLDCRD_MTCHR_HPP__
00016 #define __DERS__WLDCRD_MTCHR_HPP__
00017 
00018 #include <ders/config.hpp>
00019 #include <list>
00020 #include <vector>
00021 #include <ders/stl_alloc.hpp>
00022 #include <ders/text.hpp>
00023 
00024 namespace ders {  // ::ders
00025 
00029 class wldcrd_mtchr {
00030       struct word {
00031              int off;
00032              ch_rng str;
00033 
00034              word(int o, const ch_rng& s) : off(o), str(s) {}
00035       };
00036 
00037       struct segm {
00038              int len;
00039              std::vector<word> wds;
00040 
00041              segm() : len(0) {}
00042       };
00043 
00044       mem_pool& mp;
00045       int len;
00046       std::vector<segm*> sgs;
00047       sh_text sav_msk;
00048       std::list<segm, stl_allocator<segm> > sav_sgs;
00049 
00050       wldcrd_mtchr(const wldcrd_mtchr&);
00051       wldcrd_mtchr& operator=(const wldcrd_mtchr&);
00052 
00053       void add_sg();
00054       bool eq(const char* str, const segm& sg, int beg=0) const;
00055       const char* fnd(const ch_rng& str, const segm& sg) const;
00056 
00057  public:
00058       wldcrd_mtchr(mem_pool& m, const ch_rng& mask);
00059 
00060       const ch_rng mask() const { return sav_msk; }
00061       bool match(const ch_rng& str) const;
00062 };
00063 
00064 typedef sh_ptr<wldcrd_mtchr> sh_wldcrd_mtchr;
00065 
00072 sh_wldcrd_mtchr new_wldcrd_mtchr(mem_pool& mp, const ch_rng& mask);
00073 
00074 }  // namespace ::ders
00075 
00076 #endif  // __DERS__WLDCRD_MTCHR_HPP__
00077 

Generated on Tue Dec 8 11:35:32 2009 for derslib by  doxygen 1.5.5