Began removal of platform/. The Monitor:: namespace is completely converted.
[aesalon.git] / src / monitor / Types.cpp
blob1695683da1d97b95a8eb8d40cfd2121269f90151
1 #include <iostream>
2 #include "Types.h"
4 namespace Aesalon {
5 namespace Monitor {
7 Block::Block(Byte *data, std::size_t data_size) {
8 this->data.reserve(data_size);
10 for(std::size_t x = 0; x < data_size; x ++) {
11 this->data.push_back(data[x]);
15 void Block::remove(std::size_t from, std::size_t to) {
16 if(from > get_size() || to > get_size() || from >= to) return;
17 data.erase(data.begin()+from, data.begin()+to);
20 Misc::SmartPointer<Block> Block::subset(std::size_t from, std::size_t to) const {
21 if(from > get_size() || to > get_size() || from >= to) return NULL;
22 /* NOTE: this is rather inefficient, since the Block constuctor is copying this data again . . . */
23 std::vector<Byte> temp_data(data.begin() + from, data.begin() + to);
24 return new Block(&temp_data[0], temp_data.size());
27 void Block::read(void *data, std::size_t size) {
28 if(size > get_size()) return;
29 if(data == NULL) return;
30 for(std::size_t x = 0; x < size; x ++) {
31 *((Byte *)data + x) = *get_data(x);
33 remove(0, size);
36 void Block::hexdump() {
37 std::cout << std::hex;
38 std::size_t x = 0;
39 for(x = 0; x < get_size(); x ++) {
40 std::cout << (int)*get_data(x) << " ";
41 if((x % 40) == 39) std::cout << std::endl;
43 std::cout << std::dec << std::endl;
46 } // namespace Monitor
47 } // namespace Aesalon