Files
VoidNet/include/Utility.hpp
xX-TheDoctor-Xx 9d1c518610 Added conversion from Handshake to NetworkMessage and vice versa
Added a new ConnectionCode - Close
TcpServer: AddToClientsList and AllocateID are now called add_to_clients_list and allocate_id respectively and are now private, removed SendHandshake method - we now use SendMessage method and the HandshakeToNetworkMessage method in the Handshake class
Added a new method to Utility::StringConverter - FromString
Changed NetworkMessage conversions to allow Handshake conversions
NetworkMessage: if subject is 1 then the NetworkMessage is a handshake
I may be missing something but im going to check it
I may be overcomplicating this but i want to make it as simple as possible xD
2016-08-18 15:08:51 +01:00

80 lines
2.5 KiB
C++

#ifndef UTILITY_HPP
#define UTILITY_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
#include <string>
#include <map>
#include <vector>
struct Utility
{
static void Delete(void *pointer);
static void DeleteArray(void *pointer);
struct BitConverter
{
static const std::vector<byte> &FromUint8(uint8 number);
static uint8 ToUint8(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromUint16(uint16 number);
static uint16 ToUint16(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromUint32(uint32 number);
static uint32 ToUint32(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromUint64(uint64 number);
static uint64 ToUint64(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromInt8(int8 number);
static int8 ToInt8(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromInt16(int16 number);
static int16 ToInt16(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromInt32(int32 number);
static int32 ToInt32(const std::vector<byte> &bytes, uint16 start_index = 0);
static const std::vector<byte> &FromInt64(int64 number);
static int64 ToInt64(const std::vector<byte> &bytes, uint16 start_index = 0);
};
struct StringConverter
{
static const std::string &ToString(bool value);
static const std::string &ToString(uint8 value);
static const std::string &ToString(uint16 value);
static const std::string &ToString(uint32 value);
static const std::string &ToString(uint64 value);
static const std::string &ToString(int8 value);
static const std::string &ToString(int16 value);
static const std::string &ToString(int32 value);
static const std::string &ToString(int64 value);
static const std::string &ToString(const std::vector<byte> &bytes);
static const std::vector<byte> &FromString(const std::string &str);
static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0);
static const std::string &Trim(std::string &str, char ch);
static std::vector<std::string> Split(const std::string &str, const std::string &delimiter);
};
struct ConfigReader
{
void ReadConfig(const std::string &file_name);
void ReadNodes();
const std::string &operator[](const std::string &key);
private:
std::map<std::string, std::string> nodes;
std::string file_content;
};
};
#endif