tbx  0.7.6
memoryloader.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2021 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_MEMORYLOADER_H_
26 #define TBX_MEMORYLOADER_H_
27 
28 #include "loader.h"
29 
30 namespace tbx {
31 
41 class MemoryLoader : public Loader {
42 public:
43  MemoryLoader(bool show_error = false, const char *error_title = 0);
44  virtual ~MemoryLoader();
45 
46  virtual bool load_file(LoadEvent &event);
47 
48  virtual void *data_buffer(const LoadEvent &event, int &buffer_size);
49  virtual bool data_received(DataReceivedEvent &event);
50  virtual void data_error(const LoadEvent &event);
51  virtual void data_exception(const LoadEvent &event, std::exception &except);
52 
62  virtual void data_loaded(const LoadEvent &event, char *data, int data_size, bool &claim_data) = 0;
63 
64 private:
65  bool _show_error;
66  std::string _error_title;
67  char *_buffer;
68  int _size;
69  int _offset;
70 };
71 
72 }
73 
74 #endif /* MEMORY_LOADER_H_ */
tbx::MemoryLoader::data_error
virtual void data_error(const LoadEvent &event)
Informs loader that an error occurred during application to application data transfer.
Definition: memoryloader.cc:173
tbx::MemoryLoader::load_file
virtual bool load_file(LoadEvent &event)
Overriden from Loader to load the file and pass the bytes loaded to the data_loaded function.
Definition: memoryloader.cc:60
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::Loader
Class to handle file/data loading from the filer or an external application.
Definition: loader.h:179
tbx::MemoryLoader::data_exception
virtual void data_exception(const LoadEvent &event, std::exception &except)
Informs loader an exception occurred during the loading process.
Definition: memoryloader.cc:190
tbx::DataReceivedEvent
Class with details of buffer transferred from another application.
Definition: loader.h:113
tbx::MemoryLoader::data_loaded
virtual void data_loaded(const LoadEvent &event, char *data, int data_size, bool &claim_data)=0
Called when all the data has been loaded this method is called with a character array of the data rec...
tbx::MemoryLoader::MemoryLoader
MemoryLoader(bool show_error=false, const char *error_title=0)
Construct the memory loader object.
Definition: memoryloader.cc:38
tbx::MemoryLoader::data_buffer
virtual void * data_buffer(const LoadEvent &event, int &buffer_size)
Set up buffer for application to application data transfer.
Definition: memoryloader.cc:103
tbx::LoadEvent
Class with details of a file load operation.
Definition: loader.h:42
tbx::MemoryLoader
Helper class to implement the loader interface and call a routine once all the bytes have been loaded...
Definition: memoryloader.h:41
tbx::MemoryLoader::data_received
virtual bool data_received(DataReceivedEvent &event)
Overriden from Loader to populate the internal data buffer from the transfer.
Definition: memoryloader.cc:121