Skip to content

Commit

Permalink
Move CSV data parsing to IO component
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Aug 1, 2022
1 parent 150bb26 commit a925186
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ configure_file("${PROJECT_SOURCE_DIR}/cppcheck.suppress.in"
${PROJECT_BINARY_DIR}/cppcheck.suppress)

gz_configure_build(QUIT_IF_BUILD_ERRORS
COMPONENTS av events geospatial graphics profiler testing)
COMPONENTS av events geospatial graphics io profiler testing)

#============================================================================
# Create package information
Expand Down
76 changes: 76 additions & 0 deletions io/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
load(
"//gz_bazel:build_defs.bzl",
"GZ_ROOT",
"GZ_VISIBILITY",
"generate_include_header",
"gz_export_header",
)

package(
default_visibility = GZ_VISIBILITY,
features = [
"-parse_headers",
"-layering_check",
],
)

public_headers_no_gen = glob([
"include/gz/common/*.hh",
])

sources = glob(
["src/*.cc"],
exclude = ["src/*_TEST.cc"],
)

test_sources = glob(["src/*_TEST.cc"])

gz_export_header(
name = "include/gz/common/io/Export.hh",
export_base = "GZ_COMMON_IO",
lib_name = "gz-common-io",
visibility = ["//visibility:private"],
)

generate_include_header(
name = "iohh_genrule",
out = "include/gz/common/io.hh",
hdrs = public_headers_no_gen + [
"include/gz/common/io/Export.hh",
],
)

public_headers = public_headers_no_gen + [
"include/gz/common/io/Export.hh",
"include/gz/common/io.hh",
]

cc_library(
name = "io",
srcs = sources,
hdrs = public_headers,
includes = ["include"],
deps = [
GZ_ROOT + "gz_common",
GZ_ROOT + "gz_math",
],
)

cc_binary(
name = "libgz-common5-io.so",
includes = ["include"],
linkopts = ["-Wl,-soname,libgz-common5-io.so"],
linkshared = True,
deps = [":events"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
deps = [
":io",
GZ_ROOT + "gz_common/test:test_utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]
1 change: 1 addition & 0 deletions io/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(gz)
1 change: 1 addition & 0 deletions io/include/gz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(common)
1 change: 1 addition & 0 deletions io/include/gz/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gz_install_all_headers(COMPONENT io)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <string>
#include <vector>

#include <gz/common/Export.hh>
#include <gz/common/io/Export.hh>

#include <gz/utils/ImplPtr.hh>

Expand Down Expand Up @@ -49,8 +49,8 @@ namespace gz
/// \param[in] _lhs Left-hand side CSV dialect.
/// \param[in] _rhs Right-hand side CSV dialect.
/// \return true if CSV dialects are equal, false otherwise.
bool GZ_COMMON_VISIBLE operator==(const CSVDialect &_lhs,
const CSVDialect &_rhs);
bool GZ_COMMON_IO_VISIBLE operator==(const CSVDialect &_lhs,
const CSVDialect &_rhs);

/// \brief A token in CSV data.
///
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace gz
/// \return same CSV data stream.
std::istream &ExtractCSVToken(
std::istream &_stream, CSVToken &_token,
const CSVDialect &_dialect = CSVDialect::Unix) GZ_COMMON_VISIBLE;
const CSVDialect &_dialect = CSVDialect::Unix) GZ_COMMON_IO_VISIBLE;

/// \brief Parse a single row from an input stream of CSV data.
///
Expand All @@ -91,13 +91,13 @@ namespace gz
/// \returns same CSV data stream.
std::istream &ParseCSVRow(
std::istream &_stream, std::vector<std::string> &_row,
const CSVDialect &_dialect = CSVDialect::Unix) GZ_COMMON_VISIBLE;
const CSVDialect &_dialect = CSVDialect::Unix) GZ_COMMON_IO_VISIBLE;

/// \brief A single-pass row iterator on an input stream of CSV data.
///
/// Similar to std::istream_iterator, this iterator parses a stream of
/// CSV data, one row at a time. \see `ParseCSVRow`
class GZ_COMMON_VISIBLE CSVIStreamIterator
/// CSV data, one row at a time. \see `ParseCSVRow`.
class GZ_COMMON_IO_VISIBLE CSVIStreamIterator
{
public: using iterator_category = std::input_iterator_tag;
public: using value_type = std::vector<std::string>;
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions io/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
gz_get_libsources_and_unittests(sources gtest_sources)

gz_add_component(io SOURCES ${sources} GET_TARGET_NAME io_target)

target_link_libraries(${io_target}
PUBLIC
gz-math${GZ_MATH_VER}::gz-math${GZ_MATH_VER})

gz_build_tests(
TYPE UNIT
SOURCES ${gtest_sources}
LIB_DEPS
${io_target}
gz-common${GZ_COMMON_VER}-testing
)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a925186

Please sign in to comment.