Fixed all of the invalid reads/uninitialised value errors in aesalon.
[aesalon.git] / monitor / src / Types.cpp
blob0a650f57a537c4416082f02804176f570f5420a8
1 #include <iostream>
2 #include "Types.h"
4 Block::Block(Byte *data, std::size_t data_size) {
5 this->data.reserve(data_size);
7 for(std::size_t x = 0; x < data_size; x ++) {
8 this->data.push_back(data[x]);
12 void Block::remove(std::size_t from, std::size_t to) {
13 if(from > get_size() || to > get_size() || from >= to) return;
14 data.erase(data.begin()+from, data.begin()+to);
17 Block *Block::subset(std::size_t from, std::size_t to) const {
18 if(from > get_size() || to > get_size() || from >= to) return NULL;
19 /* NOTE: this is rather inefficient, since the Block constuctor is copying this data again . . . */
20 std::vector<Byte> temp_data(data.begin() + from, data.begin() + to);
21 return new Block(&temp_data[0], temp_data.size());
24 void Block::read(void *data, std::size_t size) {
25 if(size > get_size()) return;
26 if(data == NULL) return;
27 for(std::size_t x = 0; x < size; x ++) {
28 *((Byte *)data + x) = *get_data(x);
30 remove(0, size);
33 void Block::hexdump() {
34 std::cout << std::hex;
35 std::size_t x = 0;
36 for(x = 0; x < get_size(); x ++) {
37 std::cout << (int)*get_data(x) << " ";
38 if((x % 40) == 39) std::cout << std::endl;
40 std::cout << std::dec << std::endl;
43 void Block::push_word(Word data) {
44 std::size_t offset = get_size();
45 /* Reserve space for one 64-bit integer . . . */
46 resize(get_size()+8);
47 get_data(offset+7)[0] = (data >> 56) & 0xff;
48 get_data(offset+6)[0] = (data >> 48) & 0xff;
49 get_data(offset+5)[0] = (data >> 40) & 0xff;
50 get_data(offset+4)[0] = (data >> 32) & 0xff;
51 get_data(offset+3)[0] = (data >> 24) & 0xff;
52 get_data(offset+2)[0] = (data >> 16) & 0xff;
53 get_data(offset+1)[0] = (data >> 8) & 0xff;
54 get_data(offset+0)[0] = (data >> 0) & 0xff;