diff options
Diffstat (limited to 'src/lib/util')
-rw-r--r-- | src/lib/util/chd.cpp | 8 | ||||
-rw-r--r-- | src/lib/util/chdcodec.cpp | 4 | ||||
-rw-r--r-- | src/lib/util/corefile.cpp | 8 | ||||
-rw-r--r-- | src/lib/util/coretmpl.h | 10 | ||||
-rw-r--r-- | src/lib/util/flac.cpp | 8 | ||||
-rw-r--r-- | src/lib/util/flac.h | 20 | ||||
-rw-r--r-- | src/lib/util/options.cpp | 3 | ||||
-rw-r--r-- | src/lib/util/plaparse.cpp | 6 | ||||
-rw-r--r-- | src/lib/util/png.cpp | 6 | ||||
-rw-r--r-- | src/lib/util/pool.cpp | 10 | ||||
-rw-r--r-- | src/lib/util/unicode.cpp | 2 |
11 files changed, 47 insertions, 38 deletions
diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index 7d3e2c7c5c8..0de05849cdd 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -1626,7 +1626,7 @@ chd_error chd_file::codec_configure(chd_codec_type codec, int param, void *confi try { // find the codec and call its configuration - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compression); codecnum++) + for (int codecnum = 0; codecnum < std::size(m_compression); codecnum++) if (m_compression[codecnum] == codec) { m_decompressor[codecnum]->configure(param, config); @@ -2453,7 +2453,7 @@ chd_error chd_file::open_common(bool writeable) void chd_file::create_open_common() { // verify the compression types and initialize the codecs - for (int decompnum = 0; decompnum < ARRAY_LENGTH(m_compression); decompnum++) + for (int decompnum = 0; decompnum < std::size(m_compression); decompnum++) { m_decompressor[decompnum] = chd_codec_list::new_decompressor(m_compression[decompnum], *this); if (m_decompressor[decompnum] == nullptr && m_compression[decompnum] != 0) @@ -3071,7 +3071,7 @@ void *chd_file_compressor::async_compress_hunk_static(void *param, int threadid) void chd_file_compressor::async_compress_hunk(work_item &item, int threadid) { // use our thread's codec - assert(threadid < ARRAY_LENGTH(m_codecs)); + assert(threadid < std::size(m_codecs)); item.m_codecs = m_codecs[threadid]; // compute CRC-16 and SHA-1 hashes @@ -3278,7 +3278,7 @@ uint64_t chd_file_compressor::hashmap::find(util::crc16_t crc16, util::sha1_t sh void chd_file_compressor::hashmap::add(uint64_t itemnum, util::crc16_t crc16, util::sha1_t sha1) { // add to the appropriate map - if (m_block_list->m_nextalloc == ARRAY_LENGTH(m_block_list->m_array)) + if (m_block_list->m_nextalloc == std::size(m_block_list->m_array)) m_block_list = new entry_block(m_block_list); entry_t *entry = &m_block_list->m_array[m_block_list->m_nextalloc++]; entry->m_itemnum = itemnum; diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp index 7f6e0f018cd..4f5c23b3104 100644 --- a/src/lib/util/chdcodec.cpp +++ b/src/lib/util/chdcodec.cpp @@ -622,7 +622,7 @@ chd_compressor_group::chd_compressor_group(chd_file &chd, uint32_t compressor_li #endif { // verify the compression types and initialize the codecs - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) + for (int codecnum = 0; codecnum < std::size(m_compressor); codecnum++) { m_compressor[codecnum] = nullptr; if (compressor_list[codecnum] != CHD_CODEC_NONE) @@ -663,7 +663,7 @@ int8_t chd_compressor_group::find_best_compressor(const uint8_t *src, uint8_t *c // determine best compression technique complen = m_hunkbytes; int8_t compression = -1; - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) + for (int codecnum = 0; codecnum < std::size(m_compressor); codecnum++) if (m_compressor[codecnum] != nullptr) { // attempt to compress, swallowing errors diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 1149035045a..8cb8deea8f2 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -462,7 +462,7 @@ int core_text_file::getc() { // place the new character in the ring buffer m_back_char_head = 0; - m_back_char_tail = utf8_from_uchar(m_back_chars, ARRAY_LENGTH(m_back_chars), uchar); + m_back_char_tail = utf8_from_uchar(m_back_chars, std::size(m_back_chars), uchar); //assert(file->back_char_tail != -1); } } @@ -473,7 +473,7 @@ int core_text_file::getc() else { result = m_back_chars[m_back_char_head++]; - m_back_char_head %= ARRAY_LENGTH(m_back_chars); + m_back_char_head %= std::size(m_back_chars); } return result; @@ -488,7 +488,7 @@ int core_text_file::getc() int core_text_file::ungetc(int c) { m_back_chars[m_back_char_tail++] = char(c); - m_back_char_tail %= ARRAY_LENGTH(m_back_chars); + m_back_char_tail %= std::size(m_back_chars); return c; } @@ -577,7 +577,7 @@ int core_text_file::puts(std::string_view s) *pconvbuf++ = ch; // if we overflow, break into chunks - if (pconvbuf >= convbuf + ARRAY_LENGTH(convbuf) - 10) + if (pconvbuf >= convbuf + std::size(convbuf) - 10) { count += write(convbuf, pconvbuf - convbuf); pconvbuf = convbuf; diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 438f7134fd2..18b64e7c0ff 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -535,6 +535,16 @@ std::basic_string_view<CharT, Traits> buf_to_string_view(basic_ovectorstream<Cha } +// For declaring an array of the same dimensions as another array (including multi-dimensional arrays) +template <typename T, typename U> struct equivalent_array_or_type { typedef T type; }; +template <typename T, typename U, std::size_t N> struct equivalent_array_or_type<T, U[N]> { typedef typename equivalent_array_or_type<T, U>::type type[N]; }; +template <typename T, typename U> using equivalent_array_or_type_t = typename equivalent_array_or_type<T, U>::type; +template <typename T, typename U> struct equivalent_array { }; +template <typename T, typename U, std::size_t N> struct equivalent_array<T, U[N]> { typedef equivalent_array_or_type_t<T, U> type[N]; }; +template <typename T, typename U> using equivalent_array_t = typename equivalent_array<T, U>::type; +#define EQUIVALENT_ARRAY(a, T) util::equivalent_array_t<T, std::remove_reference_t<decltype(a)> > + + template <typename E> using enable_enum_t = typename std::enable_if_t<std::is_enum<E>::value, typename std::underlying_type_t<E> >; diff --git a/src/lib/util/flac.cpp b/src/lib/util/flac.cpp index 5b912b89279..13bf7aed8eb 100644 --- a/src/lib/util/flac.cpp +++ b/src/lib/util/flac.cpp @@ -10,7 +10,7 @@ #include "flac.h" -#include "osdcomm.h" +#include "corefile.h" #include <cassert> #include <new> @@ -129,7 +129,7 @@ bool flac_encoder::encode_interleaved(const int16_t *samples, uint32_t samples_p // process in batches of 2k samples FLAC__int32 converted_buffer[2048]; FLAC__int32 *dest = converted_buffer; - uint32_t cur_samples = (std::min<size_t>)(ARRAY_LENGTH(converted_buffer) / num_channels, samples_per_channel); + uint32_t cur_samples = (std::min<size_t>)(std::size(converted_buffer) / num_channels, samples_per_channel); // convert a buffers' worth for (uint32_t sampnum = 0; sampnum < cur_samples; sampnum++) @@ -162,7 +162,7 @@ bool flac_encoder::encode(int16_t *const *samples, uint32_t samples_per_channel, // process in batches of 2k samples FLAC__int32 converted_buffer[2048]; FLAC__int32 *dest = converted_buffer; - uint32_t cur_samples = (std::min<size_t>)(ARRAY_LENGTH(converted_buffer) / num_channels, samples_per_channel); + uint32_t cur_samples = (std::min<size_t>)(std::size(converted_buffer) / num_channels, samples_per_channel); // convert a buffers' worth for (uint32_t sampnum = 0; sampnum < cur_samples; sampnum++, srcindex++) @@ -464,7 +464,7 @@ bool flac_decoder::decode(int16_t **samples, uint32_t num_samples, bool swap_end { // make sure we don't have too many channels int chans = channels(); - if (chans > ARRAY_LENGTH(m_uncompressed_start)) + if (chans > std::size(m_uncompressed_start)) return false; // configure the uncompressed buffer diff --git a/src/lib/util/flac.h b/src/lib/util/flac.h index 2b814437cd5..ad667320b41 100644 --- a/src/lib/util/flac.h +++ b/src/lib/util/flac.h @@ -13,15 +13,17 @@ #pragma once -#include "corefile.h" - #include <FLAC/all.h> +#include <cstdint> + //************************************************************************** // TYPE DEFINITIONS //************************************************************************** +namespace util { class core_file; } + // ======================> flac_encoder class flac_encoder @@ -64,18 +66,18 @@ private: // internal state FLAC__StreamEncoder * m_encoder; // actual encoder util::core_file * m_file; // output file - uint32_t m_compressed_offset; // current offset with the compressed stream + uint32_t m_compressed_offset; // current offset with the compressed stream FLAC__byte * m_compressed_start; // start of compressed data - uint32_t m_compressed_length; // length of the compressed stream - + uint32_t m_compressed_length; // length of the compressed stream + // parameters - uint32_t m_sample_rate; // sample rate - uint8_t m_channels; // number of channels - uint32_t m_block_size; // block size + uint32_t m_sample_rate; // sample rate + uint8_t m_channels; // number of channels + uint32_t m_block_size; // block size // header stripping bool m_strip_metadata; // strip the metadata? - uint32_t m_ignore_bytes; // how many bytes to ignore when writing + uint32_t m_ignore_bytes; // how many bytes to ignore when writing bool m_found_audio; // have we hit the audio yet? }; diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index e1674a88fe1..bf1a4e45b20 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -12,7 +12,6 @@ #include "corefile.h" #include "corestr.h" -#include "osdcomm.h" #include <locale> #include <string> @@ -732,7 +731,7 @@ void core_options::parse_ini_file(util::core_file &inifile, int priority, bool i // loop over lines in the file char buffer[4096]; - while (inifile.gets(buffer, ARRAY_LENGTH(buffer)) != nullptr) + while (inifile.gets(buffer, std::size(buffer)) != nullptr) { // find the extent of the name char *optionname; diff --git a/src/lib/util/plaparse.cpp b/src/lib/util/plaparse.cpp index 76fbbad6983..09b7724375e 100644 --- a/src/lib/util/plaparse.cpp +++ b/src/lib/util/plaparse.cpp @@ -12,8 +12,6 @@ #include "plaparse.h" -#include "osdcomm.h" - #include <cstdio> #include <cstdlib> #include <cstring> @@ -214,11 +212,11 @@ static bool process_field(jed_data *data, const uint8_t **src, const uint8_t *sr // find keyword char dest[0x10]; - memset(dest, 0, ARRAY_LENGTH(dest)); + memset(dest, 0, sizeof(dest)); const uint8_t *seek = *src; int destptr = 0; - while (seek < srcend && isalpha(*seek) && destptr < ARRAY_LENGTH(dest) - 1) + while (seek < srcend && isalpha(*seek) && destptr < sizeof(dest) - 1) { dest[destptr] = tolower(*seek); seek++; diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp index 67e3366606b..0605206bbf1 100644 --- a/src/lib/util/png.cpp +++ b/src/lib/util/png.cpp @@ -123,7 +123,7 @@ private: png_error process(std::list<image_data_chunk> const &idata) { // do some basic checks for unsupported images - if (!pnginfo.bit_depth || (ARRAY_LENGTH(samples) <= pnginfo.color_type) || !samples[pnginfo.color_type]) + if (!pnginfo.bit_depth || (std::size(samples) <= pnginfo.color_type) || !samples[pnginfo.color_type]) return png_error::UNSUPPORTED_FORMAT; // unknown colour format if ((0 != pnginfo.interlace_method) && (1 != pnginfo.interlace_method)) return png_error::UNSUPPORTED_FORMAT; // unknown interlace method @@ -474,7 +474,7 @@ public: // do some basic checks for unsupported images if ((8 > pnginfo.bit_depth) || (pnginfo.bit_depth % 8)) return png_error::UNSUPPORTED_FORMAT; // only do multiples of 8bps here - expand lower bit depth first - if ((ARRAY_LENGTH(samples) <= pnginfo.color_type) || !samples[pnginfo.color_type]) + if ((std::size(samples) <= pnginfo.color_type) || !samples[pnginfo.color_type]) return png_error::UNSUPPORTED_FORMAT; // unknown colour sample format if ((0 != pnginfo.interlace_method) && (1 != pnginfo.interlace_method)) return png_error::UNSUPPORTED_FORMAT; // unknown interlace method @@ -721,7 +721,7 @@ public: static png_error verify_header(core_file &fp) { - EQUIVALENT_ARRAY(PNG_SIGNATURE, std::uint8_t) signature; + std::uint8_t signature[sizeof(PNG_SIGNATURE)]; // read 8 bytes if (fp.read(signature, sizeof(signature)) != sizeof(signature)) diff --git a/src/lib/util/pool.cpp b/src/lib/util/pool.cpp index faf1de170ae..509c4f76984 100644 --- a/src/lib/util/pool.cpp +++ b/src/lib/util/pool.cpp @@ -14,8 +14,8 @@ #include "osdcomm.h" #include <cstdarg> -#include <cstddef> #include <cstdlib> +#include <iterator> /*************************************************************************** @@ -35,7 +35,7 @@ struct objtype_entry { objtype_entry * next; - uint32_t type; + uint32_t type; const char * friendly; void (*destructor)(void *, size_t); }; @@ -296,7 +296,7 @@ void *pool_object_add_file_line(object_pool *pool, object_type _type, void *obje pool->blocklist = block; /* add all entries to the free list */ - for (entrynum = 0; entrynum < ARRAY_LENGTH(block->entry); entrynum++) + for (entrynum = 0; entrynum < std::size(block->entry); entrynum++) { block->entry[entrynum].next = pool->freelist; pool->freelist = &block->entry[entrynum]; @@ -615,8 +615,8 @@ bool test_memory_pools() /* some heavier stress tests */ for (i = 0; i < 512; i++) { - ptrs[i % ARRAY_LENGTH(ptrs)] = pool_realloc_lib(pool, - ptrs[i % ARRAY_LENGTH(ptrs)], rand() % 1000); + ptrs[i % std::size(ptrs)] = pool_realloc_lib(pool, + ptrs[i % std::size(ptrs)], rand() % 1000); } pool_free_lib(pool); diff --git a/src/lib/util/unicode.cpp b/src/lib/util/unicode.cpp index de6ef06e5c9..c4ee6c56cde 100644 --- a/src/lib/util/unicode.cpp +++ b/src/lib/util/unicode.cpp @@ -384,7 +384,7 @@ int utf8_from_uchar(char *utf8string, size_t count, char32_t uchar) std::string utf8_from_uchar(char32_t uchar) { char buffer[UTF8_CHAR_MAX]; - auto len = utf8_from_uchar(buffer, ARRAY_LENGTH(buffer), uchar); + auto len = utf8_from_uchar(buffer, std::size(buffer), uchar); return std::string(buffer, len); } |