-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataspace.hpp
More file actions
144 lines (119 loc) · 5.09 KB
/
Dataspace.hpp
File metadata and controls
144 lines (119 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// AmigaOS MUI C++ wrapper
//
// (c) 2022-2026 TDolphin
//
#pragma once
#include "Semaphore.hpp"
#include "AOS/IFFParse/ValueTypes/IFFError.hpp"
struct IFFHandle;
namespace MUI
{
/// @brief MUI Dataspace class wrapper.
/// Simple container for arbitrary data items referenced by IDs, with IFF import/export support.
class Dataspace : public Semaphore
{
public:
explicit Dataspace(Object *pMuiObject)
: Semaphore(pMuiObject)
{
}
Dataspace(const Root &root)
: Semaphore(root.muiObject())
{
}
// instanceOf
const static std::string className;
static inline bool instanceOf(Object *pMuiObject)
{
return MUI::instanceOf(pMuiObject, className.c_str());
}
static inline bool instanceOf(const Root &object)
{
return MUI::instanceOf(object.muiObject(), className.c_str());
}
// is/get/set (attributes), all setters return object reference
#ifdef MUIA_Dataspace_Count
/// @brief [ @b MUIA_Dataspace_Count ] Determine the number of entries in the Dataspace object.
/// @return Number of entries stored in the dataspace.
unsigned long getCount() const;
#endif
// methods, some returns object reference
#ifdef MUIM_Dataspace_Add
/// @brief [ @b MUIM_Dataspace_Add ] Adds or replaces an entry identified by ID.
/// @param data Pointer to entry data.
/// @param len Data length in bytes. Negative values are treated as NUL-terminated string length.
/// @param id Entry reference ID.
/// @return true on success, false on failure.
bool Add(const void *data, const long len, const unsigned long id);
#endif
#ifdef MUIM_Dataspace_Clear
/// @brief [ @b MUIM_Dataspace_Clear ] Clears all entries from the dataspace.
Dataspace &Clear();
#endif
#ifdef MUIM_Dataspace_Find
/// @brief [ @b MUIM_Dataspace_Find ] Looks up entry data by ID.
/// @param id Entry reference ID.
/// @return Pointer to stored entry data or nullptr if not found.
const void *Find(const unsigned long id) const;
#endif
#ifdef MUIM_Dataspace_Get
/// @brief [ @b MUIM_Dataspace_Get ] Looks up entry data by ID and optionally returns its size.
/// @param id Entry reference ID.
/// @param size Optional pointer receiving entry size in bytes.
/// @return Pointer to stored entry data or nullptr if not found.
const void *Get(const unsigned long id, unsigned long *size = nullptr) const;
#endif
#ifdef MUIM_Dataspace_Merge
/// @brief [ @b MUIM_Dataspace_Merge ] Merges all entries from another dataspace, replacing equal IDs.
/// @param dataspace Source dataspace object to merge from.
/// @return Number of entries added or replaced.
unsigned long Merge(const Object *dataspace);
/// @brief [ @b MUIM_Dataspace_Merge ] Merges all entries from another dataspace, replacing equal IDs.
/// @param dataspace Source dataspace wrapper to merge from.
/// @return Number of entries added or replaced.
unsigned long Merge(const Dataspace &dataspace);
#endif
#ifdef MUIM_Dataspace_ReadIFF
/// @brief [ @b MUIM_Dataspace_ReadIFF ] Reads dataspace entries from current chunk in an IFF handle.
/// @param handle Open IFF handle positioned on a chunk previously written by Dataspace_WriteIFF.
/// @return 0 on success or IFFERR_xxx on failure.
AOS::IFFParse::IFFError ReadIFF(struct IFFHandle *handle);
#endif
#ifdef MUIM_Dataspace_Remove
/// @brief [ @b MUIM_Dataspace_Remove ] Removes an entry by ID.
/// @param id Entry reference ID.
/// @return true if the entry existed and was removed, false otherwise.
bool Remove(const unsigned long id);
#endif
#ifdef MUIM_Dataspace_WriteIFF
/// @brief [ @b MUIM_Dataspace_WriteIFF ] Writes dataspace entries into a newly created IFF chunk.
/// @param handle Open IFF handle initialized for writing.
/// @param type Chunk type.
/// @param id Chunk ID.
/// @return 0 on success or IFFERR_xxx on failure.
AOS::IFFParse::IFFError WriteIFF(struct IFFHandle *handle, const unsigned long type, const unsigned long id);
#endif
};
template <typename T, typename U> class DataspaceBuilderTemplate : public SemaphoreBuilderTemplate<T, U>
{
public:
DataspaceBuilderTemplate(const std::string &uniqueId = MUI::EmptyUniqueId, const std::string &muiClassName = MUIC_Dataspace)
: SemaphoreBuilderTemplate<T, U>(uniqueId, muiClassName)
{
}
#ifdef MUIA_Dataspace_Pool
/// @brief [ @b MUIA_Dataspace_Pool ] Sets memory pool used for dataspace entries.
/// If nullptr is passed or this tag is omitted, the dataspace creates its own pool.
T &tagPool(const void *pool);
#endif
};
class DataspaceBuilder : public DataspaceBuilderTemplate<DataspaceBuilder, Dataspace>
{
public:
DataspaceBuilder();
};
}
#define MUI_DATASPACE_TPP_INCLUDE
#include "Dataspace.tpp"
#undef MUI_DATASPACE_TPP_INCLUDE