diff options
Diffstat (limited to 'src/core/common')
-rw-r--r-- | src/core/common/Rtti.cpp | 11 | ||||
-rw-r--r-- | src/core/common/Rtti.hpp | 11 | ||||
-rw-r--r-- | src/core/common/Utils.hpp | 24 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/core/common/Rtti.cpp b/src/core/common/Rtti.cpp index 6849a0e..acc98a7 100644 --- a/src/core/common/Rtti.cpp +++ b/src/core/common/Rtti.cpp @@ -147,6 +147,17 @@ bool Rtti::setIsOneOf(const RttiSet &s1, const RttiSet &s2) return false; } +RttiSet Rtti::setIntersection(const RttiSet &s1, const RttiSet &s2) +{ + RttiSet res; + for (const Rtti *t1 : s1) { + if (t1->isOneOf(s2)) { + res.insert(t1); + } + } + return res; +} + bool Rtti::composedOf(const Rtti &other) const { initialize(); diff --git a/src/core/common/Rtti.hpp b/src/core/common/Rtti.hpp index 05cc728..f371494 100644 --- a/src/core/common/Rtti.hpp +++ b/src/core/common/Rtti.hpp @@ -403,6 +403,17 @@ public: static bool setIsOneOf(const RttiSet &s1, const RttiSet &s2); /** + * Calculates the intersection of two RttiSets. Only the elements of s1 + * which are at least one element in s2 are returned. + * + * @param s1 is the first set. For each type in this set we check whether + * it is one of the types in s2, only those elements are returned. + * @param s2 is the second set. + * @return s1 restricted to the types in s2. + */ + static RttiSet setIntersection(const RttiSet &s1, const RttiSet &s2); + + /** * Returns true if an instance of this type may have references to the other * given type. This mechanism is used to prune impossible paths when * resolving objects of a certain type by name in an object graph. diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp index f6f5225..a88c716 100644 --- a/src/core/common/Utils.hpp +++ b/src/core/common/Utils.hpp @@ -73,10 +73,7 @@ public: /** * Returns true if the given character is a whitespace character. */ - static bool isLinebreak(const char c) - { - return (c == '\n') || (c == '\r'); - } + static bool isLinebreak(const char c) { return (c == '\n') || (c == '\r'); } /** * Removes whitespace at the beginning and the end of the given string. @@ -93,11 +90,12 @@ public: * @param s is the container that should be trimmed. * @param f is a function that returns true for values that should be * removed. - * @return start and end index. Note that "end" points at the character beyond - * the end, thus "end" minus "start" + * @return start and end index. Note that "end" points at the character + * beyond the end, thus "end" minus "start" */ template <class T, class Filter> - static std::pair<size_t, size_t> trim(const T &s, Filter f) { + static std::pair<size_t, size_t> trim(const T &s, Filter f) + { size_t start = 0; for (size_t i = 0; i < s.size(); i++) { if (!f(s[i])) { @@ -181,6 +179,18 @@ public: * lowercase. */ static std::string extractFileExtension(const std::string &filename); + + /** + * Hash functional to be used for enum classes. + * See http://stackoverflow.com/a/24847480/2188211 + */ + struct EnumHash { + template <typename T> + std::size_t operator()(T t) const + { + return static_cast<std::size_t>(t); + } + }; }; } |