Il 07/12/19 23:30, Paavo Helde ha scritto:
> On 7.12.2019 22:06, Soviet_Mario wrote:
>> I fork here because this doubt about template is different
>> from the enum
>> thread
>>
>> I don't know how to code this situation, so I try to write
>> broken
>> pseudocode that does not compile, hoping to be able to
>> explain better
>> than with plain words ....
>>
>> I have this situation
>>
>>
>> 'tt' will be either double or FixedString (a fast wasty
>> string class for
>> strings up to a maximum size which inside has an
>> "embedded" fixed array
>> and an used field for shorter strings to be copied for the
>> exact extent,
>> they are asciiZ '\0' terminated for support of std functions)
>
> So, reinventing std::string. Why?
no it's not : all stuff static or automatic, no malloc, no
new operator, no throw and so. At the cost of waste of space
(and negligible limitation due to natural fields size).
>
>>
>>
>> template <typename tt> class Table
>> {
>> tt Dati [constMaxRighe] [constMaxColonne];
>>
>> template <typename xx> Table <xx> ExtractSubTable \
>> (int * SelectedRowList, int * SelectedColumnList, \
>> int numRows, int numCols);
>
> What's this obsession with backslashes and line
> continuation? It's not needed beyond macro definitions.
how in the NG is to be reported line continuation ?
Underscore ?
>
>
>> }
>>
>> now assume that ExtractSubTable must exist in 4
>> specializations
>>
>> from Table <double> to Table <double>
>> from Table <double> to Table <FixedString>
>> from Table <FixedString> to Table <double>
>> from Table <FixedString> to Table <FixedString>
>
> So, every FixedString will be convertible to double?
all "selected" columns contain convertible data potentially
converted (all or part).
All other columns contain textual data to never be converted
(nor extracted).
If sth goes wrong it is not a design error but a user error,
trapped as such and suggesting to correct the selection.
> What
> happens if it is an empty string or "abc"?
throws an exception. In a grid some columns are processable
for calculations, others are Date-time, name, surname,
class/section and so. Only properly selected columns are
extracted back and forth.
> If it is
> restricted to be numeric why don't you hold everything in
> double ?
to have allow for an homogeneous complete table (a single
matrix of data) holding also textual data.
The "work" temporaries are actually of the Table <double>
kind, for calculations. But later are reinserted back in
initial positions.
Otherwise a table could be "order" dependent, which I don't
like. Numeric data can be placed in whichever order amongst
textual data (on a column basis).
Plus some replicated header rows (one per each class, I mean
a school class here not the C++ keywords).
I would not want a "variant-like" cell, with a further field
holding its type .... but this is not completely excluded
though. With a union it could be done limiting the waste.
To start with I have chosen to have either FixedStrings or
double cells.
The selection is done intersecating a list of active columns
and same-class rows. All selected columns are expected to
hold numeric data.
The Table <double> is generated from extraction, then
calculations. Than back-exported in textual complete table
for logging as text file report.
Again, I am translating an existing program in Gambas, but
with no particular restraints : the two are not expected to
exchange data. I am simply trying to port all from scratch
to C++.
Well, I could maintain a skeleton of Gambas just as a
wrapper to prepare some files and to set options to pass to
C++ program, as a script file, not a very tight interaction.
>
>> assume also I would declare and define the body outside
>> the class
>> header (it will be big)
>
> No, it will not be big, It will be two lines:
>
> 1. Extract subtable of the same type (one function call)
> 2. Convert it into the needed type (second function call).
>
> This is called modular design. The functions implementing
> those two lines might be larger, but the result will be less
> complex than your design which attempts to do two things at
> once.
>
> When you have got this working and the customer is not
no there is not any customer. I am just trying to
"translate" a facility for personal use to C++, but not for
performance reason. The SW has grown to a size I have
difficulty maintaining in gambas. Always the same problem.
C++ forces me to be more tidy, when I manage to understand
well the synthax at least.
> satisfied with the performance, then you might need to look
> into ways how to improve it. Note that it is not given that
> the your solution to do two things at once in a function is
> the best solution.
>
>>
>> template <typename tt> \
>> template <typename xx> Table <xx> \
>> Table <tt> :: ExtractSubTable \
>> (int * SelectedRowList, int * SelectedColumnList, \
>
> Weird backslash obsession again...
what about the synthax rather ?
I dunno how to write a proper declaration....