Replace std::string with custom string class

This commit is contained in:
Ilari Liusvaara 2015-05-30 18:25:40 +03:00
parent 80867950f3
commit 7929100be0
172 changed files with 2671 additions and 2043 deletions

View file

@ -9,6 +9,7 @@
#include "library/framebuffer.hpp"
#include "library/dispatch.hpp"
#include "library/threads.hpp"
#include "library/text.hpp"
class master_dumper;
class dumper_factory_base;
@ -40,7 +41,7 @@ public:
* Parameter id: The ID of dumper.
* Throws std::bad_alloc: Not enough memory.
*/
dumper_factory_base(const std::string& id) throw(std::bad_alloc);
dumper_factory_base(const text& id) throw(std::bad_alloc);
/**
* Unregister a dumper.
*/
@ -50,7 +51,7 @@ public:
*
* Returns: The id.
*/
const std::string& id() throw();
const text& id() throw();
/**
* Get set of all dumpers.
*
@ -64,28 +65,28 @@ public:
* Returns: List of all valid submodes. Empty list means this dumper has no submodes.
* Throws std::bad_alloc: Not enough memory.
*/
virtual std::set<std::string> list_submodes() throw(std::bad_alloc) = 0;
virtual std::set<text> list_submodes() throw(std::bad_alloc) = 0;
/**
* Get mode details
*
* parameter mode: The submode.
* Returns: Mode details flags
*/
virtual unsigned mode_details(const std::string& mode) throw() = 0;
virtual unsigned mode_details(const text& mode) throw() = 0;
/**
* Get mode extensions. Only called if mode details specifies that output is a single file.
*
* parameter mode: The submode.
* Returns: Mode extension
*/
virtual std::string mode_extension(const std::string& mode) throw() = 0;
virtual text mode_extension(const text& mode) throw() = 0;
/**
* Get human-readable name for this dumper.
*
* Returns: The name.
* Throws std::bad_alloc: Not enough memory.
*/
virtual std::string name() throw(std::bad_alloc) = 0;
virtual text name() throw(std::bad_alloc) = 0;
/**
* Get human-readable name for submode.
*
@ -93,7 +94,7 @@ public:
* Returns: The name.
* Throws std::bad_alloc: Not enough memory.
*/
virtual std::string modename(const std::string& mode) throw(std::bad_alloc) = 0;
virtual text modename(const text& mode) throw(std::bad_alloc) = 0;
/**
* Start dump.
*
@ -103,7 +104,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Can't start dump.
*/
virtual dumper_base* start(master_dumper& _mdumper, const std::string& mode, const std::string& targetname)
virtual dumper_base* start(master_dumper& _mdumper, const text& mode, const text& targetname)
throw(std::bad_alloc, std::runtime_error) = 0;
/**
* Is hidden?
@ -126,7 +127,7 @@ public:
*/
static void run_notify();
private:
std::string d_id;
text d_id;
};
class master_dumper
@ -145,7 +146,7 @@ public:
/**
* Game name.
*/
std::string gamename;
text gamename;
/**
* Run length in seconds.
*/
@ -153,12 +154,12 @@ public:
/**
* Rerecord count (base 10 ASCII)
*/
std::string rerecords;
text rerecords;
/**
* Authors. The first components are real names, the second components are nicknames. Either (but not both) may be
* blank.
*/
std::vector<std::pair<std::string, std::string>> authors;
std::vector<std::pair<text, text>> authors;
/**
* Format human-redable representation of the length.
*
@ -166,7 +167,7 @@ public:
* Returns: The time formated.
* Throws std::bad_alloc: Not enough memory.
*/
std::string get_readable_time(unsigned digits) const throw(std::bad_alloc);
text get_readable_time(unsigned digits) const throw(std::bad_alloc);
/**
* Get number of authors.
*
@ -180,7 +181,7 @@ public:
* Returns: The short name.
* Throws std::bad_alloc: Not enough memory.
*/
std::string get_author_short(size_t idx) const throw(std::bad_alloc);
text get_author_short(size_t idx) const throw(std::bad_alloc);
/**
* Get long name of author (full name and nickname if present).
*
@ -188,7 +189,7 @@ public:
* Returns: The long name.
* Throws std::bad_alloc: Not enough memory.
*/
std::string get_author_long(size_t idx) const throw(std::bad_alloc);
text get_author_long(size_t idx) const throw(std::bad_alloc);
/**
* Get rerecord count as a number. If rerecord count is too high, returns the maximum representatible count.
*
@ -223,7 +224,7 @@ public:
/**
* Call start on dumper.
*/
dumper_base* start(dumper_factory_base& factory, const std::string& mode, const std::string& targetname)
dumper_base* start(dumper_factory_base& factory, const text& mode, const text& targetname)
throw(std::bad_alloc, std::runtime_error);
/**
* Add dumper update notifier object.

View file

@ -4,6 +4,7 @@
#include <stdexcept>
#include <string>
#include <map>
#include "library/text.hpp"
//All the following need to be implemented by the sound driver itself
struct _audioapi_driver
@ -13,9 +14,9 @@ struct _audioapi_driver
void (*quit)() throw();
void (*enable)(bool enable);
bool (*initialized)();
void (*set_device)(const std::string& pdev, const std::string& rdev);
std::string (*get_device)(bool rec);
std::map<std::string, std::string> (*get_devices)(bool rec);
void (*set_device)(const text& pdev, const text& rdev);
text (*get_device)(bool rec);
std::map<text, text> (*get_devices)(bool rec);
const char* (*name)();
};
@ -57,7 +58,7 @@ bool audioapi_driver_initialized();
* Parameter pdev: The new sound device (playback).
* Parameter rdev: The new sound device (recording)
*/
void audioapi_driver_set_device(const std::string& pdev, const std::string& rdev) throw(std::bad_alloc,
void audioapi_driver_set_device(const text& pdev, const text& rdev) throw(std::bad_alloc,
std::runtime_error);
/**
@ -65,14 +66,14 @@ void audioapi_driver_set_device(const std::string& pdev, const std::string& rdev
*
* Returns: The current sound device.
*/
std::string audioapi_driver_get_device(bool rec) throw(std::bad_alloc);
text audioapi_driver_get_device(bool rec) throw(std::bad_alloc);
/**
* Get available sound devices (playback).
*
* Returns: The map of devices. Keyed by name of the device, values are human-readable names for devices.
*/
std::map<std::string, std::string> audioapi_driver_get_devices(bool rec) throw(std::bad_alloc);
std::map<text, text> audioapi_driver_get_devices(bool rec) throw(std::bad_alloc);
/**
* Identification for sound plugin.

View file

@ -2,6 +2,7 @@
#define _command__hpp__included__
#include "library/command.hpp"
#include "library/text.hpp"
#include "library/threads.hpp"
#include <stdexcept>
#include <string>
@ -25,7 +26,7 @@ private:
keyboard::mapper& mapper;
command::group& command;
threads::lock mut;
std::map<std::string, keyboard::invbind*> alias_binds;
std::map<text, keyboard::invbind*> alias_binds;
};
#endif

View file

@ -5,6 +5,7 @@
#include <map>
#include "library/dispatch.hpp"
#include "library/command.hpp"
#include "library/text.hpp"
struct project_info;
struct controller_state;
@ -24,9 +25,9 @@ class button_mapping
public:
struct controller_bind
{
std::string cclass;
text cclass;
unsigned number;
std::string name;
text name;
int mode; //0 => Button, 1 => Axis pair, 2 => Single axis.
bool xrel;
bool yrel;
@ -44,7 +45,7 @@ public:
};
struct controller_triple
{
std::string cclass;
text cclass;
unsigned port;
unsigned controller;
bool operator<(const struct controller_triple& t) const throw()
@ -94,32 +95,32 @@ public:
/**
* Lookup button by name.
*/
std::pair<int, int> byname(const std::string& name);
std::pair<int, int> byname(const text& name);
/**
* Map of button keys.
*/
std::map<std::string, std::string> button_keys;
std::map<text, text> button_keys;
private:
void do_analog_action(const std::string& a);
void do_autofire_action(const std::string& a, int mode);
void do_action(const std::string& name, short state, int mode);
void do_analog_action(const text& a);
void do_autofire_action(const text& a, int mode);
void do_action(const text& name, short state, int mode);
void promote_key(keyboard::ctrlrkey& k);
void add_button(const std::string& name, const controller_bind& binding);
void add_button(const text& name, const controller_bind& binding);
void process_controller(portctrl::controller& controller, unsigned number);
void process_controller(std::map<std::string, unsigned>& allocated,
void process_controller(std::map<text, unsigned>& allocated,
std::map<controller_triple, unsigned>& assigned, portctrl::controller& controller, unsigned port,
unsigned number_in_port);
void process_port(std::map<std::string, unsigned>& allocated,
void process_port(std::map<text, unsigned>& allocated,
std::map<controller_triple, unsigned>& assigned, unsigned port, portctrl::type& ptype);
void init();
bool check_button_active(const std::string& name);
void do_button_action(const std::string& name, short newstate, int mode);
void send_analog(const std::string& name, int32_t x, int32_t y);
std::map<std::string, keyboard::invbind*> macro_binds;
std::map<std::string, keyboard::invbind*> macro_binds2;
std::map<std::string, controller_bind> all_buttons;
std::map<std::string, active_bind> active_buttons;
std::map<std::string, keyboard::ctrlrkey*> added_keys;
bool check_button_active(const text& name);
void do_button_action(const text& name, short newstate, int mode);
void send_analog(const text& name, int32_t x, int32_t y);
std::map<text, keyboard::invbind*> macro_binds;
std::map<text, keyboard::invbind*> macro_binds2;
std::map<text, controller_bind> all_buttons;
std::map<text, active_bind> active_buttons;
std::map<text, keyboard::ctrlrkey*> added_keys;
std::set<core_core*> cores_done;
controller_state& controls;
keyboard::mapper& mapper;
@ -129,15 +130,15 @@ private:
lua_state& lua2;
command::group& cmd;
struct dispatch::target<> ncore;
command::_fnptr<const std::string&> button_p;
command::_fnptr<const std::string&> button_r;
command::_fnptr<const std::string&> button_h;
command::_fnptr<const std::string&> button_t;
command::_fnptr<const std::string&> button_d;
command::_fnptr<const std::string&> button_ap;
command::_fnptr<const std::string&> button_ar;
command::_fnptr<const std::string&> button_at;
command::_fnptr<const std::string&> button_a;
command::_fnptr<const text&> button_p;
command::_fnptr<const text&> button_r;
command::_fnptr<const text&> button_h;
command::_fnptr<const text&> button_t;
command::_fnptr<const text&> button_d;
command::_fnptr<const text&> button_ap;
command::_fnptr<const text&> button_ar;
command::_fnptr<const text&> button_at;
command::_fnptr<const text&> button_a;
};

View file

@ -18,6 +18,7 @@
#include "library/portctrl-data.hpp"
#include "library/command.hpp"
#include "library/threads.hpp"
#include "library/text.hpp"
class project_state;
class movie_logic;
@ -200,18 +201,18 @@ public:
* TODO: Document.
*/
bool is_present(unsigned port, unsigned controller) throw();
void erase_macro(const std::string& macro);
std::set<std::string> enumerate_macro();
portctrl::macro& get_macro(const std::string& macro);
void set_macro(const std::string& macro, const portctrl::macro& m);
void erase_macro(const text& macro);
std::set<text> enumerate_macro();
portctrl::macro& get_macro(const text& macro);
void set_macro(const text& macro, const portctrl::macro& m);
void apply_macro(portctrl::frame& f);
void rename_macro(const std::string& old, const std::string& newn);
std::set<std::string> active_macro_set();
void rename_macro(const text& old, const text& newn);
std::set<text> active_macro_set();
void advance_macros();
std::map<std::string, uint64_t> get_macro_frames();
void set_macro_frames(const std::map<std::string, uint64_t>& f);
std::map<text, uint64_t> get_macro_frames();
void set_macro_frames(const std::map<text, uint64_t>& f);
private:
void do_macro(const std::string& a, int mode);
void do_macro(const text& a, int mode);
struct autofire_info
{
uint64_t first_frame;
@ -233,7 +234,7 @@ private:
std::map<unsigned, tasinput_info> _tasinput;
bool tasinput_enaged;
portctrl::frame _committed;
std::map<std::string, portctrl::macro> all_macros;
std::map<text, portctrl::macro> all_macros;
std::list<std::pair<uint64_t, portctrl::macro*>> active_macros;
threads::lock macro_lock;
project_state& project;
@ -242,9 +243,9 @@ private:
emulator_dispatch& edispatch;
status_updater& supdater;
command::group& cmd;
command::_fnptr<const std::string&> macro_p;
command::_fnptr<const std::string&> macro_r;
command::_fnptr<const std::string&> macro_t;
command::_fnptr<const text&> macro_p;
command::_fnptr<const text&> macro_r;
command::_fnptr<const text&> macro_t;
};
#endif

View file

@ -6,6 +6,7 @@
#include <cstdint>
#include "library/command.hpp"
#include "library/dispatch.hpp"
#include "library/text.hpp"
class emulator_dispatch;
class loaded_rom;
@ -131,7 +132,7 @@ public:
/**
* Set tracelog file.
*/
void tracelog(uint64_t cpu, const std::string& filename);
void tracelog(uint64_t cpu, const text& filename);
/**
* Tracelogging on?
*/
@ -157,8 +158,8 @@ public:
std::map<uint64_t, cb_list> frame_cb;
private:
void do_showhooks();
void do_genevent(const std::string& a);
void do_tracecmd(const std::string& a);
void do_genevent(const text& a);
void do_tracecmd(const text& a);
cb_list dummy_cb; //Always empty.
uint64_t xmask = 1;
std::function<void()> tracelog_change_cb;
@ -170,13 +171,13 @@ private:
bool corechange_r = false;
bool requesting_break = false;
command::_fnptr<> showhooks;
command::_fnptr<const std::string&> genevent;
command::_fnptr<const std::string&> tracecmd;
command::_fnptr<const text&> genevent;
command::_fnptr<const text&> tracecmd;
struct tracelog_file : public callback_base
{
std::ofstream stream;
std::string full_filename;
text full_filename;
unsigned refcnt;
tracelog_file(debug_context& parent);
~tracelog_file();

View file

@ -18,7 +18,7 @@ struct emulator_dispatch
dispatch::source<unsigned, unsigned, unsigned, bool> autohold_update;
dispatch::source<unsigned, unsigned, unsigned, unsigned, unsigned> autofire_update;
dispatch::source<> close;
dispatch::source<std::pair<std::string, std::string>> sound_change;
dispatch::source<std::pair<text, text>> sound_change;
dispatch::source<> screen_update;
dispatch::source<> status_update;
dispatch::source<bool> sound_unmute;

View file

@ -41,29 +41,29 @@ struct _lsnes_status
unsigned speed; //Speed%
bool saveslot_valid; //Save slot number/info valid.
uint64_t saveslot; //Save slot number.
std::u32string slotinfo; //Save slot info.
text slotinfo; //Save slot info.
bool branch_valid; //Branch info valid?
std::u32string branch; //Current branch.
text branch; //Current branch.
bool mbranch_valid; //Movie branch info valid?
std::u32string mbranch; //Current movie branch.
std::u32string macros; //Currently active macros.
text mbranch; //Current movie branch.
text macros; //Currently active macros.
int pause; //Pause mode.
char mode; //Movie mode: C:Corrupt, R:Readwrite, P:Readonly, F:Finished.
bool rtc_valid; //RTC time valid?
std::u32string rtc; //RTC time.
std::vector<std::u32string> inputs; //Input display.
std::map<std::string, std::u32string> mvars; //Memory watches.
std::map<std::string, std::u32string> lvars; //Lua variables.
text rtc; //RTC time.
std::vector<text> inputs; //Input display.
std::map<text, text> mvars; //Memory watches.
std::map<text, text> lvars; //Lua variables.
};
struct slotinfo_cache
{
slotinfo_cache(movie_logic& _mlogic, command::group& _cmd);
std::string get(const std::string& _filename);
void flush(const std::string& _filename);
text get(const text& _filename);
void flush(const text& _filename);
void flush();
private:
std::map<std::string, std::string> cache;
std::map<text, text> cache;
movie_logic& mlogic;
command::group& cmd;
command::_fnptr<> flushcmd;

View file

@ -3,6 +3,7 @@
#include "library/threads.hpp"
#include "library/httpreq.hpp"
#include "library/text.hpp"
#include "library/urirewrite.hpp"
#include <string>
#include <list>
@ -13,8 +14,8 @@ class loaded_rom;
struct file_download
{
//Variables.
std::string url;
std::string target_slot;
text url;
text target_slot;
//Ctor
file_download();
~file_download();
@ -23,15 +24,15 @@ struct file_download
void cancel();
//Status.
volatile bool finished; //This signals download finishing, call finish().
std::string errormsg;
text errormsg;
http_async_request req;
std::string statusmsg();
text statusmsg();
threads::cv cond;
threads::lock m;
//Internal.
void _do_async(loaded_rom& rom);
std::string tempname;
std::string tempname2;
text tempname;
text tempname2;
};
extern urirewrite::rewriter lsnes_uri_rewrite;

View file

@ -4,6 +4,7 @@
#include "library/threads.hpp"
#include "library/httpreq.hpp"
#include "library/httpauth.hpp"
#include "library/text.hpp"
#include <string>
#include <list>
#include <vector>
@ -11,12 +12,12 @@
struct file_upload
{
//Variables.
std::string base_url;
text base_url;
std::vector<char> content;
std::string filename;
std::string title;
std::string description;
std::string gamename;
text filename;
text title;
text description;
text gamename;
bool hidden;
//Ctor
file_upload();
@ -26,17 +27,17 @@ struct file_upload
void _do_async();
void cancel();
//Status.
std::list<std::string> get_messages();
std::list<text> get_messages();
int get_progress_ppm(); //-1 => No progress.
volatile bool finished;
volatile bool success;
std::string final_url;
text final_url;
//Vars.
dh25519_http_auth* dh25519;
http_async_request* req;
std::list<std::string> msgs;
std::list<text> msgs;
threads::lock m;
void add_msg(const std::string& msg);
void add_msg(const text& msg);
};
void get_dh25519_pubkey(uint8_t* out);

View file

@ -73,7 +73,7 @@ public:
/**
* Take a screenshot to specified file.
*/
void take_screenshot(const std::string& file) throw(std::bad_alloc, std::runtime_error);
void take_screenshot(const text& file) throw(std::bad_alloc, std::runtime_error);
/**
* Kill pending requests associated with object.
*/

View file

@ -84,7 +84,7 @@ public:
*/
bool turboed;
private:
void set_speed_cmd(const std::string& args);
void set_speed_cmd(const text& args);
uint64_t get_time(uint64_t curtime, bool update);
double get_realized_fps();
void add_frame(uint64_t linear_time);
@ -102,7 +102,7 @@ private:
command::_fnptr<> turbo_p;
command::_fnptr<> turbo_r;
command::_fnptr<> turbo_t;
command::_fnptr<const std::string&> setspeed_t;
command::_fnptr<const text&> setspeed_t;
};
#endif

View file

@ -38,14 +38,14 @@ public:
bool collection_loaded();
std::list<playback_stream_info> get_stream_info();
void play_stream(uint64_t id);
void export_stream(uint64_t id, const std::string& filename, external_stream_format fmt);
uint64_t import_stream(uint64_t ts, const std::string& filename, external_stream_format fmt);
void export_stream(uint64_t id, const text& filename, external_stream_format fmt);
uint64_t import_stream(uint64_t ts, const text& filename, external_stream_format fmt);
void delete_stream(uint64_t id);
void export_superstream(const std::string& filename);
void load_collection(const std::string& filename);
void export_superstream(const text& filename);
void load_collection(const text& filename);
void unload_collection();
void alter_timebase(uint64_t id, uint64_t ts);
uint64_t parse_timebase(const std::string& n);
uint64_t parse_timebase(const text& n);
double ts_seconds(uint64_t ts);
float get_gain(uint64_t id);
void set_gain(uint64_t id, float gain);

View file

@ -57,7 +57,7 @@ public:
*
* Throws std::runtime_exception: No slot selected.
*/
std::string get_slot_name();
text get_slot_name();
/**
* Set size of jukebox.
*
@ -73,14 +73,14 @@ public:
*/
void unset_update();
private:
void do_slotsel(const std::string& arg);
void do_slotsel(const text& arg);
settingvar::group& settings;
size_t current_slot;
size_t current_size;
std::function<void()> update;
save_jukebox_listener* listener;
command::group& cmd;
command::_fnptr<const std::string&> slotsel;
command::_fnptr<const text&> slotsel;
command::_fnptr<> cycleprev;
command::_fnptr<> cyclenext;
};

View file

@ -4,7 +4,7 @@
#include "library/loadlib.hpp"
void handle_post_loadlibrary();
void autoload_libraries(void(*on_error)(const std::string& libname, const std::string& err, bool system) = NULL);
void autoload_libraries(void(*on_error)(const text& libname, const text& err, bool system) = NULL);
void with_loaded_library(const loadlib::module& l);
bool with_unloaded_library(loadlib::module& l);

View file

@ -11,10 +11,10 @@
*/
void main_loop(struct loaded_rom& rom, struct moviefile& settings, bool load_has_to_succeed = false)
throw(std::bad_alloc, std::runtime_error);
std::vector<std::string> get_jukebox_names();
void set_jukebox_names(const std::vector<std::string>& newj);
std::vector<text> get_jukebox_names();
void set_jukebox_names(const std::vector<text>& newj);
void init_main_callbacks();
extern std::string msu1_base_path;
extern text msu1_base_path;
/**
* Signal that fast rewind operation is needed.
@ -25,7 +25,7 @@ extern std::string msu1_base_path;
void mainloop_signal_need_rewind(void* ptr);
void set_stop_at_frame(uint64_t frame = 0);
void switch_projects(const std::string& newproj);
void switch_projects(const text& newproj);
void close_rom();
void load_new_rom(const romload_request& req);
void reload_current_rom();

View file

@ -12,17 +12,17 @@ class movie_logic;
struct movie_branches
{
movie_branches(movie_logic& _mlogic, emulator_dispatch& _dispatch, status_updater& _supdater);
std::string name(const std::string& internal);
std::set<std::string> enumerate();
std::string get();
void set(const std::string& branch);
void _new(const std::string& branch, const std::string& from);
void rename(const std::string& oldn, const std::string& newn);
void _delete(const std::string& branch);
std::set<std::string> _movie_branches(const std::string& filename);
void import_branch(const std::string& filename, const std::string& ibranch, const std::string& branchname,
text name(const text& internal);
std::set<text> enumerate();
text get();
void set(const text& branch);
void _new(const text& branch, const text& from);
void rename(const text& oldn, const text& newn);
void _delete(const text& branch);
std::set<text> _movie_branches(const text& filename);
void import_branch(const text& filename, const text& ibranch, const text& branchname,
int mode);
void export_branch(const std::string& filename, const std::string& branchname, bool binary);
void export_branch(const text& filename, const text& branchname, bool binary);
private:
movie_logic& mlogic;
emulator_dispatch& edispatch;

View file

@ -34,7 +34,7 @@ struct memwatch_printer
* Get a printer object corresponding to this object.
*/
GC::pointer<memorywatch::item_printer> get_printer_obj(
std::function<GC::pointer<mathexpr::mathexpr>(const std::string& n)> vars);
std::function<GC::pointer<mathexpr::mathexpr>(const text& n)> vars);
//Fields.
enum position_category {
PC_DISABLED,
@ -42,14 +42,14 @@ struct memwatch_printer
PC_ONSCREEN
} position;
bool cond_enable; //Ignored for disabled.
std::string enabled; //Ignored for disabled.
std::string onscreen_xpos;
std::string onscreen_ypos;
text enabled; //Ignored for disabled.
text onscreen_xpos;
text onscreen_ypos;
bool onscreen_alt_origin_x;
bool onscreen_alt_origin_y;
bool onscreen_cliprange_x;
bool onscreen_cliprange_y;
std::string onscreen_font; //"" is system default.
text onscreen_font; //"" is system default.
int64_t onscreen_fg_color;
int64_t onscreen_bg_color;
int64_t onscreen_halo_color;
@ -81,11 +81,11 @@ struct memwatch_item
/**
* Translate compatiblity item.
*/
void compatiblity_unserialize(memory_space& memory, const std::string& item);
void compatiblity_unserialize(memory_space& memory, const text& item);
//Fields
memwatch_printer printer; //The printer.
std::string expr; //The main expression.
std::string format; //Format.
text expr; //The main expression.
text format; //Format.
unsigned bytes; //Number of bytes to read (0 => Not memory read operator).
bool signed_flag; //Is signed?
bool float_flag; //Is float?
@ -102,40 +102,40 @@ struct memwatch_set
/**
* Get the specified memory watch item.
*/
memwatch_item& get(const std::string& name);
memwatch_item& get(const text& name);
/**
* Get the specified memory watch item as JSON serialization.
*
* Parameter name: The item name.
* Parameter printer: JSON pretty-printer to use.
*/
std::string get_string(const std::string& name, JSON::printer* printer = NULL);
text get_string(const text& name, JSON::printer* printer = NULL);
/**
* Set the specified memory watch item. Fills the runtime variables.
*
* Parameter name: The name of the new item.
* Parameter item: The item to insert. Fields are shallow-copied.
*/
void set(const std::string& name, memwatch_item& item);
void set(const text& name, memwatch_item& item);
/**
* Set the specified memory watch item from JSON serialization. Fills the runtime variables.
*
* Parameter name: The name of the new item.
* Parameter item: The serialization of item to insert.
*/
void set(const std::string& name, const std::string& item);
void set(const text& name, const text& item);
/**
* Set multiple items at once.
*
* Parameter list: The list of items.
*/
void set_multi(std::list<std::pair<std::string, memwatch_item>>& list);
void set_multi(std::list<std::pair<text, memwatch_item>>& list);
/**
* Set multiple items at once from JSON descriptions.
*
* Parameter list: The list of items.
*/
void set_multi(std::list<std::pair<std::string, std::string>>& list);
void set_multi(std::list<std::pair<text, text>>& list);
/**
* Rename a memory watch item.
*
@ -143,27 +143,27 @@ struct memwatch_set
* Parameter newname: The new name.
* Returns: True on success, false if failed (new item already exists).
*/
bool rename(const std::string& oname, const std::string& newname);
bool rename(const text& oname, const text& newname);
/**
* Delete an item.
*
* Parameter name: The name of the item to delete.
*/
void clear(const std::string& name);
void clear(const text& name);
/**
* Delete multiple items.
*
* Parameter names: The names of the items to delete.
*/
void clear_multi(const std::set<std::string>& name);
void clear_multi(const std::set<text>& name);
/**
* Enumerate item names.
*/
std::set<std::string> enumerate();
std::set<text> enumerate();
/**
* Get value of specified memory watch as a string.
*/
std::string get_value(const std::string& name);
text get_value(const text& name);
/**
* Watch all the items.
*
@ -173,14 +173,14 @@ struct memwatch_set
/**
* Get memory watch vars that go to window.
*/
const std::map<std::string, std::u32string>& get_window_vars() { return window_vars; }
const std::map<text, text>& get_window_vars() { return window_vars; }
private:
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 rebuild(std::map<text, memwatch_item>& nitems);
std::map<text, memwatch_item> items;
std::map<text, text> window_vars;
std::map<text, bool> used_memorywatches;
void erase_unused_watches();
void watch_output(const std::string& name, const std::string& value);
void watch_output(const text& name, const text& value);
memorywatch::set watch_set;
memory_space& memory;
project_state& project;

View file

@ -20,7 +20,7 @@ void fatal_error() throw();
* \return The config directory path.
* \throw std::bad_alloc Not enough memory.
*/
std::string get_config_path() throw(std::bad_alloc);
text get_config_path() throw(std::bad_alloc);
/**
* \brief Panic on OOM.
@ -33,7 +33,7 @@ uint32_t gcd(uint32_t a, uint32_t b) throw();
/**
* Return hexadecimal representation of address
*/
std::string format_address(void* addr);
text format_address(void* addr);
/**
* Get state of running global ctors flag.
@ -47,16 +47,16 @@ void reached_main();
/**
* Clean up filename from dangerous chars
*/
std::string safe_filename(const std::string& str);
text safe_filename(const text& str);
/**
* Mangle some characters ()|/
*/
std::string mangle_name(const std::string& orig);
text mangle_name(const text& orig);
/**
* Return a new temporary file. The file will be created.
*/
std::string get_temp_file();
text get_temp_file();
#endif

View file

