summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/corefile.h
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-03-12 12:31:13 +0100
committer ImJezze <jezze@gmx.net>2016-03-12 12:31:13 +0100
commita026a582f1a0ea8c1ede3acaddacef506ef3f3b0 (patch)
treee31573822f2359677de519f9f3b600d98e8764cd /src/lib/util/corefile.h
parent477d2abd43984f076b7e45f5527591fa8fd0d241 (diff)
parentdcab55bf53b94713a6f72e9633f5101c8dd6c08c (diff)
Merge pull request #15 from mamedev/master
Sync to base master
Diffstat (limited to 'src/lib/util/corefile.h')
-rw-r--r--src/lib/util/corefile.h127
1 files changed, 70 insertions, 57 deletions
diff --git a/src/lib/util/corefile.h b/src/lib/util/corefile.h
index 36060631f35..7ec76af7cb5 100644
--- a/src/lib/util/corefile.h
+++ b/src/lib/util/corefile.h
@@ -1,5 +1,5 @@
// license:BSD-3-Clause
-// copyright-holders:Aaron Giles
+// copyright-holders:Aaron Giles, Vas Crabb
/***************************************************************************
corefile.h
@@ -13,12 +13,16 @@
#ifndef __COREFILE_H__
#define __COREFILE_H__
-#include <stdarg.h>
#include "corestr.h"
-#include <string>
#include "coretmpl.h"
+#include "strformat.h"
+
+#include <cstdint>
+#include <memory>
+#include <string>
+namespace util {
/***************************************************************************
ADDITIONAL OPEN FLAGS
@@ -32,98 +36,107 @@
#define FCOMPRESS_MAX 9 /* maximum compression */
-
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
-struct core_file;
-
-
+class core_file
+{
+public:
+ typedef std::unique_ptr<core_file> ptr;
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
+ // ----- file open/close -----
-/* ----- file open/close ----- */
+ // open a file with the specified filename
+ static file_error open(const char *filename, std::uint32_t openflags, ptr &file);
-/* open a file with the specified filename */
-file_error core_fopen(const char *filename, UINT32 openflags, core_file **file);
+ // open a RAM-based "file" using the given data and length (read-only)
+ static file_error open_ram(const void *data, std::size_t length, std::uint32_t openflags, ptr &file);
-/* open a RAM-based "file" using the given data and length (read-only) */
-file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file);
+ // open a RAM-based "file" using the given data and length (read-only), copying the data
+ static file_error open_ram_copy(const void *data, std::size_t length, std::uint32_t openflags, ptr &file);
-/* open a RAM-based "file" using the given data and length (read-only), copying the data */
-file_error core_fopen_ram_copy(const void *data, size_t length, UINT32 openflags, core_file **file);
+ // open a proxy "file" that forwards requests to another file object
+ static file_error open_proxy(core_file &file, ptr &proxy);
-/* close an open file */
-void core_fclose(core_file *file);
+ // close an open file
+ virtual ~core_file();
-/* enable/disable streaming file compression via zlib; level is 0 to disable compression, or up to 9 for max compression */
-file_error core_fcompress(core_file *file, int level);
+ // enable/disable streaming file compression via zlib; level is 0 to disable compression, or up to 9 for max compression
+ virtual file_error compress(int level) = 0;
+ // ----- file positioning -----
-/* ----- file positioning ----- */
+ // adjust the file pointer within the file
+ virtual int seek(std::int64_t offset, int whence) = 0;
-/* adjust the file pointer within the file */
-int core_fseek(core_file *file, INT64 offset, int whence);
+ // return the current file pointer
+ virtual std::uint64_t tell() const = 0;
-/* return the current file pointer */
-UINT64 core_ftell(core_file *file);
+ // return true if we are at the EOF
+ virtual bool eof() const = 0;
-/* return true if we are at the EOF */
-int core_feof(core_file *file);
+ // return the total size of the file
+ virtual std::uint64_t size() const = 0;
-/* return the total size of the file */
-UINT64 core_fsize(core_file *file);
+ // ----- file read -----
+ // standard binary read from a file
+ virtual std::uint32_t read(void *buffer, std::uint32_t length) = 0;
-/* ----- file read ----- */
+ // read one character from the file
+ virtual int getc() = 0;
-/* standard binary read from a file */
-UINT32 core_fread(core_file *file, void *buffer, UINT32 length);
+ // put back one character from the file
+ virtual int ungetc(int c) = 0;
-/* read one character from the file */
-int core_fgetc(core_file *file);
+ // read a full line of text from the file
+ virtual char *gets(char *s, int n) = 0;
-/* put back one character from the file */
-int core_ungetc(int c, core_file *file);
+ // get a pointer to a buffer that holds the full file data in RAM
+ // this function may cause the full file data to be read
+ virtual const void *buffer() = 0;
-/* read a full line of text from the file */
-char *core_fgets(char *s, int n, core_file *file);
+ // open a file with the specified filename, read it into memory, and return a pointer
+ static file_error load(const char *filename, void **data, std::uint32_t &length);
+ static file_error load(const char *filename, dynamic_buffer &data);
-/* get a pointer to a buffer that holds the full file data in RAM */
-/* this function may cause the full file data to be read */
-const void *core_fbuffer(core_file *file);
-/* open a file with the specified filename, read it into memory, and return a pointer */
-file_error core_fload(const char *filename, void **data, UINT32 *length);
-file_error core_fload(const char *filename, dynamic_buffer &data);
+ // ----- file write -----
+ // standard binary write to a file
+ virtual std::uint32_t write(const void *buffer, std::uint32_t length) = 0;
+ // write a line of text to the file
+ virtual int puts(const char *s) = 0;
-/* ----- file write ----- */
+ // printf-style text write to a file
+ virtual int vprintf(util::format_argument_pack<std::ostream> const &args) = 0;
+ template <typename Format, typename... Params> int printf(Format &&fmt, Params &&...args)
+ {
+ return vprintf(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+ }
-/* standard binary write to a file */
-UINT32 core_fwrite(core_file *file, const void *buffer, UINT32 length);
+ // file truncation
+ virtual file_error truncate(std::uint64_t offset) = 0;
-/* write a line of text to the file */
-int core_fputs(core_file *f, const char *s);
+ // flush file buffers
+ virtual file_error flush() = 0;
-/* printf-style text write to a file */
-int core_vfprintf(core_file *f, const char *fmt, va_list va);
-int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...) ATTR_PRINTF(2,3);
-/* file truncation */
-file_error core_truncate(core_file *f, UINT64 offset);
+protected:
+ core_file();
+};
-/* flush file buffers */
-file_error core_fflush(core_file *f);
+} // namespace util
+/***************************************************************************
+ FUNCTION PROTOTYPES
+***************************************************************************/
/* ----- filename utilities ----- */