Compare commits
No commits in common. "d9ee8336bd18795f344a226f956ac58f0db1fc23" and "d7341373d4cecb7c8a3b78175ccc887fe73c8718" have entirely different histories.
d9ee8336bd
...
d7341373d4
|
@ -11,12 +11,48 @@ class Config
|
|||
private:
|
||||
static Config config;
|
||||
string path;
|
||||
Partition[string] partitions;
|
||||
PP[string] properties;
|
||||
bool readed = false;
|
||||
const string pattern = "^( |\\t)*(((\\w(\\w|-)+)(( |\\t)*(=>|=){1}"
|
||||
~ "( |\\t)*)(?!\\/(\\/|\\*))(([^ >\"'=\\n\\t#;].*?)|(\"(.+)\")"
|
||||
~ "|('(.+)')){1})|(\\[(\\w(\\w|-)+)\\])|(\\[()\\]))( |\\t)*"
|
||||
~ "(( |\\t)(#|;|\\/\\/|\\/\\*).*)?$";
|
||||
|
||||
/**
|
||||
* Parameter and its value with the ability to convert to the desired data type
|
||||
*/
|
||||
struct PP
|
||||
{
|
||||
private string property;
|
||||
private string value;
|
||||
|
||||
/**
|
||||
* Checking for the presence of a parameter
|
||||
* Returns: true if the parameter is missing, otherwise false
|
||||
*/
|
||||
@property bool empty()
|
||||
{
|
||||
return this.property.length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the value
|
||||
* Returns: default string value
|
||||
*/
|
||||
@property string toString() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
alias toString this;
|
||||
|
||||
auto opCast(T)() const
|
||||
{
|
||||
try {
|
||||
return this.value.to!T;
|
||||
} catch (Exception e) {
|
||||
Log.msg.error("Cannot convert type");
|
||||
Log.msg.warning(e);
|
||||
return T.init;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reading the configuration file
|
||||
|
@ -33,7 +69,9 @@ private:
|
|||
return;
|
||||
}
|
||||
|
||||
auto regular = regex(this.pattern, "m");
|
||||
string pattern = "^ *(\\w+)(( +=> +)|( += +))(?!\\/\\/)(([^ >\"'\\n#;].*?)|"
|
||||
~ "(\"(.+?)\")|('(.+?)')){1} *( #.*?)?( ;.*?)?( \\/\\/.*)?$";
|
||||
auto regular = regex(pattern, "m");
|
||||
|
||||
while (!configuration.eof())
|
||||
{
|
||||
|
@ -94,88 +132,26 @@ public:
|
|||
readConfig();
|
||||
}
|
||||
|
||||
Partition part(string partishion = "")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter and its value with the ability to convert to the desired data type
|
||||
*/
|
||||
struct Parameter
|
||||
{
|
||||
private string property;
|
||||
private string value;
|
||||
|
||||
/**
|
||||
* Checking for the presence of a parameter
|
||||
* Returns: true if the parameter is missing, otherwise false
|
||||
*/
|
||||
@property bool empty()
|
||||
{
|
||||
return this.property.length == 0 || this.value.length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the value
|
||||
* Returns: default string value
|
||||
*/
|
||||
@property string toString() const
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
alias toString this;
|
||||
|
||||
auto opCast(T)() const
|
||||
{
|
||||
try {
|
||||
return this.value.to!T;
|
||||
} catch (Exception e) {
|
||||
Log.msg.error("Cannot convert type");
|
||||
Log.msg.warning(e);
|
||||
return T.init;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Partition
|
||||
{
|
||||
private string name = "[]";
|
||||
private Parameter[string] parameters;
|
||||
|
||||
/**
|
||||
* Checking for the presence of a partition
|
||||
* Returns: true if the parameter is missing, otherwise false
|
||||
*/
|
||||
@property bool empty()
|
||||
{
|
||||
return this.parameters.length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parameter value
|
||||
* Params:
|
||||
* key = parameter from the configuration file
|
||||
* Returns: the value of the parameter in the PP structure view
|
||||
*/
|
||||
Parameter key(string key)
|
||||
PP key(string key)
|
||||
{
|
||||
return key in this.parameters ? this.parameters[key] : Parameter();
|
||||
if (this.readed)
|
||||
return key in this.properties ? this.properties[key] : PP();
|
||||
Log.msg.warning("The configuration file was not read!");
|
||||
return PP();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all keys and their values
|
||||
* Returns: collection of properties structures PP
|
||||
*/
|
||||
Parameter[string] keys()
|
||||
PP[string] keys()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
bool add(Parameter parameter)
|
||||
{
|
||||
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue