r39296 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39295‎ | r39296 | r39297 >
Date:16:42, 13 August 2008
Author:river
Status:old
Tags:
Comment:
provide nicer type names in error messages
Modified paths:
  • /trunk/extensions/AbuseFilter/parser_native/include/functors.h (modified) (history)
  • /trunk/extensions/AbuseFilter/parser_native/include/type_name.h (added) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/parser_native/include/type_name.h
@@ -0,0 +1,70 @@
 2+/*
 3+ * Copyright (c) 2008 Andrew Garrett.
 4+ * Copyright (c) 2008 River Tarnell <river@wikimedia.org>
 5+ * Derived from public domain code contributed by Victor Vasiliev.
 6+ *
 7+ * Permission is granted to anyone to use this software for any purpose,
 8+ * including commercial applications, and to alter it and redistribute it
 9+ * freely. This software is provided 'as-is', without any express or
 10+ * implied warranty.
 11+ */
 12+
 13+#ifndef TYPE_NAME_H
 14+#define TYPE_NAME_H
 15+
 16+#include <boost/date_time.hpp>
 17+#include <gmpxx.h>
 18+
 19+#include "fray.h"
 20+
 21+/*
 22+ * A helper class to provide nicer names for types than the compiler-generated
 23+ * ones, which look like 10__gmp_exprIA1_12__mpz_structS1_E.
 24+ */
 25+namespace afp {
 26+
 27+template<typename T>
 28+struct type_name {
 29+ static std::string name() {
 30+ return typeid(T).name();
 31+ }
 32+};
 33+
 34+template<>
 35+struct type_name<mpf_class> {
 36+ static std::string name() {
 37+ return "float";
 38+ }
 39+};
 40+
 41+template<>
 42+struct type_name<mpz_class> {
 43+ static std::string name() {
 44+ return "integer";
 45+ }
 46+};
 47+
 48+template<>
 49+struct type_name<boost::posix_time::ptime> {
 50+ static std::string name() {
 51+ return "datetime";
 52+ }
 53+};
 54+
 55+template<>
 56+struct type_name<boost::posix_time::time_duration> {
 57+ static std::string name() {
 58+ return "time_duration";
 59+ }
 60+};
 61+
 62+template<>
 63+struct type_name<u32fray> {
 64+ static std::string name() {
 65+ return "string";
 66+ }
 67+};
 68+
 69+} // namespace afp
 70+
 71+#endif /* !TYPE_NAME_H */
Index: trunk/extensions/AbuseFilter/parser_native/include/functors.h
@@ -15,6 +15,7 @@
1616 #include <boost/format.hpp>
1717
1818 #include "return_type.h"
 19+#include "type_name.h"
1920
2021 /*
2122 * Various functors used for datums. Unlike the standard functor, these are
@@ -88,7 +89,7 @@
8990 operator() (T, U) const {
9091 std::string s(str(boost::format(
9192 "operator %s cannot be applied to the types ('%s', '%s')")
92 - % opname_ % typeid(T).name() % typeid(U).name()));
 93+ % opname_ % type_name<T>::name() % type_name<U>::name()));
9394
9495 throw type_error(s);
9596 }

Status & tagging log