MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ set_text()

bool MayaFlux::Kakshya::CompositeArray::set_text ( size_t  index,
std::string_view  field_name,
std::string_view  value 
)

Write UTF-8 bytes to a std::string field.

Parameters
indexElement index.
field_nameText field to write.
valueUTF-8 bytes to append to the text store.
Returns
True on success; false for an invalid index, name, type, or text storage size. Existing text views may be invalidated.

Definition at line 186 of file Composite.cpp.

187{
188 const auto declared = m_layout.find_field(field_name);
189 const std::type_index expected = declared
190 && m_layout.fields()[*declared].type == typeid(detail::CompositeDynamic)
191 ? typeid(detail::CompositeDynamic) : typeid(std::string);
192 const auto field_index = validate_write(index, field_name, expected);
193 if (!field_index)
194 return false;
195
196 const auto& field = m_layout.fields()[*field_index];
197 auto& text = std::get<std::vector<uint8_t>>(m_text);
198 if (value.size() > text.max_size() - text.size()) {
200 "CompositeArray: text value for field '{}' exceeds addressable size", field_name);
201 return false;
202 }
203
204 const std::string value_copy(value);
205 const TextSlice slice {
206 .offset = static_cast<uint64_t>(text.size()),
207 .length = static_cast<uint64_t>(value_copy.size())
208 };
209 text.insert(text.end(), value_copy.begin(), value_copy.end());
210
211 auto& rows = std::get<std::vector<uint8_t>>(m_rows);
212 auto* destination = rows.data() + index * m_layout.stride_bytes() + field.offset_bytes;
213 if (field.type == typeid(detail::CompositeDynamic)) {
214 const DynamicCell cell { text_kind, slice.offset, slice.length };
215 std::memcpy(destination, &cell, sizeof(cell));
216 } else {
217 std::memcpy(destination, &slice, sizeof(slice));
218 }
219
220 set_present(index, *field_index, true);
221 return true;
222}
#define MF_WARN(comp, ctx,...)
uint32_t rows
glm::vec3 value
uint32_t index
Definition VKDevice.cpp:122
void set_present(size_t index, size_t field_index, bool present) noexcept
std::optional< CompositeSlice > slice(size_t start, size_t count) const
Borrow consecutive elements without copying.
std::optional< size_t > validate_write(size_t index, std::string_view field_name, std::type_index type) const
size_t stride_bytes() const noexcept
Bytes per packed element after finalization.
Definition Composite.hpp:86
const std::vector< CompositeField > & fields() const noexcept
Declared fields in element order, with finalized byte offsets.
Definition Composite.hpp:82
std::optional< size_t > find_field(std::string_view name) const noexcept
Find a field index by name, or std::nullopt if absent.
Definition Composite.cpp:54
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References MayaFlux::Kakshya::CompositeLayout::fields(), MayaFlux::Kakshya::CompositeLayout::find_field(), index, MayaFlux::Journal::Kakshya, length, m_layout, m_rows, m_text, MF_WARN, rows, MayaFlux::Journal::Runtime, set_present(), slice(), MayaFlux::Kakshya::CompositeLayout::stride_bytes(), validate_write(), and value.

Referenced by MayaFlux::Kakshya::CompositeInsertion::append().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: