Skip to content

Commit

Permalink
Improved spans support in streams loadData & saveData (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadult authored Feb 24, 2024
1 parent d698799 commit a49a72e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/fwk/io/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ template <class Base> class TStream : public Base {
template <class TSpan, class T = SpanBase<TSpan>, EnableIf<!is_const<T> && is_flat_data<T>>...>
void loadData(TSpan &);

template <class T, EnableIf<is_flat_data<T>>...> void saveData(Span<const T>);
template <class T, EnableIf<!is_const<T> && is_flat_data<T>>...> void loadData(Span<T>);

// TODO: support for serializing vector< >, maybe < > of saveable ?
template <class T, EnableIf<is_flat_data<T>>...> TStream &operator<<(const T &);
template <class T, EnableIf<is_flat_data<T>>...> TStream &operator>>(T &);
Expand Down Expand Up @@ -175,6 +178,16 @@ void TSTREAM::loadData(TSpan &data) {
this->loadData(span(data).template reinterpret<char>());
}

TEMPLATE template <class T, EnableIf<is_flat_data<T>>...>
void TSTREAM::saveData(Span<const T> data) {
this->saveData(data.template reinterpret<char>());
}

TEMPLATE template <class T, EnableIf<!is_const<T> && is_flat_data<T>>...>
void TSTREAM::loadData(Span<T> data) {
this->loadData(data.template reinterpret<char>());
}

TEMPLATE template <class T, EnableIf<is_flat_data<T>>...>
TSTREAM &TSTREAM::operator<<(const T &obj) {
saveData(cspan(&obj, 1).template reinterpret<char>());
Expand Down

0 comments on commit a49a72e

Please sign in to comment.