Skip to content
Browse files

Few code fixes.

  • Loading branch information...
1 parent 31f5ccf commit 320e3614169218fd71cc31e4ba2fe83859777405 @meh committed
Showing with 46 additions and 45 deletions.
  1. +11 −11 deimos/libconfig.d
  2. +34 −33 libconfig.d
  3. +1 −1 test.sh
View
22 deimos/libconfig.d
@@ -132,7 +132,7 @@ int config_setting_get_int (const config_setting_t* setting);
long config_setting_get_int64 (const config_setting_t* setting);
double config_setting_get_float (const config_setting_t* setting);
bool config_setting_get_bool (const config_setting_t* setting);
-immutable(char*) config_setting_get_string (const config_setting_t* setting);
+const(char*) config_setting_get_string (const config_setting_t* setting);
bool config_setting_lookup_int (const config_setting_t* setting, const char* name, int* value);
bool config_setting_lookup_int64 (const config_setting_t* setting, const char* name, long* value);
@@ -153,7 +153,7 @@ int config_setting_get_int_elem (const config_setting_t* setting, int idx);
long config_setting_get_int64_elem (const config_setting_t* setting, int idx);
double config_setting_get_float_elem (const config_setting_t* setting, int idx);
bool config_setting_get_bool_elem (const config_setting_t* setting, int idx);
-immutable (char*) config_setting_get_string_elem (const config_setting_t* setting, int idx);
+const (char*) config_setting_get_string_elem (const config_setting_t* setting, int idx);
config_setting_t* config_setting_set_int_elem (config_setting_t* setting, int idx, int value);
config_setting_t* config_setting_set_int64_elem (config_setting_t* setting, int idx, long value);
@@ -161,7 +161,7 @@ config_setting_t* config_setting_set_float_elem (config_setting_t* setting, int
config_setting_t* config_setting_set_bool_elem (config_setting_t* setting, int idx, bool value);
config_setting_t* config_setting_set_string_elem (config_setting_t* setting, int idx, const char* value);
-immutable (char*) config_get_include_dir (const config_t* config)
+const (char*) config_get_include_dir (const config_t* config)
{
return config.include_dir;
}
@@ -201,14 +201,14 @@ bool config_setting_is_scalar (const config_setting_t* setting)
return setting.type == CONFIG_TYPE_BOOL || setting.type == CONFIG_TYPE_STRING || config_setting_is_scalar(setting);
}
-immutable (char*) config_setting_name (const config_setting_t* setting)
+const (char*) config_setting_name (const config_setting_t* setting)
{
return setting.name;
}
config_setting_t* config_setting_parent (const config_setting_t* setting)
{
- return setting.parent;
+ return cast (config_setting_t*) setting.parent;
}
bool config_setting_is_root (const config_setting_t* setting)
@@ -248,7 +248,7 @@ bool config_lookup_string (const config_t* config, const char* path, const char*
config_setting_t* config_root_setting (const config_t* config)
{
- return config.root;
+ return cast (config_setting_t*) config.root;
}
void config_set_default_format (config_t* config, short format)
@@ -266,27 +266,27 @@ void config_set_tab_width (config_t* config, ushort width)
config.tab_width = width & 0x0F;
}
-ubyte config_get_tab_width (const config_t* config)
+ushort config_get_tab_width (const config_t* config)
{
return config.tab_width;
}
-ushort config_setting_source_line (const config_setting_t* setting)
+uint config_setting_source_line (const config_setting_t* setting)
{
return setting.line;
}
-immutable (char*) config_setting_source_file (const config_setting_t* setting)
+const (char*) config_setting_source_file (const config_setting_t* setting)
{
return setting.file;
}
-immutable (char*) config_error_text (const config_t* config)
+const (char*) config_error_text (const config_t* config)
{
return config.error_text;
}
-immutable (char*) config_error_file (const config_t* config)
+const (char*) config_error_file (const config_t* config)
{
return config.error_file;
}
View
67 libconfig.d
@@ -28,33 +28,11 @@ class Config
alias Algebraic!(Type, int, long, double, string, bool) Value;
- Type to(T : Type) (Value value)
- {
- if (value.type == typeid(int)) {
- return Type.Int;
- }
- else if (value.type == typeid(long)) {
- return Type.Long;
- }
- else if (value.type == typeid(double)) {
- return Type.Float;
- }
- else if (value.type == typeid(string)) {
- return Type.String;
- }
- else if (value.type == typeid(bool)) {
- return Type.Bool;
- }
- else {
- return value.get!Type;
- }
- }
-
static class Setting
{
struct Source {
string file;
- ushort line;
+ uint line;
}
this (config_setting_t* value)
@@ -93,7 +71,7 @@ class Config
Setting opIndex (uint index)
{
enforce(isList || isArray, "the Setting has to be either an Array or List");
- enforceEx!RangeError(index < length);
+ enforce(index < length, new RangeError);
return new Setting(config_setting_get_elem(native, index));
}
@@ -123,19 +101,19 @@ class Config
void opIndexAssign (Value value, uint index)
{
enforce(isList || isArray, "the Setting has to be either an Array or List");
- enforceEx!RangeError(index < length);
+ enforce(index < length, new RangeError);
}
void opIndexAssign (Value[] value, uint index)
{
enforce(isList || isArray, "the Setting has to be either an Array or List");
- enforceEx!RangeError(index < length);
+ enforce(index < length, new RangeError);
}
void opIndexAssign (Value[string] value, uint index)
{
enforce(isList || isArray, "the Setting has to be either an Array or List");
- enforceEx!RangeError(index < length);
+ enforce(index < length, new RangeError);
}
void pushBack (Value value)
@@ -198,22 +176,22 @@ class Config
case Type.Group:
case Type.Array:
case Type.List:
- return type;
+ return Value(type);
case Type.Int:
- return config_setting_get_int(native);
+ return Value(config_setting_get_int(native));
case Type.Long:
- return config_setting_get_int64(native);
+ return Value(config_setting_get_int64(native));
case Type.Float:
- return config_setting_get_float(native);
+ return Value(config_setting_get_float(native));
case Type.Bool:
- return config_setting_get_bool(native);
+ return Value(config_setting_get_bool(native));
case Type.String:
- return config_setting_get_string(native).to!string;
+ return Value(config_setting_get_string(native).to!string);
}
}
@@ -395,3 +373,26 @@ class Config
private:
config_t _config;
}
+
+private:
+ Config.Type to(T : Config.Type) (Config.Value value)
+ {
+ if (value.type == typeid(int)) {
+ return Config.Type.Int;
+ }
+ else if (value.type == typeid(long)) {
+ return Config.Type.Long;
+ }
+ else if (value.type == typeid(double)) {
+ return Config.Type.Float;
+ }
+ else if (value.type == typeid(string)) {
+ return Config.Type.String;
+ }
+ else if (value.type == typeid(bool)) {
+ return Config.Type.Bool;
+ }
+ else {
+ return value.get!(Config.Type);
+ }
+ }
View
2 test.sh
@@ -1,4 +1,4 @@
#! /bin/sh
-dmd -oftest test.d libconfig.d && ./test -L-lconfig
+dmd -oftest test.d libconfig.d deimos/libconfig.d -L-lconfig && ./test
rm -f test

0 comments on commit 320e361

Please sign in to comment.
Something went wrong with that request. Please try again.