table.h added

This commit is contained in:
j3d1 2016-01-17 00:46:51 +01:00
parent 73df3e0528
commit aa8af55608
5 changed files with 83 additions and 2 deletions

View file

@ -15,12 +15,14 @@ $(BUILDDIR):
$(TARGET): $(OBJECTS)
$(CC) $^ -o $@ -lboost_filesystem -lboost_system
$(CC) $^ -o $(BUILDDIR)/$@ -lboost_filesystem -lboost_system
$(OBJECTS): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp
$(CC) $(CFLAGS) $< -o $@
install: bin/$(TARGET)
install -m 0755 bin/$(TARGET) $(prefix)/bin
clean:
rm -f $(BUILDDIR)/*o $(TARGET)
rm -f $(BUILDDIR)/*

View file

@ -57,6 +57,7 @@ ipAddr Host::getIp() {
return data;
}
}
/*
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
if (ifa->ifa_addr == NULL)
continue;
@ -66,6 +67,7 @@ ipAddr Host::getIp() {
return data;
}
}
*/
freeifaddrs(ifaddr);
return data;
}

View file

@ -43,6 +43,7 @@ public:
std::string hardware_version;
std::string firmware_version;
macAddr mac { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
int ports;
} device;
struct {
std::string password = DEFAULT_PASS;
@ -52,6 +53,9 @@ public:
ipAddr ip_mask;
ipAddr gateway;
bool dhcp;
bool loop_prevention;
bool qos_enabled;
bool vlan_enabled;
} settings;
private:
rapidjson::Document json;

38
src/table.cpp Normal file
View file

@ -0,0 +1,38 @@
/*
* lookupTable.h
*
* Created on: 11.10.2015
* Author: jdi
*/
#include <string>
#include "table.h"
table::table(std::initializer_list<set> l) {
int i = 0;
this->data.resize(l.size());
for (set s : l) {
this->data[i] = s;
this->left[s.type] = &this->data[i];
this->right[s.name] = &this->data[i];
i++;
}
}
short table::operator[](std::string s){
return this->right[s]->type;
}
std::string table::operator[](short n){
return this->left[n]->name;
}
bool table::exists(std::string s){
return !(right.find(s) == right.end());
}
bool table::exists(short n){
return !(left.find(n) == left.end());
}
const table::set* table::get(std::string s){
return this->right[s];
}
const table::set* table::get(short n){
return this->left[n];
}

35
src/table.h Normal file
View file

@ -0,0 +1,35 @@
/*
* lookupTable.h
*
* Created on: 11.10.2015
* Author: jdi
*/
#ifndef LOOKUPTABLE_H_
#define LOOKUPTABLE_H_
#include <map>
#include <vector>
class table {
public:
enum F {STRING,HEX,DEC,ACTION,EMPTY};
struct set {
short type;
F format;
std::string name;
};
table(std::initializer_list<set> l);
short operator[](std::string);
std::string operator[](short);
bool exists(std::string);
bool exists(short);
const set* get(std::string);
const set* get(short);
private:
std::vector<set> data;
std::map<short, set*> left;
std::map<std::string, set*> right;
};
#endif /* LOOKUPTABLE_H_ */