4#include "ResourceArchive.h"
6#include "Foundation/Memory/MemoryBuffer.h"
7#include "Foundation/Platform/Threads.h"
8#include "Foundation/StringView.h"
25 uint8_t *
data() {
return static_cast<uint8_t *
>(
buffer->data()); }
29 const uint8_t *
data()
const {
return static_cast<uint8_t *
>(
buffer->data()); }
32 size_t size()
const {
return buffer ?
buffer->size() : 0; }
35 bool empty()
const {
return !
buffer || size() == 0; }
40 return empty() ? std::string_view() : std::string_view(
static_cast<const char*
>(
buffer->data()), size());
50 std::span<const T>
toSpan(
size_t offset = 0)
const {
51 if (offset >= size()) {
52 return std::span<const T>();
55 const void* dataStart =
static_cast<const uint8_t*
>(
buffer->data()) + offset;
56 return std::span<const T>(
static_cast<const T*
>(dataStart), (size() - offset) /
sizeof(T));
61 std::shared_ptr<Memory::MemoryBuffer>
buffer;
72 enum class ResourceProtocol
86 ResourceProtocol protocol = ResourceProtocol::None;
108 friend void resourceStoreInspector(
Context * context,
bool * show);
116 void preloadResources(
const std::vector<std::string> & resourceNames);
122 bool hasResources(
const std::vector<std::string> & resourceNames);
128 bool hasResource(
const std::string & resourceName);
133 void addResource(std::string_view resourceName,
const std::string_view content);
138 void addResource(std::string_view resourceName,
const void* content_data,
size_t content_size);
143 void addResourceArchive(
const std::string & archiveName,
bool prepend =
false);
149 std::string getResourcePath(std::string_view resourceName,
ResourceStoreFlags flags = ResourceStoreFlags::None)
const;
168 std::string getResourceContentString(std::string_view resourceName,
ResourceStoreFlags flags = ResourceStoreFlags::None)
const;
174 void addSearchPath(
const std::string & path,
bool prepend =
false);
180 const std::string& getDataDir()
const;
185 void purge(
const std::string & resourceName);
197 std::unique_ptr<struct ResourceStoreStorage> data;
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Provides handling of reading and caching of external resources.
@ PreferUncachedContent
Try fetching data before resorting to cached data.
@ NoCachedContent
Never use cached data.
Contains all Cogs related functionality.
std::shared_ptr< Memory::MemoryBuffer > buffer
Actual resource contents. Prefer using access methods.
std::string_view toStringView() const
Return contents as a std::string_view.
std::span< const T > toSpan(size_t offset=0) const
const uint8_t * data() const
Returns pointer to start of buffer data. Requires non-empty Contents.
uint8_t * data()
Returns pointer to start of buffer data. Requires non-empty Contents.