Ocean
Loading...
Searching...
No Matches
platform/apple/Utilities.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_APPLE_UTILITIES_H
9#define META_OCEAN_PLATFORM_APPLE_UTILITIES_H
10
12
13#include "ocean/base/Frame.h"
14
15namespace Ocean
16{
17
18namespace Platform
19{
20
21namespace Apple
22{
23
24/**
25 * This class implements utilitiy functions for Apple platforms.
26 * @ingroup platformapple
27 */
29{
30 public:
31
32 /**
33 * Converts a given string to a CFString reference object.
34 * Beware: The resulting string must be released via CFRelease once the string is not needed anymore.
35 * @param value The string to convert, may be empty
36 * @return The resulting converted string object
37 */
38 static ScopedCFStringRef toCFString(const std::string& value);
39
40 /**
41 * Converts a given string to a CFString reference object.
42 * Beware: The resulting string must be released via CFRelease once the string is not needed anymore.
43 * @param value The string to convert, may be empty
44 * @return The resulting converted string object
45 */
46 static ScopedCFStringRef toCFString(const std::wstring& value);
47
48 /**
49 * Creates an CGImage object for a given frame object.
50 * The frame data can either be copied or used only.<br>
51 * If the frame data is not copied, the frame data must exist as long as any related object exists relying on the resulting CGImage.<br>
52 * Beware: The caller has to release the image object by calling CGImageRelease.
53 *
54 * This function can be used to e.g., debug a Frame object within Xcode by using the `Quick look` functionality.
55 * Here is a code example how to debug the an image:
56 * @code
57 * #import <UIKit/UIKit.h>
58 *
59 * ScopedCGImageRef cgImage = Platform::Apple::Utilities::toCGImage(rgbFrame);
60 *
61 * // the following image object can be visualized in Xcode (via `Quick look`)
62 * UIImage* image = [[UIImage alloc] initWithCGImage:cgImage];
63 * @endcode
64 * @param frame The frame from which the CGImage object will be created
65 * @param copyData True, to create an CGImage object owning the frame data; False, to create an CGImageo object using the frame data only
66 * @return The resulting CGImage object, nullptr if the conversion failed
67 * @see asNSImageOrUIImage().
68 */
69 static ScopedCGImageRef toCGImage(const Frame& frame, bool copyData = true);
70
71 /**
72 * This function is a simple helper function to debug a frame on iOS or macOS.
73 * Within the function, Xcode's `Quick look` debugging functionality can be used to visualize the image's content.
74 * @param frame The frame to be debugged, must be valid
75 * @return True, if the frame could be handled
76 * @see toCGImage().
77 */
78 static bool asNSImageOrUIImage(const Frame& frame);
79
80 /**
81 * Shows a modal message box with a title, a message and an OK button.
82 * Beware: This function is not supported on iOS.
83 * @param title The title to be shown in the box
84 * @param message The message to be shown in the box
85 */
86 static void showMessageBox(const std::string& title, const std::string& message);
87
88 /**
89 * Returns the path to the document directory of the application.
90 * In a non-sandboxed application (e.g., a Mac console application), path will refer to the Documents folder in home.<br>
91 * In a sandboxed application (e.g., an iOS app), the path will refer to the Document folder of the app.<br>
92 * On iOS, you can use this path to the folder to e.g., to store files in the folder,<br>
93 * and you can access the data later using Apple's file sharing/accessing capabilities.
94 * Beware: You may need/want to add a 'UIFileSharingEnabled' key and a 'LSSupportsOpeningDocumentsInPlace' to the 'Info.plist' file of the application and set both to 'True'.
95 * @return The document directory's path
96 */
97 static std::string documentDirectory();
98
99 /**
100 * Returns whether the application's main window has exactly one supported interface orientation.
101 * <pre>
102 * device top
103 * ...........................
104 * . .
105 * . ^ .
106 * . Y | .
107 * . | .
108 * . | .
109 * . O ---------> .
110 * . / X .
111 * . / Z .
112 * . v .
113 * . .
114 * ...........................
115 * . home button .
116 * ...........................
117 * device bottom
118 * </pre>
119 * @param zAxisDegree The resulting angle of the supported orientation around the z-axis, possible values {-90, 0, 90, 180}
120 * @return True, if so
121 */
122 static bool hasFixedSupportedInterfaceOrientation(int& zAxisDegree);
123
124 /**
125 * Returns the application's version number.
126 * @param bundleShortVersion The resulting release version number of the bundle
127 * @param bundleVersionKey Optional resulting version key of the bundle, nullptr if not of interest
128 * @return True, if succeeded
129 */
130 static bool bundleVersion(std::string& bundleShortVersion, std::string* bundleVersionKey = nullptr);
131
132 /**
133 * Returns the application's identifier name.
134 * @param bundleIdentifier The resulting release identifier number of the bundle
135 * @param bundleIdentifierKey Optional resulting identifier key of the bundle, nullptr if not of interest
136 * @return True, if succeeded
137 */
138 static bool bundleIdentifier(std::string& bundleIdentifier, std::string* bundleIdentifierKey = nullptr);
139};
140
141}
142
143}
144
145}
146
147#endif // META_OCEAN_PLATFORM_APPLE_UTILITIES_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements utilitiy functions for Apple platforms.
Definition platform/apple/Utilities.h:29
static void showMessageBox(const std::string &title, const std::string &message)
Shows a modal message box with a title, a message and an OK button.
static bool bundleVersion(std::string &bundleShortVersion, std::string *bundleVersionKey=nullptr)
Returns the application's version number.
static ScopedCFStringRef toCFString(const std::string &value)
Converts a given string to a CFString reference object.
static bool hasFixedSupportedInterfaceOrientation(int &zAxisDegree)
Returns whether the application's main window has exactly one supported interface orientation.
static bool asNSImageOrUIImage(const Frame &frame)
This function is a simple helper function to debug a frame on iOS or macOS.
static ScopedCFStringRef toCFString(const std::wstring &value)
Converts a given string to a CFString reference object.
static std::string documentDirectory()
Returns the path to the document directory of the application.
static ScopedCGImageRef toCGImage(const Frame &frame, bool copyData=true)
Creates an CGImage object for a given frame object.
static bool bundleIdentifier(std::string &bundleIdentifier, std::string *bundleIdentifierKey=nullptr)
Returns the application's identifier name.
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition ScopedObject.h:166
The namespace covering the entire Ocean framework.
Definition Accessor.h:15