2 # -*- coding: utf-8 -*-
10 "desc": "a tool to visualize program behaviour in real time",
11 "authors": "Aesalon development team",
12 "license": "GNU GPLv3",
13 "devyears": "2009-2011",
14 "website": "http://aesalon.berlios.de/",
17 "guardBase": "Aesalon",
20 /** %(project)s, %(desc)s.
21 Copyright (C) %(devyears)s, %(authors)s.
23 %(project)s is distributed under the terms of the %(license)s. See
24 the included file LICENSE for more information.
31 #ifndef %(includeGuard)s
32 #define %(includeGuard)s
41 #include "%(incPath)s"
47 #ifndef %(includeGuard)s
48 #define %(includeGuard)s
53 namespace %(namespace)s {
66 } // namespace %(namespace)s
77 self
.__name
= "Unknown name"
82 def setName(self
, name
):
85 def generate(self
, name
):
88 class CHeader(Generator
):
90 Generator
.__init
__(self
)
91 self
.setName("cheader")
93 def generate(self
, name
):
97 fp
= file(os
.path
.join(config
["incBase"], path
), "w")
99 includeGuard
= config
["guardBase"] + " " + name
.replace("/", " ")
101 index
= includeGuard
.find(" ")
102 if index
== -1: break
104 includeGuard
= includeGuard
[:index
] + includeGuard
[index
+1].upper() + includeGuard
[index
+2:]
109 fileConfig
["path"] = path
110 fileConfig
["includeGuard"] = includeGuard
112 fp
.write(config
["fileHeader"] % fileConfig
)
113 fp
.write(config
["cHeader"] % fileConfig
)
119 class CSource(Generator
):
121 Generator
.__init
__(self
)
122 self
.setName("csource")
124 def generate(self
, name
, incPath
=""):
125 path
= os
.path
.join(config
["srcBase"], name
)
131 fileConfig
["path"] = path
132 fileConfig
["incPath"] = incPath
134 fp
.write(fileConfig
["fileHeader"] % fileConfig
)
136 fp
.write(fileConfig
["cSource"] % fileConfig
)
140 class CGenerator(Generator
):
142 Generator
.__init
__(self
)
145 def generate(self
, name
):
146 CHeader().generate(name
)
147 CSource().generate(name
, True)
151 class CppHeader(Generator
):
153 Generator
.__init
__(self
)
154 self
.setName("cppheader")
156 def generate(self
, name
):
158 path
= path
.replace("::", "/")
159 last
= path
.rfind("/")
161 path
= path
[:last
].lower() + path
[last
:]
163 filepath
= os
.path
.join(config
["incBase"], path
)
165 #fp = file(filepath, "w")
168 includeGuard
= config
["guardBase"] + " " + name
.replace("/", "_")
169 includeGuard
= includeGuard
.replace("::", "_")
171 index
= includeGuard
.find(" ")
172 if index
== -1: break
174 includeGuard
= includeGuard
[:index
] + includeGuard
[index
+1].upper() + includeGuard
[index
+2:]
179 fileConfig
["path"] = filepath
180 fileConfig
["includeGuard"] = includeGuard
182 fp
.write(config
["fileHeader"] % fileConfig
)
183 fp
.write(config
["cppHeader"] % fileConfig
)
185 namespaceList
= name
.split("::")
186 if len(namespaceList
) != 1:
187 className
= namespaceList
[-1]
188 namespaceList
= namespaceList
[:-1]
189 for namespace
in namespaceList
:
190 fileConfig
["namespace"] = namespace
191 fp
.write(fileConfig
["openNamespace"] % fileConfig
)
193 fileConfig
["className"] = className
194 fp
.write(fileConfig
["cppClassDef"] % fileConfig
)
196 for namespace
in namespaceList
[::-1]:
197 fileConfig
["namespace"] = namespace
198 fp
.write(fileConfig
["closeNamespace"] % fileConfig
)
200 fp
.write(config
["cppHeaderEnd"] % fileConfig
)
206 class CppSource(Generator
):
208 Generator
.__init
__(self
)
209 self
.setName("cppsource")
211 def generate(self
, name
, incPath
=""):
212 path
= os
.path
.join(config
["srcBase"], name
)
213 path
= path
.replace("::", "/")
214 last
= path
.rfind("/")
216 path
= path
[:last
].lower() + path
[last
:]
222 fileConfig
["path"] = path
223 fileConfig
["incPath"] = incPath
225 fp
.write(fileConfig
["fileHeader"] % fileConfig
)
227 fp
.write(fileConfig
["cSource"] % fileConfig
)
231 class CppGenerator(Generator
):
233 Generator
.__init
__(self
)
236 def generate(self
, name
):
237 incPath
= CppHeader().generate(name
)
238 CppSource().generate(name
, incPath
)
243 generatorMap
= dict()
244 def addGenerator(generator
):
245 generatorMap
[generator
.name()] = generator
247 addGenerator(CHeader())
248 addGenerator(CSource())
249 addGenerator(CGenerator())
251 addGenerator(CppHeader())
252 addGenerator(CppSource())
253 addGenerator(CppGenerator())
255 if len(sys
.argv
) < 3:
256 print "Usage:", sys
.argv
[0], "generator name1 [name2 name3 . . .]"
257 print "Where generator is one of:"
258 for g
in generatorMap
.values():
261 generator
= generatorMap
[sys
.argv
[1]]
263 for name
in sys
.argv
[2:]:
264 generator
.generate(name
)