This is an automated email from the ASF dual-hosted git repository.
weibin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new d8abc0e fix(c++): using C++17's nested namespaces (#489)
d8abc0e is described below
commit d8abc0ef523f6c31878b846991242156d5d55274
Author: teapot1de <[email protected]>
AuthorDate: Thu May 23 11:50:18 2024 +0800
fix(c++): using C++17's nested namespaces (#489)
Initial modifications to feat(c++): Use C++17's nested namespaces #473
completed, involving content of anonymous namespace and content in result.hpp
not changed yet
Reason for this PR
to slove the issue #473
What changes are included in this PR?
Most cpp folders need to use cpp17 nested loops
Are these changes tested?
No local tests
Are there any user-facing changes?
no
---
cpp/include/graphar/fwd.h | 7 +-
cpp/include/graphar/util/filesystem.h | 17 ++-
cpp/include/graphar/util/reader_util.h | 7 +-
cpp/include/graphar/util/result.h | 8 +-
cpp/include/graphar/util/status.h | 15 +--
cpp/include/graphar/util/util.h | 180 +++++++++++++-------------
cpp/include/graphar/writer/edges_builder.h | 6 +-
cpp/include/graphar/writer/vertices_builder.h | 6 +-
cpp/src/edges_builder.cc | 6 +-
cpp/src/filesystem.cc | 9 +-
cpp/src/reader_util.cc | 8 +-
cpp/src/util.cc | 7 +-
cpp/src/vertices_builder.cc | 6 +-
13 files changed, 131 insertions(+), 151 deletions(-)
diff --git a/cpp/include/graphar/fwd.h b/cpp/include/graphar/fwd.h
index 7936f5a..acc4ce0 100644
--- a/cpp/include/graphar/fwd.h
+++ b/cpp/include/graphar/fwd.h
@@ -201,12 +201,11 @@ const std::shared_ptr<DataType>& timestamp();
* @param value_type value type of the list
*/
std::shared_ptr<DataType> list(const std::shared_ptr<DataType>& value_type);
+} // namespace graphar
-namespace util {
+namespace graphar::util {
struct FilterOptions;
using Filter = std::shared_ptr<Expression>;
using ColumnNames =
std::optional<std::reference_wrapper<std::vector<std::string>>>;
-} // namespace util
-
-} // namespace graphar
+} // namespace graphar::util
diff --git a/cpp/include/graphar/util/filesystem.h
b/cpp/include/graphar/util/filesystem.h
index c929e72..712a90b 100644
--- a/cpp/include/graphar/util/filesystem.h
+++ b/cpp/include/graphar/util/filesystem.h
@@ -35,16 +35,19 @@
namespace arrow {
class Buffer;
class Table;
-namespace fs {
+} // namespace arrow
+
+namespace arrow::fs {
class FileSystem;
-}
-namespace io {
+} // namespace arrow::fs
+
+namespace arrow::io {
class RandomAccessFile;
-}
-namespace dataset {
+} // namespace arrow::io
+
+namespace arrow::dataset {
class FileFormat;
-}
-} // namespace arrow
+} // namespace arrow::dataset
namespace graphar {
diff --git a/cpp/include/graphar/util/reader_util.h
b/cpp/include/graphar/util/reader_util.h
index c71d643..e80cbfa 100644
--- a/cpp/include/graphar/util/reader_util.h
+++ b/cpp/include/graphar/util/reader_util.h
@@ -26,9 +26,7 @@
#include "graphar/fwd.h"
-namespace graphar {
-
-namespace util {
+namespace graphar::util {
struct FilterOptions {
// The row filter to apply to the table.
Filter filter = nullptr;
@@ -74,5 +72,4 @@ Result<IdType> GetEdgeNum(const std::string& prefix,
AdjListType adj_list_type,
IdType vertex_chunk_index) noexcept;
-} // namespace util
-} // namespace graphar
+} // namespace graphar::util
diff --git a/cpp/include/graphar/util/result.h
b/cpp/include/graphar/util/result.h
index 7db3601..535dd69 100644
--- a/cpp/include/graphar/util/result.h
+++ b/cpp/include/graphar/util/result.h
@@ -102,9 +102,7 @@
GAR_RETURN_ON_ARROW_ERROR_AND_ASSIGN_IMPL( \
GAR_ASSIGN_OR_RAISE_NAME(_error_or_value, __COUNTER__), lhs, rexpr);
-namespace graphar {
-
-namespace internal {
+namespace graphar::internal {
// Extract Status from Status or Result<T>
// Useful for the status check macros such as RETURN_NOT_OK.
@@ -117,6 +115,4 @@ inline Status GenericToStatus(Result<T>&& res) {
return std::move(res).status();
}
-} // namespace internal
-
-} // namespace graphar
+} // namespace graphar::internal
diff --git a/cpp/include/graphar/util/status.h
b/cpp/include/graphar/util/status.h
index 840db81..a338326 100644
--- a/cpp/include/graphar/util/status.h
+++ b/cpp/include/graphar/util/status.h
@@ -61,9 +61,7 @@
GAR_RAISE_ERROR_IF_(!__s.ok(), __s, GAR_STRINGIFY(status)); \
} while (false)
-namespace graphar {
-
-namespace util {
+namespace graphar::util {
template <typename Head>
void StringBuilderRecursive(std::ostringstream& stream, Head&& head) {
stream << head;
@@ -82,8 +80,9 @@ std::string StringBuilder(Args&&... args) {
StringBuilderRecursive(ss, std::forward<Args>(args)...);
return ss.str();
}
-} // namespace util
+} // namespace graphar::util
+namespace graphar {
/**
* An enum class representing the status codes for success or error outcomes.
*/
@@ -269,13 +268,13 @@ class Status {
State* state_;
};
-namespace internal {
+} // namespace graphar
+
+namespace graphar::internal {
// Extract Status from Status or Result<T>
// Useful for the status check macros such as RETURN_NOT_OK.
inline const Status& GenericToStatus(const Status& st) { return st; }
inline Status GenericToStatus(Status&& st) { return std::move(st); }
-} // namespace internal
-
-} // namespace graphar
+} // namespace graphar::internal
diff --git a/cpp/include/graphar/util/util.h b/cpp/include/graphar/util/util.h
index 0ff1f3d..703b2d3 100644
--- a/cpp/include/graphar/util/util.h
+++ b/cpp/include/graphar/util/util.h
@@ -38,96 +38,6 @@ class Array;
namespace graphar {
-namespace util {
-
-struct IndexConverter {
- explicit IndexConverter(std::vector<IdType>&& edge_chunk_nums)
- : edge_chunk_nums_(std::move(edge_chunk_nums)) {}
- IdType IndexPairToGlobalChunkIndex(IdType vertex_chunk_index,
- IdType edge_chunk_index) {
- IdType global_edge_chunk_index = 0;
- for (IdType i = 0; i < vertex_chunk_index; ++i) {
- global_edge_chunk_index += edge_chunk_nums_[i];
- }
- return global_edge_chunk_index + edge_chunk_index;
- }
-
- // covert edge global chunk index to <vertex_chunk_index, edge_chunk_index>
- std::pair<IdType, IdType> GlobalChunkIndexToIndexPair(IdType global_index) {
- std::pair<IdType, IdType> index_pair(0, 0);
- for (size_t i = 0; i < edge_chunk_nums_.size(); ++i) {
- if (global_index < edge_chunk_nums_[i]) {
- index_pair.first = static_cast<IdType>(i);
- index_pair.second = global_index;
- break;
- }
- global_index -= edge_chunk_nums_[i];
- }
- return index_pair;
- }
-
- private:
- std::vector<IdType> edge_chunk_nums_;
-};
-
-static inline IdType IndexPairToGlobalChunkIndex(
- const std::vector<IdType>& edge_chunk_nums, IdType vertex_chunk_index,
- IdType edge_chunk_index) {
- IdType global_edge_chunk_index = 0;
- for (IdType i = 0; i < vertex_chunk_index; ++i) {
- global_edge_chunk_index += edge_chunk_nums[i];
- }
- return global_edge_chunk_index + edge_chunk_index;
-}
-
-// covert edge global chunk index to <vertex_chunk_index, edge_chunk_index>
-static inline std::pair<IdType, IdType> GlobalChunkIndexToIndexPair(
- const std::vector<IdType>& edge_chunk_nums, IdType global_index) {
- std::pair<IdType, IdType> index_pair(0, 0);
- for (size_t i = 0; i < edge_chunk_nums.size(); ++i) {
- if (global_index < edge_chunk_nums[i]) {
- index_pair.first = static_cast<IdType>(i);
- index_pair.second = global_index;
- break;
- }
- global_index -= edge_chunk_nums[i];
- }
- return index_pair;
-}
-
-std::shared_ptr<arrow::ChunkedArray> GetArrowColumnByName(
- std::shared_ptr<arrow::Table> const& table, const std::string& name);
-
-std::shared_ptr<arrow::Array> GetArrowArrayByChunkIndex(
- std::shared_ptr<arrow::ChunkedArray> const& chunk_array,
- int64_t chunk_index);
-
-Result<const void*> GetArrowArrayData(
- std::shared_ptr<arrow::Array> const& array);
-
-static inline std::string ConcatStringWithDelimiter(
- const std::vector<std::string>& str_vec, const std::string& delimiter) {
- return std::accumulate(
- std::begin(str_vec), std::end(str_vec), std::string(),
- [&delimiter](const std::string& ss, const std::string& s) {
- return ss.empty() ? s : ss + delimiter + s;
- });
-}
-
-template <typename T>
-struct ValueGetter {
- inline static T Value(const void* data, int64_t offset) {
- return reinterpret_cast<const T*>(data)[offset];
- }
-};
-
-template <>
-struct ValueGetter<std::string> {
- static std::string Value(const void* data, int64_t offset);
-};
-
-} // namespace util
-
template <typename T>
class Array final {
public:
@@ -251,3 +161,93 @@ using DoubleArray = Array<double>;
using StringArray = Array<std::string_view>;
} // namespace graphar
+
+namespace graphar::util {
+
+struct IndexConverter {
+ explicit IndexConverter(std::vector<IdType>&& edge_chunk_nums)
+ : edge_chunk_nums_(std::move(edge_chunk_nums)) {}
+ IdType IndexPairToGlobalChunkIndex(IdType vertex_chunk_index,
+ IdType edge_chunk_index) {
+ IdType global_edge_chunk_index = 0;
+ for (IdType i = 0; i < vertex_chunk_index; ++i) {
+ global_edge_chunk_index += edge_chunk_nums_[i];
+ }
+ return global_edge_chunk_index + edge_chunk_index;
+ }
+
+ // covert edge global chunk index to <vertex_chunk_index, edge_chunk_index>
+ std::pair<IdType, IdType> GlobalChunkIndexToIndexPair(IdType global_index) {
+ std::pair<IdType, IdType> index_pair(0, 0);
+ for (size_t i = 0; i < edge_chunk_nums_.size(); ++i) {
+ if (global_index < edge_chunk_nums_[i]) {
+ index_pair.first = static_cast<IdType>(i);
+ index_pair.second = global_index;
+ break;
+ }
+ global_index -= edge_chunk_nums_[i];
+ }
+ return index_pair;
+ }
+
+ private:
+ std::vector<IdType> edge_chunk_nums_;
+};
+
+static inline IdType IndexPairToGlobalChunkIndex(
+ const std::vector<IdType>& edge_chunk_nums, IdType vertex_chunk_index,
+ IdType edge_chunk_index) {
+ IdType global_edge_chunk_index = 0;
+ for (IdType i = 0; i < vertex_chunk_index; ++i) {
+ global_edge_chunk_index += edge_chunk_nums[i];
+ }
+ return global_edge_chunk_index + edge_chunk_index;
+}
+
+// covert edge global chunk index to <vertex_chunk_index, edge_chunk_index>
+static inline std::pair<IdType, IdType> GlobalChunkIndexToIndexPair(
+ const std::vector<IdType>& edge_chunk_nums, IdType global_index) {
+ std::pair<IdType, IdType> index_pair(0, 0);
+ for (size_t i = 0; i < edge_chunk_nums.size(); ++i) {
+ if (global_index < edge_chunk_nums[i]) {
+ index_pair.first = static_cast<IdType>(i);
+ index_pair.second = global_index;
+ break;
+ }
+ global_index -= edge_chunk_nums[i];
+ }
+ return index_pair;
+}
+
+std::shared_ptr<arrow::ChunkedArray> GetArrowColumnByName(
+ std::shared_ptr<arrow::Table> const& table, const std::string& name);
+
+std::shared_ptr<arrow::Array> GetArrowArrayByChunkIndex(
+ std::shared_ptr<arrow::ChunkedArray> const& chunk_array,
+ int64_t chunk_index);
+
+Result<const void*> GetArrowArrayData(
+ std::shared_ptr<arrow::Array> const& array);
+
+static inline std::string ConcatStringWithDelimiter(
+ const std::vector<std::string>& str_vec, const std::string& delimiter) {
+ return std::accumulate(
+ std::begin(str_vec), std::end(str_vec), std::string(),
+ [&delimiter](const std::string& ss, const std::string& s) {
+ return ss.empty() ? s : ss + delimiter + s;
+ });
+}
+
+template <typename T>
+struct ValueGetter {
+ inline static T Value(const void* data, int64_t offset) {
+ return reinterpret_cast<const T*>(data)[offset];
+ }
+};
+
+template <>
+struct ValueGetter<std::string> {
+ static std::string Value(const void* data, int64_t offset);
+};
+
+} // namespace graphar::util
diff --git a/cpp/include/graphar/writer/edges_builder.h
b/cpp/include/graphar/writer/edges_builder.h
index ce17c34..1394029 100644
--- a/cpp/include/graphar/writer/edges_builder.h
+++ b/cpp/include/graphar/writer/edges_builder.h
@@ -36,8 +36,7 @@ namespace arrow {
class Array;
}
-namespace graphar {
-namespace builder {
+namespace graphar::builder {
/**
* @brief Edge is designed for constructing edges builder.
@@ -426,5 +425,4 @@ class EdgesBuilder {
ValidateLevel validate_level_;
};
-} // namespace builder
-} // namespace graphar
+} // namespace graphar::builder
diff --git a/cpp/include/graphar/writer/vertices_builder.h
b/cpp/include/graphar/writer/vertices_builder.h
index 8ca1336..2bb2b37 100644
--- a/cpp/include/graphar/writer/vertices_builder.h
+++ b/cpp/include/graphar/writer/vertices_builder.h
@@ -36,8 +36,7 @@ class Array;
class Table;
} // namespace arrow
-namespace graphar {
-namespace builder {
+namespace graphar::builder {
/**
* @brief Vertex is designed for constructing vertices builder.
@@ -347,5 +346,4 @@ class VerticesBuilder {
ValidateLevel validate_level_;
};
-} // namespace builder
-} // namespace graphar
+} // namespace graphar::builder
diff --git a/cpp/src/edges_builder.cc b/cpp/src/edges_builder.cc
index 06b2074..a64e526 100644
--- a/cpp/src/edges_builder.cc
+++ b/cpp/src/edges_builder.cc
@@ -24,8 +24,7 @@
#include "graphar/util/result.h"
#include "graphar/writer/edges_builder.h"
-namespace graphar {
-namespace builder {
+namespace graphar::builder {
Status EdgesBuilder::Dump() {
// construct the writer
@@ -349,5 +348,4 @@ Result<std::shared_ptr<arrow::Table>>
EdgesBuilder::getOffsetTable(
return arrow::Table::Make(schema, arrays);
}
-} // namespace builder
-} // namespace graphar
+} // namespace graphar::builder
diff --git a/cpp/src/filesystem.cc b/cpp/src/filesystem.cc
index 7e75e66..bc78108 100644
--- a/cpp/src/filesystem.cc
+++ b/cpp/src/filesystem.cc
@@ -31,9 +31,7 @@
#include "graphar/util/expression.h"
#include "graphar/util/filesystem.h"
-namespace graphar {
-namespace ds = arrow::dataset;
-namespace detail {
+namespace graphar::detail {
template <typename U, typename T>
static Status CastToLargeOffsetArray(
const std::shared_ptr<arrow::Array>& in,
@@ -79,7 +77,10 @@ static Status CastToLargeOffsetArray(
GAR_RETURN_ON_ARROW_ERROR_AND_ASSIGN(out, arrow::ChunkedArray::Make(chunks));
return Status::OK();
}
-} // namespace detail
+} // namespace graphar::detail
+
+namespace graphar {
+namespace ds = arrow::dataset;
std::shared_ptr<ds::FileFormat> FileSystem::GetFileFormat(
const FileType type) const {
diff --git a/cpp/src/reader_util.cc b/cpp/src/reader_util.cc
index 43cc859..3ca51c1 100644
--- a/cpp/src/reader_util.cc
+++ b/cpp/src/reader_util.cc
@@ -30,9 +30,7 @@
#include "graphar/util/filesystem.h"
#include "graphar/util/reader_util.h"
-namespace graphar {
-
-namespace util {
+namespace graphar::util {
/**
* @brief Checks whether the property names in the FilterOptions match the
@@ -206,6 +204,4 @@ Result<IdType> GetEdgeNum(const std::string& prefix,
return edge_num;
}
-} // namespace util
-
-} // namespace graphar
+} // namespace graphar::util
diff --git a/cpp/src/util.cc b/cpp/src/util.cc
index 0f7ad9c..740669b 100644
--- a/cpp/src/util.cc
+++ b/cpp/src/util.cc
@@ -24,9 +24,7 @@
#include "graphar/util/util.h"
-namespace graphar {
-
-namespace util {
+namespace graphar::util {
std::shared_ptr<arrow::ChunkedArray> GetArrowColumnByName(
std::shared_ptr<arrow::Table> const& table, const std::string& name) {
@@ -99,5 +97,4 @@ std::string ValueGetter<std::string>::Value(const void* data,
int64_t offset) {
reinterpret_cast<const arrow::LargeStringArray*>(data)->GetView(offset));
}
-} // namespace util
-} // namespace graphar
+} // namespace graphar::util
diff --git a/cpp/src/vertices_builder.cc b/cpp/src/vertices_builder.cc
index 5d7371b..4e4e7c4 100644
--- a/cpp/src/vertices_builder.cc
+++ b/cpp/src/vertices_builder.cc
@@ -21,8 +21,7 @@
#include "graphar/graph_info.h"
#include "graphar/util/convert_to_arrow_type.h"
-namespace graphar {
-namespace builder {
+namespace graphar::builder {
Status VerticesBuilder::validate(const Vertex& v, IdType index,
ValidateLevel validate_level) const {
@@ -232,5 +231,4 @@ Result<std::shared_ptr<arrow::Table>>
VerticesBuilder::convertToTable() {
return arrow::Table::Make(schema, arrays);
}
-} // namespace builder
-} // namespace graphar
+} // namespace graphar::builder
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]