Skip to content

Commit

Permalink
gh-80: rename archive to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Sep 13, 2024
1 parent d033e35 commit 4d0d071
Show file tree
Hide file tree
Showing 39 changed files with 566 additions and 566 deletions.
8 changes: 4 additions & 4 deletions engine/runtime/asset/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ namespace wmoge {
WG_YAML_WRITE(context, node, id.m_name);
return WG_OK;
}
Status archive_read(IoContext& context, Archive& archive, AssetId& id) {
WG_ARCHIVE_READ(context, archive, id.m_name);
Status stream_read(IoContext& context, IoStream& stream, AssetId& id) {
WG_ARCHIVE_READ(context, stream, id.m_name);
return WG_OK;
}
Status archive_write(IoContext& context, Archive& archive, const AssetId& id) {
WG_ARCHIVE_WRITE(context, archive, id.m_name);
Status stream_write(IoContext& context, IoStream& stream, const AssetId& id) {
WG_ARCHIVE_WRITE(context, stream, id.m_name);
return WG_OK;
}

Expand Down
4 changes: 2 additions & 2 deletions engine/runtime/asset/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ namespace wmoge {

friend Status yaml_read(IoContext& context, YamlConstNodeRef node, AssetId& id);
friend Status yaml_write(IoContext& context, YamlNodeRef node, const AssetId& id);
friend Status archive_read(IoContext& context, Archive& archive, AssetId& id);
friend Status archive_write(IoContext& context, Archive& archive, const AssetId& id);
friend Status stream_read(IoContext& context, IoStream& stream, AssetId& id);
friend Status stream_write(IoContext& context, IoStream& stream, const AssetId& id);

private:
Strid m_name;
Expand Down
18 changes: 9 additions & 9 deletions engine/runtime/asset/asset_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "asset/asset.hpp"
#include "asset/asset_manager.hpp"
#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"

#include <cassert>
Expand Down Expand Up @@ -88,9 +88,9 @@ namespace wmoge {
}

template<typename T>
Status archive_read(IoContext& context, Archive& archive, AssetRef<T>& ref) {
Status stream_read(IoContext& context, IoStream& stream, AssetRef<T>& ref) {
AssetId id;
WG_ARCHIVE_READ(context, archive, id);
WG_ARCHIVE_READ(context, stream, id);
Ref<T> ptr = context.get_asset_manager()->load(id).cast<T>();
if (!ptr) {
return StatusCode::NoAsset;
Expand All @@ -100,12 +100,12 @@ namespace wmoge {
}

template<typename T>
Status archive_write(IoContext& context, Archive& archive, const AssetRef<T>& ref) {
Status stream_write(IoContext& context, IoStream& stream, const AssetRef<T>& ref) {
assert(ref);
if (!ref) {
return StatusCode::NoAsset;
}
WG_ARCHIVE_WRITE(context, archive, ref->get_id());
WG_ARCHIVE_WRITE(context, stream, ref->get_id());
return WG_OK;
}

Expand All @@ -125,17 +125,17 @@ namespace wmoge {
}

template<typename T>
Status archive_read(IoContext& context, Archive& archive, AssetRefWeak<T>& ref) {
Status stream_read(IoContext& context, IoStream& stream, AssetRefWeak<T>& ref) {
AssetId id;
WG_ARCHIVE_READ(context, archive, id);
WG_ARCHIVE_READ(context, stream, id);
ref = AssetRefWeak<T>(id);
return WG_OK;
}

template<typename T>
Status archive_write(IoContext& context, Archive& archive, const AssetRefWeak<T>& ref) {
Status stream_write(IoContext& context, IoStream& stream, const AssetRefWeak<T>& ref) {
AssetId id = ref;
WG_ARCHIVE_WRITE(context, archive, id);
WG_ARCHIVE_WRITE(context, stream, id);
return WG_OK;
}

Expand Down
14 changes: 7 additions & 7 deletions engine/runtime/core/buffered_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#pragma once

#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"

#include <svector.hpp>
Expand All @@ -46,22 +46,22 @@ namespace wmoge {
using buffered_vector = ankerl::svector<T, MinCapacity>;

template<typename T, std::size_t MinCapacity>
Status archive_write(IoContext& context, Archive& archive, const buffered_vector<T, MinCapacity>& vector) {
WG_ARCHIVE_WRITE(context, archive, vector.size());
Status stream_write(IoContext& context, IoStream& stream, const buffered_vector<T, MinCapacity>& vector) {
WG_ARCHIVE_WRITE(context, stream, vector.size());
for (const auto& entry : vector) {
WG_ARCHIVE_WRITE(context, archive, entry);
WG_ARCHIVE_WRITE(context, stream, entry);
}
return WG_OK;
}

template<typename T, std::size_t MinCapacity>
Status archive_read(IoContext& context, Archive& archive, buffered_vector<T, MinCapacity>& vector) {
Status stream_read(IoContext& context, IoStream& stream, buffered_vector<T, MinCapacity>& vector) {
assert(vector.empty());
std::size_t size;
WG_ARCHIVE_READ(context, archive, size);
WG_ARCHIVE_READ(context, stream, size);
vector.resize(size);
for (int i = 0; i < size; i++) {
WG_ARCHIVE_READ(context, archive, vector[i]);
WG_ARCHIVE_READ(context, stream, vector[i]);
}
return WG_OK;
}
Expand Down
12 changes: 6 additions & 6 deletions engine/runtime/core/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ namespace wmoge {
return builder.get();
}

Status archive_write(IoContext& context, Archive& archive, const Ref<Data>& data) {
Status stream_write(IoContext& context, IoStream& stream, const Ref<Data>& data) {
assert(data);
WG_ARCHIVE_WRITE(context, archive, data->m_size);
return archive.nwrite(static_cast<int>(data->m_size), data->m_buffer);
WG_ARCHIVE_WRITE(context, stream, data->m_size);
return stream.nwrite(static_cast<int>(data->m_size), data->m_buffer);
}
Status archive_read(IoContext& context, Archive& archive, Ref<Data>& data) {
Status stream_read(IoContext& context, IoStream& stream, Ref<Data>& data) {
std::size_t size;
WG_ARCHIVE_READ(context, archive, size);
WG_ARCHIVE_READ(context, stream, size);
data = make_ref<Data>(size);
return archive.nread(static_cast<int>(size), data->buffer());
return stream.nread(static_cast<int>(size), data->buffer());
}

Status yaml_write(IoContext& context, YamlNodeRef node, const Ref<Data>& data) {
Expand Down
6 changes: 3 additions & 3 deletions engine/runtime/core/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "core/ref.hpp"
#include "core/sha256.hpp"
#include "core/string_utils.hpp"
#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"
#include "math/math_utils.hpp"

Expand Down Expand Up @@ -73,8 +73,8 @@ namespace wmoge {
[[nodiscard]] Crc32 to_crc32() const;
[[nodiscard]] Sha256 to_sha256() const;

friend Status archive_write(IoContext& context, Archive& archive, const Ref<Data>& data);
friend Status archive_read(IoContext& context, Archive& archive, Ref<Data>& data);
friend Status stream_write(IoContext& context, IoStream& stream, const Ref<Data>& data);
friend Status stream_read(IoContext& context, IoStream& stream, Ref<Data>& data);

friend Status yaml_write(IoContext& context, YamlNodeRef node, const Ref<Data>& data);
friend Status yaml_read(IoContext& context, YamlConstNodeRef node, Ref<Data>& data);
Expand Down
8 changes: 4 additions & 4 deletions engine/runtime/core/date_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ namespace wmoge {
WG_YAML_WRITE(context, node, s);
return WG_OK;
}
Status archive_read(IoContext& context, Archive& archive, DateTime& value) {
return archive.nread(sizeof(value.m_value), &value.m_value);
Status stream_read(IoContext& context, IoStream& stream, DateTime& value) {
return stream.nread(sizeof(value.m_value), &value.m_value);
}
Status archive_write(IoContext& context, Archive& archive, const DateTime& value) {
return archive.nwrite(sizeof(value.m_value), &value.m_value);
Status stream_write(IoContext& context, IoStream& stream, const DateTime& value) {
return stream.nwrite(sizeof(value.m_value), &value.m_value);
}

}// namespace wmoge
4 changes: 2 additions & 2 deletions engine/runtime/core/date_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ namespace wmoge {

friend Status yaml_read(IoContext& context, YamlConstNodeRef node, DateTime& value);
friend Status yaml_write(IoContext& context, YamlNodeRef node, const DateTime& value);
friend Status archive_read(IoContext& context, Archive& archive, DateTime& value);
friend Status archive_write(IoContext& context, Archive& archive, const DateTime& value);
friend Status stream_read(IoContext& context, IoStream& stream, DateTime& value);
friend Status stream_write(IoContext& context, IoStream& stream, const DateTime& value);

private:
TimePoint m_value{};
Expand Down
18 changes: 9 additions & 9 deletions engine/runtime/core/flat_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#pragma once

#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"

#include <robin_hood.hpp>
Expand All @@ -46,24 +46,24 @@ namespace wmoge {
using flat_map = robin_hood::unordered_flat_map<K, V>;

template<typename K, typename V>
Status archive_write(IoContext& context, Archive& archive, const flat_map<K, V>& map) {
WG_ARCHIVE_WRITE(context, archive, map.size());
Status stream_write(IoContext& context, IoStream& stream, const flat_map<K, V>& map) {
WG_ARCHIVE_WRITE(context, stream, map.size());
for (const auto& entry : map) {
WG_ARCHIVE_WRITE(context, archive, entry.first);
WG_ARCHIVE_WRITE(context, archive, entry.second);
WG_ARCHIVE_WRITE(context, stream, entry.first);
WG_ARCHIVE_WRITE(context, stream, entry.second);
}
return WG_OK;
}

template<typename K, typename V>
Status archive_read(IoContext& context, Archive& archive, flat_map<K, V>& map) {
Status stream_read(IoContext& context, IoStream& stream, flat_map<K, V>& map) {
assert(map.empty());
std::size_t size;
WG_ARCHIVE_READ(context, archive, size);
WG_ARCHIVE_READ(context, stream, size);
for (int i = 0; i < size; i++) {
robin_hood::pair<K, V> entry;
WG_ARCHIVE_READ(context, archive, entry.first);
WG_ARCHIVE_READ(context, archive, entry.second);
WG_ARCHIVE_READ(context, stream, entry.first);
WG_ARCHIVE_READ(context, stream, entry.second);
map.insert(std::move(entry));
}
return WG_OK;
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/core/flat_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#pragma once

#include "io/archive.hpp"
#include "io/stream.hpp"

#include <robin_hood.hpp>
#include <unordered_set>
Expand Down
10 changes: 5 additions & 5 deletions engine/runtime/core/mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#pragma once

#include "core/buffered_vector.hpp"
#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"

#include <bitset>
Expand Down Expand Up @@ -131,13 +131,13 @@ namespace wmoge {
}

template<typename T, int size>
Status archive_read(IoContext& context, Archive& archive, Mask<T, size>& mask) {
return archive.nread(sizeof(Mask<T, size>), &mask);
Status stream_read(IoContext& context, IoStream& stream, Mask<T, size>& mask) {
return stream.nread(sizeof(Mask<T, size>), &mask);
}

template<typename T, int size>
Status archive_write(IoContext& context, Archive& archive, const Mask<T, size>& mask) {
return archive.nwrite(sizeof(Mask<T, size>), &mask);
Status stream_write(IoContext& context, IoStream& stream, const Mask<T, size>& mask) {
return stream.nwrite(sizeof(Mask<T, size>), &mask);
}

}// namespace wmoge
14 changes: 7 additions & 7 deletions engine/runtime/core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ namespace wmoge {
return object->write_to_yaml(node);
}

Status archive_read_object(IoContext& context, Archive& archive, Ref<Object>& object) {
Status archive_read_object(IoContext& context, IoStream& stream, Ref<Object>& object) {
assert(!object);

Strid class_name;
WG_ARCHIVE_READ(context, archive, class_name);
WG_ARCHIVE_READ(context, stream, class_name);

auto* cls = Class::class_ptr(class_name);

if (!cls) {
WG_LOG_ERROR("no such class to read from archive " << class_name);
WG_LOG_ERROR("no such class to read from stream " << class_name);
return StatusCode::NoClass;
}

Expand All @@ -172,12 +172,12 @@ namespace wmoge {
return StatusCode::FailedInstantiate;
}

return object->read_from_archive(archive);
return object->read_from_stream(stream);
}
Status archive_write_object(IoContext& context, Archive& archive, const Ref<Object>& object) {
Status archive_write_object(IoContext& context, IoStream& stream, const Ref<Object>& object) {
assert(object);
WG_ARCHIVE_WRITE(context, archive, object->class_name());
return object->write_to_archive(archive);
WG_ARCHIVE_WRITE(context, stream, object->class_name());
return object->write_to_stream(stream);
}

}// namespace wmoge
18 changes: 9 additions & 9 deletions engine/runtime/core/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "core/status.hpp"
#include "core/string_id.hpp"
#include "core/var.hpp"
#include "io/archive.hpp"
#include "io/stream.hpp"
#include "io/yaml.hpp"

#include <cassert>
Expand Down Expand Up @@ -71,8 +71,8 @@ namespace wmoge {
virtual Status copy_to(Object& other) const { return WG_OK; }
virtual Status read_from_yaml(const YamlConstNodeRef& node) { return StatusCode::NotImplemented; }
virtual Status write_to_yaml(YamlNodeRef node) const { return StatusCode::NotImplemented; }
virtual Status read_from_archive(Archive& archive) { return StatusCode::NotImplemented; }
virtual Status write_to_archive(Archive& archive) const { return StatusCode::NotImplemented; }
virtual Status read_from_stream(IoStream& stream) { return StatusCode::NotImplemented; }
virtual Status write_to_stream(IoStream& stream) const { return StatusCode::NotImplemented; }
virtual Status clone(Ref<Object>& object) const;

virtual Ref<Object> duplicate() const;
Expand All @@ -88,8 +88,8 @@ namespace wmoge {
friend Status yaml_read_object(IoContext& context, YamlConstNodeRef node, Ref<Object>& object);
friend Status yaml_write_object(IoContext& context, YamlNodeRef node, const Ref<Object>& object);

friend Status archive_read_object(IoContext& context, Archive& archive, Ref<Object>& object);
friend Status archive_write_object(IoContext& context, Archive& archive, const Ref<Object>& object);
friend Status archive_read_object(IoContext& context, IoStream& stream, Ref<Object>& object);
friend Status archive_write_object(IoContext& context, IoStream& stream, const Ref<Object>& object);
};

template<typename T>
Expand Down Expand Up @@ -145,18 +145,18 @@ namespace wmoge {
}

template<typename T>
Status archive_read(IoContext& context, Archive& archive, Ref<T>& ref, typename std::enable_if_t<std::is_convertible_v<T*, Object*>>* = 0) {
Status stream_read(IoContext& context, IoStream& stream, Ref<T>& ref, typename std::enable_if_t<std::is_convertible_v<T*, Object*>>* = 0) {
Ref<Object> object;
auto status = archive_read_object(context, archive, object);
auto status = archive_read_object(context, stream, object);
if (!status) return status;
ref = object.template cast<T>();
return WG_OK;
}

template<typename T>
Status archive_write(IoContext& context, Archive& archive, const Ref<T>& ref, typename std::enable_if_t<std::is_convertible_v<T*, Object*>>* = 0) {
Status stream_write(IoContext& context, IoStream& stream, const Ref<T>& ref, typename std::enable_if_t<std::is_convertible_v<T*, Object*>>* = 0) {
Ref<Object> object = ref.template as<Object>();
auto status = archive_write_object(context, archive, object);
auto status = archive_write_object(context, stream, object);
if (!status) return status;
return WG_OK;
}
Expand Down
8 changes: 4 additions & 4 deletions engine/runtime/core/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ namespace wmoge {
Status yaml_write(IoContext& context, YamlNodeRef node, const Sha256& sha) {
return yaml_write(context, node, sha.to_string());
}
Status archive_read(IoContext& context, Archive& archive, Sha256& sha) {
return archive.nread(sizeof(sha), &sha);
Status stream_read(IoContext& context, IoStream& stream, Sha256& sha) {
return stream.nread(sizeof(sha), &sha);
}
Status archive_write(IoContext& context, Archive& archive, const Sha256& sha) {
return archive.nwrite(sizeof(sha), &sha);
Status stream_write(IoContext& context, IoStream& stream, const Sha256& sha) {
return stream.nwrite(sizeof(sha), &sha);
}

static constexpr std::array<uint32_t, 64> K = {
Expand Down
Loading

0 comments on commit 4d0d071

Please sign in to comment.