Skip to content

Commit

Permalink
Reworked the fmt API
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Malecki committed Jul 26, 2024
1 parent a8664d2 commit 880fa9d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ SrtCommon::~SrtCommon()
SrtSource::SrtSource(string host, int port, const map<string,string>& par)
{
Init(host, port, par, false);
hostport_copy = srt::ocat(host, ":"_V, port);
hostport_copy = srt::fmtcat(host, ":"_V, port);
}

int SrtSource::Read(size_t chunk, MediaPacket& pkt, ostream &out_stats)
Expand Down
14 changes: 7 additions & 7 deletions apps/uriparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,35 @@ string UriParser::makeUri()

ofmtstream out;

oprint(out, prefix, m_host);
out.print(prefix, m_host);
if ((m_port == "" || m_port == "0") && m_expect == EXPECT_FILE)
{
// Do not add port
}
else
{
oprint(out, ":"_V, m_port);
out.print(":"_V, m_port);
}

if (m_path != "")
{
if (m_path[0] != '/')
oprint(out, "/"_V);
oprint(out, m_path);
out.print("/"_V);
out.print(m_path);
}

if (!m_mapQuery.empty())
{
oprint(out, "?"_V);
out.print("?"_V);

query_it i = m_mapQuery.begin();
for (;;)
{
oprint(out, i->first, "="_V, i->second);
out.print(i->first, "="_V, i->second);
++i;
if (i == m_mapQuery.end())
break;
oprint(out, "&"_V);
out.print("&"_V);
}
}

Expand Down
49 changes: 33 additions & 16 deletions srtcore/ofmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,36 @@ class ofmtstream
{
return buffer.str();
}

// Additionally for C++11
#if (defined(__cplusplus) && __cplusplus > 199711L) \
|| (defined(_MSVC_LANG) && _MSVC_LANG > 199711L) // Some earlier versions get this wrong
void print_chain()
{
}

template<typename Arg1, typename... Args>
void print_chain(const Arg1& arg1, const Args&... args)

Check notice

Code scanning / CodeQL

Unused static variable Note

Static variable args is never read.

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable args is not used.
{
*this << arg1;
print_chain(args...);
}

template<typename... Args>
ofmtstream& print(const Args&... args)
{
print_chain(args...);
return *this;
}

template<typename... Args>
ofmtstream& puts(const Args&... args)
{
print_chain(args...);
buffer << std::endl;
return *this;
}
#endif
};

// Additionally for C++11
Expand All @@ -323,24 +353,11 @@ inline internal::fmt_stringview operator""_V(const char* ptr, size_t s)
return internal::fmt_stringview(ptr, s);
}

template<typename Stream> inline
Stream& oprint(Stream& out)
{
return out;
}

template<typename Stream, typename Arg1, typename... Args> inline
Stream& oprint(Stream& out, const Arg1& arg1, const Args&... args)
{
out << arg1;
return oprint(out, args...);
}

template <typename... Args> inline
std::string ocat(const Args&... args)
std::string fmtcat(const Args&... args)
{
ofmtstream out;
oprint(out, args...);
out.print(args...);
return out.str();
}

Expand All @@ -366,7 +383,7 @@ std::string fmts(const Value& val, const fmtc& fmtspec)
}

// This prevents the macro from being used with anything else
// than a string literal
// than a string literal. Version of ""_V UDL available for C++03.
#define OFMT_RAWSTR(arg) srt::internal::CreateRawString_FWD("" arg)


Expand Down
2 changes: 1 addition & 1 deletion testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ void SrtCommon::UpdateGroupStatus(const SRT_SOCKGROUPDATA* grpdata, size_t grpda
SrtSource::SrtSource(string host, int port, std::string path, const map<string,string>& par)
{
Init(host, port, path, par, SRT_EPOLL_IN);
hostport_copy = srt::ocat(host, ":"_V, port);
hostport_copy = srt::fmtcat(host, ":"_V, port);
}

static void PrintSrtStats(SRTSOCKET sock, bool clr, bool bw, bool stats)
Expand Down

0 comments on commit 880fa9d

Please sign in to comment.