summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/config.h
blob: e9f528a17cc63a24b98cb9dce36ff98fb5d16e41 (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
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria, Aaron Giles
/***************************************************************************

    config.h

    Wrappers for handling MAME configuration files
***************************************************************************/

#ifndef MAME_EMU_CONFIG_H
#define MAME_EMU_CONFIG_H

#pragma once

#include "xmlfile.h"

/*************************************
 *
 *  Constants
 *
 *************************************/

#define CONFIG_VERSION          10

enum class config_type
{
	INIT = 0,       // opportunity to initialize things first
	CONTROLLER,     // loading from controller file
	DEFAULT,        // loading from default.cfg
	GAME,           // loading from game.cfg
	FINAL           // opportunity to finish initialization
};

/*************************************
 *
 *  Type definitions
 *
 *************************************/

typedef delegate<void (config_type, util::xml::data_node const *)> config_load_delegate;
typedef delegate<void (config_type, util::xml::data_node *)> config_save_delegate;

// ======================> configuration_manager

class configuration_manager
{
	struct config_element
	{
		std::string          name;              // node name
		config_load_delegate load;              // load callback
		config_save_delegate save;              // save callback
	};

public:
	// construction/destruction
	configuration_manager(running_machine &machine);

	void config_register(const char* nodename, config_load_delegate load, config_save_delegate save);
	int load_settings();
	void save_settings();

	// getters
	running_machine &machine() const { return m_machine; }
private:
	int load_xml(emu_file &file, config_type which_type);
	int save_xml(emu_file &file, config_type which_type);

	// internal state
	running_machine &   m_machine;                  // reference to our machine
	std::vector<config_element> m_typelist;
};

#endif  /* MAME_EMU_CONFIG_H */