summaryrefslogtreecommitdiffstats
path: root/src/msg/msg_fmt.h
blob: 41c4c6af89debbf4648c39097a21f0916c6a9cf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once

/**
 * \file fmtlib formatters for some msg_types.h classes
 */

#include <fmt/format.h>

#include "msg/msg_types.h"

template <>
struct fmt::formatter<entity_name_t> {
  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

  template <typename FormatContext>
  auto format(const entity_name_t& addr, FormatContext& ctx)
  {
    if (addr.is_new() || addr.num() < 0) {
      return fmt::format_to(ctx.out(), "{}.?", addr.type_str());
    }
    return fmt::format_to(ctx.out(), "{}.{}", addr.type_str(), addr.num());
  }
};