co_ecs 0.9.0
Cobalt ECS
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <co_ecs/entity.hpp>
5
6#include <sstream>
7#include <stdexcept>
8#include <string>
9
10namespace co_ecs {
11
13class entity_not_found : public std::exception {
14public:
18 explicit entity_not_found(entity ent) {
19 std::stringstream ss;
20 ss << "entity (" << ent.id() << ", " << ent.generation() << ")" << " does not exist";
21 _msg = ss.str();
22 }
23
27 [[nodiscard]] auto what() const noexcept -> const char* override {
28 return _msg.c_str();
29 }
30
31private:
32 std::string _msg;
33};
34
36class component_not_found : public std::exception {
37public:
41 explicit component_not_found(const type_meta* meta) {
42 std::stringstream ss;
43 ss << "component \"" << meta->name << "\" not found";
44 _msg = ss.str();
45 }
46
50 [[nodiscard]] auto what() const noexcept -> const char* override {
51 return _msg.c_str();
52 }
53
54private:
55 std::string _msg;
56};
57
59class insufficient_chunk_size : public std::exception {
60public:
65 explicit insufficient_chunk_size(std::size_t requested_size, std::size_t chunk_size) {
66 std::stringstream ss;
67 ss << "Total size of components " << requested_size << " bytes exceeds chunk block size of " << chunk_size
68 << " bytes";
69 _msg = ss.str();
70 }
71
75 [[nodiscard]] auto what() const noexcept -> const char* override {
76 return _msg.c_str();
77 }
78
79private:
80 std::string _msg;
81};
82
83} // namespace co_ecs
Exception raised when accessing entities component which was not assigned.
Definition exceptions.hpp:36
auto what() const noexcept -> const char *override
Message to the client.
Definition exceptions.hpp:50
component_not_found(const type_meta *meta)
Construct a new component not found exception object.
Definition exceptions.hpp:41
Exception raised when accessing non existing entity.
Definition exceptions.hpp:13
auto what() const noexcept -> const char *override
Message to the client.
Definition exceptions.hpp:27
entity_not_found(entity ent)
Construct a new entity not found exception object.
Definition exceptions.hpp:18
Insufficient chunk size error.
Definition exceptions.hpp:59
insufficient_chunk_size(std::size_t requested_size, std::size_t chunk_size)
Construct a new component not found exception object.
Definition exceptions.hpp:65
auto what() const noexcept -> const char *override
Message to the client.
Definition exceptions.hpp:75
Definition archetype.hpp:11
detail::handle< struct entity_tag_t > entity
Represents an entity, consisting of an ID and generation.
Definition entity.hpp:13
Type meta information.
Definition type_meta.hpp:29
std::string_view name
Definition type_meta.hpp:93