summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/putil.h
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
committer Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
commit97b67170277437131adf6ed4d60139c172529e4f (patch)
tree7a5cbf608f191075f1612b1af15832c206a3fe2d /src/lib/netlist/plib/putil.h
parentb380514764cf857469bae61c11143a19f79a74c5 (diff)
(nw) Clean up the mess on master
This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release.
Diffstat (limited to 'src/lib/netlist/plib/putil.h')
-rw-r--r--src/lib/netlist/plib/putil.h103
1 files changed, 93 insertions, 10 deletions
diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h
index 8d59c0357e2..e8145361d9d 100644
--- a/src/lib/netlist/plib/putil.h
+++ b/src/lib/netlist/plib/putil.h
@@ -5,27 +5,32 @@
*
*/
-#ifndef P_UTIL_H_
-#define P_UTIL_H_
+#ifndef PUTIL_H_
+#define PUTIL_H_
#include "pstring.h"
-#include <initializer_list>
#include <algorithm>
-#include <vector> // <<= needed by windows build
+#include <initializer_list>
+#include <vector>
+
+#define PSTRINGIFY_HELP(y) # y
+#define PSTRINGIFY(x) PSTRINGIFY_HELP(x)
+
namespace plib
{
+
namespace util
{
const pstring buildpath(std::initializer_list<pstring> list );
const pstring environment(const pstring &var, const pstring &default_val);
- }
+ } // namespace util
namespace container
{
- template <class C>
- bool contains(C &con, const typename C::value_type &elem)
+ template <class C, class T>
+ bool contains(C &con, const T &elem)
{
return std::find(con.begin(), con.end(), elem) != con.end();
}
@@ -51,7 +56,51 @@ namespace plib
{
con.erase(std::remove(con.begin(), con.end(), elem), con.end());
}
- }
+ } // namespace container
+
+ /* May be further specialized .... This is the generic version */
+ template <typename T>
+ struct constants
+ {
+ static constexpr T zero() noexcept { return static_cast<T>(0); }
+ static constexpr T one() noexcept { return static_cast<T>(1); }
+ static constexpr T two() noexcept { return static_cast<T>(2); }
+
+ /*!
+ * \brief Electric constant of vacuum
+ */
+ static constexpr T eps_0() noexcept { return static_cast<T>(8.854187817e-12); }
+ /*!
+ * \brief Relative permittivity of Silicon dioxide
+ */
+ static constexpr T eps_SiO2() noexcept { return static_cast<T>(3.9); }
+ /*!
+ * \brief Relative permittivity of Silicon
+ */
+ static constexpr T eps_Si() noexcept { return static_cast<T>(11.7); }
+ /*!
+ * \brief Boltzmann constant
+ */
+ static constexpr T k_b() noexcept { return static_cast<T>(1.38064852e-23); }
+ /*!
+ * \brief room temperature (gives VT = 0.02585 at T=300)
+ */
+ static constexpr T T0() noexcept { return static_cast<T>(300); }
+ /*!
+ * \brief Elementary charge
+ */
+ static constexpr T Q_e() noexcept { return static_cast<T>(1.6021765314e-19); }
+ /*!
+ * \brief Intrinsic carrier concentration in 1/m^3 of Silicon
+ */
+ static constexpr T NiSi() noexcept { return static_cast<T>(1.45e16); }
+
+ template <typename V>
+ static constexpr const T cast(V &&v) noexcept { return static_cast<T>(v); }
+ };
+
+ static_assert(noexcept(constants<double>::one()) == true, "Not evaluated as constexpr");
+
template <class C>
struct indexed_compare
@@ -69,7 +118,41 @@ namespace plib
std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty = false);
std::vector<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl);
+ std::vector<std::string> psplit_r(const std::string &stri,
+ const std::string &token,
+ const std::size_t maxsplit);
+
+
+ //============================================================
+ // penum - strongly typed enumeration
+ //============================================================
+
+ struct penum_base
+ {
+ protected:
+ static int from_string_int(const char *str, const char *x);
+ static std::string nthstr(int n, const char *str);
+ };
+
+} // namespace plib
+
+#define P_ENUM(ename, ...) \
+ struct ename : public plib::penum_base { \
+ enum E { __VA_ARGS__ }; \
+ ename (E v) : m_v(v) { } \
+ bool set_from_string (const std::string &s) { \
+ static char const *const strings = # __VA_ARGS__; \
+ int f = from_string_int(strings, s.c_str()); \
+ if (f>=0) { m_v = static_cast<E>(f); return true; } else { return false; } \
+ } \
+ operator E() const {return m_v;} \
+ bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \
+ bool operator==(const E &rhs) const {return m_v == rhs;} \
+ std::string name() const { \
+ static char const *const strings = # __VA_ARGS__; \
+ return nthstr(static_cast<int>(m_v), strings); \
+ } \
+ private: E m_v; };
-}
-#endif /* P_UTIL_H_ */
+#endif /* PUTIL_H_ */