1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 // list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 // this list of conditions and the following disclaimer in the documentation
15 // and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32
33 #include "dbPropertyItr.h"
34
35 #include "dbProperty.h"
36 #include "dbTable.h"
37
38 namespace odb {
39
40 ////////////////////////////////////////////////////////////////////
41 //
42 // dbPropertyItr - Methods
43 //
44 ////////////////////////////////////////////////////////////////////
45
reversible()46 bool dbPropertyItr::reversible()
47 {
48 return true;
49 }
50
orderReversed()51 bool dbPropertyItr::orderReversed()
52 {
53 return true;
54 }
55
reverse(dbObject * parent)56 void dbPropertyItr::reverse(dbObject* parent)
57 {
58 _dbObject* parent_impl = parent->getImpl();
59 dbObjectTable* table = parent_impl->getTable();
60 uint id = table->getPropList(parent_impl->getOID());
61
62 if (id) {
63 uint list = 0;
64
65 while (id != 0) {
66 _dbProperty* p = _prop_tbl->getPtr(id);
67 uint n = p->_next;
68 p->_next = list;
69 list = id;
70 id = n;
71 }
72
73 table->setPropList(parent_impl->getOID(), list);
74 }
75 }
76
sequential()77 uint dbPropertyItr::sequential()
78 {
79 return 0;
80 }
81
size(dbObject * parent)82 uint dbPropertyItr::size(dbObject* parent)
83 {
84 uint id;
85 uint cnt = 0;
86
87 for (id = dbPropertyItr::begin(parent); id != dbPropertyItr::end(parent);
88 id = dbPropertyItr::next(id))
89 ++cnt;
90
91 return cnt;
92 }
93
begin(dbObject * parent)94 uint dbPropertyItr::begin(dbObject* parent)
95 {
96 dbObjectTable* table = parent->getImpl()->getTable();
97 uint id = table->getPropList(parent->getImpl()->getOID());
98 return id;
99 }
100
end(dbObject *)101 uint dbPropertyItr::end(dbObject* /* unused: parent */)
102 {
103 return 0;
104 }
105
next(uint id,...)106 uint dbPropertyItr::next(uint id, ...)
107 {
108 _dbProperty* prop = _prop_tbl->getPtr(id);
109 return prop->_next;
110 }
111
getObject(uint id,...)112 dbObject* dbPropertyItr::getObject(uint id, ...)
113 {
114 return _prop_tbl->getPtr(id);
115 }
116
117 } // namespace odb
118