Skip to content

Commit

Permalink
Merge pull request #45 from LuAPi/optimize-message-constructors
Browse files Browse the repository at this point in the history
Optimize message constructors
  • Loading branch information
pmnewman authored Jun 14, 2018
2 parents e81b246 + 2b321ce commit 4c2b9c7
Showing 1 changed file with 42 additions and 80 deletions.
122 changes: 42 additions & 80 deletions Core/libMOOS/Comms/MOOSMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,87 +48,49 @@ using namespace std;
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


CMOOSMsg::CMOOSMsg()
{
m_cMsgType=MOOS_NULL_MSG;
m_cDataType=MOOS_DOUBLE;
m_dfTime = -1;
m_dfVal = -1;
m_dfVal2 = -1;
m_nID = -1;
m_sSrc = "";
m_sSrcAux = "";
}

CMOOSMsg::~CMOOSMsg()
{

}

CMOOSMsg::CMOOSMsg(char cMsgType,const std::string & sKey,double dfVal,double dfTime)
{
m_cMsgType = cMsgType;
m_dfVal = dfVal;
m_dfVal2 = -1;
m_cDataType = MOOS_DOUBLE;
m_sKey = sKey;
m_dfTime = -1;
m_nID = -1;

if(dfTime==-1)
{
m_dfTime = MOOSTime();
}
else
{
m_dfTime=dfTime;
}
}


CMOOSMsg::CMOOSMsg(char cMsgType,const std::string & sKey,const std::string &sVal,double dfTime)
{
m_cMsgType = cMsgType;
m_dfVal = -1;
m_dfVal2 = -1;
m_cDataType = MOOS_STRING;
m_sKey = sKey;
m_sVal = sVal;
m_dfTime = -1;
m_nID = -1;

if(dfTime==-1)
{
m_dfTime = MOOSTime();
}
else
{
m_dfTime=dfTime;
}
}


CMOOSMsg::CMOOSMsg(char cMsgType,const std::string &sKey, unsigned int nDataSize,const void* Data,double dfTime)
{
m_cMsgType = cMsgType;
m_dfVal = -1;
m_dfVal2 = -1;
m_cDataType = MOOS_BINARY_STRING;
m_sKey = sKey;
m_sVal.assign((char *)Data,nDataSize);
m_dfTime = -1;
m_nID = -1;

if(dfTime==-1)
{
m_dfTime = MOOSTime();
}
else
{
m_dfTime=dfTime;
}

: m_cMsgType(MOOS_NULL_MSG),
m_cDataType(MOOS_DOUBLE),
m_nID(-1),
m_dfTime(-1),
m_dfVal(-1),
m_dfVal2(-1),
m_sSrc(""),
m_sSrcAux("") {}

CMOOSMsg::~CMOOSMsg() {}

CMOOSMsg::CMOOSMsg(char cMsgType, const std::string &sKey, double dfVal,
double dfTime)
: m_cMsgType(cMsgType),
m_cDataType(MOOS_DOUBLE),
m_sKey(sKey),
m_nID(-1),
m_dfTime((dfTime == -1) ? MOOSTime() : dfTime),
m_dfVal(dfVal),
m_dfVal2(-1) {}

CMOOSMsg::CMOOSMsg(char cMsgType, const std::string &sKey,
const std::string &sVal, double dfTime)
: m_cMsgType(cMsgType),
m_cDataType(MOOS_STRING),
m_sKey(sKey),
m_nID(-1),
m_dfTime((dfTime == -1) ? MOOSTime() : dfTime ),
m_dfVal(-1),
m_dfVal2(-1),
m_sVal(sVal) {}

CMOOSMsg::CMOOSMsg(char cMsgType, const std::string &sKey,
unsigned int nDataSize, const void *Data, double dfTime)
: m_cMsgType(cMsgType),
m_cDataType(MOOS_BINARY_STRING),
m_sKey(sKey),
m_nID(-1),
m_dfTime((dfTime == -1) ? MOOSTime() : dfTime),
m_dfVal(-1),
m_dfVal2(-1) {
m_sVal.assign((char *)Data, nDataSize);
}

bool CMOOSMsg::operator == (const CMOOSMsg & M) const
Expand Down

0 comments on commit 4c2b9c7

Please sign in to comment.