This is an automated email from the ASF dual-hosted git repository.
xiaokang 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 eced8833 fix(C++): fix all enumerations to use strongly-typed enums
(enum class) (#869)
eced8833 is described below
commit eced8833dec08bc234731f042e672308e484f367
Author: Jason <[email protected]>
AuthorDate: Tue Feb 24 10:34:40 2026 +0800
fix(C++): fix all enumerations to use strongly-typed enums (enum class)
(#869)
---
cpp/src/graphar/filesystem.cc | 8 ++++----
cpp/src/graphar/fwd.h | 8 ++++----
cpp/src/graphar/label.h | 5 +++--
cpp/src/graphar/status.h | 8 +++++++-
4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/cpp/src/graphar/filesystem.cc b/cpp/src/graphar/filesystem.cc
index b56a9ff6..93684ceb 100644
--- a/cpp/src/graphar/filesystem.cc
+++ b/cpp/src/graphar/filesystem.cc
@@ -96,14 +96,14 @@ namespace ds = arrow::dataset;
std::shared_ptr<ds::FileFormat> FileSystem::GetFileFormat(
const FileType type) const {
switch (type) {
- case CSV:
+ case FileType::CSV:
return std::make_shared<ds::CsvFileFormat>();
- case PARQUET:
+ case FileType::PARQUET:
return std::make_shared<ds::ParquetFileFormat>();
- case JSON:
+ case FileType::JSON:
return std::make_shared<ds::JsonFileFormat>();
#ifdef ARROW_ORC
- case ORC:
+ case FileType::ORC:
return std::make_shared<ds::OrcFileFormat>();
#endif
default:
diff --git a/cpp/src/graphar/fwd.h b/cpp/src/graphar/fwd.h
index 4da33c79..52ef0ec6 100644
--- a/cpp/src/graphar/fwd.h
+++ b/cpp/src/graphar/fwd.h
@@ -72,12 +72,12 @@ class FileSystem;
using IdType = int64_t;
class DataType;
/** Defines how multiple values are handled for a given property key */
-enum Cardinality : int32_t { SINGLE, LIST, SET };
+enum class Cardinality : int32_t { SINGLE, LIST, SET };
/** Type of file format */
-enum FileType : int32_t { CSV = 0, PARQUET = 1, ORC = 2, JSON = 3 };
-enum SelectType : int32_t { PROPERTIES = 0, LABELS = 1 };
+enum class FileType : int32_t { CSV = 0, PARQUET = 1, ORC = 2, JSON = 3 };
+enum class SelectType : int32_t { PROPERTIES = 0, LABELS = 1 };
/** GetChunkVersion: V1 use scanner, V2 use FileReader */
-enum GetChunkVersion : int32_t { AUTO = 0, V1 = 1, V2 = 2 };
+enum class GetChunkVersion : int32_t { AUTO = 0, V1 = 1, V2 = 2 };
enum class AdjListType : int32_t;
template <typename T>
diff --git a/cpp/src/graphar/label.h b/cpp/src/graphar/label.h
index 145312e4..ec69e626 100644
--- a/cpp/src/graphar/label.h
+++ b/cpp/src/graphar/label.h
@@ -40,7 +40,7 @@ using parquet::schema::PrimitiveNode;
constexpr int BATCH_SIZE = 1024; // the batch size
/// The query type
-enum QUERY_TYPE {
+enum class QUERY_TYPE {
COUNT, // return the number of valid vertices
INDEX, // return the indices of valid vertices
BITMAP, // return the bitmap of valid vertices
@@ -57,6 +57,7 @@ int read_parquet_file_and_get_valid_indices(
const int tested_label_num, std::vector<int> tested_label_ids,
const std::function<bool(bool*, int)>& IsValid, int chunk_idx,
int chunk_size, std::vector<int>* indices = nullptr,
- uint64_t* bitmap = nullptr, const QUERY_TYPE query_type = COUNT);
+ uint64_t* bitmap = nullptr,
+ const QUERY_TYPE query_type = QUERY_TYPE::COUNT);
#endif // CPP_SRC_GRAPHAR_LABEL_H_
diff --git a/cpp/src/graphar/status.h b/cpp/src/graphar/status.h
index 62e709ba..941ef22f 100644
--- a/cpp/src/graphar/status.h
+++ b/cpp/src/graphar/status.h
@@ -21,6 +21,7 @@
#include <sstream>
#include <string>
+#include <type_traits>
#include <utility>
#include "graphar/macros.h"
@@ -64,7 +65,12 @@
namespace graphar::util {
template <typename Head>
void StringBuilderRecursive(std::ostringstream& stream, Head&& head) {
- stream << head;
+ using Decayed = std::decay_t<Head>;
+ if constexpr (std::is_enum_v<Decayed>) {
+ stream << static_cast<std::underlying_type_t<Decayed>>(head);
+ } else {
+ stream << std::forward<Head>(head);
+ }
}
template <typename Head, typename... Tail>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]