get&set
This commit is contained in:
parent
d3b89e3b11
commit
8200103514
14 changed files with 415 additions and 356 deletions
140
src/Types.h
140
src/Types.h
|
|
@ -21,105 +21,113 @@
|
|||
|
||||
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;
|
||||
}
|
||||
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() {
|
||||
*this= {0,0,0,0,0,0};
|
||||
}
|
||||
|
||||
macAddr(std::initializer_list<byte> s) {
|
||||
int i = 0;
|
||||
macAddr(std::initializer_list<byte> s) {
|
||||
int i = 0;
|
||||
for (byte b : s) {
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macAddr(bytes bts) {
|
||||
int i = 0;
|
||||
macAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
class mac_addr : public std::array<unsigned char, 6> {
|
||||
public:
|
||||
typedef std::array<unsigned char, 6> super;
|
||||
class mac_addr : public std::array<unsigned char, 6> {
|
||||
public:
|
||||
typedef std::array<unsigned char, 6> super;
|
||||
|
||||
using super::super;
|
||||
|
||||
mac_addr{00, 00, 00, 000};
|
||||
};
|
||||
*/
|
||||
using super::super;
|
||||
|
||||
mac_addr{00, 00, 00, 000};
|
||||
};
|
||||
*/
|
||||
|
||||
class ipAddr: public std::array<byte, 4> {
|
||||
public:
|
||||
|
||||
ipAddr() {
|
||||
*this= {0,0,0,0,0,0};
|
||||
}
|
||||
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;
|
||||
ipAddr(std::initializer_list<byte> s) {
|
||||
int i = 0;
|
||||
for (byte b : s) {
|
||||
if(i<4) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ipAddr(bytes bts) {
|
||||
int i = 0;
|
||||
ipAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
if(i<4) (*this)[i++]=b;
|
||||
else break;
|
||||
if(i<4) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
A.reserve(A.size() + B.size());
|
||||
A.insert(A.end(), B.begin(), B.end());
|
||||
return A;
|
||||
}
|
||||
|
||||
struct Options {
|
||||
unsigned flags = 0x00;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string interface;
|
||||
std::string file;
|
||||
int debug_level=0;
|
||||
long timeout = 180U;
|
||||
struct {
|
||||
bool HEX;
|
||||
bool JSON;
|
||||
bool PLAIN;
|
||||
bool REVERSE;
|
||||
bool HEADER;
|
||||
bool PERMANENT;
|
||||
bool WAIT;
|
||||
} flags;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string interface;
|
||||
std::string file;
|
||||
int debug_level = 0;
|
||||
int verbosity = 0;
|
||||
long timeout = 180U;
|
||||
};
|
||||
|
||||
#endif /* TYPES_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue