Search in sources :

Example 6 with Const

use of org.bytedeco.javacpp.annotation.Const in project javacpp by bytedeco.

the class Generator method cppCastTypeName.

String[] cppCastTypeName(Class<?> type, Annotation... annotations) {
    String[] typeName = null;
    boolean warning = false, adapter = false;
    for (Annotation a : annotations) {
        if (a instanceof Cast) {
            warning = typeName != null;
            String prefix = ((Cast) a).value()[0], suffix = "";
            int templateCount = 0;
            for (int i = 0; i < prefix.length(); i++) {
                int c = prefix.charAt(i);
                if (c == '<') {
                    templateCount++;
                } else if (c == '>') {
                    templateCount--;
                } else if (templateCount == 0 && c == ')') {
                    suffix = prefix.substring(i).trim();
                    prefix = prefix.substring(0, i).trim();
                    break;
                }
            }
            typeName = prefix.length() > 0 ? new String[] { prefix, suffix } : null;
        } else if (a instanceof Const) {
            boolean[] b = ((Const) a).value();
            if ((b.length == 1 && !b[0]) || (b.length > 1 && !b[0] && !b[1])) {
                // not interested in const members
                continue;
            }
            if (warning = typeName != null) {
                // prioritize @Cast
                continue;
            }
            typeName = cppTypeName(type);
            if (b.length > 1 && b[1] && !typeName[0].endsWith(" const *")) {
                typeName[0] = valueTypeName(typeName) + " const *";
            }
            if (b.length > 0 && b[0] && !typeName[0].startsWith("const ")) {
                typeName[0] = "const " + typeName[0];
            }
            Annotation by = by(annotations);
            if (by instanceof ByPtrPtr) {
                typeName[0] += "*";
            } else if (by instanceof ByPtrRef) {
                typeName[0] += "&";
            }
        } else if (a instanceof Adapter || a.annotationType().isAnnotationPresent(Adapter.class)) {
            adapter = true;
        }
    }
    if (warning && !adapter) {
        logger.warn("Without \"Adapter\", \"Cast\" and \"Const\" annotations are mutually exclusive.");
    }
    if (typeName == null) {
        typeName = cppTypeName(type);
    }
    return typeName;
}
Also used : Cast(org.bytedeco.javacpp.annotation.Cast) ByPtrRef(org.bytedeco.javacpp.annotation.ByPtrRef) Const(org.bytedeco.javacpp.annotation.Const) Adapter(org.bytedeco.javacpp.annotation.Adapter) ByPtrPtr(org.bytedeco.javacpp.annotation.ByPtrPtr) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)6 Cast (org.bytedeco.javacpp.annotation.Cast)6 Const (org.bytedeco.javacpp.annotation.Const)6 Adapter (org.bytedeco.javacpp.annotation.Adapter)4 ByPtrPtr (org.bytedeco.javacpp.annotation.ByPtrPtr)4 ByPtrRef (org.bytedeco.javacpp.annotation.ByPtrRef)4 ByRef (org.bytedeco.javacpp.annotation.ByRef)2 ByVal (org.bytedeco.javacpp.annotation.ByVal)2 NoException (org.bytedeco.javacpp.annotation.NoException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1