VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Defaults.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "CoreObject.h"
16#include "OptionTypes.h"
17#include "Concurrency.h"
18#include "IOUtils.h"
19
20namespace vc64 {
21
22namespace fs = ::std::filesystem;
23
24class Defaults final : public CoreObject {
25
26 mutable util::ReentrantMutex mutex;
27
29 std::map <string, string> values;
30
32 std::map <string, string> fallbacks;
33
34
35 //
36 // Methods
37 //
38
39public:
40
41 Defaults();
42 Defaults(Defaults const&) = delete;
43 const char *objectName() const override { return "Defaults"; }
44 void operator=(Defaults const&) = delete;
45
46private:
47
48 void _dump(Category category, std::ostream& os) const override;
49
50
51 //
52 // Loading and saving the key-value storage
53 //
54
55public:
56
57 // Loads a storage file
58 void load(const fs::path &path);
59 void load(std::ifstream &stream);
60 void load(std::stringstream &stream);
61
62 // Saves a storage file
63 void save(const fs::path &path);
64 void save(std::ofstream &stream);
65 void save(std::stringstream &stream);
66
67
68 //
69 // Reading key-value pairs
70 //
71
72public:
73
74 // Queries a key-value pair
75 string getString(const string &key) const;
76 i64 getInt(const string &key) const;
77 // i64 get(Option option) const;
78 i64 get(Option option, isize nr = 0) const;
79
80 // Queries a fallback key-value pair
81 string getFallbackRaw(const string &key) const;
82 i64 getFallback(const string &key) const;
83 i64 getFallback(Option option) const;
84 i64 getFallback(Option option, isize nr = 0) const;
85
86
87 //
88 // Writing key-value pairs
89 //
90
91 // Writes a key-value pair into the user storage
92 void set(const string &key, const string &value);
93 void set(Option option, const string &value, std::vector<isize> objids = { 0 });
94 void set(Option option, i64 value, std::vector<isize> objids = { 0 });
95
96 // Writes a key-value pair into the fallback storage
97 void setFallback(const string &key, const string &value);
98 void setFallback(Option option, const string &value, std::vector<isize> objids = { 0 });
99 void setFallback(Option option, i64 value, std::vector<isize> objids = { 0 });
100
101
102 //
103 // Deleting key-value pairs
104 //
105
106 // Deletes all key-value pairs
107 void remove();
108
109 // Deletes selected key-value pairs
110 void remove(const string &key) throws;
111 void remove(Option option, isize nr = 0) throws;
112 void remove(Option option, std::vector <isize> nrs) throws;
113};
114
115}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16