Gorgon Game Engine
Blob.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <memory>
5 
6 #include "../Types.h"
7 #include "Base.h"
8 
9 namespace Gorgon { namespace Resource {
10  class File;
11  class Reader;
12 
15  class Blob : public Base {
16  public:
17 
19  typedef int Type;
20 
22  Blob() { }
23 
25  virtual ~Blob() { }
26 
28  virtual GID::Type GetGID() const override { return GID::Blob; }
29 
31  unsigned long GetSize() const { return (unsigned long)data.size(); }
32 
34  Type GetType() const { return type; }
35 
40  std::vector<Byte> &Ready(unsigned long size, Type type=0);
41 
43  void Destroy() {
44  type=0;
45  std::vector<Byte> t; data.swap(t);
46  isloaded=false;
47  }
48 
50  bool Load();
51 
53  bool IsLoaded() const { return isloaded; }
54 
57  std::vector<Byte> &GetData() { return data; }
58 
60  bool ImportFile(const std::string &filename) {
61  return ImportFile(filename, type);
62  }
63 
65  bool ImportFile(const std::string &filename, Type type);
66 
68  bool AppendFile(const std::string &filename);
69 
71  static Blob *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
72 
73  protected:
74 
76  bool load(std::shared_ptr<Reader> reader, unsigned long size, bool forceload);
77 
78  void save(Writer &writer) const override;
79 
82  unsigned long entrypoint = -1;
83 
85  std::shared_ptr<Reader> reader;
86 
88  bool isloaded = false;
89 
92 
94  bool lateloading = false;
95 
97  Type type = 0;
98 
100  std::vector<Byte> data;
101 
102  };
103 } }
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::String::From
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
Gorgon::Resource::Blob::LoadResource
static Blob * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a blob resource from the given file.
Definition: Blob.cpp:7
Gorgon::Resource::Blob::compression
GID::Type compression
Compression mode of this blob.
Definition: Blob.h:91
File.h
Gorgon::Resource::Blob::load
bool load(std::shared_ptr< Reader > reader, unsigned long size, bool forceload)
Loads the blob from the data stream.
Definition: Blob.cpp:52
Gorgon::Resource::Writer::GetStream
std::ostream & GetStream()
This should be last resort, use if the actual stream is needed.
Definition: Writer.h:96
Gorgon::Resource::Blob::lateloading
bool lateloading
Whether to load this blob during initial loading.
Definition: Blob.h:94
Base.h
Gorgon::Resource::Blob::GetType
Type GetType() const
Returns the type of the blob.
Definition: Blob.h:34
Gorgon::Resource::Writer::WriteChunkHeader
void WriteChunkHeader(GID::Type type, unsigned long size)
Writes the header of a chunk.
Definition: Writer.h:364
Gorgon::Resource::Blob::Type
int Type
The type information related to the blob.
Definition: Blob.h:19
Gorgon::Resource::Blob::Blob
Blob()
Default constructor.
Definition: Blob.h:22
Gorgon::Resource::Blob::Destroy
void Destroy()
Destroys the data stored in the blob.
Definition: Blob.h:43
Gorgon::Resource::Writer::WriteObjectStart
Marker WriteObjectStart(const Base &base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: File.cpp:211
Gorgon::Resource::Writer::WriteUInt32
void WriteUInt32(unsigned long value)
Writes a 32-bit unsigned integer to the stream.
Definition: Writer.h:158
Gorgon::Resource::Blob::GetData
std::vector< Byte > & GetData()
Returns the data stored in this blob.
Definition: Blob.h:57
Gorgon::Resource::Blob::Load
bool Load()
Loads the blob from the disk. If blob is already loaded, this function will return true.
Definition: Blob.cpp:33
Gorgon::Encoding::LZMA::Encode
void Encode(I_ &input, O_ &output)
Encodes the given data to LZMA compressed data.
Definition: LZMA.h:293
Gorgon::Resource::Blob::ImportFile
bool ImportFile(const std::string &filename)
Imports the given file as data without changing the type of the blob.
Definition: Blob.h:60
Gorgon::Utils::ASSERT_FALSE
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
Gorgon::Resource::Blob
This is sound resource.
Definition: Blob.h:15
Gorgon::Resource::Blob::GetGID
virtual GID::Type GetGID() const override
04010000h (Extended, Blob)
Definition: Blob.h:28
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Resource::Blob::IsLoaded
bool IsLoaded() const
Returns whether the blob data is loaded.
Definition: Blob.h:53
Gorgon::Resource::Writer::WriteChunkStart
Marker WriteChunkStart(GID::Type type)
Writes the start of a chunk. Should have a matching WriteEnd.
Definition: Writer.h:351
Gorgon::Resource::Blob::save
void save(Writer &writer) const override
Definition: Blob.cpp:108
Gorgon::Resource::Blob::GetSize
unsigned long GetSize() const
Size of the blob.
Definition: Blob.h:31
Gorgon::Resource::Blob::AppendFile
bool AppendFile(const std::string &filename)
Appends the given file to the end of the blob data.
Definition: Blob.cpp:163
Gorgon::Resource::Blob::Ready
std::vector< Byte > & Ready(unsigned long size, Type type=0)
Readies the blob for data writing.
Definition: Blob.cpp:18
Gorgon::Encoding::Lzma
LZMA Lzma
A default constructed LZMA object.
Definition: LZMA.cpp:196
Gorgon::Resource::GID::None
constexpr Type None
Empty, different from Null resource.
Definition: GID.h:81
Gorgon::Resource::GID::Blob
constexpr Type Blob
Definition: GID.h:227
Gorgon::Resource::GID::Blob_Cmp_Data
constexpr Type Blob_Cmp_Data
Definition: GID.h:230
Gorgon::Resource::Base
This class is the base for all Gorgon Resources.
Definition: Base.h:20
Gorgon::Resource::Blob::reader
std::shared_ptr< Reader > reader
Used to handle late loading.
Definition: Blob.h:85
Blob.h
Gorgon::Resource::Blob::~Blob
virtual ~Blob()
Destructor.
Definition: Blob.h:25
Gorgon::Resource::GID::Blob_Data
constexpr Type Blob_Data
Definition: GID.h:229
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Resource::Blob::data
std::vector< Byte > data
Blob data.
Definition: Blob.h:100
Gorgon::Resource::Blob::type
Type type
Type of the blob data.
Definition: Blob.h:97
Gorgon::Byte
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Gorgon::Resource::Writer::WriteEnd
void WriteEnd(Marker &marker)
This function performs writes necessary to end a chunk that is represented by the marker.
Definition: Writer.h:373
Gorgon::Resource::GID::Blob_Props
constexpr Type Blob_Props
Definition: GID.h:228
Gorgon::Resource::Writer::WriteInt32
void WriteInt32(long value)
Writes a 32-bit integer to the stream.
Definition: Writer.h:149
Gorgon::Resource::GID::LZMA
constexpr Type LZMA
LZMA compression.
Definition: GID.h:120
Gorgon::Resource::Writer::WriteBool
void WriteBool(bool value)
Writes a boolean value. In resource 1.0, booleans are stored as 32bit integers.
Definition: Writer.h:220
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Resource::Writer::WriteGID
void WriteGID(GID::Type value)
Writes a GID to the given stream.
Definition: Writer.h:303
Gorgon::Encoding::LZMA::Decode
void Decode(I_ &input, O_ &output, Byte *compressionproperties=nullptr, unsigned long long fsize=(unsigned long long)(long long) -1)
Decodes LZMA compressed data.
Definition: LZMA.h:317
Gorgon::Resource::Blob::entrypoint
unsigned long entrypoint
Entry point of this resource within the physical file.
Definition: Blob.h:82
Gorgon::Resource::Blob::isloaded
bool isloaded
Whether this blob is loaded or not.
Definition: Blob.h:88
Gorgon::Resource::Writer::WriteVector
void WriteVector(const std::vector< T_ > &data)
Writes a vector to the stream.
Definition: Writer.h:298