summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/netlist/nl_factory.h
blob: 2b29efca61f877579fefc71d96849bbece359242 (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
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * nl_factory.h
 *
 *
 */

#ifndef NLFACTORY_H_
#define NLFACTORY_H_

#include "nl_config.h"
#include "plib/palloc.h"
#include "plib/plists.h"
#include "nl_base.h"

namespace netlist
{
	// -----------------------------------------------------------------------------
	// net_dev class factory
	// -----------------------------------------------------------------------------

	class base_factory_t
	{
		NETLIST_PREVENT_COPYING(base_factory_t)
	public:
		ATTR_COLD base_factory_t(const pstring &name, const pstring &classname,
				const pstring &def_param)
		: m_name(name), m_classname(classname), m_def_param(def_param)
		{}

		virtual ~base_factory_t() {}

		virtual device_t *Create() = 0;

		ATTR_COLD const pstring &name() const { return m_name; }
		ATTR_COLD const pstring &classname() const { return m_classname; }
		ATTR_COLD const pstring &param_desc() const { return m_def_param; }
		ATTR_COLD const pstring_list_t term_param_list();
		ATTR_COLD const pstring_list_t def_params();

	protected:
		pstring m_name;                             /* device name */
		pstring m_classname;                        /* device class name */
		pstring m_def_param;                        /* default parameter */
	};

	template <class C>
	class factory_t : public base_factory_t
	{
		NETLIST_PREVENT_COPYING(factory_t)
	public:
		ATTR_COLD factory_t(const pstring &name, const pstring &classname,
				const pstring &def_param)
		: base_factory_t(name, classname, def_param) { }

		ATTR_COLD device_t *Create()
		{
			device_t *r = palloc(C);
			//r->init(setup, name);
			return r;
		}
	};

	class factory_list_t
	{
	public:
		typedef plist_t<base_factory_t *> list_t;

		factory_list_t();
		~factory_list_t();

		template<class _C>
		ATTR_COLD void register_device(const pstring &name, const pstring &classname,
				const pstring &def_param)
		{
			m_list.add(palloc(factory_t< _C >, name, classname, def_param));
		}

		ATTR_COLD void register_device(base_factory_t *factory)
		{
			m_list.add(factory);
		}

		ATTR_COLD device_t *new_device_by_classname(const pstring &classname) const;
		ATTR_COLD device_t *new_device_by_name(const pstring &name, setup_t &setup) const;
		ATTR_COLD base_factory_t * factory_by_name(const pstring &name, setup_t &setup) const;

		const list_t &list() { return m_list; }

	private:
		list_t m_list;

	};

}

#endif /* NLFACTORY_H_ */