summaryrefslogtreecommitdiff
path: root/tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools.h')
-rw-r--r--tools.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools.h b/tools.h
index 22b7e99..95c35ff 100644
--- a/tools.h
+++ b/tools.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 2.2 2009/04/14 20:41:39 kls Exp $
+ * $Id: tools.h 2.4 2009/12/23 15:14:39 kls Exp $
*/
#ifndef __TOOLS_H
@@ -13,7 +13,9 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <float.h>
#include <iconv.h>
+#include <math.h>
#include <poll.h>
#include <stddef.h>
#include <stdint.h>
@@ -60,7 +62,7 @@ void syslog_with_tid(int priority, const char *format, ...) __attribute__ ((form
int BCD2INT(int x);
// Unfortunately there are no platform independent macros for unaligned
-// access. so we do it this way:
+// access, so we do it this way:
template<class T> inline T get_unaligned(T *p)
{
@@ -74,6 +76,14 @@ template<class T> inline void put_unaligned(unsigned int v, T* p)
((s *)p)->v = v;
}
+// Comparing doubles for equality is unsafe, but unfortunately we can't
+// overwrite operator==(double, double), so this will have to do:
+
+inline bool DoubleEqual(double a, double b)
+{
+ return fabs(a - b) <= DBL_EPSILON;
+}
+
// When handling strings that might contain UTF-8 characters, it may be necessary
// to process a "symbol" that consists of several actual character bytes. The
// following functions allow transparently accessing a "char *" string without
@@ -132,7 +142,8 @@ private:
public:
cCharSetConv(const char *FromCode = NULL, const char *ToCode = NULL);
///< Sets up a character set converter to convert from FromCode to ToCode.
- ///< If FromCode is NULL, the previously set systemCharacterTable is used.
+ ///< If FromCode is NULL, the previously set systemCharacterTable is used
+ ///< (or "UTF-8" if no systemCharacterTable has been set).
///< If ToCode is NULL, "UTF-8" is used.
~cCharSetConv();
const char *Convert(const char *From, char *To = NULL, size_t ToLength = 0);