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