libqalculate-ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Makefile +157 -0
- data/Rakefile +7 -0
- data/ext/libqalculate/BuiltinFunctions.h +261 -0
- data/ext/libqalculate/Calculator.h +1037 -0
- data/ext/libqalculate/DataSet.h +304 -0
- data/ext/libqalculate/ExpressionItem.h +289 -0
- data/ext/libqalculate/Function.h +766 -0
- data/ext/libqalculate/MathStructure.h +827 -0
- data/ext/libqalculate/Number.h +387 -0
- data/ext/libqalculate/Prefix.h +219 -0
- data/ext/libqalculate/Unit.h +300 -0
- data/ext/libqalculate/Variable.h +380 -0
- data/ext/libqalculate/includes.h +644 -0
- data/ext/libqalculate/qalculate.h +28 -0
- data/ext/libqalculate/util.h +88 -0
- data/ext/qalc_wrap.cxx +198164 -0
- data/extconf.rb +8 -0
- data/test/test_qalc.rb +40 -0
- metadata +71 -0
data/Makefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = ext
|
7
|
+
topdir = /usr/lib/ruby/1.8/i486-linux
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
exec_prefix = $(prefix)
|
11
|
+
prefix = $(DESTDIR)/usr
|
12
|
+
sharedstatedir = $(prefix)/com
|
13
|
+
mandir = $(prefix)/share/man
|
14
|
+
psdir = $(docdir)
|
15
|
+
oldincludedir = $(DESTDIR)/usr/include
|
16
|
+
localedir = $(datarootdir)/locale
|
17
|
+
bindir = $(exec_prefix)/bin
|
18
|
+
libexecdir = $(prefix)/lib/ruby1.8
|
19
|
+
sitedir = $(DESTDIR)/usr/local/lib/site_ruby
|
20
|
+
htmldir = $(docdir)
|
21
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
+
includedir = $(prefix)/include
|
23
|
+
infodir = $(prefix)/share/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
+
sysconfdir = $(DESTDIR)/etc
|
26
|
+
libdir = $(exec_prefix)/lib
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
+
dvidir = $(docdir)
|
31
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
+
datarootdir = $(prefix)/share
|
33
|
+
pdfdir = $(docdir)
|
34
|
+
archdir = $(rubylibdir)/$(arch)
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(DESTDIR)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
+
|
40
|
+
CC = g++ `pkg-config --cflags --libs libqalculate`
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags) -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2
|
48
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
49
|
+
DEFS = -D_FILE_OFFSET_BITS=64
|
50
|
+
CPPFLAGS = $(DEFS) $(cppflags)
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = $(CC) -shared
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby1.8
|
61
|
+
RUBY_SO_NAME = ruby1.8
|
62
|
+
arch = i486-linux
|
63
|
+
sitearch = i486-linux
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /usr/bin/ruby1.8
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lqalculate -lpthread -ldl -lcrypt -lm -lc
|
90
|
+
SRCS = qalc_wrap.cxx
|
91
|
+
OBJS = qalc_wrap.o
|
92
|
+
TARGET = qalculate
|
93
|
+
DLLIB = $(TARGET).so
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS)
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/Rakefile
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
/*
|
2
|
+
Qalculate
|
3
|
+
|
4
|
+
Copyright (C) 2003-2007 Niklas Knutsson (nq@altern.org)
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation; either version 2 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#ifndef BUILTIN_FUNCTIONS_H
|
13
|
+
#define BUILTIN_FUNCTIONS_H
|
14
|
+
|
15
|
+
#include <libqalculate/Function.h>
|
16
|
+
#include <libqalculate/includes.h>
|
17
|
+
|
18
|
+
#define DECLARE_BUILTIN_FUNCTION(x) class x : public MathFunction { \
|
19
|
+
public: \
|
20
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
21
|
+
x(); \
|
22
|
+
x(const x *function) {set(function);} \
|
23
|
+
ExpressionItem *copy() const {return new x(this);} \
|
24
|
+
};
|
25
|
+
|
26
|
+
#define DECLARE_BUILTIN_FUNCTION_B(x) class x : public MathFunction { \
|
27
|
+
public: \
|
28
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
29
|
+
x(); \
|
30
|
+
x(const x *function) {set(function);} \
|
31
|
+
ExpressionItem *copy() const {return new x(this);} \
|
32
|
+
bool representsBoolean(const MathStructure&) const {return true;}\
|
33
|
+
};
|
34
|
+
|
35
|
+
#define DECLARE_BUILTIN_FUNCTION_PI(x) class x : public MathFunction { \
|
36
|
+
public: \
|
37
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
38
|
+
x(); \
|
39
|
+
x(const x *function) {set(function);} \
|
40
|
+
ExpressionItem *copy() const {return new x(this);} \
|
41
|
+
bool representsInteger(const MathStructure&, bool) const {return true;}\
|
42
|
+
bool representsPositive(const MathStructure&, bool) const {return true;}\
|
43
|
+
};
|
44
|
+
|
45
|
+
#define DECLARE_BUILTIN_FUNCTION_RPI(x) class x : public MathFunction { \
|
46
|
+
public: \
|
47
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
48
|
+
x(); \
|
49
|
+
x(const x *function) {set(function);} \
|
50
|
+
ExpressionItem *copy() const {return new x(this);} \
|
51
|
+
bool representsReal(const MathStructure&, bool) const;\
|
52
|
+
bool representsInteger(const MathStructure&) const;\
|
53
|
+
bool representsNonNegative(const MathStructure&) const;\
|
54
|
+
};
|
55
|
+
|
56
|
+
#define DECLARE_BUILTIN_FUNCTION_R(x) class x : public MathFunction { \
|
57
|
+
public: \
|
58
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
59
|
+
x(); \
|
60
|
+
x(const x *function) {set(function);} \
|
61
|
+
ExpressionItem *copy() const {return new x(this);} \
|
62
|
+
bool representsPositive(const MathStructure &vargs, bool allow_units = false) const;\
|
63
|
+
bool representsNegative(const MathStructure &vargs, bool allow_units = false) const;\
|
64
|
+
bool representsNonNegative(const MathStructure &vargs, bool allow_units = false) const;\
|
65
|
+
bool representsNonPositive(const MathStructure &vargs, bool allow_units = false) const;\
|
66
|
+
bool representsInteger(const MathStructure &vargs, bool allow_units = false) const;\
|
67
|
+
bool representsNumber(const MathStructure &vargs, bool allow_units = false) const;\
|
68
|
+
bool representsRational(const MathStructure &vargs, bool allow_units = false) const;\
|
69
|
+
bool representsReal(const MathStructure &vargs, bool allow_units = false) const;\
|
70
|
+
bool representsComplex(const MathStructure &vargs, bool allow_units = false) const;\
|
71
|
+
bool representsNonZero(const MathStructure &vargs, bool allow_units = false) const;\
|
72
|
+
bool representsEven(const MathStructure &vargs, bool allow_units = false) const;\
|
73
|
+
bool representsOdd(const MathStructure &vargs, bool allow_units = false) const;\
|
74
|
+
bool representsUndefined(const MathStructure &vargs) const;\
|
75
|
+
};
|
76
|
+
|
77
|
+
#define DECLARE_BUILTIN_FUNCTION_R2(x) class x : public MathFunction { \
|
78
|
+
public: \
|
79
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
80
|
+
x(); \
|
81
|
+
x(const x *function) {set(function);} \
|
82
|
+
ExpressionItem *copy() const {return new x(this);} \
|
83
|
+
bool representsNumber(const MathStructure &vargs, bool allow_units = false) const;\
|
84
|
+
bool representsReal(const MathStructure &vargs, bool allow_units = false) const;\
|
85
|
+
};
|
86
|
+
#define DECLARE_BUILTIN_FUNCTION_R1(x) class x : public MathFunction { \
|
87
|
+
public: \
|
88
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo); \
|
89
|
+
x(); \
|
90
|
+
x(const x *function) {set(function);} \
|
91
|
+
ExpressionItem *copy() const {return new x(this);} \
|
92
|
+
bool representsNumber(const MathStructure &vargs, bool allow_units = false) const;\
|
93
|
+
};
|
94
|
+
|
95
|
+
|
96
|
+
DECLARE_BUILTIN_FUNCTION(VectorFunction)
|
97
|
+
DECLARE_BUILTIN_FUNCTION(LimitsFunction)
|
98
|
+
DECLARE_BUILTIN_FUNCTION(RankFunction)
|
99
|
+
DECLARE_BUILTIN_FUNCTION(SortFunction)
|
100
|
+
DECLARE_BUILTIN_FUNCTION(ComponentFunction)
|
101
|
+
DECLARE_BUILTIN_FUNCTION_PI(DimensionFunction)
|
102
|
+
|
103
|
+
DECLARE_BUILTIN_FUNCTION(MatrixFunction)
|
104
|
+
DECLARE_BUILTIN_FUNCTION(MergeVectorsFunction)
|
105
|
+
DECLARE_BUILTIN_FUNCTION(MatrixToVectorFunction)
|
106
|
+
DECLARE_BUILTIN_FUNCTION(AreaFunction)
|
107
|
+
DECLARE_BUILTIN_FUNCTION_PI(RowsFunction)
|
108
|
+
DECLARE_BUILTIN_FUNCTION_PI(ColumnsFunction)
|
109
|
+
DECLARE_BUILTIN_FUNCTION(RowFunction)
|
110
|
+
DECLARE_BUILTIN_FUNCTION(ColumnFunction)
|
111
|
+
DECLARE_BUILTIN_FUNCTION_PI(ElementsFunction)
|
112
|
+
DECLARE_BUILTIN_FUNCTION(ElementFunction)
|
113
|
+
DECLARE_BUILTIN_FUNCTION(TransposeFunction)
|
114
|
+
DECLARE_BUILTIN_FUNCTION(IdentityFunction)
|
115
|
+
DECLARE_BUILTIN_FUNCTION(DeterminantFunction)
|
116
|
+
DECLARE_BUILTIN_FUNCTION(PermanentFunction)
|
117
|
+
DECLARE_BUILTIN_FUNCTION(AdjointFunction)
|
118
|
+
DECLARE_BUILTIN_FUNCTION(CofactorFunction)
|
119
|
+
DECLARE_BUILTIN_FUNCTION(InverseFunction)
|
120
|
+
|
121
|
+
DECLARE_BUILTIN_FUNCTION_R(FactorialFunction)
|
122
|
+
DECLARE_BUILTIN_FUNCTION_R(DoubleFactorialFunction)
|
123
|
+
DECLARE_BUILTIN_FUNCTION_R(MultiFactorialFunction)
|
124
|
+
DECLARE_BUILTIN_FUNCTION(BinomialFunction)
|
125
|
+
|
126
|
+
DECLARE_BUILTIN_FUNCTION(BitXorFunction)
|
127
|
+
DECLARE_BUILTIN_FUNCTION_B(XorFunction)
|
128
|
+
DECLARE_BUILTIN_FUNCTION_B(OddFunction)
|
129
|
+
DECLARE_BUILTIN_FUNCTION_B(EvenFunction)
|
130
|
+
DECLARE_BUILTIN_FUNCTION(ShiftFunction)
|
131
|
+
|
132
|
+
DECLARE_BUILTIN_FUNCTION_R(AbsFunction)
|
133
|
+
DECLARE_BUILTIN_FUNCTION(GcdFunction)
|
134
|
+
DECLARE_BUILTIN_FUNCTION(LcmFunction)
|
135
|
+
DECLARE_BUILTIN_FUNCTION(SignumFunction)
|
136
|
+
DECLARE_BUILTIN_FUNCTION_R(RoundFunction)
|
137
|
+
DECLARE_BUILTIN_FUNCTION_R(FloorFunction)
|
138
|
+
DECLARE_BUILTIN_FUNCTION_R(CeilFunction)
|
139
|
+
DECLARE_BUILTIN_FUNCTION_R(TruncFunction)
|
140
|
+
DECLARE_BUILTIN_FUNCTION(NumeratorFunction)
|
141
|
+
DECLARE_BUILTIN_FUNCTION(DenominatorFunction)
|
142
|
+
DECLARE_BUILTIN_FUNCTION(IntFunction)
|
143
|
+
DECLARE_BUILTIN_FUNCTION(FracFunction)
|
144
|
+
DECLARE_BUILTIN_FUNCTION(RemFunction)
|
145
|
+
DECLARE_BUILTIN_FUNCTION(ModFunction)
|
146
|
+
|
147
|
+
DECLARE_BUILTIN_FUNCTION(PolynomialUnitFunction)
|
148
|
+
DECLARE_BUILTIN_FUNCTION(PolynomialPrimpartFunction)
|
149
|
+
DECLARE_BUILTIN_FUNCTION(PolynomialContentFunction)
|
150
|
+
DECLARE_BUILTIN_FUNCTION(CoeffFunction)
|
151
|
+
DECLARE_BUILTIN_FUNCTION(LCoeffFunction)
|
152
|
+
DECLARE_BUILTIN_FUNCTION(TCoeffFunction)
|
153
|
+
DECLARE_BUILTIN_FUNCTION(DegreeFunction)
|
154
|
+
DECLARE_BUILTIN_FUNCTION(LDegreeFunction)
|
155
|
+
|
156
|
+
DECLARE_BUILTIN_FUNCTION_R(ReFunction)
|
157
|
+
DECLARE_BUILTIN_FUNCTION_R(ImFunction)
|
158
|
+
DECLARE_BUILTIN_FUNCTION(ArgFunction)
|
159
|
+
|
160
|
+
DECLARE_BUILTIN_FUNCTION(SqrtFunction)
|
161
|
+
DECLARE_BUILTIN_FUNCTION(SquareFunction)
|
162
|
+
|
163
|
+
DECLARE_BUILTIN_FUNCTION(ExpFunction)
|
164
|
+
|
165
|
+
DECLARE_BUILTIN_FUNCTION_R(LogFunction)
|
166
|
+
DECLARE_BUILTIN_FUNCTION(LognFunction)
|
167
|
+
|
168
|
+
DECLARE_BUILTIN_FUNCTION(LambertWFunction)
|
169
|
+
|
170
|
+
DECLARE_BUILTIN_FUNCTION_R2(SinFunction)
|
171
|
+
DECLARE_BUILTIN_FUNCTION_R2(CosFunction)
|
172
|
+
DECLARE_BUILTIN_FUNCTION(TanFunction)
|
173
|
+
DECLARE_BUILTIN_FUNCTION_R1(AsinFunction)
|
174
|
+
DECLARE_BUILTIN_FUNCTION_R1(AcosFunction)
|
175
|
+
DECLARE_BUILTIN_FUNCTION_R2(AtanFunction)
|
176
|
+
DECLARE_BUILTIN_FUNCTION_R2(SinhFunction)
|
177
|
+
DECLARE_BUILTIN_FUNCTION_R2(CoshFunction)
|
178
|
+
DECLARE_BUILTIN_FUNCTION_R2(TanhFunction)
|
179
|
+
DECLARE_BUILTIN_FUNCTION_R2(AsinhFunction)
|
180
|
+
DECLARE_BUILTIN_FUNCTION_R1(AcoshFunction)
|
181
|
+
DECLARE_BUILTIN_FUNCTION(AtanhFunction)
|
182
|
+
DECLARE_BUILTIN_FUNCTION(RadiansToDefaultAngleUnitFunction)
|
183
|
+
|
184
|
+
DECLARE_BUILTIN_FUNCTION(ZetaFunction)
|
185
|
+
DECLARE_BUILTIN_FUNCTION(GammaFunction)
|
186
|
+
DECLARE_BUILTIN_FUNCTION(BetaFunction)
|
187
|
+
|
188
|
+
DECLARE_BUILTIN_FUNCTION(TotalFunction)
|
189
|
+
DECLARE_BUILTIN_FUNCTION(PercentileFunction)
|
190
|
+
DECLARE_BUILTIN_FUNCTION(MinFunction)
|
191
|
+
DECLARE_BUILTIN_FUNCTION(MaxFunction)
|
192
|
+
DECLARE_BUILTIN_FUNCTION(ModeFunction)
|
193
|
+
DECLARE_BUILTIN_FUNCTION_RPI(RandFunction)
|
194
|
+
|
195
|
+
DECLARE_BUILTIN_FUNCTION(ISODateFunction)
|
196
|
+
DECLARE_BUILTIN_FUNCTION(LocalDateFunction)
|
197
|
+
DECLARE_BUILTIN_FUNCTION(TimestampFunction)
|
198
|
+
DECLARE_BUILTIN_FUNCTION(TimestampToDateFunction)
|
199
|
+
DECLARE_BUILTIN_FUNCTION(DaysFunction)
|
200
|
+
DECLARE_BUILTIN_FUNCTION(YearFracFunction)
|
201
|
+
DECLARE_BUILTIN_FUNCTION(WeekFunction)
|
202
|
+
DECLARE_BUILTIN_FUNCTION(WeekdayFunction)
|
203
|
+
DECLARE_BUILTIN_FUNCTION(MonthFunction)
|
204
|
+
DECLARE_BUILTIN_FUNCTION(DayFunction)
|
205
|
+
DECLARE_BUILTIN_FUNCTION(YearFunction)
|
206
|
+
DECLARE_BUILTIN_FUNCTION(YeardayFunction)
|
207
|
+
DECLARE_BUILTIN_FUNCTION(TimeFunction)
|
208
|
+
DECLARE_BUILTIN_FUNCTION(AddDaysFunction)
|
209
|
+
DECLARE_BUILTIN_FUNCTION(AddMonthsFunction)
|
210
|
+
DECLARE_BUILTIN_FUNCTION(AddYearsFunction)
|
211
|
+
|
212
|
+
DECLARE_BUILTIN_FUNCTION(BinFunction)
|
213
|
+
DECLARE_BUILTIN_FUNCTION(OctFunction)
|
214
|
+
DECLARE_BUILTIN_FUNCTION(HexFunction)
|
215
|
+
DECLARE_BUILTIN_FUNCTION(BaseFunction)
|
216
|
+
DECLARE_BUILTIN_FUNCTION(RomanFunction)
|
217
|
+
|
218
|
+
DECLARE_BUILTIN_FUNCTION_PI(AsciiFunction)
|
219
|
+
DECLARE_BUILTIN_FUNCTION(CharFunction)
|
220
|
+
|
221
|
+
DECLARE_BUILTIN_FUNCTION_PI(LengthFunction)
|
222
|
+
DECLARE_BUILTIN_FUNCTION(ConcatenateFunction)
|
223
|
+
|
224
|
+
DECLARE_BUILTIN_FUNCTION(ReplaceFunction)
|
225
|
+
DECLARE_BUILTIN_FUNCTION(StripUnitsFunction)
|
226
|
+
|
227
|
+
DECLARE_BUILTIN_FUNCTION(GenerateVectorFunction)
|
228
|
+
DECLARE_BUILTIN_FUNCTION(ForFunction)
|
229
|
+
DECLARE_BUILTIN_FUNCTION(SumFunction)
|
230
|
+
DECLARE_BUILTIN_FUNCTION(ProductFunction)
|
231
|
+
DECLARE_BUILTIN_FUNCTION(ProcessFunction)
|
232
|
+
DECLARE_BUILTIN_FUNCTION(ProcessMatrixFunction)
|
233
|
+
DECLARE_BUILTIN_FUNCTION(CustomSumFunction)
|
234
|
+
DECLARE_BUILTIN_FUNCTION(FunctionFunction)
|
235
|
+
DECLARE_BUILTIN_FUNCTION(SelectFunction)
|
236
|
+
DECLARE_BUILTIN_FUNCTION(TitleFunction)
|
237
|
+
DECLARE_BUILTIN_FUNCTION(IFFunction)
|
238
|
+
DECLARE_BUILTIN_FUNCTION(IsNumberFunction)
|
239
|
+
DECLARE_BUILTIN_FUNCTION(IsRealFunction)
|
240
|
+
DECLARE_BUILTIN_FUNCTION(IsRationalFunction)
|
241
|
+
DECLARE_BUILTIN_FUNCTION(IsIntegerFunction)
|
242
|
+
DECLARE_BUILTIN_FUNCTION(RepresentsNumberFunction)
|
243
|
+
DECLARE_BUILTIN_FUNCTION(RepresentsRealFunction)
|
244
|
+
DECLARE_BUILTIN_FUNCTION(RepresentsRationalFunction)
|
245
|
+
DECLARE_BUILTIN_FUNCTION(RepresentsIntegerFunction)
|
246
|
+
DECLARE_BUILTIN_FUNCTION(ErrorFunction)
|
247
|
+
DECLARE_BUILTIN_FUNCTION(WarningFunction)
|
248
|
+
DECLARE_BUILTIN_FUNCTION(MessageFunction)
|
249
|
+
DECLARE_BUILTIN_FUNCTION(SaveFunction)
|
250
|
+
DECLARE_BUILTIN_FUNCTION(LoadFunction)
|
251
|
+
DECLARE_BUILTIN_FUNCTION(ExportFunction)
|
252
|
+
|
253
|
+
DECLARE_BUILTIN_FUNCTION(RegisterFunction)
|
254
|
+
DECLARE_BUILTIN_FUNCTION(StackFunction)
|
255
|
+
|
256
|
+
DECLARE_BUILTIN_FUNCTION(DeriveFunction)
|
257
|
+
DECLARE_BUILTIN_FUNCTION(IntegrateFunction)
|
258
|
+
DECLARE_BUILTIN_FUNCTION(SolveFunction)
|
259
|
+
DECLARE_BUILTIN_FUNCTION(SolveMultipleFunction)
|
260
|
+
|
261
|
+
#endif
|
@@ -0,0 +1,1037 @@
|
|
1
|
+
/*
|
2
|
+
Qalculate
|
3
|
+
|
4
|
+
Copyright (C) 2003-2007 Niklas Knutsson (nq@altern.org)
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation; either version 2 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#ifndef CALCULATOR_H
|
13
|
+
#define CALCULATOR_H
|
14
|
+
|
15
|
+
#include <libqalculate/includes.h>
|
16
|
+
#include <libqalculate/util.h>
|
17
|
+
#include <pthread.h>
|
18
|
+
|
19
|
+
/** @file */
|
20
|
+
|
21
|
+
/** \mainpage Index
|
22
|
+
*
|
23
|
+
* \section intro_sec Introduction
|
24
|
+
*
|
25
|
+
* libqalculate is math libary for expression evaluation with units, variables and functions support and CAS functionality.
|
26
|
+
*
|
27
|
+
* The main parts of the library is the almighty Calculator class, the MathStructure class for mathematical expressions and classes for objects in an epxression,
|
28
|
+
* mostly of the class Numbers and sub classes of ExpressionItem.
|
29
|
+
*
|
30
|
+
* A simple application using libqalculate need only create a calculator object, perhaps load definitions (functions, variables, units, etc.) and use the calculate function as follows:
|
31
|
+
* \code new Calculator();
|
32
|
+
* CALCULATOR->loadGlobalDefinitions();
|
33
|
+
* CALCULATOR->loadLocalDefinitions();
|
34
|
+
* EvaluationOptions eo;
|
35
|
+
* MathStructure result = CALCULATOR->calculate("1 + 1", eo);\endcode
|
36
|
+
*
|
37
|
+
* More complex usage mainly involves manipulating objects of the MathStructure class directly.
|
38
|
+
*
|
39
|
+
* To display the resulting expression you will normally use MathStructure::format() followed by MathStructure::print() as follows:
|
40
|
+
* \code PrintOptions po;
|
41
|
+
* result.format(po);
|
42
|
+
* std::string result_str = result.print(po); \endcode
|
43
|
+
*
|
44
|
+
* Central to the flexiblity of libqalculate is the many options passed to evaluating and display functions with EvaluationOptions and PrintOptions.
|
45
|
+
*
|
46
|
+
* \section usage_sec Using the library
|
47
|
+
*
|
48
|
+
* libqalculate uses pkg-config.
|
49
|
+
*
|
50
|
+
* For a simple program use pkg-config on the command line:
|
51
|
+
* \code c++ `pkg-config --cflags --libs libqalculate` hello.c -o hello \endcode
|
52
|
+
*
|
53
|
+
* If the program uses autoconf, put the following in configure.in:
|
54
|
+
* \code PKG_CHECK_MODULES(QALCULATE, [
|
55
|
+
* libqalculate >= 0.9.6
|
56
|
+
* ])
|
57
|
+
* AC_SUBST(QALCULATE_CFLAGS)
|
58
|
+
* AC_SUBST(QALCULATE_LIBS) \endcode
|
59
|
+
*/
|
60
|
+
|
61
|
+
|
62
|
+
typedef std::vector<Prefix*> p_type;
|
63
|
+
|
64
|
+
/// Parameters passed to plotting functions.
|
65
|
+
struct PlotParameters {
|
66
|
+
/// Title label.
|
67
|
+
std::string title;
|
68
|
+
/// Y-axis label.
|
69
|
+
std::string y_label;
|
70
|
+
/// X-axis label.
|
71
|
+
std::string x_label;
|
72
|
+
/// Image to save plot to. If empty shows plot in a window on the screen.
|
73
|
+
std::string filename;
|
74
|
+
/// The image type to save as. Set to PLOT_FILETYPE_AUTO to guess from file extension.
|
75
|
+
PlotFileType filetype;
|
76
|
+
/// Font used for text
|
77
|
+
std::string font;
|
78
|
+
/// Set to true for colored plot, false for monochrome. Default: true
|
79
|
+
bool color;
|
80
|
+
/// If the minimum y-axis value shall be set automatically (otherwise uses y_min). Default: true
|
81
|
+
bool auto_y_min;
|
82
|
+
/// If the minimum x-axis value shall be set automatically (otherwise uses x_min). Default: true
|
83
|
+
bool auto_x_min;
|
84
|
+
/// If the maximum y-axis value shall be set automatically (otherwise uses y_max). Default: true
|
85
|
+
bool auto_y_max;
|
86
|
+
/// If the maximum x-axis value shall be set automatically (otherwise uses x_max). Default: true
|
87
|
+
bool auto_x_max;
|
88
|
+
/// Minimum y-axis value.
|
89
|
+
float y_min;
|
90
|
+
/// Minimum x-axis value.
|
91
|
+
float x_min;
|
92
|
+
/// Maximum y-axis value.
|
93
|
+
float y_max;
|
94
|
+
/// Maximum x-axis value.
|
95
|
+
float x_max;
|
96
|
+
/// If a logarithimic scale shall be used for the y-axis. Default: false
|
97
|
+
bool y_log;
|
98
|
+
/// If a logarithimic scale shall be used for the x-axis. Default: false
|
99
|
+
bool x_log;
|
100
|
+
/// Logarithimic base for the y-axis. Default: 10
|
101
|
+
int y_log_base;
|
102
|
+
/// Logarithimic base for the x-axis. Default: 10
|
103
|
+
int x_log_base;
|
104
|
+
/// If a grid shall be shown in the plot. Default: false
|
105
|
+
bool grid;
|
106
|
+
/// Width of lines. Default: 2
|
107
|
+
int linewidth;
|
108
|
+
/// If the plot shall be surrounded by borders on all sides (not just axis). Default: false
|
109
|
+
bool show_all_borders;
|
110
|
+
/// Where the plot legend shall be placed. Default: PLOT_LEGEND_TOP_RIGHT
|
111
|
+
PlotLegendPlacement legend_placement;
|
112
|
+
PlotParameters();
|
113
|
+
};
|
114
|
+
|
115
|
+
/// Parameters for plot data series.
|
116
|
+
struct PlotDataParameters {
|
117
|
+
/// Title label.
|
118
|
+
std::string title;
|
119
|
+
/// Plot smoothing.
|
120
|
+
PlotSmoothing smoothing;
|
121
|
+
/// Plot style
|
122
|
+
PlotStyle style;
|
123
|
+
/// Use scale on second y-axis
|
124
|
+
bool yaxis2;
|
125
|
+
/// Use scale on second x-axis
|
126
|
+
bool xaxis2;
|
127
|
+
PlotDataParameters();
|
128
|
+
};
|
129
|
+
|
130
|
+
///Message types
|
131
|
+
typedef enum {
|
132
|
+
MESSAGE_INFORMATION,
|
133
|
+
MESSAGE_WARNING,
|
134
|
+
MESSAGE_ERROR
|
135
|
+
} MessageType;
|
136
|
+
|
137
|
+
/// A message with information to the user. Primarily used for errors and warnings.
|
138
|
+
class CalculatorMessage {
|
139
|
+
protected:
|
140
|
+
std::string smessage;
|
141
|
+
MessageType mtype;
|
142
|
+
public:
|
143
|
+
CalculatorMessage(std::string message_, MessageType type_ = MESSAGE_WARNING);
|
144
|
+
CalculatorMessage(const CalculatorMessage &e);
|
145
|
+
std::string message() const;
|
146
|
+
const char* c_message() const;
|
147
|
+
MessageType type() const;
|
148
|
+
};
|
149
|
+
|
150
|
+
#include <libqalculate/MathStructure.h>
|
151
|
+
|
152
|
+
enum {
|
153
|
+
ELEMENT_CLASS_NOT_DEFINED,
|
154
|
+
ALKALI_METALS,
|
155
|
+
ALKALI_EARTH_METALS,
|
156
|
+
LANTHANIDES,
|
157
|
+
ACTINIDES,
|
158
|
+
TRANSITION_METALS,
|
159
|
+
METALS,
|
160
|
+
METALLOIDS,
|
161
|
+
NONMETALS,
|
162
|
+
HALOGENS,
|
163
|
+
NOBLE_GASES,
|
164
|
+
TRANSACTINIDES
|
165
|
+
};
|
166
|
+
|
167
|
+
struct Element {
|
168
|
+
std::string symbol, name;
|
169
|
+
int number, group;
|
170
|
+
std::string weight;
|
171
|
+
int x_pos, y_pos;
|
172
|
+
};
|
173
|
+
|
174
|
+
#define UFV_LENGTHS 20
|
175
|
+
|
176
|
+
/// The almighty calculator class.
|
177
|
+
/** The calculator class is responsible for loading functions, variables and units, and keeping track of them, as well as parsing expressions and much more. A calculator object must be created before any other Qalculate! class is used. There should never be more than one calculator object, accessed with CALCULATOR.
|
178
|
+
*
|
179
|
+
* A simple application using libqalculate need only create a calculator object, perhaps load definitions (functions, variables, units, etc.) and use the calculate function as follows:
|
180
|
+
* \code new Calculator();
|
181
|
+
* CALCULATOR->loadGlobalDefinitions();
|
182
|
+
* CALCULATOR->loadLocalDefinitions();
|
183
|
+
* MathStructure result = CALCULATOR->calculate("1 + 1");\endcode
|
184
|
+
*/
|
185
|
+
class Calculator {
|
186
|
+
|
187
|
+
protected:
|
188
|
+
|
189
|
+
std::vector<CalculatorMessage> messages;
|
190
|
+
|
191
|
+
int ianglemode;
|
192
|
+
int i_precision;
|
193
|
+
char vbuffer[200];
|
194
|
+
std::vector<void*> ufvl;
|
195
|
+
std::vector<char> ufvl_t;
|
196
|
+
std::vector<size_t> ufvl_i;
|
197
|
+
std::vector<void*> ufv[4][UFV_LENGTHS];
|
198
|
+
std::vector<size_t> ufv_i[4][UFV_LENGTHS];
|
199
|
+
|
200
|
+
std::vector<DataSet*> data_sets;
|
201
|
+
|
202
|
+
Sgi::hash_map<size_t, MathStructure*> id_structs;
|
203
|
+
Sgi::hash_map<size_t, bool> ids_p;
|
204
|
+
std::vector<size_t> freed_ids;
|
205
|
+
size_t ids_i;
|
206
|
+
|
207
|
+
std::vector<std::string> signs;
|
208
|
+
std::vector<std::string> real_signs;
|
209
|
+
std::vector<std::string> default_signs;
|
210
|
+
std::vector<std::string> default_real_signs;
|
211
|
+
char *saved_locale;
|
212
|
+
int disable_errors_ref;
|
213
|
+
std::vector<int> stopped_errors_count;
|
214
|
+
std::vector<int> stopped_warnings_count;
|
215
|
+
std::vector<int> stopped_messages_count;
|
216
|
+
pthread_t calculate_thread;
|
217
|
+
pthread_attr_t calculate_thread_attr;
|
218
|
+
pthread_t print_thread;
|
219
|
+
pthread_attr_t print_thread_attr;
|
220
|
+
bool b_functions_was, b_variables_was, b_units_was, b_unknown_was, b_calcvars_was, b_rpn_was;
|
221
|
+
std::string NAME_NUMBER_PRE_S, NAME_NUMBER_PRE_STR, DOT_STR, DOT_S, COMMA_S, COMMA_STR, ILLEGAL_IN_NAMES, ILLEGAL_IN_UNITNAMES, ILLEGAL_IN_NAMES_MINUS_SPACE_STR;
|
222
|
+
|
223
|
+
bool b_argument_errors;
|
224
|
+
bool exchange_rates_warning_issued;
|
225
|
+
|
226
|
+
int has_gnomevfs;
|
227
|
+
|
228
|
+
bool b_gnuplot_open;
|
229
|
+
std::string gnuplot_cmdline;
|
230
|
+
FILE *gnuplot_pipe, *calculate_pipe_r, *calculate_pipe_w, *print_pipe_r, *print_pipe_w;
|
231
|
+
|
232
|
+
bool local_to;
|
233
|
+
|
234
|
+
Assumptions *default_assumptions;
|
235
|
+
|
236
|
+
std::vector<Variable*> deleted_variables;
|
237
|
+
std::vector<MathFunction*> deleted_functions;
|
238
|
+
std::vector<Unit*> deleted_units;
|
239
|
+
|
240
|
+
bool b_save_called;
|
241
|
+
|
242
|
+
std::string per_str, times_str, plus_str, minus_str, and_str, AND_str, or_str, OR_str, XOR_str;
|
243
|
+
size_t per_str_len, times_str_len, plus_str_len, minus_str_len, and_str_len, AND_str_len, or_str_len, OR_str_len, XOR_str_len;
|
244
|
+
|
245
|
+
std::vector<MathStructure*> rpn_stack;
|
246
|
+
|
247
|
+
bool calculateRPN(MathStructure *mstruct, int command, size_t index, int msecs, const EvaluationOptions &eo);
|
248
|
+
bool calculateRPN(std::string str, int command, size_t index, int msecs, const EvaluationOptions &eo, MathStructure *parsed_struct, MathStructure *to_struct, bool make_to_division);
|
249
|
+
|
250
|
+
public:
|
251
|
+
|
252
|
+
KnownVariable *v_pi, *v_e, *v_i, *v_inf, *v_pinf, *v_minf, *v_undef;
|
253
|
+
UnknownVariable *v_x, *v_y, *v_z;
|
254
|
+
MathFunction *f_vector, *f_sort, *f_rank, *f_limits, *f_component, *f_dimension, *f_merge_vectors;
|
255
|
+
MathFunction *f_matrix, *f_matrix_to_vector, *f_area, *f_rows, *f_columns, *f_row, *f_column, *f_elements, *f_element, *f_transpose, *f_identity, *f_determinant, *f_permanent, *f_adjoint, *f_cofactor, *f_inverse;
|
256
|
+
MathFunction *f_factorial, *f_factorial2, *f_multifactorial, *f_binomial;
|
257
|
+
MathFunction *f_xor, *f_bitxor, *f_even, *f_odd, *f_shift;
|
258
|
+
MathFunction *f_abs, *f_gcd, *f_lcm, *f_signum, *f_round, *f_floor, *f_ceil, *f_trunc, *f_int, *f_frac, *f_rem, *f_mod;
|
259
|
+
MathFunction *f_polynomial_unit, *f_polynomial_primpart, *f_polynomial_content, *f_coeff, *f_lcoeff, *f_tcoeff, *f_degree, *f_ldegree;
|
260
|
+
MathFunction *f_re, *f_im, *f_arg, *f_numerator, *f_denominator;
|
261
|
+
MathFunction *f_sqrt, *f_sq;
|
262
|
+
MathFunction *f_exp;
|
263
|
+
MathFunction *f_ln, *f_logn;
|
264
|
+
MathFunction *f_lambert_w;
|
265
|
+
MathFunction *f_sin, *f_cos, *f_tan, *f_asin, *f_acos, *f_atan, *f_sinh, *f_cosh, *f_tanh, *f_asinh, *f_acosh, *f_atanh, *f_radians_to_default_angle_unit;
|
266
|
+
MathFunction *f_zeta, *f_gamma, *f_beta;
|
267
|
+
MathFunction *f_total, *f_percentile, *f_min, *f_max, *f_mode, *f_rand;
|
268
|
+
MathFunction *f_isodate, *f_localdate, *f_timestamp, *f_stamptodate, *f_days, *f_yearfrac, *f_week, *f_weekday, *f_month, *f_day, *f_year, *f_yearday, *f_time, *f_add_days, *f_add_months, *f_add_years;
|
269
|
+
MathFunction *f_bin, *f_oct, *f_hex, *f_base, *f_roman;
|
270
|
+
MathFunction *f_ascii, *f_char;
|
271
|
+
MathFunction *f_length, *f_concatenate;
|
272
|
+
MathFunction *f_replace, *f_stripunits;
|
273
|
+
MathFunction *f_genvector, *f_for, *f_sum, *f_product, *f_process, *f_process_matrix, *f_csum, *f_if, *f_is_number, *f_is_real, *f_is_rational, *f_is_integer, *f_represents_number, *f_represents_real, *f_represents_rational, *f_represents_integer, *f_function, *f_select;
|
274
|
+
MathFunction *f_diff, *f_integrate, *f_solve, *f_multisolve;
|
275
|
+
MathFunction *f_error, *f_warning, *f_message, *f_save, *f_load, *f_export, *f_title;
|
276
|
+
MathFunction *f_register, *f_stack;
|
277
|
+
Unit *u_rad, *u_gra, *u_deg, *u_euro;
|
278
|
+
DecimalPrefix *decimal_null_prefix;
|
279
|
+
BinaryPrefix *binary_null_prefix;
|
280
|
+
|
281
|
+
bool place_currency_code_before, place_currency_sign_before;
|
282
|
+
bool place_currency_code_before_negative, place_currency_sign_before_negative;
|
283
|
+
bool default_dot_as_separator;
|
284
|
+
|
285
|
+
bool b_busy, calculate_thread_stopped, print_thread_stopped;
|
286
|
+
std::string expression_to_calculate, tmp_print_result;
|
287
|
+
PrintOptions tmp_printoptions;
|
288
|
+
EvaluationOptions tmp_evaluationoptions;
|
289
|
+
MathStructure *tmp_parsedstruct;
|
290
|
+
MathStructure *tmp_tostruct;
|
291
|
+
MathStructure *tmp_rpn_mstruct;
|
292
|
+
bool tmp_maketodivision;
|
293
|
+
int tmp_proc_command;
|
294
|
+
size_t tmp_rpnindex;
|
295
|
+
|
296
|
+
PrintOptions save_printoptions;
|
297
|
+
|
298
|
+
std::vector<Variable*> variables;
|
299
|
+
std::vector<MathFunction*> functions;
|
300
|
+
std::vector<Unit*> units;
|
301
|
+
std::vector<Prefix*> prefixes;
|
302
|
+
std::vector<DecimalPrefix*> decimal_prefixes;
|
303
|
+
std::vector<BinaryPrefix*> binary_prefixes;
|
304
|
+
|
305
|
+
/** @name Constructor */
|
306
|
+
//@{
|
307
|
+
Calculator();
|
308
|
+
virtual ~Calculator();
|
309
|
+
//@}
|
310
|
+
|
311
|
+
/** @name Functions for calculating expressions. */
|
312
|
+
//@{
|
313
|
+
/** Calculates an expression. The expression should be unlocalized first with unlocalizeExpression().
|
314
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
315
|
+
* The calculation can then be stopped with abort().
|
316
|
+
*
|
317
|
+
* @param[out] mstruct Math structure to fill with the result.
|
318
|
+
* @param str Expression.
|
319
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
320
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
321
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the result of the parsing of the expression.
|
322
|
+
* @param[out] to_struct NULL or a math structure to fill with unit expression parsed after "to".
|
323
|
+
* @param make_to_division If true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
|
324
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
325
|
+
*/
|
326
|
+
bool calculate(MathStructure *mstruct, std::string str, int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
327
|
+
/** Calculates an expression. The expression should be unlocalized first with unlocalizeExpression().
|
328
|
+
*
|
329
|
+
* @param str Expression.
|
330
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
331
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the result of the parsing of the expression.
|
332
|
+
* @param[out] to_struct NULL or a math structure to fill with unit expression parsed after "to".
|
333
|
+
* @param make_to_division If true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
|
334
|
+
* @returns The result of the calculation.
|
335
|
+
*/
|
336
|
+
MathStructure calculate(std::string str, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
337
|
+
std::string printMathStructureTimeOut(const MathStructure &mstruct, int msecs = 100000, const PrintOptions &op = default_print_options);
|
338
|
+
int testCondition(std::string expression);
|
339
|
+
//@}
|
340
|
+
|
341
|
+
/** @name Functions for handling of threaded calculations */
|
342
|
+
//@{
|
343
|
+
/** Aborts the current calculation. */
|
344
|
+
void abort();
|
345
|
+
/** Aborts the current calculation. Used from within the calculation thread. */
|
346
|
+
void abort_this();
|
347
|
+
/** Returns true if the calculate or print thread is busy. */
|
348
|
+
bool busy();
|
349
|
+
/** Saves the state of the calculator. Used internally to be able to restore the state after aborted calculation. */
|
350
|
+
void saveState();
|
351
|
+
/** Restores the saved state of the calculator. Used internally to restore the state after aborted calculation. */
|
352
|
+
void restoreState();
|
353
|
+
/** Clears all stored values. Used internally after aborted calculation. */
|
354
|
+
void clearBuffers();
|
355
|
+
/** Terminate calculation and print threads if started. Do not use to terminate calculation. */
|
356
|
+
void terminateThreads();
|
357
|
+
//@}
|
358
|
+
|
359
|
+
/** @name Functions for manipulation of the RPN stack. */
|
360
|
+
//@{
|
361
|
+
/** Evaluates a value on the RPN stack.
|
362
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
363
|
+
* The calculation can then be stopped with abort().
|
364
|
+
*
|
365
|
+
* @param index Index, starting at 1, on the RPN stack.
|
366
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
367
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
368
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
369
|
+
*/
|
370
|
+
bool calculateRPNRegister(size_t index, int msecs, const EvaluationOptions &eo = default_evaluation_options);
|
371
|
+
/** Applies a mathematical operation to the first and second value on the RPN stack. The the second value is changed with input from the first value.
|
372
|
+
* For example, with OPERATION_SUBTRACT the first value is subtracted from the second. The first value on the stack is removed.
|
373
|
+
* If not enough registers is available, then zeros are added.
|
374
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
375
|
+
* The calculation can then be stopped with abort().
|
376
|
+
*
|
377
|
+
* @param op Operation.
|
378
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
379
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
380
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
381
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
382
|
+
*/
|
383
|
+
bool calculateRPN(MathOperation op, int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
384
|
+
/** Applies a mathematical operation to the first value on the RPN stack. The value is set as the first argument of the function.
|
385
|
+
* If no register is available, then zero is added.
|
386
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
387
|
+
* The calculation can then be stopped with abort().
|
388
|
+
*
|
389
|
+
* @param f Mathematical function.
|
390
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
391
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
392
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
393
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
394
|
+
*/
|
395
|
+
bool calculateRPN(MathFunction *f, int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
396
|
+
/** Applies bitwise not to the first value on the RPN stack.
|
397
|
+
* If no register is available, then zero is added.
|
398
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
399
|
+
* The calculation can then be stopped with abort().
|
400
|
+
*
|
401
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
402
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
403
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
404
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
405
|
+
*/
|
406
|
+
bool calculateRPNBitwiseNot(int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
407
|
+
/** Applies logical not to the first value on the RPN stack.
|
408
|
+
* If no register is available, then zero is added.
|
409
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
410
|
+
* The calculation can then be stopped with abort().
|
411
|
+
*
|
412
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
413
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
414
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
415
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
416
|
+
*/
|
417
|
+
bool calculateRPNLogicalNot(int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
418
|
+
/** Applies a mathematical operation to the first and second value on the RPN stack. The the second value is changed with input from the first value.
|
419
|
+
* For example, with OPERATION_SUBTRACT the first value is subtracted from the second. The first value on the stack is removed.
|
420
|
+
* If not enough registers is available, then zeros are added.
|
421
|
+
*
|
422
|
+
* @param op Operation.
|
423
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
424
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
425
|
+
* @returns The first value on the stack.
|
426
|
+
*/
|
427
|
+
MathStructure *calculateRPN(MathOperation op, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
428
|
+
/** Applies a mathematical operation to the first value on the RPN stack. The value is set as the first argument of the function.
|
429
|
+
* If no register is available, then zero is added.
|
430
|
+
*
|
431
|
+
* @param f Mathematical function.
|
432
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
433
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
434
|
+
* @returns The first value on the stack.
|
435
|
+
*/
|
436
|
+
MathStructure *calculateRPN(MathFunction *f, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
437
|
+
/** Applies bitwise not to the first value on the RPN stack.
|
438
|
+
* If no register is available, then zero is added.
|
439
|
+
*
|
440
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
441
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
442
|
+
* @returns The first value on the stack.
|
443
|
+
*/
|
444
|
+
MathStructure *calculateRPNBitwiseNot(const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
445
|
+
/** Applies logical not to the first value on the RPN stack.
|
446
|
+
* If no register is available, then zero is added.
|
447
|
+
*
|
448
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
449
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the unevaluated result.
|
450
|
+
* @returns The first value on the stack.
|
451
|
+
*/
|
452
|
+
MathStructure *calculateRPNLogicalNot(const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL);
|
453
|
+
/** Evaluates a value and adds the result first on the RPN stack.
|
454
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
455
|
+
* The calculation can then be stopped with abort().
|
456
|
+
*
|
457
|
+
* @param mstruct Value.
|
458
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
459
|
+
* @param eo Options for the evaluation of the expression.
|
460
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
461
|
+
*/
|
462
|
+
bool RPNStackEnter(MathStructure *mstruct, int msecs, const EvaluationOptions &eo = default_evaluation_options);
|
463
|
+
/** Calculates an expression and adds the result first on the RPN stack. The expression should be unlocalized first with unlocalizeExpression().
|
464
|
+
* This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified.
|
465
|
+
* The calculation can then be stopped with abort().
|
466
|
+
*
|
467
|
+
* @param str Expression.
|
468
|
+
* @param msecs The maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
|
469
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
470
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the result of the parsing of the expression.
|
471
|
+
* @param[out] to_struct NULL or a math structure to fill with unit expression parsed after "to".
|
472
|
+
* @param make_to_division If true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
|
473
|
+
* @returns true if the calculation was successfully started (and finished if msecs > 0).
|
474
|
+
*/
|
475
|
+
bool RPNStackEnter(std::string str, int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
476
|
+
/** Adds a value first on the RPN stack.
|
477
|
+
*
|
478
|
+
* @param mstruct Value.
|
479
|
+
* @param eval If true, the the mathematical structure will be evaluated first.
|
480
|
+
*/
|
481
|
+
void RPNStackEnter(MathStructure *mstruct, bool eval = false, const EvaluationOptions &eo = default_evaluation_options);
|
482
|
+
/** Calculates an expression adds the result first on the RPN stack. The expression should be unlocalized first with unlocalizeExpression().
|
483
|
+
*
|
484
|
+
* @param str Expression.
|
485
|
+
* @param eo Options for the evaluation and parsing of the expression.
|
486
|
+
* @param[out] parsed_struct NULL or a math structure to fill with the result of the parsing of the expression.
|
487
|
+
* @param[out] to_struct NULL or a math structure to fill with unit expression parsed after "to".
|
488
|
+
* @param make_to_division If true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
|
489
|
+
*/
|
490
|
+
void RPNStackEnter(std::string str, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
491
|
+
bool setRPNRegister(size_t index, MathStructure *mstruct, int msecs, const EvaluationOptions &eo = default_evaluation_options);
|
492
|
+
bool setRPNRegister(size_t index, std::string str, int msecs, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
493
|
+
void setRPNRegister(size_t index, MathStructure *mstruct, bool eval = false, const EvaluationOptions &eo = default_evaluation_options);
|
494
|
+
void setRPNRegister(size_t index, std::string str, const EvaluationOptions &eo = default_evaluation_options, MathStructure *parsed_struct = NULL, MathStructure *to_struct = NULL, bool make_to_division = true);
|
495
|
+
void deleteRPNRegister(size_t index);
|
496
|
+
MathStructure *getRPNRegister(size_t index = 1) const;
|
497
|
+
size_t RPNStackSize() const;
|
498
|
+
void clearRPNStack();
|
499
|
+
void moveRPNRegister(size_t old_index, size_t new_index);
|
500
|
+
void moveRPNRegisterUp(size_t index);
|
501
|
+
void moveRPNRegisterDown(size_t index);
|
502
|
+
//@}
|
503
|
+
|
504
|
+
/** @name Functions for expression parsing. */
|
505
|
+
//@{
|
506
|
+
/** Returns a localized expressions. Affects decimal signs and argument separators.
|
507
|
+
*
|
508
|
+
* @param str The expression to localize.
|
509
|
+
* @returns A localized expression.
|
510
|
+
*/
|
511
|
+
std::string localizeExpression(std::string str) const;
|
512
|
+
/** Returns an unlocalized expressions. Affects decimal signs and argument separators.
|
513
|
+
*
|
514
|
+
* @param str The expression to unlocalize.
|
515
|
+
* @returns An unlocalized expression.
|
516
|
+
*/
|
517
|
+
std::string unlocalizeExpression(std::string str, const ParseOptions &po = default_parse_options) const;
|
518
|
+
/** Split an expression std::string after and before " to ".
|
519
|
+
*
|
520
|
+
* @param[out] str The expression. Will be set to the std::string before " to ".
|
521
|
+
* @param[out] to_str Will be set to the std::string after " to ".
|
522
|
+
* @param eo Options for the evaluation and parsing of the expression (nothing will be done if units are not enabled).
|
523
|
+
* @returns true if " to " was found and the expression split.
|
524
|
+
*/
|
525
|
+
bool separateToExpression(std::string &str, std::string &to_str, const EvaluationOptions &eo) const;
|
526
|
+
|
527
|
+
void parseSigns(std::string &str) const;
|
528
|
+
/** Parse an expression and place in a MathStructure object.
|
529
|
+
*
|
530
|
+
* @param str Expression
|
531
|
+
* @param po Parse options.
|
532
|
+
* @returns MathStructure with result of parse.
|
533
|
+
*/
|
534
|
+
MathStructure parse(std::string str, const ParseOptions &po = default_parse_options);
|
535
|
+
void parse(MathStructure *mstruct, std::string str, const ParseOptions &po = default_parse_options);
|
536
|
+
bool parseNumber(MathStructure *mstruct, std::string str, const ParseOptions &po = default_parse_options);
|
537
|
+
bool parseOperators(MathStructure *mstruct, std::string str, const ParseOptions &po = default_parse_options);
|
538
|
+
bool parseAdd(std::string &str, MathStructure *mstruct, const ParseOptions &po, MathOperation s);
|
539
|
+
bool parseAdd(std::string &str, MathStructure *mstruct, const ParseOptions &po);
|
540
|
+
//@}
|
541
|
+
|
542
|
+
/** @name Functions converting epxressions between units. */
|
543
|
+
//@{
|
544
|
+
/** Converts to a unit expression.
|
545
|
+
* The converted value is evaluated.
|
546
|
+
*
|
547
|
+
* @param mstruct The value to convert.
|
548
|
+
* @param composite_ Unit expression.
|
549
|
+
* @param eo Evaluation options.
|
550
|
+
* @returns Converted value.
|
551
|
+
*/
|
552
|
+
MathStructure convert(const MathStructure &mstruct, std::string composite_, const EvaluationOptions &eo = default_evaluation_options);
|
553
|
+
/** Converts to a unit.
|
554
|
+
* The converted value is evaluated.
|
555
|
+
*
|
556
|
+
* @param mstruct The value to convert.
|
557
|
+
* @param composite_ Unit to convert to.
|
558
|
+
* @param eo Evaluation options.
|
559
|
+
* @param always_convert ...
|
560
|
+
* @returns Converted value.
|
561
|
+
*/
|
562
|
+
MathStructure convert(const MathStructure &mstruct, Unit *to_unit, const EvaluationOptions &eo = default_evaluation_options, bool always_convert = true);
|
563
|
+
MathStructure convert(double value, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo = default_evaluation_options);
|
564
|
+
MathStructure convert(std::string str, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo = default_evaluation_options);
|
565
|
+
MathStructure convertToBaseUnits(const MathStructure &mstruct, const EvaluationOptions &eo = default_evaluation_options);
|
566
|
+
Unit *getBestUnit(Unit *u, bool allow_only_div = false);
|
567
|
+
MathStructure convertToBestUnit(const MathStructure &mstruct, const EvaluationOptions &eo = default_evaluation_options);
|
568
|
+
MathStructure convertToCompositeUnit(const MathStructure &mstruct, CompositeUnit *cu, const EvaluationOptions &eo = default_evaluation_options, bool always_convert = true);
|
569
|
+
//@}
|
570
|
+
|
571
|
+
/** @name Functions for default assumptions for unknown variables and symbols */
|
572
|
+
//@{
|
573
|
+
/** Set assumptions for objects without own assumptions (unknown variables and symbols).
|
574
|
+
*/
|
575
|
+
void setDefaultAssumptions(Assumptions *ass);
|
576
|
+
/** Returns the default assumptions for objects without own assumptions (unknown variables and symbols).
|
577
|
+
*/
|
578
|
+
Assumptions *defaultAssumptions();
|
579
|
+
//@}
|
580
|
+
|
581
|
+
/** @name Functions for retrieval of angle units */
|
582
|
+
//@{
|
583
|
+
/** Returns the gradians unit.
|
584
|
+
*/
|
585
|
+
Unit *getGraUnit();
|
586
|
+
/** Returns the radians unit.
|
587
|
+
*/
|
588
|
+
Unit *getRadUnit();
|
589
|
+
/** Returns the degrees unit.
|
590
|
+
*/
|
591
|
+
Unit *getDegUnit();
|
592
|
+
//@}
|
593
|
+
|
594
|
+
/** @name Functions for finding a suitable prefix. */
|
595
|
+
//@{
|
596
|
+
/** Returns a decimal prefix with exactly the provided value, that fulfils the condition prefix->exponent(exp) == exp10.
|
597
|
+
*
|
598
|
+
* @param exp10 Base-10 exponent of the requested prefix.
|
599
|
+
* @param exp The exponent of the unit.
|
600
|
+
* @returns A prefix or NULL if not found.
|
601
|
+
*/
|
602
|
+
DecimalPrefix *getExactDecimalPrefix(int exp10, int exp = 1) const;
|
603
|
+
/** Returns a binary prefix with exactly the provided value, that fulfils the condition prefix->exponent(exp) == exp2.
|
604
|
+
*
|
605
|
+
* @param exp2 Base-2 exponent of the requested prefix.
|
606
|
+
* @param exp The exponent of the unit.
|
607
|
+
* @returns A prefix or NULL if not found.
|
608
|
+
*/
|
609
|
+
BinaryPrefix *getExactBinaryPrefix(int exp2, int exp = 1) const;
|
610
|
+
/** Returns a prefix with exactly the provided value, that fulfils the condition prefix->value(exp) == o.
|
611
|
+
*
|
612
|
+
* @param o Value of the requested prefix.
|
613
|
+
* @param exp The exponent of the unit.
|
614
|
+
* @returns A prefix or NULL if not found.
|
615
|
+
*/
|
616
|
+
Prefix *getExactPrefix(const Number &o, int exp = 1) const;
|
617
|
+
/** Returns the nearest decimal prefix for a value.
|
618
|
+
*
|
619
|
+
* @param exp10 Base-10 exponent of the value.
|
620
|
+
* @param exp The exponent of the unit.
|
621
|
+
* @returns A prefix or NULL if no decimal prefix is available.
|
622
|
+
*/
|
623
|
+
DecimalPrefix *getNearestDecimalPrefix(int exp10, int exp = 1) const;
|
624
|
+
/** Returns the best suited decimal prefix for a value.
|
625
|
+
*
|
626
|
+
* @param exp10 Base-10 exponent of the value.
|
627
|
+
* @param exp The exponent of the unit.
|
628
|
+
* @param all_prefixes If false, prefixes which is not a multiple of thousand (centi, deci, deka, hekto) will be skipped.
|
629
|
+
* @returns A prefix or NULL if the unit should be left without prefix.
|
630
|
+
*/
|
631
|
+
DecimalPrefix *getBestDecimalPrefix(int exp10, int exp = 1, bool all_prefixes = true) const;
|
632
|
+
/** Returns the best suited decimal prefix for a value.
|
633
|
+
*
|
634
|
+
* @param exp10 Base-10 exponent of the value.
|
635
|
+
* @param exp The exponent of the unit.
|
636
|
+
* @param all_prefixes If false, prefixes which is not a multiple of thousand (centi, deci, deka, hekto) will be skipped.
|
637
|
+
* @returns A prefix or NULL if the unit should be left without prefix.
|
638
|
+
*/
|
639
|
+
DecimalPrefix *getBestDecimalPrefix(const Number &exp10, const Number &exp, bool all_prefixes = true) const;
|
640
|
+
/** Returns the nearest binary prefix for a value.
|
641
|
+
*
|
642
|
+
* @param exp10 Base-2 exponent of the value.
|
643
|
+
* @param exp The exponent of the unit.
|
644
|
+
* @returns A prefix or NULL if no binary prefix is available.
|
645
|
+
*/
|
646
|
+
BinaryPrefix *getNearestBinaryPrefix(int exp2, int exp = 1) const;
|
647
|
+
/** Returns the best suited binary prefix for a value.
|
648
|
+
*
|
649
|
+
* @param exp10 Base-2 exponent of the value.
|
650
|
+
* @param exp The exponent of the unit.
|
651
|
+
* @returns A prefix or NULL if the unit should be left without prefix.
|
652
|
+
*/
|
653
|
+
BinaryPrefix *getBestBinaryPrefix(int exp2, int exp = 1) const;
|
654
|
+
/** Returns the best suited binary prefix for a value.
|
655
|
+
*
|
656
|
+
* @param exp10 Base-2 exponent of the value.
|
657
|
+
* @param exp The exponent of the unit.
|
658
|
+
* @returns A prefix or NULL if the unit should be left without prefix.
|
659
|
+
*/
|
660
|
+
BinaryPrefix *getBestBinaryPrefix(const Number &exp2, const Number &exp) const;
|
661
|
+
/** Add a new prefix to the calculator. */
|
662
|
+
Prefix *addPrefix(Prefix *p);
|
663
|
+
/** Used internally. */
|
664
|
+
void prefixNameChanged(Prefix *p, bool new_item = false);
|
665
|
+
//@}
|
666
|
+
|
667
|
+
/** @name Functions for managing functions, variables, units, prefixes and data sets. */
|
668
|
+
//@{
|
669
|
+
void expressionItemActivated(ExpressionItem *item);
|
670
|
+
void expressionItemDeactivated(ExpressionItem *item);
|
671
|
+
void expressionItemDeleted(ExpressionItem *item);
|
672
|
+
void nameChanged(ExpressionItem *item, bool new_item = false);
|
673
|
+
void deleteName(std::string name_, ExpressionItem *object = NULL);
|
674
|
+
void deleteUnitName(std::string name_, Unit *object = NULL);
|
675
|
+
Unit* addUnit(Unit *u, bool force = true, bool check_names = true);
|
676
|
+
void delPrefixUFV(Prefix *object);
|
677
|
+
void delUFV(ExpressionItem *object);
|
678
|
+
/** Checks if a variable exists/is registered in the calculator. */
|
679
|
+
bool hasVariable(Variable *v);
|
680
|
+
/** Checks if a unit exists/is registered in the calculator. */
|
681
|
+
bool hasUnit(Unit *u);
|
682
|
+
/** Checks if a function exists/is registered in the calculator. */
|
683
|
+
bool hasFunction(MathFunction *f);
|
684
|
+
/** Checks if a pointer points to a variable that still exists in the calculator.
|
685
|
+
* As opposed to hasFunction(), this function only checks if the mathematical function has been deleted.
|
686
|
+
*/
|
687
|
+
bool stillHasVariable(Variable *v);
|
688
|
+
/** Checks if a pointer points to a unit that still exists in the calculator.
|
689
|
+
* As opposed to hasUnit(), this function only checks if the unit has been deleted.
|
690
|
+
*/
|
691
|
+
bool stillHasUnit(Unit *u);
|
692
|
+
/** Checks if a pointer points to a mathematical function that still exists in the calculator.
|
693
|
+
* As opposed to hasFunction(), this function only checks if the mathematical function has been deleted.
|
694
|
+
*/
|
695
|
+
bool stillHasFunction(MathFunction *f);
|
696
|
+
void saveFunctionCalled();
|
697
|
+
bool checkSaveFunctionCalled();
|
698
|
+
ExpressionItem *getActiveExpressionItem(std::string name, ExpressionItem *item = NULL);
|
699
|
+
ExpressionItem *getInactiveExpressionItem(std::string name, ExpressionItem *item = NULL);
|
700
|
+
ExpressionItem *getActiveExpressionItem(ExpressionItem *item);
|
701
|
+
ExpressionItem *getExpressionItem(std::string name, ExpressionItem *item = NULL);
|
702
|
+
Unit* getUnit(std::string name_);
|
703
|
+
Unit* getActiveUnit(std::string name_);
|
704
|
+
Unit* getCompositeUnit(std::string internal_name_);
|
705
|
+
/** Returns prefix for an index (starting at zero). All prefixes can be traversed by starting at index zero and increasing the index until NULL is returned.
|
706
|
+
*
|
707
|
+
* @param index Index of prefix.
|
708
|
+
* @returns Prefix for index or NULL if not found.
|
709
|
+
*/
|
710
|
+
Prefix *getPrefix(size_t index) const;
|
711
|
+
/** Returns prefix with provided name.
|
712
|
+
*
|
713
|
+
* @param name_ Name of prefix to retrieve.
|
714
|
+
* @returns Prefix with provided name or NULL if not found.
|
715
|
+
*/
|
716
|
+
Prefix *getPrefix(std::string name_) const;
|
717
|
+
Variable* addVariable(Variable *v, bool force = true, bool check_names = true);
|
718
|
+
void variableNameChanged(Variable *v, bool new_item = false);
|
719
|
+
void functionNameChanged(MathFunction *f, bool new_item = false);
|
720
|
+
void unitNameChanged(Unit *u, bool new_item = false);
|
721
|
+
Variable* getVariable(std::string name_);
|
722
|
+
Variable* getActiveVariable(std::string name_);
|
723
|
+
ExpressionItem *addExpressionItem(ExpressionItem *item, bool force = true);
|
724
|
+
MathFunction* addFunction(MathFunction *f, bool force = true, bool check_names = true);
|
725
|
+
DataSet* addDataSet(DataSet *dc, bool force = true, bool check_names = true);
|
726
|
+
DataSet* getDataSet(size_t index);
|
727
|
+
DataSet* getDataSet(std::string name);
|
728
|
+
MathFunction* getFunction(std::string name_);
|
729
|
+
MathFunction* getActiveFunction(std::string name_);
|
730
|
+
/** Returns variable for an index (starting at zero). All variables can be traversed by starting at index zero and increasing the index until NULL is returned.
|
731
|
+
*
|
732
|
+
* @param index Index of variable.
|
733
|
+
* @returns Variable for index or NULL if not found.
|
734
|
+
*/
|
735
|
+
Variable *getVariable(size_t index) const;
|
736
|
+
/** Returns unit for an index (starting at zero). All units can be traversed by starting at index zero and increasing the index until NULL is returned.
|
737
|
+
*
|
738
|
+
* @param index Index of unit.
|
739
|
+
* @returns Unit for index or NULL if not found.
|
740
|
+
*/
|
741
|
+
Unit *getUnit(size_t index) const;
|
742
|
+
/** Returns function for an index (starting at zero). All functions can be traversed by starting at index zero and increasing the index until NULL is returned.
|
743
|
+
*
|
744
|
+
* @param index Index of function.
|
745
|
+
* @returns Function for index or NULL if not found.
|
746
|
+
*/
|
747
|
+
MathFunction *getFunction(size_t index) const;
|
748
|
+
bool unitIsUsedByOtherUnits(const Unit *u) const;
|
749
|
+
//@}
|
750
|
+
|
751
|
+
/** @name Functions for handling of builtin expression items */
|
752
|
+
//@{
|
753
|
+
/** Unloads all non-builtin variables. */
|
754
|
+
void resetVariables();
|
755
|
+
/** Unloads all non-builtin functions. */
|
756
|
+
void resetFunctions();
|
757
|
+
/** Unloads all non-builtin units. */
|
758
|
+
void resetUnits();
|
759
|
+
/** Unloads all non-builtin variables, functions and units. */
|
760
|
+
void reset();
|
761
|
+
/** Adds builtin variables. Called automatically when the calculator is created. */
|
762
|
+
void addBuiltinVariables();
|
763
|
+
/** Adds builtin functions. Called automatically when the calculator is created. */
|
764
|
+
void addBuiltinFunctions();
|
765
|
+
/** Adds builtin units. Called automatically when the calculator is created. */
|
766
|
+
void addBuiltinUnits();
|
767
|
+
//@}
|
768
|
+
|
769
|
+
/** @name Functions for testing validity of functions, variable and unit names. */
|
770
|
+
//@{
|
771
|
+
/** Tests if a name is valid for a variable.
|
772
|
+
*
|
773
|
+
* @param name_ Variable name.
|
774
|
+
* @returns true if the name is valid for a variable.
|
775
|
+
*/
|
776
|
+
bool variableNameIsValid(const std::string &name_);
|
777
|
+
/** Tests if a name is valid for a variable.
|
778
|
+
*
|
779
|
+
* @param name_ Variable name.
|
780
|
+
* @returns true if the name is valid for a variable.
|
781
|
+
*/
|
782
|
+
bool variableNameIsValid(const char *name_);
|
783
|
+
bool variableNameIsValid(const char *name_, int version_numbers[3], bool is_user_defs);
|
784
|
+
bool variableNameIsValid(const std::string &name_, int version_numbers[3], bool is_user_defs);
|
785
|
+
std::string convertToValidVariableName(std::string name_);
|
786
|
+
bool functionNameIsValid(const std::string &name_);
|
787
|
+
bool functionNameIsValid(const char *name_);
|
788
|
+
bool functionNameIsValid(const char *name_, int version_numbers[3], bool is_user_defs);
|
789
|
+
bool functionNameIsValid(const std::string &name_, int version_numbers[3], bool is_user_defs);
|
790
|
+
std::string convertToValidFunctionName(std::string name_);
|
791
|
+
bool unitNameIsValid(const std::string &name_);
|
792
|
+
bool unitNameIsValid(const char *name_);
|
793
|
+
bool unitNameIsValid(const char *name_, int version_numbers[3], bool is_user_defs);
|
794
|
+
bool unitNameIsValid(const std::string &name_, int version_numbers[3], bool is_user_defs);
|
795
|
+
bool utf8_pos_is_valid_in_name(char *pos);
|
796
|
+
std::string convertToValidUnitName(std::string name_);
|
797
|
+
/** Checks if a name is used by another object which is not allowed to have the same name.
|
798
|
+
*
|
799
|
+
* @param name Name.
|
800
|
+
* @param object Object to exclude from check.
|
801
|
+
* @returns true if the name is used.
|
802
|
+
*/
|
803
|
+
bool nameTaken(std::string name, ExpressionItem *object = NULL);
|
804
|
+
bool variableNameTaken(std::string name, Variable *object = NULL);
|
805
|
+
bool unitNameTaken(std::string name, Unit *object = NULL);
|
806
|
+
bool functionNameTaken(std::string name, MathFunction *object = NULL);
|
807
|
+
std::string getName(std::string name = "", ExpressionItem *object = NULL, bool force = false, bool always_append = false);
|
808
|
+
//@}
|
809
|
+
|
810
|
+
/** @name Functions for message handling. */
|
811
|
+
//@{
|
812
|
+
void error(bool critical, const char *TEMPLATE,...);
|
813
|
+
/** Put a message in the message queue.
|
814
|
+
*/
|
815
|
+
void message(MessageType mtype, const char *TEMPLATE,...);
|
816
|
+
/** Returns the first message in queue.
|
817
|
+
*/
|
818
|
+
CalculatorMessage *message();
|
819
|
+
/** Removes the first message in queue and returns the next.
|
820
|
+
*/
|
821
|
+
CalculatorMessage *nextMessage();
|
822
|
+
bool showArgumentErrors() const;
|
823
|
+
void beginTemporaryStopMessages();
|
824
|
+
int endTemporaryStopMessages(int *message_count = NULL, int *warning_count = NULL);
|
825
|
+
//@}
|
826
|
+
|
827
|
+
/** @name Functions for loading and saving definitions (variables, functions, units, etc.). */
|
828
|
+
//@{
|
829
|
+
/** Load all standard global (system wide) definitions from the global data directory ($PREFIX/share/qalculate).
|
830
|
+
*
|
831
|
+
* @returns true if the definitions were successfully loaded.
|
832
|
+
*/
|
833
|
+
bool loadGlobalDefinitions();
|
834
|
+
/** Load global (system wide) definitions from a file in the global data directory ($PREFIX/share/qalculate).
|
835
|
+
*
|
836
|
+
* @param filename Name of the file in the global data directory.
|
837
|
+
* @returns true if the definitions were successfully loaded.
|
838
|
+
*/
|
839
|
+
bool loadGlobalDefinitions(std::string filename);
|
840
|
+
/** Load prefixes.
|
841
|
+
*
|
842
|
+
* @returns true if the definitions were successfully loaded.
|
843
|
+
*/
|
844
|
+
bool loadGlobalPrefixes();
|
845
|
+
/** Load currencies.
|
846
|
+
*
|
847
|
+
* @returns true if the definitions were successfully loaded.
|
848
|
+
*/
|
849
|
+
bool loadGlobalCurrencies();
|
850
|
+
/** Load units.
|
851
|
+
*
|
852
|
+
* @returns true if the definitions were successfully loaded.
|
853
|
+
*/
|
854
|
+
bool loadGlobalUnits();
|
855
|
+
/** Load variables.
|
856
|
+
*
|
857
|
+
* @returns true if the definitions were successfully loaded.
|
858
|
+
*/
|
859
|
+
bool loadGlobalVariables();
|
860
|
+
/** Load functions.
|
861
|
+
*
|
862
|
+
* @returns true if the definitions were successfully loaded.
|
863
|
+
*/
|
864
|
+
bool loadGlobalFunctions();
|
865
|
+
/** Load data sets.
|
866
|
+
*
|
867
|
+
* @returns true if the definitions were successfully loaded.
|
868
|
+
*/
|
869
|
+
bool loadGlobalDataSets();
|
870
|
+
/** Load local, user specific, definitions from the local definitions directory (~/.qalculate/definitions).
|
871
|
+
* All files in the directory and in the datasets subdirectory are loaded.
|
872
|
+
*
|
873
|
+
* @returns true if the definitions were successfully loaded.
|
874
|
+
*/
|
875
|
+
bool loadLocalDefinitions();
|
876
|
+
/** Load definitions from a file.
|
877
|
+
*
|
878
|
+
* @param file_name The path to the file to load.
|
879
|
+
* @param is_user_defs true if the definitions are local, false if they are global.
|
880
|
+
* @returns true if the definitions were successfully loaded.
|
881
|
+
*/
|
882
|
+
int loadDefinitions(const char *file_name, bool is_user_defs = true);
|
883
|
+
/** Save local definitions to ~/.qalculate/definitions/
|
884
|
+
*
|
885
|
+
* @returns true if definitions was successfully saved.
|
886
|
+
*/
|
887
|
+
bool saveDefinitions();
|
888
|
+
int saveDataObjects();
|
889
|
+
int savePrefixes(const char *file_name, bool save_global = false);
|
890
|
+
int saveVariables(const char *file_name, bool save_global = false);
|
891
|
+
int saveUnits(const char *file_name, bool save_global = false);
|
892
|
+
int saveFunctions(const char *file_name, bool save_global = false);
|
893
|
+
int saveDataSets(const char *file_name, bool save_global = false);
|
894
|
+
//@}
|
895
|
+
|
896
|
+
/** @name Functions for CSV file import/export. */
|
897
|
+
//@{
|
898
|
+
bool importCSV(MathStructure &mstruct, const char *file_name, int first_row = 1, std::string delimiter = ",", std::vector<std::string> *headers = NULL);
|
899
|
+
bool importCSV(const char *file_name, int first_row = 1, bool headers = true, std::string delimiter = ",", bool to_matrix = false, std::string name = "", std::string title = "", std::string category = "");
|
900
|
+
bool exportCSV(const MathStructure &mstruct, const char *file_name, std::string delimiter = ",");
|
901
|
+
//@}
|
902
|
+
|
903
|
+
/** @name Functions for exchange rates. */
|
904
|
+
//@{
|
905
|
+
/** Checks if gnomevfs-copy or wget is available for downloading exchange rates from the Internet.
|
906
|
+
*
|
907
|
+
* @returns true if gnomevfs-copy or wget was found.
|
908
|
+
*/
|
909
|
+
bool canFetch();
|
910
|
+
/** Checks if gnomevfs-copy available.
|
911
|
+
*
|
912
|
+
* @returns true if gnomevfs-copy was found.
|
913
|
+
*/
|
914
|
+
bool hasGnomeVFS();
|
915
|
+
/** Load saved (local) currency units and exchange rates.
|
916
|
+
*
|
917
|
+
* @returns true if operation successful.
|
918
|
+
*/
|
919
|
+
bool loadExchangeRates();
|
920
|
+
/** Name of the exchange rates file on local disc.
|
921
|
+
*
|
922
|
+
* @returns name of local exchange rates file.
|
923
|
+
*/
|
924
|
+
std::string getExchangeRatesFileName();
|
925
|
+
/** Url of the exchange rates file on the Internet.
|
926
|
+
*
|
927
|
+
* @returns Url of exchange rates file.
|
928
|
+
*/
|
929
|
+
std::string getExchangeRatesUrl();
|
930
|
+
/** Download current exchange rates from the Internet to local disc.
|
931
|
+
*
|
932
|
+
* @param timeout Timeout for donwload try (only used by wget)
|
933
|
+
* @param wget_args Extra arguments to pass to wget.
|
934
|
+
* @returns true if operation was successful.
|
935
|
+
*/
|
936
|
+
bool fetchExchangeRates(int timeout, std::string wget_args);
|
937
|
+
/** Download current exchange rates from the Internet to local disc with default wget arguments.
|
938
|
+
*
|
939
|
+
* @param timeout Timeout for donwload try (only used by wget)
|
940
|
+
* @returns true if operation was successful.
|
941
|
+
*/
|
942
|
+
bool fetchExchangeRates(int timeout = 15);
|
943
|
+
/** Returns true if the exchange rates on local disc is older than one week. */
|
944
|
+
bool checkExchangeRatesDate();
|
945
|
+
//@}
|
946
|
+
|
947
|
+
/** @name Functions for plotting */
|
948
|
+
//@{
|
949
|
+
/** Checks if gnuplot is available.
|
950
|
+
*
|
951
|
+
* @returns true if gnuplot was found.
|
952
|
+
*/
|
953
|
+
bool canPlot();
|
954
|
+
MathStructure expressionToPlotVector(std::string expression, const MathStructure &min, const MathStructure &max, int steps, MathStructure *x_vector = NULL, std::string x_var = "\\x", const ParseOptions &po = default_parse_options);
|
955
|
+
MathStructure expressionToPlotVector(std::string expression, float min, float max, int steps, MathStructure *x_vector = NULL, std::string x_var = "\\x", const ParseOptions &po = default_parse_options);
|
956
|
+
MathStructure expressionToPlotVector(std::string expression, const MathStructure &min, const MathStructure &max, const MathStructure &step, MathStructure *x_vector = NULL, std::string x_var = "\\x", const ParseOptions &po = default_parse_options);
|
957
|
+
MathStructure expressionToPlotVector(std::string expression, float min, float max, float step, MathStructure *x_vector = NULL, std::string x_var = "\\x", const ParseOptions &po = default_parse_options);
|
958
|
+
MathStructure expressionToPlotVector(std::string expression, const MathStructure &x_vector, std::string x_var = "\\x", const ParseOptions &po = default_parse_options);
|
959
|
+
bool plotVectors(PlotParameters *param, const std::vector<MathStructure> &y_vectors, const vector<MathStructure> &x_vectors, vector<PlotDataParameters*> &pdps, bool persistent = false);
|
960
|
+
bool invokeGnuplot(std::string commands, std::string commandline_extra = "", bool persistent = false);
|
961
|
+
bool closeGnuplot();
|
962
|
+
bool gnuplotOpen();
|
963
|
+
//@}
|
964
|
+
|
965
|
+
/** @name Functions for global precision */
|
966
|
+
//@{
|
967
|
+
/** Set default precision for approximate calculations.
|
968
|
+
*
|
969
|
+
* @param precision Precision.
|
970
|
+
*/
|
971
|
+
void setPrecision(int precision = DEFAULT_PRECISION);
|
972
|
+
/** Returns default precision for approximate calculations.
|
973
|
+
*/
|
974
|
+
int getPrecision() const;
|
975
|
+
//@}
|
976
|
+
|
977
|
+
/** @name Functions for localization */
|
978
|
+
//@{
|
979
|
+
/** Returns the preferred decimal point character.
|
980
|
+
*/
|
981
|
+
const std::string &getDecimalPoint() const;
|
982
|
+
/** Returns the preferred comma character for separating arguments.*/
|
983
|
+
const std::string &getComma() const;
|
984
|
+
/** Sets argument separator and decimal sign from the current locale. Mainly for internal use. */
|
985
|
+
void setLocale();
|
986
|
+
void useDecimalComma();
|
987
|
+
void useDecimalPoint();
|
988
|
+
/** Resets argument separator and decimal sign. Mainly for internal use. */
|
989
|
+
void unsetLocale();
|
990
|
+
/** Returns the translated text std::string used in expressions for converting to a specific unit expression (ex "5 meters to feet.*/
|
991
|
+
std::string localToString() const;
|
992
|
+
//@}
|
993
|
+
|
994
|
+
/** @name Functions adding alternative symbols for operators and such */
|
995
|
+
//@{
|
996
|
+
void addStringAlternative(std::string replacement, std::string standard);
|
997
|
+
bool delStringAlternative(std::string replacement, std::string standard);
|
998
|
+
void addDefaultStringAlternative(std::string replacement, std::string standard);
|
999
|
+
bool delDefaultStringAlternative(std::string replacement, std::string standard);
|
1000
|
+
//@}
|
1001
|
+
|
1002
|
+
/** @name Functions for storing values with associated identifiers */
|
1003
|
+
//@{
|
1004
|
+
/** Stores a value with an associated id. Mainly for internal use.
|
1005
|
+
*
|
1006
|
+
* @param mstruct The value to store.
|
1007
|
+
* @param persistent If false the values will be removed from storage when retrieved with getId().
|
1008
|
+
* @returns Storage id.
|
1009
|
+
*/
|
1010
|
+
size_t addId(MathStructure *mstruct, bool persistent = false);
|
1011
|
+
/** Stores a function value with arguments parsed from a text std::string using Function::parse(), with an associated id. Mainly for internal use.
|
1012
|
+
*
|
1013
|
+
* @param f Mathematical function.
|
1014
|
+
* @param str Arguments.
|
1015
|
+
* @param po Parse options.
|
1016
|
+
* @param persistent If false the values will be removed from storage when retrieved with getId().
|
1017
|
+
* @returns Storage id.
|
1018
|
+
*/
|
1019
|
+
size_t parseAddId(MathFunction *f, const std::string &str, const ParseOptions &po, bool persistent = false);
|
1020
|
+
size_t parseAddIdAppend(MathFunction *f, const MathStructure &append_mstruct, const std::string &str, const ParseOptions &po, bool persistent = false);
|
1021
|
+
size_t parseAddVectorId(const std::string &str, const ParseOptions &po, bool persistent = false);
|
1022
|
+
/** Returns a stored value. Mainly for internal use.
|
1023
|
+
*
|
1024
|
+
* @param id Storage id.
|
1025
|
+
* @returns A stored value.
|
1026
|
+
*/
|
1027
|
+
MathStructure *getId(size_t id);
|
1028
|
+
/** Removes and unreferences (value->unref() will be called) a value from storage. Mainly for internal use.
|
1029
|
+
*
|
1030
|
+
* @param id Storage id.
|
1031
|
+
*/
|
1032
|
+
void delId(size_t id);
|
1033
|
+
//@}
|
1034
|
+
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
#endif
|