From a139654980b2d2560667b12c886de7518ec97c40 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 12 Jun 2018 15:08:01 +0200 Subject: Add IdString API Signed-off-by: Clifford Wolf --- common/nextpnr.h | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'common/nextpnr.h') diff --git a/common/nextpnr.h b/common/nextpnr.h index 0c74c1ad..bc92719f 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -41,8 +41,43 @@ NEXTPNR_NAMESPACE_BEGIN -// replace with proper IdString later -typedef std::string IdString; +struct IdString +{ + std::string data; + + IdString() {} + IdString(std::string s) : data(s) {} + IdString(const char *s) : data(s) {} + + const char *c_str() const { return data.c_str(); } + const std::string &str() const { return data; } + + operator const char *() const { return c_str(); } + operator const std::string &() const { return str(); } + + bool operator<(const IdString &other) const { return data < other.data; } + bool operator==(const IdString &other) const { return data == other.data; } + bool operator==(const std::string &s) const { return data == s; } + bool operator==(const char *s) const { return data == s; } + + size_t size() const { return data.size(); } + bool empty() const { return data.empty(); } +}; + +NEXTPNR_NAMESPACE_END + +namespace std { +template <> struct hash +{ + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX IdString &obj) const + noexcept + { + return std::hash()(obj.data); + } +}; +} + +NEXTPNR_NAMESPACE_BEGIN struct GraphicElement { -- cgit v1.2.3