Some checks failed
dev release / build (push) Failing after 12s
Builds out the full v1 scope: a vendored+patched openscreen subset for low-latency Cast Streaming (Mirroring receiver 0F5096E8) alongside the existing Cast V2/HLS and new DLNA/AVTransport casting paths, breadcastd's Idle/Casting state machine with a private IPC socket, the breadcast GTK4 popup as a thin IPC client, and bread.cast.*/bread.command.cast.* breadd integration (device discovery, start/stop, mirroring lifecycle events). Also adds bakery/systemd/Forgejo CI packaging. Validated end-to-end against a real Chromecast/Google TV: negotiated Cast Streaming session, live pipeline playback, and daemon+GUI click-to-cast/ stop through the actual popup.
104 lines
3.3 KiB
C++
104 lines
3.3 KiB
C++
// Copyright 2019 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef UTIL_STD_UTIL_H_
|
|
#define UTIL_STD_UTIL_H_
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "util/stringprintf.h"
|
|
|
|
namespace openscreen {
|
|
|
|
template <typename T, size_t N>
|
|
constexpr size_t countof(T (&array)[N]) {
|
|
return N;
|
|
}
|
|
|
|
// Removes ALL whitespace in place from the string, based on the present C
|
|
// locale. This includes spaces, tabs, and returns. This is useful for string
|
|
// comparisons where whitespace doesn't matter, or, in the case of JSON
|
|
// serialization, is dependent on build configuration and other settings.
|
|
std::string& RemoveWhitespace(std::string& s);
|
|
|
|
template <typename Key, typename Value>
|
|
void RemoveValueFromMap(std::map<Key, Value*>* map, Value* value) {
|
|
for (auto it = map->begin(); it != map->end();) {
|
|
if (it->second == value) {
|
|
it = map->erase(it);
|
|
} else {
|
|
++it;
|
|
}
|
|
}
|
|
}
|
|
|
|
template <typename ForwardIteratingContainer>
|
|
bool AreElementsSortedAndUnique(const ForwardIteratingContainer& c) {
|
|
return std::is_sorted(c.begin(), c.end()) &&
|
|
std::adjacent_find(c.begin(), c.end()) == c.end();
|
|
}
|
|
|
|
template <typename RandomAccessContainer>
|
|
void SortAndDedupeElements(RandomAccessContainer* c) {
|
|
std::sort(c->begin(), c->end());
|
|
const auto new_end = std::unique(c->begin(), c->end());
|
|
c->erase(new_end, c->end());
|
|
}
|
|
|
|
// Append the provided elements together into a single vector. This can be
|
|
// useful when creating a vector of variadic templates in the ctor.
|
|
//
|
|
// This is the base case for the recursion
|
|
template <typename T>
|
|
std::vector<T>&& Append(std::vector<T>&& so_far) {
|
|
return std::move(so_far);
|
|
}
|
|
|
|
// This is the recursive call. Depending on the number of remaining elements, it
|
|
// either calls into itself or into the above base case.
|
|
template <typename T, typename TFirst, typename... TOthers>
|
|
std::vector<T>&& Append(std::vector<T>&& so_far,
|
|
TFirst&& new_element,
|
|
TOthers&&... new_elements) {
|
|
so_far.push_back(std::move(new_element));
|
|
return Append(std::move(so_far), std::move(new_elements)...);
|
|
}
|
|
|
|
// Creates an empty vector with `size` elements reserved. Intended to be used as
|
|
// GetEmptyVectorOfSize<T>(sizeof...(variadic_input))
|
|
template <typename T>
|
|
std::vector<T> GetVectorWithCapacity(size_t size) {
|
|
std::vector<T> results;
|
|
results.reserve(size);
|
|
return results;
|
|
}
|
|
|
|
// Returns true if an element equal to `element` is found in `container`.
|
|
// C.begin() must return an iterator to the beginning of C and C.end() must
|
|
// return an iterator to the end.
|
|
template <typename C, typename E>
|
|
bool Contains(const C& container, const E& element) {
|
|
return std::find(container.begin(), container.end(), element) !=
|
|
container.end();
|
|
}
|
|
|
|
// Returns true if any element in `container` returns true for `predicate`.
|
|
// C.begin() must return an iterator to the beginning of C and C.end() must
|
|
// return an iterator to the end.
|
|
template <typename C, typename P>
|
|
bool ContainsIf(const C& container, P predicate) {
|
|
return std::find_if(container.begin(), container.end(),
|
|
std::move(predicate)) != container.end();
|
|
}
|
|
|
|
} // namespace openscreen
|
|
|
|
#endif // UTIL_STD_UTIL_H_
|