summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/nl_factory.cpp
blob: eca8de4d4b25d58bd88b988c36e5d104edf6010f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// license:GPL-2.0+
// copyright-holders:Couriersud
/***************************************************************************

    nl_factory.c

    Discrete netlist implementation.

****************************************************************************/

#include "nl_factory.h"
#include "nl_base.h"
#include "nl_setup.h"
#include "plib/putil.h"
#include "nl_errstr.h"

namespace netlist { namespace factory
{

	class NETLIB_NAME(wrapper) : public device_t
	{
	public:
		NETLIB_NAME(wrapper)(netlist_base_t &anetlist, const pstring &name)
		: device_t(anetlist, name)
		{
		}
	protected:
		NETLIB_RESETI() { }
		NETLIB_UPDATEI() { };
	};

	element_t::element_t(const pstring &name, const pstring &classname,
			const pstring &def_param, const pstring &sourcefile)
		: m_name(name), m_classname(classname), m_def_param(def_param),
		  m_sourcefile(sourcefile)
	{
	}

	element_t::element_t(const pstring &name, const pstring &classname,
			const pstring &def_param)
		: m_name(name), m_classname(classname), m_def_param(def_param),
		  m_sourcefile("<unknown>")
	{
	}

	element_t::~element_t()
	{
	}

	// ----------------------------------------------------------------------------------------
	// net_device_t_base_factory
	// ----------------------------------------------------------------------------------------

	list_t::list_t( setup_t &setup)
	: m_setup(setup)
	{
	}

	list_t::~list_t()
	{
		clear();
	}

	void list_t::register_device(std::unique_ptr<element_t> &&factory)
	{
		for (auto & e : *this)
			if (e->name() == factory->name())
				m_setup.log().fatal(MF_1_FACTORY_ALREADY_CONTAINS_1, factory->name());
		push_back(std::move(factory));
	}

	factory::element_t * list_t::factory_by_name(const pstring &devname)
	{
		for (auto & e : *this)
		{
			if (e->name() == devname)
				return e.get();
		}

		m_setup.log().fatal(MF_1_CLASS_1_NOT_FOUND, devname);
		return nullptr; // appease code analysis
	}

	// -----------------------------------------------------------------------------
	// factory_lib_entry_t: factory class to wrap macro based chips/elements
	// -----------------------------------------------------------------------------

	plib::owned_ptr<device_t> library_element_t::Create(netlist_base_t &anetlist, const pstring &name)
	{
		return plib::owned_ptr<device_t>::Create<NETLIB_NAME(wrapper)>(anetlist, name);
	}

	void library_element_t::macro_actions(netlist_base_t &anetlist, const pstring &name)
	{
		anetlist.setup().namespace_push(name);
		anetlist.setup().include(this->name());
		anetlist.setup().namespace_pop();
	}


} }