diff options
author | 2017-01-26 19:55:37 +0100 | |
---|---|---|
committer | 2017-01-26 19:55:37 +0100 | |
commit | f603c763fe35a81bd3a7f41ab8a53c61c953e2cb (patch) | |
tree | 26b3659573426ea0111c3d5203b3eea78e508357 /src/lib/netlist/plib/pstring.h | |
parent | 4e5f922341d962577d19a62ee4ed21c7de1fc8f0 (diff) | |
parent | 4ba1c0f2cad36dc23613e0dec24e7e439d3e80fd (diff) |
Merge branch 'master' of https://github.com/mamedev/mame
Diffstat (limited to 'src/lib/netlist/plib/pstring.h')
-rw-r--r-- | src/lib/netlist/plib/pstring.h | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 999bd10ce6b..e3dd475175e 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -10,6 +10,7 @@ #include <cstdarg> #include <cstddef> #include <iterator> +#include <exception> #include "pconfig.h" @@ -22,27 +23,24 @@ struct pstr_t { - //str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; } - pstr_t(const std::size_t alen) - { - init(alen); - } + pstr_t(const std::size_t alen) { init(alen); } void init(const std::size_t alen) { - m_ref_count = 1; - m_len = alen; - m_str[0] = 0; + m_ref_count = 1; + m_len = alen; + m_str[0] = 0; } char *str() { return &m_str[0]; } unsigned char *ustr() { return reinterpret_cast<unsigned char *>(&m_str[0]); } std::size_t len() const { return m_len; } - int m_ref_count; + void inc() { m_ref_count++; } + bool dec_and_check() { --m_ref_count; return m_ref_count == 0; } private: + int m_ref_count; std::size_t m_len; char m_str[1]; }; - template <typename F> struct pstring_t { @@ -75,7 +73,8 @@ public: pstring_t(C (&string)[N]) : m_ptr(&m_zero) { static_assert(std::is_same<C, const mem_t>::value, "pstring constructor only accepts const mem_t"); static_assert(N>0,"pstring from array of length 0"); - //static_assert(string[N-1] == 0, "pstring constructor parameter not a string literal"); + if (string[N-1] != 0) + throw std::exception(); init(string); } @@ -170,13 +169,6 @@ public: const pstring_t ucase() const; - // FIXME: do something with encoding - // FIXME: belongs into derived class - // This is only used in state saving to support "owners" whose name() function - // returns char*. - static pstring_t from_utf8(const mem_t *c) { return pstring_t(c, UTF8); } - static pstring_t from_utf8(const pstring_t &c) { return c; } - static void resetmem(); protected: @@ -185,13 +177,13 @@ protected: private: void init(const mem_t *string) { - m_ptr->m_ref_count++; + m_ptr->inc(); if (string != nullptr && *string != 0) pcopy(string); } void init(const pstring_t &string) { - m_ptr->m_ref_count++; + m_ptr->inc(); pcopy(string); } @@ -206,7 +198,7 @@ private: { sfree(m_ptr); m_ptr = from.m_ptr; - m_ptr->m_ref_count++; + m_ptr->inc(); } void pcat(const mem_t *s); void pcat(const pstring_t &s); @@ -217,8 +209,6 @@ private: static pstr_t m_zero; }; -template <typename F> pstr_t pstring_t<F>::m_zero(0); - struct pu8_traits { static const unsigned MAXCODELEN = 1; /* in memory units */ |