aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-11 14:02:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-11 14:02:00 +0000
commitcc9a5b5398a299ade3e9e83fb5f8e69413771716 (patch)
treefdf66a91956e53a9baf477efca8459ed6ee3052a
parenta45a81f92f9c1c0a9bcfd1a8c790d9f76c60888c (diff)
downloadpaludis-cc9a5b5398a299ade3e9e83fb5f8e69413771716.tar.gz
paludis-cc9a5b5398a299ade3e9e83fb5f8e69413771716.tar.xz
Change how we avoid stringify compiling for pointers etc so that &stringify<T_> can be used. Fix test cases that relied upon being able to stringify pointers.
-rw-r--r--paludis/util/instantiation_policy_TEST.cc4
-rw-r--r--paludis/util/log_TEST.cc2
-rw-r--r--paludis/util/stringify.hh54
3 files changed, 36 insertions, 24 deletions
diff --git a/paludis/util/instantiation_policy_TEST.cc b/paludis/util/instantiation_policy_TEST.cc
index f57ab99..581fc54 100644
--- a/paludis/util/instantiation_policy_TEST.cc
+++ b/paludis/util/instantiation_policy_TEST.cc
@@ -91,7 +91,7 @@ namespace test_cases
TEST_CHECK_EQUAL(MyClass::instances, 0);
TEST_CHECK(0 != MyClass::get_instance());
TEST_CHECK_EQUAL(MyClass::instances, 1);
- TEST_CHECK_EQUAL(MyClass::get_instance(), MyClass::get_instance());
+ TEST_CHECK(MyClass::get_instance() == MyClass::get_instance());
TEST_CHECK(MyClass::get_instance()->s.empty());
MyClass::get_instance()->s = "foo";
TEST_CHECK_EQUAL(MyClass::get_instance()->s, "foo");
@@ -115,7 +115,7 @@ namespace test_cases
TEST_CHECK_EQUAL(MyLoadAtStartupClass::instances, 1);
TEST_CHECK(0 != MyLoadAtStartupClass::get_instance());
TEST_CHECK_EQUAL(MyLoadAtStartupClass::instances, 1);
- TEST_CHECK_EQUAL(MyLoadAtStartupClass::get_instance(), MyLoadAtStartupClass::get_instance());
+ TEST_CHECK(MyLoadAtStartupClass::get_instance() == MyLoadAtStartupClass::get_instance());
TEST_CHECK(MyLoadAtStartupClass::get_instance()->s.empty());
MyLoadAtStartupClass::get_instance()->s = "foo";
TEST_CHECK_EQUAL(MyLoadAtStartupClass::get_instance()->s, "foo");
diff --git a/paludis/util/log_TEST.cc b/paludis/util/log_TEST.cc
index 4f14616..8fd9bd6 100644
--- a/paludis/util/log_TEST.cc
+++ b/paludis/util/log_TEST.cc
@@ -39,7 +39,7 @@ namespace test_cases
void run()
{
TEST_CHECK(Log::get_instance());
- TEST_CHECK_EQUAL(Log::get_instance(), Log::get_instance());
+ TEST_CHECK(Log::get_instance() == Log::get_instance());
std::stringstream s;
Log::get_instance()->set_log_stream(&s);
diff --git a/paludis/util/stringify.hh b/paludis/util/stringify.hh
index bafcdd1..d259a7d 100644
--- a/paludis/util/stringify.hh
+++ b/paludis/util/stringify.hh
@@ -22,6 +22,7 @@
#include <sstream>
#include <string>
+#include <paludis/util/attributes.hh>
/** \file
* Stringify functions.
@@ -29,6 +30,34 @@
namespace paludis
{
+ template <typename T_, typename U_, typename V_>
+ class CountedPtr;
+
+ namespace stringify_internals
+ {
+ template <typename T_>
+ struct CheckType
+ {
+ enum { value = 0 } Value;
+ };
+
+ template <typename T_>
+ struct CheckType<T_ *>
+ {
+ };
+
+ template <typename T_, typename U_, typename V_>
+ struct CheckType<CountedPtr<T_, U_, V_> >
+ {
+ };
+
+ template <>
+ struct CheckType<char *>
+ {
+ enum { value = 0 } Value;
+ };
+ }
+
/**
* Convert item to a string.
*/
@@ -36,6 +65,10 @@ namespace paludis
std::string
stringify(const T_ & item)
{
+ /* check that we're not trying to stringify a pointer or somesuch */
+ int check_for_stringifying_silly_things
+ PALUDIS_ATTRIBUTE((unused)) = stringify_internals::CheckType<T_>::value;
+
std::ostringstream s;
s << item;
return s.str();
@@ -78,27 +111,6 @@ namespace paludis
}
/**
- * Convert item to a string (undefined overload for pointers, to
- * catch screwups at compiletime rather than printing out addresses in
- * weird places because of a missing *).
- */
- template <typename T_>
- void
- stringify(const T_ * const item);
-
- template <typename T_, typename U_, typename V_>
- class CountedPtr;
-
- /**
- * Convert item to a string (undefined overload for counted
- * pointers, to catch screwups at compiletime rather than printing
- * out addresses in weird places because of a missing *).
- */
- template <typename T_, typename U_, typename V_>
- void
- stringify(const CountedPtr<T_, U_, V_> & item);
-
- /**
* Convert item to a string (overload for char *, which isn't a
* screwup like other pointers).
*/