2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2026-03-10 21:21:17 +01:00
|
|
|
// Copyright (c) 2026, Parallax Software, Inc.
|
2018-09-28 17:54:21 +02:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2022-01-04 18:17:08 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-28 17:54:21 +02:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2022-01-04 18:17:08 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2025-01-22 02:54:33 +01:00
|
|
|
//
|
|
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
|
|
|
|
//
|
|
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
|
|
|
|
//
|
|
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-02-16 01:13:16 +01:00
|
|
|
#pragma once
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
// Java style container iterator.
|
|
|
|
|
// Iterator<Object*> iter(container);
|
|
|
|
|
// while (iter.hasNext()) {
|
|
|
|
|
// Object *obj = iter.next();
|
|
|
|
|
// }
|
|
|
|
|
template <class OBJ>
|
|
|
|
|
class Iterator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Iterator() {}
|
|
|
|
|
virtual bool hasNext() = 0;
|
|
|
|
|
virtual OBJ next() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-04 01:59:35 +01:00
|
|
|
template <typename VECTOR_TYPE, typename OBJ_TYPE>
|
|
|
|
|
class VectorIterator : public Iterator<OBJ_TYPE>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VectorIterator(const VECTOR_TYPE *seq) :
|
|
|
|
|
seq_(seq)
|
|
|
|
|
{
|
|
|
|
|
if (seq_)
|
|
|
|
|
itr_ = seq_->begin();
|
|
|
|
|
}
|
|
|
|
|
VectorIterator(const VECTOR_TYPE &seq) :
|
|
|
|
|
seq_(&seq),
|
|
|
|
|
itr_(seq.begin())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 22:07:40 +01:00
|
|
|
bool hasNext() override { return seq_ && itr_ != seq_->end(); }
|
|
|
|
|
OBJ_TYPE next() override { return *itr_++; }
|
2026-01-04 01:59:35 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
const VECTOR_TYPE *seq_;
|
|
|
|
|
VECTOR_TYPE::const_iterator itr_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename MAP_TYPE, typename OBJ_TYPE>
|
|
|
|
|
class MapIterator : public Iterator<OBJ_TYPE>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MapIterator(const MAP_TYPE *map) :
|
|
|
|
|
map_(map)
|
|
|
|
|
{
|
|
|
|
|
if (map)
|
|
|
|
|
itr_ = map->begin();
|
|
|
|
|
}
|
|
|
|
|
MapIterator(const MAP_TYPE &map) :
|
|
|
|
|
map_(&map),
|
|
|
|
|
itr_(map.begin())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 22:07:40 +01:00
|
|
|
bool hasNext() override { return map_ && itr_ != map_->end(); }
|
|
|
|
|
OBJ_TYPE next() override {
|
2026-01-04 01:59:35 +01:00
|
|
|
OBJ_TYPE next = itr_->second;
|
|
|
|
|
itr_++;
|
|
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
const MAP_TYPE *map_;
|
|
|
|
|
MAP_TYPE::const_iterator itr_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename SET_TYPE, typename OBJ_TYPE>
|
|
|
|
|
class SetIterator : public Iterator<OBJ_TYPE>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SetIterator(const SET_TYPE *set) :
|
|
|
|
|
set_(set)
|
|
|
|
|
{
|
|
|
|
|
if (set)
|
|
|
|
|
itr_ = set->begin();
|
|
|
|
|
}
|
|
|
|
|
SetIterator(const SET_TYPE &set) :
|
|
|
|
|
set_(&set),
|
|
|
|
|
itr_(set.begin())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 22:07:40 +01:00
|
|
|
bool hasNext() override { return set_ && itr_ != set_->end(); }
|
|
|
|
|
OBJ_TYPE next() override { return *itr_++; }
|
2026-01-04 01:59:35 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
const SET_TYPE *set_;
|
|
|
|
|
SET_TYPE::const_iterator itr_;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
} // namespace
|