diff options
Diffstat (limited to 'src/lib/netlist/plib/putil.h')
-rw-r--r-- | src/lib/netlist/plib/putil.h | 198 |
1 files changed, 0 insertions, 198 deletions
diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 7cc855e2802..4ba761fc642 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -102,184 +102,6 @@ namespace plib { - /// \brief Source code locations. - /// - /// The c++20 draft for source locations is based on const char * strings. - /// It is thus only suitable for c++ source code and not for programmatic - /// parsing of files. This class is a replacement for dynamic use cases. - /// - struct source_location - { - source_location() noexcept - : m_file("unknown"), m_func(m_file), m_line(0), m_col(0) - { } - - source_location(pstring file, unsigned line) noexcept - : m_file(std::move(file)), m_func("unknown"), m_line(line), m_col(0) - { } - - source_location(pstring file, pstring func, unsigned line) noexcept - : m_file(std::move(file)), m_func(std::move(func)), m_line(line), m_col(0) - { } - - PCOPYASSIGNMOVE(source_location, default) - - ~source_location() = default; - - unsigned line() const noexcept { return m_line; } - unsigned column() const noexcept { return m_col; } - pstring file_name() const noexcept { return m_file; } - pstring function_name() const noexcept { return m_func; } - - source_location &operator ++() noexcept - { - ++m_line; - return *this; - } - - private: - pstring m_file; - pstring m_func; - unsigned m_line; - unsigned m_col; - }; - - /// \brief Base source class. - /// - /// Pure virtual class all other source implementations are based on. - /// Sources provide an abstraction to read input from a variety of - /// sources, e.g. files, memory, remote locations. - /// - class psource_t - { - public: - - struct stream_ext - { - explicit stream_ext() = default; - - stream_ext(std::unique_ptr<std::istream> &&strm, const pstring &filename) - : m_strm(std::move(strm)) - , m_filename(filename) - { - } - stream_ext(const stream_ext &) = delete; - stream_ext &operator=(const stream_ext &) = delete; - stream_ext(stream_ext &&rhs) /*noexcept*/ - { - m_strm = std::move(rhs.m_strm); - m_filename = rhs.m_filename; - } - stream_ext &operator=(stream_ext &&) /*noexcept*/ = delete; - - std::istream &stream() noexcept { return *m_strm; } - pstring filename() { return m_filename; } - - bool empty() { return m_strm == nullptr; } - - // FIXME: workaround input context should accept stream_ptr - - std::unique_ptr<std::istream> release_stream() { return std::move(m_strm); } - private: - std::unique_ptr<std::istream> m_strm; - pstring m_filename; - }; - - using stream_ptr = stream_ext; //FIXME: rename to stream_type - - psource_t() noexcept = default; - - PCOPYASSIGNMOVE(psource_t, delete) - - virtual ~psource_t() noexcept = default; - - virtual stream_ptr stream(const pstring &name) = 0; - private: - }; - - /// \brief Generic string source. - /// - /// Will return the given string when name matches. - /// Is used in preprocessor code to eliminate inclusion of certain files. - /// - class psource_str_t : public psource_t - { - public: - psource_str_t(pstring name, pstring str) - : m_name(std::move(name)), m_str(std::move(str)) - {} - - PCOPYASSIGNMOVE(psource_str_t, delete) - ~psource_str_t() noexcept override = default; - - typename psource_t::stream_ptr stream(const pstring &name) override - { - if (name == m_name) - return stream_ptr(std::make_unique<std::stringstream>(m_str), name); - - return psource_t::stream_ptr(); - } - private: - pstring m_name; - pstring m_str; - }; - - /// \brief Generic sources collection. - /// - /// \tparam ARENA memory arena, defaults to aligned_arena - /// - template <typename ARENA = aligned_arena> - class psource_collection_t - { - public: - using source_type = std::unique_ptr<psource_t>; - using list_t = std::vector<source_type>; - - psource_collection_t() noexcept = default; - - PCOPYASSIGNMOVE(psource_collection_t, delete) - virtual ~psource_collection_t() noexcept = default; - - void add_source(source_type &&src) - { - m_collection.push_back(std::move(src)); - } - - template <typename S = psource_t> - typename psource_t::stream_ptr get_stream(pstring name) - { - for (auto &s : m_collection) - { - auto *source(dynamic_cast<S *>(s.get())); - if (source) - { - auto strm = source->stream(name); - if (!strm.empty()) - return strm; - } - } - return typename S::stream_ptr(); - } - - template <typename S, typename F> - bool for_all(F lambda) - { - for (auto &s : m_collection) - { - auto *source(dynamic_cast<S *>(s.get())); - if (source) - { - if (lambda(source)) - return true; - } - } - return false; - } - - private: - list_t m_collection; - }; - namespace util { pstring basename(const pstring &filename, const pstring &suffix = ""); @@ -320,26 +142,6 @@ namespace plib } } // namespace container - template <class C> - struct indexed_compare - { - explicit indexed_compare(const C& target): m_target(target) {} - - bool operator()(int a, int b) const { return m_target[a] < m_target[b]; } - - const C& m_target; - }; - - // ---------------------------------------------------------------------------------------- - // string list - // ---------------------------------------------------------------------------------------- - - 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, - std::size_t maxsplit); - // ---------------------------------------------------------------------------------------- // simple hash // ---------------------------------------------------------------------------------------- |