Add CSV logger
This commit is contained in:
committed by
Patrick Nicolas
parent
30f472bdb4
commit
2d400d9314
@@ -228,8 +228,6 @@ if (WIVRN_BUILD_WIVRNCTL)
|
||||
endif()
|
||||
|
||||
# Common dependencies
|
||||
FetchContent_Declare(boostpfr EXCLUDE_FROM_ALL SYSTEM URL https://github.com/boostorg/pfr/archive/refs/tags/2.2.0.tar.gz
|
||||
URL_HASH SHA256=6f490ec1383de5855dcf801c23f0a967f888eb6e1440b6ca0bf36c12d4ae7ac7)
|
||||
FetchContent_Declare(boost EXCLUDE_FROM_ALL SYSTEM URL https://github.com/boostorg/boost/releases/download/boost-1.89.0/boost-1.89.0-cmake.tar.xz
|
||||
URL_HASH SHA256=67acec02d0d118b5de9eb441f5fb707b3a1cdd884be00ca24b9a73c995511f74)
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
if (WIVRN_USE_SYSTEM_BOOST)
|
||||
add_library(Boost::pfr ALIAS Boost::headers)
|
||||
elseif (WIVRN_BUILD_CLIENT)
|
||||
else()
|
||||
set(BOOST_INCLUDE_LIBRARIES locale url pfr)
|
||||
FetchContent_MakeAvailable(boost)
|
||||
else()
|
||||
FetchContent_MakeAvailable(boostpfr)
|
||||
endif()
|
||||
|
||||
if (GIT_DESC)
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/pfr.hpp>
|
||||
#include <concepts>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#if __has_include(<boost/pfr/core_name.hpp>)
|
||||
#define BOOST_HAS_CORE_NAME
|
||||
#endif
|
||||
|
||||
namespace details
|
||||
{
|
||||
template <class>
|
||||
struct is_stdarray : public std::false_type
|
||||
{};
|
||||
|
||||
template <class T, size_t N>
|
||||
struct is_stdarray<std::array<T, N>> : public std::true_type
|
||||
{};
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool is_stdarray_v = is_stdarray<T>::value;
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct csv_logger_traits;
|
||||
|
||||
template <typename T>
|
||||
struct csv_logger_traits<T, std::enable_if_t<std::is_aggregate_v<T> && !is_stdarray_v<T>>>
|
||||
{
|
||||
#ifdef BOOST_HAS_CORE_NAME
|
||||
static void write_header(std::ostream & out, const std::string & name, bool first = true)
|
||||
{
|
||||
boost::pfr::for_each_field_with_name(T{}, [&](std::string_view member_name, const auto & value) {
|
||||
csv_logger_traits<std::remove_cvref_t<decltype(value)>>::write_header(out, name + "." + (std::string)member_name, first);
|
||||
first = false;
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
static void write_line(std::ostream & out, const T & value, bool first = true)
|
||||
{
|
||||
boost::pfr::for_each_field(value, [&](const auto & member) {
|
||||
csv_logger_traits<std::remove_cvref_t<decltype(member)>>::write_line(out, member, first);
|
||||
first = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct csv_logger_traits<T, std::enable_if_t<is_stdarray_v<T>>>
|
||||
{
|
||||
static void write_header(std::ostream & out, const std::string & name, bool first = true)
|
||||
{
|
||||
for (int i = 0; i < std::tuple_size_v<T>; i++)
|
||||
{
|
||||
csv_logger_traits<std::tuple_element_t<0, T>>::write_header(out, name + "[" + std::to_string(i) + "]", first and i == 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_line(std::ostream & out, const T & value, bool first = true)
|
||||
{
|
||||
for (int i = 0; i < std::tuple_size_v<T>; i++)
|
||||
{
|
||||
csv_logger_traits<std::tuple_element_t<0, T>>::write_line(out, value[i], first and i == 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct csv_logger_traits<T, std::enable_if_t<!std::is_aggregate_v<T>>>
|
||||
{
|
||||
static void write_header(std::ostream & out, std::string_view name, bool first = true)
|
||||
{
|
||||
if (not first)
|
||||
out << ",";
|
||||
out << name.substr(1);
|
||||
}
|
||||
|
||||
static void write_line(std::ostream & out, const T & value, bool first = true)
|
||||
{
|
||||
if (not first)
|
||||
out << ",";
|
||||
out << value;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
template <typename T, typename Stream = std::ofstream>
|
||||
requires std::derived_from<Stream, std::ostream>
|
||||
class csv_logger
|
||||
{
|
||||
Stream stream;
|
||||
|
||||
public:
|
||||
template <typename... Args>
|
||||
csv_logger(Args &&... args) : stream(std::forward<Args>(args)...)
|
||||
{
|
||||
#ifdef BOOST_HAS_CORE_NAME
|
||||
details::csv_logger_traits<T>::write_header(stream, "");
|
||||
stream << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void write(const T & data)
|
||||
{
|
||||
details::csv_logger_traits<T>::write_line(stream, data);
|
||||
stream << std::endl;
|
||||
}
|
||||
};
|
||||
@@ -396,9 +396,9 @@ modules:
|
||||
WIVRN_SRC2
|
||||
WIVRN_SRC3
|
||||
- type: archive
|
||||
url: BOOSTPFR_URL
|
||||
dest: deps/boostpfr-src
|
||||
sha256: BOOSTPFR_SHA256
|
||||
url: BOOST_URL
|
||||
dest: deps/boost-src
|
||||
sha256: BOOST_SHA256
|
||||
- type: git
|
||||
url: https://gitlab.freedesktop.org/monado/monado
|
||||
tag: MONADO_COMMIT
|
||||
@@ -406,4 +406,3 @@ modules:
|
||||
- type: shell
|
||||
commands:
|
||||
- cd deps/monado-src && ../../patches/apply.sh ../../patches/monado/*
|
||||
- cd deps/boostpfr-src && ../../patches/apply.sh ../../flatpak/boostpfr-gcc-12-internal-compiler-error.patch
|
||||
|
||||
@@ -59,8 +59,8 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
monado_commit = open(os.path.join(root, "monado-rev")).read()
|
||||
boostpfr_url = cmake.get("boostpfr", "URL")
|
||||
boostpfr_sha256 = cmake.get("boostpfr", "URL_HASH").split("=")[-1]
|
||||
boost_url = cmake.get("boost", "URL")
|
||||
boost_sha256 = cmake.get("boost", "URL_HASH").split("=")[-1]
|
||||
|
||||
try:
|
||||
git_commit = subprocess.check_output(
|
||||
@@ -93,8 +93,8 @@ if __name__ == "__main__":
|
||||
template = template.replace("WIVRN_GIT_DESC", git_desc)
|
||||
template = template.replace("WIVRN_GIT_COMMIT", git_commit)
|
||||
|
||||
template = template.replace("BOOSTPFR_URL", boostpfr_url)
|
||||
template = template.replace("BOOSTPFR_SHA256", boostpfr_sha256)
|
||||
template = template.replace("BOOST_URL", boost_url)
|
||||
template = template.replace("BOOST_SHA256", boost_sha256)
|
||||
template = template.replace("MONADO_COMMIT", monado_commit)
|
||||
|
||||
with open(os.path.join(args.out, "io.github.wivrn.wivrn.yml"), "w") as f:
|
||||
|
||||
Reference in New Issue
Block a user