def generate_auto_functions(auto_function_objects, h_file_name): replacements = [ ["replace_file", "warning", get_script_dir() + "text_includes/warning.inc"] ] includes = [] auto_classes_h_file = File(open(get_script_dir() + "text_includes/auto_classes.h.skel").read(), replacements) auto_classes_cpp_file = File(open(get_script_dir() + "text_includes/auto_classes.cpp.skel").read(), replacements) auto_classes_cpp_file.replace_text("h_file", h_file_name) for auto_function in auto_function_objects: includes += auto_function.get_includes() auto_classes_h_file.insert_text("classes", auto_function.get_class()[0]) auto_classes_cpp_file.insert_text("classes", auto_function.get_class()[1]) auto_classes_h_file.insert_text("generators", auto_function.get_generator()[0]) auto_classes_cpp_file.insert_text("generators", auto_function.get_generator()[1]) auto_function_arg_string = "-".join([argl[0] for argl in auto_function.get_args()]) auto_classes_cpp_file.insert_text("addgenerators", File(open(get_script_dir() + "text_includes/add_to_return_vector.skel").read(), [["replace_text", "name", auto_function.get_name()], ["replace_text", "args", auto_function_arg_string]]).text) includes = ["#include " + name for name in includes] auto_classes_h_file.insert_text("include", "\n".join(includes)) auto_classes_cpp_file.replace_file("convert", get_script_dir() + "text_includes/ls_convert.inc") return [auto_classes_h_file.text, auto_classes_cpp_file.text]
def get_class(self): class_h_skel_file = open(self.script_dir + "text_includes/auto_function_class.h.skel") class_h_file = File(class_h_skel_file.read()) class_h_file.replace_text("name", self.get_name()) for var in self.get_section("global").split("\n"): if var != "": class_h_file.insert_text("vars", var + ";") if len(self.get_args()) == 0: class_cpp_skel_file = open( self.script_dir + "text_includes/auto_function_class_no_args.cpp.skel") else: class_cpp_skel_file = open( self.script_dir + "text_includes/auto_function_class.cpp.skel") class_cpp_file = File(class_cpp_skel_file.read()) class_cpp_file.replace_text("name", self.get_name()) class_cpp_file.replace_text("init_code", self.get_section_code("init")) class_cpp_file.replace_text("periodic_code", self.get_section_code("periodic")) return [class_h_file.text, class_cpp_file.text]
def generate_auto_functions(auto_function_objects, h_file_name): replacements = [[ "replace_file", "warning", get_script_dir() + "text_includes/warning.inc" ]] includes = [] auto_classes_h_file = File( open(get_script_dir() + "text_includes/auto_classes.h.skel").read(), replacements) auto_classes_cpp_file = File( open(get_script_dir() + "text_includes/auto_classes.cpp.skel").read(), replacements) auto_classes_cpp_file.replace_text("h_file", h_file_name) for auto_function in auto_function_objects: includes += auto_function.get_includes() auto_classes_h_file.insert_text("classes", auto_function.get_class()[0]) auto_classes_cpp_file.insert_text("classes", auto_function.get_class()[1]) auto_classes_h_file.insert_text("generators", auto_function.get_generator()[0]) auto_classes_cpp_file.insert_text("generators", auto_function.get_generator()[1]) auto_function_arg_string = "-".join( [argl[0] for argl in auto_function.get_args()]) auto_classes_cpp_file.insert_text( "addgenerators", File( open(get_script_dir() + "text_includes/add_to_return_vector.skel").read(), [["replace_text", "name", auto_function.get_name()], ["replace_text", "args", auto_function_arg_string]]).text) includes = ["#include " + name for name in includes] auto_classes_h_file.insert_text("include", "\n".join(includes)) auto_classes_cpp_file.replace_file( "convert", get_script_dir() + "text_includes/ls_convert.inc") return [auto_classes_h_file.text, auto_classes_cpp_file.text]
def get_class(self): class_h_skel_file = open(self.script_dir + "text_includes/auto_function_class.h.skel") class_h_file = File(class_h_skel_file.read()) class_h_file.replace_text("name", self.get_name()) for var in self.get_section("global").split("\n"): if var != "": class_h_file.insert_text("vars", var + " = 0;") class_cpp_skel_file = open(self.script_dir + "text_includes/auto_function_class.cpp.skel") class_cpp_file = File(class_cpp_skel_file.read()) class_cpp_file.replace_text("name", self.get_name()) class_cpp_file.replace_text("init_code", self.get_section_code("init")) class_cpp_file.replace_text("periodic_code", self.get_section_code("periodic")) return [class_h_file.text, class_cpp_file.text]