Hydra 0.20
hydra.src/hydra/Query.h
00001 
00002 /*
00003  * Copyright (c) 2010 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRA_QUERY_H__
00009 #define __INCLUDED_HYDRA_QUERY_H__
00010 
00011 #include <set>
00012 #include <hydra/TR1.h>
00013 
00014 #include <QString>
00015 
00016 namespace hydra
00017 {
00018   typedef std::set<QString> tags_t;
00019 
00020   class Token;
00021 
00022   static const char SCORE_CHAR = '$';
00023 
00024   /**
00025    * Finds and returns the length of the score tag.
00026    * If none, 0 is returned.
00027    * 
00028    * @author Aleksander Demko
00029    */ 
00030   int scoreValue(const tags_t &tags);
00031 
00032   bool isQueryChar(const QChar &c); 
00033 
00034   /**
00035    * Parse a given search/query string into a token tree.
00036    * Returns true on success, false on failure. tok is no modified on failures.
00037    * Empty strings return an always true query that matches everything.
00038    * The resulting hydra::Token can they be used to test
00039    * against hydra::Tags
00040    *
00041    * @author Aleksander Demko
00042    */ 
00043   bool parseQueryTokens(const QString &s, std::shared_ptr<hydra::Token> &tok);
00044 }
00045 
00046 /**
00047  * Core token/query object for token trees. This is an object
00048  * reprentation of a query that can then be used to
00049  * test against tag sets for matches.
00050  *
00051  * @author Aleksander Demko
00052  */ 
00053 class hydra::Token
00054 {
00055   public:
00056     virtual ~Token() { }
00057 
00058     /**
00059      * Does this token tree match against the
00060      * given tags?
00061      *
00062      * @author Aleksander Demko
00063      */ 
00064     virtual bool isMatch(const hydra::tags_t &t) = 0;
00065 };
00066 
00067 #endif
00068 
 All Classes Namespaces Functions Variables