arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1235: [C++] Make operator<< for Array/Status and std::ostream inline
Date Tue, 18 Jul 2017 17:51:19 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 8152433e7 -> a73252d0e


ARROW-1235: [C++] Make operator<< for Array/Status and std::ostream inline

I'm unable to reproduce the linker failure, but I think this will fix it.

Author: Wes McKinney <wes.mckinney@twosigma.com>
Author: Wes McKinney <wesmckinn@gmail.com>

Closes #864 from wesm/xcode-6.4-fixes and squashes the following commits:

43bb0b8c [Wes McKinney] Add tests for operator<< with Status and Array
f7524379 [Wes McKinney] Also make operator<<(std::ostream& for Array inline, add
Array::ToString
cf2b4719 [Wes McKinney] Make operator<< for Status inline


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/a73252d0
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/a73252d0
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/a73252d0

Branch: refs/heads/master
Commit: a73252d0e1e8e6e4ca9474571de657c38aedf9a3
Parents: 8152433
Author: Wes McKinney <wes.mckinney@twosigma.com>
Authored: Tue Jul 18 13:51:14 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Tue Jul 18 13:51:14 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/array.cc             | 7 ++++---
 cpp/src/arrow/array.h              | 8 +++++++-
 cpp/src/arrow/pretty_print-test.cc | 4 ++++
 cpp/src/arrow/status-test.cc       | 6 ++++++
 cpp/src/arrow/status.cc            | 5 -----
 cpp/src/arrow/status.h             | 5 ++++-
 6 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/array.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.cc b/cpp/src/arrow/array.cc
index f20b849..4a405f2 100644
--- a/cpp/src/arrow/array.cc
+++ b/cpp/src/arrow/array.cc
@@ -107,9 +107,10 @@ std::shared_ptr<Array> Array::Slice(int64_t offset) const {
   return Slice(offset, slice_length);
 }
 
-std::ostream& operator<<(std::ostream& os, const Array& x) {
-  DCHECK(PrettyPrint(x, 0, &os).ok());
-  return os;
+std::string Array::ToString() const {
+  std::stringstream ss;
+  DCHECK(PrettyPrint(*this, 0, &ss).ok());
+  return ss.str();
 }
 
 static inline std::shared_ptr<ArrayData> SliceData(

http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/array.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.h b/cpp/src/arrow/array.h
index 2da0b54..c32d5e1 100644
--- a/cpp/src/arrow/array.h
+++ b/cpp/src/arrow/array.h
@@ -236,6 +236,9 @@ class ARROW_EXPORT Array {
 
   int num_fields() const { return static_cast<int>(data_->child_data.size()); }
 
+  /// \return PrettyPrint representation of array suitable for debugging
+  std::string ToString() const;
+
  protected:
   Array() {}
 
@@ -256,7 +259,10 @@ class ARROW_EXPORT Array {
   DISALLOW_COPY_AND_ASSIGN(Array);
 };
 
-ARROW_EXPORT std::ostream& operator<<(std::ostream& os, const Array& x);
+static inline std::ostream& operator<<(std::ostream& os, const Array& x)
{
+  os << x.ToString();
+  return os;
+}
 
 class ARROW_EXPORT FlatArray : public Array {
  protected:

http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/pretty_print-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/pretty_print-test.cc b/cpp/src/arrow/pretty_print-test.cc
index 72bd0a8..10a91f5 100644
--- a/cpp/src/arrow/pretty_print-test.cc
+++ b/cpp/src/arrow/pretty_print-test.cc
@@ -49,6 +49,10 @@ void CheckArray(const Array& arr, int indent, const char* expected)
{
   ASSERT_OK(PrettyPrint(arr, indent, &sink));
   std::string result = sink.str();
   ASSERT_EQ(std::string(expected, strlen(expected)), result);
+
+  std::stringstream ss;
+  ss << arr;
+  ASSERT_EQ(result, ss.str());
 }
 
 template <typename TYPE, typename C_TYPE>

http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/status-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/status-test.cc b/cpp/src/arrow/status-test.cc
index 969ba97..f32eb15 100644
--- a/cpp/src/arrow/status-test.cc
+++ b/cpp/src/arrow/status-test.cc
@@ -15,6 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
+#include <sstream>
+
 #include "gtest/gtest.h"
 
 #include "arrow/status.h"
@@ -33,6 +35,10 @@ TEST(StatusTest, TestCodeAndMessage) {
 TEST(StatusTest, TestToString) {
   Status file_error = Status::IOError("file error");
   ASSERT_EQ("IOError: file error", file_error.ToString());
+
+  std::stringstream ss;
+  ss << file_error;
+  ASSERT_EQ(file_error.ToString(), ss.str());
 }
 
 }  // namespace arrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/status.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/status.cc b/cpp/src/arrow/status.cc
index 77ecb93..9989742 100644
--- a/cpp/src/arrow/status.cc
+++ b/cpp/src/arrow/status.cc
@@ -32,11 +32,6 @@ void Status::CopyFrom(const State* state) {
   }
 }
 
-std::ostream& operator<<(std::ostream& os, const Status& x) {
-  os << x.ToString();
-  return os;
-}
-
 std::string Status::CodeAsString() const {
   if (state_ == NULL) { return "OK"; }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/a73252d0/cpp/src/arrow/status.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h
index 8491ac8..1bea1fc 100644
--- a/cpp/src/arrow/status.h
+++ b/cpp/src/arrow/status.h
@@ -176,7 +176,10 @@ class ARROW_EXPORT Status {
   void CopyFrom(const State* s);
 };
 
-std::ostream& operator<<(std::ostream& os, const Status& x);
+static inline std::ostream& operator<<(std::ostream& os, const Status&
x) {
+  os << x.ToString();
+  return os;
+}
 
 inline Status::Status(const Status& s)
     : state_((s.state_ == NULL) ? NULL : new State(*s.state_)) {}


Mime
View raw message