Ginga  0.13.6.1771-df200
The iTV middleware.
aux-ginga.h
Go to the documentation of this file.
1 /* Copyright (C) 2006-2017 PUC-Rio/Laboratorio TeleMidia
2 
3 This file is part of Ginga (Ginga-NCL).
4 
5 Ginga is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9 
10 Ginga is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13 License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with Ginga. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #ifndef AUX_GINGA_H
19 #define AUX_GINGA_H
20 
21 #include "ginga.h"
22 
24 
25 #include <config.h>
26 #include "aux-glib.h"
27 
28 #define GINGA_PRAGMA_DIAG PRAGMA_DIAG
29 #define GINGA_PRAGMA_DIAG_PUSH PRAGMA_DIAG_PUSH
30 #define GINGA_PRAGMA_DIAG_POP PRAGMA_DIAG_POP
31 #define GINGA_PRAGMA_DIAG_IGNORE PRAGMA_DIAG_IGNORE
32 #define GINGA_PRAGMA_DIAG_WARNING PRAGMA_DIAG_WARNING
33 
34 // C library.
35 #include <math.h>
36 #include <stdlib.h>
37 
38 // External C libraries.
39 #include <gdk/gdk.h>
40 
42 GINGA_PRAGMA_DIAG_IGNORE (-Wcast-qual)
43 GINGA_PRAGMA_DIAG_IGNORE (-Wconversion)
44 #include <gst/app/gstappsink.h>
45 #include <gst/gst.h>
46 #include <gst/video/video.h>
48 
50 
51 // C++ library.
52 #include <algorithm>
53 #include <list>
54 #include <map>
55 #include <set>
56 #include <string>
57 #include <vector>
58 using namespace std;
59 
60 // Namespaces.
61 #define GINGA_NAMESPACE_BEGIN namespace ginga {/*}*/
62 #define GINGA_NAMESPACE_END /*{*/}
63 
65 
66 // Utility macros.
67 #undef unused
68 #define unused(...) G_GNUC_UNUSED __VA_ARGS__
69 
70 #undef cast
71 #define cast(a, b) (dynamic_cast<a>((b)))
72 #define instanceof(a, b) (cast (a,(b)) != nullptr)
73 
74 #define tryinsert(a, b, fn) \
75  (std::count ((b).begin (), (b).end (), (a)) == 0) \
76  ? ((b).fn (a), true) : false
77 
78 #define MAP_GET_IMPL(m, a, b) \
79  G_STMT_START \
80  { \
81  auto it = (m).find ((a)); \
82  if (it == (m).end ()) \
83  return false; \
84  tryset ((b), it->second); \
85  return true; \
86  } \
87  G_STMT_END \
88 
89 #define MAP_SET_IMPL(m, a, b) \
90  G_STMT_START \
91  { \
92  auto it = (m).find ((a)); \
93  (m)[(a)] = (b); \
94  return it == (m).end (); \
95  } \
96  G_STMT_END
97 
98 // Logging, warnings and errors.
99 #define GINGA_STRFUNC (__ginga_strfunc (G_STRFUNC)).c_str ()
100 string __ginga_strfunc (const string &);
101 #define __ginga_log(fn, fmt, ...)\
102  fn ("%s: " fmt, GINGA_STRFUNC, ## __VA_ARGS__)
103 
104 #define TRACE(fmt, ...) __ginga_log (g_debug, fmt, ## __VA_ARGS__)
105 #define WARNING(fmt, ...) __ginga_log (g_warning, fmt, ## __VA_ARGS__)
106 #define ERROR(fmt, ...) __ginga_log (g_error, fmt, ## __VA_ARGS__)
107 #define CRITICAL(fmt, ...) __ginga_log (g_critical, fmt, ## __VA_ARGS__)
108 
109 #define ERROR_NOT_IMPLEMENTED(fmt, ...)\
110  ERROR ("not implemented: " fmt, ## __VA_ARGS__)
111 
112 // Internal types.
113 typedef GdkRGBA Color;
114 typedef GdkRectangle Rect;
115 typedef GstClockTime Time;
116 
117 // Time macros and functions.
118 #define GINGA_TIME_NONE GST_CLOCK_TIME_NONE
119 #define GINGA_TIME_IS_VALID(t) GST_CLOCK_TIME_IS_VALID ((t))
120 #define GINGA_STIME_NONE GST_CLOCK_STIME_NONE
121 #define GINGA_STIME_IS_VALID(t) GST_CLOCK_STIME_IS_VALID ((t))
122 #define GINGA_SECOND GST_SECOND
123 #define GINGA_MSECOND GST_MSECOND
124 #define GINGA_USECOND GST_USECOND
125 #define GINGA_NSECOND GST_NSECOND
126 #define GINGA_TIME_AS_SECONDS(t) GST_TIME_AS_SECONDS ((t))
127 #define GINGA_TIME_AS_MSECONDS(t) GST_TIME_AS_MSECONDS ((t))
128 #define GINGA_TIME_AS_USECONDS(t) GST_TIME_AS_USECONDS ((t))
129 #define GINGA_TIME_AS_NSECONDS(t) GST_TIME_AS_NSECONDS ((t))
130 #define GINGA_TIME_DIFF(s,e) GST_CLOCK_DIFF ((s), (e))
131 #define GINGA_TIME_FORMAT GST_TIME_FORMAT
132 #define GINGA_TIME_ARGS(t) GST_TIME_ARGS ((t))
133 #define GINGA_STIME_FORMAT GST_STIME_FORMAT
134 #define GINGA_STIME_ARGS(t) GST_STIME_ARGS ((t))
135 
136 // Parsing and evaluation functions.
137 bool try_parse_bool (const string &, bool *);
138 bool parse_bool (const string &);
139 
140 bool try_parse_color (const string &, Color *);
141 Color parse_color (const string &);
142 
143 bool try_parse_list (const string &, char, size_t, size_t, list<string> *);
144 list<string> parse_list (const string &, char, size_t, size_t);
145 
146 bool try_parse_time (const string &, Time *);
147 Time parse_time (const string &);
148 
149 int parse_percent (const string &, int, int, int);
150 guint8 parse_pixel (const string &);
151 
152 // String functions.
153 bool _xstrtod (const string &, double *);
154 bool _xstrtoll (const string &, gint64 *, guint);
155 bool _xstrtoull (const string &, guint64 *, guint);
156 double xstrtod (const string &);
157 gint xstrtoint (const string &, guint8);
158 gint8 xstrtoint8 (const string &, guint8);
159 gint64 xstrtoint64 (const string &, guint8);
160 guint xstrtouint (const string &, guint8);
161 guint8 xstrtouint8 (const string &, guint8);
162 guint64 xstrtouint64 (const string &, guint8);
163 bool xstrispercent (const string &);
164 double xstrtodorpercent (const string &, bool *);
165 int xstrcasecmp (const string &, const string &);
166 #define xstrcaseeq(s1, s2) (xstrcasecmp ((s1), (s2)) == 0)
167 bool xstrhasprefix (const string &, const string &);
168 bool xstrhassuffix (const string &, const string &);
169 int G_GNUC_PRINTF (2,3) xstrassign (string &, const char *, ...);
170 string G_GNUC_PRINTF (1,2) xstrbuild (const char *, ...);
171 string xstrstrip (string);
172 list<string> xstrsplit (const string &, char);
173 
174 // Path functions.
175 string xpathbasename (string);
176 string xpathdirname (string);
177 bool xpathisabs (const string &);
178 bool xpathisuri (const string &);
179 string xpathmakeabs (string);
180 string xpathbuild (const string &, const string &);
181 string xpathbuildabs (const string &, const string &);
182 
183 // User data.
184 typedef void (*UserDataCleanFunc)(void *);
185 class UserData
186 {
187 public:
188  UserData ();
189  ~UserData ();
190  bool getData (const string &, void **);
191  bool setData (const string &, void *, UserDataCleanFunc fn=nullptr);
192 private:
193  map<string,pair<void *, void (*)(void *)>> _udata;
194 };
195 
197 using namespace ginga;
198 
199 #endif // AUX_GINGA_H
GdkRGBA Color
Definition: aux-ginga.h:113
#define GINGA_PRAGMA_DIAG_PUSH
Definition: aux-ginga.h:29
list< string > parse_list(const string &, char, size_t, size_t)
Definition: aux-ginga.cpp:186
#define GINGA_PRAGMA_DIAG_POP
Definition: aux-ginga.h:30
Color parse_color(const string &)
string __ginga_strfunc(const string &)
Parses G_STRFUNC string to generate a log prefix.
Definition: aux-ginga.cpp:32
gint64 xstrtoint64(const string &, guint8)
string xpathdirname(string)
Returns the dirname of path.
Definition: aux-ginga.cpp:516
bool parse_bool(const string &)
guint64 xstrtouint64(const string &, guint8)
bool try_parse_bool(const string &, bool *)
Parses boolean string.
Definition: aux-ginga.cpp:58
string xpathbuildabs(const string &, const string &)
Builds an absolute path from the given components.
Definition: aux-ginga.cpp:577
int parse_percent(const string &, int, int, int)
Parses number or percent string to an integer.
Definition: aux-ginga.cpp:203
bool xpathisabs(const string &)
Checks if path is absolute.
Definition: aux-ginga.cpp:528
bool xstrhassuffix(const string &, const string &)
Tests string suffix.
Definition: aux-ginga.cpp:411
guint8 parse_pixel(const string &)
Parses pixel string to an integer.
Definition: aux-ginga.cpp:227
int G_GNUC_PRINTF(2, 3) xstrassign(string &
#define GINGA_NAMESPACE_END
Definition: aux-ginga.h:62
string xstrbuild(const char *format,...)
Builds string from format.
Definition: aux-ginga.cpp:447
int const char string string xstrstrip(string)
Removes leading and trailing whitespace from string.
Definition: aux-ginga.cpp:470
guint8 xstrtouint8(const string &, guint8)
bool xpathisuri(const string &)
Checks if path is an URI.
Definition: aux-ginga.cpp:537
int xstrassign(string &s, const char *format,...)
Assigns format to string.
Definition: aux-ginga.cpp:423
#define GINGA_PRAGMA_DIAG_IGNORE
Definition: aux-ginga.h:31
gint xstrtoint(const string &, guint8)
Definition: aux-ginga.h:185
int xstrcasecmp(const string &, const string &)
Compares two strings ignoring case.
Definition: aux-ginga.cpp:387
#define GINGA_END_DECLS
Definition: ginga.h:26
double xstrtod(const string &)
Definition: aux-ginga.cpp:304
string xpathbasename(string)
Returns the basename of path.
Definition: aux-ginga.cpp:504
bool try_parse_time(const string &, Time *)
Definition: aux-ginga.cpp:134
bool try_parse_color(const string &, Color *)
Parses color string.
Definition: aux-ginga.cpp:83
Time parse_time(const string &)
#define GINGA_NAMESPACE_BEGIN
Definition: aux-ginga.h:61
#define GINGA_BEGIN_DECLS
Definition: ginga.h:25
bool _xstrtoull(const string &, guint64 *, guint)
Converts string to an unsigned 64-bit integer.
Definition: aux-ginga.cpp:287
void(* UserDataCleanFunc)(void *)
Definition: aux-ginga.h:184
gint8 xstrtoint8(const string &, guint8)
double xstrtodorpercent(const string &, bool *)
Converts number or percent string to floating-point number.
Definition: aux-ginga.cpp:364
guint xstrtouint(const string &, guint8)
bool try_parse_list(const string &, char, size_t, size_t, list< string > *)
Parses list of string items.
Definition: aux-ginga.cpp:107
map< string, pair< void *, void(*)(void *)> > _udata
Definition: aux-ginga.h:193
bool _xstrtod(const string &, double *)
Converts string to a floating-point number.
Definition: aux-ginga.cpp:241
bool _xstrtoll(const string &, gint64 *, guint)
Converts string to a 64-bit integer.
Definition: aux-ginga.cpp:264
bool xstrhasprefix(const string &, const string &)
Tests string prefix.
Definition: aux-ginga.cpp:399
GdkRectangle Rect
Definition: aux-ginga.h:114
string xpathbuild(const string &, const string &)
Builds a path from the given components.
Definition: aux-ginga.cpp:564
GstClockTime Time
Definition: aux-ginga.h:115
bool xstrispercent(const string &)
Checks if string is a percent value.
Definition: aux-ginga.cpp:343
list< string > xstrsplit(const string &, char)
Splits strings according to separator.
Definition: aux-ginga.cpp:485
string xpathmakeabs(string)
Makes path absolute.
Definition: aux-ginga.cpp:547