Peano
Loading...
Searching...
No Matches
StepsToStepRepository.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3
4
6import os
7
8
10 def __init__(self,steps):
11 self.steps = steps
12 self.d = {}
13 self.d["FORWARD_DECLARATIONS"] = ""
14 self.d["ENUM_VARIANTS"] = ""
15 self.d["STRING_RETURN_CASE"] = ""
16 self.d["INT_RETURN_CASE"] = ""
17 self.d["STEP_RETURN_CASE"] = ""
18
19 def __get_full_namespace(self, step):
20 return step.namespace + [ "repositories" ] # self.steps._namespace
21
23 return "StepRepository"
24
25 def construct_output(self,output):
26 # print("steps._project.namespaces = ", self.steps._project.namespaces)
27 for i in range(len(self.steps._project.namespaces)):
28 namespace = self.steps._project.namespaces[i]
29 subdirectory = self.steps._project.subdirectories[i]
30 temporary_subdirectory = self.steps._project.temporary_subdirectories[i]
31 self.d["FORWARD_DECLARATIONS"] = ""
32 self.d["ENUM_VARIANTS"] = ""
33 self.d["STRING_RETURN_CASE"] = ""
34 self.d["INT_RETURN_CASE"] = ""
35 self.d["STEP_RETURN_CASE"] = ""
36 for step in self.steps._steps:
37 if step.namespace == namespace:
38 self.d["FORWARD_DECLARATIONS"] += " class " + step.name + ";\n"
39 self.d["ENUM_VARIANTS"] += ", " + step.name
40 self.d["STRING_RETURN_CASE"] += " case Steps::" + step.name + ": return \"" + step.name + "\";\n"
41 self.d["INT_RETURN_CASE"] += " case Steps::" + step.name + ": return " + str(self.steps._steps.index(step)+1) + ";\n"
42 self.d["STEP_RETURN_CASE"] += " case " + str(self.steps._steps.index(step)+1) + ": return Steps::" + step.name + ";\n"
43
44 # + " = peano4::parallel::Node::UndefProgramStep + " +
45 # print("steps.subdirectory = ", subdirectory, ", steps.namespace = ", namespace)
46
47 class_name = self.__get_class_name()
48 output.makefile.add_cpp_file( os.path.join(subdirectory, "repositories", class_name + ".cpp"), generated=True )
49 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
50 local_d = self.d.copy()
52 templatefile_prefix+".h.template",
53 templatefile_prefix+".cpp.template",
54 class_name,
55 namespace + ["repositories"],
56 os.path.join(temporary_subdirectory, "repositories"),
57 local_d,
58 True)
59 output.add(generated_files)
60 pass