-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathproperty.cpp
More file actions
79 lines (64 loc) · 1.77 KB
/
Copy pathproperty.cpp
File metadata and controls
79 lines (64 loc) · 1.77 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#include "graphics/render_graph/property.h"
#include <array>
#include <cstddef>
#include <memory>
#include <string>
#include "core/error_handling.h"
namespace
{
/**
* Helper function to write value into buffer.
*
* @param buffer
* Where to write value to.
*
* @param value
* Value to write.
*/
template <class T>
void do_set_value(std::byte *buffer, const T &value)
{
// by convention the buffer always has a value - so destruct it first
std::destroy_at(reinterpret_cast<T *>(buffer));
// write the new value in via its copy constructor
std::construct_at(reinterpret_cast<T *>(buffer), value);
}
}
namespace iris
{
Property::Property(const std::string &name, std::byte *buffer, float value)
: name_(name)
, type_(PropertyType::FLOAT)
, buffer_(buffer)
{
expect(buffer_ != nullptr, "must supply buffer for value");
std::construct_at(reinterpret_cast<float *>(buffer_), value);
}
Property::~Property()
{
// ensure correct destructor is called
switch (type_)
{
using enum PropertyType;
case FLOAT: std::destroy_at(reinterpret_cast<float *>(buffer_)); break;
default: expect(false, "unknown property type");
}
}
std::string Property::name() const
{
return name_;
}
PropertyType Property::type() const
{
return type_;
}
void Property::set_value(float value)
{
do_set_value(buffer_, value);
}
}