1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <string>
#include <algorithm>
#include "./Settings_Exceptions.hpp"
class Settings
{
private:
std::string server;
std::string channel;
unsigned short port;
std::string nick;
Settings_Exception *SE;
//friend class Config;
public:
Settings() { SE = new Settings_Exception; }
Settings (Settings &a) : server(a.server), channel(a.channel),
port(a.port), nick(a.nick)
{
try
{
SE = new Settings_Exception(a.server,a.channel,a.port);
}
catch(Settings_Exception &S)
{
std::cout<<"Oops....found an error!!!\n";
std::cout<<S.what()<<std::endl;
}
}
Settings(std::string &Serv,std::string &Chan,unsigned short &Port,
std::string &Nick): server(Serv),channel(Chan),port(Port),nick(Nick)
{
try
{
SE = new Settings_Exception(Serv,Chan,Port);
}
catch(Settings_Exception &S)
{
std::cout<<"Oops....found an error!!!\n";
std::cout<<S.what()<<std::endl;
}
}
~Settings() { delete SE; }
std::string rServer() { return this->server; }
std::string rChannel() { return this->channel; }
unsigned short rPort() { return this->port; }
std::string rNick() { return this->nick; }
void gServer(std::string &Serv)
{
server = Serv;
try { SE->gServ(server); }
catch(Settings_Exception &S)
{
std::cout<<"Oops....found an error!!!\n";
std::cout<<S.what()<<std::endl;
}
}
void gChannel(std::string &Chan)
{ channel = Chan; SE->gChan(channel); }
void gPort(unsigned short &Port)
{
port = Port;
try { SE->gPort(port); }
catch(Settings_Exception &S)
{
std::cout<<"Oops....found an error!!!\n";
std::cout<<S.what()<<std::endl;
}
}
void gNick(std::string &Nick) { nick = Nick; }
//Get the data
inline void getData(std::string &serv,std::string &chan,
unsigned short &p,std::string &n)
{
server = serv; channel = chan; port = p; nick = n;
try
{
SE->gServ(server); SE->gChan(channel); SE->gPort(port);
}
catch(Settings_Exception &S)
{
std::cout<<"Oops....found an error!!!\n";
std::cout<<S.what()<<std::endl;
}
}
inline void putData(std::string &serv,std::string &chan,
unsigned short &p,std::string &n)
{
serv = server; chan = channel; p = port; n = nick;
}
//Compare two strings
inline bool Compare_To(std::string param1,std::string param2)
{
std::transform(param1.begin(),param1.end(),param1.begin(),
std::ptr_fun<int,int>(std::toupper));
std::transform(param2.begin(),param2.end(),param2.begin(),
std::ptr_fun<int,int>(std::toupper));
if( param1.compare(param2) == 0 )
return true;
else if( param1.compare(param2) != 0 )
return false;
}
//Compare two unsigned shorts
inline bool Compare_To(unsigned short param1,unsigned short param2)
{
if( param1 == param2 )
return true;
else if ( param1 != param2 )
return false;
}
//Clear the contents of the variables
inline void clear()
{
server.clear();
channel.clear();
nick.clear();
port = 0;
}
};
| |