Rename some classes

This commit is contained in:
Ilari Liusvaara 2014-05-13 18:43:05 +03:00
parent 670f92c3f8
commit 6c9d34123d
6 changed files with 79 additions and 85 deletions

View file

@ -20,7 +20,7 @@ struct emulator_instance
movie_logic mlogic;
memory_space memory;
lua::state lua;
lsnes_memorywatch_set mwatch;
memwatch_set mwatch;
settingvar::group settings;
settingvar::cache setcache;
voice_commentary commentary;

View file

@ -7,19 +7,15 @@
#include "library/memorywatch.hpp"
#include "library/json.hpp"
std::set<std::string> get_watches() throw(std::bad_alloc);
std::string get_watchexpr_for(const std::string& w) throw(std::bad_alloc);
void set_watchexpr_for(const std::string& w, const std::string& expr) throw(std::bad_alloc);
/**
* lsnes memory watch printer variables.
*/
struct lsnes_memorywatch_printer
struct memwatch_printer
{
/**
* Ctor.
*/
lsnes_memorywatch_printer();
memwatch_printer();
/**
* Serialize the printer to JSON value.
*/
@ -56,12 +52,12 @@ struct lsnes_memorywatch_printer
/**
* lsnes memory watch item.
*/
struct lsnes_memorywatch_item
struct memwatch_item
{
/**
* Ctor.
*/
lsnes_memorywatch_item();
memwatch_item();
/**
* Serialize the item to JSON value.
*/
@ -81,7 +77,7 @@ struct lsnes_memorywatch_item
*/
void compatiblity_unserialize(const std::string& item);
//Fields
lsnes_memorywatch_printer printer; //The printer.
memwatch_printer printer; //The printer.
std::string expr; //The main expression.
std::string format; //Format.
unsigned bytes; //Number of bytes to read (0 => Not memory read operator).
@ -94,12 +90,12 @@ struct lsnes_memorywatch_item
memory_space* mspace; //Memory space to read.
};
struct lsnes_memorywatch_set
struct memwatch_set
{
/**
* Get the specified memory watch item.
*/
lsnes_memorywatch_item& get(const std::string& name);
memwatch_item& get(const std::string& name);
/**
* Get the specified memory watch item as JSON serialization.
*
@ -113,7 +109,7 @@ struct lsnes_memorywatch_set
* Parameter name: The name of the new item.
* Parameter item: The item to insert. Fields are shallow-copied.
*/
void set(const std::string& name, lsnes_memorywatch_item& item);
void set(const std::string& name, memwatch_item& item);
/**
* Set the specified memory watch item from JSON serialization. Fills the runtime variables.
*
@ -126,7 +122,7 @@ struct lsnes_memorywatch_set
*
* Parameter list: The list of items.
*/
void set_multi(std::list<std::pair<std::string, lsnes_memorywatch_item>>& list);
void set_multi(std::list<std::pair<std::string, memwatch_item>>& list);
/**
* Set multiple items at once from JSON descriptions.
*
@ -172,8 +168,8 @@ struct lsnes_memorywatch_set
*/
const std::map<std::string, std::u32string>& get_window_vars() { return window_vars; }
private:
void rebuild(std::map<std::string, lsnes_memorywatch_item>& nitems);
std::map<std::string, lsnes_memorywatch_item> items;
void rebuild(std::map<std::string, memwatch_item>& nitems);
std::map<std::string, memwatch_item> items;
std::map<std::string, std::u32string> window_vars;
std::map<std::string, bool> used_memorywatches;
void erase_unused_watches();

View file

@ -98,7 +98,7 @@ namespace
void dummy_target_fn(const std::string& n, const std::string& v) {}
}
lsnes_memorywatch_printer::lsnes_memorywatch_printer()
memwatch_printer::memwatch_printer()
{
position = PC_MEMORYWATCH;
cond_enable = false;
@ -111,7 +111,7 @@ lsnes_memorywatch_printer::lsnes_memorywatch_printer()
onscreen_halo_color = 0;
}
JSON::node lsnes_memorywatch_printer::serialize()
JSON::node memwatch_printer::serialize()
{
JSON::node ndata(JSON::object);
switch(position) {
@ -134,7 +134,7 @@ JSON::node lsnes_memorywatch_printer::serialize()
return ndata;
}
void lsnes_memorywatch_printer::unserialize(const JSON::node& node)
void memwatch_printer::unserialize(const JSON::node& node)
{
std::string _position = json_string_default(node, "position", "");
if(_position == "disabled") position = PC_DISABLED;
@ -155,7 +155,7 @@ void lsnes_memorywatch_printer::unserialize(const JSON::node& node)
onscreen_halo_color = json_signed_default(node, "onscreen_halo_color", false);
}
gcroot_pointer<memorywatch_item_printer> lsnes_memorywatch_printer::get_printer_obj(
gcroot_pointer<memorywatch_item_printer> memwatch_printer::get_printer_obj(
std::function<gcroot_pointer<mathexpr>(const std::string& n)> vars)
{
gcroot_pointer<memorywatch_item_printer> ptr;
@ -220,7 +220,7 @@ gcroot_pointer<memorywatch_item_printer> lsnes_memorywatch_printer::get_printer_
return ptr;
}
lsnes_memorywatch_item::lsnes_memorywatch_item()
memwatch_item::memwatch_item()
{
bytes = 0;
signed_flag = false;
@ -232,7 +232,7 @@ lsnes_memorywatch_item::lsnes_memorywatch_item()
mspace = &lsnes_instance.memory;
}
JSON::node lsnes_memorywatch_item::serialize()
JSON::node memwatch_item::serialize()
{
JSON::node ndata(JSON::object);
ndata["printer"] = printer.serialize();
@ -248,12 +248,12 @@ JSON::node lsnes_memorywatch_item::serialize()
return ndata;
}
void lsnes_memorywatch_item::unserialize(const JSON::node& node)
void memwatch_item::unserialize(const JSON::node& node)
{
if(node.type_of("printer") == JSON::object)
printer.unserialize(node["printer"]);
else
printer = lsnes_memorywatch_printer();
printer = memwatch_printer();
expr = json_string_default(node, "expr", "0");
format = json_string_default(node, "format", "");
bytes = json_unsigned_default(node, "bytes", 0);
@ -265,7 +265,7 @@ void lsnes_memorywatch_item::unserialize(const JSON::node& node)
addr_size = json_unsigned_default(node, "addr_size", 0);
}
memorywatch_memread_oper* lsnes_memorywatch_item::get_memread_oper()
memorywatch_memread_oper* memwatch_item::get_memread_oper()
{
if(!bytes)
return NULL;
@ -281,7 +281,7 @@ memorywatch_memread_oper* lsnes_memorywatch_item::get_memread_oper()
return o;
}
void lsnes_memorywatch_item::compatiblity_unserialize(const std::string& item)
void memwatch_item::compatiblity_unserialize(const std::string& item)
{
regex_results r;
if(!(r = regex("C0x([0-9A-Fa-f]{1,16})z([bBwWoOdDqQfF])(H([0-9A-Ga-g]))?", item)))
@ -330,7 +330,7 @@ void lsnes_memorywatch_item::compatiblity_unserialize(const std::string& item)
expr = (stringfmt() << "0x" << std::hex << addr).str();
scale_div = 1;
mspace = &lsnes_instance.memory;
printer.position = lsnes_memorywatch_printer::PC_MEMORYWATCH;
printer.position = memwatch_printer::PC_MEMORYWATCH;
printer.cond_enable = false;
printer.enabled = "true";
printer.onscreen_xpos = "0";
@ -345,7 +345,7 @@ void lsnes_memorywatch_item::compatiblity_unserialize(const std::string& item)
printer.onscreen_halo_color = 0;
}
std::set<std::string> lsnes_memorywatch_set::enumerate()
std::set<std::string> memwatch_set::enumerate()
{
std::set<std::string> r;
for(auto& i : items)
@ -353,9 +353,9 @@ std::set<std::string> lsnes_memorywatch_set::enumerate()
return r;
}
void lsnes_memorywatch_set::clear(const std::string& name)
void memwatch_set::clear(const std::string& name)
{
std::map<std::string, lsnes_memorywatch_item> nitems = items;
std::map<std::string, memwatch_item> nitems = items;
nitems.erase(name);
rebuild(nitems);
std::swap(items, nitems);
@ -367,9 +367,9 @@ void lsnes_memorywatch_set::clear(const std::string& name)
redraw_framebuffer();
}
void lsnes_memorywatch_set::set(const std::string& name, const std::string& item)
void memwatch_set::set(const std::string& name, const std::string& item)
{
lsnes_memorywatch_item _item;
memwatch_item _item;
if(item != "" && item[0] != '{') {
//Compatiblity.
try {
@ -383,14 +383,14 @@ void lsnes_memorywatch_set::set(const std::string& name, const std::string& item
set(name, _item);
}
lsnes_memorywatch_item& lsnes_memorywatch_set::get(const std::string& name)
memwatch_item& memwatch_set::get(const std::string& name)
{
if(!items.count(name))
throw std::runtime_error("No such memory watch named '" + name + "'");
return items[name];
}
std::string lsnes_memorywatch_set::get_string(const std::string& name, JSON::printer* printer)
std::string memwatch_set::get_string(const std::string& name, JSON::printer* printer)
{
auto& x = get(name);
auto y = x.serialize();
@ -398,7 +398,7 @@ std::string lsnes_memorywatch_set::get_string(const std::string& name, JSON::pri
return z;
}
void lsnes_memorywatch_set::watch(struct framebuffer::queue& rq)
void memwatch_set::watch(struct framebuffer::queue& rq)
{
//Set framebuffer for all FB watches.
watch_set.foreach([&rq](memorywatch_item& i) {
@ -410,9 +410,9 @@ void lsnes_memorywatch_set::watch(struct framebuffer::queue& rq)
erase_unused_watches();
}
bool lsnes_memorywatch_set::rename(const std::string& oldname, const std::string& newname)
bool memwatch_set::rename(const std::string& oldname, const std::string& newname)
{
std::map<std::string, lsnes_memorywatch_item> nitems = items;
std::map<std::string, memwatch_item> nitems = items;
if(nitems.count(newname))
return false;
if(!nitems.count(oldname))
@ -425,9 +425,9 @@ bool lsnes_memorywatch_set::rename(const std::string& oldname, const std::string
return true;
}
void lsnes_memorywatch_set::set(const std::string& name, lsnes_memorywatch_item& item)
void memwatch_set::set(const std::string& name, memwatch_item& item)
{
std::map<std::string, lsnes_memorywatch_item> nitems = items;
std::map<std::string, memwatch_item> nitems = items;
nitems[name] = item;
rebuild(nitems);
std::swap(items, nitems);
@ -439,14 +439,14 @@ void lsnes_memorywatch_set::set(const std::string& name, lsnes_memorywatch_item&
redraw_framebuffer();
}
std::string lsnes_memorywatch_set::get_value(const std::string& name)
std::string memwatch_set::get_value(const std::string& name)
{
return watch_set.get(name).get_value();
}
void lsnes_memorywatch_set::set_multi(std::list<std::pair<std::string, lsnes_memorywatch_item>>& list)
void memwatch_set::set_multi(std::list<std::pair<std::string, memwatch_item>>& list)
{
std::map<std::string, lsnes_memorywatch_item> nitems = items;
std::map<std::string, memwatch_item> nitems = items;
for(auto& i : list)
nitems[i.first] = i.second;
rebuild(nitems);
@ -460,20 +460,20 @@ void lsnes_memorywatch_set::set_multi(std::list<std::pair<std::string, lsnes_mem
redraw_framebuffer();
}
void lsnes_memorywatch_set::set_multi(std::list<std::pair<std::string, std::string>>& list)
void memwatch_set::set_multi(std::list<std::pair<std::string, std::string>>& list)
{
std::list<std::pair<std::string, lsnes_memorywatch_item>> _list;
std::list<std::pair<std::string, memwatch_item>> _list;
for(auto& i: list) {
lsnes_memorywatch_item it;
memwatch_item it;
it.unserialize(JSON::node(i.second));
_list.push_back(std::make_pair(i.first, it));
}
set_multi(_list);
}
void lsnes_memorywatch_set::clear_multi(const std::set<std::string>& names)
void memwatch_set::clear_multi(const std::set<std::string>& names)
{
std::map<std::string, lsnes_memorywatch_item> nitems = items;
std::map<std::string, memwatch_item> nitems = items;
for(auto& i : names)
nitems.erase(i);
rebuild(nitems);
@ -487,7 +487,7 @@ void lsnes_memorywatch_set::clear_multi(const std::set<std::string>& names)
redraw_framebuffer();
}
void lsnes_memorywatch_set::rebuild(std::map<std::string, lsnes_memorywatch_item>& nitems)
void memwatch_set::rebuild(std::map<std::string, memwatch_item>& nitems)
{
{
memorywatch_set new_set;
@ -541,13 +541,13 @@ void lsnes_memorywatch_set::rebuild(std::map<std::string, lsnes_memorywatch_item
garbage_collectable::do_gc();
}
void lsnes_memorywatch_set::memorywatch_output(const std::string& name, const std::string& value)
void memwatch_set::memorywatch_output(const std::string& name, const std::string& value)
{
used_memorywatches[name] = true;
window_vars[name] = utf8::to32(value);
}
void lsnes_memorywatch_set::erase_unused_watches()
void memwatch_set::erase_unused_watches()
{
for(auto& i : used_memorywatches) {
if(!i.second)
@ -555,5 +555,3 @@ void lsnes_memorywatch_set::erase_unused_watches()
i.second = false;
}
}
lsnes_memorywatch_set lsnes_memorywatch;

View file

@ -502,7 +502,7 @@ public:
<< "Enter name for watch at 0x" << std::hex << addr << ":").str());
if(n == "")
return;
lsnes_memorywatch_item e;
memwatch_item e;
e.expr = (stringfmt() << addr).str();
e.format = datatypes[curtype].format;
e.bytes = datatypes[curtype].len;

View file

@ -123,11 +123,11 @@ public:
void on_cancel(wxCommandEvent& e);
void enable_condenable2(wxCommandEvent& e);
private:
void enable_for_pos(lsnes_memorywatch_printer::position_category p);
void enable_for_pos(memwatch_printer::position_category p);
void enable_for_addr(bool is_addr);
void enable_for_vma(bool free, uint64_t _base, uint64_t _size);
void enable_condenable();
lsnes_memorywatch_printer::position_category get_poscategory();
memwatch_printer::position_category get_poscategory();
label_control<wxComboBox> type;
label_control<wxTextCtrl> expr;
label_control<wxTextCtrl> format;
@ -299,7 +299,7 @@ wxeditor_memorywatch::wxeditor_memorywatch(wxWindow* parent, const std::string&
this);
top_s->Add(s12, 0, wxGROW);
lsnes_memorywatch_item it;
memwatch_item it;
bool had_it = false;
try {
it = lsnes_instance.mwatch.get(name);
@ -320,9 +320,9 @@ wxeditor_memorywatch::wxeditor_memorywatch(wxWindow* parent, const std::string&
endianess->SetSelection(it.endianess + 1);
addrbase->SetValue(towxstring(hex::to<uint64_t>(it.addr_base)));
addrsize->SetValue(towxstring(hex::to<uint64_t>(it.addr_size)));
if(it.printer.position == lsnes_memorywatch_printer::PC_DISABLED) position->SetSelection(0);
if(it.printer.position == lsnes_memorywatch_printer::PC_MEMORYWATCH) position->SetSelection(1);
if(it.printer.position == lsnes_memorywatch_printer::PC_ONSCREEN) position->SetSelection(2);
if(it.printer.position == memwatch_printer::PC_DISABLED) position->SetSelection(0);
if(it.printer.position == memwatch_printer::PC_MEMORYWATCH) position->SetSelection(1);
if(it.printer.position == memwatch_printer::PC_ONSCREEN) position->SetSelection(2);
switch(it.bytes) {
case 0: type->SetSelection(0); break;
case 1: type->SetSelection(it.signed_flag ? 1 : 2); break;
@ -353,36 +353,36 @@ bool wxeditor_memorywatch::ShouldPreventAppExit() const
return false;
}
lsnes_memorywatch_printer::position_category wxeditor_memorywatch::get_poscategory()
memwatch_printer::position_category wxeditor_memorywatch::get_poscategory()
{
if(position->GetSelection() == 0) return lsnes_memorywatch_printer::PC_DISABLED;
if(position->GetSelection() == 1) return lsnes_memorywatch_printer::PC_MEMORYWATCH;
if(position->GetSelection() == 2) return lsnes_memorywatch_printer::PC_ONSCREEN;
return lsnes_memorywatch_printer::PC_DISABLED; //NOTREACHED.
if(position->GetSelection() == 0) return memwatch_printer::PC_DISABLED;
if(position->GetSelection() == 1) return memwatch_printer::PC_MEMORYWATCH;
if(position->GetSelection() == 2) return memwatch_printer::PC_ONSCREEN;
return memwatch_printer::PC_DISABLED; //NOTREACHED.
}
void wxeditor_memorywatch::enable_for_pos(lsnes_memorywatch_printer::position_category p)
void wxeditor_memorywatch::enable_for_pos(memwatch_printer::position_category p)
{
bool full_disable = (p == lsnes_memorywatch_printer::PC_DISABLED);
bool full_disable = (p == memwatch_printer::PC_DISABLED);
cond_enable->Enable(!full_disable);
enabled->Enable(cond_enable->GetValue() && !full_disable);
xpos.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
ypos.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
alt_origin_x->Enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
alt_origin_y->Enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
cliprange_x->Enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
cliprange_y->Enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
font.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
font_sel->Enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
fg_color.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
bg_color.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
halo_color.enable(p == lsnes_memorywatch_printer::PC_ONSCREEN);
xpos.enable(p == memwatch_printer::PC_ONSCREEN);
ypos.enable(p == memwatch_printer::PC_ONSCREEN);
alt_origin_x->Enable(p == memwatch_printer::PC_ONSCREEN);
alt_origin_y->Enable(p == memwatch_printer::PC_ONSCREEN);
cliprange_x->Enable(p == memwatch_printer::PC_ONSCREEN);
cliprange_y->Enable(p == memwatch_printer::PC_ONSCREEN);
font.enable(p == memwatch_printer::PC_ONSCREEN);
font_sel->Enable(p == memwatch_printer::PC_ONSCREEN);
fg_color.enable(p == memwatch_printer::PC_ONSCREEN);
bg_color.enable(p == memwatch_printer::PC_ONSCREEN);
halo_color.enable(p == memwatch_printer::PC_ONSCREEN);
}
void wxeditor_memorywatch::enable_condenable()
{
lsnes_memorywatch_printer::position_category p = get_poscategory();
bool full_disable = (p == lsnes_memorywatch_printer::PC_DISABLED);
memwatch_printer::position_category p = get_poscategory();
bool full_disable = (p == memwatch_printer::PC_DISABLED);
enabled->Enable(cond_enable->GetValue() && !full_disable);
}
@ -450,7 +450,7 @@ void wxeditor_memorywatch::on_fontsel(wxCommandEvent& e)
void wxeditor_memorywatch::on_ok(wxCommandEvent& e)
{
lsnes_memorywatch_item it;
memwatch_item it;
it.expr = tostdstring(expr->GetValue());
it.format = tostdstring(format->GetValue());
it.printer.cond_enable = cond_enable->GetValue();
@ -471,10 +471,10 @@ void wxeditor_memorywatch::on_ok(wxCommandEvent& e)
wxICON_EXCLAMATION);
return;
}
if(position->GetSelection() == 0) it.printer.position = lsnes_memorywatch_printer::PC_DISABLED;
else if(position->GetSelection() == 1) it.printer.position = lsnes_memorywatch_printer::PC_MEMORYWATCH;
else if(position->GetSelection() == 2) it.printer.position = lsnes_memorywatch_printer::PC_ONSCREEN;
else it.printer.position = lsnes_memorywatch_printer::PC_MEMORYWATCH;
if(position->GetSelection() == 0) it.printer.position = memwatch_printer::PC_DISABLED;
else if(position->GetSelection() == 1) it.printer.position = memwatch_printer::PC_MEMORYWATCH;
else if(position->GetSelection() == 2) it.printer.position = memwatch_printer::PC_ONSCREEN;
else it.printer.position = memwatch_printer::PC_MEMORYWATCH;
it.signed_flag = false;
it.float_flag = false;
switch(type->GetSelection()) {

View file

@ -1043,7 +1043,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
<< "Enter name for watch at 0x" << std::hex << addr << ":").str());
if(n == "")
continue;
lsnes_memorywatch_item e;
memwatch_item e;
e.expr = (stringfmt() << addr).str();
bool is_hex = hexmode2->GetValue();
e.bytes = watch_properties[typecode].len;