@ -30,19 +30,18 @@
#define SAVE_STATE 0
#define SAVE_MOVIE 1
std::string resolve_relative_path(const std::string& path);
std::pair<std::string, std::string> split_author(const std::string& author) throw(std::bad_alloc,
std::runtime_error);
text resolve_relative_path(const text& path);
std::pair<text, text> split_author(const text& author) throw(std::bad_alloc, std::runtime_error);
void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc, std::runtime_error);
void do_save_movie(const std::string& filename, int binary) throw(std::bad_alloc, std::runtime_error);
void do_save_state(const text& filename, int binary) throw(std::bad_alloc, std::runtime_error);
void do_save_movie(const text& filename, int binary) throw(std::bad_alloc, std::runtime_error);
void do_load_rom() throw(std::bad_alloc, std::runtime_error);
void do_load_rewind() throw(std::bad_alloc, std::runtime_error);
void do_load_state(struct moviefile& _movie, int lmode, bool& used);
bool do_load_state(const std::string& filename, int lmode);
std::string translate_name_mprefix(std::string original, int& binary, int save);
bool do_load_state(const text& filename, int lmode);
text translate_name_mprefix(text original, int& binary, int save);
extern std::string last_save;
extern text last_save;
/**
* Restore the actual core state from quicksave. Only call in rewind callback.
@ -53,16 +52,16 @@ extern std::string last_save;
*/
void mainloop_restore_state(const dynamic_state& state);
std::string get_mprefix_for_project();
void set_mprefix_for_project(const std::string& pfx);
void set_mprefix_for_project(const std::string& prjid, const std::string& pfx);
text get_mprefix_for_project();
void set_mprefix_for_project(const text& pfx);
void set_mprefix_for_project(const text& prjid, const text& pfx);
class rrdata
{
public:
rrdata();
rrdata_set::instance operator()();
static std::string filename(const std::string& projectid);
static text filename(const text& projectid);
private:
bool init;
rrdata_set::instance next;

View file

@ -6,9 +6,9 @@
#define DEFAULT_RTC_SUBSECOND 0ULL
template<typename target>
static void moviefile_write_settings(target& w, const std::map<std::string, std::string>& settings,
core_setting_group& sgroup, std::function<void(target& w, const std::string& name,
const std::string& value)> writefn)
static void moviefile_write_settings(target& w, const std::map<text, text>& settings,
core_setting_group& sgroup, std::function<void(target& w, const text& name,
const text& value)> writefn)
{
for(auto i : settings) {
if(!sgroup.settings.count(i.first))
@ -21,40 +21,40 @@ static void moviefile_write_settings(target& w, const std::map<std::string, std:
struct moviefile_branch_extractor_text : public moviefile::branch_extractor
{
moviefile_branch_extractor_text(const std::string& filename);
moviefile_branch_extractor_text(const text& filename);
~moviefile_branch_extractor_text();
std::set<std::string> enumerate();
void read(const std::string& name, portctrl::frame_vector& v);
std::set<text> enumerate();
void read(const text& name, portctrl::frame_vector& v);
private:
zip::reader z;
};
struct moviefile_branch_extractor_binary : public moviefile::branch_extractor
{
moviefile_branch_extractor_binary(const std::string& filename);
moviefile_branch_extractor_binary(const text& filename);
~moviefile_branch_extractor_binary();
std::set<std::string> enumerate();
void read(const std::string& name, portctrl::frame_vector& v);
std::set<text> enumerate();
void read(const text& name, portctrl::frame_vector& v);
private:
int s;
};
struct moviefile_sram_extractor_text : public moviefile::sram_extractor
{
moviefile_sram_extractor_text(const std::string& filename);
moviefile_sram_extractor_text(const text& filename);
~moviefile_sram_extractor_text();
std::set<std::string> enumerate();
void read(const std::string& name, std::vector<char>& v);
std::set<text> enumerate();
void read(const text& name, std::vector<char>& v);
private:
zip::reader z;
};
struct moviefile_sram_extractor_binary : public moviefile::sram_extractor
{
moviefile_sram_extractor_binary(const std::string& filename);
moviefile_sram_extractor_binary(const text& filename);
~moviefile_sram_extractor_binary();
std::set<std::string> enumerate();
void read(const std::string& name, std::vector<char>& v);
std::set<text> enumerate();
void read(const text& name, std::vector<char>& v);
private:
int s;
};

View file

@ -10,6 +10,7 @@
#include "core/subtitles.hpp"
#include "interface/romtype.hpp"
#include "library/rrdata.hpp"
#include "library/text.hpp"
#include "library/zip.hpp"
class loaded_rom;
@ -26,7 +27,7 @@ struct dynamic_state
/**
* Contents of SRAM on time of savestate (if is_savestate is true).
*/
std::map<std::string, std::vector<char>> sram;
std::map<text, std::vector<char>> sram;
/**
* Core savestate (if is_savestate is true).
*/
@ -66,11 +67,11 @@ struct dynamic_state
/**
* Active macros at savestate.
*/
std::map<std::string, uint64_t> active_macros;
std::map<text, uint64_t> active_macros;
/**
* Clear the state to power-on defaults.
*/
void clear(int64_t sec, int64_t ssec, const std::map<std::string, std::vector<char>>& initsram);
void clear(int64_t sec, int64_t ssec, const std::map<text, std::vector<char>>& initsram);
/**
* Swap the dynamic state with another.
*/
@ -88,13 +89,13 @@ struct moviefile
struct brief_info
{
brief_info() { current_frame = 0; rerecords = 0; }
brief_info(const std::string& filename);
std::string sysregion;
std::string corename;
std::string projectid;
std::string hash[ROM_SLOT_COUNT];
std::string hashxml[ROM_SLOT_COUNT];
std::string hint[ROM_SLOT_COUNT];
brief_info(const text& filename);
text sysregion;
text corename;
text projectid;
text hash[ROM_SLOT_COUNT];
text hashxml[ROM_SLOT_COUNT];
text hint[ROM_SLOT_COUNT];
uint64_t current_frame;
uint64_t rerecords;
private:
@ -106,10 +107,10 @@ struct moviefile
*/
struct branch_extractor
{
branch_extractor(const std::string& filename);
branch_extractor(const text& filename);
virtual ~branch_extractor();
virtual std::set<std::string> enumerate() { return real->enumerate(); }
virtual void read(const std::string& name, portctrl::frame_vector& v) { real->read(name, v); }
virtual std::set<text> enumerate() { return real->enumerate(); }
virtual void read(const text& name, portctrl::frame_vector& v) { real->read(name, v); }
protected:
branch_extractor() { real = NULL; }
private:
@ -120,10 +121,10 @@ struct moviefile
*/
struct sram_extractor
{
sram_extractor(const std::string& filename);
sram_extractor(const text& filename);
virtual ~sram_extractor();
virtual std::set<std::string> enumerate() { return real->enumerate(); }
virtual void read(const std::string& name, std::vector<char>& v) { real->read(name, v); }
virtual std::set<text> enumerate() { return real->enumerate(); }
virtual void read(const text& name, std::vector<char>& v) { real->read(name, v); }
protected:
sram_extractor() { real = NULL; }
private:
@ -132,7 +133,7 @@ struct moviefile
/**
* Identify if file is movie/savestate file or not.
*/
static bool is_movie_or_savestate(const std::string& filename);
static bool is_movie_or_savestate(const text& filename);
/**
* This constructor construct movie structure with default settings.
*
@ -148,7 +149,7 @@ struct moviefile
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Can't load the movie file
*/
moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
moviefile(const text& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
/**
* Fill a stub movie with specified loaded ROM.
@ -158,7 +159,7 @@ struct moviefile
* Parameter rtc_sec: The RTC seconds value.
* Parameter rtc_subsec: The RTC subseconds value.
*/
moviefile(loaded_rom& rom, std::map<std::string, std::string>& c_settings, uint64_t rtc_sec,
moviefile(loaded_rom& rom, std::map<text, text>& c_settings, uint64_t rtc_sec,
uint64_t rtc_subsec);
/**
@ -171,7 +172,7 @@ struct moviefile
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Can't save the movie file.
*/
void save(const std::string& filename, unsigned compression, bool binary, rrdata_set& rrd, bool as_state)
void save(const text& filename, unsigned compression, bool binary, rrdata_set& rrd, bool as_state)
throw(std::bad_alloc, std::runtime_error);
/**
* Reads this movie structure and saves it to stream (uncompressed ZIP).
@ -188,23 +189,23 @@ struct moviefile
/**
* Settings.
*/
std::map<std::string, std::string> settings;
std::map<text, text> settings;
/**
* Emulator Core version string.
*/
std::string coreversion;
text coreversion;
/**
* Name of the game
*/
std::string gamename;
text gamename;
/**
* Project ID (used to identify if two movies are from the same project).
*/
std::string projectid;
text projectid;
/**
* Rerecord count (only saved).
*/
std::string rerecords;
text rerecords;
/**
* Rerecord count (memory saves only).
*/
@ -212,27 +213,27 @@ struct moviefile
/**
* SHA-256 of ROM (empty string if none).
*/
std::string romimg_sha256[ROM_SLOT_COUNT];
text romimg_sha256[ROM_SLOT_COUNT];
/**
* SHA-256 of ROM XML (empty string if none).
*/
std::string romxml_sha256[ROM_SLOT_COUNT];
text romxml_sha256[ROM_SLOT_COUNT];
/**
* ROM name hint (empty string if none).
*/
std::string namehint[ROM_SLOT_COUNT];
text namehint[ROM_SLOT_COUNT];
/**
* Authors of the run, first in each pair is full name, second is nickname.
*/
std::vector<std::pair<std::string, std::string>> authors;
std::vector<std::pair<text, text>> authors;
/**
* Contents of SRAM on time of initial powerup.
*/
std::map<std::string, std::vector<char>> movie_sram;
std::map<text, std::vector<char>> movie_sram;
/**
* Contents of RAM on time of initial powerup.
*/
std::map<std::string, std::vector<char>> ramcontent;
std::map<text, std::vector<char>> ramcontent;
/**
* Anchoring core savestate (if not empty).
*/
@ -248,7 +249,7 @@ struct moviefile
/**
* Branches.
*/
std::map<std::string, portctrl::frame_vector> branches;
std::map<text, portctrl::frame_vector> branches;
/**
* Movie starting RTC second.
*/
@ -268,7 +269,7 @@ struct moviefile
/**
* Subtitles.
*/
std::map<moviefile_subtiming, std::string> subtitles;
std::map<moviefile_subtiming, text> subtitles;
/**
* Dynamic state.
*/
@ -288,7 +289,7 @@ struct moviefile
/**
* Return reference to memory slot.
*/
static moviefile*& memref(const std::string& slot);
static moviefile*& memref(const text& slot);
/**
* Copy data.
@ -302,11 +303,11 @@ struct moviefile
/**
* Get name of current branch.
*/
const std::string& current_branch();
const text& current_branch();
/**
* Fork a branch.
*/
void fork_branch(const std::string& oldname, const std::string& newname);
void fork_branch(const text& oldname, const text& newname);
/**
* Fixup input pointer post-copy.
*/

View file

@ -32,7 +32,7 @@ public:
private:
void do_mt_fwd();
void do_mt_bw();
void do_mt_set(const std::string& args);
void do_mt_set(const text& args);
threads::lock mlock;
bool enabled;
std::map<std::pair<unsigned, unsigned>, state> controllerstate;
@ -44,7 +44,7 @@ private:
command::group& cmd;
command::_fnptr<> mt_f;
command::_fnptr<> mt_b;
command::_fnptr<const std::string&> mt_s;
command::_fnptr<const text&> mt_s;
};
#endif

View file

@ -8,6 +8,7 @@
#include "core/rom-small.hpp"
#include "library/command.hpp"
#include "library/json.hpp"
#include "library/text.hpp"
class voice_commentary;
class memwatch_set;
@ -24,49 +25,49 @@ struct project_branch_info
//Parent branch ID.
uint64_t pbid;
//Name.
std::string name;
text name;
};
//Information about project.
struct project_info
{
//Internal ID of the project.
std::string id;
text id;
//Name of the project.
std::string name;
text name;
//Bundle ROM used.
std::string rom;
text rom;
//ROMs used.
std::string roms[ROM_SLOT_COUNT];
text roms[ROM_SLOT_COUNT];
//Last savestate.
std::string last_save;
text last_save;
//Directory for save/load dialogs.
std::string directory;
text directory;
//Prefix for save/load dialogs.
std::string prefix;
text prefix;
//List of Lua scripts to run at startup.
std::list<std::string> luascripts;
std::list<text> luascripts;
//Memory watches.
std::map<std::string, std::string> watches;
std::map<text, text> watches;
//Macros.
std::map<std::string, JSON::node> macros;
std::map<text, JSON::node> macros;
//Branches.
std::map<uint64_t, project_branch_info> branches;
uint64_t active_branch;
uint64_t next_branch;
//Filename this was loaded from.
std::string filename;
text filename;
//Stub movie data.
std::string gametype;
std::map<std::string, std::string> settings;
std::string coreversion;
std::string gamename;
std::string projectid;
std::string romimg_sha256[ROM_SLOT_COUNT];
std::string romxml_sha256[ROM_SLOT_COUNT];
std::string namehint[ROM_SLOT_COUNT];
std::vector<std::pair<std::string, std::string>> authors;
std::map<std::string, std::vector<char>> movie_sram;
text gametype;
std::map<text, text> settings;
text coreversion;
text gamename;
text projectid;
text romimg_sha256[ROM_SLOT_COUNT];
text romxml_sha256[ROM_SLOT_COUNT];
text namehint[ROM_SLOT_COUNT];
std::vector<std::pair<text, text>> authors;
std::map<text, std::vector<char>> movie_sram;
std::vector<char> anchor_savestate;
int64_t movie_rtc_second;
int64_t movie_rtc_subsecond;
@ -104,7 +105,7 @@ struct project_info
* Throws std::runtime_error: Invalid branch ID.
* Note: The name of ROOT branch is always empty string.
*/
const std::string& get_branch_name(uint64_t bid);
const text& get_branch_name(uint64_t bid);
/**
* Set name of branch.
*
@ -113,7 +114,7 @@ struct project_info
* Throws std::runtime_error: Invalid branch ID.
* Note: The name of ROOT branch can't be changed.
*/
void set_branch_name(uint64_t bid, const std::string& name);
void set_branch_name(uint64_t bid, const text& name);
/**
* Set parent branch of branch.
*
@ -139,7 +140,7 @@ struct project_info
* Returns: Id of new branch.
* Throws std::runtime_error: Invalid branch ID.
*/
uint64_t create_branch(uint64_t pbid, const std::string& name);
uint64_t create_branch(uint64_t pbid, const text& name);
/**
* Delete a branch.
*
@ -150,7 +151,7 @@ struct project_info
/**
* Get name of current branch as string.
*/
std::string get_branch_string();
text get_branch_string();
/**
* Flush the project to disk.
*/
@ -185,32 +186,32 @@ public:
*
* Returns: Map from IDs of projects to project names.
*/
std::map<std::string, std::string> enumerate();
std::map<text, text> enumerate();
/**
* Load a given project.
*
* Parameter id: The ID of project to load.
* Returns: The project information.
*/
project_info& load(const std::string& id);
project_info& load(const text& id);
/**
* Get project movie path.
*
* Returns: The movie path.
*/
std::string moviepath();
text moviepath();
/**
* Get project other path.
*
* Returns: The other path.
*/
std::string otherpath();
text otherpath();
/**
* Get project savestate extension.
*
* Returns: The savestate extension.
*/
std::string savestate_ext();
text savestate_ext();
/**
* Copy watches to project
*/
@ -222,11 +223,11 @@ public:
private:
void recursive_list_branch(uint64_t bid, std::set<unsigned>& dset, unsigned depth, bool last_of);
void do_branch_ls();
void do_branch_mk(const std::string& a);
void do_branch_rm(const std::string& a);
void do_branch_set(const std::string& a);
void do_branch_rp(const std::string& a);
void do_branch_mv(const std::string& a);
void do_branch_mk(const text& a);
void do_branch_rm(const text& a);
void do_branch_set(const text& a);
void do_branch_rp(const text& a);
void do_branch_mv(const text& a);
project_info* active_project;
voice_commentary& commentary;
memwatch_set& mwatch;
@ -239,11 +240,11 @@ private:
loaded_rom& rom;
status_updater& supdater;
command::_fnptr<> branch_ls;
command::_fnptr<const std::string&> branch_mk;
command::_fnptr<const std::string&> branch_rm;
command::_fnptr<const std::string&> branch_set;
command::_fnptr<const std::string&> branch_rp;
command::_fnptr<const std::string&> branch_mv;
command::_fnptr<const text&> branch_mk;
command::_fnptr<const text&> branch_rm;
command::_fnptr<const text&> branch_set;
command::_fnptr<const text&> branch_rp;
command::_fnptr<const text&> branch_mv;
};
#endif

View file

@ -65,7 +65,7 @@ struct input_queue
threads::lock queue_lock;
threads::cv queue_condition;
std::deque<keypress_info> keypresses;
std::deque<std::pair<const char*, std::string>> commands;
std::deque<std::pair<const char*, text>> commands;
std::deque<function_queue_entry> functions;
volatile uint64_t functions_executed;
volatile uint64_t next_function;
@ -90,7 +90,7 @@ struct input_queue
*
* Parameter c: The command to queue.
*/
void queue(const std::string& c) throw(std::bad_alloc);
void queue(const text& c) throw(std::bad_alloc);
/**
* Queue command and arguments.
*
@ -99,7 +99,7 @@ struct input_queue
* Parameter c: The command to queue.
* Parameter a: The arguments for function.
*/
void queue(const char* c, const std::string& a) throw(std::bad_alloc);
void queue(const char* c, const text& a) throw(std::bad_alloc);
/**
* Queue function to be called in emulation thread.
*

View file

@ -15,7 +15,7 @@
* \return The random hexadecimal string.
* \throws std::bad_alloc Not enough memory.
*/
std::string get_random_hexstring(size_t length) throw(std::bad_alloc);
text get_random_hexstring(size_t length) throw(std::bad_alloc);
/**
* \brief Set random seed
@ -25,7 +25,7 @@ std::string get_random_hexstring(size_t length) throw(std::bad_alloc);
* \param seed The value to use as seed.
* \throw std::bad_alloc Not enough memory.
*/
void set_random_seed(const std::string& seed) throw(std::bad_alloc);
void set_random_seed(const text& seed) throw(std::bad_alloc);
/**
* \brief Set random seed to (hopefully) unique value

View file

@ -35,7 +35,7 @@ struct loaded_rom
* throws std::bad_alloc: Not enough memory
* throws std::runtime_error: Switching cartridges failed.
*/
void load(std::map<std::string, std::string>& settings, uint64_t rtc_sec, uint64_t rtc_subsec)
void load(std::map<text, text>& settings, uint64_t rtc_sec, uint64_t rtc_subsec)
throw(std::bad_alloc, std::runtime_error);
/**
* Reset the emulation state to state just before last load.
@ -94,29 +94,29 @@ struct loaded_rom
/**
* Get filename of ROM pack, if any.
*/
const std::string& get_pack_filename() { return image->get_pack_filename(); }
const text& get_pack_filename() { return image->get_pack_filename(); }
/**
* Get MSU-1 base fileaname.
*/
const std::string& get_msu1_base() { return image->get_msu1_base(); }
const text& get_msu1_base() { return image->get_msu1_base(); }
//ROM methods.
std::string get_core_identifier() { return rtype().get_core_identifier(); }
text get_core_identifier() { return rtype().get_core_identifier(); }
std::pair<uint32_t, uint32_t> get_scale_factors(uint32_t width, uint32_t height)
{
return rtype().get_scale_factors(width, height);
}
const std::string& get_hname() { return image->get_hname(); }
const text& get_hname() { return image->get_hname(); }
core_sysregion& combine_region(core_region& reg) { return rtype().combine_region(reg); }
bool isnull() { return rtype().isnull(); }
std::vector<std::string> get_trace_cpus() { return rtype().get_trace_cpus(); }
controller_set controllerconfig(std::map<std::string, std::string>& settings)
std::vector<text> get_trace_cpus() { return rtype().get_trace_cpus(); }
controller_set controllerconfig(std::map<text, text>& settings)
{
return rtype().controllerconfig(settings);
}
core_setting_group& get_settings() { return rtype().get_settings(); }
std::set<std::string> srams() { return rtype().srams(); }
std::set<text> srams() { return rtype().srams(); }
double get_PAR() { return rtype().get_PAR(); }
std::string get_systemmenu_name() { return rtype().get_systemmenu_name(); }
text get_systemmenu_name() { return rtype().get_systemmenu_name(); }
unsigned action_flags(unsigned id) { return rtype().action_flags(id); }
std::set<const interface_action*> get_actions() { return rtype().get_actions(); }
void execute_action(unsigned id, const std::vector<interface_action_paramval>& p)
@ -129,9 +129,9 @@ struct loaded_rom
void set_pflag(bool pflag) { rtype().set_pflag(pflag); }
std::pair<uint64_t, uint64_t> get_bus_map() { return rtype().get_bus_map(); }
std::list<core_region*> get_regions() { return image->get_regions(); }
const std::string& get_iname() { return rtype().get_iname(); }
std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc) { return rtype().save_sram(); }
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc)
const text& get_iname() { return rtype().get_iname(); }
std::map<text, std::vector<char>> save_sram() throw(std::bad_alloc) { return rtype().save_sram(); }
void load_sram(std::map<text, std::vector<char>>& sram) throw(std::bad_alloc)
{
rtype().load_sram(sram);
}
@ -155,10 +155,10 @@ struct loaded_rom
rtype().debug_reset();
}
//Region methods.
const std::string& orig_region_get_iname() { return image->get_region().get_iname(); }
const std::string& orig_region_get_hname() { return image->get_region().get_hname(); }
const std::string& region_get_iname() { return region->get_iname(); }
const std::string& region_get_hname() { return region->get_hname(); }
const text& orig_region_get_iname() { return image->get_region().get_iname(); }
const text& orig_region_get_hname() { return image->get_region().get_hname(); }
const text& region_get_iname() { return region->get_iname(); }
const text& region_get_hname() { return region->get_hname(); }
double region_approx_framerate() { return region->approx_framerate(); }
void region_fill_framerate_magic(uint64_t* magic) { region->fill_framerate_magic(magic); }
bool region_compatible_with(core_region& run)
@ -188,31 +188,30 @@ std::pair<core_type*, core_region*> get_current_rom_info() throw();
* throws std::bad_alloc: Out of memory.
* throws std::runtime_error: Failed to load.
*/
std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)
std::map<text, std::vector<char>> load_sram_commandline(const std::vector<text>& cmdline)
throw(std::bad_alloc, std::runtime_error);
struct romload_request
{
//Pack file to load. Overrides everything else.
std::string packfile;
text packfile;
//Single file to load to default slot.
std::string singlefile;
text singlefile;
//Core and system. May be blank.
std::string core;
std::string system;
std::string region;
text core;
text system;
text region;
//Files to load.
std::string files[ROM_SLOT_COUNT];
text files[ROM_SLOT_COUNT];
};
bool load_null_rom();
bool _load_new_rom(const romload_request& req);
bool reload_active_rom();
regex_results get_argument(const std::vector<std::string>& cmdline, const std::string& regexp);
std::string get_requested_core(const std::vector<std::string>& cmdline);
regex_results get_argument(const std::vector<text>& cmdline, const text& regexp);
text get_requested_core(const std::vector<text>& cmdline);
void try_guess_roms(rom_request& req);
std::string try_to_guess_rom(const std::string& hint, const std::string& hash, const std::string& xhash,
core_type& type, unsigned i);
text try_to_guess_rom(const text& hint, const text& hash, const text& xhash, core_type& type, unsigned i);

View file

@ -17,9 +17,9 @@ struct rom_request
//Filename selected (on entry, filename hint).
bool has_slot[ROM_SLOT_COUNT];
bool guessed[ROM_SLOT_COUNT];
std::string filename[ROM_SLOT_COUNT];
std::string hash[ROM_SLOT_COUNT];
std::string hashxml[ROM_SLOT_COUNT];
text filename[ROM_SLOT_COUNT];
text hash[ROM_SLOT_COUNT];
text hashxml[ROM_SLOT_COUNT];
//Canceled flag.
bool canceled;
};
@ -42,18 +42,18 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Loading ROM file failed.
*/
rom_image(const std::string& file, const std::string& tmpprefer = "") throw(std::bad_alloc,
rom_image(const text& file, const text& tmpprefer = "") throw(std::bad_alloc,
std::runtime_error);
/**
* Take a ROM and load it.
*/
rom_image(const std::string& file, const std::string& core, const std::string& type,
const std::string& region);
rom_image(const text& file, const text& core, const text& type,
const text& region);
/**
* Load a multi-file ROM.
*/
rom_image(const std::string file[ROM_SLOT_COUNT], const std::string& core, const std::string& type,
const std::string& region);
rom_image(const text file[ROM_SLOT_COUNT], const text& core, const text& type,
const text& region);
/**
* Take in ROM filename and load it to memory with specified type.
*
@ -62,7 +62,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Loading ROM file failed.
*/
rom_image(const std::string& file, core_type& ctype) throw(std::bad_alloc, std::runtime_error);
rom_image(const text& file, core_type& ctype) throw(std::bad_alloc, std::runtime_error);
/**
* Destroy ROM image.
*/
@ -95,11 +95,11 @@ public:
/**
* Get filename of ROM pack, if any.
*/
const std::string& get_pack_filename() { return load_filename; }
const text& get_pack_filename() { return load_filename; }
/**
* Get MSU-1 base fileaname.
*/
const std::string& get_msu1_base() { return msu1_base; }
const text& get_msu1_base() { return msu1_base; }
/**
* Is same ROM type?
*/
@ -111,10 +111,10 @@ public:
* retruns: True if gamepak, false if not.
* throws std::runtime_error: No such file.
*/
static bool is_gamepak(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
static bool is_gamepak(const text& filename) throw(std::bad_alloc, std::runtime_error);
//ROM functions.
std::list<core_region*> get_regions() { return rtype->get_regions(); }
const std::string& get_hname() { return rtype->get_hname(); }
const text& get_hname() { return rtype->get_hname(); }
private:
rom_image(const rom_image&);
rom_image& operator=(const rom_image&);
@ -127,9 +127,9 @@ private:
//Loaded ROM XML (markup) images.
fileimage::image romxml[ROM_SLOT_COUNT];
//MSU-1 base filename.
std::string msu1_base;
text msu1_base;
//Load filename.
std::string load_filename;
text load_filename;
//ROM type.
core_type* rtype;
//ROM region.
@ -143,7 +143,7 @@ private:
bool put() { threads::alock l(usage_lock); return !--usage_count; }
friend class rom_image_handle;
//Handle bundle load case.
void load_bundle(const std::string& file, std::istream& spec, const std::string& tmpprefer)
void load_bundle(const text& file, std::istream& spec, const text& tmpprefer)
throw(std::bad_alloc, std::runtime_error);
//Tracker.
memtracker::autorelease tracker;
@ -218,12 +218,12 @@ private:
};
void record_filehash(const std::string& file, uint64_t prefix, const std::string& hash);
void record_filehash(const text& file, uint64_t prefix, const text& hash);
void set_hasher_callback(std::function<void(uint64_t, uint64_t)> cb);
rom_image_handle construct_rom(const std::string& movie_filename, const std::vector<std::string>& cmdline);
rom_image_handle construct_rom(const text& movie_filename, const std::vector<text>& cmdline);
//Map of preferred cores for each extension and type.
extern std::map<std::string, core_type*> preferred_core;
extern std::map<text, core_type*> preferred_core;
//Main hasher
extern fileimage::hash lsnes_image_hasher;

View file

@ -34,20 +34,20 @@ public:
subtitle_commentary(movie_logic& _mlogic, emu_framebuffer& _fbuf, emulator_dispatch& _dispatch,
command::group& _cmd);
std::set<std::pair<uint64_t, uint64_t>> get_all();
std::string get(uint64_t f, uint64_t l);
void set(uint64_t f, uint64_t l, const std::string& x);
static std::string s_unescape(std::string x);
static std::string s_escape(std::string x);
text get(uint64_t f, uint64_t l);
void set(uint64_t f, uint64_t l, const text& x);
static text s_unescape(text x);
static text s_escape(text x);
void render(lua::render_context& ctx);
private:
void do_editsub(const std::string& a);
void do_editsub(const text& a);
void do_listsub();
void do_savesub(const std::string& a);
void do_savesub(const text& a);
movie_logic& mlogic;
emu_framebuffer& fbuf;
emulator_dispatch& edispatch;
command::group& cmd;
command::_fnptr<const std::string&> editsub;
command::_fnptr<const text&> editsub;
command::_fnptr<> listsub;
command::_fnptr<command::arg_filename> savesub;
};

View file

@ -7,6 +7,7 @@
#include <list>
#include <string>
#include <sstream>
#include "library/text.hpp"
/*********************************************************************************************************************
UI services.
@ -26,19 +27,19 @@ struct project_author_info
//True if this is a project, false if not. Ignored when saving.
bool is_project;
//Lua scripts. Ignored when saving if not in project context.
std::list<std::string> luascripts;
std::list<text> luascripts;
//Autorun new lua scripts. Ignored when saving if not in project context, always loaded as false.
bool autorunlua;
//Authors. First of each pair is full name, second is nickname.
std::list<std::pair<std::string, std::string>> authors;
std::list<std::pair<text, text>> authors;
//Name of the game.
std::string gamename;
text gamename;
//Project Directory. Ignored if not in project context.
std::string directory;
text directory;
//Project name. Ignored if not in project context.
std::string projectname;
text projectname;
//Save prefix.
std::string prefix;
text prefix;
};
struct dumper_information_1
@ -46,24 +47,24 @@ struct dumper_information_1
//The factory for this dumper.
dumper_factory_base* factory;
//Name of this dumper.
std::string name;
text name;
//Is this dumper active?
bool active;
//Hidden?
bool hidden;
//Modes available (first is internal name, second is human-readable one).
std::map<std::string, std::string> modes;
std::map<text, text> modes;
};
struct dumper_information
{
std::map<std::string, dumper_information_1> dumpers;
std::map<text, dumper_information_1> dumpers;
};
/**
* Fill branch name map.
*/
void UI_get_branch_map(emulator_instance& instance, uint64_t& cur, std::map<uint64_t, std::string>& namemap,
void UI_get_branch_map(emulator_instance& instance, uint64_t& cur, std::map<uint64_t, text>& namemap,
std::map<uint64_t, std::set<uint64_t>>& childmap);
/**
* Arrange current project to be flushed.
@ -72,12 +73,12 @@ void UI_call_flush(emulator_instance& instance, std::function<void(std::exceptio
/**
* Arrage branch to be created.
*/
void UI_create_branch(emulator_instance& instance, uint64_t id, const std::string& name,
void UI_create_branch(emulator_instance& instance, uint64_t id, const text& name,
std::function<void(std::exception&)> onerror);
/**
* Arrage branch to be renamed.
*/
void UI_rename_branch(emulator_instance& instance, uint64_t id, const std::string& name,
void UI_rename_branch(emulator_instance& instance, uint64_t id, const text& name,
std::function<void(std::exception&)> onerror);
/**
* Arrage branch to be reparented.
@ -107,8 +108,8 @@ dumper_information UI_get_dumpers(emulator_instance& instance);
/**
* Start dumping.
*/
void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const std::string& mode,
const std::string& prefix);
void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const text& mode,
const text& prefix);
/**
* End dumping.
*/
@ -129,15 +130,15 @@ void UI_save_movie(emulator_instance& inst, std::ostringstream& buffer);
/**
* Look up (platform,game) pair.
*/
std::pair<std::string, std::string> UI_lookup_platform_and_game(emulator_instance& inst);
std::pair<text, text> UI_lookup_platform_and_game(emulator_instance& inst);
/**
* Get otherpath of current project.
*/
std::string UI_get_project_otherpath(emulator_instance& inst);
text UI_get_project_otherpath(emulator_instance& inst);
/**
* Get moviepath of current project.
*/
std::string UI_get_project_moviepath(emulator_instance& inst);
text UI_get_project_moviepath(emulator_instance& inst);
/**
* Is in project context?
*/

View file

@ -18,7 +18,7 @@ struct _graphics_driver
void (*init)();
void (*quit)();
void (*notify_message)();
void (*error_message)(const std::string& text);
void (*error_message)(const text& text);
void (*fatal_error)();
const char* (*name)();
void (*request_rom)(rom_request& req);
@ -52,7 +52,7 @@ void graphics_driver_notify_message() throw();
*
* Parameter text: The text for dialog.
*/
void graphics_driver_error_message(const std::string& text) throw();
void graphics_driver_error_message(const text& text) throw();
/**
* Displays fatal error message.
*
@ -110,7 +110,7 @@ struct platform
* parameter msg: The messages to add (split by '\n').
* throws std::bad_alloc: Not enough memory.
*/
static void message(const std::string& msg) throw(std::bad_alloc);
static void message(const text& msg) throw(std::bad_alloc);
/**
* Displays fatal error message, quitting after the user acks it (called by fatal_error()).
*
@ -132,23 +132,23 @@ struct platform
/**
* Set sound device.
*/
static void set_sound_device(const std::string& pdev, const std::string& rdev) throw();
static void set_sound_device(const text& pdev, const text& rdev) throw();
/**
* Set sound device by description.
*/
static void set_sound_device_by_description(const std::string& pdev, const std::string& rdev) throw();
static void set_sound_device_by_description(const text& pdev, const text& rdev) throw();
/**
* Get sound device description.
*/
static std::string get_sound_device_description(bool rec) throw(std::bad_alloc);
static text get_sound_device_description(bool rec) throw(std::bad_alloc);
/**
* Show error message dialog after UI thread becomes free.
*
* Parameter text: The text for dialog.
*/
static void error_message(const std::string& text) throw()
static void error_message(const text& _text) throw()
{
return graphics_driver_error_message(text);
return graphics_driver_error_message(_text);
}
/**
* Process command and keypress queues.

View file

@ -26,7 +26,7 @@ public:
/**
* Notifies about latch. Only called on some systems.
*/
virtual void notify_latch(std::list<std::string>& l) = 0;
virtual void notify_latch(std::list<text>& l) = 0;
/**
* Tick the RTC timer.
*/
@ -34,11 +34,11 @@ public:
/**
* Get path for firmware.
*/
virtual std::string get_firmware_path() = 0;
virtual text get_firmware_path() = 0;
/**
* Get the base filename for ROM.
*/
virtual std::string get_base_path() = 0;
virtual text get_base_path() = 0;
/**
* Get current RTC time.
*/

View file

@ -7,10 +7,10 @@
void cover_render_character(void* fb, unsigned x, unsigned y, uint32_t ch, uint32_t fg, uint32_t bg, size_t w,
size_t h, size_t istride, size_t pstride);
void cover_render_string(void* fb, unsigned x, unsigned y, const std::string& str, uint32_t fg, uint32_t bg,
void cover_render_string(void* fb, unsigned x, unsigned y, const text& str, uint32_t fg, uint32_t bg,
size_t w, size_t h, size_t istride, size_t pstride);
void cover_next_position(uint32_t ch, unsigned& x, unsigned& y);
void cover_next_position(const std::string& ch, unsigned& x, unsigned& y);
std::vector<std::string> cover_information();
void cover_next_position(const text& ch, unsigned& x, unsigned& y);
std::vector<text> cover_information();
#endif

View file

@ -5,20 +5,21 @@
#include <string>
#include <map>
#include <set>
#include "library/text.hpp"
class disassembler
{
public:
disassembler(const std::string& name);
disassembler(const text& name);
virtual ~disassembler();
virtual std::string disassemble(uint64_t base, std::function<unsigned char()> fetchpc) = 0;
static disassembler& byname(const std::string& name);
static std::set<std::string> list();
virtual text disassemble(uint64_t base, std::function<unsigned char()> fetchpc) = 0;
static disassembler& byname(const text& name);
static std::set<text> list();
template<typename T> static T fetch_le(std::function<unsigned char()> fetchpc);
template<typename T> static T fetch_be(std::function<unsigned char()> fetchpc);
private:
std::string name;
static std::map<std::string, disassembler*>& disasms();
text name;
static std::map<text, disassembler*>& disasms();
};
#endif

View file

@ -10,6 +10,7 @@
#include "library/framebuffer.hpp"
#include "library/threads.hpp"
#include "library/loadlib.hpp"
#include "library/text.hpp"
struct core_region;
struct core_type;
@ -55,7 +56,7 @@ struct interface_action_param
*/
struct interface_action_paramval
{
std::string s;
text s;
int64_t i;
bool b;
};
@ -69,8 +70,8 @@ struct interface_action
const char* _title;
const char* _symbol;
std::list<interface_action_param> params;
std::string get_title() const { return _title; }
std::string get_symbol() const { return _symbol; }
text get_title() const { return _title; }
text get_symbol() const { return _symbol; }
bool is_toggle() const;
};
@ -151,12 +152,12 @@ struct core_romimage_info_params
struct core_romimage_info
{
core_romimage_info(const core_romimage_info_params& params);
std::string iname;
std::string hname;
text iname;
text hname;
unsigned mandatory;
int pass_mode;
unsigned headersize;
std::set<std::string> extensions;
std::set<text> extensions;
size_t get_headnersize(size_t imagesize);
};
@ -192,7 +193,7 @@ struct core_vma_info
/**
* Name of the VMA.
*/
std::string name;
text name;
/**
* Base address of the VMA.
*/
@ -287,8 +288,8 @@ struct core_region
public:
core_region(const core_region_params& params);
core_region(std::initializer_list<core_region_params> p) : core_region(*p.begin()) {}
const std::string& get_iname();
const std::string& get_hname();
const text& get_iname();
const text& get_hname();
unsigned get_priority();
unsigned get_handle();
bool is_multi();
@ -298,8 +299,8 @@ public:
private:
core_region(const core_region&);
core_region& operator=(const core_region&);
std::string iname;
std::string hname;
text iname;
text hname;
bool multi;
unsigned handle;
unsigned priority;
@ -323,9 +324,9 @@ struct core_core
std::pair<uint32_t, uint32_t> get_video_rate();
double get_PAR();
std::pair<uint32_t, uint32_t> get_audio_rate();
std::string get_core_identifier() const;
std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc);
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc);
text get_core_identifier() const;
std::map<text, std::vector<char>> save_sram() throw(std::bad_alloc);
void load_sram(std::map<text, std::vector<char>>& sram) throw(std::bad_alloc);
void serialize(std::vector<char>& out);
void unserialize(const char* in, size_t insize);
core_region& get_region();
@ -340,13 +341,13 @@ struct core_core
void set_pflag(bool pflag);
framebuffer::raw& draw_cover();
std::vector<portctrl::type*> get_port_types() { return port_types; }
std::string get_core_shortname() const;
text get_core_shortname() const;
void pre_emulate_frame(portctrl::frame& cf);
void execute_action(unsigned id, const std::vector<interface_action_paramval>& p);
unsigned action_flags(unsigned id);
std::pair<uint64_t, uint64_t> get_bus_map();
std::list<core_vma_info> vma_list();
std::set<std::string> srams();
std::set<text> srams();
static std::set<core_core*> all_cores();
static void install_all_handlers();
static void uninstall_all_handlers();
@ -359,7 +360,7 @@ struct core_core
std::pair<unsigned, unsigned> lightgun_scale();
void set_debug_flags(uint64_t addr, unsigned flags_set, unsigned flags_clear);
void set_cheat(uint64_t addr, uint64_t value, bool set);
std::vector<std::string> get_trace_cpus();
std::vector<text> get_trace_cpus();
void debug_reset();
bool isnull() const;
void reset_to_load() { c_reset_to_load(); }
@ -368,7 +369,7 @@ protected:
/**
* Get the name of the core.
*/
virtual std::string c_core_identifier() const = 0;
virtual text c_core_identifier() const = 0;
/**
* Set the current region.
*
@ -393,13 +394,13 @@ protected:
/**
* Save all SRAMs.
*/
virtual std::map<std::string, std::vector<char>> c_save_sram() throw(std::bad_alloc) = 0;
virtual std::map<text, std::vector<char>> c_save_sram() throw(std::bad_alloc) = 0;
/**
* Load all SRAMs.
*
* Note: Must handle SRAM being missing or shorter or longer than expected.
*/
virtual void c_load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc) = 0;
virtual void c_load_sram(std::map<text, std::vector<char>>& sram) throw(std::bad_alloc) = 0;
/**
* Serialize the system state.
*/
@ -461,7 +462,7 @@ protected:
/**
* Get shortened name of the core.
*/
virtual std::string c_get_core_shortname() const = 0;
virtual text c_get_core_shortname() const = 0;
/**
* Set the system controls to appropriate values for next frame.
*
@ -507,7 +508,7 @@ protected:
*
* Returns: The list of SRAMs.
*/
virtual std::set<std::string> c_srams() = 0;
virtual std::set<text> c_srams() = 0;
/**
* Get lightgun scale (only cores that have lightguns need to define this).
*/
@ -526,7 +527,7 @@ protected:
/**
* Get list of trace processor names.
*/
virtual std::vector<std::string> c_get_trace_cpus() = 0;
virtual std::vector<text> c_get_trace_cpus() = 0;
/**
* Reset all debug hooks.
*/
@ -542,7 +543,7 @@ protected:
private:
std::vector<portctrl::type*> port_types;
bool hidden;
std::map<std::string, interface_action> actions;
std::map<text, interface_action> actions;
threads::lock actions_lock;
};
@ -556,30 +557,30 @@ public:
core_region& get_preferred_region() const;
std::list<core_region*> get_regions() const;
core_sysregion& combine_region(core_region& reg) const;
const std::string& get_iname() const;
const std::string& get_hname() const;
std::list<std::string> get_extensions() const;
bool is_known_extension(const std::string& ext) const;
core_sysregion& lookup_sysregion(const std::string& sysreg) const;
std::string get_biosname() const;
const text& get_iname() const;
const text& get_hname() const;
std::list<text> get_extensions() const;
bool is_known_extension(const text& ext) const;
core_sysregion& lookup_sysregion(const text& sysreg) const;
text get_biosname() const;
unsigned get_id() const;
unsigned get_image_count() const;
core_romimage_info get_image_info(unsigned index) const;
bool load(core_romimage* images, std::map<std::string, std::string>& settings, uint64_t rtc_sec,
bool load(core_romimage* images, std::map<text, text>& settings, uint64_t rtc_sec,
uint64_t rtc_subsec);
controller_set controllerconfig(std::map<std::string, std::string>& settings);
controller_set controllerconfig(std::map<text, text>& settings);
core_setting_group& get_settings();
std::pair<uint64_t, uint64_t> get_bus_map() { return core->get_bus_map(); }
std::list<core_vma_info> vma_list() { return core->vma_list(); }
std::set<std::string> srams() { return core->srams(); }
std::set<text> srams() { return core->srams(); }
core_core* get_core() { return core; }
bool set_region(core_region& region) { return core->set_region(region); }
std::pair<uint32_t, uint32_t> get_video_rate() { return core->get_video_rate(); }
std::pair<uint32_t, uint32_t> get_audio_rate() { return core->get_audio_rate(); }
std::string get_core_identifier() { return core->get_core_identifier(); }
std::string get_core_shortname() const { return core->get_core_shortname(); }
std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc) { return core->save_sram(); }
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc)
text get_core_identifier() { return core->get_core_identifier(); }
text get_core_shortname() const { return core->get_core_shortname(); }
std::map<text, std::vector<char>> save_sram() throw(std::bad_alloc) { return core->save_sram(); }
void load_sram(std::map<text, std::vector<char>>& sram) throw(std::bad_alloc)
{
core->load_sram(sram);
}
@ -599,7 +600,7 @@ public:
bool get_pflag() { return core->get_pflag(); }
void set_pflag(bool pflag) { core->set_pflag(pflag); }
framebuffer::raw& draw_cover() { return core->draw_cover(); }
std::string get_systemmenu_name() { return sysname; }
text get_systemmenu_name() { return sysname; }
void execute_action(unsigned id, const std::vector<interface_action_paramval>& p)
{
return core->execute_action(id, p);
@ -620,7 +621,7 @@ public:
{
return core->set_cheat(addr, value, set);
}
std::vector<std::string> get_trace_cpus() { return core->get_trace_cpus(); }
std::vector<text> get_trace_cpus() { return core->get_trace_cpus(); }
void debug_reset() { core->debug_reset(); }
bool isnull() const { return core->isnull(); }
void reset_to_load() { return core->reset_to_load(); }
@ -635,7 +636,7 @@ protected:
* Parameter rtc_subsec: The initial RTC subseconds value.
* Returns: -1 on failure, 0 on success.
*/
virtual int t_load_rom(core_romimage* images, std::map<std::string, std::string>& settings, uint64_t rtc_sec,
virtual int t_load_rom(core_romimage* images, std::map<text, text>& settings, uint64_t rtc_sec,
uint64_t rtc_subsec) = 0;
/**
* Obtain controller config for given settings.
@ -643,15 +644,15 @@ protected:
* Parameter settings: The settings to use.
* Returns: The controller configuration.
*/
virtual controller_set t_controllerconfig(std::map<std::string, std::string>& settings) = 0;
virtual controller_set t_controllerconfig(std::map<text, text>& settings) = 0;
private:
core_type(const core_type&);
core_type& operator=(const core_type&);
unsigned id;
std::string iname;
std::string hname;
std::string biosname;
std::string sysname;
text iname;
text hname;
text biosname;
text sysname;
std::list<core_region*> regions;
std::vector<core_romimage_info> imageinfo;
core_setting_group settings;
@ -673,9 +674,9 @@ public:
* Parameter type: The system.
* Parameter region: The region.
*/
core_sysregion(const std::string& name, core_type& type, core_region& region);
core_sysregion(const text& name, core_type& type, core_region& region);
~core_sysregion() throw();
const std::string& get_name() const;
const text& get_name() const;
core_region& get_region();
core_type& get_type();
void fill_framerate_magic(uint64_t* magic); //4 elements filled.
@ -685,18 +686,18 @@ public:
* Parameter name: The name of system region.
* Returns: Sysregions matching the specified.
*/
static std::set<core_sysregion*> find_matching(const std::string& name);
static std::set<core_sysregion*> find_matching(const text& name);
private:
core_sysregion(const core_sysregion&);
core_sysregion& operator=(const core_sysregion&);
std::string name;
text name;
core_type& type;
core_region& region;
};
//Register a sysregion to name mapping.
void register_sysregion_mapping(std::string from, std::string to);
std::string lookup_sysregion_mapping(std::string from);
void register_sysregion_mapping(text from, text to);
text lookup_sysregion_mapping(text from);
//Set to true if new core is detected.
extern bool new_core_flag;

View file

@ -6,6 +6,7 @@
#include <vector>
#include <map>
#include <set>
#include "library/text.hpp"
struct core_setting;
struct core_setting_group;
@ -44,11 +45,11 @@ struct core_setting_value
/**
* Internal value.
*/
const std::string iname;
const text iname;
/**
* Human-readable value.
*/
const std::string hname;
const text hname;
/**
* Index.
*/
@ -67,19 +68,19 @@ struct core_setting
/**
* Internal name.
*/
const std::string iname;
const text iname;
/**
* Human-readable name.
*/
const std::string hname;
const text hname;
/**
* Regular expression for validation of fretext setting.
*/
const std::string regex;
const text regex;
/**
* The default value.
*/
const std::string dflt;
const text dflt;
/**
* The values.
*/
@ -95,21 +96,21 @@ struct core_setting
/**
* Get set of human-readable strings.
*/
std::vector<std::string> hvalues() const throw(std::runtime_error);
std::vector<text> hvalues() const throw(std::runtime_error);
/**
* Translate hvalue to ivalue.
*/
std::string hvalue_to_ivalue(const std::string& hvalue) const throw(std::runtime_error);
text hvalue_to_ivalue(const text& hvalue) const throw(std::runtime_error);
/**
* Translate ivalue to index.
*/
signed ivalue_to_index(const std::string& ivalue) const throw(std::runtime_error);
signed ivalue_to_index(const text& ivalue) const throw(std::runtime_error);
/**
* Validate a value.
*
* Parameter value: The value to validate.
*/
bool validate(const std::string& value) const;
bool validate(const text& value) const;
};
/**
@ -129,15 +130,15 @@ struct core_setting_group
/**
* The settings.
*/
std::map<std::string, core_setting> settings;
std::map<text, core_setting> settings;
/**
* Get specified setting.
*/
core_setting& operator[](const std::string& name) { return settings.find(name)->second; }
core_setting& operator[](const text& name) { return settings.find(name)->second; }
/**
* Translate ivalue to index.
*/
signed ivalue_to_index(std::map<std::string, std::string>& values, const std::string& name) const
signed ivalue_to_index(std::map<text, text>& values, const text& name) const
throw(std::runtime_error)
{
return settings.find(name)->second.ivalue_to_index(values[name]);
@ -145,11 +146,11 @@ struct core_setting_group
/**
* Fill a map of settings with defaults.
*/
void fill_defaults(std::map<std::string, std::string>& values) throw(std::bad_alloc);
void fill_defaults(std::map<text, text>& values) throw(std::bad_alloc);
/**
* Get set of settings.
*/
std::set<std::string> get_setting_set();
std::set<text> get_setting_set();
};
#endif

