Search in sources :

Example 1 with Namespace

use of org.bytedeco.javacpp.annotation.Namespace in project bigbluebutton by bigbluebutton.

the class Generator method cppScopeName.

static String cppScopeName(Class<?> type) {
    String scopeName = "";
    while (type != null) {
        Namespace namespace = type.getAnnotation(Namespace.class);
        String spaceName = namespace == null ? "" : namespace.value();
        if (Pointer.class.isAssignableFrom(type) && (!baseClasses.contains(type) || type.isAnnotationPresent(Name.class))) {
            Name name = type.getAnnotation(Name.class);
            String s;
            if (name == null) {
                s = type.getName();
                int i = s.lastIndexOf("$");
                if (i < 0) {
                    i = s.lastIndexOf(".");
                }
                s = s.substring(i + 1);
            } else {
                s = name.value()[0];
            }
            if (spaceName.length() > 0 && !spaceName.endsWith("::")) {
                spaceName += "::";
            }
            spaceName += s;
        }
        if (scopeName.length() > 0 && !spaceName.endsWith("::")) {
            spaceName += "::";
        }
        scopeName = spaceName + scopeName;
        if ((namespace != null && namespace.value().length() == 0) || spaceName.startsWith("::")) {
            // user wants to reset namespace here
            break;
        }
        type = type.getDeclaringClass();
    }
    return scopeName;
}
Also used : CLongPointer(org.bytedeco.javacpp.CLongPointer) CharPointer(org.bytedeco.javacpp.CharPointer) IntPointer(org.bytedeco.javacpp.IntPointer) BytePointer(org.bytedeco.javacpp.BytePointer) PointerPointer(org.bytedeco.javacpp.PointerPointer) FunctionPointer(org.bytedeco.javacpp.FunctionPointer) LongPointer(org.bytedeco.javacpp.LongPointer) ShortPointer(org.bytedeco.javacpp.ShortPointer) BoolPointer(org.bytedeco.javacpp.BoolPointer) DoublePointer(org.bytedeco.javacpp.DoublePointer) FloatPointer(org.bytedeco.javacpp.FloatPointer) Pointer(org.bytedeco.javacpp.Pointer) SizeTPointer(org.bytedeco.javacpp.SizeTPointer) Namespace(org.bytedeco.javacpp.annotation.Namespace) Name(org.bytedeco.javacpp.annotation.Name)

Example 2 with Namespace

use of org.bytedeco.javacpp.annotation.Namespace in project bigbluebutton by bigbluebutton.

the class Generator method cppFunctionTypeName.

