From 7052a1fafbd1e6fbbf4efa85926f5d9beb0692ec Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 9 Jul 2020 17:16:59 +0800 Subject: [PATCH] Log: Refine context id --- trunk/src/core/srs_core.cpp | 28 ++++++++++++++++++++++++++++ trunk/src/core/srs_core.hpp | 28 ++++++++++------------------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/trunk/src/core/srs_core.cpp b/trunk/src/core/srs_core.cpp index 57259c0de..96db00bc9 100644 --- a/trunk/src/core/srs_core.cpp +++ b/trunk/src/core/srs_core.cpp @@ -23,4 +23,32 @@ #include +_SrsContextId::_SrsContextId() +{ +} + +_SrsContextId::_SrsContextId(std::string v) +{ + v_ = v; +} + +_SrsContextId::_SrsContextId(const _SrsContextId& cp) +{ + v_ = cp.v_; +} + +const char* _SrsContextId::c_str() +{ + return v_.c_str(); +} + +bool _SrsContextId::empty() +{ + return v_.empty(); +} + +int _SrsContextId::compare(const _SrsContextId& to) +{ + return v_.compare(to.v_); +} diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 8d256cee2..65da94cd0 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -117,30 +117,22 @@ typedef SrsCplxError* srs_error_t; // The context ID, it default to a string object, we can also use other objects. // @remark User can directly user string as SrsContextId, we user struct to ensure the context is an object. #if 1 -struct _SrsContextId +class _SrsContextId { +private: std::string v_; - _SrsContextId() { - } - _SrsContextId(std::string v) { - v_ = v; - } - _SrsContextId(const _SrsContextId& cp) { - v_ = cp.v_; - } - const char* c_str() { - return v_.c_str(); - } - bool empty() { - return v_.empty(); - } +public: + _SrsContextId(); + _SrsContextId(std::string v); + _SrsContextId(const _SrsContextId& cp); +public: + const char* c_str(); + bool empty(); // Compare the two context id. @see http://www.cplusplus.com/reference/string/string/compare/ // 0 They compare equal // <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter. // >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer. - int compare(const _SrsContextId& to) { - return v_.compare(to.v_); - } + int compare(const _SrsContextId& to); }; typedef _SrsContextId SrsContextId; #else