[core] Show string args as quoted strings in NS_LOG_FUNCTION

This commit is contained in:
Peter D. Barnes, Jr.
2016-09-02 21:47:53 -04:00
parent 25c02db88c
commit b5b2b5398a
2 changed files with 60 additions and 13 deletions

View File

@@ -638,4 +638,28 @@ ParameterLogger::ParameterLogger (std::ostream &os)
{
}
template<>
ParameterLogger&
ParameterLogger::operator<< <std::string>(const std::string param)
{
if (m_first)
{
m_os << "\"" << param << "\"";
m_first = false;
}
else
{
m_os << ", \"" << param << "\"";
}
return *this;
}
template<>
ParameterLogger&
ParameterLogger::operator<< <const char *>(const char * param)
{
(*this) << std::string (param);
return *this;
}
} // namespace ns3

View File

@@ -433,21 +433,44 @@ public:
* \return This ParameterLogger, so it's chainable.
*/
template<typename T>
ParameterLogger& operator<< (T param)
{
if (m_first)
{
m_os << param;
m_first = false;
}
else
{
m_os << ", " << param;
}
return *this;
}
ParameterLogger& operator<< (T param);
};
template<typename T>
ParameterLogger&
ParameterLogger::operator<< (T param)
{
if (m_first)
{
m_os << param;
m_first = false;
}
else
{
m_os << ", " << param;
}
return *this;
}
/**
* Specialization for strings.
* \param [in] param The function parameter.
* \return This ParameterLogger, so it's chainable.
*/
template<>
ParameterLogger&
ParameterLogger::operator<< <std::string>(const std::string param);
/**
* Specialization for C-strings.
* \param [in] param The function parameter.
* \return This ParameterLogger, so it's chainable.
*/
template<>
ParameterLogger&
ParameterLogger::operator<< <const char *>(const char * param);
} // namespace ns3
/**@}*/ // \ingroup logging