Commit aa8af556 authored by jedi's avatar jedi
Browse files

table.h added

parent 73df3e05
......@@ -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)/*
......@@ -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;
}
......
......@@ -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;
......
/*
* 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];
}
/*
* 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_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment