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 self.d["FORWARD_DECLARATIONS"] = ""
31 self.d["ENUM_VARIANTS"] = ""
32 self.d["STRING_RETURN_CASE"] = ""
33 self.d["INT_RETURN_CASE"] = ""
34 self.d["STEP_RETURN_CASE"] = ""
35 for step in self.steps._steps:
36 if step.namespace == namespace:
37 self.d["FORWARD_DECLARATIONS"] += " class " + step.name + ";\n"
38 self.d["ENUM_VARIANTS"] += ", " + step.name
39 self.d["STRING_RETURN_CASE"] += " case Steps::" + step.name + ": return \"" + step.name + "\";\n"
40 self.d["INT_RETURN_CASE"] += " case Steps::" + step.name + ": return " + str(self.steps._steps.index(step)+1) + ";\n"
41 self.d["STEP_RETURN_CASE"] += " case " + str(self.steps._steps.index(step)+1) + ": return Steps::" + step.name + ";\n"
42
43 # + " = peano4::parallel::Node::UndefProgramStep + " +
44 # print("steps.subdirectory = ", subdirectory, ", steps.namespace = ", namespace)
45
46 class_name = self.__get_class_name()
47 output.makefile.add_cpp_file( subdirectory + "repositories" + "/" + class_name + ".cpp", generated=True )
48 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
49 local_d = self.d.copy()
51 templatefile_prefix+".h.template",
52 templatefile_prefix+".cpp.template",
53 class_name,
54 namespace + ["repositories"],
55 subdirectory + "repositories",
56 local_d,
57 True)
58 output.add(generated_files)
59 pass