lintel 0.2.0
Loading...
Searching...
No Matches
PropertyChange.h
Go to the documentation of this file.
1#ifndef LINTEL_PROPERTYCHANGE_H
2#define LINTEL_PROPERTYCHANGE_H
3
4#include <cstddef>
5#include <cstdint>
6#include <cstring>
7#include <string>
8#include <type_traits>
9
12
13namespace lintel {
27{
29 static constexpr std::size_t PART_SIZE = 32;
31 static constexpr std::size_t VALUE_SIZE = Event::CONTENT_SIZE - 4 * PART_SIZE - 1;
33 static constexpr std::size_t MAX_VALUE_LENGTH = VALUE_SIZE - 1;
34
38 char name[PART_SIZE]{};
41 bool m_valueTruncated = false;
42
47 {
49 copyInto(change.processName, property.getProcessName());
50 copyInto(change.className, property.getClassName());
51 copyInto(change.instanceName, property.getInstanceName());
52 copyInto(change.name, property.getName());
53 const std::string value = property.toString();
54 change.m_valueTruncated = value.size() >= VALUE_SIZE;
55 copyInto(change.value, value);
56 return change;
57 }
58
60 [[nodiscard]] std::string identifier() const
61 {
62 return std::string(name) + "_" + instanceName + "_" + className + "_" + processName;
63 }
64
65private:
66 static constexpr void copyInto(char (&destination)[PART_SIZE], std::string_view value)
67 {
68 const std::size_t length = value.size() >= PART_SIZE ? PART_SIZE - 1 : value.size();
69 std::memcpy(destination, value.data(), length);
70 destination[length] = '\0';
71 }
72
73 static constexpr void copyInto(char (&destination)[VALUE_SIZE], std::string_view value)
74 {
75 const std::size_t length = value.size() >= VALUE_SIZE ? VALUE_SIZE - 1 : value.size();
76 std::memcpy(destination, value.data(), length);
77 destination[length] = '\0';
78 }
79};
80
81static_assert(std::is_trivially_copyable_v<PropertyChange>,
82 "PropertyChange must be trivially copyable for the lock-free "
83 "queues");
84static_assert(sizeof(PropertyChange) == Event::CONTENT_SIZE, "PropertyChange must exactly fit into the Event payload");
85
86}// namespace lintel
87#endif// LINTEL_PROPERTYCHANGE_H
static constexpr std::size_t CONTENT_SIZE
Definition Event.h:27
Definition PropertyBase.h:13
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9
Definition PropertyChange.h:27
std::string identifier() const
Definition PropertyChange.h:60
static constexpr std::size_t VALUE_SIZE
Definition PropertyChange.h:31
static constexpr std::size_t MAX_VALUE_LENGTH
Definition PropertyChange.h:33
bool m_valueTruncated
Definition PropertyChange.h:41
static PropertyChange of(PropertyBase &property)
Definition PropertyChange.h:46
char value[VALUE_SIZE]
Definition PropertyChange.h:39
char instanceName[PART_SIZE]
Definition PropertyChange.h:37
static constexpr std::size_t PART_SIZE
Definition PropertyChange.h:29
char className[PART_SIZE]
Definition PropertyChange.h:36
char processName[PART_SIZE]
Definition PropertyChange.h:35
char name[PART_SIZE]
Definition PropertyChange.h:38