Commit Graph

17919 Commits

Author SHA1 Message Date
Geert Janssens
7c041eb283 Fix gnc-numeric locale test on travis
- Change locale from de_DE to fr_FR.utf8
- Expect correct thousands separator

This also partly undoes the previous commit (it removes the
test for gcc 5 or more)
2017-02-21 16:49:48 +01:00
John Ralls
75e6a41bd7 Prevent localizing the decimal point in gcc<5.
Apparently gcc V4.8 provides a defective implementation of
std::locale which first doesn't support std::numpunct and second
throws the wrong exception type.

Unfortunately boost::locale isn't a solution because it uses the
gcc facets.

So for now, we don't compile that bit if gcc is too old.
2017-02-20 16:51:06 -08:00
John Ralls
cbe52dad34 Merge fetaure-branch 'numeric', provides GncNumeric C++ API. 2017-02-20 16:05:30 -08:00
John Ralls
e322457e45 Fix Geert’s code review comments.
Except the big one about string IO not being flexible enough.
2017-02-20 15:50:32 -08:00
John Ralls
a193b9a2c1 Fix documentation errors. 2017-02-20 15:50:32 -08:00
John Ralls
0b09b58cf6 Relax comparison test for GncRational::round_to_numeric
To allow for a difference of 1 on very large numbers (>1e16). At the
same time made the test harder with a wider range, skipping cases where
the result overflows. Use GncRational::valid() instead of testing
components for both overflow and NaN.
2017-02-20 15:50:32 -08:00
John Ralls
d0726de391 Replace std::regex with boost::regex.
Gcc's std::regex compiler doesn't correctly recognize capture blocks.
2017-02-20 15:50:32 -08:00
John Ralls
b60d6a8466 Add libgnc-qof to dependencies for test-numeric. 2017-02-20 15:50:32 -08:00
John Ralls
bff0e745fc Fix indentation error. 2017-02-20 15:50:32 -08:00
John Ralls
6220b85045 Remove a commented-out diagnostic. 2017-02-20 15:50:32 -08:00
John Ralls
ea44b16f54 Make the GncRational and GncNumeric APIs mostly identical.
Leaving string conversion and stream operators out of GncRational.
2017-02-20 15:50:32 -08:00
John Ralls
739c91a4cc Change GncRational::round to GncRational::convert.
With the same signature as the GncNumeric version.
2017-02-20 15:50:32 -08:00
John Ralls
e506f9a4a1 Make the rounding functions templates and move them to their own header. 2017-02-20 15:50:31 -08:00
John Ralls
0403a6667a Replace GncInt128’s flags variable with bit-stuffing in the high leg.
Loses three bits so GncInt128 becomes really a GncInt125, but we don’t
really need the single order-of-magnitude: 10**38 is big enough. Saves
a full word of memory for each GncInt128, which means 2 words for GncRational.
That’s a 33% saving in memory for 64-bit and makes the object size the
same (32 bytes) for all architectures.
2017-02-20 15:50:31 -08:00
John Ralls
c633e80a24 Convert GncRational to throw instead of using a status byte.
More consistent with GncNumeric and saves a word of memory per instance.
Still bleeping huge because the two GncInt128s each need 128 bits (2 or 4 words)
plus a word for status (for 3 bits!).
Also provide a couple of convenience functions, is_big() and valid() to
test if the either numerator and denominator is big or overflowed or NaN.
2017-02-20 15:50:31 -08:00
John Ralls
ff7e6a37d5 Reimplement gnc_numeric in terms of GncNumeric instead of GncRational.
Except when how has DenomType::exact; that triggers direct use of GncRational
and direct rounding to the specified denominator.
2017-02-20 15:50:31 -08:00
John Ralls
c3d22c429f Add GncRational test for GncRational::round_to_numeric().
Needed GncNumeric to be defined.
2017-02-20 15:50:31 -08:00
John Ralls
4a46ae3ddf Fix GncInt128 tests for older compilers. 2017-02-20 15:50:31 -08:00
John Ralls
a54edf1a5e Add GncRational(GncNumeric) constructor. 2017-02-20 15:50:31 -08:00
John Ralls
82fe06e390 Extract new class GncNumeric.
Similar to GncRational, except that it’s based on int64_t instead of
GncInt128 and throws instead of using a status byte.

