[gnome-calculator/60-split-out-a-backend-library] Added implementation of GCalc main interfaces
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/60-split-out-a-backend-library] Added implementation of GCalc main interfaces
- Date: Wed, 2 Jan 2019 16:19:35 +0000 (UTC)
commit 1668c229cad9f5cdaa6fbdc3785816830b6d431a
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Dec 10 17:10:44 2018 -0600
Added implementation of GCalc main interfaces
gcalc/gcalc-expression.vala | 24 ++++++++++++++++++++++++
gcalc/gcalc-gexpression.vala | 31 +++++++++++++++++++++++++++++++
gcalc/gcalc-gresult.vala | 34 ++++++++++++++++++++++++++++++++++
gcalc/gcalc-gsolver.vala | 29 +++++++++++++++++++++++++++++
gcalc/gcalc-number.vala | 2 +-
gcalc/gcalc-result.vala | 2 +-
gcalc/meson.build | 6 +++++-
7 files changed, 125 insertions(+), 3 deletions(-)
---
diff --git a/gcalc/gcalc-expression.vala b/gcalc/gcalc-expression.vala
new file mode 100644
index 00000000..c45547b6
--- /dev/null
+++ b/gcalc/gcalc-expression.vala
@@ -0,0 +1,24 @@
+/* gcalc-expresion.vala
+ *
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+public interface GCalc.Expression : Object {
+ public abstract string to_string ();
+}
+
diff --git a/gcalc/gcalc-gexpression.vala b/gcalc/gcalc-gexpression.vala
new file mode 100644
index 00000000..715755bd
--- /dev/null
+++ b/gcalc/gcalc-gexpression.vala
@@ -0,0 +1,31 @@
+/* gcalc-gexpresion.vala
+ *
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+public class GCalc.GExpression : Object {
+ public GCalc.Number number { get; set; }
+ public GExpression.number_object (Number number) {
+ this.number = number;
+ }
+ public string to_string () {
+ var ser = new Serializer (DisplayFormat.AUTOMATIC, 10, 10);
+ return ser.to_string (number);
+ }
+}
+
diff --git a/gcalc/gcalc-gresult.vala b/gcalc/gcalc-gresult.vala
new file mode 100644
index 00000000..48b47bbe
--- /dev/null
+++ b/gcalc/gcalc-gresult.vala
@@ -0,0 +1,34 @@
+/* gcalc-gresult.vala
+ *
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+public class GCalc.GResult : Object {
+ private Expression _expression;
+ private ErrorResult _error;
+ public GResult (Expression exp) {
+ _expression = exp;
+ }
+ public bool is_valid { get { return expression != null; } }
+ public string to_string () {
+ return expression.to_string ();
+ }
+ public Expression expression { get { return _expression; } }
+ public ErrorResult error { get { return _error; } }
+}
+
diff --git a/gcalc/gcalc-gsolver.vala b/gcalc/gcalc-gsolver.vala
new file mode 100644
index 00000000..78902148
--- /dev/null
+++ b/gcalc/gcalc-gsolver.vala
@@ -0,0 +1,29 @@
+/* gcalc-solver.vala
+ *
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+public class GCalc.GSolver : Object, Solver {
+ private Equation equation;
+ public Result solve (string str) throws GLib.Error {
+ equation = new Equation (str);
+ var num = equation.parse ();
+ var exp = new GExpression.number_object (num) as Expression;
+ return new GResult (exp) as Result;
+ }
+}
diff --git a/gcalc/gcalc-number.vala b/gcalc/gcalc-number.vala
index fb77da25..abe42097 100644
--- a/gcalc/gcalc-number.vala
+++ b/gcalc/gcalc-number.vala
@@ -46,7 +46,7 @@ namespace GCalc {
{
/* real and imaginary part of a Number */
- private Complex num = Complex (1000);
+ internal Complex num = Complex (1000);
construct {
MPFR.Precision _mpfr_precision = 1000;
diff --git a/gcalc/gcalc-result.vala b/gcalc/gcalc-result.vala
index 814d6ff9..7bb82b7b 100644
--- a/gcalc/gcalc-result.vala
+++ b/gcalc/gcalc-result.vala
@@ -21,7 +21,7 @@
public interface GCalc.Result : Object {
public abstract bool is_valid { get; }
public abstract string to_string ();
- public abstract Number number { get; }
+ public abstract Expression expression { get; }
public abstract ErrorResult error { get; }
}
diff --git a/gcalc/meson.build b/gcalc/meson.build
index c5778db8..ae978daf 100644
--- a/gcalc/meson.build
+++ b/gcalc/meson.build
@@ -43,8 +43,12 @@ sources = files([
'gcalc-equation.vala',
'gcalc-equation-parser.vala',
'gcalc-equation-lexer.vala',
+ 'gcalc-expression.vala',
'gcalc-error-result.vala',
'gcalc-function-manager.vala',
+ 'gcalc-gexpression.vala',
+ 'gcalc-gresult.vala',
+ 'gcalc-gsolver.vala',
'gcalc-math-equation.vala',
'gcalc-math-equation-manager.vala',
'gcalc-math-function.vala',
@@ -140,4 +144,4 @@ custom_target('typelib',
depends: lib,
install: true,
install_dir: join_paths(get_option('libdir'), 'girepository-1.0'))
-endif
\ No newline at end of file
+endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]