diff --git a/lib/wlib/stl/Comparator.h b/lib/wlib/stl/Comparator.h new file mode 100644 index 00000000..52b40a85 --- /dev/null +++ b/lib/wlib/stl/Comparator.h @@ -0,0 +1,132 @@ +#ifndef EMBEDDEDCPLUSPLUS_COMPARATOR_H +#define EMBEDDEDCPLUSPLUS_COMPARATOR_H + +#include + +#include "../WlibConfig.h" +#include "Equal.h" + +namespace wlp { + + int8_t strcmp(const char *s1, const char *s2) { + for (; *s1 == *s2; ++s1, ++s2) { + if (*s1 == 0) { + return 0; + } + } + return *s2 - *s1; + } + + template + struct Comparator { + bool __lt__(const T t1, const T t2) const { + return t1 < t2; + } + bool __le__(const T t1, const T t2) const { + return t1 <= t2; + } + bool __eq__(const T t1, const T t2) const { + return t1 == t2; + } + bool __ne__(const T t1, const T t2) const { + return t1 != t2; + } + bool __gt__(const T t1, const T t2) const { + return t1 > t2; + } + bool __ge__(const T t1, const T t2) const { + return t1 >= t2; + } + }; + + TEMPLATE_NULL + struct Comparator { + bool __lt__(const char *s1, const char *s2) { + return strcmp(s1, s2) < 0; + } + bool __le__(const char *s1, const char *s2) { + return strcmp(s1, s2) <= 0; + } + bool __eq__(const char *s1, const char *s2) { + return strcmp(s1, s2) == 0; + } + bool __ne__(const char *s1, const char *s2) { + return strcmp(s1, s2) != 0; + } + bool __gt__(const char *s1, const char *s2) { + return strcmp(s1, s2) > 0; + } + bool __ge__(const char *s1, const char *s2) { + return strcmp(s1, s2) >= 0; + } + }; + + TEMPLATE_NULL + struct Comparator { + bool __lt__(const char *s1, const char *s2) { + return strcmp(s1, s2) < 0; + } + bool __le__(const char *s1, const char *s2) { + return strcmp(s1, s2) <= 0; + } + bool __eq__(const char *s1, const char *s2) { + return strcmp(s1, s2) == 0; + } + bool __ne__(const char *s1, const char *s2) { + return strcmp(s1, s2) != 0; + } + bool __gt__(const char *s1, const char *s2) { + return strcmp(s1, s2) > 0; + } + bool __ge__(const char *s1, const char *s2) { + return strcmp(s1, s2) >= 0; + } + };ß + + template + struct Comparator> { + bool __lt__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) < 0; + } + bool __le__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) <= 0; + } + bool __eq__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) == 0; + } + bool __ne__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) != 0; + } + bool __gt__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) > 0; + } + bool __ge__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) >= 0; + } + }; + + template + struct Comparator> { + bool __lt__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) < 0; + } + bool __le__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) <= 0; + } + bool __eq__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) == 0; + } + bool __ne__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) != 0; + } + bool __gt__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) > 0; + } + bool __ge__(const StaticString &s1, const StaticString &s2) { + return strcmp(s1.c_str(), s2.c_str()) >= 0; + } + }; + +} + +#endif //EMBEDDEDCPLUSPLUS_COMPARATOR_H diff --git a/lib/wlib/stl/Equal.h b/lib/wlib/stl/Equal.h index 1e716d7d..46bc857c 100644 --- a/lib/wlib/stl/Equal.h +++ b/lib/wlib/stl/Equal.h @@ -52,7 +52,14 @@ namespace wlp { } template - struct equals > { + struct equals> { + bool operator()(const StaticString &key1, const StaticString &key2) const { + return static_string_equals(key1, key2); + } + }; + + template + struct equals> { bool operator()(const StaticString &key1, const StaticString &key2) const { return static_string_equals(key1, key2); }