本文整理汇总了Java中org.bridj.Pointer.allocateBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Pointer.allocateBytes方法的具体用法?Java Pointer.allocateBytes怎么用?Java Pointer.allocateBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bridj.Pointer
的用法示例。
在下文中一共展示了Pointer.allocateBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValue
import org.bridj.Pointer; //导入方法依赖的package包/类
public String getValue() throws ClingoException {
Pointer<SizeT> size = Pointer.allocateSizeT();
handleError(LIB.clingo_configuration_value_get_size(pointer, key, size), "Error reading the configuration value size!");
Pointer<Byte> value = Pointer.allocateBytes(size.getInt());
handleError(LIB.clingo_configuration_value_get(pointer, key, value, size.getInt()), "Error reading the configuration value!");
return value.getCString();
}
示例2: toString
import org.bridj.Pointer; //导入方法依赖的package包/类
@Override
public String toString() {
Pointer<SizeT> size = Pointer.allocateSizeT();
handleRuntimeError(LIB.clingo_symbol_to_string_size(structObject, size), "Error reading the symbol string size!");
Pointer<Byte> string = Pointer.allocateBytes(size.getLong());
handleRuntimeError(LIB.clingo_symbol_to_string(structObject, string, size.getLong()), "Error reading the symbol string value!");
return string.getCString();
}
示例3: printModel
import org.bridj.Pointer; //导入方法依赖的package包/类
private static void printModel(Pointer<Pointer<clingo_control>> ctrl, Pointer<Pointer<clingo_model>> model) {
Set<String> result = new HashSet<>(RESULTS);
int show = (int) (clingo_show_type.clingo_show_type_shown.value);
Pointer<SizeT> atoms_n = Pointer.allocateSizeT();
// determine the number of (shown) symbols in the model
if (!LIB.clingo_model_symbols_size(model.get(), show, atoms_n)) {
error(ctrl, "Error create symbol size");
}
// allocate required memory to hold all the symbols
Pointer<Long> atoms = Pointer.allocateLongs(atoms_n.getLong());
// retrieve the symbols in the model
if (!LIB.clingo_model_symbols(model.get(), show, atoms, atoms_n.getLong())) {
error(ctrl, "Error create symbol symbols");
}
System.out.println("Model: ");
for (int i = 0; i < atoms_n.getLong(); i++) {
Long atom = atoms.get(i);
// determine size of the string representation of the next symbol in the model
Pointer<SizeT> size = Pointer.allocateSizeT();
LIB.clingo_symbol_to_string_size(atom, size);
// allocate required memory to hold the symbol's string
Pointer<Byte> string = Pointer.allocateBytes(size.getLong());
// retrieve the symbol's string
if (!LIB.clingo_symbol_to_string(atom, string, size.getLong())) {
error(ctrl, "Error symbol to string");
}
String st = string.getCString();
System.out.print(st);
Assert.assertTrue("Atom " + st + " does not exists in the result set", result.remove(st));
System.out.print(" -> ");
Pointer<Pointer<Long>> arguments = Pointer.allocatePointer(Long.class);
Pointer<SizeT> arguments_size = Pointer.allocateSizeT();
LIB.clingo_symbol_arguments(atom, arguments, arguments_size);
Pointer<Pointer<Byte>> name = Pointer.allocatePointer(Byte.class);
LIB.clingo_symbol_name(atom, name);
System.out.print("name=" + name.get().getCString());
System.out.print(",args=[");
Pointer<Integer> t = Pointer.allocateInt();
for (int a = 0; a < arguments_size.getLong(); a++) {
if (a > 0) {
System.out.print(",");
}
LIB.clingo_symbol_number(arguments.get().get(a), t);
System.out.print(t.get());
}
System.out.print("]");
System.out.println();
}
Assert.assertTrue("Result set is not empty!", result.isEmpty());
}