OSSIA
Open Scenario System for Interactive Application
debug.hpp
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 #if defined(OSSIA_HAS_FMT)
4 #include <ossia/detail/fmt.hpp>
5 #include <ossia/detail/optional.hpp>
6 #include <ossia/network/base/node.hpp>
7 #include <ossia/network/base/parameter.hpp>
8 #include <ossia/network/common/parameter_properties.hpp>
10 #include <ossia/network/domain/domain.hpp>
11 #include <ossia/network/value/format_value.hpp>
12 
20 namespace fmt
21 {
22 template <>
23 struct formatter<ossia::access_mode>
24 {
25  template <typename ParseContext>
26  constexpr auto parse(ParseContext& ctx)
27  {
28  return ctx.begin();
29  }
30 
31  template <typename FormatContext>
32  auto format(ossia::access_mode e, FormatContext& ctx)
33  {
34  string_view name = "unknown";
35  switch(e)
36  {
37  case ossia::access_mode::BI:
38  name = "BI";
39  break;
41  name = "GET";
42  break;
44  name = "SET";
45  break;
46  }
47  return formatter<string_view>{}.format(name, ctx);
48  }
49 };
50 
51 template <>
52 struct formatter<ossia::bounding_mode> final : formatter<string_view>
53 {
54  template <typename ParseContext>
55  constexpr auto parse(ParseContext& ctx)
56  {
57  return ctx.begin();
58  }
59 
60  template <typename FormatContext>
61  auto format(ossia::bounding_mode e, FormatContext& ctx)
62  {
63  string_view name = "unknown";
64  switch(e)
65  {
66  case ossia::bounding_mode::FREE:
67  name = "FREE";
68  break;
70  name = "CLIP";
71  break;
73  name = "WRAP";
74  break;
76  name = "FOLD";
77  break;
79  name = "LOW";
80  break;
82  name = "HIGH";
83  break;
84  }
85  return formatter<string_view>::format(name, ctx);
86  }
87 };
88 
89 template <>
90 struct formatter<ossia::domain> final : formatter<string_view>
91 {
92  template <typename ParseContext>
93  constexpr auto parse(ParseContext& ctx)
94  {
95  return ctx.begin();
96  }
97 
98  template <typename FormatContext>
99  auto format(const ossia::domain& e, FormatContext& ctx)
100  {
101  return formatter<string_view>::format(e.to_pretty_string(), ctx);
102  }
103 };
104 
105 template <>
106 struct formatter<ossia::net::node_base>
107 {
108  template <typename ParseContext>
109  constexpr auto parse(ParseContext& ctx)
110  {
111  return ctx.begin();
112  }
113 
114  template <typename FormatContext>
115  auto format(const ossia::net::node_base& n, FormatContext& ctx)
116  {
117  int num_indent = 0;
118  auto parent = n.get_parent();
119  while(parent != nullptr)
120  {
121  num_indent++;
122  parent = parent->get_parent();
123  }
124 
125  if(auto p = n.get_parameter())
126  {
127  return fmt::format_to(
128  ctx.out(),
129  "{:<{}} : {}, AccessMode({}), BoundingMode({}), Domain({}), "
130  "Unit({})",
131  n.get_name(), num_indent, p->value(), p->get_access(), p->get_bounding(),
132  p->get_domain(), ossia::get_pretty_unit_text(p->get_unit()));
133  }
134  else
135  {
136  return fmt::format_to(ctx.out(), "{}{}", num_indent, n.get_name());
137  }
138  }
139 };
140 }
141 
142 #endif
143 
144 namespace ossia
145 {
146 struct domain;
147 namespace net
148 {
149 class node_base;
150 
151 OSSIA_EXPORT
152 void debug_recursively(std::string& str, const ossia::net::node_base&);
153 }
154 }
The node_base class.
Definition: network/base/node.hpp:48
virtual node_base * get_parent() const =0
Parent of this node. May be null if it is the device (i.e. root).
const std::string & get_name() const
The name of this node, e.g. "foo".
Definition: network/base/node.hpp:70
access_mode
Defines Write (Set), Read (Get) or Read/Write (Bi) access to the parameter's value.
Definition: ossia-cpp98.hpp:66
bounding_mode
Behaviour at the bounds of the value.
Definition: ossia-cpp98.hpp:75
Definition: git_info.h:7
bounding_mode
Address behaviors at crossing domain boundaries.
Definition: parameter_properties.hpp:56
@ CLIP
The bounds are ignored.
std::string_view get_pretty_unit_text(const unit_t &u)
get_pretty_unit_text Unit for human readability and debugging
Definition: dataspace_visitors.cpp:43
access_mode
Address behaviors at crossing domain boundaries time.
Definition: parameter_properties.hpp:46
@ GET
The value can be retrieved and changed.
@ SET
The value can be retrieved.
domain A domain of values
Definition: domain_base.hpp:23