Music Hub ..
A session-wide music playback service
utils.h
Go to the documentation of this file.
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef UTILS_H_
19#define UTILS_H_
20
21#include <boost/format.hpp>
22
23#include <string>
24#include <vector>
25
26#define MCS_STR_VALUE(str) #str
27
28namespace core {
29namespace ubuntu {
30namespace media {
31typedef int64_t TimestampNs;
32typedef int64_t TimestampUs;
33struct Utils
34{
35 // Merely used as a namespace.
36 Utils() = delete;
37
38 // Sprintf - much like what you would expect :)
39 template<typename... Types>
40 static std::string Sprintf(const std::string& fmt_str, Types&&... args);
41 // GetEnv - returns a variable value from the environment
42 static uint64_t GetNowNs();
43 // GetNowUs - get a timestamp in microseconds
44 static uint64_t GetNowUs();
45};
46
47namespace impl {
48// Base case, just return the passed in boost::format instance.
49inline boost::format& Sprintf(boost::format& f)
50{
51 return f;
52}
53// Sprintf recursively walks the parameter pack at compile time.
54template <typename Head, typename... Tail>
55inline boost::format& Sprintf(boost::format& f, Head const& head, Tail&&... tail) {
56 return Sprintf(f % head, std::forward<Tail>(tail)...);
57}
58} // namespace impl
59} // namespace media
60} // namespace ubuntu
61} // namespace core
62
63template <typename... Types>
64inline std::string core::ubuntu::media::Utils::Sprintf(const std::string& format, Types&&... args) {
65 boost::format f(format);
66 return core::ubuntu::media::impl::Sprintf(f, std::forward<Types>(args)...).str();
67}
68
69#endif
boost::format & Sprintf(boost::format &f)
Definition: utils.h:49
int64_t TimestampUs
Definition: utils.h:32
int64_t TimestampNs
Definition: utils.h:31
Definition: player.h:34
static std::string Sprintf(const std::string &fmt_str, Types &&... args)
Definition: utils.h:64
static uint64_t GetNowNs()
Definition: utils.cpp:32
static uint64_t GetNowUs()
Definition: utils.cpp:39