mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 13:43:19 +02:00
ConnectionInfo
- Updated `string getDB(string)` to `T getDB(T)(string)` which will now attempt conversion to type `T`, on failure to do so it will return `T.init` ConnInfo - Added `setDefaults(ref ConnectionInfo)` which will set defaults in the `db`, namely so far it sets the `MAXNICKLEN` to `9` as per rfc1459 Package (`birchwood.config`) - Now publically imports `setDefaults()`
This commit is contained in:
parent
1015a4ec1c
commit
9ca98ac664
@ -5,6 +5,7 @@ module birchwood.config.conninfo;
|
|||||||
|
|
||||||
import std.socket : SocketException, Address, getAddress;
|
import std.socket : SocketException, Address, getAddress;
|
||||||
import birchwood.client.exceptions;
|
import birchwood.client.exceptions;
|
||||||
|
import std.conv : to, ConvException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the connection details for a server
|
* Represents the connection details for a server
|
||||||
@ -127,11 +128,25 @@ public shared struct ConnectionInfo
|
|||||||
db[key] = value;
|
db[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getDB(string key)
|
public T getDB(T)(string key)
|
||||||
{
|
{
|
||||||
|
import std.stdio;
|
||||||
|
writeln("GETDB: '"~key~"' with len ", key.length);
|
||||||
if(key in db)
|
if(key in db)
|
||||||
{
|
{
|
||||||
return db[key];
|
/* Attempt conversion into T */
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/* Fetch and convert */
|
||||||
|
T value = to!(T)(db[key]);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
/* If conversion to type T fails */
|
||||||
|
catch(ConvException e)
|
||||||
|
{
|
||||||
|
/* Return the initial value for such a paremeter */
|
||||||
|
return T.init;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -206,3 +221,12 @@ public shared struct ConnectionInfo
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDefaults(ref ConnectionInfo connInfo)
|
||||||
|
{
|
||||||
|
/* Set the `MAXNICKLEN` to a default of 9 */
|
||||||
|
connInfo.updateDB("MAXNICKLEN", "9");
|
||||||
|
assert(connInfo.getDB!(ulong)("MAXNICKLEN") == 9);
|
||||||
|
import std.stdio;
|
||||||
|
writeln("MAXKAK: ", connInfo.getDB!(ulong)("MAXNICKLEN"));
|
||||||
|
}
|
@ -6,4 +6,4 @@ module birchwood.config;
|
|||||||
/**
|
/**
|
||||||
* Connection information
|
* Connection information
|
||||||
*/
|
*/
|
||||||
public import birchwood.config.conninfo : ConnectionInfo;
|
public import birchwood.config.conninfo : ConnectionInfo, setDefaults;
|
Loading…
Reference in New Issue
Block a user