mirror of https://github.com/KLayout/klayout.git
Made region tests less susceptible to 'unordered_set' implementation details.
This commit is contained in:
parent
c184a8a5fb
commit
3677a36804
|
|
@ -43,16 +43,26 @@ template<> void extractor_impl (tl::Extractor &ex, db::DEdgePair &e)
|
|||
template<class C> bool _test_extractor_impl (tl::Extractor &ex, db::edge_pair<C> &e)
|
||||
{
|
||||
typedef db::edge<C> edge_type;
|
||||
tl::Extractor ex_saved = ex;
|
||||
|
||||
edge_type e1, e2;
|
||||
|
||||
if (ex.try_read (e1)) {
|
||||
|
||||
ex.expect ("/");
|
||||
ex.read (e2);
|
||||
bool symmetric = false;
|
||||
if (ex.test ("|")) {
|
||||
symmetric = true;
|
||||
} else if (! ex.test ("/")) {
|
||||
ex = ex_saved;
|
||||
return false;
|
||||
}
|
||||
|
||||
e = db::edge_pair<C> (e1, e2);
|
||||
if (! ex.try_read (e2)) {
|
||||
ex = ex_saved;
|
||||
return false;
|
||||
}
|
||||
|
||||
e = db::edge_pair<C> (e1, e2, symmetric);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -204,6 +204,9 @@ namespace tl
|
|||
{
|
||||
db::EdgePair ep;
|
||||
|
||||
if (ex.at_end ()) {
|
||||
return true;
|
||||
}
|
||||
if (! ex.try_read (ep)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,6 +229,9 @@ namespace tl
|
|||
{
|
||||
db::Edge p;
|
||||
|
||||
if (ex.at_end ()) {
|
||||
return true;
|
||||
}
|
||||
if (! ex.try_read (p)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -514,6 +514,8 @@ template<class C> DB_PUBLIC bool _test_extractor_impl (tl::Extractor &ex, db::po
|
|||
|
||||
if (ex.test ("(")) {
|
||||
|
||||
p.clear ();
|
||||
|
||||
point_type pt;
|
||||
while (ex.try_read (pt)) {
|
||||
points.push_back (pt);
|
||||
|
|
|
|||
|
|
@ -607,6 +607,9 @@ namespace tl
|
|||
{
|
||||
db::Polygon p;
|
||||
|
||||
if (ex.at_end ()) {
|
||||
return true;
|
||||
}
|
||||
if (! ex.try_read (p)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -623,7 +626,7 @@ namespace tl
|
|||
template<> DB_PUBLIC void extractor_impl (tl::Extractor &ex, db::Region &b)
|
||||
{
|
||||
if (! test_extractor_impl (ex, b)) {
|
||||
ex.error (tl::to_string (tr ("Expected an region collection specification")));
|
||||
ex.error (tl::to_string (tr ("Expected a region specification")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@
|
|||
#include "dbLayoutDiff.h"
|
||||
#include "dbNetlist.h"
|
||||
#include "dbNetlistCompare.h"
|
||||
#include "dbRegion.h"
|
||||
#include "dbEdges.h"
|
||||
#include "dbEdgePairs.h"
|
||||
#include "dbTexts.h"
|
||||
|
||||
#include "tlUnitTest.h"
|
||||
#include "tlFileUtils.h"
|
||||
|
|
@ -326,5 +330,87 @@ void DB_PUBLIC compare_netlist (tl::TestBase *_this, const db::Netlist &netlist,
|
|||
}
|
||||
}
|
||||
|
||||
template <class Container, class Shape>
|
||||
static
|
||||
bool do_compare (const Container &cont, const std::string &string)
|
||||
{
|
||||
std::set<Shape> a, b;
|
||||
|
||||
Container cs;
|
||||
tl::Extractor ex (string.c_str ());
|
||||
ex.read (cs);
|
||||
|
||||
for (typename Container::const_iterator i = cont.begin (); !i.at_end (); ++i) {
|
||||
a.insert (*i);
|
||||
}
|
||||
|
||||
for (typename Container::const_iterator i = cs.begin (); !i.at_end (); ++i) {
|
||||
b.insert (*i);
|
||||
}
|
||||
|
||||
if (a != b) {
|
||||
|
||||
tl::error << "Compare details:";
|
||||
tl::error << " a = '" << cont.to_string () << "'";
|
||||
tl::error << " b = '" << cs.to_string () << "'";
|
||||
tl::error << "In list a, but not in b:";
|
||||
for (typename std::set<Shape>::const_iterator i = a.begin (); i != a.end (); ++i) {
|
||||
if (b.find (*i) == b.end ()) {
|
||||
tl::error << " " << i->to_string ();
|
||||
}
|
||||
}
|
||||
tl::error << "In list b, but not in a:";
|
||||
for (typename std::set<Shape>::const_iterator i = b.begin (); i != b.end (); ++i) {
|
||||
if (a.find (*i) == a.end ()) {
|
||||
tl::error << " " << i->to_string ();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of region vs. string
|
||||
*/
|
||||
bool compare (const db::Region ®ion, const std::string &string)
|
||||
{
|
||||
return do_compare<db::Region, db::Polygon> (region, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of edges vs. string
|
||||
*/
|
||||
bool compare (const db::Edges &edges, const std::string &string)
|
||||
{
|
||||
return do_compare<db::Edges, db::Edge> (edges, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of edge pairs vs. string
|
||||
*/
|
||||
bool compare (const db::EdgePairs &edge_pairs, const std::string &string)
|
||||
{
|
||||
return do_compare<db::EdgePairs, db::EdgePair> (edge_pairs, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of texts vs. string
|
||||
*/
|
||||
bool compare (const db::Texts &texts, const std::string &string)
|
||||
{
|
||||
return do_compare<db::Texts, db::Text> (texts, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of box vs. string
|
||||
*/
|
||||
bool compare (const db::Box &box, const std::string &string)
|
||||
{
|
||||
return box.to_string () == string;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "dbCommon.h"
|
||||
#include "dbTypes.h"
|
||||
#include "dbBox.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
@ -40,6 +41,10 @@ class Layout;
|
|||
class Cell;
|
||||
class LayerMap;
|
||||
class Netlist;
|
||||
class Region;
|
||||
class EdgePairs;
|
||||
class Edges;
|
||||
class Texts;
|
||||
|
||||
/**
|
||||
* @brief Specifies the normalization mode for compare_layouts
|
||||
|
|
@ -84,6 +89,31 @@ void DB_PUBLIC compare_netlist (tl::TestBase *_this, const db::Netlist &netlist,
|
|||
*/
|
||||
void DB_PUBLIC compare_netlist (tl::TestBase *_this, const db::Netlist &netlist, const db::Netlist &netlist_au, bool exact_parameter_match = false);
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of region vs. string
|
||||
*/
|
||||
bool DB_PUBLIC compare (const db::Region ®ion, const std::string &string);
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of edges vs. string
|
||||
*/
|
||||
bool DB_PUBLIC compare (const db::Edges &edges, const std::string &string);
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of edge pairs vs. string
|
||||
*/
|
||||
bool DB_PUBLIC compare (const db::EdgePairs &edge_pairs, const std::string &string);
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of texts vs. string
|
||||
*/
|
||||
bool DB_PUBLIC compare (const db::Texts &texts, const std::string &string);
|
||||
|
||||
/**
|
||||
* @brief Convenient compare of box vs. string
|
||||
*/
|
||||
bool DB_PUBLIC compare (const db::Box &box, const std::string &string);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -194,6 +194,9 @@ namespace tl
|
|||
{
|
||||
db::Text ep;
|
||||
|
||||
if (ex.at_end ()) {
|
||||
return true;
|
||||
}
|
||||
if (! ex.try_read (ep)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue