Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Marshalling auto_ptr/unique_ptr objects

Reply
Thread Tools

Marshalling auto_ptr/unique_ptr objects

 
 
Brian
Guest
Posts: n/a
 
      03-06-2010
I'm adding support for auto_ptr/unique_ptr to the C++
Middleware Writer. In the past I've gotten a few pointers
on implementations here and since I'm not an expert on
either of those classes, I would like to get some
feedback on what I have so far. There are two pieces
of input:

class mytype
{
std::complex<float> c_;
std::auto_ptr<uint32_t> a_;

void SendTypeNum(SendCompressedBuffer*) const;
void SendMemberData(SendCompressedBuffer*) const;

public:
template <typename B>
explicit mytype(B* buf);

void
Send(SendCompressedBuffer* buf, bool = false) const
{
SendMemberData(buf);
}

void CalculateMarshallingSize(Counter& cntr) const;
};



And the Middle file is:

tst_shepherd
(auto_ptr<vector<mytype> >, auto_ptr<uint32_t>, auto_ptr<mytype>)
}




The output is:

// Generated by the C++ Middleware Writer version 1.11

#include <memory>
#include <vector>
#include <tst.hh>
#include <MarshallingFunctions.hh>
#include <ReceiveCompressedBuffer.hh>
#include <SendCompressedBuffer.hh>


extern uint32_t msg_length_max;

struct tst_shepherd
{

void
Send(SendCompressedBuffer* buf, const auto_ptr<vector<mytype> >& abt1,
const auto_ptr<uint32_t>& abt2, const auto_ptr<mytype>& abt3)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(uint32_t));
groupCount(cntr, false, sizeof(uint16_t), *abt1.get());
cntr.Add(sizeof(uint32_t));
abt3->CalculateMarshallingSize(cntr);
buf->Receive(&msg_id_direct, sizeof(msg_id_direct));
buf->Receive(&cntr.value_, sizeof(cntr.value_));

groupSend(buf, false, *abt1.get());

buf->Receive(abt2.get(), sizeof(uint32_t));

abt3->Send(buf, false);
buf->Flush();
}


template <typename B>
void
Receive(B* buf, auto_ptr<vector<mytype> >& abt1, auto_ptr<uint32_t>&
abt2, auto_ptr<mytype>& abt3)
{
uint32_t headCount[1];
vector<mytype>* raw1 = new vector<mytype>;
buf->Give(headCount[0]);
raw1->reserve(raw1->size() + headCount[0]);
while (headCount[0] > 0) {
--headCount[0];
mytype rep3(buf);
raw1->push_back(rep3);
}
abt1.reset(raw1);

uint32_t* raw3 = new uint32_t;
buf->Give(*raw3);
abt2.reset(raw3);

mytype* raw4 = new mytype(buf);
abt3.reset(raw4);
}

};

uint16_t const mytype_num = 7001;


template <typename B>
inline
mytype::mytype(B* buf)
{
buf->Give(c_);
uint32_t* raw5 = new uint32_t;
buf->Give(*raw5);
a_.reset(raw5);
}


inline void
mytype::CalculateMarshallingSize(Counter& cntr) const
{
cntr.Add(sizeof(c_));
cntr.Add(sizeof(uint32_t));
}


inline void
mytype::SendTypeNum(SendCompressedBuffer* buf) const
{
buf->Receive(&mytype_num, sizeof(mytype_num));
}


inline void
mytype::SendMemberData(SendCompressedBuffer* buf) const
{
complexSend(buf, c_);
buf->Receive(a_.get(), sizeof(uint32_t));
}

-----------------------------------------------------------------------

I've only confirmed that the output compiles correctly
on g++ 4.4.2. I'd like to hear ideas on what could be
done to improve the implementation. In particular, I
wonder if the Receive function and mytype's stream
constructor are correct and efficient. If you want to
dig into the details, there's an archive here --
http://webEbenezer.net/misc/direct.tar.bz2 --
that has everything needed to compile the above
code. The implementation for unique_ptr is the
same, except it pulls in the file "utility" rather than
"memory." Thanks in advance.


Brian Wood
http://webEbenezer.net
(651) 251-9384
 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      03-06-2010
On Mar 5, 7:35*pm, Brian <(E-Mail Removed)> wrote:
> I'm adding support for auto_ptr/unique_ptr to the C++
> Middleware Writer. In the past I've gotten a few pointers
> on implementations here and since I'm not an expert on
> either of those classes, I would like to get some
> feedback on what I have so far. *There are two pieces
> of input:
>
> class mytype
> {
> * std::complex<float> * * *c_;
> * std::auto_ptr<uint32_t> *a_;



Just noticed that this should be changed
to a unique_ptr since I've got a vector of
mytype.


Brian Wood
http://webEbenezer.net
(651) 251-9384

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Marshalling big objects Gabriel Genellina Python 1 07-16-2007 01:47 AM
Marshalling big objects =?iso-8859-1?Q?=22Orlando_D=F6hring=22?= Python 0 07-14-2007 11:04 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Chunking Marshalling with JAXB rottyguy70@yahoo.com Java 0 04-13-2006 12:03 PM
Marshalling objects that include 'Singleton' Tom Counsell Ruby 1 09-21-2004 12:52 PM



Advertisments