reformat
This commit is contained in:
parent
f15abc71be
commit
1f3730ac87
26 changed files with 880 additions and 844 deletions
194
src/Types.h
194
src/Types.h
|
|
@ -20,117 +20,117 @@
|
|||
#include "table.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];
|
||||
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;
|
||||
}
|
||||
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;
|
||||
macAddr() {
|
||||
*this= {0,0,0,0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
macAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
macAddr(std::initializer_list<byte> s) {
|
||||
int i = 0;
|
||||
for (byte b : s) {
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int hash() {
|
||||
int ret=0;
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
ret = (ret*33) ^ (*this)[i];
|
||||
macAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
if(i<6) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool operator==(const macAddr &A) {
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
if(A[i]!=(*this)[i])return false;
|
||||
int hash() {
|
||||
int ret=0;
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
ret = (ret*33) ^ (*this)[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const macAddr &A) {
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
if(A[i]!=(*this)[i])return true;
|
||||
bool operator==(const macAddr &A) {
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
if(A[i]!=(*this)[i])return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
class mac_addr : public std::array<unsigned char, 6> {
|
||||
public:
|
||||
typedef std::array<unsigned char, 6> super;
|
||||
bool operator!=(const macAddr &A) {
|
||||
for (unsigned i = 0; i < 6; i++) {
|
||||
if(A[i]!=(*this)[i])return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
using super::super;
|
||||
/*
|
||||
class mac_addr : public std::array<unsigned char, 6> {
|
||||
public:
|
||||
typedef std::array<unsigned char, 6> super;
|
||||
|
||||
mac_addr{00, 00, 00, 000};
|
||||
};
|
||||
*/
|
||||
using super::super;
|
||||
|
||||
mac_addr{00, 00, 00, 000};
|
||||
};
|
||||
*/
|
||||
|
||||
class ipAddr: public std::array<byte, 4> {
|
||||
public:
|
||||
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;
|
||||
ipAddr() {
|
||||
*this= {0,0,0,0,0,0};
|
||||
}
|
||||
}
|
||||
|
||||
ipAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
ipAddr(bytes bts) {
|
||||
int i = 0;
|
||||
for (byte b : bts) {
|
||||
if(i<4) (*this)[i++]=b;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
namespace smrtlink {
|
||||
|
||||
constexpr unsigned int caseArg(const char* str, int h = 0) {
|
||||
return !str[h] ? 5381 : (caseArg(str, h + 1) * 33) ^ str[h];
|
||||
}
|
||||
constexpr unsigned int caseArg(const char* str, int h = 0) {
|
||||
return !str[h] ? 5381 : (caseArg(str, h + 1) * 33) ^ str[h];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -142,24 +142,24 @@ std::vector<T> &operator+=(std::vector<T> &A, const std::vector<T> &B) {
|
|||
}
|
||||
|
||||
struct Options {
|
||||
struct {
|
||||
bool HEX;
|
||||
bool JSON;
|
||||
bool PLAIN;
|
||||
bool REVERSE;
|
||||
struct {
|
||||
bool HEX;
|
||||
bool JSON;
|
||||
bool PLAIN;
|
||||
bool REVERSE;
|
||||
|
||||
bool HEADER;
|
||||
bool PERMANENT;
|
||||
bool WAIT;
|
||||
bool INTERACTIVE;
|
||||
} flags;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string interface;
|
||||
std::string file;
|
||||
int debug_level = 0;
|
||||
int verbosity = 0;
|
||||
long timeout = 250U;
|
||||
bool HEADER;
|
||||
bool PERMANENT;
|
||||
bool WAIT;
|
||||
bool INTERACTIVE;
|
||||
} flags;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string interface;
|
||||
std::string file;
|
||||
int debug_level = 0;
|
||||
int verbosity = 0;
|
||||
long timeout = 250U;
|
||||
};
|
||||
|
||||
#endif /* TYPES_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue