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 "dbSBoxItr.h"
34 
35 #include "dbBlock.h"
36 #include "dbSBox.h"
37 #include "dbSWire.h"
38 #include "dbTable.h"
39 
40 namespace odb {
41 
reversible()42 bool dbSBoxItr::reversible()
43 {
44   return true;
45 }
46 
orderReversed()47 bool dbSBoxItr::orderReversed()
48 {
49   return true;
50 }
51 
reverse(dbObject * parent)52 void dbSBoxItr::reverse(dbObject* parent)
53 {
54   switch (parent->getImpl()->getType()) {
55     case dbSWireObj: {
56       _dbSWire* wire = (_dbSWire*) parent;
57       uint id = wire->_wires;
58       uint list = 0;
59 
60       while (id != 0) {
61         _dbSBox* b = _box_tbl->getPtr(id);
62         uint n = b->_next_box;
63         b->_next_box = list;
64         list = id;
65         id = n;
66       }
67 
68       wire->_wires = list;
69       break;
70     }
71 
72     default:
73       break;
74   }
75 }
76 
sequential()77 uint dbSBoxItr::sequential()
78 {
79   return 0;
80 }
81 
size(dbObject * parent)82 uint dbSBoxItr::size(dbObject* parent)
83 {
84   uint id;
85   uint cnt = 0;
86 
87   for (id = dbSBoxItr::begin(parent); id != dbSBoxItr::end(parent);
88        id = dbSBoxItr::next(id))
89     ++cnt;
90 
91   return cnt;
92 }
93 
begin(dbObject * parent)94 uint dbSBoxItr::begin(dbObject* parent)
95 {
96   switch (parent->getImpl()->getType()) {
97     case dbSWireObj: {
98       _dbSWire* wire = (_dbSWire*) parent;
99       return wire->_wires;
100     }
101 
102     default:
103       break;
104   }
105 
106   return 0;
107 }
108 
end(dbObject *)109 uint dbSBoxItr::end(dbObject* /* unused: parent */)
110 {
111   return 0;
112 }
113 
next(uint id,...)114 uint dbSBoxItr::next(uint id, ...)
115 {
116   _dbSBox* box = _box_tbl->getPtr(id);
117   return box->_next_box;
118 }
119 
getObject(uint id,...)120 dbObject* dbSBoxItr::getObject(uint id, ...)
121 {
122   return _box_tbl->getPtr(id);
123 }
124 
125 }  // namespace odb
126