00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil c-basic-offset: 3 -*- */ 00002 // vim:cindent:ts=3:sw=3:et:tw=80:sta: 00003 /*************************************************************** cppdom-cpr beg 00004 * 00005 * cppdom was forked from the original xmlpp version 0.6 under the LGPL. This 00006 * new, branched xmlpp is under the same LGPL (of course) and is being 00007 * maintained by: 00008 * Kevin Meinert <subatomic@users.sourceforge.net> 00009 * Allen Bierbaum <allenb@users.sourceforge.net> 00010 * Ben Scott <nonchocoboy@users.sourceforge.net> 00011 * 00012 * ----------------------------------------------------------------- 00013 * 00014 * xmlpp - an xml parser and validator written in C++ 00015 * copyright (c) 2000-2001 Michael Fink 00016 * 00017 * This library is free software; you can redistribute it and/or 00018 * modify it under the terms of the GNU Library General Public 00019 * License as published by the Free Software Foundation; either 00020 * version 2 of the License, or (at your option) any later version. 00021 * 00022 * This library is distributed in the hope that it will be useful, 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00025 * Library General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU Library General Public 00028 * License along with this library; if not, write to the 00029 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00030 * Boston, MA 02111-1307, USA. 00031 * 00032 * ----------------------------------------------------------------- 00033 * File: $RCSfile: predicates.h,v $ 00034 * Date modified: $Date: 2003/01/03 03:06:47 $ 00035 * Version: $Revision: 1.11 $ 00036 * ----------------------------------------------------------------- 00037 * 00038 ************************************************************ cppdom-cpr-end */ 00039 #ifndef CPPDOM_PREDICATES_H 00040 #define CPPDOM_PREDICATES_H 00041 00042 #include <string> 00043 #include "cppdom.h" 00044 00045 namespace cppdom 00046 { 00047 class HasAttributeNamePredicate 00048 { 00049 public: 00051 HasAttributeNamePredicate(const std::string& attrName) 00052 : mName(attrName) 00053 {} 00054 00056 void setName(const std::string& attrName) { mName = attrName; } 00057 00058 bool operator()(const XMLNodePtr& node) 00059 { 00060 return node->hasAttribute(mName); 00061 } 00062 00063 private: 00064 std::string mName; 00065 }; 00066 00067 class HasAttributeValuePredicate 00068 { 00069 public: 00074 HasAttributeValuePredicate(const std::string& attrName, const std::string& val) 00075 : mName(attrName), mValue(val) 00076 {} 00077 00079 void setName(const std::string& attrName) { mName = attrName; } 00080 00082 void setValue(const std::string& val) { mValue = val; } 00083 00084 bool operator()(const XMLNodePtr& node) 00085 { 00086 // if doesn't have the attribute, then were done. 00087 if (!node->hasAttribute(mName)) 00088 { 00089 return false; 00090 } 00091 00092 return mValue == (std::string)node->getAttribute(mName); 00093 } 00094 private: 00095 std::string mName; 00096 std::string mValue; 00097 }; 00098 } 00099 00100 #endif