Types.h 2.12 KB
Newer Older
/jdi/'s avatar
basics  
/jdi/ committed
1
2
3
4
5
6
7
8
9
10
/*
 * Types.h
 *
 *  Created on: 11.09.2015
 *      Author: jdi
 */

#ifndef TYPES_H_
#define TYPES_H_

/jdi/'s avatar
/jdi/ committed
11
12
13
14
#include <initializer_list>
#include <algorithm>
#include <iostream>
#include <iomanip>
/jdi/'s avatar
basics  
/jdi/ committed
15
#include <vector>
/jdi/'s avatar
/jdi/ committed
16
#include <array>
/jdi/'s avatar
/jdi/ committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Types/bytes.h"

class macAddr: public std::array<byte, 6> {
public:
	friend std::ostream& operator<<(std::ostream& out, const macAddr& arr) {
		out << std::hex << std::setw(2) << std::setfill('0')
				<< (unsigned) arr[0];
		for (unsigned i = 1; i < 6; i++) {
			out << ":" << std::setw(2) << std::setfill('0')
					<< (unsigned) arr[i];
		}
		return out;
	}

	macAddr() {
		*this= {0,0,0,0,0,0};
	}

	macAddr(std::initializer_list<byte> s) {
		int i = 0;
        for (byte b : s) {
        	if(i<6) (*this)[i++]=b;
        	else break;
        }
	}
/jdi/'s avatar
/jdi/ committed
42
43
44
45
46
47
48
49

	macAddr(bytes bts) {
		int i = 0;
        for (byte b : bts) {
        	if(i<6) (*this)[i++]=b;
        	else break;
        }
	}
/jdi/'s avatar
/jdi/ committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
};

class ipAddr: public std::array<byte, 4> {
public:

	ipAddr() {
		*this= {0,0,0,0,0,0};
	}

	ipAddr(std::initializer_list<byte> s) {
		int i = 0;
        for (byte  b : s) {
        	if(i<4) (*this)[i++]=b;
        	else break;
        }
	}

/jdi/'s avatar
/jdi/ committed
67
68
69
70
71
72
73
74
	ipAddr(bytes bts) {
		int i = 0;
        for (byte b : bts) {
        	if(i<4) (*this)[i++]=b;
        	else break;
        }
	}

/jdi/'s avatar
/jdi/ committed
75
76
77
78
79
80
81
82
	friend std::ostream& operator<<(std::ostream& out, ipAddr& arr) {
		out << std::dec << (unsigned) arr[0];
		for (unsigned i = 1; i < 4; i++) {
			out << "." << (unsigned) arr[i];
		}
		return out;
	}
};
/jdi/'s avatar
basics  
/jdi/ committed
83

/jdi/'s avatar
/jdi/ committed
84
85
86
87
88
89
90
template<typename T>
std::vector<T> operator+(const std::vector<T> &A, const std::vector<T> &B) {
	std::vector<T> AB;
	AB.reserve(A.size() + B.size());                // preallocate memory
	AB.insert(AB.end(), A.begin(), A.end());        // add A;
	AB.insert(AB.end(), B.begin(), B.end());        // add B;
	return AB;
/jdi/'s avatar
basics  
/jdi/ committed
91
92
}

/jdi/'s avatar
/jdi/ committed
93
94
95
96
97
template<typename T>
std::vector<T> &operator+=(std::vector<T> &A, const std::vector<T> &B) {
	A.reserve(A.size() + B.size());
	A.insert(A.end(), B.begin(), B.end());
	return A;
/jdi/'s avatar
basics  
/jdi/ committed
98
99
}

/jdi/'s avatar
/jdi/ committed
100
101
102
103
104
struct Options {
	unsigned flags = 0x00;
	std::string user;
	std::string password;
	std::string interface;
/jdi/'s avatar
/jdi/ committed
105
106
	std::string file;
	long timeout;
/jdi/'s avatar
/jdi/ committed
107
};
/jdi/'s avatar
basics  
/jdi/ committed
108
109

#endif /* TYPES_H_ */