You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/01/15 17:19:44 UTC
arrow git commit: ARROW-486: [C++] Use virtual inheritance for
diamond inheritance
Repository: arrow
Updated Branches:
refs/heads/master 47115aa3e -> a098fd04f
ARROW-486: [C++] Use virtual inheritance for diamond inheritance
arrow::io::ReadWriteFileInterface inheritances arrow::io::FileInterface
as diamond style via:
* ReadableFileInterface -> InputStream -> FileInterface
* WriteableFileInterface -> OutputStream -> FileInterface
If we have diamond inheritance, we can't cast subclasses of
arrow::io::ReadWriteFileInterface such as arrow::io::MemoryMappedFile to
arrow::io::FileInterface.
C++:
#include <arrow/io/file.h>
int
main(void)
{
std::shared_ptr<arrow::io::MemoryMappedFile> memory_mapped_file;
std::shared_ptr<arrow::io::FileInterface> file = memory_mapped_file;
return 0;
}
Build result:
a.cc: In function 'int main()':
a.cc:8:52: error: conversion from 'std::shared_ptr<arrow::io::MemoryMappedFile>' to non-scalar type 'std::shared_ptr<arrow::io::FileInterface>' requested
std::shared_ptr<arrow::io::FileInterface> file = memory_mapped_file;
^~~~~~~~~~~~~~~~~~
We can resolve it by using virtual inheritance.
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #282 from kou/use-virtual-inheritance-for-diamond-inheritance and squashes the following commits:
e9d3a0b [Kouhei Sutou] ARROW-486: [C++] Use virtual inheritance for diamond inheritance
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/a098fd04
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/a098fd04
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/a098fd04
Branch: refs/heads/master
Commit: a098fd04fe229a9ce6f1f531c54c0c9a8eed56c4
Parents: 47115aa
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Sun Jan 15 12:19:37 2017 -0500
Committer: Wes McKinney <we...@twosigma.com>
Committed: Sun Jan 15 12:19:37 2017 -0500
----------------------------------------------------------------------
cpp/src/arrow/io/interfaces.h | 4 ++--
cpp/src/arrow/io/io-file-test.cc | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/a098fd04/cpp/src/arrow/io/interfaces.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/interfaces.h b/cpp/src/arrow/io/interfaces.h
index 8fe2849..fdb3788 100644
--- a/cpp/src/arrow/io/interfaces.h
+++ b/cpp/src/arrow/io/interfaces.h
@@ -83,12 +83,12 @@ class Readable {
virtual Status Read(int64_t nbytes, std::shared_ptr<Buffer>* out) = 0;
};
-class OutputStream : public FileInterface, public Writeable {
+class OutputStream : virtual public FileInterface, public Writeable {
protected:
OutputStream() {}
};
-class InputStream : public FileInterface, public Readable {
+class InputStream : virtual public FileInterface, public Readable {
protected:
InputStream() {}
};
http://git-wip-us.apache.org/repos/asf/arrow/blob/a098fd04/cpp/src/arrow/io/io-file-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/io-file-test.cc b/cpp/src/arrow/io/io-file-test.cc
index 20cd047..f18f7b6 100644
--- a/cpp/src/arrow/io/io-file-test.cc
+++ b/cpp/src/arrow/io/io-file-test.cc
@@ -419,5 +419,10 @@ TEST_F(TestMemoryMappedFile, InvalidFile) {
IOError, MemoryMappedFile::Open(non_existent_path, FileMode::READ, &result));
}
+TEST_F(TestMemoryMappedFile, CastableToFileInterface) {
+ std::shared_ptr<MemoryMappedFile> memory_mapped_file;
+ std::shared_ptr<FileInterface> file = memory_mapped_file;
+}
+
} // namespace io
} // namespace arrow