From: g0dil Date: Mon, 5 Oct 2009 12:56:07 +0000 (+0000) Subject: Utils: Much better TypeIdValue implementation X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=a9d8ca7d0cd9d0ee9d3bd37988546d016ea5c27a;p=senf.git Utils: Much better TypeIdValue implementation git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1476 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Utils/TypeIdValue.cc b/senf/Utils/TypeIdValue.cc index bc0d01b..55fad7d 100644 --- a/senf/Utils/TypeIdValue.cc +++ b/senf/Utils/TypeIdValue.cc @@ -32,9 +32,6 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ senf::TypeIdValue::Value::~Value() -{} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "TypeIdValue.mpp" diff --git a/senf/Utils/TypeIdValue.cci b/senf/Utils/TypeIdValue.cci index e73ffd0..e11e44b 100644 --- a/senf/Utils/TypeIdValue.cci +++ b/senf/Utils/TypeIdValue.cci @@ -27,48 +27,48 @@ // Custom includes #include "TypeInfo.hh" +#include "senfassert.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// prefix_ senf::TypeIdValue::TypeIdValue() - : value_(new ValueImpl()) + : p_ (&typeid(void)) {} -prefix_ senf::TypeIdValue::TypeIdValue(TypeIdValue const & other) -{ - value_.reset(other.value_->clone()); -} - -prefix_ senf::TypeIdValue const & -senf::TypeIdValue::operator=(TypeIdValue const & other) -{ - value_.reset(other.value_->clone()); - return *this; -} +prefix_ senf::TypeIdValue::TypeIdValue(std::type_info const & v) + : p_ (&v) +{} prefix_ bool senf::TypeIdValue::operator==(TypeIdValue const & other) const { - return value_->id() == other.value_->id(); + return (*p_) == (*other.p_); } prefix_ bool senf::TypeIdValue::operator<(TypeIdValue const & other) const { - return value_->id().before(other.value_->id()); + return p_->before(*other.p_); } prefix_ std::string senf::TypeIdValue::name() const { - return std::string(value_->id().name()); + return p_->name(); +} + +prefix_ std::string senf::TypeIdValue::prettyName() + const +{ + return senf::prettyName(id()); } prefix_ std::type_info const & senf::TypeIdValue::id() const { - return value_->id(); + SENF_ASSERT(p_); + return *p_; } prefix_ senf::TypeIdValue const senf::typeIdValue() @@ -78,7 +78,7 @@ prefix_ senf::TypeIdValue const senf::typeIdValue() prefix_ std::ostream & senf::operator<<(std::ostream & os, TypeIdValue const & v) { - os << prettyName(v.id()); + os << v.prettyName(); return os; } diff --git a/senf/Utils/TypeIdValue.cti b/senf/Utils/TypeIdValue.cti index ade0402..a90b470 100644 --- a/senf/Utils/TypeIdValue.cti +++ b/senf/Utils/TypeIdValue.cti @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -31,39 +31,27 @@ ///////////////////////////////cti.p/////////////////////////////////////// template -prefix_ senf::TypeIdValue::TypeIdValue(Type *) - : value_(new ValueImpl()) -{} - -template -prefix_ std::type_info const & senf::TypeIdValue::ValueImpl::id() +prefix_ senf::TypeIdValue const senf::typeIdValue() { return typeid(Type); } template -prefix_ senf::TypeIdValue::Value * -senf::TypeIdValue::ValueImpl::clone() -{ - return new ValueImpl(); -} - -template -prefix_ senf::TypeIdValue const senf::typeIdValue() +prefix_ senf::TypeIdValue const senf::typeidValue(Type const & ob) { - return TypeIdValue(static_cast(0)); + return typeid(ob); } -///////////////////////////////cti.e/////////////////////////////////////// +/////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 +// comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" -// comment-column: 40 // End: diff --git a/senf/Utils/TypeIdValue.hh b/senf/Utils/TypeIdValue.hh index 85eebf0..f1b8018 100644 --- a/senf/Utils/TypeIdValue.hh +++ b/senf/Utils/TypeIdValue.hh @@ -54,8 +54,7 @@ namespace senf { // no conversion constructors TypeIdValue(); - TypeIdValue(TypeIdValue const & other); - TypeIdValue const & operator=(TypeIdValue const & other); + TypeIdValue(std::type_info const & v); ///@} /////////////////////////////////////////////////////////////////////////// @@ -64,28 +63,14 @@ namespace senf { bool operator<(TypeIdValue const & other) const; std::string name() const; + std::string prettyName() const; + std::type_info const & id() const; protected: private: - template TypeIdValue(Type *); - - struct Value { - virtual ~Value(); - virtual std::type_info const & id() = 0; - virtual Value * clone() = 0; - }; - - template - struct ValueImpl : public Value { - virtual std::type_info const & id(); - virtual Value * clone(); - }; - - boost::scoped_ptr value_; - - template friend TypeIdValue const typeIdValue(); + std::type_info const * p_; }; TypeIdValue const typeIdValue(); @@ -93,6 +78,9 @@ namespace senf { template TypeIdValue const typeIdValue(); + template + TypeIdValue const typeidValue(Type const & ob); + std::ostream & operator<<(std::ostream & os, TypeIdValue const & v); } diff --git a/senf/Utils/TypeIdValue.test.cc b/senf/Utils/TypeIdValue.test.cc index 4652f53..7f9d816 100644 --- a/senf/Utils/TypeIdValue.test.cc +++ b/senf/Utils/TypeIdValue.test.cc @@ -39,7 +39,8 @@ BOOST_AUTO_UNIT_TEST(typeIdValue) { // We don't care for the ordering, just that the following compiles (void) ( senf::typeIdValue() < senf::typeIdValue() ); - (void) ( senf::typeIdValue() == senf::typeIdValue() ); + BOOST_CHECK ( senf::typeIdValue() != senf::typeIdValue() ); + BOOST_CHECK ( senf::typeIdValue() == senf::typeIdValue() ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/tools/find-sources.sh b/tools/find-sources.sh index ca5e9bb..33ea4b8 100755 --- a/tools/find-sources.sh +++ b/tools/find-sources.sh @@ -20,7 +20,7 @@ find . \ -name "*.o" -o \ -name "*.os" -o \ -name "*.so" -o \ - \( -type f -a ! -name "*.*" \) -o \ + \( -type f -a ! -name "*.*" -a -exec sh -c "file --brief {} | grep -q ELF" \; \) -o \ -name "*~" -o \ -name "#*#" -o \ -name "*.pyc" -o \