String[] cppFunctionTypeName(Method functionMethod) {
    String prefix, suffix;
    Class<?> type = functionMethod.getDeclaringClass();
    Convention convention = type.getAnnotation(Convention.class);
    String callingConvention = convention == null ? "" : convention.value() + " ";
    // for virtual functions, the namespace is managed by the enclosing class
    Namespace namespace = FunctionPointer.class.isAssignableFrom(type) ? type.getAnnotation(Namespace.class) : null;
    String spaceName = namespace == null ? "" : namespace.value();
    if (spaceName.length() > 0 && !spaceName.endsWith("::")) {
        spaceName += "::";
    }
    Class returnType = functionMethod.getReturnType();
    Class[] parameterTypes = functionMethod.getParameterTypes();
    Annotation[] annotations = functionMethod.getAnnotations();
    Annotation[][] parameterAnnotations = functionMethod.getParameterAnnotations();
    String[] returnTypeName = cppAnnotationTypeName(returnType, annotations);
    AdapterInformation returnAdapterInfo = adapterInformation(false, valueTypeName(returnTypeName), annotations);
    if (returnAdapterInfo != null && returnAdapterInfo.cast.length() > 0) {
        prefix = returnAdapterInfo.cast;
    } else {
        prefix = returnTypeName[0] + returnTypeName[1];
    }
    prefix += " (" + callingConvention + spaceName + "*";
    suffix = ")(";
    if (FunctionPointer.class.isAssignableFrom(type) && namespace != null && (parameterTypes.length == 0 || !Pointer.class.isAssignableFrom(parameterTypes[0]))) {
        logger.warn("First parameter of caller method call() or apply() for member function pointer " + type.getCanonicalName() + " is not a Pointer. Compilation will most likely fail.");
    }
    for (int j = namespace == null ? 0 : 1; j < parameterTypes.length; j++) {
        String[] paramTypeName = cppAnnotationTypeName(parameterTypes[j], parameterAnnotations[j]);
        AdapterInformation paramAdapterInfo = adapterInformation(false, valueTypeName(paramTypeName), parameterAnnotations[j]);
        if (paramAdapterInfo != null && paramAdapterInfo.cast.length() > 0) {
            suffix += paramAdapterInfo.cast + " arg" + j;
        } else {
            suffix += paramTypeName[0] + " arg" + j + paramTypeName[1];
        }
        if (j < parameterTypes.length - 1) {
            suffix += ", ";
        }
    }
    suffix += ")";
    if (type.isAnnotationPresent(Const.class)) {
        suffix += " const";
    }
    return new String[] { prefix, suffix };
}
Also used : FunctionPointer(org.bytedeco.javacpp.FunctionPointer) Namespace(org.bytedeco.javacpp.annotation.Namespace) Annotation(java.lang.annotation.Annotation) Convention(org.bytedeco.javacpp.annotation.Convention)

Example 3 with Namespace

use of org.bytedeco.javacpp.annotation.Namespace in project bigbluebutton by bigbluebutton.

the class Generator method cppScopeName.

static String cppScopeName(MethodInformation methodInfo) {
    String scopeName = cppScopeName(methodInfo.cls);
    if (methodInfo.method.isAnnotationPresent(Virtual.class)) {
        String subType = "JavaCPP_" + mangle(scopeName);
        scopeName = subType;
    }
    Namespace namespace = methodInfo.method.getAnnotation(Namespace.class);
    String spaceName = namespace == null ? "" : namespace.value();
    if ((namespace != null && namespace.value().length() == 0) || spaceName.startsWith("::")) {
        // user wants to reset namespace here
        scopeName = "";
    }
    if (scopeName.length() > 0 && !scopeName.endsWith("::")) {
        scopeName += "::";
    }
    scopeName += spaceName;
    if (spaceName.length() > 0 && !spaceName.endsWith("::")) {
        scopeName += "::";
    }
    return scopeName + methodInfo.memberName[0];
}
Also used : Namespace(org.bytedeco.javacpp.annotation.Namespace)

Aggregations

Namespace (org.bytedeco.javacpp.annotation.Namespace)3 FunctionPointer (org.bytedeco.javacpp.FunctionPointer)2 Annotation (java.lang.annotation.Annotation)1 BoolPointer (org.bytedeco.javacpp.BoolPointer)1 BytePointer (org.bytedeco.javacpp.BytePointer)1 CLongPointer (org.bytedeco.javacpp.CLongPointer)1 CharPointer (org.bytedeco.javacpp.CharPointer)1 DoublePointer (org.bytedeco.javacpp.DoublePointer)1 FloatPointer (org.bytedeco.javacpp.FloatPointer)1 IntPointer (org.bytedeco.javacpp.IntPointer)1 LongPointer (org.bytedeco.javacpp.LongPointer)1 Pointer (org.bytedeco.javacpp.Pointer)1 PointerPointer (org.bytedeco.javacpp.PointerPointer)1 ShortPointer (org.bytedeco.javacpp.ShortPointer)1 SizeTPointer (org.bytedeco.javacpp.SizeTPointer)1 Convention (org.bytedeco.javacpp.annotation.Convention)1 Name (org.bytedeco.javacpp.annotation.Name)1