Make joysticks actually work
[lsnes.git] / rrdata.hpp
blobe4d31301b3a983d927ccc652ec4a45495414b8a9
1 #ifndef _rrdata__hpp__included__
2 #define _rrdata__hpp__included__
4 #define RRDATA_BYTES 32
5 #include <cstdint>
6 #include <stdexcept>
8 /**
9 * Set of load IDs
11 class rrdata
13 public:
14 /**
15 * One load ID.
17 struct instance
19 /**
20 * Create new random load ID.
22 * throws std::bad_alloc: Not enough memory
24 instance() throw(std::bad_alloc);
25 /**
26 * Create new load id from bytes.
28 * parameter b: 32 byte array containing the new ID.
30 instance(unsigned char* b) throw();
31 /**
32 * The load ID.
34 unsigned char bytes[RRDATA_BYTES];
35 /**
36 * Is this ID before another one?
38 * parameter i: Another ID.
39 * returns: True if this ID is before another one, false otherwise.
41 bool operator<(const struct instance& i) const throw();
42 /**
43 * Is this ID equal to another one?
45 * parameter i: Another ID.
46 * returns: True if this ID is equal to another one, false otherwise.
48 bool operator==(const struct instance& i) const throw();
49 /**
50 * Increment this ID.
52 * returns: Copy of the ID before the increment.
54 const struct instance operator++(int) throw();
55 /**
56 * Increment this ID.
58 * returns: Reference to this.
60 struct instance& operator++() throw();
62 /**
63 * Read the saved set of load IDs for specified project and switch to that project.
65 * parameter project: The name of project.
66 * throws std::bad_alloc: Not enough memory
68 static void read_base(const std::string& project) throw(std::bad_alloc);
69 /**
70 * Switch to no project, closing the load IDs.
72 static void close() throw();
73 /**
74 * Add new specified instance to current project.
76 * Not allowed if there is no project open.
78 * parameter i: The load ID to add.
80 static void add(const struct instance& i) throw(std::bad_alloc);
81 /**
82 * Generate new load ID and add it to the current proejct.
84 * Not allowed if there is no project open.
86 * throws std::bad_alloc: Not enough memory.
88 static void add_internal() throw(std::bad_alloc);
89 /**
90 * Write compressed representation of current load ID set to stream.
92 * parameter strm: The stream to write to.
93 * throws std::bad_alloc: Not enough memory.
95 static uint64_t write(std::ostream& strm) throw(std::bad_alloc);
96 /**
97 * Load compressed representation of load ID set from stream and union it with current set to form new current
98 * set.
100 * parameter strm: The stream to read from.
101 * throws std::bad_alloc: Not enough memory.
103 static uint64_t read(std::istream& strm) throw(std::bad_alloc);
105 * Internal pointer used by add_internal.
107 static struct instance* internal;
111 * Print load ID. Mainly useful for deubugging.
113 * parameter os: Stream to print to.
114 * parameter i: load ID to print.
116 std::ostream& operator<<(std::ostream& os, const struct rrdata::instance& i);
118 #endif