View file

@ -3,6 +3,7 @@
#include <cstring>
#include "serialization.hpp"
#include "text.hpp"
#include <cstdint>
#include <stdexcept>
#include <functional>
@ -163,7 +164,7 @@ struct assembler
void operator()() {}
void _label(label& l);
void _label(label& l, const std::string& globalname);
void _label(label& l, const text& globalname);
void byte(uint8_t b);
void byte(std::initializer_list<uint8_t> b);
void byte(const uint8_t* b, size_t l);
@ -172,8 +173,8 @@ struct assembler
void align(size_t multiple);
void pad(size_t amount);
size_t size();
void dump(const std::string& basename, const std::string& name, void* base, std::map<std::string, void*> map);
std::map<std::string, void*> flush(void* base);
void dump(const text& basename, const text& name, void* base, std::map<text, void*> map);
std::map<text, void*> flush(void* base);
private:
struct reloc
{
@ -183,7 +184,7 @@ private:
};
std::vector<uint8_t> data;
std::list<reloc> relocs;
std::map<std::string, const label*> globals;
std::map<text, const label*> globals;
};
class dynamic_code

View file

@ -52,7 +52,7 @@ public:
* Parameter string: The string to query.
* Return: The number of bytes needed.
*/
size_t stringbytes(const std::string& string);
size_t stringbytes(const text& string);
/**
* Output a 32-bit number to stream (4 byte).
*
@ -66,7 +66,7 @@ public:
*
* Parameter string: The number to output.
*/
void string(const std::string& string);
void string(const text& string);
/**
* Output a string without length indication to the stream.
*
@ -74,7 +74,7 @@ public:
*
* Parameter string: The number to output.
*/
void string_implicit(const std::string& string);
void string_implicit(const text& string);
/**
* Output a octet string without length indication to the stream.
*
@ -128,7 +128,7 @@ public:
*
* Returns: The internal buffer contents.
*/
std::string get();
text get();
private:
inline void write(const char* buf, size_t size);
int strm;
@ -191,7 +191,7 @@ public:
*
* Returns: The read string.
*/
std::string string();
text string();
/**
* Read a string without explicit length indication, quitting when reaching end of extension substream.
*
@ -199,7 +199,7 @@ public:
*
* Returns: The read string.
*/
std::string string_implicit();
text string_implicit();
/**
* Read a octet string without explicit length indication, quitting when reaching end of extension substream.
*

View file

@ -7,6 +7,7 @@
#include <set>
#include <map>
#include <list>
#include "text.hpp"
namespace command
{
@ -33,11 +34,11 @@ public:
/**
* New item in set.
*/
virtual void create(set& s, const std::string& name, factory_base& cmd) = 0;
virtual void create(set& s, const text& name, factory_base& cmd) = 0;
/**
* Deleted item from set.
*/
virtual void destroy(set& s, const std::string& name) = 0;
virtual void destroy(set& s, const text& name) = 0;
/**
* Destroyed the entiere set.
*/
@ -54,11 +55,11 @@ public:
/**
* Add a command to set.
*/
void do_register(const std::string& name, factory_base& cmd) throw(std::bad_alloc);
void do_register(const text& name, factory_base& cmd) throw(std::bad_alloc);
/**
* Remove a command from set.
*/
void do_unregister(const std::string& name, factory_base& cmd) throw(std::bad_alloc);
void do_unregister(const text& name, factory_base& cmd) throw(std::bad_alloc);
/**
* Add a notification callback and call ccb on all.
*
@ -94,38 +95,38 @@ public:
*
* parameter cmd: Command to exeucte.
*/
void invoke(const std::string& cmd) throw();
void invoke(const text& cmd) throw();
/**
* Look up and invoke a command. No alias expansion is performed, but recursion checking is.
*
* parameter cmd: Command to execute.
* parameter args: The parameters for command.
*/
void invoke(const std::string& cmd, const std::string& args) throw();
void invoke(const text& cmd, const text& args) throw();
/**
* Get set of aliases.
*/
std::set<std::string> get_aliases() throw(std::bad_alloc);
std::set<text> get_aliases() throw(std::bad_alloc);
/**
* Get alias
*/
std::string get_alias_for(const std::string& aname) throw(std::bad_alloc);
text get_alias_for(const text& aname) throw(std::bad_alloc);
/**
* Set alias
*/
void set_alias_for(const std::string& aname, const std::string& avalue) throw(std::bad_alloc);
void set_alias_for(const text& aname, const text& avalue) throw(std::bad_alloc);
/**
* Is alias name valid.
*/
bool valid_alias_name(const std::string& aname) throw(std::bad_alloc);
bool valid_alias_name(const text& aname) throw(std::bad_alloc);
/**
* Register a command.
*/
void do_register(const std::string& name, base& cmd) throw(std::bad_alloc);
void do_register(const text& name, base& cmd) throw(std::bad_alloc);
/**
* Unregister a command.
*/
void do_unregister(const std::string& name, base& cmd) throw(std::bad_alloc);
void do_unregister(const text& name, base& cmd) throw(std::bad_alloc);
/**
* Add all commands (including future ones) in given set.
*/
@ -148,14 +149,14 @@ private:
public:
listener(group& _grp);
~listener();
void create(set& s, const std::string& name, factory_base& cmd);
void destroy(set& s, const std::string& name);
void create(set& s, const text& name, factory_base& cmd);
void destroy(set& s, const text& name);
void kill(set& s);
private:
group& grp;
} _listener;
std::set<std::string> command_stack;
std::map<std::string, std::list<std::string>> aliases;
std::set<text> command_stack;
std::map<text, std::list<text>> aliases;
std::ostream* output;
void (*oom_panic_routine)();
base* builtin[1];
@ -175,7 +176,7 @@ public:
* parameter dynamic: Should the object be freed when its parent group dies?
* throws std::bad_alloc: Not enough memory.
*/
base(group& group, const std::string& cmd, bool dynamic) throw(std::bad_alloc);
base(group& group, const text& cmd, bool dynamic) throw(std::bad_alloc);
/**
* Deregister a command.
@ -189,20 +190,20 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Command execution failed.
*/
virtual void invoke(const std::string& arguments) throw(std::bad_alloc, std::runtime_error) = 0;
virtual void invoke(const text& arguments) throw(std::bad_alloc, std::runtime_error) = 0;
/**
* Get short help for command.
*/
virtual std::string get_short_help() throw(std::bad_alloc);
virtual text get_short_help() throw(std::bad_alloc);
/**
* Get long help for command.
*/
virtual std::string get_long_help() throw(std::bad_alloc);
virtual text get_long_help() throw(std::bad_alloc);
/**
* Get name of command.
*/
const std::string& get_name() { return commandname; }
const text& get_name() { return commandname; }
/**
* Notify that the parent group died.
*
@ -212,7 +213,7 @@ public:
private:
base(const base&);
base& operator=(const base&);
std::string commandname;
text commandname;
group* in_group;
bool is_dynamic;
};
@ -231,7 +232,7 @@ public:
* parameter cmd: The command to register.
* throws std::bad_alloc: Not enough memory.
*/
void _factory_base(set& _set, const std::string& cmd) throw(std::bad_alloc);
void _factory_base(set& _set, const text& cmd) throw(std::bad_alloc);
/**
* Destructor.
*/
@ -249,7 +250,7 @@ public:
private:
factory_base(const factory_base&);
factory_base& operator=(const factory_base&);
std::string commandname;
text commandname;
set* in_set;
};
@ -280,13 +281,13 @@ struct arg_filename
/**
* The filename itself.
*/
std::string v;
text v;
/**
* Return the filename.
*
* returns: The filename.
*/
operator std::string() { return v; }
operator text() { return v; }
};
/**
@ -296,7 +297,7 @@ struct arg_filename
* parameter a: The arguments to pass.
*/
template<typename... args>
void invoke_fn(std::function<void(args... arguments)> fn, const std::string& a);
void invoke_fn(std::function<void(args... arguments)> fn, const text& a);
/**
* Warp function pointer as command.
@ -315,8 +316,8 @@ public:
* parameter fn: Function to call on command.
* parameter dynamic: Should the object be freed when its parent group dies?
*/
_fnptr(group& group, const std::string& name, const std::string& _description,
const std::string& _help, void (*_fn)(args... arguments), bool dynamic = false) throw(std::bad_alloc)
_fnptr(group& group, const text& name, const text& _description,
const text& _help, void (*_fn)(args... arguments), bool dynamic = false) throw(std::bad_alloc)
: base(group, name, dynamic)
{
shorthelp = _description;
@ -349,7 +350,7 @@ public:
*
* parameter a: Arguments to function.
*/
void invoke(const std::string& a) throw(std::bad_alloc, std::runtime_error)
void invoke(const text& a) throw(std::bad_alloc, std::runtime_error)
{
invoke_fn(fn, a);
}
@ -359,7 +360,7 @@ public:
* returns: Description.
* throw std::bad_alloc: Not enough memory.
*/
std::string get_short_help() throw(std::bad_alloc)
text get_short_help() throw(std::bad_alloc)
{
return shorthelp;
}
@ -369,14 +370,14 @@ public:
* returns: help.
* throw std::bad_alloc: Not enough memory.
*/
std::string get_long_help() throw(std::bad_alloc)
text get_long_help() throw(std::bad_alloc)
{
return help;
}
private:
std::function<void(args... arguments)> fn;
std::string shorthelp;
std::string help;
text shorthelp;
text help;
};
/**
@ -410,8 +411,8 @@ public:
* parameter help: Help for the command.
* parameter fn: Function to call on command.
*/
fnptr(set& _set, const std::string& _name, const std::string& _description,
const std::string& _help, void (*_fn)(args... arguments)) throw(std::bad_alloc)
fnptr(set& _set, const text& _name, const text& _description,
const text& _help, void (*_fn)(args... arguments)) throw(std::bad_alloc)
{
shorthelp = _description;
name = _name;
@ -434,9 +435,9 @@ public:
}
private:
void (*fn)(args... arguments);
std::string shorthelp;
std::string help;
std::string name;
text shorthelp;
text help;
text name;
};
/**
@ -449,7 +450,7 @@ public:
/**
* Create a new factory.
*/
byname_factory(set& s, const std::string& _name)
byname_factory(set& s, const text& _name)
{
name = _name;
_factory_base(s, name);
@ -468,7 +469,7 @@ public:
return new T(grp, name);
}
private:
std::string name;
text name;
};
}
#endif

View file

@ -4,17 +4,18 @@
#include <set>
#include <string>
#include <cstdlib>
#include "text.hpp"
namespace directory
{
std::set<std::string> enumerate(const std::string& dir, const std::string& match);
std::string absolute_path(const std::string& relative);
uintmax_t size(const std::string& path);
time_t mtime(const std::string& path);
bool exists(const std::string& filename);
bool is_regular(const std::string& filename);
bool is_directory(const std::string& filename);
bool ensure_exists(const std::string& path);
std::set<text> enumerate(const text& dir, const text& match);
text absolute_path(const text& relative);
uintmax_t size(const text& path);
time_t mtime(const text& path);
bool exists(const text& filename);
bool is_regular(const text& filename);
bool is_directory(const text& filename);
bool ensure_exists(const text& path);
int rename_overwrite(const char* oldname, const char* newname);
}

View file