Most calculations are performed using GncRational, the result is then
rounded (RoundType::half_down) to fit. GncRational should be used in
circumstances where the automatic rounding is undesirable.
2017-02-20 15:50:31 -08:00
John Ralls
4fef04c17b Remove #ifdef __cplusplus from gnu-numeric.cpp
It’s always compiled with C++.
2017-02-20 15:50:31 -08:00
John Ralls
570c8a8d60 Fix GncInt128 shift operators when shift amount will clear a leg. 2017-02-20 15:50:31 -08:00
John Ralls
4a134ae0b1 Declare GncInt128::div() const
Because it doesn’t change the value of *this, it returns the results in
the return value args.
2017-02-20 15:50:31 -08:00
John Ralls
06d22718f5 Fix minor typos and whitespace issues. 2017-02-20 15:50:30 -08:00
John Ralls
3975b0b465 Change signature of GncRational::round from taking a GncDenominator…
to a separate denominator and RoundType.
2017-02-20 15:50:30 -08:00
John Ralls
6f5d628b12 Move test-numeric from src/engine to src/libqof/qof.
It’s testing a file in qof and doesn’t need to be in engine just because
it uses some functions from test-engine-stuff.
2017-02-20 15:50:30 -08:00
John Ralls
b0dfd96a93 Add GncRational::reduce() and GncRational::round_to_numeric(). 2017-02-20 15:50:30 -08:00
John Ralls
340fb9761c Fix inverted subtraction. 2017-02-20 15:50:30 -08:00
John Ralls
a88d21245e Add guard macro to gnu-rational.hpp. 2017-02-20 15:50:30 -08:00
John Ralls
e1b280b36b Untabify gnu-numeric.cpp. 2017-02-20 15:50:30 -08:00
John Ralls
b1995932fc Remove unused gnc_numeric_foo_with_error functions. 2017-02-20 15:50:30 -08:00
John Ralls
a852dfb4ef Implement basic arithmetic operators for GncRational.
The operators do no rounding or reducing yet.
2017-02-20 15:50:30 -08:00
John Ralls
d9aa5e1ad5 Reorder test parameters so that the expected value is first. 2017-02-20 15:50:30 -08:00
John Ralls
b5f06ab6dc Add an error parameter on the GncInt128 constructor. 2017-02-20 15:50:30 -08:00
John Ralls
43fbb338af Add GTest test program for GncRational.
Starting off with the constructors.
2017-02-20 15:50:29 -08:00
John Ralls
848f77dacf Add explicit and correct default GncRational constructor.
As suggested by Geert Janssens.
2017-02-20 15:50:29 -08:00
John Ralls
b30a547d18 Add ICU libraries on which Boost:locale is dependent to CSV-Import LINK_LIBRARIES. 2017-02-20 15:50:14 -08:00
Geert Janssens
2c5f6b9cc3 Merge branch 'csv_imp_cpp'
This feature branch is about the c++ conversion of the
csv transaction importer.
2017-02-20 20:42:21 +01:00
Geert Janssens
1d552fbe7f Use boost::locale:conv:utf_to_uft instead of codecvt_utf8
The latter is not available until gcc 5.x and we still depend on
gcc 4.8 on some platforms (RHEL/Centos, Travis/Ubuntu 14.04, Windows).
2017-02-20 20:23:20 +01:00
Geert Janssens
558d4b43b2 Properly test for invalid dates (gnc-date C interface no longer throws - rightfully so) 2017-02-20 18:05:05 +01:00
Geert Janssens
cd66fb2e2d Some ui refinement
- Adjust description on the assistant's start page to match current behavior
- Hide separator buttons in case the file format is set to fixed width
- For fixed width display some instructions on how to manipulate columns
- Move the error messages to below the preview table
2017-02-20 18:05:03 +01:00
Geert Janssens
a295680212 Cleanup - use less ambiguous variable name for an iterator 2017-02-20 18:04:59 +01:00
Geert Janssens
372c46cc0f Fix base account reset when an account column is selected
This got broken somehow while refactoring the assistant.
2017-02-20 18:04:57 +01:00
Geert Janssens
61244301f2 Recover separators or column_widths when juggling file format more than once 2017-02-20 18:04:54 +01:00
Geert Janssens
5d96e47b39 Prevent multi-byte characters from erroneously being split in fixed-width mode
This happens because in case std::string is the base type for the tokenizer
the offsets are interpreted as byte offsets although some characters
may consist of more that one byte in utf-8. This is not so for std::wstring
so to solve this issue the fixed width tokenizer is changed to use
wide character strings internally.
2017-02-20 18:04:52 +01:00
Geert Janssens
8d03abac19 Include glib.h as everywhere else 2017-02-20 18:04:49 +01:00
Geert Janssens
6657e6660b Remove some obsolete comments and commented out code 2017-02-20 18:04:46 +01:00
Geert Janssens
4687eb649b Trim newlines from csv data
If the newline happens in the middle some field, replace it with a space.
We can't import newlines in gnucash.
2017-02-20 18:04:44 +01:00
Geert Janssens
9fbbd7366c Fix crash when adding columns by double-clicking the preview data
Each column change would cause the code to completely delete the
existing columns and then add new ones from scratch. For some
reason his upsets the MOVE_NOTIFY event, which is triggered
whenever you move the mouse pointer around. I suspect it internally
keeps a link to the last hovered column to check if the move action
moves the mouse to a different column. As the code removed the columns
this internal references becomes invalid.

I have worked around this by no longer completely recreating the
columns. Instead columns are added or removed as needed to follow
the changes in the data model.

At the same time the refresh function has been split into several
smaller ones.
2017-02-20 18:04:38 +01:00
Geert Janssens
449db62921 Fix settings loading and saving
- fixed width columns widths weren't saved
- column types were lost when loading a fixed width preset
2017-02-20 18:04:35 +01:00