Allow specifying ROM type in file load dialog
[lsnes.git] / include / core / misc.hpp
blob1c1a9e35f0ed8ee793496d67fe663357d6de16ba
1 #ifndef _misc__hpp__included__
2 #define _misc__hpp__included__
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 #include "library/string.hpp"
9 /**
10 * \brief Get random hexes
12 * Get string of random hex characters of specified length.
14 * \param length The number of hex characters to return.
15 * \return The random hexadecimal string.
16 * \throws std::bad_alloc Not enough memory.
18 std::string get_random_hexstring(size_t length) throw(std::bad_alloc);
20 /**
21 * \brief Set random seed
23 * This function sets the random seed to use.
25 * \param seed The value to use as seed.
26 * \throw std::bad_alloc Not enough memory.
28 void set_random_seed(const std::string& seed) throw(std::bad_alloc);
30 /**
31 * \brief Set random seed to (hopefully) unique value
33 * This function sets the random seed to value that should only be used once. Note, the value is not necressarily
34 * crypto-secure, even if it is unique.
36 * \throw std::bad_alloc Not enough memory.
38 void set_random_seed() throw(std::bad_alloc);
40 /**
41 * \brief Load a ROM.
43 * Given commandline arguments, load a ROM.
45 * \param cmdline The command line.
46 * \return The loaded ROM set.
47 * \throws std::bad_alloc Not enough memory.
48 * \throws std::runtime_error Can't load the ROMset.
50 struct loaded_rom load_rom_from_commandline(std::vector<std::string> cmdline) throw(std::bad_alloc,
51 std::runtime_error);
53 /**
54 * \brief Dump listing of regions to graphics system messages.
56 * \throws std::bad_alloc Not enough memory.
58 void dump_region_map() throw(std::bad_alloc);
60 /**
61 * \brief Fatal error.
63 * Fatal error.
65 void fatal_error() throw();
67 /**
68 * \brief Get path to config directory.
70 * \return The config directory path.
71 * \throw std::bad_alloc Not enough memory.
73 std::string get_config_path() throw(std::bad_alloc);
75 /**
76 * \brief Panic on OOM.
78 void OOM_panic();
80 /**
81 * messages -> window::out().
83 class messages_relay_class
85 public:
86 operator std::ostream&() { return getstream(); }
87 static std::ostream& getstream();
89 template<typename T> inline std::ostream& operator<<(messages_relay_class& x, T value)
91 return messages_relay_class::getstream() << value;
93 inline std::ostream& operator<<(messages_relay_class& x, std::ostream& (*fn)(std::ostream& o))
95 return fn(messages_relay_class::getstream());
97 extern messages_relay_class messages;
99 uint32_t gcd(uint32_t a, uint32_t b) throw();
102 * Return hexadecimal representation of address
104 std::string format_address(void* addr);
107 * Get state of running global ctors flag.
109 bool in_global_ctors();
111 * Clear the global ctors flag.
113 void reached_main();
116 * Clean up filename from dangerous chars
118 std::string safe_filename(const std::string& str);
121 * Mangle some characters ()|/
123 std::string mangle_name(const std::string& orig);
126 #endif