diff options
author | Aki <please@ignore.pl> | 2022-04-10 20:01:38 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-10 20:55:52 +0200 |
commit | 014ec9abb825fc91366ae54945187d01e2c92e55 (patch) | |
tree | 4ba7f305bcb4bae3fe0707102b8ef4d39161d42a /StarsEx/DataSource.h | |
parent | 879612a1dcb6bb5b891447baffd4d5917ea37ee5 (diff) | |
download | starshatter-014ec9abb825fc91366ae54945187d01e2c92e55.zip starshatter-014ec9abb825fc91366ae54945187d01e2c92e55.tar.gz starshatter-014ec9abb825fc91366ae54945187d01e2c92e55.tar.bz2 |
Added simple DataSources to replace parts of DataLoader
Diffstat (limited to 'StarsEx/DataSource.h')
-rw-r--r-- | StarsEx/DataSource.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/StarsEx/DataSource.h b/StarsEx/DataSource.h new file mode 100644 index 0000000..3da58ca --- /dev/null +++ b/StarsEx/DataSource.h @@ -0,0 +1,64 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. +*/ + +#ifndef DataSource_h +#define DataSource_h + +#include <cstdint> + +#include "Archive.h" +#include "List.h" +#include "Text.h" + + +class DataSource +{ +public: + DataSource(); + virtual ~DataSource(); + + virtual void SetPrefix(const char* prefix=nullptr); + virtual bool Find(const char* name) const = 0; + virtual int ListFiles(Text filter, List<Text>& items, bool recurse=false) const = 0; + virtual int Load(const char* name, std::uint8_t*& buf, bool null_terminate=false) const = 0; + +protected: + Text m_prefix; +}; + + +class ArchiveDataSource : public DataSource +{ +public: + explicit ArchiveDataSource(const char* name); + explicit ArchiveDataSource(DataArchive* archive); + ~ArchiveDataSource() override; + + bool Find(const char* name) const override; + int ListFiles(Text filter, List<Text>& items, bool recurse=false) const override; + int Load(const char* name, std::uint8_t*& buf, bool null_terminate=false) const override; + +protected: + DataArchive* m_archive; +}; + + +class FileSystemDataSource : public DataSource +{ +public: + explicit FileSystemDataSource(const char* path=""); + ~FileSystemDataSource() override; + + bool Find(const char* name) const override; + int ListFiles(Text filter, List<Text>& items, bool recurse=false) const override; + int Load(const char* name, std::uint8_t*& buf, bool null_terminate=false) const override; + +protected: + const char* m_path; +}; + + +#endif // DataSource_h |