summaryrefslogtreecommitdiff
path: root/core/id_list.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/id_list.hpp')
-rw-r--r--core/id_list.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/id_list.hpp b/core/id_list.hpp
new file mode 100644
index 0000000..99ff5a2
--- /dev/null
+++ b/core/id_list.hpp
@@ -0,0 +1,47 @@
+#ifndef iUCKfY0lAetXcXu8Ykh6wMB3KhQ
+#define iUCKfY0lAetXcXu8Ykh6wMB3KhQ
+
+#include <set>
+
+#include <boost/xpressive/xpressive_static.hpp>
+#include <boost/xpressive/regex_actions.hpp>
+
+namespace IdListImpl {
+
+using namespace boost::xpressive;
+
+struct push_impl {
+ typedef void result_type;
+ template<typename Set, class Value>
+ void operator()(Set &s, Value const &from, Value const &until) const {
+ for (Value i = from; i <= until; ++i)
+ s.insert(i);
+ }
+};
+function<push_impl>::type const pushRange = {{}};
+
+
+template<typename ID>
+struct IdList : std::set<ID> {
+ explicit IdList(char *s = (char*) "") {
+ cregex number = (s1= +_d)
+ [insert(boost::xpressive::ref(*this), as<ID>(s1))];
+ cregex range = ((s1= +_d) >> as_xpr('-') >> (s2= +_d))
+ [pushRange(boost::xpressive::ref(*this), as<ID>(s1), as<ID>(s2))];
+ cregex list = *((range | number) >> *( as_xpr(',') >> (range | number)));
+ assert(regex_match(s, list));
+ }
+
+ template<typename OtherID>
+ IdList(IdList<OtherID> &src) {
+ for (auto i : src) {
+ assert(i <= std::numeric_limits<ID>::max());
+ this->insert(i);
+ }
+ }
+};
+
+} // IdListImpl
+
+using IdListImpl::IdList;
+#endif // iUCKfY0lAetXcXu8Ykh6wMB3KhQ
contact: Jan Huwald // Impressum