|
|
f07ad6 |
#ifndef ADDRESS_H
|
|
|
f07ad6 |
#define ADDRESS_H
|
|
|
f07ad6 |
|
|
|
f07ad6 |
|
|
|
541903 |
#include <cstring></cstring>
|
|
|
541903 |
|
|
|
f07ad6 |
#include <string></string>
|
|
|
f07ad6 |
|
|
|
f07ad6 |
|
|
|
541903 |
enum : ErrorCode {
|
|
|
541903 |
ERR_ADDRESS_COMMON = ERR_ADDRESS,
|
|
|
541903 |
ERR_ADDRESS_INCORRECT,
|
|
|
541903 |
ERR_ADDRESS_NOT_FOUND,
|
|
|
541903 |
};
|
|
|
541903 |
|
|
|
541903 |
|
|
|
f07ad6 |
class Address {
|
|
|
f07ad6 |
public:
|
|
|
f07ad6 |
enum Type {
|
|
|
f07ad6 |
NONE,
|
|
|
f07ad6 |
COMMON_STRING,
|
|
|
f07ad6 |
SOCKET,
|
|
|
f07ad6 |
};
|
|
|
f07ad6 |
|
|
|
f07ad6 |
Type type;
|
|
|
f07ad6 |
std::string text;
|
|
|
541903 |
size_t size;
|
|
|
f07ad6 |
char data[512];
|
|
|
f07ad6 |
|
|
|
541903 |
inline Address(): type(NONE), size(), data() { }
|
|
|
541903 |
|
|
|
541903 |
inline void clear()
|
|
|
541903 |
{ type = NONE; text.clear(); size = 0; memset(data, 0, sizeof(data)); }
|
|
|
541903 |
|
|
|
541903 |
inline void set(Type type, const char *text = nullptr) {
|
|
|
541903 |
this->type = type;
|
|
|
9bbba5 |
if (text) this->text = text; else this->text.clear();
|
|
|
541903 |
size = 0;
|
|
|
541903 |
memset(data, 0, sizeof(data));
|
|
|
541903 |
}
|
|
|
541903 |
|
|
|
541903 |
template<typename t=""></typename>
|
|
|
541903 |
inline void set(Type type, const char *text, const T& data)
|
|
|
541903 |
{ set(type, text); as<t>() = data; size = sizeof(T); }</t>
|
|
|
f07ad6 |
|
|
|
f07ad6 |
template<typename t=""></typename>
|
|
|
f07ad6 |
inline const T& as() const
|
|
|
f07ad6 |
{ assert(sizeof(T) < sizeof(data)); return *reinterpret_cast<const t*="">(data); }</const>
|
|
|
f07ad6 |
|
|
|
f07ad6 |
template<typename t=""></typename>
|
|
|
541903 |
inline T& as()
|
|
|
f07ad6 |
{ assert(sizeof(T) < sizeof(data)); return *reinterpret_cast<t*>(data); }</t*>
|
|
|
f07ad6 |
};
|
|
|
f07ad6 |
|
|
|
f07ad6 |
|
|
|
f07ad6 |
#endif
|