00001 /* 00002 * Copyright 2005-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 00018 00019 #ifndef __OASYS_DURABLE_STORE_INTERNAL_HEADER__ 00020 #error DurableIterator.h must only be included from within DurableStore.h 00021 #endif 00022 00023 00028 class DurableIterator { 00029 public: 00030 // virtual destructor 00031 virtual ~DurableIterator() {} 00032 00055 virtual int next() = 0; 00056 00060 virtual int get_key(SerializableObject* key) = 0; 00061 }; 00062 00063 //---------------------------------------------------------------------------- 00070 template<typename _filter> 00071 class DurableFilterIterator : public DurableIterator { 00072 public: 00073 DurableFilterIterator(DurableIterator* itr) 00074 : itr_(itr) {} 00075 00076 // virtual from DurableIterator 00077 int next() 00078 { 00079 for (;;) 00080 { 00081 int ret = itr_->next(); 00082 if (ret != DS_OK) { 00083 return ret; 00084 } 00085 00086 if (_filter::accept(itr_)) { 00087 return DS_OK; 00088 } 00089 } 00090 } 00091 00092 int get_key(SerializableObject* key) 00093 { 00094 return itr_->get_key(key); 00095 } 00096 00097 private: 00098 DurableIterator* itr_; 00099 };