Make various instance stuff to take references to other instance objs
[lsnes.git] / include / core / memorywatch.hpp
blob26aee2236670e157242ee1e847ea98e0a915c0bb
1 #ifndef _memorywatch__hpp__included__
2 #define _memorywatch__hpp__included__
4 #include <string>
5 #include <stdexcept>
6 #include <set>
7 #include "library/memorywatch.hpp"
8 #include "library/json.hpp"
10 class memory_space;
11 class project_state;
12 class emu_framebuffer;
14 /**
15 * lsnes memory watch printer variables.
17 struct memwatch_printer
19 /**
20 * Ctor.
22 memwatch_printer();
23 /**
24 * Serialize the printer to JSON value.
26 JSON::node serialize();
27 /**
28 * Unserialize the printer from JSON value.
30 void unserialize(const JSON::node& node);
31 /**
32 * Get a printer object corresponding to this object.
34 gcroot_pointer<memorywatch::item_printer> get_printer_obj(
35 std::function<gcroot_pointer<mathexpr::mathexpr>(const std::string& n)> vars);
36 //Fields.
37 enum position_category {
38 PC_DISABLED,
39 PC_MEMORYWATCH,
40 PC_ONSCREEN
41 } position;
42 bool cond_enable; //Ignored for disabled.
43 std::string enabled; //Ignored for disabled.
44 std::string onscreen_xpos;
45 std::string onscreen_ypos;
46 bool onscreen_alt_origin_x;
47 bool onscreen_alt_origin_y;
48 bool onscreen_cliprange_x;
49 bool onscreen_cliprange_y;
50 std::string onscreen_font; //"" is system default.
51 int64_t onscreen_fg_color;
52 int64_t onscreen_bg_color;
53 int64_t onscreen_halo_color;
56 /**
57 * lsnes memory watch item.
59 struct memwatch_item
61 /**
62 * Ctor.
64 memwatch_item(memory_space& memory);
65 /**
66 * Serialize the item to JSON value.
68 JSON::node serialize();
69 /**
70 * Unserialize the item from JSON value.
72 void unserialize(const JSON::node& node);
73 /**
74 * Get memory read operator.
76 * If bytes == 0, returns NULL.
78 memorywatch::memread_oper* get_memread_oper();
79 /**
80 * Translate compatiblity item.
82 void compatiblity_unserialize(memory_space& memory, const std::string& item);
83 //Fields
84 memwatch_printer printer; //The printer.
85 std::string expr; //The main expression.
86 std::string format; //Format.
87 unsigned bytes; //Number of bytes to read (0 => Not memory read operator).
88 bool signed_flag; //Is signed?
89 bool float_flag; //Is float?
90 int endianess; //Endianess (-1 => little, 0 => host, 1 => Big).
91 uint64_t scale_div; //Scale divisor.
92 uint64_t addr_base; //Address base.
93 uint64_t addr_size; //Address size (0 => All).
94 memory_space* mspace; //Memory space to read.
97 struct memwatch_set
99 memwatch_set(memory_space& _memory, project_state& _project, emu_framebuffer& _fbuf);
101 * Get the specified memory watch item.
103 memwatch_item& get(const std::string& name);
105 * Get the specified memory watch item as JSON serialization.
107 * Parameter name: The item name.
108 * Parameter printer: JSON pretty-printer to use.
110 std::string get_string(const std::string& name, JSON::printer* printer = NULL);
112 * Set the specified memory watch item. Fills the runtime variables.
114 * Parameter name: The name of the new item.
115 * Parameter item: The item to insert. Fields are shallow-copied.
117 void set(const std::string& name, memwatch_item& item);
119 * Set the specified memory watch item from JSON serialization. Fills the runtime variables.
121 * Parameter name: The name of the new item.
122 * Parameter item: The serialization of item to insert.
124 void set(const std::string& name, const std::string& item);
126 * Set multiple items at once.
128 * Parameter list: The list of items.
130 void set_multi(std::list<std::pair<std::string, memwatch_item>>& list);
132 * Set multiple items at once from JSON descriptions.
134 * Parameter list: The list of items.
136 void set_multi(std::list<std::pair<std::string, std::string>>& list);
138 * Rename a memory watch item.
140 * Parameter oname: The old name.
141 * Parameter newname: The new name.
142 * Returns: True on success, false if failed (new item already exists).
144 bool rename(const std::string& oname, const std::string& newname);
146 * Delete an item.
148 * Parameter name: The name of the item to delete.
150 void clear(const std::string& name);
152 * Delete multiple items.
154 * Parameter names: The names of the items to delete.
156 void clear_multi(const std::set<std::string>& name);
158 * Enumerate item names.
160 std::set<std::string> enumerate();
162 * Get value of specified memory watch as a string.
164 std::string get_value(const std::string& name);
166 * Watch all the items.
168 * Parameter rq: The render queue to use.
170 void watch(struct framebuffer::queue& rq);
172 * Get memory watch vars that go to window.
174 const std::map<std::string, std::u32string>& get_window_vars() { return window_vars; }
175 private:
176 void rebuild(std::map<std::string, memwatch_item>& nitems);
177 std::map<std::string, memwatch_item> items;
178 std::map<std::string, std::u32string> window_vars;
179 std::map<std::string, bool> used_memorywatches;
180 void erase_unused_watches();
181 void watch_output(const std::string& name, const std::string& value);
182 memorywatch::set watch_set;
183 memory_space& memory;
184 project_state& project;
185 emu_framebuffer& fbuf;
188 #endif