00001 /*************************************************************************** 00002 * Copyright (C) 2009,2010 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the dbus-cxx library. * 00006 * * 00007 * The dbus-cxx library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The dbus-cxx library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 #include <dbus-cxx/enums.h> 00020 00021 #ifndef DBUSCXX_ACCUMULATORS_H 00022 #define DBUSCXX_ACCUMULATORS_H 00023 00024 namespace DBus 00025 { 00032 00037 struct PredicateAccumulatorDefaultTrue { 00038 typedef bool result_type; 00039 00040 template <typename T_iterator> 00041 result_type operator()( T_iterator first, T_iterator last ) const { 00042 bool result = true; 00043 while ( first != last ) { 00044 result = result and( *first ); 00045 } 00046 return result; 00047 } 00048 }; 00049 00054 struct InterruptablePredicateAccumulatorDefaultFalse { 00055 typedef bool result_type; 00056 00057 template <typename T_iterator> 00058 result_type operator()( T_iterator first, T_iterator last ) const { 00059 while ( first != last ) { 00060 if ( *first ) return true; 00061 ++first; 00062 } 00063 return false; 00064 } 00065 }; 00066 00076 struct MessageHandlerAccumulator { 00077 typedef HandlerResult result_type; 00078 00079 template <typename T_iterator> 00080 result_type operator()( T_iterator first, T_iterator last ) const { 00081 HandlerResult retval = NOT_HANDLED; 00082 while ( first != last ) { 00083 switch ( *first ) 00084 { 00085 case HANDLED: 00086 return HANDLED; 00087 case HANDLER_NEEDS_MEMORY: 00088 retval = HANDLER_NEEDS_MEMORY; 00089 // no break because we'll slide through to the next case 00090 case NOT_HANDLED: 00091 ++first; 00092 } 00093 } 00094 return retval; 00095 } 00096 }; 00097 00107 struct FilterAccumulator { 00108 typedef FilterResult result_type; 00109 00110 template <typename T_iterator> 00111 result_type operator()( T_iterator first, T_iterator last ) const { 00112 FilterResult retval = DONT_FILTER; 00113 while ( first != last ) { 00114 switch ( *first ) 00115 { 00116 case FILTER: 00117 return FILTER; 00118 case FILTER_NEEDS_MEMORY: 00119 retval = FILTER_NEEDS_MEMORY; 00120 // no break because we'll slide through to the next case 00121 case DONT_FILTER: 00122 ++first; 00123 } 00124 } 00125 return retval; 00126 } 00127 }; 00128 00133 struct PredicateAccumulatorDefaultFalse { 00134 typedef bool result_type; 00135 00136 template <typename T_iterator> 00137 result_type operator()( T_iterator first, T_iterator last ) const { 00138 bool result = false; 00139 while ( first != last ) { 00140 result = result or( *first ); 00141 ++first; 00142 } 00143 return result; 00144 } 00145 }; 00146 00148 00149 } 00150 00151 #endif