refactor(config): assign memory address to _configPointer variable

This commit is contained in:
Aleksey Kulikov 2021-07-08 20:27:25 +03:00
parent 4bd324a596
commit b8b69100f1

View file

@ -23,14 +23,14 @@ class Config {
if (path == null) { if (path == null) {
try { try {
_configPointer = bindings.openDefault(); _configPointer = bindings.openDefault().value;
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
} else { } else {
try { try {
if (File(path!).existsSync()) { if (File(path!).existsSync()) {
_configPointer = bindings.open(path!); _configPointer = bindings.open(path!).value;
} else { } else {
throw Exception('File not found'); throw Exception('File not found');
} }
@ -50,7 +50,7 @@ class Config {
try { try {
final systemPath = bindings.findSystem(); final systemPath = bindings.findSystem();
_configPointer = bindings.open(systemPath); _configPointer = bindings.open(systemPath).value;
} catch (e) { } catch (e) {
_configPointer = nullptr; _configPointer = nullptr;
rethrow; rethrow;
@ -67,7 +67,7 @@ class Config {
try { try {
final globalPath = bindings.findGlobal(); final globalPath = bindings.findGlobal();
_configPointer = bindings.open(globalPath); _configPointer = bindings.open(globalPath).value;
} catch (e) { } catch (e) {
_configPointer = nullptr; _configPointer = nullptr;
rethrow; rethrow;
@ -84,7 +84,7 @@ class Config {
try { try {
final xdgPath = bindings.findXdg(); final xdgPath = bindings.findXdg();
_configPointer = bindings.open(xdgPath); _configPointer = bindings.open(xdgPath).value;
} catch (e) { } catch (e) {
_configPointer = nullptr; _configPointer = nullptr;
rethrow; rethrow;
@ -95,17 +95,17 @@ class Config {
String? path; String? path;
/// Pointer to memory address for allocated config object. /// Pointer to memory address for allocated config object.
late final Pointer<Pointer<git_config>> _configPointer; late final Pointer<git_config> _configPointer;
/// Returns map of all the config variables and their values. /// Returns map of all the config variables and their values.
Map<String, String> getEntries() { Map<String, String> getEntries() {
return bindings.getEntries(_configPointer.value); return bindings.getEntries(_configPointer);
} }
/// Returns the value of config [variable]. /// Returns the value of config [variable].
String getValue(String variable) { String getValue(String variable) {
try { try {
return bindings.getValue(_configPointer.value, variable); return bindings.getValue(_configPointer, variable);
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
@ -115,11 +115,11 @@ class Config {
void setValue(String variable, dynamic value) { void setValue(String variable, dynamic value) {
try { try {
if (value.runtimeType == bool) { if (value.runtimeType == bool) {
bindings.setBool(_configPointer.value, variable, value); bindings.setBool(_configPointer, variable, value);
} else if (value.runtimeType == int) { } else if (value.runtimeType == int) {
bindings.setInt(_configPointer.value, variable, value); bindings.setInt(_configPointer, variable, value);
} else { } else {
bindings.setString(_configPointer.value, variable, value); bindings.setString(_configPointer, variable, value);
} }
} catch (e) { } catch (e) {
rethrow; rethrow;
@ -132,7 +132,7 @@ class Config {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void deleteEntry(String variable) { void deleteEntry(String variable) {
try { try {
bindings.deleteEntry(_configPointer.value, variable); bindings.deleteEntry(_configPointer, variable);
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
@ -143,7 +143,7 @@ class Config {
/// If [regexp] is present, then the iterator will only iterate over all /// If [regexp] is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> getMultivarValue(String variable, {String? regexp}) { List<String> getMultivarValue(String variable, {String? regexp}) {
return bindings.getMultivarValue(_configPointer.value, variable, regexp); return bindings.getMultivarValue(_configPointer, variable, regexp);
} }
/// Sets the [value] of a multivar [variable] in the config file with the /// Sets the [value] of a multivar [variable] in the config file with the
@ -152,7 +152,7 @@ class Config {
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] sets [value] for all values of a multivar [variable]. /// Empty [regexp] sets [value] for all values of a multivar [variable].
void setMultivarValue(String variable, String regexp, String value) { void setMultivarValue(String variable, String regexp, String value) {
bindings.setMultivarValue(_configPointer.value, variable, regexp, value); bindings.setMultivarValue(_configPointer, variable, regexp, value);
} }
/// Deletes one or several values from a multivar [variable] in the config file /// Deletes one or several values from a multivar [variable] in the config file
@ -161,7 +161,7 @@ class Config {
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] deletes all values of a multivar [variable]. /// Empty [regexp] deletes all values of a multivar [variable].
void deleteMultivar(String variable, String regexp) { void deleteMultivar(String variable, String regexp) {
bindings.deleteMultivar(_configPointer.value, variable, regexp); bindings.deleteMultivar(_configPointer, variable, regexp);
} }
/// Releases memory allocated for config object. /// Releases memory allocated for config object.