ctkLDAPExpr.h

Go to the documentation of this file.
00001 /*=============================================================================
00002 
00003 Library: CTK
00004 
00005 Copyright (c) 2010 German Cancer Research Center,
00006 Division of Medical and Biological Informatics
00007 
00008 Licensed under the Apache License, Version 2.0 (the "License");
00009 you may not use this file except in compliance with the License.
00010 You may obtain a copy of the License at
00011 
00012 http://www.apache.org/licenses/LICENSE-2.0
00013 
00014 Unless required by applicable law or agreed to in writing, software
00015 distributed under the License is distributed on an "AS IS" BASIS,
00016 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017 See the License for the specific language governing permissions and
00018 limitations under the License.
00019 
00020 =============================================================================*/
00021 
00022 #include "ctkPluginConstants.h"
00023 #include <exception>
00024 
00025 #include <QString>
00026 #include <QHash>
00027 #include <QSharedDataPointer>
00028 
00029 #include <stdexcept>
00030 
00031 
00032 
00033 typedef std::invalid_argument ctkInvalidSyntaxException;
00034 typedef QHash< QString, QVariant > ctkDictionary;
00035 class ctkLDAPExprData;
00036 
00043 class CTK_PLUGINFW_EXPORT ctkLDAPExpr {
00044 
00045 public:
00046   const static int AND     =  0;
00047   const static int OR      =  1;
00048   const static int NOT     =  2;
00049   const static int EQ      =  4;
00050   const static int LE      =  8;
00051   const static int GE      = 16;
00052   const static int APPROX  = 32;
00053   const static int COMPLEX = AND | OR | NOT;
00054   const static int SIMPLE  = EQ | LE | GE | APPROX;
00055   typedef char Byte;
00056 
00057 public:
00059   ctkLDAPExpr(const QString &filter) throw ( ctkInvalidSyntaxException );
00060 
00062   ctkLDAPExpr(const ctkLDAPExpr& other);
00063 
00070   QSet<QString> getMatchedObjectClasses() const;
00071 
00072 
00095   bool isSimple(
00096     const QList<QString> &keywords, 
00097     QHash<int, QList<QString> > &cache, 
00098     bool matchCase) const;
00099 
00101   static bool query(const QString &filter, const ctkDictionary &pd)
00102     throw (ctkInvalidSyntaxException);
00103 
00105   bool evaluate(const ctkDictionary &p, bool matchCase) const;
00106 
00108   const QString toQString() const;
00109 
00110 
00111 private:
00113   bool compare(const QVariant &obj, int op, const QString &s) const;
00114 
00116   static bool compareQString(const QString &s1, int op, const QString &s2);
00117 
00119   const static QString fixupQString(const QString &s);
00120 
00122   static bool patSubstr(const QString &s, const QString &pat);
00123 
00125   static bool patSubstr(const QString &s, int si, const QString &pat, int pi);
00126 
00128   class ParseState {
00129     int m_pos;
00130     QString m_str;
00131 
00132   public:
00133     ParseState(const QString &str) throw (ctkInvalidSyntaxException);
00134 
00136     bool prefix(const QString &pre);
00137 
00141     QChar peek();
00142 
00144     void skip(int n);
00145 
00147     const QString rest();
00148 
00150     void skipWhite();
00151 
00153     const QString getAttributeName();
00154 
00156     const QString getAttributeValue();
00157 
00159     void error(const QString &m) throw (ctkInvalidSyntaxException);
00160 
00161   };
00162 
00164   static ctkLDAPExpr parseExpr(ParseState &ps)
00165     throw (ctkInvalidSyntaxException);
00166 
00168   static ctkLDAPExpr parseSimple(ParseState &ps)
00169     throw (ctkInvalidSyntaxException);
00170 
00171 private:
00173   ctkLDAPExpr(int op, const QList<ctkLDAPExpr> &args);
00174 
00176   ctkLDAPExpr(int op, const QString &attrName, const QString &attrValue);
00177 
00178 
00179 private:
00180   const static QChar WILDCARD; // = 65535;
00181   const static QString WILDCARD_QString;// = QString( WILDCARD );
00182 
00183   const static QString NULLQ;//      = "Null query";
00184   const static QString GARBAGE;//   = "Trailing garbage";
00185   const static QString EOS;//       = "Unexpected end of query";
00186   const static QString MALFORMED;// = "Malformed query";
00187   const static QString OPERATOR;//  = "Undefined m_operator";
00188 
00189 private:
00190 
00192   QSharedDataPointer<ctkLDAPExprData> d;
00193 
00194 };
00195 
00196 
00203 class ctkLDAPExprData : public QSharedData
00204 {
00205 public:
00206 
00207   ctkLDAPExprData( int op, QList<ctkLDAPExpr> args )
00208   {
00209     m_operator = op;
00210     m_args = args;
00211     m_attrName = QString::Null( );
00212     m_attrValue = QString::Null( );
00213   }
00214 
00215   ctkLDAPExprData( int op, QString attrName, QString attrValue )
00216   {
00217     m_operator = op;
00218     m_args.clear();
00219     m_attrName = attrName;
00220     m_attrValue = attrValue;
00221   }
00222 
00223   ctkLDAPExprData( const ctkLDAPExprData& other ) : QSharedData(other)
00224   {
00225     m_operator = other.m_operator;
00226     m_args = other.m_args;
00227     m_attrName = other.m_attrName;
00228     m_attrValue = other.m_attrValue;
00229   }
00230 
00232   int m_operator;
00234   QList<ctkLDAPExpr> m_args;
00236   QString m_attrName;
00238   QString m_attrValue;
00239 };
00240 
00241 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1