@ -5,6 +5,7 @@
#include <cstdint>
#include <list>
#include <vector>
#include "text.hpp"
#include "threads.hpp"
namespace fileimage
@ -24,7 +25,7 @@ public:
/**
* Construct a future, with value that is immediately resolved.
*/
hashval(const std::string& value, uint64_t _prefix = 0);
hashval(const text& value, uint64_t _prefix = 0);
/**
* Is the result known?
*/
@ -32,7 +33,7 @@ public:
/**
* Read the result (or throw error). Waits until result is ready.
*/
std::string read() const;
text read() const;
/**
* Read the prefix value. Waits until result is ready.
*/
@ -57,8 +58,8 @@ private:
/**
* Resolve a future.
*/
void resolve(unsigned id, const std::string& hash, uint64_t _prefix);
void resolve_error(unsigned id, const std::string& err);
void resolve(unsigned id, const text& hash, uint64_t _prefix);
void resolve_error(unsigned id, const text& err);
friend class hash;
mutable threads::lock mlock;
@ -66,8 +67,8 @@ private:
bool is_ready;
unsigned cbid;
uint64_t prefixv;
std::string value;
std::string error;
text value;
text error;
hashval* prev;
hashval* next;
hash* hasher;
@ -94,11 +95,11 @@ public:
/**
* Compute SHA-256 of file.
*/
hashval operator()(const std::string& filename, uint64_t prefixlen = 0);
hashval operator()(const text& filename, uint64_t prefixlen = 0);
/**
* Compute SHA-256 of file.
*/
hashval operator()(const std::string& filename, std::function<uint64_t(uint64_t)> prefixlen);
hashval operator()(const text& filename, std::function<uint64_t(uint64_t)> prefixlen);
/**
* Thread entrypoint.
*/
@ -112,7 +113,7 @@ private:
friend class hashval;
struct queue_job
{
std::string filename;
text filename;
uint64_t prefix;
uint64_t size;
unsigned cbid;
@ -173,7 +174,7 @@ struct image
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Can't load the data.
*/
image(hash& hasher, const std::string& filename, const std::string& base,
image(hash& hasher, const text& filename, const text& base,
const struct info& imginfo) throw(std::bad_alloc, std::runtime_error);
/**
@ -194,11 +195,11 @@ struct image
/**
* Filename this is loaded from.
*/
std::string filename;
text filename;
/**
* ROM name hint.
*/
std::string namehint;
text namehint;
/**
* The actual data for this slot.
*/

View file

@ -4,6 +4,7 @@
#include <map>
#include <set>
#include <string>
#include "text.hpp"
/**
* List of files.
@ -14,7 +15,7 @@ public:
/**
* Create a new list, backed by specific file.
*/
filelist(const std::string& backingfile, const std::string& directory);
filelist(const text& backingfile, const text& directory);
/**
* Dtor.
*/
@ -22,27 +23,27 @@ public:
/**
* Enumerate the files on the list. Files that don't have matching timestamp are auto-removed.
*/
std::set<std::string> enumerate();
std::set<text> enumerate();
/**
* Add a file to the list. Current timestamp is used to mark version.
*/
void add(const std::string& filename);
void add(const text& filename);
/**
* Remove a file from the list.
*/
void remove(const std::string& filename);
void remove(const text& filename);
/**
* Rename a file from the list.
*/
void rename(const std::string& oldname, const std::string& newname);
void rename(const text& oldname, const text& newname);
private:
filelist(const filelist&);
filelist& operator=(const filelist&);
std::map<std::string, int64_t> readfile();
void check_stale(std::map<std::string, int64_t>& data);
void writeback(const std::map<std::string, int64_t>& data);
std::string backingfile;
std::string directory;
std::map<text, int64_t> readfile();
void check_stale(std::map<text, int64_t>& data);
void writeback(const std::map<text, int64_t>& data);
text backingfile;
text directory;
};
#endif

View file

@ -24,7 +24,7 @@ public:
*
* Parameters backingfile: The backing file name.
*/
filesystem(const std::string& backingfile);
filesystem(const text& backingfile);
/**
* Allocate a new file.
*
@ -96,7 +96,7 @@ public:
*
* Parameters backingfile: The backing file.
*/
ref(const std::string& backingfile)
ref(const text& backingfile)
{
refcnt = NULL;
mlock = NULL;

View file

@ -28,18 +28,18 @@ public:
void render(uint8_t* buf, size_t stride, uint32_t u, uint32_t v, uint32_t w, uint32_t h) const;
};
font2();
font2(const std::string& file);
font2(const text& file);
font2(struct font& bfont);
void add(const std::u32string& key, const glyph& fglyph) throw(std::bad_alloc);
std::u32string best_ligature_match(const std::u32string& codepoints, size_t start) const
void add(const text& key, const glyph& fglyph) throw(std::bad_alloc);
text best_ligature_match(const text& codepoints, size_t start) const
throw(std::bad_alloc);
const glyph& lookup_glyph(const std::u32string& key) const throw();
const glyph& lookup_glyph(const text& key) const throw();
unsigned get_rowadvance() const throw() { return rowadvance; }
std::pair<uint32_t, uint32_t> get_metrics(const std::u32string& str, uint32_t xalign) const;
void for_each_glyph(const std::u32string& str, uint32_t xalign, std::function<void(uint32_t x, uint32_t y,
std::pair<uint32_t, uint32_t> get_metrics(const text& str, uint32_t xalign) const;
void for_each_glyph(const text& str, uint32_t xalign, std::function<void(uint32_t x, uint32_t y,
const glyph& g)> cb) const;
private:
std::map<std::u32string, glyph> glyphs;
std::map<text, glyph> glyphs;
unsigned rowadvance;
};
}

View file

@ -8,6 +8,7 @@
#include <map>
#include <set>
#include "framebuffer-pixfmt.hpp"
#include "text.hpp"
#include "threads.hpp"
#include "memtracker.hpp"
@ -141,7 +142,7 @@ struct raw
* parameter file: The filename to save to.
* throws std::runtime_error: Can't save the PNG.
*/
void save_png(const std::string& file) throw(std::bad_alloc, std::runtime_error);
void save_png(const text& file) throw(std::bad_alloc, std::runtime_error);
/**
* Get width.
*
@ -422,8 +423,8 @@ struct color
set_palette(default_shift_r << 1, default_shift_g << 1, default_shift_b << 1, true);
//std::cerr << "Color " << color << " -> hi=" << hi << " lo=" << lo << " inv=" << inv << std::endl;
}
color(const std::string& color) throw(std::bad_alloc, std::runtime_error);
static std::string stringify(int64_t number);
color(const text& color) throw(std::bad_alloc, std::runtime_error);
static text stringify(int64_t number);
void set_palette(unsigned rshift, unsigned gshift, unsigned bshift, bool X) throw();
template<bool X> void set_palette(struct fb<X>& s) throw()
{
@ -470,7 +471,7 @@ int64_t color_adjust_lightness(int64_t color, double adjust);
*/
struct basecolor
{
basecolor(const std::string& name, int64_t value);
basecolor(const text& name, int64_t value);
};
/**
@ -478,7 +479,7 @@ struct basecolor
*/
struct color_mod
{
color_mod(const std::string& name, std::function<void(int64_t&)> fn);
color_mod(const text& name, std::function<void(int64_t&)> fn);
};
/**
@ -540,7 +541,7 @@ struct font
* Parameter string: The string to get metrics of.
* Returns: A pair. First element is width of string, the second is height of string.
*/
std::pair<size_t, size_t> get_metrics(const std::string& string, uint32_t xalign, bool xdbl, bool ydbl)
std::pair<size_t, size_t> get_metrics(const text& string, uint32_t xalign, bool xdbl, bool ydbl)
throw();
/**
* Layout a string.
@ -548,14 +549,14 @@ struct font
* Parameter string: The string to get layout of.
* Returns: String layout.
*/
std::vector<layout> dolayout(const std::string& string) throw(std::bad_alloc);
std::vector<layout> dolayout(const text& string) throw(std::bad_alloc);
/**
* Get width of string.
*
* Parameter string: The string to get width of.
* Returns: The width.
*/
uint32_t get_width(const std::string& string);
uint32_t get_width(const text& string);
/**
* Get set of all glyph numbers.
*/
@ -576,7 +577,7 @@ struct font
* Parameter hdbl: If set, double width horizontally.
* Parameter vdbl: If set, double height vertically.
*/
template<bool X> void render(struct fb<X>& scr, int32_t x, int32_t y, const std::string& text,
template<bool X> void render(struct fb<X>& scr, int32_t x, int32_t y, const text& _text,
color fg, color bg, bool hdbl, bool vdbl) throw();
/**
* Call function on every glyph.
@ -585,7 +586,7 @@ struct font
* Parameter alignx: The x alignment.
* Parameter cb: The callback to call.
*/
void for_each_glyph(const std::string& str, uint32_t alignx, bool xdbl, bool ydbl,
void for_each_glyph(const text& str, uint32_t alignx, bool xdbl, bool ydbl,
std::function<void(uint32_t x, uint32_t y, const glyph& g, bool xdbl, bool ydbl)> cb);
/**
* Render to bitmap.
@ -597,7 +598,7 @@ struct font
* Parameter hdbl: If set, double width horizontally.
* Parameter vdbl: If set, double height vertically.
*/
void render(uint8_t* buf, size_t stride, const std::string& str, uint32_t alignx, bool hdbl, bool vdbl);
void render(uint8_t* buf, size_t stride, const text& str, uint32_t alignx, bool hdbl, bool vdbl);
private:
glyph bad_glyph;
uint32_t bad_glyph_data[4];

View file

@ -12,13 +12,13 @@ class pad
{
public:
pad(const JSON::node& state, unsigned jnum);
pad(const std::string& _name, unsigned jnum);
pad(const text& _name, unsigned jnum);
~pad();
unsigned add_axis(uint64_t id, int64_t min, int64_t max, bool pressure, const std::string& name);
unsigned add_button(uint64_t id, const std::string& name);
unsigned add_hat(uint64_t id, const std::string& name);
unsigned add_hat(uint64_t idx, uint64_t idy, int64_t mindev, const std::string& namex,
const std::string& namey);
unsigned add_axis(uint64_t id, int64_t min, int64_t max, bool pressure, const text& name);
unsigned add_button(uint64_t id, const text& name);
unsigned add_hat(uint64_t id, const text& name);
unsigned add_hat(uint64_t idx, uint64_t idy, int64_t mindev, const text& namex,
const text& namey);
unsigned axes() { return next_axis; }
unsigned buttons() { return next_button; }
unsigned hats() { return next_hat; }
@ -39,7 +39,7 @@ public:
void report_hat(uint64_t id, int angle);
void set_online(bool status);
bool online() { return online_flag; }
const std::string& name() { return _name; }
const text& name() { return _name; }
void set_axis_cb(std::function<void(unsigned jnum, unsigned num, int16_t val)> fn)
{
axis_fn = fn;
@ -53,7 +53,7 @@ public:
void set_newitem_cb(std::function<void(unsigned jnum, unsigned num, int type)> fn) { newitem_fn = fn; }
void load(const JSON::node& state);
JSON::node save();
std::string get_summary();
text get_summary();
private:
struct axis_info
{
@ -67,7 +67,7 @@ private:
bool pressure;
bool disabled;
bool online;
std::string name;
text name;
int16_t state;
int64_t rstate;
};
@ -75,7 +75,7 @@ private:
{
uint64_t id;
unsigned num;
std::string name;
text name;
bool online;
bool state;
};
@ -86,8 +86,8 @@ private:
uint64_t id2;
unsigned num;
int64_t mindev;
std::string name;
std::string name2;
text name;
text name2;
unsigned state;
bool online;
};
@ -99,7 +99,7 @@ private:
std::function<void(unsigned jnum, unsigned num, int mode, double tolerance)> amode_fn;
std::function<void(unsigned jnum, unsigned num, int type)> newitem_fn;
bool online_flag;
std::string _name;
text _name;
std::map<uint64_t, axis_info> _axes;
std::map<uint64_t, hat_info*> _axes_hat;
std::map<uint64_t, button_info> _buttons;
@ -120,13 +120,13 @@ public:
JSON::node save();
unsigned gamepads();
pad& operator[](unsigned gpnum);
unsigned add(const std::string& name);
unsigned add(const text& name);
void set_axis_cb(std::function<void(unsigned jnum, unsigned num, int16_t val)> fn);
void set_button_cb(std::function<void(unsigned jnum, unsigned num, bool val)> fn);
void set_hat_cb(std::function<void(unsigned jnum, unsigned num, unsigned val)> fn);
void set_axismode_cb(std::function<void(unsigned jnum, unsigned num, int mode, double tolerance)> fn);
void set_newitem_cb(std::function<void(unsigned jnum, unsigned num, int type)> fn);
std::string get_summary();
text get_summary();
void offline_all();
private:
set(const set&);

View file

@ -5,6 +5,7 @@
#include <string>
#include <cstdlib>
#include <stdexcept>
#include "text.hpp"
namespace hex
{
@ -17,7 +18,7 @@ namespace hex
* Returns: Hex string.
* Throws std::bad_alloc: Not enough memory.
*/
std::string b_to(const uint8_t* data, size_t datalen, bool uppercase = false) throw(std::bad_alloc);
text b_to(const uint8_t* data, size_t datalen, bool uppercase = false) throw(std::bad_alloc);
/**
* Transform unsigned integer into full-width hexadecimal.
@ -27,7 +28,7 @@ std::string b_to(const uint8_t* data, size_t datalen, bool uppercase = false) th
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
template<typename T> std::string to(T data, bool prefix = false) throw(std::bad_alloc);
template<typename T> text to(T data, bool prefix = false) throw(std::bad_alloc);
/**
* Transform uint8 into full-width hexadecimal.
@ -37,7 +38,7 @@ template<typename T> std::string to(T data, bool prefix = false) throw(std::bad_
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
inline std::string to8(uint8_t data, bool prefix = false) throw(std::bad_alloc) { return to<uint8_t>(data, prefix); }
inline text to8(uint8_t data, bool prefix = false) throw(std::bad_alloc) { return to<uint8_t>(data, prefix); }
/**
* Transform uint16 into full-width hexadecimal.
@ -47,7 +48,7 @@ inline std::string to8(uint8_t data, bool prefix = false) throw(std::bad_alloc)
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
inline std::string to16(uint16_t data, bool prefix = false) throw(std::bad_alloc)
inline text to16(uint16_t data, bool prefix = false) throw(std::bad_alloc)
{
return to<uint16_t>(data, prefix);
}
@ -60,7 +61,7 @@ inline std::string to16(uint16_t data, bool prefix = false) throw(std::bad_alloc
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
std::string to24(uint32_t data, bool prefix = false) throw(std::bad_alloc);
text to24(uint32_t data, bool prefix = false) throw(std::bad_alloc);
/**
* Transform uint32 into full-width hexadecimal.
@ -70,7 +71,7 @@ std::string to24(uint32_t data, bool prefix = false) throw(std::bad_alloc);
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
inline std::string to32(uint32_t data, bool prefix = false) throw(std::bad_alloc)
inline text to32(uint32_t data, bool prefix = false) throw(std::bad_alloc)
{
return to<uint32_t>(data, prefix);
}
@ -83,7 +84,7 @@ inline std::string to32(uint32_t data, bool prefix = false) throw(std::bad_alloc
* Returns: The hex string.
* Throws std::bad_alloc: Not enough memory.
*/
inline std::string to64(uint64_t data, bool prefix = false) throw(std::bad_alloc)
inline text to64(uint64_t data, bool prefix = false) throw(std::bad_alloc)
{
return to<uint64_t>(data, prefix);
}
@ -95,7 +96,7 @@ inline std::string to64(uint64_t data, bool prefix = false) throw(std::bad_alloc
* Parameter hex: The hexadecimal string.
* Throws std::runtime_error: Bad hexadecimal character in string.
*/
void b_from(uint8_t* buf, const std::string& hex) throw(std::runtime_error);
void b_from(uint8_t* buf, const text& hex) throw(std::runtime_error);
/**
* Transform hexadecimal into unsigned integer.
@ -103,7 +104,7 @@ void b_from(uint8_t* buf, const std::string& hex) throw(std::runtime_error);
* Parameter hex: The hexadecimal string.
* Throws std::runtime_error: Bad hexadecimal character in string.
*/
template<typename T> T from(const std::string& hex) throw(std::runtime_error);
template<typename T> T from(const text& hex) throw(std::runtime_error);
}
#endif

View file

@ -2,6 +2,7 @@
#define _library__httpauth__hpp__included__
#include "skein.hpp"
#include "text.hpp"
#include <string>
#include <cstring>
#include <list>
@ -22,7 +23,7 @@ public:
/**
* Construct.
*/
request_hash(const std::string& _id, const uint8_t* _key, unsigned _nonce, skein::hash _h,
request_hash(const text& _id, const uint8_t* _key, unsigned _nonce, skein::hash _h,
const uint8_t* _prereq)
: id(_id), nonce(_nonce), h(_h)
{
@ -39,9 +40,9 @@ public:
/**
* Read the final Authorization header.
*/
std::string get_authorization();
text get_authorization();
private:
std::string id;
text id;
uint8_t pubkey[32];
uint8_t prereq[8];
unsigned nonce;
@ -62,20 +63,20 @@ public:
*
* Returns: The value for Authorization header.
*/
std::string format_get_session_request();
text format_get_session_request();
/**
* Start request hash computation. Hashes in the shared secret and nonce. The nonce is incremented.
*
* Parameter url: The notional URL.
* Returns: The skein hash instance.
*/
request_hash start_request(const std::string& url, const std::string& verb);
request_hash start_request(const text& url, const text& verb);
/**
* Parse session auth response. If it contains new session parameters, the session is updated.
*
* Parameter response: The response from server (WWW-Authenticate).
*/
void parse_auth_response(const std::string& response);
void parse_auth_response(const text& response);
/**
* Is the session ready?
*/
@ -85,11 +86,11 @@ public:
*/
void get_pubkey(uint8_t* pubkey);
private:
void parse_auth_response(std::map<std::string, std::string> pparse);
void parse_auth_response(std::map<text, text> pparse);
unsigned char privkey[32];
unsigned char pubkey[32];
unsigned char ssecret[32];
std::string id;
text id;
unsigned nonce;
bool ready; //id&ssecret is valid.
};

View file

@ -6,6 +6,7 @@
#include <cstdlib>
#include <map>
#include <string>
#include "text.hpp"
#include "threads.hpp"
class http_request
@ -60,7 +61,7 @@ public:
/**
* Sink header.
*/
virtual void header(const std::string& name, const std::string& cotent) = 0;
virtual void header(const text& name, const text& cotent) = 0;
/**
* Sink data.
*/
@ -80,17 +81,17 @@ public:
class www_authenticate_extractor : public output_handler
{
public:
www_authenticate_extractor(std::function<void(const std::string& value)> _callback);
www_authenticate_extractor(std::function<void(const text& value)> _callback);
~www_authenticate_extractor();
void header(const std::string& name, const std::string& cotent);
void header(const text& name, const text& cotent);
void write(const char* source, size_t srcsize);
private:
std::function<void(const std::string& value)> callback;
std::function<void(const text& value)> callback;
};
/**
* Create a new request instance.
*/
http_request(const std::string& verb, const std::string& url);
http_request(const text& verb, const text& url);
/**
* Destructor.
*/
@ -98,7 +99,7 @@ public:
/**
* Set the authorization header to use.
*/
void set_authorization(const std::string& hdr)
void set_authorization(const text& hdr)
{
authorization = hdr;
}
@ -126,7 +127,7 @@ private:
http_request(const http_request&);
http_request& operator=(const http_request&);
void* handle;
std::string authorization;
text authorization;
bool has_body;
double dltotal, dlnow, ultotal, ulnow;
};
@ -139,12 +140,12 @@ struct http_async_request
http_async_request();
http_request::input_handler* ihandler; //Input handler (INPUT).
http_request::output_handler* ohandler; //Output handler (INPUT).
std::string verb; //HTTP verb (INPUT)
std::string url; //URL to access (INPUT)
std::string authorization; //Authorization to use (INPUT)
text verb; //HTTP verb (INPUT)
text url; //URL to access (INPUT)
text authorization; //Authorization to use (INPUT)
int64_t final_dl; //Final amount downloaded (OUTPUT).
int64_t final_ul; //Final amound uploaded (OUTPUT).
std::string errormsg; //Final error (OUTPUT).
text errormsg; //Final error (OUTPUT).
long http_code; //HTTP error code (OUTPUT).
volatile bool finished; //Finished flag (semi-transient).
threads::cv finished_cond; //This condition variable is fired on finish.
@ -169,17 +170,17 @@ struct property_upload_request : public http_request::input_handler
/**
* Data to upload.
*/
std::map<std::string, std::string> data;
std::map<text, text> data;
private:
unsigned state;
std::map<std::string, std::string>::iterator itr;
std::map<text, text>::iterator itr;
size_t sent;
void str_helper(const std::string& str, char*& target, size_t& maxread, size_t& x, unsigned next);
void str_helper(const text& str, char*& target, size_t& maxread, size_t& x, unsigned next);
void chr_helper(char ch, char*& target, size_t& maxread, size_t& x, unsigned next);
void len_helper(size_t len, char*& target, size_t& maxread, size_t& x, unsigned next);
};
//Lowercase a string.
std::string http_strlower(const std::string& name);
text http_strlower(const text& name);
#endif

View file

@ -7,6 +7,7 @@
#include <vector>
#include <stdexcept>
#include <map>
#include "text.hpp"
#include "utf8.hpp"
namespace JSON
@ -27,8 +28,7 @@ struct number_tag
struct string_tag
{
const static int id = 3;
node operator()(const std::string& s) const;
node operator()(const std::u32string& s) const;
node operator()(const text& s) const;
bool operator==(const int& n) const { return n == id; }
bool operator!=(const int& n) const { return !(*this == n); }
operator int() { return id; }
@ -89,8 +89,8 @@ node i(int64_t n);
node u(uint64_t n);
node f(double n);
node b(bool bl);
node s(const std::string& st);
node s(const std::u32string& st);
node s(const text& st);
node s(const text& st);
node n();
enum errorcode
@ -156,7 +156,7 @@ extern const char* state_desc[];
struct error : public std::runtime_error
{
error(errorcode _code) : runtime_error(error_desc[_code]), code(_code), state(PARSE_NOT_PARSING),
position(std::string::npos) {}
position((size_t)(ssize_t)-1) {}
error(errorcode _code, parsestate _state, size_t pos) : runtime_error(error_desc[_code]), code(_code),
state(_state), position(pos) {}
errorcode get_code() { return code; }
@ -165,7 +165,7 @@ struct error : public std::runtime_error
std::pair<size_t, size_t> get_position_lc(const std::string& doc) { return get_position_lc(doc, position); }
std::pair<size_t, size_t> get_position_lc(const std::string& doc, size_t pos);
const char* what() const throw();
std::string extended_error(const std::string& doc);
text extended_error(const std::string& doc);
private:
errorcode code;
parsestate state;
@ -182,28 +182,22 @@ class pointer
{
public:
pointer();
pointer(const std::string& ptr) throw(std::bad_alloc);
pointer(const std::u32string& ptr) throw(std::bad_alloc);
pointer(const text& ptr) throw(std::bad_alloc);
pointer pastend() const throw(std::bad_alloc) { return field(U"-"); }
pointer& pastend_inplace() throw(std::bad_alloc) { return field_inplace(U"-"); }
pointer index(uint64_t idx) const throw(std::bad_alloc);
pointer& index_inplace(uint64_t idx) throw(std::bad_alloc);
pointer field(const std::string& fld) const throw(std::bad_alloc) { return field(utf8::to32(fld)); }
pointer& field_inplace(const std::string& fld) throw(std::bad_alloc)
{
return field_inplace(utf8::to32(fld));
}
pointer field(const std::u32string& fld) const throw(std::bad_alloc);
pointer& field_inplace(const std::u32string& fld) throw(std::bad_alloc);
pointer field(const text& fld) const throw(std::bad_alloc);
pointer& field_inplace(const text& fld) throw(std::bad_alloc);
pointer remove() const throw(std::bad_alloc);
pointer& remove_inplace() throw(std::bad_alloc);
std::string as_string8() const { return utf8::to8(_pointer); }
std::u32string as_string() const { return _pointer; }
text as_string8() const { return utf8::to8(_pointer); }
text as_string() const { return _pointer; }
friend std::ostream& operator<<(std::ostream& s, const pointer& p);
friend std::basic_ostream<char32_t>& operator<<(std::basic_ostream<char32_t>& s, const pointer& p);
private:
friend class node;
std::u32string _pointer;
text _pointer;
};
/**
@ -216,11 +210,11 @@ public:
/**
* Print a value that is null, boolean or integer.
*/
virtual std::string value_val(const std::string& val);
virtual std::string value_val(const text& val);
/**
* Print a string value.
*/
virtual std::string value_string(const std::u32string& s);
virtual std::string value_string(const text& s);
/**
* Print beginning of array.
*/
@ -240,7 +234,7 @@ public:
/**
* Print key in object.
*/
virtual std::string object_key(const std::u32string& s);
virtual std::string object_key(const text& s);
/**
* Print field separator in object.
*/
@ -259,13 +253,13 @@ class printer_indenting : public printer
public:
printer_indenting();
~printer_indenting() throw();
std::string value_val(const std::string& val);
std::string value_string(const std::u32string& s);
std::string value_val(const text& val);
std::string value_string(const text& s);
std::string array_begin();
std::string array_separator();
std::string array_end();
std::string object_begin();
std::string object_key(const std::u32string& s);
std::string object_key(const text& s);
std::string object_separator();
std::string object_end();
private:
@ -299,8 +293,7 @@ public:
*/
node(null_tag) throw();
node(boolean_tag, bool b) throw();
node(string_tag, const std::u32string& str) throw(std::bad_alloc);
node(string_tag, const std::string& str) throw(std::bad_alloc);
node(string_tag, const text& str) throw(std::bad_alloc);
node(number_tag, double n) throw();
node(number_tag, int64_t n) throw();
node(number_tag, uint64_t n) throw();
@ -330,11 +323,7 @@ public:
/**
* Get type of node by pointer.
*/
int type_of(const std::u32string& pointer) const throw(std::bad_alloc);
int type_of(const std::string& pointer) const throw(std::bad_alloc)
{
return type_of(utf8::to32(pointer));
}
int type_of(const text& pointer) const throw(std::bad_alloc);
int type_of(const pointer& ptr) const throw(std::bad_alloc)
{
return type_of(ptr._pointer);
@ -342,11 +331,7 @@ public:
/**
* Get type of node by pointer (indirect).
*/
int type_of_indirect(const std::u32string& pointer) const throw(std::bad_alloc);
int type_of_indirect(const std::string& pointer) const throw(std::bad_alloc)
{
return type_of_indirect(utf8::to32(pointer));
}
int type_of_indirect(const text& pointer) const throw(std::bad_alloc);
int type_of_indirect(const pointer& ptr) const throw(std::bad_alloc)
{
return type_of_indirect(ptr._pointer);
@ -354,11 +339,7 @@ public:
/**
* Resolve an indirect pointer
*/
std::u32string resolve_indirect(const std::u32string& pointer) const throw(std::bad_alloc);
std::string resolve_indirect(const std::string& pointer) const throw(std::bad_alloc)
{
return utf8::to8(resolve_indirect(utf8::to32(pointer)));
}
text resolve_indirect(const text& pointer) const throw(std::bad_alloc);
pointer resolve_indirect(const pointer& ptr) const throw(std::bad_alloc)
{
return pointer(resolve_indirect(ptr._pointer));
@ -378,8 +359,8 @@ public:
/**
* Read the string as UTF-8 (NT_STRING).
*/
const std::u32string& as_string() const throw(std::bad_alloc, error);
std::string as_string8() const throw(std::bad_alloc, error) { return utf8::to8(as_string()); }
const text& as_string() const throw(std::bad_alloc, error);
text as_string8() const throw(std::bad_alloc, error) { return utf8::to8(as_string()); }
/**
* Get boolean value (NT_BOOLEAN).
*/
@ -401,48 +382,32 @@ public:
/**
* Read number of indices in object key (NT_OBJECT).
*/
size_t field_count(const std::u32string& key) const throw(error);
size_t field_count(const std::string& key) const throw(std::bad_alloc, error)
{
return field_count(utf8::to32(key));
}
size_t field_count(const text& key) const throw(error);
/**
* Specified field exists (NT_OBJECT)
*/
bool field_exists(const std::u32string& key) const throw(error);
bool field_exists(const std::string& key) const throw(std::bad_alloc, error)
{
return field_exists(utf8::to32(key));
}
bool field_exists(const text& key) const throw(error);
/**
* Read specified key from object (NT_OBJECT).
*/
const node& field(const std::u32string& key, size_t subindex = 0) const throw(error)
const node& field(const text& key, size_t subindex = 0) const throw(error)
{
const node* n;
auto e = field_soft(key, subindex, n);
if(e != ERR_OK) throw error(e);
return *n;
}
const node& field(const std::string& key, size_t subindex = 0) const throw(std::bad_alloc, error)
{
return field(utf8::to32(key), subindex);
}
/**
* Apply JSON pointer (RFC 6901).
*/
const node& follow(const std::u32string& pointer) const throw(std::bad_alloc, error)
const node& follow(const text& pointer) const throw(std::bad_alloc, error)
{
const node* n;
auto e = follow_soft(pointer, n);
if(e != ERR_OK) throw error(e);
return *n;
}
const node& follow(const std::string& pointer) const throw(std::bad_alloc, error)
{
return follow(utf8::to32(pointer));
}
const node& follow(const pointer& ptr) const throw(std::bad_alloc, error)
{
return follow(ptr._pointer);
@ -450,14 +415,10 @@ public:
/**
* Apply JSON pointer (RFC 6901) following strings as indirect references.
*/
const node& follow_indirect(const std::u32string& pointer) const throw(std::bad_alloc, error)
const node& follow_indirect(const text& pointer) const throw(std::bad_alloc, error)
{
return follow(resolve_indirect(pointer));
}
const node& follow_indirect(const std::string& pointer) const throw(std::bad_alloc, error)
{
return follow_indirect(utf8::to32(pointer));
}
const node& follow_indirect(const pointer& ptr) const throw(std::bad_alloc, error)
{
return follow_indirect(ptr._pointer);
@ -474,11 +435,7 @@ public:
node& set(number_tag, double number) throw();
node& set(number_tag, int64_t number) throw();
node& set(number_tag, uint64_t number) throw();
node& set(string_tag, const std::u32string& key) throw(std::bad_alloc);
node& set(string_tag tag, const std::string& key) throw(std::bad_alloc)
{
return set(tag, utf8::to32(key));
}
node& set(string_tag, const text& key) throw(std::bad_alloc);
/**
* Read/Write specified index from array (NT_ARRAY).
*/
@ -496,39 +453,27 @@ public:
/**
* Read/Write specified key from object (NT_OBJECT).
*/
node& field(const std::u32string& key, size_t subindex = 0) throw(error)
node& field(const text& key, size_t subindex = 0) throw(error)
{
node* n;
auto e = field_soft(key, subindex, n);
if(e != ERR_OK) throw error(e);
return *n;
}
node& field(const std::string& key, size_t subindex = 0) throw(std::bad_alloc, error)
{
return field(utf8::to32(key), subindex);
}
/**
* Insert new element to object (NT_OBJECT).
*/
node& insert(const std::u32string& key, const node& node) throw(std::bad_alloc, error);
node& insert(const std::string& key, const node& node) throw(std::bad_alloc, error)
{
return insert(utf8::to32(key), node);
}
node& insert(const text& key, const node& node) throw(std::bad_alloc, error);
/**
* Apply JSON pointer (RFC 6901).
*/
node& follow(const std::u32string& pointer) throw(std::bad_alloc, error)
node& follow(const text& pointer) throw(std::bad_alloc, error)
{
node* n;
auto e = follow_soft(pointer, n);
if(e != ERR_OK) throw error(e);
return *n;
}
node& follow(const std::string& pointer) throw(std::bad_alloc, error)
{
return follow(utf8::to32(pointer));
}
node& follow(const pointer& ptr) throw(std::bad_alloc, error)
{
return follow(ptr._pointer);
@ -536,14 +481,10 @@ public:
/**
* Apply JSON pointer (RFC 6901) following strings as indirect references.
*/
node& follow_indirect(const std::u32string& pointer) throw(std::bad_alloc, error)
node& follow_indirect(const text& pointer) throw(std::bad_alloc, error)
{
return follow(resolve_indirect(pointer));
}
node& follow_indirect(const std::string& pointer) throw(std::bad_alloc, error)
{
return follow_indirect(utf8::to32(pointer));
}
node& follow_indirect(const pointer& ptr) throw(std::bad_alloc, error)
{
return follow_indirect(ptr._pointer);
@ -551,11 +492,7 @@ public:
/**
* Return node specified by JSON pointer (RFC 6901). If the last component doesn't exist, it is created as NULL.
*/
node& operator[](const std::u32string& pointer) throw(std::bad_alloc, error);
node& operator[](const std::string& pointer) throw(std::bad_alloc, error)
{
return (*this)[utf8::to32(pointer)];
}
node& operator[](const text& pointer) throw(std::bad_alloc, error);
node& operator[](const pointer& ptr) throw(std::bad_alloc, error)
{
return (*this)[ptr._pointer];
@ -563,11 +500,7 @@ public:
/**
* Create node at specified pointer and return it.
*/
node& insert_node(const std::u32string& pointer, const node& nwn) throw(std::bad_alloc, error);
node& insert_node(const std::string& pointer, const node& nwn) throw(std::bad_alloc, error)
{
return insert_node(utf8::to32(pointer), nwn);
}
node& insert_node(const text& pointer, const node& nwn) throw(std::bad_alloc, error);
node& insert_node(const pointer& ptr, const node& nwn) throw(std::bad_alloc, error)
{
return insert_node(ptr._pointer, nwn);
@ -575,11 +508,7 @@ public:
/**
* Delete a node by pointer and return what was deleted.
*/
node delete_node(const std::u32string& pointer) throw(std::bad_alloc, error);
node delete_node(const std::string& pointer) throw(std::bad_alloc, error)
{
return delete_node(utf8::to32(pointer));
}
node delete_node(const text& pointer) throw(std::bad_alloc, error);
node delete_node(const pointer& ptr) throw(std::bad_alloc, error)
{
return delete_node(ptr._pointer);
@ -587,11 +516,7 @@ public:
/**
* Synonym for follow().
*/
const node& operator[](const std::u32string& pointer) const throw(std::bad_alloc, error)
{
return follow(pointer);
}
const node& operator[](const std::string& pointer) const throw(std::bad_alloc, error)
const node& operator[](const text& pointer) const throw(std::bad_alloc, error)
{
return follow(pointer);
}
@ -606,19 +531,11 @@ public:
/**
* Delete an array field. The rest are shifted.
*/
void erase_field(const std::u32string& fld, size_t idx = 0) throw(error);
void erase_field(const std::string& fld, size_t idx = 0) throw(std::bad_alloc, error)
{
erase_field(utf8::to32(fld), idx);
}
void erase_field(const text& fld, size_t idx = 0) throw(error);
/**
* Delete an entiere array field.
*/
void erase_field_all(const std::u32string& fld) throw(error);
void erase_field_all(const std::string& fld) throw(std::bad_alloc, error)
{
erase_field_all(utf8::to32(fld));
}
void erase_field_all(const text& fld) throw(error);
/**
* Apply a JSON patch.
*/
@ -640,8 +557,7 @@ public:
typedef node* pointer;
iterator() throw();
iterator(node& n) throw(error);
std::u32string key() throw(std::bad_alloc, error);
std::string key8() throw(std::bad_alloc, error) { return utf8::to8(key()); }
text key() throw(std::bad_alloc, error);
size_t index() throw(error);
node& operator*() throw(error);
node* operator->() throw(error);
@ -653,7 +569,7 @@ public:
friend class node;
node* n;
size_t idx;
std::u32string _key;
text _key;
};
/**
* Constant iterator.
@ -668,8 +584,7 @@ public:
typedef const node* pointer;
const_iterator() throw();
const_iterator(const node& n) throw(error);
std::u32string key() throw(std::bad_alloc, error);
std::string key8() throw(std::bad_alloc, error) { return utf8::to8(key()); }
text key() throw(std::bad_alloc, error);
size_t index() throw(error);
const node& operator*() throw(error);
const node* operator->() throw(error);
@ -680,7 +595,7 @@ public:
private:
const node* n;
size_t idx;
std::u32string _key;
text _key;
};
/**
* Iterators
@ -727,7 +642,7 @@ private:
node(const std::string& doc, size_t& ptr, size_t len) throw(std::bad_alloc, error);
template<typename T> void set_helper(T v)
{
std::u32string tmp;
text tmp;
vtype = number;
_number.from<T>(v);
std::swap(_string, tmp);
@ -744,14 +659,14 @@ private:
int vtype;
number_holder _number;
bool _boolean;
std::u32string _string;
text _string;
std::list<node> xarray;
std::vector<node*> xarray_index;
std::map<std::u32string, std::list<node>> xobject;
errorcode follow_soft(const std::u32string& pointer, const node*& out) const throw(std::bad_alloc);
errorcode follow_soft(const std::u32string& pointer, node*& out) throw(std::bad_alloc);
errorcode field_soft(const std::u32string& key, size_t subindex, node*& out) throw();
errorcode field_soft(const std::u32string& key, size_t subindex, const node*& out) const throw();
std::map<text, std::list<node>> xobject;
errorcode follow_soft(const text& pointer, const node*& out) const throw(std::bad_alloc);
errorcode follow_soft(const text& pointer, node*& out) throw(std::bad_alloc);
errorcode field_soft(const text& key, size_t subindex, node*& out) throw();
errorcode field_soft(const text& key, size_t subindex, const node*& out) const throw();
errorcode index_soft(size_t index, node*& out) throw();
errorcode index_soft(size_t index, const node*& out) const throw();
};

View file

@ -17,7 +17,7 @@ namespace keyboard
class invbind;
class ctrlrkey;
std::pair<key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const std::string& name,
std::pair<key*, unsigned> keymapper_lookup_subkey(keyboard& kbd, const text& name,
bool axis) throw(std::bad_alloc, std::runtime_error);
/**
@ -34,11 +34,11 @@ struct keyspec
*
* Parameter keyspec: The key specifier.
*/
keyspec(const std::string& keyspec) throw(std::bad_alloc, std::runtime_error);
keyspec(const text& keyspec) throw(std::bad_alloc, std::runtime_error);
/**
* Get the key specifier as a keyspec.
*/
operator std::string() throw(std::bad_alloc);
operator text() throw(std::bad_alloc);
/**
* Is valid?
*/
@ -62,15 +62,15 @@ struct keyspec
/**
* The modifier.
*/
std::string mod;
text mod;
/**
* The mask.
*/
std::string mask;
text mask;
/**
* The key itself.
*/
std::string key;
text key;
};
class invbind_set;
@ -97,11 +97,11 @@ public:
/**
* New item in set.
*/
virtual void create(invbind_set& s, const std::string& name, invbind_info& ibinfo) = 0;
virtual void create(invbind_set& s, const text& name, invbind_info& ibinfo) = 0;
/**
* Deleted item from set.
*/
virtual void destroy(invbind_set& s, const std::string& name) = 0;
virtual void destroy(invbind_set& s, const text& name) = 0;
/**
* Destroyed the entiere set.
*/
@ -118,11 +118,11 @@ public:
/**
* Register a inverse bind.
*/
void do_register(const std::string& name, invbind_info& info);
void do_register(const text& name, invbind_info& info);
/**
* Unregister a inverse bind.
*/
void do_unregister(const std::string& name, invbind_info& info);
void do_unregister(const text& name, invbind_info& info);
/**
* Add a callback on new invese bind.
*/
@ -157,7 +157,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: The binding would conflict with existing one or invalid modifier/key.
*/
void bind(std::string mod, std::string modmask, std::string keyname, std::string command)
void bind(text mod, text modmask, text keyname, text command)
throw(std::bad_alloc, std::runtime_error);
/**
* Unbinds a key, erroring out if binding does not exist.
@ -168,7 +168,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: The binding does not exist.
*/
void unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
void unbind(text mod, text modmask, text keyname) throw(std::bad_alloc,
std::runtime_error);
/**
* Get keys bound.
@ -179,14 +179,14 @@ public:
/**
* Get command for key.
*/
std::string get(const keyspec& keyspec) throw(std::bad_alloc);
text get(const keyspec& keyspec) throw(std::bad_alloc);
/**
* Bind command for key.
*
* Parameter keyspec: The key specifier to bind to.
* Parameter cmd: The command to bind. If "", the key is unbound.
*/
void set(const keyspec& keyspec, const std::string& cmd) throw(std::bad_alloc, std::runtime_error);
void set(const keyspec& keyspec, const text& cmd) throw(std::bad_alloc, std::runtime_error);
/**
* Get set of inverse binds.
*
@ -199,7 +199,7 @@ public:
* Parameter command: The command.
* Returns: The inverse bind, or NULL if none.
*/
invbind* get_inverse(const std::string& command) throw(std::bad_alloc);
invbind* get_inverse(const text& command) throw(std::bad_alloc);
/**
* Get set of controller keys.
*
@ -209,7 +209,7 @@ public:
/**
* Get specific controller key.
*/
ctrlrkey* get_controllerkey(const std::string& command) throw(std::bad_alloc);
ctrlrkey* get_controllerkey(const text& command) throw(std::bad_alloc);
/**
* Get list of controller keys for specific keyboard key.
*/
@ -217,19 +217,19 @@ public:
/**
* Register inverse bind.
*/
void do_register(const std::string& name, invbind& bind) throw(std::bad_alloc);
void do_register(const text& name, invbind& bind) throw(std::bad_alloc);
/**
* Unregister inverse bind.
*/
void do_unregister(const std::string& name, invbind& bind) throw(std::bad_alloc);
void do_unregister(const text& name, invbind& bind) throw(std::bad_alloc);
/**
* Register controller key.
*/
void do_register(const std::string& name, ctrlrkey& ckey) throw(std::bad_alloc);
void do_register(const text& name, ctrlrkey& ckey) throw(std::bad_alloc);
/**
* Unregister inverse bind.
*/
void do_unregister(const std::string& name, ctrlrkey& ckey) throw(std::bad_alloc);
void do_unregister(const text& name, ctrlrkey& ckey) throw(std::bad_alloc);
/**
* Get keyboard.
*/
@ -245,7 +245,7 @@ public:
* Parameter polarity: Polarity (true is rising edge, false is falling edge).
* Returns: The fixed command, or "" if nothing should be run.
*/
static std::string fixup_command_polarity(std::string cmd, bool polarity) throw(std::bad_alloc);
static text fixup_command_polarity(text cmd, bool polarity) throw(std::bad_alloc);
/**
* Add a set of inverse binds.
*/
@ -281,13 +281,13 @@ private:
public:
listener(mapper& _grp);
~listener();
void create(invbind_set& s, const std::string& name, invbind_info& ibinfo);
void destroy(invbind_set& s, const std::string& name);
void create(invbind_set& s, const text& name, invbind_info& ibinfo);
void destroy(invbind_set& s, const text& name);
void kill(invbind_set& s);
private:
mapper& grp;
} _listener;
void change_command(const keyspec& spec, const std::string& old, const std::string& newc);
void change_command(const keyspec& spec, const text& old, const text& newc);
void on_key_event(modifier_set& mods, key& key, event& event);
void on_key_event_subkey(modifier_set& mods, key& key, unsigned skey, bool polarity);
mapper(const mapper&);
@ -311,7 +311,7 @@ public:
* Parameter _command: Command this is for.
* Parameter _name: Name of inverse key.
*/
invbind_info(invbind_set& set, const std::string& _command, const std::string& _name)
invbind_info(invbind_set& set, const text& _command, const text& _name)
throw(std::bad_alloc);
/**
* Destructor.
@ -327,8 +327,8 @@ public:
void set_died();
private:
invbind_set* in_set;
std::string command;
std::string name;
text command;
text name;
};
/**
@ -344,7 +344,7 @@ public:
* Parameter command: Command this is for.
* Parameter name: Name of inverse key.
*/
invbind(mapper& kmapper, const std::string& command, const std::string& name, bool dynamic = false)
invbind(mapper& kmapper, const text& command, const text& name, bool dynamic = false)
throw(std::bad_alloc);
/**
* Destructor.
@ -374,7 +374,7 @@ public:
*
* Returns: The name.
*/
std::string getname() throw(std::bad_alloc);
text getname() throw(std::bad_alloc);
/**
* Notify mapper dying.
*/
@ -385,8 +385,8 @@ private:
invbind& operator=(const invbind&);
void addkey(const keyspec& keyspec);
mapper* _mapper;
std::string cmd;
std::string oname;
text cmd;
text oname;
std::vector<keyspec> specs;
bool is_dynamic;
};
@ -407,7 +407,7 @@ public:
* Parameter name: Name of controller key.
* Parameter axis: If true, create a axis-type key.
*/
ctrlrkey(mapper& kmapper, const std::string& command, const std::string& name,
ctrlrkey(mapper& kmapper, const text& command, const text& name,
bool axis = false) throw(std::bad_alloc);
/**
* Destructor.
@ -420,7 +420,7 @@ public:
/**
* Get the trigger key.
*/
std::string get_string(unsigned index) throw(std::bad_alloc);
text get_string(unsigned index) throw(std::bad_alloc);
/**
* Set the trigger key (appends).
*/
@ -428,7 +428,7 @@ public:
/**
* Set the trigger key (appends).
*/
void append(const std::string& key) throw(std::bad_alloc, std::runtime_error);
void append(const text& key) throw(std::bad_alloc, std::runtime_error);
/**
* Remove the trigger key.
*/
@ -436,11 +436,11 @@ public:
/**
* Get the command.
*/
const std::string& get_command() const throw() { return cmd; }
const text& get_command() const throw() { return cmd; }
/**
* Get the name.
*/
const std::string& get_name() const throw() { return oname; }
const text& get_name() const throw() { return oname; }
/**
* Is axis-type?
*/
@ -448,8 +448,8 @@ public:
private:
void on_key_event(modifier_set& mods, key& key, event& event);
mapper& _mapper;
std::string cmd;
std::string oname;
text cmd;
text oname;
std::vector<std::pair<key*, unsigned>> keys;
bool axis;
};

View file

@ -7,6 +7,7 @@
#include <vector>
#include <list>
#include <stdexcept>
#include "text.hpp"
namespace keyboard
{
@ -41,14 +42,14 @@ public:
* Returns: The modifier.
* Throws std::runtime_error: No such modifier.
*/
modifier& lookup_modifier(const std::string& name) throw(std::runtime_error);
modifier& lookup_modifier(const text& name) throw(std::runtime_error);
/**
* Try lookup modifier by name.
*
* Parameter name: The name of the modifier.
* Returns: The modifier, or NULL if not found.
*/
modifier* try_lookup_modifier(const std::string& name) throw();
modifier* try_lookup_modifier(const text& name) throw();
/**
* Look up all modifiers.
*
@ -61,13 +62,13 @@ public:
* Parameter name: The name of the modifier.
* Parameter mod: The modifier.
*/
void do_register(const std::string& name, modifier& mod) throw(std::bad_alloc);
void do_register(const text& name, modifier& mod) throw(std::bad_alloc);
/**
* Unregister a modifier.
*
* Parameter name: The name of the modifier.
*/
void do_unregister(const std::string& name, modifier& mod) throw();
void do_unregister(const text& name, modifier& mod) throw();
/**
* Lookup key by name.
*
@ -75,14 +76,14 @@ public:
* Returns: The key.
* Throws std::runtime_error: No such key.
*/
key& lookup_key(const std::string& name) throw(std::runtime_error);
key& lookup_key(const text& name) throw(std::runtime_error);
/**
* Try lookup key by name.
*
* Parameter name: The name of the key.
* Returns: The key, or NULL if not found.
*/
key* try_lookup_key(const std::string& name) throw();
key* try_lookup_key(const text& name) throw();
/**
* Look up all keys.
*
@ -95,13 +96,13 @@ public:
* Parameter name: The name of the key.
* Parameter mod: The key.
*/
void do_register(const std::string& name, key& mod) throw(std::bad_alloc);
void do_register(const text& name, key& mod) throw(std::bad_alloc);
/**
* Unregister a key.
*
* Parameter name: The name of the key.
*/
void do_unregister(const std::string& name, key& mod) throw();
void do_unregister(const text& name, key& mod) throw();
/**
* Set exclusive listener for all keys at once.
*/
@ -132,7 +133,7 @@ public:
* Parameter keyb: The keyboard these will be on.
* Parameter _name: The name of the modifier.
*/
modifier(keyboard& keyb, const std::string& _name) throw(std::bad_alloc)
modifier(keyboard& keyb, const text& _name) throw(std::bad_alloc)
: kbd(keyb), name(_name)
{
keyb.do_register(name, *this);
@ -144,7 +145,7 @@ public:
* Parameter _name: The name of the modifier.
* Parameter _link: The name of the modifier group this is in.
*/
modifier(keyboard& keyb, const std::string& _name, const std::string& _link) throw(std::bad_alloc)
modifier(keyboard& keyb, const text& _name, const text& _link) throw(std::bad_alloc)
: kbd(keyb), name(_name), link(_link)
{
keyb.do_register(name, *this);
@ -163,13 +164,13 @@ public:
/**
* Get name of the modifier.
*/
const std::string& get_name() const throw() { return name; }
const text& get_name() const throw() { return name; }
/**
* Get linked name of the modifier.
*
* Returns: The linked name, or "" if none.
*/
const std::string& get_link_name() const throw() { return link; }
const text& get_link_name() const throw() { return link; }
/**
* Get the linked modifier.
*
@ -178,8 +179,8 @@ public:
modifier* get_link() { return kbd.try_lookup_modifier(link); }
private:
keyboard& kbd;
std::string name;
std::string link;
text name;
text link;
};
/**
@ -213,7 +214,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Illegal modifier or wrong syntax.
*/
static modifier_set construct(keyboard& kbd, const std::string& modifiers) throw(std::bad_alloc,
static modifier_set construct(keyboard& kbd, const text& modifiers) throw(std::bad_alloc,
std::runtime_error);
/**
* Check modifier against its mask for validity.
@ -240,7 +241,7 @@ public:
/**
* Stringify.
*/
operator std::string() const throw(std::bad_alloc);
operator text() const throw(std::bad_alloc);
/**
* Equality check.
*
@ -500,7 +501,7 @@ public:
* Parameter clazz: The class of the key.
* Parameter type: The type of key.
*/
key(keyboard& keyb, const std::string& name, const std::string& clazz, keytype type)
key(keyboard& keyb, const text& name, const text& clazz, keytype type)
throw(std::bad_alloc);
/**
* Destructor.
@ -509,11 +510,11 @@ public:
/**
* Get class.
*/
const std::string& get_class() { return clazz; }
const text& get_class() { return clazz; }
/**
* Get name.
*/
const std::string& get_name() { return name; }
const text& get_name() { return name; }
/**
* Get keyboard this is on.
*/
@ -559,7 +560,7 @@ public:
/**
* Get the subkey suffixes.
*/
virtual std::vector<std::string> get_subkeys() throw(std::bad_alloc) = 0;
virtual std::vector<text> get_subkeys() throw(std::bad_alloc) = 0;
/**
* Dynamic cast to axis type.
*/
@ -580,8 +581,8 @@ private:
key(key&);
key& operator=(key&);
keyboard& kbd;
std::string clazz;
std::string name;
text clazz;
text name;
std::set<event_listener*> digital_listeners;
std::set<event_listener*> analog_listeners;
event_listener* exclusive_listener;
@ -601,7 +602,7 @@ public:
* Parameter name: The base name of the key.
* Parameter clazz: The class of the key.
*/
key_key(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
key_key(keyboard& keyb, const text& name, const text& clazz) throw(std::bad_alloc);
/**
* Destructor.
*/
@ -624,7 +625,7 @@ public:
/**
* Get the subkey suffixes.
*/
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
std::vector<text> get_subkeys() throw(std::bad_alloc);
private:
key_key(key_key&);
key_key& operator=(key_key&);
@ -644,7 +645,7 @@ public:
* Parameter name: The base name of the key.
* Parameter clazz: The class of the key.
*/
key_hat(keyboard& keyb, const std::string& name, const std::string& clazz) throw(std::bad_alloc);
key_hat(keyboard& keyb, const text& name, const text& clazz) throw(std::bad_alloc);
/**
* Destructor.
*/
@ -667,7 +668,7 @@ public:
/**
* Get the subkey suffixes.
*/
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
std::vector<text> get_subkeys() throw(std::bad_alloc);
private:
key_hat(key_hat&);
key_hat& operator=(key_hat&);
@ -688,7 +689,7 @@ public:
* Parameter clazz: The class of the key.
* Parameter mode: Initial mode: -1 => disabled, 0 => axis, 1 => pressure
*/
key_axis(keyboard& keyb, const std::string& name, const std::string& clazz, int mode)
key_axis(keyboard& keyb, const text& name, const text& clazz, int mode)
throw(std::bad_alloc);
/**
* Destructor.
@ -712,7 +713,7 @@ public:
/**
* Get the subkey suffixes.
*/
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
std::vector<text> get_subkeys() throw(std::bad_alloc);
/**
* Get mode.
*/
@ -744,7 +745,7 @@ public:
* Parameter clazz: The class of the key.
* Parameter cal: Initial calibration.
*/
key_mouse(keyboard& keyb, const std::string& name, const std::string& clazz,
key_mouse(keyboard& keyb, const text& name, const text& clazz,
mouse_calibration cal) throw(std::bad_alloc);
/**
* Destructor.
@ -768,7 +769,7 @@ public:
/**
* Get the subkey suffixes. Returns empty list.
*/
std::vector<std::string> get_subkeys() throw(std::bad_alloc);
std::vector<text> get_subkeys() throw(std::bad_alloc);
/**
* Get calibration.
*/

View file

@ -5,8 +5,10 @@
#include <stdexcept>
#include <map>
#include <set>
#include "text.hpp"
#include "threads.hpp"
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
@ -35,7 +37,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Error loading shared library.
*/
library(const std::string& filename) throw(std::bad_alloc, std::runtime_error)
library(const text& filename) throw(std::bad_alloc, std::runtime_error)
{
try {
set_loading(this);
@ -63,7 +65,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Error looking up the symbol.
*/
void* operator[](const std::string& symbol) const throw(std::bad_alloc, std::runtime_error)
void* operator[](const text& symbol) const throw(std::bad_alloc, std::runtime_error)
{
threads::alock h(global_mutex());
if(!lib) throw std::runtime_error("Symbol '" + symbol + "' not found");
@ -74,13 +76,13 @@ public:
*
* Returns: The name of library.
*/
static const std::string& name() throw();
static const text& name() throw();
/**
* See what standard library extension is on this platform.
*
* Returns: The extension of library.
*/
static const std::string& extension() throw();
static const text& extension() throw();
/**
* Copy ctor.
*/
@ -101,7 +103,7 @@ public:
if(lib) ++lib->refs;
return *this;
}
std::string get_libname() const { return lib->libname; }
text get_libname() const { return lib->libname; }
void mark(const void* obj) const { if(lib) lib->mark(obj); }
bool is_marked(const void* obj) const { return lib ? lib->is_marked(obj) : false; }
/**
@ -112,9 +114,9 @@ private:
void set_loading(library* lib) throw(std::bad_alloc);
struct internal
{
internal(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
internal(const text& filename) throw(std::bad_alloc, std::runtime_error);
~internal() throw();
void* operator[](const std::string& symbol) const throw(std::bad_alloc, std::runtime_error);
void* operator[](const text& symbol) const throw(std::bad_alloc, std::runtime_error);
internal(const internal&);
internal& operator=(const internal&);
#if defined(_WIN32) || defined(_WIN64)
@ -123,7 +125,7 @@ private:
void* handle;
#endif
size_t refs;
std::string libname;
text libname;
void mark(const void* obj) { marked.insert(obj); }
bool is_marked(const void* obj) { return marked.count(obj); }
std::set<const void*> marked;
@ -165,18 +167,18 @@ public:
/**
* Symbol lookup.
*/
void* operator[](const std::string& symbol) const throw(std::bad_alloc, std::runtime_error);
void* operator[](const text& symbol) const throw(std::bad_alloc, std::runtime_error);
/**
* Variable symbol lookup.
*/
template<typename T> T* var(const std::string& symbol) const throw(std::bad_alloc, std::runtime_error)
template<typename T> T* var(const text& symbol) const throw(std::bad_alloc, std::runtime_error)
{
return (T*)(*this)[symbol];
}
/**
* Function symbol lookup.
*/
template<typename T, typename... U> typename fntype<T, U...>::t fn(const std::string& symbol) const
template<typename T, typename... U> typename fntype<T, U...>::t fn(const text& symbol) const
throw(std::bad_alloc, std::runtime_error)
{
return (typename fntype<T, U...>::t)(*this)[symbol];
@ -184,7 +186,7 @@ public:
/**
* Get name.
*/
std::string get_libname() const { return libname; }
text get_libname() const { return libname; }
/**
* Run all not ran initialization functions.
*/
@ -200,9 +202,9 @@ public:
private:
bool dynamic;
library lib;
std::map<std::string, void*> symbols;
std::map<text, void*> symbols;
std::function<void(const module&)> init;
std::string libname;
text libname;
};
}

View file

@ -14,6 +14,7 @@
#include "string.hpp"
#include "utf8.hpp"
#include "lua-version.hpp"
#include "text.hpp"
namespace lua
{
@ -40,8 +41,8 @@ public:
//Auxillary type for vararg-tag.
struct vararg_tag
{
std::list<std::string> args;
vararg_tag(std::list<std::string>& _args) : args(_args) {}
std::list<text> args;
vararg_tag(std::list<text>& _args) : args(_args) {}
int pushargs(state& L);
};
@ -117,7 +118,7 @@ public:
*
* Parameter v: The string value to pass.
*/
struct string_tag { std::string val; string_tag(const std::string& v) : val(v) {}};
struct string_tag { text val; string_tag(const text& v) : val(v) {}};
/**
* Callback parameter: Pass nil argument.
@ -307,7 +308,7 @@ public:
* Returns: The string.
* Throws std::runtime_error: The specified argument is not a string.
*/
std::string get_string(int argindex, const std::string& fname) throw(std::runtime_error, std::bad_alloc)
text get_string(int argindex, const text& fname) throw(std::runtime_error, std::bad_alloc)
{
if(isnone(argindex))
(stringfmt() << "argument #" << argindex << " to " << fname << " must be string").throwex();
@ -315,7 +316,7 @@ public:
const char* f = lua_tolstring(lua_handle, argindex, &len);
if(!f)
(stringfmt() << "argument #" << argindex << " to " << fname << " must be string").throwex();
return std::string(f, f + len);
return text(f, len);
}
/**
* Get a boolean argument.
@ -325,7 +326,7 @@ public:
* Returns: The string.
* Throws std::runtime_error: The specified argument is not a boolean.
*/
bool get_bool(int argindex, const std::string& fname) throw(std::runtime_error, std::bad_alloc)
bool get_bool(int argindex, const text& fname) throw(std::runtime_error, std::bad_alloc)
{
if(isnone(argindex) || !isboolean(argindex))
(stringfmt() << "argument #" << argindex << " to " << fname << " must be boolean").throwex();
@ -340,7 +341,7 @@ public:
* Throws std::runtime_error: Bad type.
*/
template<typename T>
T get_numeric_argument(int argindex, const std::string& fname)
T get_numeric_argument(int argindex, const text& fname)
{
if(std::numeric_limits<T>::is_integer) {
if(isnone(argindex) || !isinteger(argindex))
@ -363,7 +364,7 @@ public:
* Throws std::runtime_error: Bad type.
*/
template<typename T>
void get_numeric_argument(unsigned argindex, T& value, const std::string& fname)
void get_numeric_argument(unsigned argindex, T& value, const text& fname)
{
if(isnoneornil(argindex))
return;
@ -386,7 +387,7 @@ public:
* Parameter args: Arguments to pass to the callback.
*/
template<typename... T>
bool callback(const std::string& name, T... args)
bool callback(const text& name, T... args)
{
getglobal(name.c_str());
int t = type(-1);
@ -431,11 +432,11 @@ public:
/**
* Function callback.
*/
void function_callback(const std::string& name, function* func);
void function_callback(const text& name, function* func);
/**
* Class callback.
*/
void class_callback(const std::string& name, class_base* func);
void class_callback(const text& name, class_base* func);
/**
* Do something just once per VM.
*
@ -449,7 +450,7 @@ public:
class callback_list
{
public:
callback_list(state& L, const std::string& name, const std::string& fn_cbname = "");
callback_list(state& L, const text& name, const text& fn_cbname = "");
~callback_list();
void _register(state& L); //Reads callback from top of lua stack.
void _unregister(state& L); //Reads callback from top of lua stack.
@ -459,15 +460,15 @@ public:
any = true;
return any;
}
const std::string& get_name() { return name; }
const text& get_name() { return name; }
void clear() { callbacks.clear(); }
private:
callback_list(const callback_list&);
callback_list& operator=(const callback_list&);
std::list<char> callbacks;
state& L;
std::string name;
std::string fn_cbname;
text name;
text fn_cbname;
};
/**
* Enumerate all callbacks.
@ -476,8 +477,8 @@ public:
/**
* Register/Unregister a callback list.
*/
void do_register(const std::string& name, callback_list& callback);
void do_unregister(const std::string& name, callback_list& callback);
void do_register(const text& name, callback_list& callback);
void do_unregister(const text& name, callback_list& callback);
//All kinds of Lua API functions.
void pop(int n) { lua_pop(lua_handle, n); }
@ -522,7 +523,7 @@ public:
const char* tostring(int index) { return lua_tostring(lua_handle, index); }
const char* tolstring(int index, size_t& len) { return lua_tolstring(lua_handle, index, &len); }
void pushlstring(const char* s, size_t len) { lua_pushlstring(lua_handle, s, len); }
void pushlstring(const std::string& s) { lua_pushlstring(lua_handle, s.c_str(), s.length()); }
void pushlstring(const text& s) { lua_pushlstring(lua_handle, s.c_str(), s.length_utf8()); }
void pushlstring(const char32_t* s, size_t len) { pushlstring(utf8::to8(std::u32string(s, len))); }
int pcall(int nargs, int nresults, int errfunc)
{

View file

@ -26,21 +26,21 @@ public:
/**
* Add a class to group.
*/
void do_register(const std::string& name, class_base& fun);
void do_register(const text& name, class_base& fun);
/**
* Drop a class from group.
*/
void do_unregister(const std::string& name, class_base& fun);
void do_unregister(const text& name, class_base& fun);
/**
* Request callbacks on all currently registered functions.
*/
void request_callback(std::function<void(std::string, class_base*)> cb);
void request_callback(std::function<void(text, class_base*)> cb);
/**
* Bind a callback.
*
* Callbacks for all registered functions are immediately called.
*/
int add_callback(std::function<void(std::string, class_base*)> cb,
int add_callback(std::function<void(text, class_base*)> cb,
std::function<void(class_group*)> dcb);
/**
* Unbind a calback.
@ -53,13 +53,13 @@ private:
struct class_ops
{
bool (*is)(state& _state, int index);
const std::string& (*name)();
std::string (*print)(state& _state, int index);
const text& (*name)();
text (*print)(state& _state, int index);
};
std::list<class_ops>& userdata_recogn_fns();
std::string try_recognize_userdata(state& _state, int index);
std::string try_print_userdata(state& _state, int index);
text try_recognize_userdata(state& _state, int index);
text try_print_userdata(state& _state, int index);
std::unordered_map<std::type_index, void*>& class_types();
/**
@ -155,7 +155,7 @@ public:
* Parameter _group: The group the class will be in.
* Parameter _name: The name of the class.
*/
class_base(class_group& _group, const std::string& _name);
class_base(class_group& _group, const text& _name);
/**
* Dtor.
*/
@ -167,15 +167,15 @@ public:
* Parameter _name: The name of the class.
* Returns: The class instance, or NULL if no match.
*/
static class_base* lookup(state& L, const std::string& _name);
static class_base* lookup(state& L, const text& _name);
/**
* Push class table to stack.
*/
static bool lookup_and_push(state& L, const std::string& _name);
static bool lookup_and_push(state& L, const text& _name);
/**
* Get set of all classes.
*/
static std::set<std::string> all_classes(state& L);
static std::set<text> all_classes(state& L);
/**
* Register in given Lua state.
*/
@ -187,17 +187,17 @@ public:
/**
* Lookup class methods in class.
*/
virtual std::set<std::string> class_methods() = 0;
virtual std::set<text> class_methods() = 0;
/**
* Get name of class.
*/
const std::string& get_name() { return name; }
const text& get_name() { return name; }
protected:
void delayed_register();
void register_static(state& L);
private:
class_group& group;
std::string name;
text name;
bool registered;
};
@ -248,7 +248,7 @@ template<class T> class _class : public class_base
return (p->*(b->fn))(L, P);
}
T* _get(state& _state, int arg, const std::string& fname, bool optional = false)
T* _get(state& _state, int arg, const text& fname, bool optional = false)
{
if(_state.type(arg) == LUA_TNONE || _state.type(arg) == LUA_TNIL) {
if(optional)
@ -282,7 +282,7 @@ badtype:
return ret;
}
objpin<T> _pin(state& _state, int arg, const std::string& fname)
objpin<T> _pin(state& _state, int arg, const text& fname)
{
T* obj = get(_state, arg, fname);
_state.pushvalue(arg);
@ -295,13 +295,13 @@ badtype:
{
load_metatable(_state);
_state.pushstring(keyname);
std::string fname = name + std::string("::") + keyname;
void* ptr = _state.newuserdata(sizeof(class_binding<T>) + fname.length() + 1);
text fname = name + text("::") + keyname;
size_t utflen = fname.length_utf8();
void* ptr = _state.newuserdata(sizeof(class_binding<T>) + utflen + 1);
class_binding<T>* bdata = reinterpret_cast<class_binding<T>*>(ptr);
bdata->fn = fn;
bdata->_state = &_state.get_master();
std::copy(fname.begin(), fname.end(), bdata->fname);
bdata->fname[fname.length()] = 0;
memcpy(bdata->fname, fname.c_str(), utflen + 1);
_state.push_trampoline(class_bind_trampoline, 1);
_state.rawset(-3);
_state.pop(1);
@ -325,8 +325,8 @@ public:
* Parameter _cmethods: Class methods of the class.
* Parameter _print: The print method.
*/
_class(class_group& _group, const std::string& _name, std::initializer_list<static_method> _smethods,
std::initializer_list<class_method<T>> _cmethods = {}, std::string (T::*_print)() = NULL)
_class(class_group& _group, const text& _name, std::initializer_list<static_method> _smethods,
std::initializer_list<class_method<T>> _cmethods = {}, text (T::*_print)() = NULL)
: class_base(_group, _name), smethods(_smethods), cmethods(_cmethods)
{
name = _name;
@ -375,7 +375,7 @@ public:
* Parameter optional: If true and argument is NIL or none, return NULL.
* Throws std::runtime_error: Wrong type.
*/
static T* get(state& _state, int arg, const std::string& fname, bool optional = false)
static T* get(state& _state, int arg, const text& fname, bool optional = false)
throw(std::bad_alloc, std::runtime_error)
{
return objclass<T>()._get(_state, arg, fname, optional);
@ -399,19 +399,19 @@ public:
/**
* Get name of class.
*/
static const std::string& get_name()
static const text& get_name()
{
try {
return objclass<T>().name;
} catch(...) {
static std::string foo = "???";
static text foo = "???";
return foo;
}
}
/**
* Format instance of this class as string.
*/
static std::string print(state& _state, int index)
static text print(state& _state, int index)
{
T* obj = get(_state, index, "__internal_print");
try {
@ -432,7 +432,7 @@ public:
* Parameter fname: Name of function for error message purposes.
* Throws std::runtime_error: Wrong type.
*/
static objpin<T> pin(state& _state, int arg, const std::string& fname) throw(std::bad_alloc,
static objpin<T> pin(state& _state, int arg, const text& fname) throw(std::bad_alloc,
std::runtime_error)
{
return objclass<T>()._pin(_state, arg, fname);
@ -447,9 +447,9 @@ public:
/**
* Lookup class methods.
*/
std::set<std::string> class_methods()
std::set<text> class_methods()
{
std::set<std::string> r;
std::set<text> r;
for(auto& i : cmethods)
r.insert(i.name);
return r;
@ -473,7 +473,7 @@ private:
L.pushvalue(2);
L.rawget(-2);
if(L.type(-1) == LUA_TNIL) {
std::string err = std::string("Class '") + L.tostring(L.trampoline_upval(1)) +
text err = text("Class '") + L.tostring(L.trampoline_upval(1)) +
"' does not have class method '" + L.tostring(2) + "'";
throw std::runtime_error(err);
}
@ -505,10 +505,10 @@ again:
goto again;
}
}
std::string name;
text name;
std::list<static_method> smethods;
std::list<class_method<T>> cmethods;
std::string (T::*printmeth)();
text (T::*printmeth)();
_class(const _class<T>&);
_class& operator=(const _class<T>&);
};

View file

@ -17,9 +17,9 @@ struct render_context
uint32_t height;
};
framebuffer::color get_fb_color(lua::state& L, int index, const std::string& fname)
framebuffer::color get_fb_color(lua::state& L, int index, const text& fname)
throw(std::bad_alloc, std::runtime_error);
framebuffer::color get_fb_color(lua::state& L, int index, const std::string& fname, int64_t dflt)
framebuffer::color get_fb_color(lua::state& L, int index, const text& fname, int64_t dflt)
throw(std::bad_alloc, std::runtime_error);
}

View file

@ -23,21 +23,21 @@ public:
/**
* Add a function to group.
*/
void do_register(const std::string& name, function& fun);
void do_register(const text& name, function& fun);
/**
* Drop a function from group.
*/
void do_unregister(const std::string& name, function& dummy);
void do_unregister(const text& name, function& dummy);
/**
* Request callbacks on all currently registered functions.
*/
void request_callback(std::function<void(std::string, function*)> cb);
void request_callback(std::function<void(text, function*)> cb);
/**
* Bind a callback.
*
* Callbacks for all registered functions are immediately called.
*/
int add_callback(std::function<void(std::string, function*)> cb,
int add_callback(std::function<void(text, function*)> cb,
std::function<void(function_group*)> dcb);
/**
* Unbind a calback.
@ -56,7 +56,7 @@ public:
/**
* Register function.
*/
function(function_group& group, const std::string& name) throw(std::bad_alloc);
function(function_group& group, const text& name) throw(std::bad_alloc);
/**
* Unregister function.
*/
@ -67,7 +67,7 @@ public:
*/
virtual int invoke(state& L) = 0;
protected:
std::string fname;
text fname;
function_group& group;
};
@ -82,7 +82,7 @@ public:
*/
struct entry
{
const std::string& name;
const text& name;
std::function<int(state& L, parameters& P)> func;
};
/**
@ -92,7 +92,7 @@ public:
* Parameter basetable: The base table to interpret function names relative to.
* Parameter fnlist: The list of functions to register.
*/
functions(function_group& grp, const std::string& basetable, std::initializer_list<entry> fnlist);
functions(function_group& grp, const text& basetable, std::initializer_list<entry> fnlist);
/**
* Dtor.
*/
@ -101,7 +101,7 @@ private:
class fn : public function
{
public:
fn(function_group& grp, const std::string& name, std::function<int(state& L, parameters& P)> _func);
fn(function_group& grp, const text& name, std::function<int(state& L, parameters& P)> _func);
~fn() throw();
int invoke(state& L);
private:

View file

@ -30,42 +30,42 @@ struct skipped_parameter_tag
{
};
template<typename T> static void arg_helper(state& L, T& x, int idx, const std::string& fname)
template<typename T> static void arg_helper(state& L, T& x, int idx, const text& fname)
{
x = L.get_numeric_argument<T>(idx, fname);
}
template<> void arg_helper(state& L, bool& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, bool& x, int idx, const text& fname)
{
x = L.get_bool(idx, fname);
}
template<> void arg_helper(state& L, std::string& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, text& x, int idx, const text& fname)
{
x = L.get_string(idx, fname);
}
template<typename T> void arg_helper(state& L, T*& x, int idx, const std::string& fname)
template<typename T> void arg_helper(state& L, T*& x, int idx, const text& fname)
{
x = _class<T>::get(L, idx, fname);
}
template<typename T> void arg_helper(state& L, lua::objpin<T>& x, int idx, const std::string& fname)
template<typename T> void arg_helper(state& L, lua::objpin<T>& x, int idx, const text& fname)
{
x = _class<T>::pin(L, idx, fname);
}
template<> void arg_helper(state& L, framebuffer::color& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, framebuffer::color& x, int idx, const text& fname)
{
x = get_fb_color(L, idx, fname);
}
template<> void arg_helper(state& L, skipped_parameter_tag& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, skipped_parameter_tag& x, int idx, const text& fname)
{
delete &x;
}
template<> void arg_helper(state& L, function_parameter_tag& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, function_parameter_tag& x, int idx, const text& fname)
{
if(L.type(idx) != LUA_TFUNCTION)
(stringfmt() << "Expected function as argument #" << idx << " to " << fname).throwex();
@ -73,7 +73,7 @@ template<> void arg_helper(state& L, function_parameter_tag& x, int idx, const s
delete &x;
}
template<> void arg_helper(state& L, table_parameter_tag& x, int idx, const std::string& fname)
template<> void arg_helper(state& L, table_parameter_tag& x, int idx, const text& fname)
{
if(L.type(idx) != LUA_TTABLE)
(stringfmt() << "Expected table as argument #" << idx << " to " << fname).throwex();
@ -82,35 +82,35 @@ template<> void arg_helper(state& L, table_parameter_tag& x, int idx, const std:
}
template<typename T, typename U> void arg_helper(state& L, optional_parameter_tag<T, U>& x, int idx,
const std::string& fname)
const text& fname)
{
x.target = x.dflt;
L.get_numeric_argument<T>(idx, x.target, fname);
delete &x;
}
template<typename U> void arg_helper(state& L, optional_parameter_tag<bool, U>& x, int idx, const std::string& fname)
template<typename U> void arg_helper(state& L, optional_parameter_tag<bool, U>& x, int idx, const text& fname)
{
x.target = (L.type(idx) == LUA_TNIL || L.type(idx) == LUA_TNONE) ? x.dflt : L.get_bool(idx, fname);
delete &x;
}
template<typename U> void arg_helper(state& L, optional_parameter_tag<std::string, U>& x, int idx,
const std::string& fname)
template<typename U> void arg_helper(state& L, optional_parameter_tag<text, U>& x, int idx,
const text& fname)
{
x.target = (L.type(idx) == LUA_TNIL || L.type(idx) == LUA_TNONE) ? x.dflt : L.get_string(idx, fname);
delete &x;
}
template<typename U> void arg_helper(state& L, optional_parameter_tag<framebuffer::color, U>& x, int idx,
const std::string& fname)
const text& fname)
{
x.target = get_fb_color(L, idx, fname, x.dflt);
delete &x;
}
template<typename T, typename U> void arg_helper(state& L, optional_parameter_tag<T*, U>& x, int idx,
const std::string& fname)
const text& fname)
{
x.target = _class<T>::get(L, idx, fname, true);
delete &x;
@ -125,7 +125,7 @@ public:
/**
* Make
*/
parameters(state& _L, const std::string& _fname)
parameters(state& _L, const text& _fname)
: L(_L), fname(_fname), next(1)
{
}
@ -188,7 +188,7 @@ public:
/**
* Get name.
*/
const std::string& get_fname() { return fname; }
const text& get_fname() { return fname; }
/**
* More arguments remain?
*/
@ -210,7 +210,7 @@ public:
/**
* Throw an error.
*/
void expected(const std::string& what, int i = 0)
void expected(const text& what, int i = 0)
{
(stringfmt() << "Expected " << what << " as argument #" << (i ? i : next) << " of "
<< fname).throwex();
@ -259,7 +259,7 @@ public:
state& get_state() { return L; }
private:
state& L;
std::string fname;
text fname;
int next;
};
}

View file

@ -3,6 +3,7 @@
#include <string>
#include <stdexcept>
#include "text.hpp"
namespace mathexpr
{
@ -24,7 +25,7 @@ public:
FORMAT, //Bad format string.
UNKNOWN, //Unknown error.
};
error(errorcode code, const std::string& message);
error(errorcode code, const text& message);
errorcode get_code();
const char* get_short_error();
private:

View file

@ -5,12 +5,12 @@
namespace mathexpr
{
std::string format_bool(bool v, _format fmt);
std::string format_unsigned(uint64_t v, _format fmt);
std::string format_signed(int64_t v, _format fmt);
std::string format_float(double v, _format fmt);
std::string format_complex(double vr, double vi, _format fmt);
std::string format_string(std::string v, _format fmt);
text format_bool(bool v, _format fmt);
text format_unsigned(uint64_t v, _format fmt);
text format_signed(int64_t v, _format fmt);
text format_float(double v, _format fmt);
text format_complex(double vr, double vi, _format fmt);
text format_string(text v, _format fmt);
}
#endif

View file

@ -40,11 +40,11 @@ struct _format
struct operinfo
{
operinfo(std::string funcname);
operinfo(std::string opername, unsigned _operands, int _percedence, bool _rtl = false);
operinfo(text funcname);
operinfo(text opername, unsigned _operands, int _percedence, bool _rtl = false);
virtual ~operinfo();
virtual void evaluate(value target, std::vector<std::function<value()>> promises) = 0;
const std::string fnname;
const text fnname;
const bool is_operator;
const unsigned operands; //Only for operators (max 2 operands).
const int precedence; //Higher binds more tightly.
@ -55,7 +55,7 @@ struct typeinfo
{
virtual ~typeinfo();
virtual void* allocate() = 0;
virtual void* parse(const std::string& str, bool string) = 0;
virtual void* parse(const text& str, bool string) = 0;
virtual void parse_u(void* obj, uint64_t v) = 0;
virtual void parse_s(void* obj, int64_t v) = 0;
virtual void parse_f(void* obj, double v) = 0;
@ -63,8 +63,8 @@ struct typeinfo
virtual void scale(void* val, uint64_t scale) = 0;
virtual void deallocate(void* obj) = 0;
virtual void copy(void* target, void* source) = 0;
virtual std::string tostring(void* obj) = 0;
virtual std::string format(void* obj, _format fmt) = 0;
virtual text tostring(void* obj) = 0;
virtual text format(void* obj, _format fmt) = 0;
virtual uint64_t tounsigned(void* obj) = 0;
virtual int64_t tosigned(void* obj) = 0;
virtual bool toboolean(void* obj) = 0;
@ -84,11 +84,11 @@ struct typeinfo
template<class T> struct operinfo_wrapper : public operinfo
{
operinfo_wrapper(std::string funcname, T (*_fn)(std::vector<std::function<T&()>> promises))
operinfo_wrapper(text funcname, T (*_fn)(std::vector<std::function<T&()>> promises))
: operinfo(funcname), fn(_fn)
{
}
operinfo_wrapper(std::string opername, unsigned _operands, int _percedence, bool _rtl,
operinfo_wrapper(text opername, unsigned _operands, int _percedence, bool _rtl,
T (*_fn)(std::vector<std::function<T&()>> promises))
: operinfo(opername, _operands, _percedence, _rtl), fn(_fn)
{
@ -114,7 +114,7 @@ private:
template<class T> struct opfun_info
{
std::string name;
text name;
T (*_fn)(std::vector<std::function<T&()>> promises);
bool is_operator;
unsigned operands;
@ -160,7 +160,7 @@ template<class T> struct typeinfo_wrapper : public typeinfo
{
return new T;
}
void* parse(const std::string& str, bool string)
void* parse(const text& str, bool string)
{
return new T(str, string);
}
@ -188,11 +188,11 @@ template<class T> struct typeinfo_wrapper : public typeinfo
{
*(T*)target = *(T*)source;
}
std::string tostring(void* obj)
text tostring(void* obj)
{
return ((T*)obj)->tostring();
}
std::string format(void* obj, _format fmt)
text format(void* obj, _format fmt)
{
return ((T*)obj)->format(fmt);
}
@ -244,7 +244,7 @@ public:
//Value of specified type.
mathexpr(value value);
//Value of specified type.
mathexpr(typeinfo* _type, const std::string& value, bool string);
mathexpr(typeinfo* _type, const text& value, bool string);
//Specified Operator.
mathexpr(typeinfo* _type, operinfo* fn, std::vector<GC::pointer<mathexpr>> _args,
bool _owns_operator = false);
@ -260,18 +260,18 @@ public:
//Reset.
void reset();
//Parse an expression.
static GC::pointer<mathexpr> parse(typeinfo& _type, const std::string& expr,
std::function<GC::pointer<mathexpr>(const std::string&)> vars);
static GC::pointer<mathexpr> parse(typeinfo& _type, const text& expr,
std::function<GC::pointer<mathexpr>(const text&)> vars);
protected:
void trace();
private:
void mark_error_and_throw(error::errorcode _errcode, const std::string& _error);
void mark_error_and_throw(error::errorcode _errcode, const text& _error);
eval_state state;
typeinfo& type; //Type of value.
void* _value; //Value if state is EVALUATED or FIXED.
operinfo* fn; //Function (if state is TO_BE_EVALUATED, EVALUATING or EVALUATED)
error::errorcode errcode; //Error code if state is FAILED.
std::string _error; //Error message if state is FAILED.
text _error; //Error message if state is FAILED.
std::vector<mathexpr*> arguments;
mutable bool owns_operator;
};

View file

@ -28,7 +28,7 @@ public:
/**
* Name of the region (mainly for debugging and showing to user).
*/
std::string name;
text name;
/**
* Base address of the region.
*/
@ -101,7 +101,7 @@ public:
* Parameter size: Size of the region.
* Parameter _readonly: If true, region is readonly.
*/
region_direct(const std::string& name, uint64_t base, int endian, unsigned char* memory,
region_direct(const text& name, uint64_t base, int endian, unsigned char* memory,
size_t size, bool _readonly = false);
/**
* Destructor.
@ -247,7 +247,7 @@ public:
* Parameter addr: The address to get textual form for.
* Returns: The textual address.
*/
std::string address_to_textual(uint64_t addr);
text address_to_textual(uint64_t addr);
private:
threads::lock mlock;
std::vector<region*> u_regions;

View file

@ -18,7 +18,7 @@ struct output_fb : public item_printer
~output_fb();
void set_rqueue(framebuffer::queue& rqueue);
void set_dtor_cb(std::function<void(output_fb&)> cb);
void show(const std::string& iname, const std::string& val);
void show(const text& iname, const text& val);
void reset();
bool cond_enable;
GC::pointer<mathexpr::mathexpr> enabled;

View file

@ -12,13 +12,13 @@ struct output_list : public item_printer
{
output_list();
~output_list();
void set_output(std::function<void(const std::string& n, const std::string& v)> _fn);
void show(const std::string& iname, const std::string& val);
void set_output(std::function<void(const text& n, const text& v)> _fn);
void show(const text& iname, const text& val);
void reset();
bool cond_enable;
GC::pointer<mathexpr::mathexpr> enabled;
//State variables.
std::function<void(const std::string& n, const std::string& v)> fn;
std::function<void(const text& n, const text& v)> fn;
};
}

View file

@ -11,7 +11,7 @@ struct output_null : public item_printer
{
output_null();
~output_null();
void show(const std::string& iname, const std::string& val);
void show(const text& iname, const text& val);
void reset();
};
}

View file

@ -52,7 +52,7 @@ struct item_printer : public GC::item
/**
* Show the watched value.
*/
virtual void show(const std::string& iname, const std::string& val) = 0;
virtual void show(const text& iname, const text& val) = 0;
/**
* Reset the printer.
*/
@ -78,17 +78,17 @@ struct item
/**
* Get the value as string.
*/
std::string get_value();
text get_value();
/**
* Print the value to specified printer.
*
* Parameter iname: The name of the watch.
*/
void show(const std::string& iname);
void show(const text& iname);
//Fields.
GC::pointer<item_printer> printer; //Printer to use.
GC::pointer<mathexpr::mathexpr> expr; //Expression to watch.
std::string format; //Formatting to use.
text format; //Formatting to use.
};
/**
@ -113,7 +113,7 @@ struct set
*
* Returns: The longest nontrivial name, or "" if none.
*/
const std::string& get_longest_name()
const text& get_longest_name()
{
return get_longest_name(set::utflength_rate);
}
@ -123,11 +123,11 @@ struct set
* Parameter rate: Get length for name function.
* Returns: The longest nontrivial name, or "" if none.
*/
const std::string& get_longest_name(std::function<size_t(const std::string& n)> rate);
const text& get_longest_name(std::function<size_t(const text& n)> rate);
/**
* Get the set of memory watch names.
*/
std::set<std::string> names_set();
std::set<text> names_set();
/**
* Get specified memory watch item.
*
@ -135,27 +135,27 @@ struct set
* Returns: The item.
* Throws std::runtime_error: No such item in set.
*/
item& get(const std::string& name);
item& get(const text& name);
/**
* Get specified memory watch item (without throwing).
*
* Parameter name: The name of the item.
* Returns: The item, or NULL if no such item exists.
*/
item* get_soft(const std::string& name);
item* get_soft(const text& name);
/**
* Create a new memory watch item.
*
* Parameter name: The name of the new item.
* Parameter item: The new item. All fields are shallow-copied.
*/
item* create(const std::string& name, item& item);
item* create(const text& name, item& item);
/**
* Destroy a memory watch item.
*
* Parameter name: The name of the item to destroy.
*/
void destroy(const std::string& name);
void destroy(const text& name);
/**
* Call routine for all roots.
*/
@ -165,8 +165,8 @@ struct set
*/
void swap(set& s) throw();
private:
static size_t utflength_rate(const std::string& s);
std::map<std::string, item> roots;
static size_t utflength_rate(const text& s);
std::map<text, item> roots;
};
}

View file

@ -2,8 +2,11 @@
#define _library__memtracker__hpp__included__
#include "threads.hpp"
#include <cstring>
#include <map>
class text;
class memtracker
{
public:
@ -11,39 +14,79 @@ public:
~memtracker();
void operator()(const char* category, ssize_t change);
void reset(const char* category, size_t value);
std::map<std::string, size_t> report();
std::map<text, size_t> report();
static memtracker& singleton();
class autorelease
{
public:
autorelease(memtracker& _track, const char* cat, size_t amount)
: tracker(_track), category(cat), committed(amount)
autorelease(size_t amount)
: tracker(NULL), category(NULL), committed(amount)
{
tracker(category, committed);
}
autorelease(memtracker& _track, const char* cat, size_t amount)
: tracker(&_track), category(cat), committed(amount)
{
if(category && tracker)
(*tracker)(category, committed);
}
~autorelease()
{
tracker(category, -(ssize_t)committed);
if(committed && category && tracker)
(*tracker)(category, -(ssize_t)committed);
}
void operator()(ssize_t delta)
{
if(delta < 0 && committed < (size_t)-delta) {
tracker(category, -(ssize_t)committed);
if(category && tracker)
(*tracker)(category, -(ssize_t)committed);
committed = 0;
} else {
tracker(category, delta);
if(category && tracker)
(*tracker)(category, delta);
committed = committed + delta;
}
}
void untrack()
{
if(category && tracker)
(*tracker)(category, -(ssize_t)committed);
category = NULL;
tracker = NULL;
}
void track(memtracker& _tracker, const char* cat)
{
if(category && tracker)
(*tracker)(category, -(ssize_t)committed);
category = cat;
tracker = &_tracker;
if(category && tracker)
(*tracker)(category, committed);
}
memtracker& get_tracker() const throw() { return *tracker; }
const char* get_category() const throw() { return category; }
private:
memtracker& tracker;
memtracker* tracker;
const char* category;
size_t committed;
};
private:
class cstr_container
{
public:
cstr_container(const char* _str) { str = _str; }
const char* as_str() const { return str; }
bool operator<(const cstr_container& x) const { return strcmp(str, x.str) < 0; }
bool operator<=(const cstr_container& x) const { return strcmp(str, x.str) <= 0; }
bool operator==(const cstr_container& x) const { return strcmp(str, x.str) == 0; }
bool operator!=(const cstr_container& x) const { return strcmp(str, x.str) != 0; }
bool operator>=(const cstr_container& x) const { return strcmp(str, x.str) >= 0; }
bool operator>(const cstr_container& x) const { return strcmp(str, x.str) > 0; }
private:
const char* str;
};
bool invalid;
threads::lock mut;
std::map<std::string, size_t> data;
std::map<cstr_container, size_t> data;
memtracker(const memtracker&);
memtracker& operator=(const memtracker&);
};

View file

@ -6,6 +6,7 @@
#include <set>
#include <cstdint>
#include <string>
#include "text.hpp"
class messagebuffer
{
@ -42,7 +43,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Thrown through from update handler.
*/
void add_message(const std::string& msg) throw(std::bad_alloc, std::runtime_error);
void add_message(const text& msg) throw(std::bad_alloc, std::runtime_error);
/**
* Read a message.
@ -52,7 +53,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::logic_error: Invalid message number.
*/
const std::string& get_message(size_t msgnum) throw(std::bad_alloc, std::logic_error);
const text& get_message(size_t msgnum) throw(std::bad_alloc, std::logic_error);
/**
* Get the number of first message present.
@ -191,10 +192,10 @@ public:
/**
* Read the last message.
*/
std::string get_last_message();
text get_last_message();
private:
void send_notifications();
std::map<uint64_t, std::string> messages_buf;
std::map<uint64_t, text> messages_buf;
uint64_t first_present_message;
uint64_t next_message_number;
uint64_t window_start;

View file

@ -46,7 +46,7 @@ public:
* returns: The movie rerecord count
* throws std::bad_alloc: Not enough memory.
*/
std::string rerecord_count() throw(std::bad_alloc);
text rerecord_count() throw(std::bad_alloc);
/**
* Sets the movie rerecord count (this is not the same thing as global rerecord count).
@ -54,7 +54,7 @@ public:
* parameter count: The new rerecord count
* throws std::bad_alloc: Not enough memory.
*/
void rerecord_count(const std::string& count) throw(std::bad_alloc);
void rerecord_count(const text& count) throw(std::bad_alloc);
/**
* Read project ID
@ -62,7 +62,7 @@ public:
* returns: The project ID
* throws std::bad_alloc: Not enough memory.
*/
std::string project_id() throw(std::bad_alloc);
text project_id() throw(std::bad_alloc);
/**
* brief Set project ID
@ -70,7 +70,7 @@ public:
* parameter id: New project ID.
* throws std::bad_alloc: Not enough memory.
*/
void project_id(const std::string& id) throw(std::bad_alloc);
void project_id(const text& id) throw(std::bad_alloc);
/**
* Get number of frames in movie
@ -154,7 +154,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Bad movie data.
*/
void load(const std::string& rerecs, const std::string& project_id, portctrl::frame_vector& input)
void load(const text& rerecs, const text& project_id, portctrl::frame_vector& input)
throw(std::bad_alloc, std::runtime_error);
/**
@ -166,7 +166,7 @@ public:
* Parameter pcounters: Poll counters are written here.
* throws std::bad_alloc: Not enough memory.
*/
void save_state(std::string& proj_id, uint64_t& curframe, uint64_t& lagframes,
void save_state(text& proj_id, uint64_t& curframe, uint64_t& lagframes,
std::vector<uint32_t>& pcounters) throw(std::bad_alloc);
/**
@ -183,7 +183,7 @@ public:
* Throws std::runtime_error: Movie check failure.
*/
size_t restore_state(uint64_t curframe, uint64_t lagframe, const std::vector<uint32_t>& pcounters, bool ro,
portctrl::frame_vector* old_movie, const std::string& old_projectid) throw(std::bad_alloc,
portctrl::frame_vector* old_movie, const text& old_projectid) throw(std::bad_alloc,
std::runtime_error);
/**
* Reset the state of movie to initial state.
@ -301,9 +301,9 @@ private:
//TRUE if movie is latched to end.
bool latch_end;
//Movie (not global!) rerecord count.
std::string rerecords;
text rerecords;
//Project ID.
std::string _project_id;
text _project_id;
//The actual controller data.
portctrl::frame_vector* movie_data;
//Current frame + 1 (0 before next_frame() has been called.

View file

@ -200,11 +200,11 @@ public:
/**
* Get debugging info for stream this page is from.
*/
std::string stream_debug_id() const throw(std::bad_alloc);
text stream_debug_id() const throw(std::bad_alloc);
/**
* Get debugging info for this page.
*/
std::string page_debug_id() const throw(std::bad_alloc);
text page_debug_id() const throw(std::bad_alloc);
/**
* The special granule pos for nothing.
*/

View file

@ -4,6 +4,7 @@
#include <functional>
#include <cstdint>
#include "ogg.hpp"
#include "text.hpp"
namespace opus
{
@ -42,8 +43,8 @@ struct ogg_header
*/
struct ogg_tags
{
std::string vendor;
std::vector<std::string> comments;
text vendor;
std::vector<text> comments;
/**
* Parse Ogg packet as OggOpus comment.
*

View file

@ -692,7 +692,7 @@ uint32_t packet_get_nb_samples(const unsigned char* packet, size_t len, samplera
uint32_t packet_get_nb_channels(const unsigned char* packet);
bandwidth packet_get_bandwidth(const unsigned char* packet);
parsed_packet packet_parse(const unsigned char* packet, size_t len);
std::string version();
text version();
/**
* Get tick (2.5ms) count from opus packet.

View file

@ -13,7 +13,7 @@ struct decoder
{
decoder();
decoder(std::istream& file);
decoder(const std::string& file);
decoder(const text& file);
size_t width;
size_t height;
bool has_palette;
@ -33,7 +33,7 @@ struct encoder
uint32_t colorkey;
std::vector<uint32_t> data;
std::vector<uint32_t> palette;
void encode(const std::string& file) const;
void encode(const text& file) const;
void encode(std::ostream& file) const;
};
}

View file

@ -208,12 +208,12 @@ struct button
};
enum _type type;
char32_t symbol;
std::string name;
text name;
bool shadow;
int16_t rmin; //Range min.
int16_t rmax; //Range max.
bool centers;
std::string macro; //Name in macro (must be prefix-free).
text macro; //Name in macro (must be prefix-free).
char msymbol; //Symbol in movie.
/**
* Is analog?
@ -227,8 +227,8 @@ struct button
*/
struct controller
{
std::string cclass; //Controller class.
std::string type; //Controller type.
text cclass; //Controller class.
text type; //Controller type.
std::vector<button> buttons; //Buttons.
/**
* Count number of analog actions on this controller.
@ -254,9 +254,9 @@ struct controller
*/
struct controller_set
{
std::string iname;
std::string hname;
std::string symbol;
text iname;
text hname;
text symbol;
std::vector<controller> controllers; //Controllers.
std::set<unsigned> legal_for; //Ports this is legal for
/**
@ -288,7 +288,7 @@ public:
* Parameter ssize: The storage size in bytes.
* Throws std::bad_alloc: Not enough memory.
*/
type(const std::string& iname, const std::string& hname, size_t ssize) throw(std::bad_alloc);
type(const text& iname, const text& hname, size_t ssize) throw(std::bad_alloc);
/**
* Unregister a port type.
*/
@ -360,7 +360,7 @@ public:
/**
* Human-readable name.
*/
std::string hname;
text hname;
/**
* Number of bytes it takes to store this.
*/
@ -368,7 +368,7 @@ public:
/**
* Name of port type.
*/
std::string name;
text name;
/**
* Is given controller present?
*/
@ -1387,7 +1387,7 @@ struct macro_data
struct axis_transform
{
axis_transform() { coeffs[0] = coeffs[3] = 1; coeffs[1] = coeffs[2] = coeffs[4] = coeffs[5] = 0; }
axis_transform(const std::string& expr);
axis_transform(const text& expr);
double coeffs[6];
int16_t transform(const button& b, int16_t v);
std::pair<int16_t, int16_t> transform(const button& b1,
@ -1402,14 +1402,14 @@ struct macro_data
AM_XOR
};
macro_data() { buttons = 0; }
macro_data(const std::string& spec, const JSON::node& desc, unsigned i);
macro_data(const text& spec, const JSON::node& desc, unsigned i);
macro_data(const JSON::node& ser, unsigned i);
void serialize(JSON::node& v);
static JSON::node make_descriptor(const controller& ctrl);
const JSON::node& get_descriptor() { return _descriptor; }
static bool syntax_check(const std::string& spec, const JSON::node& ctrl);
static bool syntax_check(const text& spec, const JSON::node& ctrl);
void write(frame& frame, unsigned port, unsigned controller, int64_t nframe, apply_mode amode);
std::string dump(const controller& ctrl); //Mainly for debugging.
text dump(const controller& ctrl); //Mainly for debugging.
size_t get_frames() { return data.size() / get_stride(); }
size_t get_stride() { return buttons; }
size_t buttons;
@ -1417,7 +1417,7 @@ struct macro_data
std::vector<std::pair<unsigned, unsigned>> aaxes;
std::vector<unsigned> btnmap;
std::vector<axis_transform> adata;
std::string orig;
text orig;
JSON::node _descriptor;
bool enabled;
bool autoterminate;

View file

@ -13,15 +13,15 @@ namespace portctrl
class controller_set;
class type;
struct controller_set* pcs_from_json(const JSON::node& root, const std::string& ptr);
std::vector<controller_set*> pcs_from_json_array(const JSON::node& root, const std::string& ptr);
std::string pcs_write_class(const struct controller_set& pset, unsigned& tmp_idx);
std::string pcs_write_trailer(const std::vector<controller_set*>& p);
std::string pcs_write_classes(const std::vector<controller_set*>& p, unsigned& tmp_idx);
struct controller_set* pcs_from_json(const JSON::node& root, const text& ptr);
std::vector<controller_set*> pcs_from_json_array(const JSON::node& root, const text& ptr);
text pcs_write_class(const struct controller_set& pset, unsigned& tmp_idx);
text pcs_write_trailer(const std::vector<controller_set*>& p);
text pcs_write_classes(const std::vector<controller_set*>& p, unsigned& tmp_idx);
struct type_generic : public type
{
type_generic(const JSON::node& root, const std::string& ptr) throw(std::exception);
type_generic(const JSON::node& root, const text& ptr) throw(std::exception);
~type_generic() throw();
struct ser_instruction
{
@ -46,9 +46,9 @@ private:
std::vector<idxinfo> indexinfo;
void* dyncode_block;
mutable std::vector<ser_instruction> serialize_instructions;
std::string port_iname(const JSON::node& root, const std::string& ptr);
std::string port_hname(const JSON::node& root, const std::string& ptr);
size_t port_size(const JSON::node& root, const std::string& ptr);
text port_iname(const JSON::node& root, const text& ptr);
text port_hname(const JSON::node& root, const text& ptr);
size_t port_size(const JSON::node& root, const text& ptr);
static void _write(const type* _this, unsigned char* buffer, unsigned idx, unsigned ctrl, short x);
static short _read(const type* _this, const unsigned char* buffer, unsigned idx, unsigned ctrl);
static size_t _serialize(const type* _this, const unsigned char* buffer, char* textbuf);

View file

@ -5,6 +5,7 @@
#include <cstdlib>
#include <list>
#include <vector>
#include "text.hpp"
namespace recentfiles
{
@ -12,48 +13,48 @@ class path
{
public:
path();
path(const std::string& p);
std::string serialize() const;
static path deserialize(const std::string& s);
path(const text& p);
text serialize() const;
static path deserialize(const text& s);
bool check() const;
std::string display() const;
std::string get_path() const;
text display() const;
text get_path() const;
bool operator==(const path& p) const;
private:
std::string pth;
text pth;
};
class multirom
{
public:
multirom();
std::string serialize() const;
static multirom deserialize(const std::string& s);
text serialize() const;
static multirom deserialize(const text& s);
bool check() const;
std::string display() const;
text display() const;
bool operator==(const multirom& p) const;
std::string packfile;
std::string singlefile;
std::string core;
std::string system;
std::string region;
std::vector<std::string> files;
text packfile;
text singlefile;
text core;
text system;
text region;
std::vector<text> files;
};
class namedobj
{
public:
namedobj();
std::string serialize() const;
static namedobj deserialize(const std::string& s);
text serialize() const;
static namedobj deserialize(const text& s);
bool check() const;
std::string display() const;
text display() const;
bool operator==(const namedobj& p) const;
std::string _id;
std::string _filename;
std::string _display;
text _id;
text _filename;
text _display;
};
struct hook
@ -66,13 +67,13 @@ template<class T>
class set
{
public:
set(const std::string& cfgfile, size_t maxcount) __attribute__((noinline));
set(const text& cfgfile, size_t maxcount) __attribute__((noinline));
void add(const T& file);
void add_hook(hook& h);
void remove_hook(hook& h);
std::list<T> get();
private:
std::string cfgfile;
text cfgfile;
size_t maxcount;
std::list<hook*> hooks;
};

View file

@ -10,6 +10,7 @@
#include <iostream>
#include <fstream>
#include <set>
#include "text.hpp"
class rrdata_set
@ -30,7 +31,7 @@ public:
/**
* Create load id from string (mainly intended for debugging).
*/
instance(const std::string& id) throw();
instance(const text& id) throw();
/**
* The load ID.
*/
@ -127,7 +128,7 @@ public:
* parameter lazy: If true, just switch to project, don't read the IDs.
* throws std::bad_alloc: Not enough memory
*/
void read_base(const std::string& projectfile, bool lazy) throw(std::bad_alloc);
void read_base(const text& projectfile, bool lazy) throw(std::bad_alloc);
/**
* Is lazy?
*/
@ -196,7 +197,7 @@ public:
/**
* Debugging functions.
*/
std::string debug_dump();
text debug_dump();
bool debug_add(const instance& b) { return _add(b); }
void debug_add(const instance& b, const instance& e) { return _add(b, e); }
bool debug_in_set(const instance& b) { return _in_set(b); }
@ -214,7 +215,7 @@ private:
std::set<std::pair<instance, instance>> data;
std::ofstream ohandle;
bool handle_open;
std::string current_projectfile;
text current_projectfile;
bool lazy_mode;
uint64_t rcount;
};

View file

@ -9,6 +9,6 @@
* Returns: Full path of current executable.
* Throws std::runtime_error: Operation not supported!
*/
std::string running_executable();
text running_executable();
#endif

View file

@ -6,6 +6,7 @@
#include <set>
#include "threads.hpp"
#include "string.hpp"
#include "text.hpp"
#include <string>
namespace settingvar
@ -52,11 +53,11 @@ public:
/**
* New item in set.
*/
virtual void create(set& s, const std::string& name, superbase& svar) = 0;
virtual void create(set& s, const text& name, superbase& svar) = 0;
/**
* Deleted item from set.
*/
virtual void destroy(set& s, const std::string& name) = 0;
virtual void destroy(set& s, const text& name) = 0;
/**
* Destroyed the entiere set.
*/
@ -73,11 +74,11 @@ public:
/**
* Register a supervariable.
*/
void do_register(const std::string& name, superbase& info);
void do_register(const text& name, superbase& info);
/**
* Unregister a supervariable.
*/
void do_unregister(const std::string& name, superbase& info);
void do_unregister(const text& name, superbase& info);
/**
* Add a callback on new supervariable.
*/
@ -107,11 +108,11 @@ public:
/**
* Get all settings.
*/
std::set<std::string> get_settings_set() throw(std::bad_alloc);
std::set<text> get_settings_set() throw(std::bad_alloc);
/**
* Get setting.
*/
base& operator[](const std::string& name);
base& operator[](const text& name);
/**
* Add a listener.
*/
@ -123,11 +124,11 @@ public:
/**
* Register a setting.
*/
void do_register(const std::string& name, base& _setting) throw(std::bad_alloc);
void do_register(const text& name, base& _setting) throw(std::bad_alloc);
/**
* Unregister a setting.
*/
void do_unregister(const std::string& name, base& _setting) throw(std::bad_alloc);
void do_unregister(const text& name, base& _setting) throw(std::bad_alloc);
/**
* Fire listener.
*/
@ -149,8 +150,8 @@ private:
public:
xlistener(group& _grp);
~xlistener();
void create(set& s, const std::string& name, superbase& sb);
void destroy(set& s, const std::string& name);
void create(set& s, const text& name, superbase& sb);
void destroy(set& s, const text& name);
void kill(set& s);
private:
group& grp;
@ -172,13 +173,13 @@ public:
*
* Note: This reads cached values in perference to actual values.
*/
std::map<std::string, std::string> get_all();
std::map<text, text> get_all();
/**
* Enumerate valid keys.
*
* Returns: The set of actually valid keys.
*/
std::set<std::string> get_keys();
std::set<text> get_keys();
/**
* Set a value.
*
@ -189,7 +190,7 @@ public:
*
* Note: If setting has cached value and setting it succeeds, the cached value is cleared.
*/
void set(const std::string& name, const std::string& value, bool allow_invalid = false) throw(std::bad_alloc,
void set(const text& name, const text& value, bool allow_invalid = false) throw(std::bad_alloc,
std::runtime_error);
/**
* Get a value.
@ -198,11 +199,11 @@ public:
* Return: Actual value of the setting.
* Throws std::runtime_error: Setting doesn't exist.
*/
std::string get(const std::string& name) throw(std::bad_alloc, std::runtime_error);
text get(const text& name) throw(std::bad_alloc, std::runtime_error);
/**
* Get descriptor for.
*/
const description& get_description(const std::string& name) throw(std::bad_alloc,
const description& get_description(const text& name) throw(std::bad_alloc,
std::runtime_error);
/**
* Get human-readable name.
@ -211,10 +212,10 @@ public:
* Return: Human-readable name of the setting.
* Throws std::runtime_error: Setting doesn't exist.
*/
std::string get_hname(const std::string& name) throw(std::bad_alloc, std::runtime_error);
text get_hname(const text& name) throw(std::bad_alloc, std::runtime_error);
private:
group& grp;
std::map<std::string, std::string> badcache;
std::map<text, text> badcache;
};
/**
@ -229,10 +230,10 @@ struct enumeration
values[bound = x++] = i;
}
}
std::string get(unsigned val) { return values.count(val) ? values[val] : ""; }
text get(unsigned val) { return values.count(val) ? values[val] : ""; }
unsigned max_val() { return bound; }
private:
std::map<unsigned, std::string> values;
std::map<unsigned, text> values;
unsigned bound;
};
@ -269,7 +270,7 @@ public:
/**
* Constructor.
*/
void _superbase(set& _s, const std::string& iname) throw(std::bad_alloc);
void _superbase(set& _s, const text& iname) throw(std::bad_alloc);
/**
* Destructor.
*/
@ -284,7 +285,7 @@ public:
void set_died();
private:
set* s;
std::string iname;
text iname;
};
/**
@ -296,7 +297,7 @@ public:
/**
* Constructor.
*/
base(group& _group, const std::string& iname, const std::string& hname, bool dynamic) throw(std::bad_alloc);
base(group& _group, const text& iname, const text& hname, bool dynamic) throw(std::bad_alloc);
/**
* Destructor.
*/
@ -304,16 +305,16 @@ public:
/**
* Set setting.
*/
virtual void str(const std::string& val) throw(std::runtime_error, std::bad_alloc) = 0;
virtual void str(const text& val) throw(std::runtime_error, std::bad_alloc) = 0;
/**
* Get setting.
*/
virtual std::string str() const throw(std::runtime_error, std::bad_alloc) = 0;
virtual text str() const throw(std::runtime_error, std::bad_alloc) = 0;
/**
* Get setting name.
*/
const std::string& get_iname() const throw() { return iname; }
const std::string& get_hname() const throw() { return hname; }
const text& get_iname() const throw() { return iname; }
const text& get_hname() const throw() { return hname; }
/**
* Get setting description.
*/
@ -326,8 +327,8 @@ protected:
base(const base&);
base& operator=(const base&);
group* sgroup;
std::string iname;
std::string hname;
text iname;
text hname;
bool is_dynamic;
};
@ -343,7 +344,7 @@ public:
/**
* Constructor.
*/
variable(group& sgroup, const std::string& iname, const std::string& hname,
variable(group& sgroup, const text& iname, const text& hname,
valtype_t defaultvalue, bool dynamic = false)
: base(sgroup, iname, hname, dynamic)
{
@ -358,7 +359,7 @@ public:
/**
* Set setting.
*/
void str(const std::string& val) throw(std::runtime_error, std::bad_alloc)
void str(const text& val) throw(std::runtime_error, std::bad_alloc)
{
{
threads::arlock h(get_setting_lock());
@ -369,7 +370,7 @@ public:
/**
* Get setting.
*/
std::string str() const throw(std::runtime_error, std::bad_alloc)
text str() const throw(std::runtime_error, std::bad_alloc)
{
threads::arlock h(get_setting_lock());
return model::write(value);
@ -426,7 +427,7 @@ public:
/**
* Constructor.
*/
supervariable(set& _s, const std::string& _iname, const std::string& _hname, valtype_t _defaultvalue)
supervariable(set& _s, const text& _iname, const text& _hname, valtype_t _defaultvalue)
throw(std::bad_alloc)
: s(_s)
{
@ -472,8 +473,8 @@ public:
}
private:
set& s;
std::string iname;
std::string hname;
text iname;
text hname;
valtype_t defaultvalue;
};
@ -493,14 +494,14 @@ template<typename values> struct model_bool
{
typedef bool valtype_t;
static bool valid(bool val) { return true; /* Any boolean is valid boolean. */ }
static bool read(const std::string& val)
static bool read(const text& val)
{
int x = string_to_bool(val);
if(x < 0)
throw std::runtime_error("Invalid boolean value");
return (x != 0);
}
static std::string write(bool val)
static text write(bool val)
{
return val ? values::enable : values::disable;
}
@ -526,14 +527,14 @@ template<int32_t minimum, int32_t maximum> struct model_int
{
typedef int32_t valtype_t;
static bool valid(int32_t val) { return (val >= minimum && val <= maximum); }
static int32_t read(const std::string& val)
static int32_t read(const text& val)
{
int x = parse_value<int32_t>(val);
if(x < minimum || x > maximum)
(stringfmt() << "Value out of range (" << minimum << " to " << maximum << ")").throwex();
return x;
}
static std::string write(int32_t val)
static text write(int32_t val)
{
return (stringfmt() << val).str();
}
@ -558,17 +559,17 @@ template<int32_t m, int32_t M> description& description_get(model_int<m, M> X)
*/
struct model_path
{
typedef std::string valtype_t;
static bool valid(std::string val) { return true; /* Any boolean is valid boolean. */ }
static std::string read(const std::string& val)
typedef text valtype_t;
static bool valid(text val) { return true; /* Any boolean is valid boolean. */ }
static text read(const text& val)
{
return val;
}
static std::string write(std::string val)
static text write(text val)
{
return val;
}
static std::string transform(std::string val)
static text transform(text val)
{
return (val != "") ? val : ".";
}
@ -592,7 +593,7 @@ template<enumeration* e> struct model_enumerated
{
typedef unsigned valtype_t;
static bool valid(unsigned val) { return (val <= e->max_val()); }
static unsigned read(const std::string& val)
static unsigned read(const text& val)
{
for(unsigned i = 0; i <= e->max_val(); i++)
if(val == e->get(i))
@ -602,7 +603,7 @@ template<enumeration* e> struct model_enumerated
(stringfmt() << "Value out of range (0 to " << e->max_val() << ")").throwex();
return x;
}
static std::string write(unsigned val)
static text write(unsigned val)
{
return e->get(val);
}

View file

@ -65,7 +65,7 @@ public:
* Returns: Hexadecimal hash
* Throws std::bad_alloc: Not enough memory.
*/
static std::string tostring(const uint8_t* hashout) throw(std::bad_alloc)
static text tostring(const uint8_t* hashout) throw(std::bad_alloc)
{
return hex::b_to(hashout, 32);
}
@ -87,7 +87,7 @@ public:
* Returns: The hash in hex form.
* Throws std::bad_alloc: Not enough memory.
*/
std::string read() throw(std::bad_alloc)
text read() throw(std::bad_alloc)
{
uint8_t x[32];
read(x);
@ -138,7 +138,7 @@ public:
* Returns: Hexadecimal hash of the data.
* Throws std::bad_alloc: Not enough memory.
*/
static std::string hash(const uint8_t* data, size_t datalen) throw(std::bad_alloc)
static text hash(const uint8_t* data, size_t datalen) throw(std::bad_alloc)
{
uint8_t hashout[32];
hash(hashout, data, datalen);
@ -152,7 +152,7 @@ public:
* Returns: Hexadecimal hash of the data.
* Throws std::bad_alloc: Not enough memory.
*/
static std::string hash(const std::vector<uint8_t>& data) throw(std::bad_alloc)
static text hash(const std::vector<uint8_t>& data) throw(std::bad_alloc)
{
uint8_t hashout[32];
hash(hashout, &data[0], data.size());
@ -166,7 +166,7 @@ public:
* Returns: Hexadecimal hash of the data.
* Throws std::bad_alloc: Not enough memory.
*/
static std::string hash(const std::vector<char>& data) throw(std::bad_alloc)
static text hash(const std::vector<char>& data) throw(std::bad_alloc)
{
uint8_t hashout[32];
hash(hashout, reinterpret_cast<const uint8_t*>(&data[0]), data.size());

View file

@ -9,11 +9,12 @@
#include <map>
#include <functional>
#include "minmax.hpp"
#include "text.hpp"
#include <cstring>
namespace streamcompress
{
std::map<std::string, std::string> parse_attributes(const std::string& val);
std::map<text, text> parse_attributes(const text& val);
class base
{
@ -31,11 +32,11 @@ public:
*/
virtual bool process(uint8_t*& in, size_t& insize, uint8_t*& out, size_t& outsize, bool final) = 0;
static std::set<std::string> get_compressors();
static base* create_compressor(const std::string& name, const std::string& args);
static void do_register(const std::string& name,
std::function<base*(const std::string&)> ctor);
static void do_unregister(const std::string& name);
static std::set<text> get_compressors();
static base* create_compressor(const text& name, const text& args);
static void do_register(const text& name,
std::function<base*(const text&)> ctor);
static void do_unregister(const text& name);
};
class iostream

168
include/library/text.hpp Normal file
View file

@ -0,0 +1,168 @@
#ifndef _library__text__hpp__included__
#define _library__text__hpp__included__
#include <cstdint>
#include <string>
#include <cstdlib>
#include <exception>
#include <algorithm>
#include <iostream>
#include "memtracker.hpp"
#include "utf8.hpp"
/**
* An UTF-32 string.
*/
class text
{
public:
text() throw();
text(const std::string& str) throw(std::bad_alloc);
text(const std::u32string& str) throw(std::bad_alloc);
text(const char* str) throw(std::bad_alloc);
text(const char* str, size_t len) throw(std::bad_alloc);
text(const char32_t* str) throw(std::bad_alloc);
text(const char32_t* str, size_t len) throw(std::bad_alloc);
text(const text& t) throw(std::bad_alloc);
text& operator=(const text& t) throw(std::bad_alloc);
~text() throw();
size_t length() const throw() { return len; }
operator std::string() const throw(std::bad_alloc) { return utf8::to8(data, len); }
operator std::u32string() const throw(std::bad_alloc) { return std::u32string(data, data + len); }
char32_t& operator[](size_t idx) throw(std::out_of_range)
{
if(idx >= len) throw std::out_of_range("String index out of range");
return data[idx];
}
const char32_t& operator[](size_t idx) const throw(std::out_of_range)
{
if(idx >= len) throw std::out_of_range("String index out of range");
return data[idx];
}
void set_tracking_category(const char* category);
text substr(size_t start, size_t len) const throw(std::bad_alloc, std::out_of_range);
text substr(size_t start) const throw(std::bad_alloc, std::out_of_range);
size_t find_first_of(const char32_t* chlist, size_t ptr = 0) const throw();
size_t find_first_not_of(const char32_t* chlist, size_t ptr = 0) const throw();
size_t find_last_of(const char32_t* chlist, size_t ptr = 0) const throw();
size_t find_last_not_of(const char32_t* chlist, size_t ptr = 0) const throw();
text strip_CR() const throw(std::bad_alloc);
static text& istrip_CR(text& t) throw();
void ostream_helper(std::ostream& os) const;
static text getline(std::istream& is);
std::pair<size_t, size_t> output_utf8_fragment(size_t startidx, char* out, size_t outsize) const throw();
size_t length_utf8() const throw();
const char* c_str() const throw(std::bad_alloc);
std::string to_cpp_str() const throw(std::bad_alloc) { return (std::string)*this; }
void resize(size_t sz);
static text concatenate(const text& a, const text& b) throw(std::bad_alloc);
static text concatenate(const text& a, const std::string& b) throw(std::bad_alloc);
static text concatenate(const text& a, const std::u32string& b) throw(std::bad_alloc);
static text concatenate(const text& a, const char* b) throw(std::bad_alloc);
static text concatenate(const text& a, const char32_t* b) throw(std::bad_alloc);
static text concatenate(const std::string& a, const text& b) throw(std::bad_alloc);
static text concatenate(const std::u32string& a, const text& b) throw(std::bad_alloc);
static text concatenate(const char* a, const text& b) throw(std::bad_alloc);
static text concatenate(const char32_t* a, const text& b) throw(std::bad_alloc);
static text& concatenate_inplace(text& a, const text& b) throw(std::bad_alloc);
static text& concatenate_inplace(text& a, const std::string& b) throw(std::bad_alloc);
static text& concatenate_inplace(text& a, const std::u32string& b) throw(std::bad_alloc);
static text& concatenate_inplace(text& a, const char* b) throw(std::bad_alloc);
static text& concatenate_inplace(text& a, const char32_t* b) throw(std::bad_alloc);
static int compare(const text& a, const text& b) throw();
static int compare(const text& a, const std::string& b) throw();
static int compare(const text& a, const std::u32string& b) throw();
static int compare(const text& a, const char* b) throw();
static int compare(const text& a, const char32_t* b) throw();
static int compare(const std::string& a, const text& b) throw() { return -compare(b, a); }
static int compare(const std::u32string& a, const text& b) throw() { return -compare(b, a); }
static int compare(const char* a, const text& b) throw() { return -compare(b, a); }
static int compare(const char32_t* a, const text& b) throw() { return -compare(b, a); }
const char32_t* _internal_ptr() const { return data; }
char32_t* _internal_ptr_mut() { return data; }
void _internal_set_len(size_t _len) { len = _len; }
void _internal_init() { data = NULL; len = 0; }
void _internal_reallocate(size_t _cap) { reallocate(_cap); }
private:
void reallocate(size_t newsize);
char32_t* data;
size_t len;
size_t allocated;
const char* c_str_buf;
memtracker::autorelease tracker;
};
inline bool operator<(const text& a, const text& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const text& a, const text& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const text& a, const text& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const text& a, const text& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const text& a, const text& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const text& a, const text& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const text& a, const text& b) throw() { return text::concatenate(a, b); }
inline text& operator+=(text& a, const text& b) throw() { return text::concatenate_inplace(a, b); }
inline bool operator<(const std::string& a, const text& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const std::string& a, const text& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const std::string& a, const text& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const std::string& a, const text& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const std::string& a, const text& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const std::string& a, const text& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const std::string& a, const text& b) throw() { return text::concatenate(a, b); }
inline bool operator<(const std::u32string& a, const text& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const std::u32string& a, const text& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const std::u32string& a, const text& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const std::u32string& a, const text& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const std::u32string& a, const text& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const std::u32string& a, const text& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const std::u32string& a, const text& b) throw() { return text::concatenate(a, b); }
inline bool operator<(const char* a, const text& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const char* a, const text& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const char* a, const text& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const char* a, const text& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const char* a, const text& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const char* a, const text& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const char* a, const text& b) throw() { return text::concatenate(a, b); }
inline bool operator<(const char32_t* a, const text& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const char32_t* a, const text& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const char32_t* a, const text& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const char32_t* a, const text& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const char32_t* a, const text& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const char32_t* a, const text& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const char32_t* a, const text& b) throw() { return text::concatenate(a, b); }
inline bool operator<(const text& a, const std::string& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const text& a, const std::string& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const text& a, const std::string& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const text& a, const std::string& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const text& a, const std::string& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const text& a, const std::string& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const text& a, const std::string& b) throw() { return text::concatenate(a, b); }
inline text& operator+=(text& a, const std::string& b) throw() { return text::concatenate_inplace(a, b); }
inline bool operator<(const text& a, const std::u32string& b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const text& a, const std::u32string& b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const text& a, const std::u32string& b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const text& a, const std::u32string& b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const text& a, const std::u32string& b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const text& a, const std::u32string& b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const text& a, const std::u32string& b) throw() { return text::concatenate(a, b); }
inline text& operator+=(text& a, const std::u32string& b) throw() { return text::concatenate_inplace(a, b); }
inline bool operator<(const text& a, const char* b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const text& a, const char* b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const text& a, const char* b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const text& a, const char* b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const text& a, const char* b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const text& a, const char* b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const text& a, const char* b) throw() { return text::concatenate(a, b); }
inline text& operator+=(text& a, const char* b) throw() { return text::concatenate_inplace(a, b); }
inline bool operator<(const text& a, const char32_t* b) throw() { return text::compare(a, b) < 0; }
inline bool operator<=(const text& a, const char32_t* b) throw() { return text::compare(a, b) <= 0; }
inline bool operator==(const text& a, const char32_t* b) throw() { return text::compare(a, b) == 0; }
inline bool operator!=(const text& a, const char32_t* b) throw() { return text::compare(a, b) != 0; }
inline bool operator>=(const text& a, const char32_t* b) throw() { return text::compare(a, b) >= 0; }
inline bool operator>(const text& a, const char32_t* b) throw() { return text::compare(a, b) > 0; }
inline text operator+(const text& a, const char32_t* b) throw() { return text::concatenate(a, b); }
inline text& operator+=(text& a, const char32_t* b) throw() { return text::concatenate_inplace(a, b); }
inline std::ostream& operator<<(std::ostream& os, const text& a) { a.ostream_helper(os); return os; }
#endif

View file

@ -16,20 +16,20 @@ public:
*
* Returns: The known schemes.
*/
std::set<std::string> get_schemes();
std::set<text> get_schemes();
/**
* Delete rewrite pattern.
*
* Parameter scheme: The scheme to delete.
*/
void delete_rewrite(const std::string& scheme);
void delete_rewrite(const text& scheme);
/**
* Set rewrite pattern
*
* Parameter scheme: The scheme to rewrite.
* Parameter pattern: The target pattern to rewrite to.
*/
void set_rewrite(const std::string& scheme, const std::string& pattern);
void set_rewrite(const text& scheme, const text& pattern);
/**
* Get rewrite pattern
*
@ -37,29 +37,29 @@ public:
* Returns: The current rewrite pattern.
* Throws std::runtime_error: No pattern for scheme.
*/
std::string get_rewrite(const std::string& scheme);
text get_rewrite(const text& scheme);
/**
* Rewrite URI.
*
* Parameter uri: The URI to rewrite.
* Returns: The rewritten URI.
*/
std::string operator()(const std::string& uri);
text operator()(const text& uri);
/**
* Save URI rewrite patterns to file.
*
* Parameter filename: The name of the file.
*/
void save(const std::string& filename);
void save(const text& filename);
/**
* Load URI rewrite pattern from file.
*
* Parameter filename: The name of the file.
*/
void load(const std::string& filename);
void load(const text& filename);
private:
threads::lock mlock;
std::map<std::string, std::string> rewrites;
std::map<text, text> rewrites;
};
}

View file

@ -30,6 +30,13 @@ int32_t parse_byte(int ch, uint16_t& state) throw();
* Returns: The length in codepoints.
*/
size_t strlen(const std::string& str) throw();
/**
* Return length of string in UTF-8 codepoints and bytes.
*
* Parameter str: The string.
* Returns: The length in codepoints (first) and bytes (second).
*/
std::pair<size_t,size_t> strlen_c(const char* str) throw();
/**
* Transform UTF-8 into UTF-32.
@ -41,6 +48,11 @@ std::u32string to32(const std::string& utf8);
*/
std::string to8(const std::u32string& utf32);
/**
* Transform UTF-32 into UTF-8.
*/
std::string to8(const char32_t* ptr, size_t len);
/**
* Iterator copy from UTF-8 to UTF-32
*/

View file

@ -104,7 +104,7 @@ private:
volatile bool exception_oom;
volatile uint64_t waitamt_busy;
volatile uint64_t waitamt_work;
std::string exception_text;
text exception_text;
};
#endif

View file

@ -10,6 +10,7 @@
#include <sstream>
#include <zlib.h>
#include "string.hpp"
#include "text.hpp"
namespace zip
{
@ -145,12 +146,12 @@ public:
/**
* This iterator iterates members of ZIP archive in forward order.
*/
typedef iterator_class<std::map<std::string, unsigned long long>::iterator, std::string> iterator;
typedef iterator_class<std::map<text, unsigned long long>::iterator, text> iterator;
/**
* This iterator iterates members of ZIP archive in reverse order
*/
typedef iterator_class<std::map<std::string, unsigned long long>::reverse_iterator, std::string>
typedef iterator_class<std::map<text, unsigned long long>::reverse_iterator, text>
riterator;
/**
@ -160,7 +161,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Can't open the ZIP file.
*/
reader(const std::string& zipfile) throw(std::bad_alloc, std::runtime_error);
reader(const text& zipfile) throw(std::bad_alloc, std::runtime_error);
/**
* Destroy the ZIP reader. Opened input streams continue to be valid.
@ -173,7 +174,7 @@ public:
* returns: The member name
* throws std::bad_alloc: Not enough memory.
*/
std::string find_first() throw(std::bad_alloc);
text find_first() throw(std::bad_alloc);
/**
* Gives the name of the next member after specified, or "" if that member is the last.
@ -182,7 +183,7 @@ public:
* returns: The member name
* throws std::bad_alloc: Not enough memory.
*/
std::string find_next(const std::string& name) throw(std::bad_alloc);
text find_next(const text& name) throw(std::bad_alloc);
/**
* Starting iterator
@ -221,7 +222,7 @@ public:
* parameter name: The name of the member to check
* returns: True if specified member exists, false otherwise.
*/
bool has_member(const std::string& name) throw();
bool has_member(const text& name) throw();
/**
* Opens specified member. The resulting stream is not seekable, allocated using new and continues to be valid
@ -232,7 +233,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: The specified member does not exist
*/
std::istream& operator[](const std::string& name) throw(std::bad_alloc, std::runtime_error);
std::istream& operator[](const text& name) throw(std::bad_alloc, std::runtime_error);
/**
* Reads a file consisting of single line.
*
@ -243,7 +244,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Error reading file.
*/
bool read_linefile(const std::string& member, std::string& out, bool conditional = false)
bool read_linefile(const text& member, text& out, bool conditional = false)
throw(std::bad_alloc, std::runtime_error);
/**
* Read a raw file.
@ -253,7 +254,7 @@ public:
* Throws std::bad_alloc: Not enough memory.
* Throws std::runtime_error: Error reading file.
*/
void read_raw_file(const std::string& member, std::vector<char>& out) throw(std::bad_alloc,
void read_raw_file(const text& member, std::vector<char>& out) throw(std::bad_alloc,
std::runtime_error);
/**
* Reads a file consisting of single numeric constant.
@ -266,10 +267,10 @@ public:
* Throws std::runtime_error: Error reading file.
*/
template<typename T>
bool read_numeric_file(const std::string& member, T& out, bool conditional = false)
bool read_numeric_file(const text& member, T& out, bool conditional = false)
throw(std::bad_alloc, std::runtime_error)
{
std::string _out;
text _out;
if(!read_linefile(member, _out, conditional))
return false;
out = parse_value<T>(_out);
@ -278,7 +279,7 @@ public:
private:
reader(reader&);
reader& operator=(reader&);
std::map<std::string, unsigned long long> offsets;
std::map<text, unsigned long long> offsets;
std::ifstream* zipstream;
size_t* refcnt;
};
@ -296,7 +297,7 @@ private:
* throw std::bad_alloc: Not enough memory.
* throw std::runtime_error: The file does not exist or can't be opened.
*/
std::istream& openrel(const std::string& name, const std::string& referencing_path) throw(std::bad_alloc,
std::istream& openrel(const text& name, const text& referencing_path) throw(std::bad_alloc,
std::runtime_error);
/**
@ -309,7 +310,7 @@ std::istream& openrel(const std::string& name, const std::string& referencing_pa
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: The file does not exist or can't be opened.
*/
std::vector<char> readrel(const std::string& name, const std::string& referencing_path)
std::vector<char> readrel(const text& name, const text& referencing_path)
throw(std::bad_alloc, std::runtime_error);
/**
@ -321,7 +322,7 @@ std::vector<char> readrel(const std::string& name, const std::string& referencin
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Bad path.
*/
std::string resolverel(const std::string& name, const std::string& referencing_path) throw(std::bad_alloc,
text resolverel(const text& name, const text& referencing_path) throw(std::bad_alloc,
std::runtime_error);
/**
@ -331,7 +332,7 @@ std::string resolverel(const std::string& name, const std::string& referencing_p
* returns: True if file exists, false if not.
* throws std::bad_alloc: Not enough memory.
*/
bool file_exists(const std::string& name) throw(std::bad_alloc);
bool file_exists(const text& name) throw(std::bad_alloc);
/**
* This class handles writing a ZIP archives.
@ -348,7 +349,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Can't open archive or invalid argument.
*/
writer(const std::string& zipfile, unsigned _compression) throw(std::bad_alloc, std::runtime_error);
writer(const text& zipfile, unsigned _compression) throw(std::bad_alloc, std::runtime_error);
writer(std::ostream& stream, unsigned _compression) throw(std::bad_alloc, std::runtime_error);
/**
* Destroys ZIP writer, aborting the transaction (unless commit() has been called).
@ -373,7 +374,7 @@ public:
* throws std::logic_error: Existing file open.
* throws std::runtime_error: Illegal name.
*/
std::ostream& create_file(const std::string& name) throw(std::bad_alloc, std::logic_error,
std::ostream& create_file(const text& name) throw(std::bad_alloc, std::logic_error,
std::runtime_error);
/**
@ -393,7 +394,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Error from operating system.
*/
void write_linefile(const std::string& member, const std::string& value, bool conditional = false)
void write_linefile(const text& member, const text& value, bool conditional = false)
throw(std::bad_alloc, std::runtime_error);
/**
* Write a raw file. No existing member may be open.
@ -403,7 +404,7 @@ public:
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Error from operating system.
*/
void write_raw_file(const std::string& member, const std::vector<char>& content)
void write_raw_file(const text& member, const std::vector<char>& content)
throw(std::bad_alloc, std::runtime_error);
/**
* Write a file consisting of a single number. No existing member may be open.
@ -414,7 +415,7 @@ public:
* throws std::runtime_error: Error from operating system.
*/
template<typename T>
void write_numeric_file(const std::string& member, T value) throw(std::bad_alloc, std::runtime_error)
void write_numeric_file(const text& member, T value) throw(std::bad_alloc, std::runtime_error)
{
write_linefile(member, (stringfmt() << value).str());
}
@ -431,12 +432,12 @@ private:
writer& operator=(writer&);
std::ostream* zipstream;
bool system_stream;
std::string temp_path;
std::string zipfile_path;
std::string open_file;
text temp_path;
text zipfile_path;
text open_file;
uint32_t base_offset;
std::vector<char> current_compressed_file;
std::map<std::string, file_info> files;
std::map<text, file_info> files;
unsigned compression;
boost::iostreams::filtering_ostream* s;
uint32_t basepos;

View file

@ -2,6 +2,7 @@
#define lsnes__hpp__included__
#include <iostream>
#include "library/text.hpp"
#define STILL_HERE do { std::cerr << "Still here at file " << __FILE__ << " line " << __LINE__ << "." << std::endl; } \
while(0)
@ -13,7 +14,7 @@
#define PROFILE_ACCURACY
#endif
extern std::string lsnes_version;
extern std::string lsnes_git_revision;
extern text lsnes_version;
extern text lsnes_git_revision;
#endif

View file

@ -4,7 +4,7 @@
namespace lua { class parameters; }
namespace lua { class state; }
uint64_t lua_get_vmabase(const std::string& vma);
uint64_t lua_get_vmabase(const text& vma);
uint64_t lua_get_read_address(lua::parameters& P);
class lua_address
@ -12,9 +12,9 @@ class lua_address
public:
lua_address(lua::state& L);
static int create(lua::state& L, lua::parameters& P);
std::string print();
text print();
uint64_t get();
std::string get_vma();
text get_vma();
uint64_t get_offset();
int l_get(lua::state& L, lua::parameters& P);
int l_get_vma(lua::state& L, lua::parameters& P);
@ -24,7 +24,7 @@ public:
static size_t overcommit();
template<class T, bool _bswap> int rw(lua::state& L, lua::parameters& P);
private:
std::string vma;
text vma;
uint64_t addr;
};

View file

@ -25,7 +25,7 @@ struct lua_palette
}
~lua_palette();
threads::lock palette_mutex;
std::string print();
text print();
static int create(lua::state& L, lua::parameters& P);
static int load(lua::state& L, lua::parameters& P);
static int load_str(lua::state& L, lua::parameters& P);
@ -49,7 +49,7 @@ struct lua_bitmap
size_t height;
uint16_t* pixels;
std::vector<char> save_png(const lua_palette& pal) const;
std::string print();
text print();
static int create(lua::state& L, lua::parameters& P);
template<bool outside, bool clip> int draw(lua::state& L, lua::parameters& P);
int pset(lua::state& L, lua::parameters& P);
@ -73,7 +73,7 @@ struct lua_dbitmap
size_t height;
framebuffer::color* pixels;
std::vector<char> save_png() const;
std::string print();
text print();
static int create(lua::state& L, lua::parameters& P);
template<bool outside, bool clip> int draw(lua::state& L, lua::parameters& P);
int pset(lua::state& L, lua::parameters& P);
@ -94,7 +94,7 @@ struct lua_loaded_bitmap
std::vector<int64_t> bitmap;
std::vector<int64_t> palette;
static struct lua_loaded_bitmap load(std::istream& stream);
static struct lua_loaded_bitmap load(const std::string& name);
static struct lua_loaded_bitmap load(const text& name);
template<bool png> static int load(lua::state& L, lua::parameters& P);
template<bool png> static int load_str(lua::state& L, lua::parameters& P);
};

View file

@ -27,7 +27,7 @@ extern lua::class_group lua_class_fileio;
void push_keygroup_parameters(lua::state& L, keyboard::key& p);
void lua_renderq_run(lua::render_context* ctx, void* synchronous_paint_ctx);
uint64_t lua_get_vmabase(const std::string& vma);
uint64_t lua_get_vmabase(const text& vma);
uint64_t lua_get_read_address(lua::parameters& P);
#endif

View file

@ -66,27 +66,27 @@ struct lua_state
void callback_do_readwrite() throw();
void callback_do_idle() throw();
void callback_do_timer() throw();
void callback_pre_load(const std::string& name) throw();
void callback_err_load(const std::string& name) throw();
void callback_post_load(const std::string& name, bool was_state) throw();
void callback_pre_save(const std::string& name, bool is_state) throw();
void callback_err_save(const std::string& name) throw();
void callback_post_save(const std::string& name, bool is_state) throw();
void callback_pre_load(const text& name) throw();
void callback_err_load(const text& name) throw();
void callback_post_load(const text& name, bool was_state) throw();
void callback_pre_save(const text& name, bool is_state) throw();
void callback_err_save(const text& name) throw();
void callback_post_save(const text& name, bool is_state) throw();
void callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw();
void callback_quit() throw();
void callback_keyhook(const std::string& key, keyboard::key& p) throw();
void callback_keyhook(const text& key, keyboard::key& p) throw();
void callback_do_unsafe_rewind(movie& mov, void* u);
bool callback_do_button(uint32_t port, uint32_t controller, uint32_t index, const char* type);
void callback_movie_lost(const char* what);
void callback_do_latch(std::list<std::string>& args);
void callback_do_latch(std::list<text>& args);
void run_startup_scripts();
void add_startup_script(const std::string& file);
void add_startup_script(const text& file);
uint64_t timed_hook(int timer) throw();
const std::map<std::string, std::u32string>& get_watch_vars();
const std::map<text, text>& get_watch_vars();
void do_eval_lua(const std::string& c) throw(std::bad_alloc);
void do_run_lua(const std::string& c) throw(std::bad_alloc);
void do_eval_lua(const text& c) throw(std::bad_alloc);
void do_run_lua(const text& c) throw(std::bad_alloc);
void run_sysrc_lua(bool rerun);
bool requests_repaint;
@ -98,7 +98,7 @@ struct lua_state
uint32_t* hscl;
uint32_t* vscl;
bool* veto_flag;
std::set<std::string> hooked_keys;
std::set<text> hooked_keys;
uint64_t idle_hook_time;
uint64_t timer_hook_time;
lua::render_context* renderq_saved;
@ -106,11 +106,11 @@ struct lua_state
bool renderq_redirect;
void set_memory_limit(size_t max_mb);
std::list<std::string> startup_scripts;
std::map<std::string, std::u32string> watch_vars;
std::list<text> startup_scripts;
std::map<text, text> watch_vars;
private:
void do_reset();
void do_evaluate(const std::string& a);
void do_evaluate(const text& a);
bool run_lua_fragment() throw(std::bad_alloc);
template<typename... T> bool run_callback(lua::state::callback_list& list, T... args);
void run_synchronous_paint(struct lua::render_context* ctx);
@ -119,8 +119,8 @@ private:
bool recursive_flag;
const char* luareader_fragment;
command::_fnptr<> resetcmd;
command::_fnptr<const std::string&> evalcmd;
command::_fnptr<const std::string&> evalcmd2;
command::_fnptr<const text&> evalcmd;
command::_fnptr<const text&> evalcmd2;
command::_fnptr<command::arg_filename> runcmd;
struct _listener : public settingvar::listener
{

View file

@ -13,7 +13,7 @@ struct lua_unsaferewind
dynamic_state console_state;
//Extra state variable involved in fast movie restore. It is not part of normal console state.
uint64_t ptr;
std::string print()
text print()
{
return (stringfmt() << "to frame " << console_state.save_frame).str();
}

View file

@ -6,48 +6,48 @@
struct filedialog_type_entry
{
filedialog_type_entry(std::string _name, std::string _extensions, std::string _primaryext)
filedialog_type_entry(text _name, text _extensions, text _primaryext)
{
name = _name;
extensions = _extensions;
primaryext = _primaryext;
}
std::string name;
std::string extensions;
std::string primaryext;
text name;
text extensions;
text primaryext;
};
struct filedialog_input_params
{
std::vector<filedialog_type_entry> types;
int default_type;
std::string default_filename;
text default_filename;
};
struct filedialog_output_params
{
std::string path;
text path;
int typechoice;
};
class single_type
{
public:
typedef std::string returntype;
single_type(const std::string& _ext, const std::string& _desc = "");
typedef text returntype;
single_type(const text& _ext, const text& _desc = "");
filedialog_input_params input(bool save) const;
std::string output(const filedialog_output_params& p, bool save) const;
text output(const filedialog_output_params& p, bool save) const;
private:
std::string ext;
std::string desc;
text ext;
text desc;
};
class lua_script_type
{
public:
typedef std::string returntype;
typedef text returntype;
filedialog_input_params input(bool save) const;
std::string output(const filedialog_output_params& p, bool save) const;
text output(const filedialog_output_params& p, bool save) const;
};
extern lua_script_type filetype_lua_script;
@ -64,12 +64,12 @@ extern single_type filetype_trace;
extern single_type filetype_font;
extern single_type filetype_disassembly;
filedialog_output_params show_filedialog(wxWindow* parent, const std::string& title, const std::string& basepath,
const filedialog_input_params& p, const std::string& defaultname, bool saving);
filedialog_output_params show_filedialog(wxWindow* parent, const text& title, const text& basepath,
const filedialog_input_params& p, const text& defaultname, bool saving);
template<typename T>
typename T::returntype choose_file_load(wxWindow* parent, const std::string& title, const std::string& basepath,
const T& types, const std::string& defaultname = "")
typename T::returntype choose_file_load(wxWindow* parent, const text& title, const text& basepath,
const T& types, const text& defaultname = "")
{
filedialog_input_params p = types.input(false);
filedialog_output_params q = show_filedialog(parent, title, basepath, p, defaultname, false);
@ -77,8 +77,8 @@ typename T::returntype choose_file_load(wxWindow* parent, const std::string& tit
}
template<typename T>
typename T::returntype choose_file_save(wxWindow* parent, const std::string& title, const std::string& basepath,
const T& types, const std::string& defaultname = "")
typename T::returntype choose_file_save(wxWindow* parent, const text& title, const text& basepath,
const T& types, const text& defaultname = "")
{
filedialog_input_params p = types.input(true);
filedialog_output_params q = show_filedialog(parent, title, basepath, p, defaultname, true);

View file

@ -4,6 +4,7 @@
#include <wx/string.h>
#include <wx/wx.h>
#include <map>
#include "library/text.hpp"
class dumper_menu_monitor;
class dumper_info;
@ -22,7 +23,7 @@ private:
wxWindow* pwin;
int wxid_range_low;
int wxid_range_high;
std::map<std::string, dumper_information_1> existing_dumpers;
std::map<text, dumper_information_1> existing_dumpers;
emulator_instance& inst;
};

View file

@ -14,8 +14,8 @@ class emulator_instance;
class projects_menu : public wxMenu
{
public:
projects_menu(wxWindow* win, emulator_instance& _inst, int wxid_low, int wxid_high, const std::string& cfg,
std::function<void(const std::string& id)> cb);
projects_menu(wxWindow* win, emulator_instance& _inst, int wxid_low, int wxid_high, const text& cfg,
std::function<void(const text& id)> cb);
~projects_menu();
void on_select(wxCommandEvent& e);
void update();
@ -36,7 +36,7 @@ private:
int wxid_range_high;
std::map<int, wxMenuItem*> items;
std::map<int, recentfiles::namedobj> entries;
std::function<void(std::string id)> selected_cb;
std::function<void(text id)> selected_cb;
recentfiles::set<recentfiles::namedobj> rfiles;
};

View file

@ -12,7 +12,7 @@ template<class T>
class recent_menu : public wxMenu
{
public:
recent_menu(wxWindow* win, emulator_instance& _inst, int wxid_low, int wxid_high, const std::string& cfg,
recent_menu(wxWindow* win, emulator_instance& _inst, int wxid_low, int wxid_high, const text& cfg,
void (*cb)(emulator_instance& inst, const T& name)) __attribute__((noinline));
void on_select(wxCommandEvent& e);
void update();

View file

@ -26,7 +26,7 @@ private:
int wxid_range_low;
int wxid_range_high;
std::vector<wxMenuItem*> items;
std::map<int, std::string> cpunames;
std::map<int, text> cpunames;
std::function<void(bool enabled)> disabler_fn;
};

View file

@ -16,8 +16,8 @@ public:
void on_select(wxCommandEvent& e);
struct upload_entry
{
std::string name;
std::string url;
text name;
text url;
enum _auth
{
AUTH_DH25519

View file

@ -60,16 +60,14 @@ extern bool vflip_enabled;
extern bool rotate_enabled;
extern int wx_escape_count;
wxString towxstring(const std::string& str) throw(std::bad_alloc);
std::string tostdstring(const wxString& str) throw(std::bad_alloc);
wxString towxstring(const std::u32string& str) throw(std::bad_alloc);
std::u32string tou32string(const wxString& str) throw(std::bad_alloc);
wxString towxstring(const text& str) throw(std::bad_alloc);
text tostdstring(const wxString& str) throw(std::bad_alloc);
void bring_app_foreground();
std::string pick_archive_member(wxWindow* parent, const std::string& filename) throw(std::bad_alloc);
text pick_archive_member(wxWindow* parent, const text& filename) throw(std::bad_alloc);
void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, bool fscreen);
void handle_wx_keyboard(emulator_instance& inst, wxKeyEvent& e, bool polarity);
void handle_wx_mouse(emulator_instance& inst, wxMouseEvent& e);
std::string map_keycode_to_key(int kcode);
text map_keycode_to_key(int kcode);
void initialize_wx_keyboard(emulator_instance& inst);
void deinitialize_wx_keyboard(emulator_instance& inst);
void initialize_wx_mouse(emulator_instance& inst);
@ -81,7 +79,7 @@ void show_projectwindow(wxWindow* modwin, emulator_instance& inst);
void signal_core_change();
void do_save_configuration();
std::vector<interface_action_paramval> prompt_action_params(wxWindow* parent, const std::string& label,
std::vector<interface_action_paramval> prompt_action_params(wxWindow* parent, const text& label,
const std::list<interface_action_param>& params);
@ -90,7 +88,7 @@ void wxeditor_authors_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_hotkeys_display(wxWindow* parent);
void wxeditor_memorywatches_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_subtitles_display(wxWindow* parent, emulator_instance& inst);
std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
text wxeditor_keyselect(wxWindow* parent, bool clearable);
void show_wxeditor_voicesub(wxWindow* parent, emulator_instance& inst);
void open_rom_select_window();
void open_new_project_window(wxWindow* parent, emulator_instance& inst);
@ -104,9 +102,9 @@ void wxeditor_macro_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_hexedit_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_multitrack_display(wxWindow* parent, emulator_instance& inst);
bool wxeditor_plugin_manager_display(wxWindow* parent);
void wxeditor_tracelog_display(wxWindow* parent, emulator_instance& inst, int cpuid, const std::string& cpuname);
void wxeditor_tracelog_display(wxWindow* parent, emulator_instance& inst, int cpuid, const text& cpuname);
void wxeditor_disassembler_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_plugin_manager_notify_fail(const std::string& libname);
void wxeditor_plugin_manager_notify_fail(const text& libname);
//Auxillary windows.
void wxwindow_memorysearch_display(emulator_instance& inst);
@ -134,30 +132,30 @@ public:
};
//Prompt for stuff. These all can throw canceled_exception.
std::string pick_file_member(wxWindow* parent, const std::string& title, const std::string& startdir);
unsigned pick_among_index(wxWindow* parent, const std::string& title, const std::string& prompt,
const std::vector<std::string>& choices, unsigned defaultchoice = 0);
std::string pick_among(wxWindow* parent, const std::string& title, const std::string& prompt,
const std::vector<std::string>& choices, unsigned defaultchoice = 0);
std::string pick_text(wxWindow* parent, const std::string& title, const std::string& prompt,
const std::string& dflt = "", bool multiline = false);
text pick_file_member(wxWindow* parent, const text& title, const text& startdir);
unsigned pick_among_index(wxWindow* parent, const text& title, const text& prompt,
const std::vector<text>& choices, unsigned defaultchoice = 0);
text pick_among(wxWindow* parent, const text& title, const text& prompt,
const std::vector<text>& choices, unsigned defaultchoice = 0);
text pick_text(wxWindow* parent, const text& title, const text& prompt,
const text& dflt = "", bool multiline = false);
//Show message box with OK button.
void show_message_ok(wxWindow* parent, const std::string& title, const std::string& text, int icon);
void show_message_ok(wxWindow* parent, const text& title, const text& text, int icon);
//Run function and show errors. Returns true on error.
bool run_show_error(wxWindow* parent, const std::string& title, const std::string& text, std::function<void()> fn);
void show_exception(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
void show_exception_any(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
bool run_show_error(wxWindow* parent, const text& title, const text& text, std::function<void()> fn);
void show_exception(wxWindow* parent, const text& title, const text& text, std::exception& e);
void show_exception_any(wxWindow* parent, const text& title, const text& text, std::exception& e);
//Some important windows (if open).
extern wxwin_messages* msg_window;
extern wxwin_mainwindow* main_window;
extern std::string our_rom_name;
extern text our_rom_name;
extern bool wxwidgets_exiting;
//Some important settings.
extern std::map<std::string, std::string> core_selections;
extern std::map<text, text> core_selections;
#endif

View file

@ -36,14 +36,14 @@ private:
struct settings_tab_factory
{
settings_tab_factory(const std::string& tabname, std::function<settings_tab*(wxWindow* parent,
settings_tab_factory(const text& tabname, std::function<settings_tab*(wxWindow* parent,
emulator_instance& inst)> create_fn);
~settings_tab_factory();
settings_tab* create(wxWindow* parent, emulator_instance& inst) { return _create_fn(parent, inst); }
std::string get_name() { return _tabname; }
text get_name() { return _tabname; }
static std::list<settings_tab_factory*> factories();
private:
std::string _tabname;
text _tabname;
std::function<settings_tab*(wxWindow* parent, emulator_instance& inst)> _create_fn;
};
@ -58,7 +58,7 @@ private:
};
void display_settings_dialog(wxWindow* parent, emulator_instance& inst, settings_tab_factory* singletab = NULL);
void settings_activate_keygrab(emulator_instance& inst, std::function<void(std::string key)> callback);
void settings_activate_keygrab(emulator_instance& inst, std::function<void(text key)> callback);
void settings_deactivate_keygrab(emulator_instance& inst);
#endif

Some files were not shown because too many files have changed in this diff Show more