mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
* added file asset loader * tests for asset loader * made asset loader rcp * addressed pr comments feat(CommandQueue) Added request Ids associated with jobs (#9796) 5aedcdc61f * added request ids that are associated with callbacks for the command queue * modified tests to check for request id feat: TextInput - refactor shapes for runtime text input (#9836) 455374455c * chore: updating runtime defs * chore: refactor TextStyle into TextStylePaint * chore: missed hpp files * chore: missed cpp files * chore: fix clone of text_style_paint * feat: more text input at runtime * chore: cleanup * chore: add typed child iterator * chore: missed files * chore: running runtime input in editor * feat: completing integration with editor * chore: missed file * chore: fix builds with text disabled * chore: use child for test * tests: adding more tests for text input * chore: missed test file * chore: more coverage for child iterator * chore: using clipping on text input * chore: test text input selected text * chore: dry up iterator Co-authored-by: Jonathon Copeland <jcopela4@gmail.com> Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
85 lines
2.0 KiB
C++
85 lines
2.0 KiB
C++
/*
|
|
* Copyright 2025 Rive
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "rive/refcnt.hpp"
|
|
|
|
#include <cassert>
|
|
#include <deque>
|
|
|
|
namespace rive
|
|
{
|
|
// Stream for recording objects of a specific type, using C++-style "<<" ">>"
|
|
// operators.
|
|
template <typename T> class ObjectStream
|
|
{
|
|
public:
|
|
bool empty() const { return m_stream.empty(); }
|
|
|
|
ObjectStream& operator<<(T obj)
|
|
{
|
|
m_stream.push_back(std::move(obj));
|
|
return *this;
|
|
}
|
|
|
|
ObjectStream& operator>>(T& dst)
|
|
{
|
|
assert(!empty());
|
|
dst = std::move(m_stream.front());
|
|
m_stream.pop_front();
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
std::deque<T> m_stream;
|
|
};
|
|
|
|
// Stream for recording objects of any trivially-copyable type, using C++-style
|
|
// "<<" ">>" operators. Object types must be read back in the same order they
|
|
// were writen.
|
|
class PODStream
|
|
{
|
|
public:
|
|
bool empty() const { return m_byteStream.empty(); }
|
|
|
|
template <typename T> PODStream& operator<<(T obj)
|
|
{
|
|
static_assert(std::is_pod<T>(),
|
|
"PODStream only accepts plain-old-data types");
|
|
const char* data = reinterpret_cast<const char*>(&obj);
|
|
m_byteStream.insert(m_byteStream.end(), data, data + sizeof(T));
|
|
return *this;
|
|
}
|
|
|
|
template <typename T> PODStream& operator>>(T& dst)
|
|
{
|
|
static_assert(std::is_pod<T>(),
|
|
"PODStream only accepts plain-old-data types");
|
|
assert(m_byteStream.size() >= sizeof(T));
|
|
char* data = reinterpret_cast<char*>(&dst);
|
|
std::copy(m_byteStream.begin(), m_byteStream.begin() + sizeof(T), data);
|
|
m_byteStream.erase(m_byteStream.begin(),
|
|
m_byteStream.begin() + sizeof(T));
|
|
return *this;
|
|
}
|
|
|
|
template <typename T> PODStream& operator<<(rcp<T> obj)
|
|
{
|
|
return *this << obj.release();
|
|
}
|
|
|
|
template <typename T> PODStream& operator>>(rcp<T>& obj)
|
|
{
|
|
T* raw;
|
|
*this >> raw;
|
|
obj = rcp<T>(raw);
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
std::deque<char> m_byteStream;
|
|
};
|
|
}; // namespace rive
|