Marshalling segmented_array

Discussion in 'C++' started by Ebenezer, Feb 4, 2012.

  1. Ebenezer

    Ebenezer Guest

    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<double, 64u, std::allocator<double>
    >::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
    Ebenezer, Feb 4, 2012
    #1
    1. Advertising

  2. Ebenezer

    Ebenezer Guest

    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
    Ebenezer, Feb 6, 2012
    #2
    1. Advertising

  3. Ebenezer

    Ebenezer Guest

    On Feb 7, 7:11 am, Leigh Johnston <> wrote:
    > On 06/02/2012 19:07, Ebenezer wrote:
    >
    >
    >
    >
    >
    > > 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>.
    Ebenezer, Feb 7, 2012
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    586
  2. Peter Flynn
    Replies:
    2
    Views:
    432
    Peter Flynn
    Aug 9, 2004
  3. Terence
    Replies:
    2
    Views:
    361
    Frank Schmitt
    Nov 12, 2003
  4. dev_chandok

    Marshalling in COM

    dev_chandok, Oct 26, 2004, in forum: C++
    Replies:
    1
    Views:
    689
    red floyd
    Oct 26, 2004
  5. Ebenezer

    segmented_array question

    Ebenezer, Sep 29, 2011, in forum: C++
    Replies:
    2
    Views:
    326
    Ebenezer
    Sep 30, 2011
Loading...

Share This Page