Exemplo n.º 1
0
def print_get_child(name, child):
    print("SEXP ", common.create_get_name(name, child['name'], prefix="r_so"), "(SEXP self", sep ='', end='')
    if child.get("array", False):
        print(", SEXP index", end='')
    print(")")
    print("{")
    if child['type'] == "type_string":
        this_type = "char"
    elif child['type'] == "type_real":
        this_type = "double"
    elif child['type'] == "type_int":
        this_type = "int"
    else:
        this_type = "so_" + child['type']
    print("\t", this_type, " *child = ", common.create_get_name(name, child['name'], prefix="so"), "(R_ExternalPtrAddr(self)", sep='', end='')
    if child.get("array", False):
        print(", INTEGER(index)[0]", end='')
    print(");")
    if child['type'] == 'Table':
        print("\tSEXP result = table2df(child);")
    elif child['type'] == 'type_string':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_STRING(1));")
        print("\tSET_STRING_ELT(result, 0, mkChar(child));")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'type_real':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_NUMERIC(1));")
        print("\tREAL(result)[0] = *child;")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'type_int':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_INTEGER(1));")
        print("\tINTEGER(result)[0] = *child;")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'Matrix':
        print("\tSEXP result = matrix2Rmatrix(child);")
    else:
        print("\tSEXP result = R_MakeExternalPtr(child, R_NilValue, R_NilValue);")
    print("\treturn result;")
    print("}")
Exemplo n.º 2
0
Arquivo: R.py Projeto: rikardn/libsoc
def print_get_child(name, child):
    print("SEXP ", common.create_get_name(name, child['name'], prefix="r_so"), "(SEXP self", sep ='', end='')
    if child.get("array", False):
        print(", SEXP index", end='')
    print(")")
    print("{")
    if child['type'] == "type_string":
        this_type = "char"
    elif child['type'] == "type_real":
        this_type = "double"
    elif child['type'] == "type_int":
        this_type = "int"
    else:
        this_type = "so_" + child['type']
    print("\t", this_type, " *child = ", common.create_get_name(name, child['name'], prefix="so"), "(R_ExternalPtrAddr(self)", sep='', end='')
    if child.get("array", False):
        print(", INTEGER(index)[0]", end='')
    print(");")
    if child['type'] == 'Table':
        print("\tSEXP result = table2df(child);")
    elif child['type'] == 'type_string':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_STRING(1));")
        print("\tSET_STRING_ELT(result, 0, mkChar(child));")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'type_real':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_NUMERIC(1));")
        print("\tREAL(result)[0] = *child;")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'type_int':
        print("\tif (!child) {")
        print("\t\treturn R_NilValue;")
        print("\t}")
        print("\tSEXP result;")
        print("\tPROTECT(result = NEW_INTEGER(1));")
        print("\tINTEGER(result)[0] = *child;")
        print("\tUNPROTECT(1);")
    elif child['type'] == 'Matrix':
        print("\tSEXP result = matrix2Rmatrix(child);")
    else:
        print("\tSEXP result = R_MakeExternalPtr(child, R_NilValue, R_NilValue);")
    print("\treturn result;")
    print("}")
Exemplo n.º 3
0
def print_attribute_getter(name, attr):
    print("SEXP ", common.create_get_name(name, attr['name'], prefix="r_so"), "(SEXP self)", sep='')
    print("{")
    if attr['type'] == 'type_string': 
        print("\tchar *value = ", common.create_get_name(name, attr['name'], prefix="so"), "(R_ExternalPtrAddr(self));", sep='')
    elif attr['type'] == 'type_int':
        print("\tint *value = ", common.create_get_name(name, attr['name'], prefix="so"), "(R_ExternalPtrAddr(self));", sep='')
    print()
    print("\tSEXP result;")
    print()
    print("\tif (value) {")
    if attr['type'] == 'type_string':
        print("\t\tresult = PROTECT(NEW_STRING(1));")
        print("\t\tSET_STRING_ELT(result, 0, mkChar(value));")
    elif attr['type'] == 'type_int':
        print("\t\tresult = PROTECT(NEW_INTEGER(1));")
        print("\t\tINTEGER(result)[0] = *value;")
    print()
    print("\t\tUNPROTECT(1);")
    print("\t} else {")
    print("\t\tresult = R_NilValue;")
    print("\t}")
    print("\treturn result;")
    print("}")
Exemplo n.º 4
0
Arquivo: R.py Projeto: rikardn/libsoc
def print_attribute_getter(name, attr):
    print("SEXP ", common.create_get_name(name, attr['name'], prefix="r_so"), "(SEXP self)", sep='')
    print("{")
    if attr['type'] == 'type_string': 
        print("\tchar *value = ", common.create_get_name(name, attr['name'], prefix="so"), "(R_ExternalPtrAddr(self));", sep='')
    elif attr['type'] == 'type_int':
        print("\tint *value = ", common.create_get_name(name, attr['name'], prefix="so"), "(R_ExternalPtrAddr(self));", sep='')
    print()
    print("\tSEXP result;")
    print()
    print("\tif (value) {")
    if attr['type'] == 'type_string':
        print("\t\tresult = PROTECT(NEW_STRING(1));")
        print("\t\tSET_STRING_ELT(result, 0, mkChar(value));")
    elif attr['type'] == 'type_int':
        print("\t\tresult = PROTECT(NEW_INTEGER(1));")
        print("\t\tINTEGER(result)[0] = *value;")
    print()
    print("\t\tUNPROTECT(1);")
    print("\t} else {")
    print("\t\tresult = R_NilValue;")
    print("\t}")
    print("\treturn result;")
    print("}")