00001 /* 00002 EyeDB Object Database Management System 00003 Copyright (C) 1994-2008 SYSRA 00004 00005 EyeDB is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 EyeDB is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00018 */ 00019 00020 /* 00021 Author: Eric Viara <viara@sysra.com> 00022 */ 00023 00024 00025 #include "eyedb_p.h" 00026 00027 namespace eyedb { 00028 00029 OQLIterator::OQLIterator(Database *db, const std::string &s) 00030 { 00031 q = new OQL(db, s.c_str()); 00032 toDelete = True; 00033 status = q->execute(val_arr); 00034 // 19/09/05: cannot throw in a constructor 00035 //if (status) throw *status; 00036 cur = 0; 00037 } 00038 00039 OQLIterator::OQLIterator(OQL &_q) 00040 { 00041 q = &_q; 00042 toDelete = False; 00043 status = q->execute(val_arr); 00044 // 19/09/05: cannot throw in a constructor 00045 //if (status) throw *status; 00046 cur = 0; 00047 } 00048 00049 Bool OQLIterator::next(Oid &oid) 00050 { 00051 for (;;) 00052 { 00053 Value v; 00054 if (!next(v)) 00055 return False; 00056 00057 if (v.getType() == Value::tOid) { 00058 oid = *v.oid; 00059 return True; 00060 } 00061 } 00062 } 00063 00064 Bool OQLIterator::next(ObjectPtr &o_ptr, const RecMode *rcm) 00065 { 00066 Object *o = 0; 00067 Bool b = next(o, rcm); 00068 o_ptr = o; 00069 return b; 00070 } 00071 00072 Bool OQLIterator::next(Object *&o, const RecMode *rcm) 00073 { 00074 Oid oid; 00075 if (!next(oid)) 00076 return False; 00077 00078 o = 0; 00079 status = q->getDatabase()->loadObject(oid, o, rcm); 00080 if (status) 00081 throw *status; 00082 00083 return True; 00084 } 00085 00086 Bool OQLIterator::next(Value &v) 00087 { 00088 if (cur < val_arr.getCount()) { 00089 v = val_arr[cur++]; 00090 return True; 00091 } 00092 00093 return False; 00094 } 00095 00096 OQLIterator::~OQLIterator() 00097 { 00098 if (toDelete) delete q; 00099 } 00100 }