Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2013-2015 RoboVM AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bugvm.apple.corefoundation;
/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.dispatch.*;
import com.bugvm.apple.coreservices.*;
import com.bugvm.apple.coremedia.*;
import com.bugvm.apple.uikit.*;
import com.bugvm.apple.coretext.*;
/**/
import com.bugvm.apple.foundation.NSObject;
import com.bugvm.apple.foundation.NSString;
import com.bugvm.apple.foundation.NSObject.NSObjectPtr;
/**/
/**/
/**/@Library("CoreFoundation")/**/
/**/public/**/ class /**/CFArray/**/
extends /**/CFPropertyList/**/
/**//**/ {
public static class AsStringListMarshaler {
@MarshalsPointer
public static List toObject(Class extends CFType> cls, long handle, long flags) {
CFArray o = (CFArray) CFType.Marshaler.toObject(cls, handle, flags);
if (o == null) {
return null;
}
return o.asStringList();
}
@MarshalsPointer
public static long toNative(List l, long flags) {
if (l == null) {
return 0L;
}
return CFType.Marshaler.toNative(CFArray.fromStrings(l), flags);
}
}
/**/public static class CFArrayPtr extends Ptr {}/**/
/**/static { Bro.bind(CFArray.class); }/**/
/**//**/
/**/
protected CFArray() {}
/**/
/**//**/
/**//**/
public static CFArray create(Collection objects) {
if (objects == null) {
throw new NullPointerException("objects");
}
if (objects.size() == 0 || objects.iterator().next() instanceof CFType) {
return create(objects.toArray(new CFType[objects.size()]));
}
if (objects.iterator().next() instanceof NSObject) {
return create(objects.toArray(new NSObject[objects.size()]));
}
throw new IllegalArgumentException("items can only be of type CFType or NSObject!");
}
public static CFArray create(NSObject ... objects) {
if (objects == null) {
throw new NullPointerException("objects");
}
if (objects.length == 0) {
return create(null, null, 0, getTypeCallBacks());
}
NSObjectPtr values = Struct.allocate(NSObjectPtr.class, objects.length);
values.set(objects);
return create(null, values.as(VoidPtr.VoidPtrPtr.class), objects.length, getTypeCallBacks());
}
public static CFArray create(CFType ... objects) {
if (objects == null) {
throw new NullPointerException("objects");
}
if (objects.length == 0) {
return create(null, null, 0, getTypeCallBacks());
}
CFTypePtr values = Struct.allocate(CFTypePtr.class, objects.length);
values.set(objects);
return create(null, values.as(VoidPtr.VoidPtrPtr.class), objects.length, getTypeCallBacks());
}
@SuppressWarnings("unchecked")
public T[] toArray(Class type) {
T[] result = (T[]) java.lang.reflect.Array.newInstance(type, (int) getCount());
for (int i = 0; i < result.length; i++) {
result[i] = get(i, type);
}
return result;
}
public List toList(Class type) {
int size = (int) size();
List result = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
result.add(get(i, type));
}
return result;
}
public T get(@MachineSizedSInt long index, Class type) {
return getValueAtIndex(index).as(type);
}
public @MachineSizedSInt long size() {
return getCount();
}
public void add(NativeObject value) {
throw new UnsupportedOperationException("CFArray is immutable. Use CFMutableArray instead!");
}
public void insert(@MachineSizedSInt long idx, NativeObject value) {
throw new UnsupportedOperationException("CFArray is immutable. Use CFMutableArray instead!");
}
public void replace(@MachineSizedSInt long idx, NativeObject value) {
throw new UnsupportedOperationException("CFArray is immutable. Use CFMutableArray instead!");
}
public void remove(@MachineSizedSInt long idx) {
throw new UnsupportedOperationException("CFArray is immutable. Use CFMutableArray instead!");
}
public void clear() {
throw new UnsupportedOperationException("CFArray is immutable. Use CFMutableArray instead!");
}
/**
* Use this method to convert a CFArray of CFString items to a List of String items.
* @return
*/
public List asStringList() {
List list = new ArrayList<>();
if (size() == 0)
return list;
for (int i = 0; i < size(); i++) {
list.add(get(i, CFString.class).toString());
}
return list;
}
public static CFArray fromStrings (String... strings) {
int length = strings.length;
CFString[] cfStrings = new CFString[length];
for (int i = 0; i < length; i++) {
cfStrings[i] = new CFString(strings[i]);
}
return CFArray.create(cfStrings);
}
public static CFArray fromStrings (Collection strings) {
CFString[] cfStrings = new CFString[strings.size()];
int i = 0;
for (String s : strings) {
cfStrings[i] = new CFString(s);
i++;
}
return CFArray.create(cfStrings);
}
/**/
@GlobalValue(symbol="kCFTypeArrayCallBacks", optional=true)
public static native @ByVal CFArrayCallBacks getTypeCallBacks();
@Bridge(symbol="CFArrayGetTypeID", optional=true)
public static native @MachineSizedUInt long getClassTypeID();
@Bridge(symbol="CFArrayCreate", optional=true)
private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFArray create(CFAllocator allocator, VoidPtr.VoidPtrPtr values, @MachineSizedSInt long numValues, CFArrayCallBacks callBacks);
@Bridge(symbol="CFArrayCreateCopy", optional=true)
private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFArray createCopy(CFAllocator allocator, CFArray theArray);
@Bridge(symbol="CFArrayGetCount", optional=true)
protected native @MachineSizedSInt long getCount();
@Bridge(symbol="CFArrayGetCountOfValue", optional=true)
protected native @MachineSizedSInt long getCountOfValue(@ByVal CFRange range, VoidPtr value);
@Bridge(symbol="CFArrayContainsValue", optional=true)
protected native boolean containsValue(@ByVal CFRange range, VoidPtr value);
@Bridge(symbol="CFArrayGetValueAtIndex", optional=true)
protected native VoidPtr getValueAtIndex(@MachineSizedSInt long idx);
@Bridge(symbol="CFArrayGetValues", optional=true)
protected native void getValues(@ByVal CFRange range, VoidPtr.VoidPtrPtr values);
@Bridge(symbol="CFArrayApplyFunction", optional=true)
protected native void applyFunction(@ByVal CFRange range, FunctionPtr applier, VoidPtr context);
@Bridge(symbol="CFArrayGetFirstIndexOfValue", optional=true)
protected native @MachineSizedSInt long getFirstIndexOfValue(@ByVal CFRange range, VoidPtr value);
@Bridge(symbol="CFArrayGetLastIndexOfValue", optional=true)
protected native @MachineSizedSInt long getLastIndexOfValue(@ByVal CFRange range, VoidPtr value);
@Bridge(symbol="CFArrayBSearchValues", optional=true)
protected native @MachineSizedSInt long bSearchValues(@ByVal CFRange range, VoidPtr value, FunctionPtr comparator, VoidPtr context);
/**/
}