Marshalling segmented_array

E

Ebenezer

I'm looking for some advice with this.

template <typename B, typename T, unsigned chunk_size>
void
segmented_arrayMarshal (B& buf, ::neolib::segmented_array<T,
chunk_size> const& grp)
{
typename ::neolib::segmented_array<T, chunk_size>::segment& seg =
::neolib::segmented_iterator<T,
chunk_size>(grp.begin()).segment();

// ...
}



../MarshallingFunctions.hh:180:87: error: no matching function for call
to ‘neolib::segmented_iterator said:
::segmented_iterator(neolib::segmented_array<double,
64u>::const_iterator)’
../MarshallingFunctions.hh:180:87: note: candidates are:
../segmented_array.h:668:5: note: neolib::segmented_iterator<T, N,
A>::segmented_iterator(const base&) [with T = double, unsigned int N =
64u, A = std::allocator<double>, neolib::segmented_iterator<T, N,
A>::base = neolib::segmented_array<double, 64u>::iterator]
../segmented_array.h:668:5: note: no known conversion for argument 1
from ‘neolib::segmented_array<double, 64u>::const_iterator’ to ‘const
base& {aka const neolib::segmented_array<double, 64u>::iterator&}’
../segmented_array.h:664:7: note: neolib::segmented_iterator<double,
64u, std::allocator<double> >::segmented_iterator(const
neolib::segmented_iterator<double, 64u, std::allocator<double> >&)
../segmented_array.h:664:7: note: no known conversion for argument 1
from ‘neolib::segmented_array<double, 64u>::const_iterator’ to ‘const
neolib::segmented_iterator<double, 64u, std::allocator<double> >&’


It builds if I remove the const, but think the const should stay.
Tia.

Brian
Ebenezer Enterprises
http://webEbenezer.net
 
E

Ebenezer

Here's what I have:

template <typename B, typename T, unsigned chunk_size>
void
segmented_arrayMarshal (B& buf, ::neolib::segmented_array<T,
chunk_size> const& grp)
{
uint32_t headCount = grp.size();
buf.Receive(&headCount, sizeof(headCount));

if (headCount > 0) {
size_t index = ::neolib::segmented_iterator<T,
chunk_size>(const_cast<neolib::segmented_array<T,
chunk_size>&>(grp).begin()).segment().size();
buf.Receive(&grp[0], index * sizeof(T));

int32_t const chunks = (headCount - index) / chunk_size;
for (int32_t ii = 0; ii < chunks; ++ii) {
buf.Receive(&grp[index], chunk_size * sizeof(T));
index += chunk_size;
}

if (index < headCount) {
buf.Receive(&grp[index], (headCount - index) * sizeof(T));
}
}
}

Do others agree that ideally segmented_array would support this
so the cast isn't needed?

The above is only used in certain circumstances.

Brian
Ebenezer Enterprises
http://webEbenezer.net
 
E

Ebenezer

Here's what I have:
template<typename B, typename T, unsigned chunk_size>
void
segmented_arrayMarshal (B&  buf, ::neolib::segmented_array<T,
chunk_size>  const&  grp)
{
   uint32_t headCount = grp.size();
   buf.Receive(&headCount, sizeof(headCount));
   if (headCount>  0) {
     size_t index = ::neolib::segmented_iterator<T,
chunk_size>(const_cast<neolib::segmented_array<T,
chunk_size>&>(grp).begin()).segment().size();
     buf.Receive(&grp[0], index * sizeof(T));
     int32_t const chunks = (headCount - index) / chunk_size;
     for (int32_t ii = 0; ii<  chunks; ++ii) {
       buf.Receive(&grp[index],  chunk_size * sizeof(T));
       index += chunk_size;
     }
     if (index<  headCount) {
       buf.Receive(&grp[index], (headCount - index) * sizeof(T));
     }
   }
}
Do others agree that ideally segmented_array would support this
so the cast isn't needed?
The above is only used in certain circumstances.

Why don't you create a const_segmented_iterator?

It would be better that if you didn't try and access the segments
directly but instead use the normal container class interface
(iterators, elements and such).

OK, I guess from your other reply I may stick to the iterator
interface. I was hoping to optimize the process for things
like segmented_array<double>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top