Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
62 lines
1.4 KiB
Vala
62 lines
1.4 KiB
Vala
/*
|
|
* ParseResult.vala
|
|
*
|
|
* Result type for feed parsing operations
|
|
*/
|
|
|
|
public class RSSuper.ParseError : Object {
|
|
public string message { get; private set; }
|
|
public int code { get; private set; }
|
|
|
|
public ParseError(string message, int code = 0) {
|
|
this.message = message;
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
public class RSSuper.ParseResult : Object {
|
|
private Object? _value;
|
|
private ParseError? _error;
|
|
public bool ok { get; private set; }
|
|
private Type _value_type;
|
|
|
|
private ParseResult() {}
|
|
|
|
public static ParseResult success(Object value) {
|
|
var result = new ParseResult();
|
|
result.ok = true;
|
|
result._value = value;
|
|
result._value_type = value.get_type();
|
|
return result;
|
|
}
|
|
|
|
public static ParseResult error(string message, int code = 0) {
|
|
var result = new ParseResult();
|
|
result.ok = false;
|
|
result._error = new ParseError(message, code);
|
|
return result;
|
|
}
|
|
|
|
public Object? get_value() {
|
|
return this._value;
|
|
}
|
|
|
|
public T? get_value_as<T>() {
|
|
if (!ok) {
|
|
return null;
|
|
}
|
|
if (_value is T) {
|
|
return (T)_value;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public ParseError? get_error() {
|
|
return this._error;
|
|
}
|
|
|
|
public bool is_type<T>() {
|
|
return ok && _value_type == typeof(T);
|
|
}
|
|
}
|