Skip to content
Snippets Groups Projects
Commit c177d182 authored by Ruben Heinrich's avatar Ruben Heinrich
Browse files

Moved functions to generate_functions

parent d8a6641d
No related branches found
No related tags found
4 merge requests!57 vtkdiff,!47 parameter,!37 process borehole heat exchanger,!2Basic import and export functionality
...@@ -189,95 +189,9 @@ analyse_xml <- function(path, pattern, element_name) { ...@@ -189,95 +189,9 @@ analyse_xml <- function(path, pattern, element_name) {
} }
#Experimental stuff
generate_from_element <- function(element_name, attrs, children) {
}
generate_class_from_element <- function(element_name, class_name = NULL) {
#Generate name of new class from element name if class_name is not specified
if(is.null(class_name)){
class_name <- snakecase::to_any_case(element_name, "snake")
}
generated_class <- structure(list(), class = class_name)
return(generated_class)
}
generate_validator_from_element <- function() {
}
#cat(generate_as_node_from_element("DataArray", c("SexyAttr")))
#'generate_as_node_from_element
#'@description Generates a method for the generic function as_node based on an XML element
#'@param element_name The name of the XML element to base the function on
#'@param attrs Optional: A list of element attributes
#'@param children Optional: A list of element children
generate_as_node_from_element <- function(element_name,
attrs = NULL,
children = NULL) {
attrs_snake_names <- sapply(attrs, snakecase::to_any_case, case = "snake")
children_snake_names <- sapply(children, snakecase::to_any_case, case = "snake")
element_snake_name <- snakecase::to_any_case(element_name, "snake")
f_name <- paste0("as_node.", element_snake_name)
#Is the child a parent itself?
is_parent = TRUE
func_str <- paste0(f_name, " <- function(obj) {\n")
node_name <- paste0(element_snake_name, "_node")
func_str <- paste0(func_str, "\t", node_name, " <- list(", element_name," = structure(list())\n")
#Add attributes
for(i in seq_len(length(attrs))){
nattr <- attrs_snake_names[[i]]
attr <- attrs[[i]]
func_str <- paste0(func_str, "\t", node_name, " <- add_attr(", node_name,
", obj$", nattr, ", '", attr, "')\n")
}
#Add children
for(i in seq_len(length(children))){
child_snake <- children_snake_names[[i]]
child <- children[[i]]
#If a child is a parent, either call as_node or adopt_nodes
if(is_parent){
if(1){
func_str <- paste0(func_str, "\t", node_name, " <- add_child(", node_name,
", obj$", child_snake, ", '", child, "')\n")
}else{
}
}else{
func_str <- paste0(func_str, "\t", node_name, " <- add_child(", node_name,
", obj$", child_snake, ")\n")
}
}
func_str <- paste0(func_str, "\t", "return(", node_name, ")\n")
func_str <- paste0(func_str, "}")
return(invisible(func_str))
}
#============================== HELPERS FOR analyse_xml ================================ #============================== HELPERS FOR analyse_xml ================================
#'get_required #'get_required
#'@description Helper function to mark required attributes or children from a vector of names and a #'@description Helper function to mark required attributes or children from a vector of names and a
#' vector of occurrence probabilities #' vector of occurrence probabilities
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment