Pretty much converted the ASM namespace to use the StorageManager system.
[aesalon.git] / monitor / src / Types.h
blob59742674b1b467cf9cb6316cb20188e39c0b35d5
1 #ifndef AESALON_MONITOR_TYPES_H
2 #define AESALON_MONITOR_TYPES_H
4 #include <sys/types.h>
6 #include <vector>
8 /** Byte typedef; simply an 8-bit integer. */
9 typedef u_int8_t Byte;
10 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
11 /** Unsigned word, 32-bits on 32-bit machines, 64 bits on 64-bit machines. */
12 typedef u_int64_t Word;
13 /** Signed-word, signed version of @a Word. */
14 typedef int64_t SWord;
15 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
16 /** Unsigned word, 32-bits on 32-bit machines, 64 bits on 64-bit machines. */
17 typedef u_int32_t Word;
18 /** Signed-word, signed version of @a Word. */
19 typedef int32_t SWord;
20 #endif
22 /** A block of data, presumably from an executable file. Custom version of std::vector&lt;Byte&gt;.*/
23 class Block {
24 private:
25 std::vector<Byte> data;
26 public:
27 /** Generic constructor, sets data and data_size to NULL and zero, respectively. */
28 Block() : data() {}
29 /** Constructor that takes a pointer and a std::size_t, for data and data_size. */
30 Block(Byte *data, std::size_t data_size);
32 /** Returns the data that this block points to, with an optional offset.
33 @param offset How many bytes to ignore when determining the address.
34 @return The block data, @a offset bytes in.
36 Byte *get_data() { return &data[0]; }
38 /** Retrieves the size of the current data.
39 @return The current size of the referenced data.
41 std::size_t get_size() const { return data.size(); }
42 /** Removes a swath of Bytes, from offset @a from to offset @a to. This invalidates all
43 pointers to the current Block.
44 @param from Where to begin deleting.
45 @param to Where to end deleteing.
47 void remove(std::size_t from, std::size_t to);
49 /** Creates a copy of a subset of the block of represented data.
50 @param from Where to begin copying.
51 @param to Where to end copying.
52 @return The subset of the block.
54 Block *subset(std::size_t from, std::size_t to) const;
56 /** Acts like the POSIX read() function -- reads a specific amount of
57 data into a buffer.
58 @param data The buffer to read into.
59 @param size The amount of data to read.
61 void read(void *data, std::size_t size);
63 void hexdump();
65 void resize(std::size_t new_size) {
66 data.resize(new_size);
69 void push_word(Word data);
75 #endif