aboutsummaryrefslogtreecommitdiffstats
path: root/common/util.h
diff options
context:
space:
mode:
authorEddie Hung <eddie.hung+gitlab@gmail.com>2018-07-15 19:22:57 +0000
committerEddie Hung <eddie.hung+gitlab@gmail.com>2018-07-15 19:22:57 +0000
commit0bae7f5606b15591a23fb63da1c5ff6f93b40747 (patch)
tree7b0760fa1e5c837f9b43cf1c97fa9f55973a169b /common/util.h
parent1457a6453c11af34a73460868833a9462e987854 (diff)
parent21bf78dae9ef95e65b549c60061bce9790b1b611 (diff)
downloadnextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.tar.gz
nextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.tar.bz2
nextpnr-0bae7f5606b15591a23fb63da1c5ff6f93b40747.zip
Merge branch 'master' into 'master'
Master See merge request eddiehung/nextpnr!1
Diffstat (limited to 'common/util.h')
-rw-r--r--common/util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/util.h b/common/util.h
index 60eb35af..8f361dc8 100644
--- a/common/util.h
+++ b/common/util.h
@@ -39,6 +39,18 @@ ValueType get_or_default(const Container &ct, const KeyType &key, ValueType def
return found->second;
};
+// Get a value from a map-style container, returning default if value is not
+// found (forces string)
+template <typename Container, typename KeyType>
+std::string str_or_default(const Container &ct, const KeyType &key, std::string def = "")
+{
+ auto found = ct.find(key);
+ if (found == ct.end())
+ return def;
+ else
+ return found->second;
+};
+
// Get a value from a map-style container, converting to int, and returning
// default if value is not found
template <typename Container, typename KeyType> int int_or_default(const Container &ct, const KeyType &key, int def = 0)
@@ -84,6 +96,7 @@ inline const NetInfo *get_net_or_empty(const CellInfo *cell, const IdString port
else
return nullptr;
};
+
NEXTPNR_NAMESPACE_END
#endif