Jump to content
  • Advertisement
Sign in to follow this  
wood_brian

C++ Code Review

This topic is 2755 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like to receive some ideas/comments on how to improve what I'm working on. First here are a couple of links to files with classes used below:
http://webEbenezer.net/misc/File.hh
http://webEbenezer.net/misc/account_info.hh

This is the high-level input read by the code generator:


msg_shepherd
(std::vector<cmw_account_info>) @msg_id_login

(uint32_t,
uint32_t, cmw_user_input) @out @msg_id_direct
(uint32_t, cmw_user_input) @in

(bool, uint32_t, std::vector<File>) @out
(bool)
(std::vector<File>) @in

(bool, uint32_t, flex_string<char>) @out
(bool, uint32_t) @in
(flex_string<char>) @in

(bool, flex_string<char>) @out
(cmw_request)
}


And here's the output from the code generator:


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


#ifndef msg_shepherd_hh
#define msg_shepherd_hh
#include <flex_string.h>
#include <vector>
#include <File.hh>
#include <account_info.hh>
#include <MarshallingFunctions.hh>
#include <ReceiveCompressedBuffer.hh>
#include <SendCompressedBuffer.hh>

uint16_t const msg_id_login = 1201;
uint16_t const msg_id_direct = 1202;
uint16_t const msg_id_max = 1203;


struct msg_shepherd
{
uint32_t msg_length_max;

msg_shepherd(uint32_t msgLengthMax) : msg_length_max(msgLengthMax)
{}

void
Send(SendCompressedBuffer& buf, const std::vector<cmw_account_info>& abt1)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(uint32_t));
groupCount(cntr, false, sizeof(uint16_t), abt1);
cntr.Add(sizeof(msg_id_login));
buf.Receive(&msg_id_login, sizeof(msg_id_login));
groupSend(buf, false, abt1);
buf.Compress();
}


template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, std::vector<cmw_account_info>& abt1)
{
uint32_t headCount[1];
buf.Give(headCount[0]);
abt1.reserve(abt1.size() + headCount[0]);
for (; headCount[0] > 0; --headCount[0]) {
cmw_account_info rep2(buf);
abt1.push_back(rep2);
}
}


void
Send(SendCompressedBuffer& buf, const uint32_t abt1, const uint32_t abt2, const cmw_user_input& abt3)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(uint32_t));
cntr.Add(sizeof(uint32_t));
abt3.CalculateMarshallingSize(cntr);
cntr.Add(sizeof(msg_id_direct));
buf.Receive(&msg_id_direct, sizeof(msg_id_direct));
buf.Receive(&abt1, sizeof(uint32_t));
buf.Receive(&abt2, sizeof(uint32_t));
abt3.Send(buf, false);
buf.Compress();
}


template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, uint32_t& abt1, cmw_user_input& abt2)
{
buf.Give(abt1);
abt2 = cmw_user_input(buf);
}


void
Send(SendCompressedBuffer& buf, const bool abt1, const uint32_t abt2, const std::vector<File>& abt3)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(unsigned char));
cntr.Add(sizeof(uint32_t));
cntr.Add(sizeof(uint32_t));
groupCount(cntr, false, sizeof(uint16_t), abt3);
boolSend(buf, abt1);
buf.Receive(&abt2, sizeof(uint32_t));
groupSend(buf, false, abt3);
buf.Compress();
}


void
Send(SendCompressedBuffer& buf, const bool abt1)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(unsigned char));
boolSend(buf, abt1);
buf.Compress();
}

template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, bool& abt1)
{
boolReceive(buf, abt1);
}


template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, std::vector<File>& abt1)
{
uint32_t headCount[1];
buf.Give(headCount[0]);
abt1.reserve(abt1.size() + headCount[0]);
for (; headCount[0] > 0; --headCount[0]) {
File rep3(buf);
abt1.push_back(rep3);
}
}


void
Send(SendCompressedBuffer& buf, const bool abt1, const uint32_t abt2, const flex_string<char>& abt3)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(unsigned char));
cntr.Add(sizeof(uint32_t));
stringCount(cntr, abt3);
boolSend(buf, abt1);
buf.Receive(&abt2, sizeof(uint32_t));
stringSend(buf, abt3);
buf.Compress();
}


