Skip to content

Commit 0d3bbf6

Browse files
marcusmuellerwillcode
authored andcommitted
Runtime: add PMT fmt-formatting capabilities
This was long overdue; PMTs have to be logged routinely. Signed-off-by: Marcus Müller <[email protected]>
1 parent 385ffc7 commit 0d3bbf6

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

gnuradio-runtime/include/gnuradio/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ install(
4545
msg_handler.h
4646
msg_queue.h
4747
nco.h
48+
pmt_fmt.h
4849
pdu.h
4950
prefs.h
5051
pycallback_object.h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* -*- c++ -*- */
2+
/*
3+
* Copyright 2023 Marcus Müller
4+
*
5+
* This file is part of GNU Radio
6+
*
7+
* SPDX-License-Identifier: GPL-3.0-or-later
8+
*
9+
*/
10+
#ifndef INCLUDED_GNURADIO_PMT_FMT_H
11+
#define INCLUDED_GNURADIO_PMT_FMT_H
12+
#include <gnuradio/api.h>
13+
#include <pmt/pmt.h>
14+
#include <spdlog/fmt/fmt.h>
15+
#include <string_view>
16+
17+
//!\brief enables PMTs to be formatted with fmt
18+
template <>
19+
struct GR_RUNTIME_API fmt::formatter<pmt::pmt_t> : formatter<std::string_view> {
20+
fmt::format_context::iterator format(const pmt::pmt_t& obj,
21+
format_context& ctx) const;
22+
};
23+
#endif

gnuradio-runtime/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_library(
7171
msg_queue.cc
7272
pagesize.cc
7373
pdu.cc
74+
pmt_fmt.cc
7475
prefs.cc
7576
realtime.cc
7677
realtime_impl.cc

gnuradio-runtime/lib/pmt_fmt.cc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* -*- c++ -*- */
2+
/*
3+
* Copyright 2023 Marcus Müller
4+
*
5+
* This file is part of GNU Radio
6+
*
7+
* SPDX-License-Identifier: GPL-3.0-or-later
8+
*
9+
*/
10+
#include <gnuradio/pmt_fmt.h>
11+
#include <pmt/pmt.h>
12+
#include <spdlog/fmt/fmt.h>
13+
#include <string_view>
14+
15+
fmt::format_context::iterator
16+
fmt::formatter<pmt::pmt_t>::format(const pmt::pmt_t& obj, fmt::format_context& ctx) const
17+
{
18+
return fmt::format_to(ctx.out(), "{}", pmt::write_string(obj));
19+
}

0 commit comments

Comments
 (0)