diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:08:01 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:08:01 +0200 |
commit | a139654980b2d2560667b12c886de7518ec97c40 (patch) | |
tree | 7f8d1c6f5553af3ae637e087a86988b04faa5db7 /common/nextpnr.h | |
parent | 592a627e0c99ddf2cf06c286813a2d08962d8cd9 (diff) | |
download | nextpnr-a139654980b2d2560667b12c886de7518ec97c40.tar.gz nextpnr-a139654980b2d2560667b12c886de7518ec97c40.tar.bz2 nextpnr-a139654980b2d2560667b12c886de7518ec97c40.zip |
Add IdString API
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'common/nextpnr.h')
-rw-r--r-- | common/nextpnr.h | 39 |
1 files changed, 37 insertions, 2 deletions
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<NEXTPNR_NAMESPACE_PREFIX IdString> +{ + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX IdString &obj) const + noexcept + { + return std::hash<std::string>()(obj.data); + } +}; +} + +NEXTPNR_NAMESPACE_BEGIN struct GraphicElement { |