Skip to content

Commit 616a3a8

Browse files
authored
Merge pull request #8924 from The-OpenROAD-Project-staging/odb-refactor3
Odb refactor3
2 parents 7559f96 + 0ae774d commit 616a3a8

File tree

158 files changed

+1493
-1645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1493
-1645
lines changed

src/odb/include/odb/ZException.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/odb/include/odb/dbIterator.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33

44
#pragma once
55

6-
#include <iterator>
7-
86
#include "odb/odb.h"
97

108
namespace odb {
119

1210
class dbObject;
13-
class dbObjectTable;
1411

1512
class dbIterator
1613
{
1714
public:
18-
virtual bool reversible() = 0;
19-
virtual bool orderReversed() = 0;
15+
virtual ~dbIterator() = default;
16+
17+
virtual bool reversible() const = 0;
18+
virtual bool orderReversed() const = 0;
2019
virtual void reverse(dbObject* parent) = 0;
21-
virtual uint sequential() = 0;
22-
virtual uint size(dbObject* parent) = 0;
23-
virtual uint begin(dbObject* parent) = 0;
24-
virtual uint end(dbObject* parent) = 0;
25-
virtual uint next(uint id, ...) = 0;
20+
virtual uint sequential() const = 0;
21+
virtual uint size(dbObject* parent) const = 0;
22+
virtual uint begin(dbObject* parent) const = 0;
23+
virtual uint end(dbObject* parent) const = 0;
24+
virtual uint next(uint id, ...) const = 0;
2625
virtual dbObject* getObject(uint id, ...) = 0;
27-
virtual ~dbIterator() = default;
2826
};
2927

3028
} // namespace odb

src/odb/include/odb/dbMap.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#pragma once
55

6+
#include <cassert>
67
#include <map>
78
#include <vector>
89

9-
#include "odb/ZException.h"
1010
#include "odb/dbMap.h"
1111
#include "odb/dbSet.h"
1212

@@ -48,12 +48,12 @@ inline const D& dbMap<T, D>::operator[](T* object) const
4848
{
4949
if (_map) {
5050
typename std::map<T*, D>::const_iterator itr = _map->find(object);
51-
ZASSERT(itr != _map->end());
51+
assert(itr != _map->end());
5252
return (*itr).second;
5353
}
5454

5555
uint idx = object->getId();
56-
ZASSERT(idx && (idx < _vector->size()));
56+
assert(idx && (idx < _vector->size()));
5757
return (*_vector)[idx];
5858
}
5959

@@ -65,7 +65,7 @@ inline D& dbMap<T, D>::operator[](T* object)
6565
}
6666

6767
uint idx = object->getId();
68-
ZASSERT(idx && (idx < _vector->size()));
68+
assert(idx && (idx < _vector->size()));
6969
return (*_vector)[idx];
7070
}
7171

src/odb/include/odb/dbSet.h

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iterator>
88

99
#include "odb/dbIterator.h"
10+
#include "odb/odb.h"
1011

