Unit.hpp
1 #pragma once
2 #include <score/serialization/DataStreamFwd.hpp>
3 #include <score/serialization/VisitorInterface.hpp>
4 
5 #include <QLatin1String>
6 
7 #include <score_lib_state_export.h>
8 
9 #include <memory>
10 #include <verdigris>
11 namespace ossia
12 {
13 struct unit_t;
14 }
15 namespace State
16 {
17 struct SCORE_LIB_STATE_EXPORT Unit
18 {
19  // W_GADGET(Unit)
20 public:
21  Unit() noexcept;
22  Unit(const Unit& other) noexcept;
23  Unit(Unit&& other) noexcept;
24  Unit& operator=(const Unit& other) noexcept;
25  Unit& operator=(Unit&& other) noexcept;
26  ~Unit();
27 
28  Unit(const ossia::unit_t&) noexcept;
29  Unit& operator=(const ossia::unit_t&) noexcept;
30 
31  operator const ossia::unit_t&() const noexcept;
32  operator ossia::unit_t&() noexcept;
33 
34  bool operator==(const State::Unit& other) const noexcept;
35  bool operator!=(const State::Unit& other) const noexcept;
36 
37  const ossia::unit_t& get() const noexcept;
38  ossia::unit_t& get() noexcept;
39 
40 private:
41  std::unique_ptr<ossia::unit_t> unit;
42 };
43 
44 SCORE_LIB_STATE_EXPORT
45 QLatin1String prettyUnitText(const ossia::unit_t&);
46 }
47 
48 template <>
49 struct SCORE_LIB_STATE_EXPORT TSerializer<DataStream, ossia::unit_t>
50 {
51  static void readFrom(DataStreamReader& s, const ossia::unit_t& var);
52  static void writeTo(DataStreamWriter& s, ossia::unit_t& var);
53 };
54 
55 template <>
56 struct SCORE_LIB_STATE_EXPORT TSerializer<DataStream, State::Unit>
57 {
58  static void readFrom(DataStreamReader& s, const State::Unit& var);
59  static void writeTo(DataStreamWriter& s, State::Unit& var);
60 };
61 
62 template <>
63 struct is_custom_serialized<ossia::unit_t> : public std::true_type
64 {
65 };
66 
67 SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::Unit)
68 Q_DECLARE_METATYPE(State::Unit)
69 W_REGISTER_ARGTYPE(State::Unit)
Definition: VisitorInterface.hpp:53
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: Unit.hpp:18
Definition: VisitorInterface.hpp:13