• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Solid

predicateparse.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2006 Kevin Ottens <ervin@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) version 3, or any
00008     later version accepted by the membership of KDE e.V. (or its
00009     successor approved by the membership of KDE e.V.), which shall
00010     act as a proxy defined in Section 6 of version 3 of the license.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 extern "C"
00022 {
00023 #include "predicateparse.h"
00024 
00025 void PredicateParse_mainParse(const char *_code);
00026 }
00027 
00028 #include "predicate.h"
00029 #include "soliddefs_p.h"
00030 
00031 #include <stdlib.h>
00032 
00033 #include <QtCore/QStringList>
00034 #include <QtCore/QThreadStorage>
00035 
00036 namespace Solid
00037 {
00038 namespace PredicateParse
00039 {
00040 
00041 struct ParsingData
00042 {
00043     ParsingData()
00044         : result(0)
00045     {}
00046 
00047     Solid::Predicate *result;
00048     QByteArray buffer;
00049 };
00050 
00051 }
00052 }
00053 
00054 SOLID_GLOBAL_STATIC(QThreadStorage<Solid::PredicateParse::ParsingData *>, s_parsingData)
00055 
00056 Solid::Predicate Solid::Predicate::fromString(const QString &predicate)
00057 {
00058     Solid::PredicateParse::ParsingData *data = new Solid::PredicateParse::ParsingData();
00059     s_parsingData->setLocalData(data);
00060     data->buffer = predicate.toAscii();
00061     PredicateParse_mainParse(data->buffer.constData());
00062     Predicate result;
00063     if (data->result)
00064     {
00065         result = Predicate(*data->result);
00066         delete data->result;
00067     }
00068     s_parsingData->setLocalData(0);
00069     return result;
00070 }
00071 
00072 
00073 void PredicateParse_setResult(void *result)
00074 {
00075     Solid::PredicateParse::ParsingData *data = s_parsingData->localData();
00076     data->result = (Solid::Predicate *) result;
00077 }
00078 
00079 void PredicateParse_errorDetected(const char* s)
00080 {
00081     qWarning("ERROR from solid predicate parser: %s", s);
00082     s_parsingData->localData()->result = 0;
00083 }
00084 
00085 void PredicateParse_destroy(void *pred)
00086 {
00087     Solid::PredicateParse::ParsingData *data = s_parsingData->localData();
00088     Solid::Predicate *p = (Solid::Predicate *) pred;
00089     if (p != data->result) {
00090         delete p;
00091     }
00092 }
00093 
00094 void *PredicateParse_newAtom(char *interface, char *property, void *value)
00095 {
00096     QString iface(interface);
00097     QString prop(property);
00098     QVariant *val = (QVariant *)value;
00099 
00100     Solid::Predicate *result = new Solid::Predicate(iface, prop, *val);
00101 
00102     delete val;
00103     free(interface);
00104     free(property);
00105 
00106     return result;
00107 }
00108 
00109 void *PredicateParse_newMaskAtom(char *interface, char *property, void *value)
00110 {
00111     QString iface(interface);
00112     QString prop(property);
00113     QVariant *val = (QVariant *)value;
00114 
00115     Solid::Predicate *result = new Solid::Predicate(iface, prop, *val, Solid::Predicate::Mask);
00116 
00117     delete val;
00118     free(interface);
00119     free(property);
00120 
00121     return result;
00122 }
00123 
00124 
00125 void *PredicateParse_newIsAtom(char *interface)
00126 {
00127     QString iface(interface);
00128 
00129     Solid::Predicate *result = new Solid::Predicate(iface);
00130 
00131     free(interface);
00132 
00133     return result;
00134 }
00135 
00136 
00137 void *PredicateParse_newAnd(void *pred1, void *pred2)
00138 {
00139     Solid::Predicate *result = new Solid::Predicate();
00140 
00141     Solid::PredicateParse::ParsingData *data = s_parsingData->localData();
00142     Solid::Predicate *p1 = (Solid::Predicate *)pred1;
00143     Solid::Predicate *p2 = (Solid::Predicate *)pred2;
00144 
00145     if (p1==data->result || p2==data->result) {
00146         data->result = 0;
00147     }
00148 
00149     *result = *p1 & *p2;
00150 
00151     delete p1;
00152     delete p2;
00153 
00154     return result;
00155 }
00156 
00157 
00158 void *PredicateParse_newOr(void *pred1, void *pred2)
00159 {
00160     Solid::Predicate *result = new Solid::Predicate();
00161 
00162     Solid::PredicateParse::ParsingData *data = s_parsingData->localData();
00163     Solid::Predicate *p1 = (Solid::Predicate *)pred1;
00164     Solid::Predicate *p2 = (Solid::Predicate *)pred2;
00165 
00166     if (p1==data->result || p2==data->result) {
00167         data->result = 0;
00168     }
00169 
00170     *result = *p1 | *p2;
00171 
00172     delete p1;
00173     delete p2;
00174 
00175     return result;
00176 }
00177 
00178 
00179 void *PredicateParse_newStringValue(char *val)
00180 {
00181     QString s(val);
00182 
00183     free(val);
00184 
00185     return new QVariant(s);
00186 }
00187 
00188 
00189 void *PredicateParse_newBoolValue(int val)
00190 {
00191     bool b = (val != 0);
00192     return new QVariant(b);
00193 }
00194 
00195 
00196 void *PredicateParse_newNumValue(int val)
00197 {
00198     return new QVariant(val);
00199 }
00200 
00201 
00202 void *PredicateParse_newDoubleValue(double val)
00203 {
00204     return new QVariant(val);
00205 }
00206 
00207 
00208 void *PredicateParse_newEmptyStringListValue()
00209 {
00210     return new QVariant(QStringList());
00211 }
00212 
00213 
00214 void *PredicateParse_newStringListValue(char *name)
00215 {
00216     QStringList list;
00217     list << QString(name);
00218 
00219     free(name);
00220 
00221     return new QVariant(list);
00222 }
00223 
00224 
00225 void *PredicateParse_appendStringListValue(char *name, void *list)
00226 {
00227     QVariant *variant = (QVariant *)list;
00228 
00229     QStringList new_list = variant->toStringList();
00230 
00231     new_list << QString(name);
00232 
00233     delete variant;
00234     free(name);
00235 
00236     return new QVariant(new_list);
00237 }
00238 
00239 void PredicateLexer_unknownToken(const char* text)
00240 {
00241     qWarning("ERROR from solid predicate parser: unrecognized token '%s' in predicate '%s'\n",
00242              text, s_parsingData->localData()->buffer.constData());
00243 }

Solid

Skip menu "Solid"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal