diff --git a/src/core/model/log.cc b/src/core/model/log.cc index 131bebd0f..2e6495e84 100644 --- a/src/core/model/log.cc +++ b/src/core/model/log.cc @@ -648,7 +648,7 @@ ParameterLogger::ParameterLogger (std::ostream &os) template<> ParameterLogger & -ParameterLogger::operator<< (const std::string param) +ParameterLogger::operator<< (const std::string& param) { if (m_first) { @@ -662,9 +662,8 @@ ParameterLogger::operator<< (const std::string param) return *this; } -template<> ParameterLogger & -ParameterLogger::operator<< (const char * param) +ParameterLogger::operator<< (const char * param) { (*this) << std::string (param); return *this; diff --git a/src/core/model/log.h b/src/core/model/log.h index 6213c5213..f0779e6af 100644 --- a/src/core/model/log.h +++ b/src/core/model/log.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "node-printer.h" @@ -461,13 +462,29 @@ public: /** * Write a function parameter on the output stream, * separating parameters after the first by `,` strings. + * Overload for arithmetic types (integral type or floating point type), + * enabling the parameter to be passed by value. * * \param [in] param The function parameter. * \return This ParameterLogger, so it's chainable. */ - template + template>> ParameterLogger& operator<< (T param); + /** + * Write a function parameter on the output stream, + * separating parameters after the first by `,` strings. + * Overload for non-arithmetic types, enabling the parameter + * to be passed by reference. + * + * \param [in] param The function parameter. + * \return This ParameterLogger, so it's chainable. + */ + template>> + ParameterLogger& operator<< (const T& param); + /** * Overload for vectors, to print each element. * @@ -475,11 +492,18 @@ public: * \return This ParameterLogger, so it's chainable. */ template - ParameterLogger& operator<< (std::vector vector); + ParameterLogger& operator<< (const std::vector& vector); + /** + * Overload for C-strings. + * + * \param [in] param The C-string + * \return This ParameterLogger, so it's chainable. + */ + ParameterLogger& operator<< (const char* param); }; -template +template ParameterLogger& ParameterLogger::operator<< (T param) { @@ -495,11 +519,27 @@ ParameterLogger::operator<< (T param) return *this; } +template +ParameterLogger& +ParameterLogger::operator<< (const T& param) +{ + if (m_first) + { + m_os << param; + m_first = false; + } + else + { + m_os << ", " << param; + } + return *this; +} + template ParameterLogger& -ParameterLogger::operator<< (std::vector vector) +ParameterLogger::operator<< (const std::vector& vector) { - for (auto i : vector) + for (const auto& i : vector) { *this << i; } @@ -513,16 +553,7 @@ ParameterLogger::operator<< (std::vector vector) */ template<> ParameterLogger & -ParameterLogger::operator<< (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 * param); +ParameterLogger::operator<< (const std::string& param); /** * Specialization for int8_t. @@ -531,7 +562,7 @@ ParameterLogger::operator<< (const char * param); */ template<> ParameterLogger & -ParameterLogger::operator<< (int8_t param); +ParameterLogger::operator<< (const int8_t param); /** * Specialization for uint8_t. @@ -540,7 +571,7 @@ ParameterLogger::operator<< (int8_t param); */ template<> ParameterLogger & -ParameterLogger::operator<< (uint8_t param); +ParameterLogger::operator<< (const uint8_t param); } // namespace ns3 diff --git a/src/lte/model/epc-tft.cc b/src/lte/model/epc-tft.cc index f8b38e35a..e495c166e 100644 --- a/src/lte/model/epc-tft.cc +++ b/src/lte/model/epc-tft.cc @@ -37,7 +37,7 @@ NS_LOG_COMPONENT_DEFINE ("EpcTft"); * \param d EPC TFT direction * \return ostream */ -std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d) +std::ostream& operator<< (std::ostream& os, const EpcTft::Direction& d) { switch (d) { @@ -62,7 +62,7 @@ std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d) * \param f EPC TFT packet filter * \return ostream */ -std::ostream& operator<< (std::ostream& os, EpcTft::PacketFilter& f) +std::ostream& operator<< (std::ostream& os, const EpcTft::PacketFilter& f) { os << " direction: " << f.direction << " remoteAddress: " << f.remoteAddress diff --git a/src/lte/model/epc-tft.h b/src/lte/model/epc-tft.h index 085e0c425..afbc1a586 100644 --- a/src/lte/model/epc-tft.h +++ b/src/lte/model/epc-tft.h @@ -208,7 +208,7 @@ private: }; -std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d); +std::ostream& operator<< (std::ostream& os, const EpcTft::Direction& d); } // namespace ns3