1 : /**********************************************************************
2 : * $Id: iom_iterator.cpp 12582 2007-10-29 09:38:21Z pka $
3 : *
4 : * Project: iom - The INTERLIS Object Model
5 : * Purpose: For more information, please see <http://iom.sourceforge.net>
6 : * Author: Claude Eisenhut
7 : *
8 : **********************************************************************
9 : * Copyright (c) 2007, Claude Eisenhut
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 :
31 : /** @file
32 : * implementation of object iterator
33 : * @defgroup iterator iterator functions
34 : * @{
35 : */
36 :
37 : #include <iom/iom_p.h>
38 :
39 :
40 : /**
41 : * release handle
42 : */
43 0 : extern "C" int iom_releaseiterator(IOM_ITERATOR iterator)
44 : {
45 0 : if(!iterator->freeRef()){
46 0 : delete iterator;
47 : }
48 0 : return 0;
49 : }
50 :
51 : /** @}
52 : */
53 :
54 0 : iom_iterator::iom_iterator(IomFile file1)
55 : : type(iom_iterator::eBASKET)
56 : , useCount(0)
57 : , basketv(file1)
58 0 : , basketi(0)
59 : {
60 0 : }
61 :
62 0 : IomBasket iom_iterator::next_basket()
63 : {
64 0 : if(basketi==basketv->basketv.size()){
65 : // file completly read?
66 0 : if(!basketv->parser){
67 0 : return IomBasket();
68 : }
69 : // read next basket
70 0 : basketv->readBasket(basketv);
71 : }
72 0 : if(basketi==basketv->basketv.size()){
73 : // file completly read
74 0 : return IomBasket();
75 : }
76 0 : return basketv->basketv.at(basketi++);
77 : }
78 :
79 0 : iom_iterator::iom_iterator(IomBasket basket1)
80 : : type(iom_iterator::eOBJECT)
81 : , useCount(0)
82 : , objectv(basket1)
83 0 : , objecti(0)
84 : {
85 0 : }
86 :
87 0 : IomObject iom_iterator::next_object()
88 : {
89 0 : if(objecti==objectv->objectv.size()){
90 : // basket completly read
91 0 : return IomObject();
92 : }
93 0 : return objectv->objectv.at(objecti++);
94 : }
95 :
96 :
97 0 : iom_iterator::~iom_iterator()
98 : {
99 0 : }
100 :
101 :
102 0 : IomIterator::IomIterator(struct iom_iterator *pointee1)
103 0 : : pointee(pointee1 ? pointee1->getRef() : 0){
104 0 : }
105 0 : IomIterator::IomIterator(const IomIterator& src)
106 0 : : pointee(src.pointee ? src.pointee->getRef() : 0){
107 0 : }
108 0 : IomIterator& IomIterator::operator=(const IomIterator& src){
109 0 : if(this!=&src){
110 0 : if(pointee && !pointee->freeRef()){
111 0 : delete pointee;
112 : }
113 0 : pointee=src.pointee ? src.pointee->getRef() : 0;
114 : }
115 0 : return *this;
116 : }
117 0 : IomIterator::~IomIterator(){
118 0 : if(pointee && !pointee->freeRef()){
119 0 : delete pointee;
120 : }
121 1947 : }
122 :
|