template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, bool& abt1, uint32_t& abt2)
{
boolReceive(buf, abt1);
buf.Give(abt2);
}

template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, flex_string<char>& abt1)
{
stringReceive(buf, abt1);
}


void
Send(SendCompressedBuffer& buf, const bool abt1, const flex_string<char>& abt2)
{
Counter cntr(msg_length_max);
cntr.Add(sizeof(unsigned char));
stringCount(cntr, abt2);
boolSend(buf, abt1);
stringSend(buf, abt2);
buf.Compress();
}


void
Send(SendCompressedBuffer& buf, const cmw_request& abt1)
{
Counter cntr(msg_length_max);
abt1.CalculateMarshallingSize(cntr);
abt1.Send(buf, false);
buf.Compress();
}


template <typename R>
void
Receive(ReceiveCompressedBuffer<R>& buf, cmw_request& abt1)
{
abt1 = cmw_request(buf);
}

};

uint16_t const File_num = 7001;
uint16_t const cmw_account_info_num = 7002;
uint16_t const cmw_user_input_num = 7003;
uint16_t const cmw_request_num = 7004;

template <typename R>
inline
cmw_account_info::cmw_account_info(ReceiveCompressedBuffer<R>& buf)

{
buf.Give(accountnumber);
password = lil_string(buf);
}


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


inline void
cmw_account_info::SendMemberData(SendCompressedBuffer& buf) const
{
buf.Receive(&accountnumber, sizeof(uint32_t));
password.Send(buf, false);
}


inline void
cmw_account_info::SendTypeNum(SendCompressedBuffer& buf) const
{
buf.Receive(&cmw_account_info_num, sizeof(cmw_account_info_num));
}


template <typename R>
inline
cmw_request::cmw_request(ReceiveCompressedBuffer<R>& buf)

{
buf.Give(accountNbr);
stringReceive(buf, directory);
stringReceive(buf, filename);
}


inline void
cmw_request::CalculateMarshallingSize(Counter& cntr) const
{
cntr.Add(sizeof(uint32_t));
stringCount(cntr, directory);
stringCount(cntr, filename);
}

inline void
cmw_request::SendMemberData(SendCompressedBuffer& buf) const
{
buf.Receive(&accountNbr, sizeof(uint32_t));
stringSend(buf, directory);
stringSend(buf, filename);
}


inline void
cmw_request::SendTypeNum(SendCompressedBuffer& buf) const
{
buf.Receive(&cmw_request_num, sizeof(cmw_request_num));
}


template <typename R>
inline
cmw_user_input::cmw_user_input(ReceiveCompressedBuffer<R>& buf)

{
unsigned int headCount[1];
buf.Give(headCount[0]);
headers.reserve(headers.size() + headCount[0]);
for (; headCount[0] > 0; --headCount[0]) {
File rep4(buf);
headers.push_back(rep4);
}
middlefile = File(buf);
buf.Give(choices);
}


inline void
cmw_user_input::CalculateMarshallingSize(Counter& cntr) const
{
cntr.Add(sizeof(uint32_t));
groupCount(cntr, false, sizeof(uint16_t), headers);
middlefile.CalculateMarshallingSize(cntr);
cntr.Add(sizeof(uint32_t));
}

inline void
cmw_user_input::SendMemberData(SendCompressedBuffer& buf) const
{
unsigned int headCount;
groupSend(buf, false, headers);
middlefile.Send(buf, false);
buf.Receive(&choices, sizeof(uint32_t));
}


inline void
cmw_user_input::SendTypeNum(SendCompressedBuffer& buf) const
{
buf.Receive(&cmw_user_input_num, sizeof(cmw_user_input_num));
}


#endif


There's also an archive here -- http://webEbenezer.n.../direct.tar.bz2 -- with the files that are included here.

Thanks in advance.


Brian Wood
Ebenezer Enterprises
http://webEbenezer.net

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!