Hi Daniel,

thanks for your answer.

Daniel Rentz schrieb:
Am 10.05.2011 17:48, schrieb Regina Henschel:
Hi,

I'm not well-versed in C++, so I need some help in programming in
Splines.cxx in chart2.

There are already
typedef ::std::pair< double, double > tPointType;
typedef ::std::vector< tPointType > tPointVecType;
typedef tPointVecType::size_type lcl_tSizeType;

My data is in
tPointVecType aPointsIn;
and the last valid index is
lcl_tSizeType n;

Now I need a lot of for-loops from 0 to n. They iterate over a matrix of
elements of type double, over an array of elements of type double, and
over a vector of type tPointVecType, sometimes in the same loop. What is
the correct type for the iterator? Should it be lcl_tSizeType or
sal_uInt32? What is the implication of one or the other?

The correct index type for vectors is lcl_tSizeType here, which is
typedefed to "size_t" by the vector class. On 32-bit systems, this is an
unsigned 32-bit type, but on 64-bit systems, it is an unsigned 64-bit
type. Using sal_uInt32 may cause compiler warnings on these systems,
e.g. when using

sal_uInt32 i = n;

Oh. That's important. I wouldn't have noticed it on my 32bit Windows and VC Express. I have used some of those mixed assignments and get no warnings. I have to revise the code in Splines.cxx



I recommend to use real iterators. If your "n" contains the size of the
vector, i.e. you want to iterate all elements of the vector:

tPointVecType aPointsIn;
...
for (tPointVecType::const_iterator it = aPointsIn.begin(),
it_end = aPointsIn.end(); it != it_end; ++it)
{
/* "it" points to a pair of double */

it->first; // this is the first value of the pair
it->second; // this is the second value of the pair
}


n can be as large as the count of Spreadsheet rows, theoretically, but
will be smaller than hundred in most cases.

If "n" is less than aPointsIn.size(), you can modify the loop header:

for (tPointVecType::const_iterator it = aPointsIn.begin(),
it_end = it + n; it != it_end; ++it)


OK, that's clear. But I need to iterate over vector and matrix parallel and therefore need an unsigned integer as index for the matrix.


If you still prefer iterating by index: :-)

for (lcl_tSizeType i = 0; i < n; ++i)
{
aPointsIn[i].first;
aPointsIn[i].second;
}

I think, that works best for me. I have to solve a LGS with a vector on right side and a matrix, which is nearly, but not exact, banded. So I need some index calculations for shifting and for calculating, whether I can terminate the loops earlier.

Kind regards
Regina


--
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help

Reply via email to