MythTV  master
mythosxutils.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * = NAME
3  * util-osx.cpp
4  *
5  * = DESCRIPTION
6  * A few routines for extracting data (int/float)
7  * from OS X Core Foundation data structures
8  *
9  * = REVISION
10  * $Id$
11  *
12  * = AUTHORS
13  * Nigel Pearson
14  *****************************************************************************/
15 
16 // MythTV
17 #import "mythosxutils.h"
18 #import "mythutilscocoa.h"
19 
20 // OSX
21 #import <CoreFoundation/CFNumber.h>
22 
23 // Std
24 #include <cstdio>
25 
26 int get_int_CF(CFDictionaryRef dict, CFStringRef key)
27 {
28  CFNumberRef ref = (CFNumberRef)CFDictionaryGetValue(dict, key);
29  int val = 0;
30  if (!ref )
31  puts("get_int_CF() - Failed to get number reference");
32  else if (!CFNumberGetValue(ref, kCFNumberSInt32Type, &val))
33  puts("get_int_CF() - Failed to get 32bit int from number");
34  return val;
35 }
36 
37 float get_float_CF(CFDictionaryRef dict, CFStringRef key)
38 {
39  CFNumberRef ref = (CFNumberRef)CFDictionaryGetValue(dict, key);
40  float val = 0.0;
41  if (!ref )
42  puts("get_float_CF() - Failed to get number reference");
43  else if (!CFNumberGetValue(ref, kCFNumberFloatType, &val))
44  puts("get_float_CF() - Failed to get float from number");
45  return val;
46 }
47 
48 double get_double_CF(CFDictionaryRef dict, CFStringRef key)
49 {
50  CFNumberRef ref = (CFNumberRef)CFDictionaryGetValue(dict, key);
51  double val = 0.0;
52  if (!ref )
53  puts("get_float_CF() - Failed to get number reference");
54  else if (!CFNumberGetValue(ref, kCFNumberFloatType, &val))
55  puts("get_float_CF() - Failed to get float from number");
56  return val;
57 }
58 
59 bool get_bool_CF(CFDictionaryRef dict, CFStringRef key)
60 {
61  CFNumberRef ref = (CFNumberRef)CFDictionaryGetValue(dict, key);
62  bool val = false;
63  if (!ref)
64  puts("get_float_CF() - Failed to get number reference");
65  else if (!CFNumberGetValue(ref, kCFNumberFloatType, &val) )
66  puts("get_float_CF() - Failed to get float from number");
67  return val;
68 }
69 
70 CGDirectDisplayID GetOSXDisplay(WId win)
71 {
72  if (!win)
73  return 0;
74  return GetOSXCocoaDisplay((void*)win);
75 }
get_double_CF
double get_double_CF(CFDictionaryRef dict, CFStringRef key)
Definition: mythosxutils.cpp:48
mythosxutils.h
hardwareprofile.software.dict
dictionary dict
Definition: software.py:55
GetOSXCocoaDisplay
CGDirectDisplayID GetOSXCocoaDisplay(void *View)
Definition: mythutilscocoa.mm:13
get_float_CF
float get_float_CF(CFDictionaryRef dict, CFStringRef key)
Definition: mythosxutils.cpp:37
get_bool_CF
bool get_bool_CF(CFDictionaryRef dict, CFStringRef key)
Definition: mythosxutils.cpp:59
get_int_CF
int get_int_CF(CFDictionaryRef dict, CFStringRef key)
Definition: mythosxutils.cpp:26
GetOSXDisplay
CGDirectDisplayID GetOSXDisplay(WId win)
Definition: mythosxutils.cpp:70
mythutilscocoa.h