Ginga  0.13.6
 All Classes Namespaces Functions Variables
functions.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef _FUNCTIONS_H_
51 #define _FUNCTIONS_H_
52 
53 #include <fstream>
54 #include <string>
55 #include <vector>
56 #include <set>
57 #include <iostream>
58 #include <sstream>
59 #include <limits>
60 using namespace std;
61 
62 extern "C" {
63  #include <ctype.h>
64  #include <sys/stat.h>
65  #include <sys/types.h>
66 #ifdef _WIN32
67 #define _WINSOCKAPI_ // stops windows.h including winsock.h
68  #include <windows.h>
69  #include <io.h>
70  #include <time.h>
71  #include <direct.h>
72 #endif
73 #ifndef _WIN32
74  #include <sys/param.h>
75  #include <unistd.h>
76  #include <sys/time.h>
77 #endif
78  #include <errno.h>
79  #include <sys/timeb.h>
80  #include <pthread.h>
81 }
82 #include <math.h>
83 #include <string.h>
84 #include <stdlib.h>
85 #include <stdio.h>
86 #include <signal.h>
87 #include <string.h>
88 
89 #ifndef PATH_MAX
90 # define PATH_MAX 512
91 #endif
92 
93 #ifndef ARRAY_SIZE
94 # define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
95 #endif
96 
97 // Macros for namespace declaration.
98 
99 #define NAMESPACE_BEGIN(t) \
100  namespace t {
101 
102 #define NAMESPACE_BEGIN2(t1, t2) \
103  NAMESPACE_BEGIN (t1) NAMESPACE_BEGIN (t2)
104 
105 #define NAMESPACE_BEGIN3(t1, t2, t3) \
106  NAMESPACE_BEGIN2 (t1, t2) NAMESPACE_BEGIN (t3)
107 
108 #define NAMESPACE_BEGIN4(t1, t2, t3, t4) \
109  NAMESPACE_BEGIN3 (t1, t2, t3) NAMESPACE_BEGIN(t4)
110 
111 #define NAMESPACE_BEGIN5(t1, t2, t3, t4, t5) \
112  NAMESPACE_BEGIN4 (t1, t2, t3, t4) NAMESPACE_BEGIN (t5)
113 
114 #define NAMESPACE_END }
115 #define NAMESPACE_END2 }}
116 #define NAMESPACE_END3 }}}
117 #define NAMESPACE_END4 }}}}
118 #define NAMESPACE_END5 }}}}}
119 
120 #define NAMESPACE_TELEMIDIA_BEGIN \
121  NAMESPACE_BEGIN3 (br, pucrio, telemidia)
122 #define NAMESPACE_TELEMIDIA_END \
123  NAMESPACE_END3
124 
125 #define NAMESPACE_GINGA_BEGIN \
126  NAMESPACE_TELEMIDIA_BEGIN NAMESPACE_BEGIN (ginga)
127 #define NAMESPACE_GINGA_END \
128  NAMESPACE_TELEMIDIA_END NAMESPACE_END
129 
130 #define NAMESPACE_GINGA_CORE_BEGIN \
131  NAMESPACE_GINGA_BEGIN NAMESPACE_BEGIN (core)
132 #define NAMESPACE_GINGA_CORE_END \
133  NAMESPACE_GINGA_END NAMESPACE_END
134 
135 #define NAMESPACE_GINGA_CORE_PLAYER_BEGIN \
136  NAMESPACE_GINGA_CORE_BEGIN NAMESPACE_BEGIN (player)
137 #define NAMESPACE_GINGA_CORE_PLAYER_END \
138  NAMESPACE_GINGA_CORE_END NAMESPACE_END
139 
140 #define TELEMIDIA_UTIL_BEGIN_DECLS \
141  NAMESPACE_TELEMIDIA_BEGIN NAMESPACE_BEGIN (util)
142 #define TELEMIDIA_UTIL_END_DECLS \
143  NAMESPACE_TELEMIDIA_END NAMESPACE_END
144 
145 TELEMIDIA_UTIL_BEGIN_DECLS
146 
147 string ultostr(unsigned long int value);
148 double strUTCToSec(string utcValue);
149 string cvtPercentual(string value, bool* isPercentual);
150 void initTimeStamp();
151 void printTimeStamp();
152 string intToStrHexa(int value);
153 int strHexaToInt(string value);
154 string upperCase(string s);
155 string lowerCase(string s);
156 bool isNumeric(void* value);
157 string itos(double i);
158 float stof(string s);
159 float itof(int i);
160 vector<string>* split(string str, string token, string pos_delimiter = "");
161 string trim(string str);
162 float getPercentualValue(string value);
163 bool isPercentualValue(string value);
164 bool fileExists(string filename);
165 bool isDirectory(const char* path);
166 double NaN();
167 double infinity();
168 bool isNaN(double value);
169 bool isInfinity(double value);
170 double getCurrentTimeMillis();
171 
172 double getNextStepValue(
173  double currentStepValue,
174  double value,
175  int factor,
176  double time, double initTime, double dur, int stepSize);
177 
178 bool readPPMFile(char *fn, int &X, int &Y, unsigned char* &result);
179 bool readBMPFile(char *fn, int &X, int &Y, unsigned char* &result);
180 
181 bool ppmToJpeg(char *ppmfile, char *jpegfile, int quality);
182 bool bmpToJpeg(char *bmpfile, char *jpegfile, int quality);
183 
184 void str_replace_all(string &str, const string &find_what, const string &replace_with);
185 
186 TELEMIDIA_UTIL_END_DECLS
187 
188 #endif //_FUNCTIONS_H_