00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : XObjectQuery 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef XObjectQueryH 00033 #define XObjectQueryH 00034 00035 #include <zeusbase/System/ZObject.h> 00036 #include <zeusbase/System/Interfaces/IXObject.hpp> 00037 00038 BEGIN_NAMESPACE_Zeus 00039 00040 /***************************************************************************/ 00043 /***************************************************************************/ 00044 class TXObjectQuery : public TZObject 00045 { 00046 public: 00047 00048 /************************************************************************/ 00051 /************************************************************************/ 00052 inline TXObjectQuery(const TString& rRealName) 00053 { 00054 if (rRealName != L"*") 00055 { 00056 m_strRealName = rRealName; 00057 } 00058 //else name is empty 00059 } 00060 00061 /************************************************************************/ 00064 /************************************************************************/ 00065 inline const TString& getRealName() const { return m_strRealName; } 00066 00067 /************************************************************************/ 00070 /************************************************************************/ 00071 inline bool matchObjectName(IXObject& rObject) const 00072 { 00073 TString strName; 00074 rObject.getName(strName); 00075 return (m_strRealName == strName || m_strRealName.isEmpty()); 00076 } 00077 00078 /************************************************************************/ 00081 /************************************************************************/ 00082 inline virtual bool matchQuery(Int /*iCurrentIndex*/, IXObject& /*rObject*/) const 00083 { 00084 return true; 00085 } 00086 00087 /************************************************************************/ 00090 /************************************************************************/ 00091 inline bool match(Int iCurrentIndex, IXObject& rObject) const 00092 { 00093 return matchObjectName(rObject) && matchQuery(iCurrentIndex, rObject); 00094 } 00095 00096 //factory methods 00097 static TXObjectQuery& createQuery(const TString& rQueryData); 00098 00099 protected: 00100 /************************************************************************/ 00103 /************************************************************************/ 00104 inline virtual ~TXObjectQuery() {} 00105 00107 TString m_strRealName; 00108 }; 00109 00110 /***************************************************************************/ 00113 /***************************************************************************/ 00114 class TIndexQuery : public TXObjectQuery 00115 { 00116 public: 00117 00118 /************************************************************************/ 00121 /************************************************************************/ 00122 inline TIndexQuery(const TString& rRealName, Int iIndex) 00123 : TXObjectQuery(rRealName) 00124 { 00125 m_iIndex = iIndex; 00126 } 00127 00128 00129 /************************************************************************/ 00132 /************************************************************************/ 00133 virtual inline bool matchQuery(Int iCurrentIndex, IXObject& /*rObject*/) const 00134 { 00135 return (iCurrentIndex == m_iIndex); 00136 } 00137 00138 protected: 00139 /************************************************************************/ 00142 /************************************************************************/ 00143 inline virtual ~TIndexQuery() {} 00144 00145 private: 00147 Int m_iIndex; 00148 }; 00149 00150 /***************************************************************************/ 00153 /***************************************************************************/ 00154 class TAttributeQuery : public TXObjectQuery 00155 { 00156 public: 00157 00158 /************************************************************************/ 00161 /************************************************************************/ 00162 inline TAttributeQuery(const TString& rRealName, 00163 const TString& rAttName, 00164 const TString& rAttValue) 00165 : TXObjectQuery(rRealName) , 00166 m_strAttName(rAttName), 00167 m_strAttValue(rAttValue) 00168 { 00169 } 00170 00171 00172 /************************************************************************/ 00175 /************************************************************************/ 00176 virtual inline bool matchQuery(Int /*iCurrentIndex*/, IXObject& rObject) const 00177 { 00178 TString strAttValue; 00179 rObject.readStringAttribute(m_strAttName, strAttValue); 00180 00181 return (m_strAttValue == strAttValue); 00182 } 00183 00184 protected: 00185 /************************************************************************/ 00188 /************************************************************************/ 00189 inline virtual ~TAttributeQuery() {} 00190 00191 private: 00193 TString m_strAttName; 00195 TString m_strAttValue; 00196 }; 00197 00198 00199 END_NAMESPACE_Zeus 00200 00201 //--------------------------------------------------------------------------- 00202 #endif