aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-18 08:41:19 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-18 08:41:19 +0000
commit1ac2d4a08a6d1f2686dfebd853f6b8f69f0e3999 (patch)
tree96eaa595a270994e6e1f4b1141edd98020e346d8
parent281f2f4c33dd7edf4709220fbf7f7d7e96516310 (diff)
downloadpaludis-1ac2d4a08a6d1f2686dfebd853f6b8f69f0e3999.tar.gz
paludis-1ac2d4a08a6d1f2686dfebd853f6b8f69f0e3999.tar.xz
Make stringify(ContentsEntry) work for subclassed entries even if we don't know the subclass at compile time.
-rw-r--r--paludis/contents-fwd.hh7
-rw-r--r--paludis/contents.cc18
-rw-r--r--paludis/contents.hh10
3 files changed, 22 insertions, 13 deletions
diff --git a/paludis/contents-fwd.hh b/paludis/contents-fwd.hh
index 606c23a..5983a33 100644
--- a/paludis/contents-fwd.hh
+++ b/paludis/contents-fwd.hh
@@ -44,13 +44,6 @@ namespace paludis
struct ContentsVisitorTypes;
/**
- * Write a ContentsSymEntry to a stream.
- *
- * \ingroup g_contents
- */
- std::ostream & operator<< (std::ostream &, const ContentsSymEntry &) PALUDIS_VISIBLE;
-
- /**
* Write a ContentsEntry to a stream.
*
* \ingroup g_contents
diff --git a/paludis/contents.cc b/paludis/contents.cc
index 6eed36f..966033a 100644
--- a/paludis/contents.cc
+++ b/paludis/contents.cc
@@ -133,15 +133,21 @@ Contents::end() const
}
std::ostream &
-paludis::operator<< (std::ostream & s, const ContentsSymEntry & e)
+paludis::operator<< (std::ostream & s, const ContentsEntry & e)
{
- s << e.name() << " -> " << e.target();
+ s << e.as_string();
return s;
}
-std::ostream &
-paludis::operator<< (std::ostream & s, const ContentsEntry & e)
+const std::string
+ContentsEntry::as_string() const
{
- s << e.name();
- return s;
+ return name();
}
+
+const std::string
+ContentsSymEntry::as_string() const
+{
+ return name() + " -> " + target();
+}
+
diff --git a/paludis/contents.hh b/paludis/contents.hh
index 1213546..aa2b040 100644
--- a/paludis/contents.hh
+++ b/paludis/contents.hh
@@ -71,6 +71,8 @@ namespace paludis
private InstantiationPolicy<ContentsEntry, instantiation_method::NonCopyableTag>,
public virtual ConstAcceptInterface<ContentsVisitorTypes>
{
+ friend std::ostream & operator<< (std::ostream &, const ContentsEntry &);
+
private:
std::string _name;
@@ -80,6 +82,11 @@ namespace paludis
ContentsEntry(const std::string & our_name);
+ /**
+ * Used to implement the ostream operator<<.
+ */
+ virtual const std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
///\}
public:
@@ -202,6 +209,9 @@ namespace paludis
private:
std::string _target;
+ protected:
+ virtual const std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
public:
///\name Basic operations
///\{