Peano
Loading...
Searching...
No Matches
DefaultSequence.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
3import os
5
6class DefaultSequence(object):
7 """
8 The default sequence sketches what Peano does if there's no main. You can
9 alter it. The project holds an instance of this object through its main
10 attribute. So it holds an instance of this class. As a consequence, you can
11 either change this object's attributes or you can replace this object if
12 the object of you choice.
13
14 Most people who wanna redefine the main create a subclass of DefaultSequence
15 and overwrite _get_header_file_template() and _get_implementation_file_template().
16 Some also redefine the default overwrite policy by changing the attribute
17 overwrite.
18 """
19 def __init__(self,project):
20 self.project = project
21 self.overwrite = False
22 self.d = {}
23 self.is_extended = False
24
26 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
27 return templatefile_prefix+".template.h"
28
30 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
31 return templatefile_prefix+".template.cpp"
32
33 def construct_output(self,output,main_name):
34 """
35 Pass in a version of output
36
37 main_name Is the name of you main file. By default, this might be
38 Main.cpp, but you might want to have different main files for
39 different experiments. Please do not give the file an extension.
40 """
41 output.makefile.add_h_file( main_name + ".h", generated=True )
42 output.makefile.add_cpp_file( main_name + ".cpp", generated=True )
43
44 header_file_template = self._get_header_file_template()
45 cpp_file_template = self._get_implementation_file_template()
46 self.d[ "MAIN_NAME" ] = main_name
47 self.d[ "HEADER_FILE_TEMPLATE" ] = os.path.basename(header_file_template)
48 self.d[ "CPP_FILE_TEMPLATE" ] = os.path.basename(cpp_file_template)
49 self.d[ "PROJECT_NAME" ] = self.project.project_name
50 self.d[ "SUBNAMESPACE" ] = ""
51 if self.project._subdirectory:
52 self.d[ "SUBNAMESPACE" ] = self.project._subdirectory + "::"
53 self.d[ "SUBDIRECTORY" ] = self.project.subdirectory
54 self.d[ "SUBDIRECTORIES" ] = []
55 if self.project.subdirectories:
56 for subdirectory in self.project.subdirectories:
57 self.d[ "SUBDIRECTORIES" ].append(subdirectory)
58
60 header_file_template,
61 cpp_file_template,
62 main_name,
63 self.project.rootnamespace,
64 "./",
65 self.d,
66 self.overwrite)
67 output.add(generated_files)
68
69 def merge(self, main):
70 """
71 Make subproject's data a part of the project
72 (will be extended)
73 """
74
75 self.is_extended = True
The default sequence sketches what Peano does if there's no main.
construct_output(self, output, main_name)
Pass in a version of output.
merge(self, main)
Make subproject's data a part of the project (will be extended)