Port the generic control stuff from wxwidgets work
[lsnes.git] / generic / rrdata.hpp
blobc1bc886277b1192847fb34382273612d91902fc4
1 #ifndef _rrdata__hpp__included__
2 #define _rrdata__hpp__included__
4 #define RRDATA_BYTES 32
5 #include <cstdint>
6 #include <stdexcept>
7 #include <vector>
9 /**
10 * Set of load IDs
12 class rrdata
14 public:
15 /**
16 * One load ID.
18 struct instance
20 /**
21 * Create new random load ID.
23 * throws std::bad_alloc: Not enough memory
25 instance() throw(std::bad_alloc);
26 /**
27 * Create new load id from bytes.
29 * parameter b: 32 byte array containing the new ID.
31 instance(unsigned char* b) throw();
32 /**
33 * The load ID.
35 unsigned char bytes[RRDATA_BYTES];
36 /**
37 * Is this ID before another one?
39 * parameter i: Another ID.
40 * returns: True if this ID is before another one, false otherwise.
42 bool operator<(const struct instance& i) const throw();
43 /**
44 * Is this ID equal to another one?
46 * parameter i: Another ID.
47 * returns: True if this ID is equal to another one, false otherwise.
49 bool operator==(const struct instance& i) const throw();
50 /**
51 * Increment this ID.
53 * returns: Copy of the ID before the increment.
55 const struct instance operator++(int) throw();
56 /**
57 * Increment this ID.
59 * returns: Reference to this.
61 struct instance& operator++() throw();
63 /**
64 * Read the saved set of load IDs for specified project and switch to that project.
66 * parameter project: The name of project.
67 * throws std::bad_alloc: Not enough memory
69 static void read_base(const std::string& project) throw(std::bad_alloc);
70 /**
71 * Switch to no project, closing the load IDs.
73 static void close() throw();
74 /**
75 * Add new specified instance to current project.
77 * Not allowed if there is no project open.
79 * parameter i: The load ID to add.
81 static void add(const struct instance& i) throw(std::bad_alloc);
82 /**
83 * Generate new load ID and add it to the current proejct.
85 * Not allowed if there is no project open.
87 * throws std::bad_alloc: Not enough memory.
89 static void add_internal() throw(std::bad_alloc);
90 /**
91 * Write compressed representation of current load ID set to stream.
93 * parameter strm: The stream to write to.
94 * returns: Rerecord count.
95 * throws std::bad_alloc: Not enough memory.
97 static uint64_t write(std::vector<char>& strm) throw(std::bad_alloc);
98 /**
99 * Load compressed representation of load ID set from stream and union it with current set to form new current
100 * set.
102 * parameter strm: The stream to read from.
103 * returns: Rerecord count.
104 * throws std::bad_alloc: Not enough memory.
106 static uint64_t read(std::vector<char>& strm, bool dummy = false) throw(std::bad_alloc);
108 * Load compressed representation of load ID set from stream, but don't do anything to it.
110 * parameter strm: The stream to read from.
111 * returns: Rerecord count.
112 * throws std::bad_alloc: Not enough memory.
114 static uint64_t count(std::vector<char>& strm) throw(std::bad_alloc);
116 * Internal pointer used by add_internal.
118 static struct instance* internal;
122 * Print load ID. Mainly useful for deubugging.
124 * parameter os: Stream to print to.
125 * parameter i: load ID to print.
127 std::ostream& operator<<(std::ostream& os, const struct rrdata::instance& i);
129 #endif