From 288b448b9f9a5a80052f3bf43e534e51c74adf63 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 10:16:16 +0200 Subject: [PATCH] Brought across Region operator<< from Cubiquity branch. --- library/PolyVoxCore/include/PolyVoxCore/Region.h | 4 ++++ library/PolyVoxCore/source/Region.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 655b3bce..4fe45a7e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -202,6 +202,10 @@ namespace PolyVox int32_t m_iUpperZ; }; + // Non-member overloaded operators. + /// Stream insertion operator. + std::ostream& operator<<(std::ostream& os, const Region& region); + // Functions to be inlined to to be in the header rather than the .cpp. // 'inline' keyword is used for the definition rather than the declaration. // See also http://www.parashift.com/c++-faq-lite/inline-functions.html diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 444a1770..2f61f63a 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -487,4 +487,17 @@ namespace PolyVox { shrink(v3dAmount.getX(), v3dAmount.getY(), v3dAmount.getZ()); } -} + + /** + * Enables the Region to be used intuitively with output streams such as cout. + * \param os The output stream to write to. + * \param region The Region to write to the stream. + * \return A reference to the output stream to allow chaining. + */ + std::ostream& operator<<(std::ostream& os, const Region& region) + { + os << "(" << region.getLowerX() << "," << region.getLowerY() << "," << region.getLowerZ() << + ") to (" << region.getUpperX() << "," << region.getUpperY() << "," << region.getUpperZ() << ")"; + return os; + } +} \ No newline at end of file