OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / collectionIterator.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: collectionIterator.cc /main/4 1996/06/11 17:28:28 cde-hal $
24
25 #include "oliasdb/collectionIterator.h"
26 #include "oliasdb/olias_consts.h"
27 #include "oliasdb/node_hd.h"
28 #include "oliasdb/stylesheet_hd.h"
29 #include "oliasdb/graphic_hd.h"
30 #include "oliasdb/locator_hd.h"
31
32 collectionIterator::collectionIterator(info_base* base, int position) :
33    f_set_ptr(base ->  get_set(position)), f_base(base), f_index(-1)
34 {
35    if ( f_set_ptr == 0 )
36      throw(stringException("can't find set"));
37 }
38
39 collectionIterator::~collectionIterator()
40 {
41 }
42
43 unsigned int collectionIterator::operator++()
44 {
45    if ( f_index == -1 ) {
46       f_index = 0;
47       return 1;
48    }
49
50    if ( f_index == -2 ) {
51      MESSAGE(cerr, "can't advance iterator any more");
52      return 0;
53    }
54
55    if ( (*f_set_ptr) -> count() - 1 == f_index ) {
56       f_index = -2;
57       return 0;
58    } else {
59       f_index++;
60       return 1;
61    }
62 }
63
64 oid_t collectionIterator::get_oid(int index)
65 {
66    c_index_handler* x = (*f_set_ptr) -> get_index_ptr(index);
67
68    if ( x == 0 )
69      throw(stringException("bad internal index"));
70
71    return (*x) -> first_of_invlist(f_index);
72 }
73
74 nodeCollectionIterator::nodeCollectionIterator(info_base* base) :
75    collectionIterator(base, NODE_SET_POS)
76 {
77 }
78
79 nodeCollectionIterator::~nodeCollectionIterator()
80 {
81 }
82
83 const char* nodeCollectionIterator::get_locator()
84 {
85    oid_t id = get_oid(1);
86    node_smart_ptr node(f_base, id);
87    return node.locator();
88 }
89
90 stylesheetCollectionIterator::stylesheetCollectionIterator(info_base* base) :
91    collectionIterator(base, STYLESHEET_SET_POS)
92 {
93 }
94
95 stylesheetCollectionIterator::~stylesheetCollectionIterator()
96 {
97 }
98
99
100 const char* stylesheetCollectionIterator::get_locator()
101 {
102    oid_t id = get_oid(1);
103    stylesheet_smart_ptr ss(f_base, id);
104    return ss.name();
105 }
106
107 graphicCollectionIterator::graphicCollectionIterator(info_base* base) :
108    collectionIterator(base, GRAPHIC_SET_POS)
109 {
110 }
111
112 graphicCollectionIterator::~graphicCollectionIterator()
113 {
114 }
115
116
117 const char* graphicCollectionIterator::get_locator()
118 {
119    oid_t id = get_oid(1);
120    graphic_smart_ptr gr(f_base, id);
121    return gr.locator();
122 }
123
124 locatorCollectionIterator::locatorCollectionIterator(info_base* base) :
125    collectionIterator(base, LOCATOR_SET_POS)
126 {
127 }
128
129 locatorCollectionIterator::~locatorCollectionIterator()
130 {
131 }
132
133
134 const char* locatorCollectionIterator::get_locator()
135 {
136    oid_t id = get_oid(1);
137    locator_smart_ptr lc(f_base, id);
138    return lc.inside_node_locator_str();
139 }
140
141