summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/netlist/plib/pstate.c
blob: 326eb13fe49fe36ab535ac1a0c738f5978cff9be (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
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * pstate.c
 *
 */

#include "pstate.h"

pstate_manager_t::pstate_manager_t()
{
}

pstate_manager_t::~pstate_manager_t()
{
	m_save.clear_and_free();
}



ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pstate_data_type_e dt, const void *owner, const int size, const int count, void *ptr, bool is_ptr)
{
	pstring fullname = stname;
	ATTR_UNUSED  pstring ts[] = {
			"NOT_SUPPORTED",
			"DT_CUSTOM",
			"DT_DOUBLE",
			"DT_INT64",
			"DT_INT16",
			"DT_INT8",
			"DT_INT",
			"DT_BOOLEAN",
			"DT_FLOAT"
	};

	pstate_entry_t *p = palloc(pstate_entry_t(stname, dt, owner, size, count, ptr, is_ptr));
	m_save.add(p);
}

ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner)
{
	pstate_entry_t::list_t todelete;

	for (std::size_t i=0; i < m_save.size(); i++)
	{
		if (m_save[i]->m_owner == owner)
			todelete.add(m_save[i]);
	}
	for (std::size_t i=0; i < todelete.size(); i++)
	{
		m_save.remove(todelete[i]);
	}
	todelete.clear_and_free();
}

ATTR_COLD void pstate_manager_t::pre_save()
{
	for (std::size_t i=0; i < m_save.size(); i++)
		if (m_save[i]->m_dt == DT_CUSTOM)
			m_save[i]->m_callback->on_pre_save();
}

ATTR_COLD void pstate_manager_t::post_load()
{
	for (std::size_t i=0; i < m_save.size(); i++)
		if (m_save[i]->m_dt == DT_CUSTOM)
			m_save[i]->m_callback->on_post_load();
}

template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname)
{
	//save_state_ptr(stname, DT_CUSTOM, 0, 1, &state);
	pstate_callback_t *state_p = &state;
	pstate_entry_t *p = palloc(pstate_entry_t(stname, owner, state_p));
	m_save.add(p);
	state.register_state(*this, stname);
}