1112
namespace odb {
1213

@@ -20,30 +21,31 @@ class dbSet;
2021
template <class T>
2122
class dbSetIterator
2223
{
23-
friend class dbSet<T>;
24-
25-
dbIterator* _itr;
26-
uint _cur;
27-
28-
dbSetIterator(dbIterator* itr, uint id);
29-
3024
public:
3125
using value_type = T*;
3226
using difference_type = std::ptrdiff_t;
3327
using pointer = T**;
3428
using reference = T*&;
3529
using iterator_category = std::input_iterator_tag;
3630

37-
dbSetIterator();
31+
dbSetIterator() = default;
3832
dbSetIterator(const dbSetIterator& it) = default;
3933

40-
bool operator==(const dbSetIterator<T>& it);
41-
bool operator!=(const dbSetIterator<T>& it);
34+
bool operator==(const dbSetIterator<T>& it) const;
35+
bool operator!=(const dbSetIterator<T>& it) const;
4236

4337
T* operator*();
4438
T* operator->();
4539
dbSetIterator<T>& operator++();
4640
dbSetIterator<T> operator++(int);
41+
42+
private:
43+
dbSetIterator(dbIterator* itr, uint id);
44+
45+
dbIterator* itr_{nullptr};
46+
uint cur_{0};
47+
48+
friend class dbSet<T>;
4749
};
4850

4951
///
@@ -71,44 +73,33 @@ class dbSetIterator
7173
template <class T>
7274
class dbSet
7375
{
74-
dbIterator* _itr;
75-
dbObject* _parent;
76-
7776
public:
7877
using iterator = dbSetIterator<T>;
7978

80-
dbSet()
81-
{
82-
_itr = nullptr;
83-
_parent = nullptr;
84-
}
79+
dbSet() = default;
8580

8681
dbSet(dbObject* parent, dbIterator* itr)
8782
{
88-
_parent = parent;
89-
_itr = itr;
83+
parent_ = parent;
84+
itr_ = itr;
9085
}
9186

92-
dbSet(const dbSet<T>& c)
93-
{
94-
_itr = c._itr;
95-
_parent = c._parent;
96-
}
87+
dbSet(const dbSet<T>& c) = default;
9788

9889
///
9990
/// Returns the number of items in this set.
10091
///
101-
uint size() { return _itr->size(_parent); }
92+
uint size() const { return itr_->size(parent_); }
10293

10394
///
10495
/// Return a begin() iterator.
10596
///
106-
iterator begin() { return iterator(_itr, _itr->begin(_parent)); }
97+
iterator begin() const { return iterator(itr_, itr_->begin(parent_)); }
10798

10899
///
109100
/// Return an end() iterator.
110101
///
111-
iterator end() { return iterator(_itr, _itr->end(_parent)); }
102+
iterator end() const { return iterator(itr_, itr_->end(parent_)); }
112103

113104
///
114105
/// If this set is sequential, this function will return the database
@@ -119,80 +110,77 @@ class dbSet
119110
///
120111
/// If this set is non-sequential then it returns 0.
121112
///
122-
uint sequential() { return _itr->sequential(); }
113+
uint sequential() const { return itr_->sequential(); }
123114

124115
///
125116
/// Returns true if this set is reversible.
126117
///
127-
bool reversible() { return _itr->reversible(); }
118+
bool reversible() const { return itr_->reversible(); }
128119

129120
///
130121
/// Returns true if the is iterated in the reverse order that
131122
/// it was created.
132123
///
133-
bool orderReversed() { return _itr->orderReversed(); }
124+
bool orderReversed() const { return itr_->orderReversed(); }
134125

135126
///
136127
/// Reverse the order of this set.
137128
///
138-
void reverse() { _itr->reverse(_parent); }
129+
void reverse() { itr_->reverse(parent_); }
139130

140131
///
141132
/// Returns true if set is empty
142133
///
143-
bool empty() { return begin() == end(); }
144-
};
134+
bool empty() const { return begin() == end(); }
145135

146-
template <class T>
147-
inline dbSetIterator<T>::dbSetIterator()
148-
{
149-
_itr = nullptr;
150-
_cur = 0;
151-
}
136+
private:
137+
dbIterator* itr_{nullptr};
138+
dbObject* parent_{nullptr};
139+
};
152140

153141
template <class T>
154142
inline dbSetIterator<T>::dbSetIterator(dbIterator* itr, uint id)
155143
{
156-
_itr = itr;
157-
_cur = id;
144+
itr_ = itr;
145+
cur_ = id;
158146
}
159147

160148
template <class T>
161-
inline bool dbSetIterator<T>::operator==(const dbSetIterator& it)
149+
inline bool dbSetIterator<T>::operator==(const dbSetIterator& it) const
162150
{
163-
return (_itr == it._itr) && (_cur == it._cur);
151+
return (itr_ == it.itr_) && (cur_ == it.cur_);
164152
}
165153

166154
template <class T>
167-
inline bool dbSetIterator<T>::operator!=(const dbSetIterator& it)
155+
inline bool dbSetIterator<T>::operator!=(const dbSetIterator& it) const
168156
{
169-
return (_itr != it._itr) || (_cur != it._cur);
157+
return !(*this == it);
170158
}
171159

172160
template <class T>
173161
inline T* dbSetIterator<T>::operator*()
174162
{
175-
return (T*) _itr->getObject(_cur);
163+
return (T*) itr_->getObject(cur_);
176164
}
177165

178166
template <class T>
179167
inline T* dbSetIterator<T>::operator->()
180168
{
181-
return (T*) _itr->getObject(_cur);
169+
return (T*) itr_->getObject(cur_);
182170
}
183171

184172
template <class T>
185173
inline dbSetIterator<T>& dbSetIterator<T>::operator++()
186174
{
187-
_cur = _itr->next(_cur);
175+
cur_ = itr_->next(cur_);
188176
return *this;
189177
}
190178

191179
template <class T>
192180
inline dbSetIterator<T> dbSetIterator<T>::operator++(int)
193181
{
194182
dbSetIterator it(*this);
195-
_cur = _itr->next(_cur);
183+
cur_ = itr_->next(cur_);
196184
return it;
197185
}
198186

src/odb/include/odb/dbShape.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <cmath>
88
#include <vector>
99

10-
#include "odb/ZException.h"
1110
#include "odb/dbObject.h"
1211
#include "odb/dbSet.h"
1312
#include "odb/dbTransform.h"

src/odb/include/odb/dbStream.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <vector>
2121

2222
#include "boost/container/flat_map.hpp"
23-
#include "odb/ZException.h"
2423
#include "odb/dbObject.h"
2524
#include "odb/odb.h"
2625

0 commit comments

Comments
 (0)