Ginga  0.13.6.2086-83aa
The iTV middleware.
aux-ginga.h
1 /* Copyright (C) 2006-2018 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 <https://www.gnu.org/licenses/>. */
17 
18 #ifndef AUX_GINGA_H
19 #define AUX_GINGA_H
20 
21 #include "ginga.h"
22 
23 GINGA_BEGIN_DECLS
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 
41 GINGA_PRAGMA_DIAG_PUSH ()
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>
47 GINGA_PRAGMA_DIAG_POP ()
48 
49 GINGA_END_DECLS
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 
64 GINGA_NAMESPACE_BEGIN
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 // Numeric functions.
137 bool floateq (double, double, double epsilon=.0000001);
138 #define doubleeq floateq
139 
140 // Parsing and evaluation functions.
141 bool try_parse_bool (const string &, bool *);
142 bool parse_bool (const string &);
143 
144 bool try_parse_color (const string &, Color *);
145 Color parse_color (const string &);
146 
147 bool try_parse_list (const string &, char, size_t, size_t, list<string> *);
148 list<string> parse_list (const string &, char, size_t, size_t);
149 
150 bool try_parse_table (const string &, map<string, string> *);
151 map<string, string> parse_table (const string &);
152 
153 bool try_parse_time (const string &, Time *);
154 Time parse_time (const string &);
155 
156 int parse_percent (const string &, int, int, int);
157 guint8 parse_pixel (const string &);
158 
159 // String functions.
160 bool _xstrtod (const string &, double *);
161 bool _xstrtoll (const string &, gint64 *, guint);
162 bool _xstrtoull (const string &, guint64 *, guint);
163 double xstrtod (const string &);
164 gint xstrtoint (const string &, guint8);
165 gint8 xstrtoint8 (const string &, guint8);
166 gint64 xstrtoint64 (const string &, guint8);
167 guint xstrtouint (const string &, guint8);
168 guint8 xstrtouint8 (const string &, guint8);
169 guint64 xstrtouint64 (const string &, guint8);
170 bool xstrispercent (const string &);
171 double xstrtodorpercent (const string &, bool *);
172 int xstrcasecmp (const string &, const string &);
173 #define xstrcaseeq(s1, s2) (xstrcasecmp ((s1), (s2)) == 0)
174 bool xstrhasprefix (const string &, const string &);
175 bool xstrhassuffix (const string &, const string &);
176 int G_GNUC_PRINTF (2,3) xstrassign (string &, const char *, ...);
177 string G_GNUC_PRINTF (1,2) xstrbuild (const char *, ...);
178 string xstrstrip (string);
179 list<string> xstrsplit (const string &, char);
180 
181 // Path functions.
182 string xpathbasename (string);
183 string xpathdirname (string);
184 bool xpathisabs (const string &);
185 bool xpathisuri (const string &);
186 string xpathmakeabs (string);
187 string xpathbuild (const string &, const string &);
188 string xpathbuildabs (const string &, const string &);
189 
190 // User data.
191 typedef void (*UserDataCleanFunc)(void *);
192 class UserData
193 {
194 public:
195  UserData ();
196  ~UserData ();
197  bool getData (const string &, void **);
198  bool setData (const string &, void *, UserDataCleanFunc fn=nullptr);
199 private:
200  map<string,pair<void *, void (*)(void *)>> _udata;
201 };
202 
203 GINGA_NAMESPACE_END
204 using namespace ginga;
205 
206 #endif // AUX_GINGA_H
Definition: aux-ginga.h:192
The libginga API.