UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2014-2023 CESNET z.s.p.o.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of CESNET nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
27 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef UTILS_MISC_H_
40#define UTILS_MISC_H_
41
42#ifdef __cplusplus
43#include <cstddef>
44#include <cstdint>
45#else
46#include <stdbool.h>
47#include <stddef.h>
48#include <stdint.h>
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55bool is_wine(void);
56long long unit_evaluate(const char *str, const char **endptr);
57double unit_evaluate_dbl(const char *str, bool case_sensitive,
58 const char **endptr);
59const char *format_in_si_units(unsigned long long int val);
60int get_framerate_n(double framerate);
61int get_framerate_d(double framerate);
62
63const char *ug_strerror(int errnum);
64void ug_perror(const char *s);
65int get_cpu_core_count(void);
66bool is_arm_mac(void);
67
68struct key_val {
69 const char *key;
70 const char *val;
71};
72void print_module_usage(const char *module_name, const struct key_val *options, const struct key_val *options_full, bool print_full_help);
73
74bool invalid_arg_is_numeric(const char *what);
75
76#ifdef __cplusplus
77}
78#endif
79
80#ifdef __cplusplus
81uint32_t parse_uint32(const char *value_str) noexcept(false);
82
83#include <map>
84template<typename key, typename T>
85inline T get_map_val_or_default(std::map<key, T> const& map, key const& k, T const& def) {
86 if (auto && it = map.find(k); it != map.end()) {
87 return it->second;
88 }
89 return def;
90}
91
92/* Like std::out_ptr from C++23 */
93template<class Smart, class Pointer = typename Smart::pointer>
94class out_ptr{
95public:
96 out_ptr(Smart& out) noexcept: smart_ptr(out) { }
98 smart_ptr.reset(ptr);
99 }
100
101 out_ptr(out_ptr&&) = delete;
103
104 operator Pointer*() noexcept { return &ptr; }
105 operator void**() noexcept { return &ptr; }
106private:
107 Smart& smart_ptr;
108 Pointer ptr = nullptr;
109};
110#endif //__cplusplus
111
112#endif// UTILS_MISC_H_
113
int void * val
Definition misc.h:94
out_ptr & operator=(out_ptr &&)=delete
out_ptr(Smart &out) noexcept
Definition misc.h:96
Smart & smart_ptr
Definition misc.h:107
~out_ptr()
Definition misc.h:97
Pointer ptr
Definition misc.h:108
out_ptr(out_ptr &&)=delete
Definition misc.h:68
const char * key
Definition misc.h:69
const char * val
Definition misc.h:70
Definition rtp.c:253
bool invalid_arg_is_numeric(const char *what)
Definition misc.cpp:340
void ug_perror(const char *s)
Definition misc.cpp:213
void print_module_usage(const char *module_name, const struct key_val *options, const struct key_val *options_full, bool print_full_help)
Definition misc.cpp:242
bool is_arm_mac(void)
Definition misc.cpp:315
double unit_evaluate_dbl(const char *str, bool case_sensitive, const char **endptr)
Definition misc.cpp:102
bool is_wine(void)
Definition misc.cpp:172
T get_map_val_or_default(std::map< key, T > const &map, key const &k, T const &def)
Definition misc.h:85
int get_cpu_core_count(void)
Definition misc.cpp:218
long long unit_evaluate(const char *str, const char **endptr)
Definition misc.cpp:81
const char * ug_strerror(int errnum)
Definition misc.cpp:203
const char * format_in_si_units(unsigned long long int val)
Definition misc.cpp:154
uint32_t parse_uint32(const char *value_str) noexcept(false)
Definition misc.cpp:296
int get_framerate_d(double framerate)
Definition misc.cpp:190
int get_framerate_n(double framerate)
Definition misc.cpp:184
const char * key
Definition cineform.cpp:125