00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Benjamin Hadorn (b_hadorn@bluewin.ch) * 00003 *************************************************************************** 00004 * Projekt : Zeus Base Library 00005 * Module : XObjectQuery 00006 * Package : System 00007 * Author : Benjamin Hadorn 00008 * Datum : $Date: 24.01.08 10:09 $ 00009 * Ablage : $File$ 00010 * System : Cell Computing Model 00011 *************************************************************************** 00012 * Licence: * 00013 * This library is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU Lesser General Public License as * 00015 * published by the Free Software Foundation; either version * 00016 * 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00026 ***************************************************************************/ 00027 00028 /*************************************************************************** 00029 Changes : 00030 $Log: /Development_F/StuderWIN/dev/Zeus/src/zeusbase/System/XObjectQuery.h $ 00031 ** 00032 ** 2 24.01.08 10:09 Bha 00033 ** Wildcart query supported 00034 ** 00035 ** 1 14.01.08 14:26 Bha 00036 ** Created 00037 ***************************************************************************/ 00038 //--------------------------------------------------------------------------- 00039 00040 #ifndef XObjectQueryH 00041 #define XObjectQueryH 00042 00043 #include <zeusbase/System/ZObject.h> 00044 #include <zeusbase/System/Interfaces/IXObject.hpp> 00045 00046 BEGIN_NAMESPACE_Zeus 00047 00048 /***************************************************************************/ 00051 /***************************************************************************/ 00052 class TXObjectQuery : public TZObject 00053 { 00054 public: 00055 00056 /************************************************************************/ 00059 /************************************************************************/ 00060 inline TXObjectQuery(const TString& rRealName) 00061 { 00062 if (rRealName != L"*") 00063 { 00064 m_strRealName = rRealName; 00065 } 00066 //else name is empty 00067 } 00068 00069 /************************************************************************/ 00072 /************************************************************************/ 00073 inline const TString& getRealName() const { return m_strRealName; } 00074 00075 /************************************************************************/ 00078 /************************************************************************/ 00079 inline bool matchObjectName(IXObject& rObject) const 00080 { 00081 TString strName; 00082 rObject.getName(strName); 00083 return (m_strRealName == strName || m_strRealName.isEmpty()); 00084 } 00085 00086 /************************************************************************/ 00089 /************************************************************************/ 00090 inline virtual bool matchQuery(Int /*iCurrentIndex*/, IXObject& /*rObject*/) const 00091 { 00092 return true; 00093 } 00094 00095 /************************************************************************/ 00098 /************************************************************************/ 00099 inline bool match(Int iCurrentIndex, IXObject& rObject) const 00100 { 00101 return matchObjectName(rObject) && matchQuery(iCurrentIndex, rObject); 00102 } 00103 00104 //factory methods 00105 static TXObjectQuery& createQuery(const TString& rQueryData); 00106 00107 protected: 00108 /************************************************************************/ 00111 /************************************************************************/ 00112 inline virtual ~TXObjectQuery() {} 00113 00115 TString m_strRealName; 00116 }; 00117 00118 /***************************************************************************/ 00121 /***************************************************************************/ 00122 class TIndexQuery : public TXObjectQuery 00123 { 00124 public: 00125 00126 /************************************************************************/ 00129 /************************************************************************/ 00130 inline TIndexQuery(const TString& rRealName, Int iIndex) 00131 : TXObjectQuery(rRealName) 00132 { 00133 m_iIndex = iIndex; 00134 } 00135 00136 00137 /************************************************************************/ 00140 /************************************************************************/ 00141 virtual inline bool matchQuery(Int iCurrentIndex, IXObject& /*rObject*/) const 00142 { 00143 return (iCurrentIndex == m_iIndex); 00144 } 00145 00146 protected: 00147 /************************************************************************/ 00150 /************************************************************************/ 00151 inline virtual ~TIndexQuery() {} 00152 00153 private: 00155 Int m_iIndex; 00156 }; 00157 00158 /***************************************************************************/ 00161 /***************************************************************************/ 00162 class TAttributeQuery : public TXObjectQuery 00163 { 00164 public: 00165 00166 /************************************************************************/ 00169 /************************************************************************/ 00170 inline TAttributeQuery(const TString& rRealName, 00171 const TString& rAttName, 00172 const TString& rAttValue) 00173 : TXObjectQuery(rRealName) , 00174 m_strAttName(rAttName), 00175 m_strAttValue(rAttValue) 00176 { 00177 } 00178 00179 00180 /************************************************************************/ 00183 /************************************************************************/ 00184 virtual inline bool matchQuery(Int /*iCurrentIndex*/, IXObject& rObject) const 00185 { 00186 TString strAttValue; 00187 rObject.readStringAttribute(m_strAttName, strAttValue); 00188 00189 return (m_strAttValue == strAttValue); 00190 } 00191 00192 protected: 00193 /************************************************************************/ 00196 /************************************************************************/ 00197 inline virtual ~TAttributeQuery() {} 00198 00199 private: 00201 TString m_strAttName; 00203 TString m_strAttValue; 00204 }; 00205 00206 00207 END_NAMESPACE_Zeus 00208 00209 //--------------------------------------------------------------------------- 00210 #endif