00001 namespace search_tools {
00002
00003 PFC_DECLARE_EXCEPTION(exception_parse_error,pfc::exception,"Error parsing filter expression");
00004
00005 class filter_node;
00006
00007 typedef pfc::rcptr_const_t<filter_node> filter_node_cptr;
00008 typedef pfc::rcptr_t<filter_node> filter_node_ptr;
00009
00010 class NOVTABLE filter_node {
00011 public:
00012 virtual bool test(const file_info * item,const metadb_handle_ptr & handle) const = 0;
00013 virtual ~filter_node() {}
00014 static filter_node_cptr g_create(const char * ptr,t_size len,bool b_allow_simple = false);
00015 static filter_node_cptr g_create(const class parser & p,bool b_allow_simple = false);
00016 };
00017
00018 class search_filter {
00019 filter_node_cptr m_root;
00020 public:
00021 search_filter() {}
00022 ~search_filter() {}
00023 bool init(const char * pattern) {
00024 try {
00025 m_root = filter_node::g_create(pattern,strlen(pattern),true) ;
00026 return true;
00027 } catch(exception_parse_error) {return false;}
00028 }
00029
00030 void deinit() {
00031 m_root.release();
00032 }
00033
00034 bool test(const file_info * item,const metadb_handle_ptr & handle) const {
00035 return m_root.is_valid() ? m_root->test(item,handle) : false;
00036 }
00037
00038 bool test(const metadb_handle_ptr & item) const {
00039 bool rv = false;
00040 const file_info * ptr;
00041 if (item->get_info_locked(ptr)) rv = test(ptr,item);
00042 return rv;
00043 }
00044 };
00045
00046
00047 };