r38984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38983‎ | r38984 | r38985 >
Date:09:16, 9 August 2008
Author:river
Status:old
Tags:
Comment:
implement unary - + operators
Modified paths:
  • /trunk/extensions/AbuseFilter/parser_native/aftypes.cpp (modified) (history)
  • /trunk/extensions/AbuseFilter/parser_native/aftypes.h (modified) (history)
  • /trunk/extensions/AbuseFilter/parser_native/parser.cpp (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/parser_native/aftypes.cpp
@@ -263,6 +263,18 @@
264264 from_string_converter<T>::convert(a),
265265 from_string_converter<U>::convert(b));
266266 }
 267+
 268+ /*
 269+ * Unary version.
 270+ */
 271+ template<typename T>
 272+ datum operator() (T const &a) const {
 273+ typedef typename from_string_converter<T>::type a_type;
 274+
 275+ Operator<typename preferred_type<a_type, a_type>::type> op;
 276+ return op(from_string_converter<T>::convert(a));
 277+ }
 278+
267279 };
268280
269281 /*
@@ -370,6 +382,18 @@
371383 }
372384
373385 datum
 386+datum::operator+() const
 387+{
 388+ return *this;
 389+}
 390+
 391+datum
 392+datum::operator-() const
 393+{
 394+ return boost::apply_visitor(arith_visitor<std::negate>(), value_);
 395+}
 396+
 397+datum
374398 operator+(datum const &a, datum const &b) {
375399 return datum(a) += b;
376400 }
Index: trunk/extensions/AbuseFilter/parser_native/aftypes.h
@@ -84,6 +84,8 @@
8585 datum &operator/=(datum const &other);
8686 datum &operator%=(datum const &other);
8787 bool operator!() const;
 88+ datum operator+() const;
 89+ datum operator-() const;
8890
8991 bool compare(datum const &other) const;
9092 bool compare_with_type(datum const &other) const;
Index: trunk/extensions/AbuseFilter/parser_native/parser.cpp
@@ -293,6 +293,8 @@
294294 basic =
295295 ( '(' >> tern_expr[basic.val = arg1] >> ')' )
296296 | ch_p('!') >> tern_expr[basic.val = !arg1]
 297+ | ch_p('+') >> tern_expr[basic.val = arg1]
 298+ | ch_p('-') >> tern_expr[basic.val = -arg1]
297299 | variable[basic.val = arg1]
298300 | function[basic.val = arg1]
299301 | value[basic.val = arg1]

Status & tagging log