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",
19 """/** %(project)s, %(desc)s.
20 Copyright (C) %(devyears)s, %(authors)s.
22 %(project)s is distributed under the terms of the %(license)s. See
23 the included file LICENSE for more information.
30 #ifndef %(includeGuard)s
31 #define %(includeGuard)s
40 #include "%(incPath)s"
46 #ifndef %(includeGuard)s
47 #define %(includeGuard)s
52 namespace %(namespace)s {""",
65 } // namespace %(namespace)s""",
75 self
.__name
= "Unknown name"
80 def setName(self
, name
):
83 def generate(self
, name
):
86 class CHeader(Generator
):
88 Generator
.__init
__(self
)
89 self
.setName("cheader")
91 def generate(self
, name
):
95 fp
= file(os
.path
.join(config
["incBase"], path
), "w")
97 includeGuard
= config
["guardBase"] + " " + name
.replace("/", " ")
99 index
= includeGuard
.find(" ")
100 if index
== -1: break
102 includeGuard
= includeGuard
[:index
] + includeGuard
[index
+1].upper() + includeGuard
[index
+2:]
107 fileConfig
["path"] = path
108 fileConfig
["includeGuard"] = includeGuard
110 fp
.write(config
["fileHeader"] % fileConfig
)
111 fp
.write(config
["cHeader"] % fileConfig
)
117 class CSource(Generator
):
119 Generator
.__init
__(self
)
120 self
.setName("csource")
122 def generate(self
, name
, incPath
=""):
123 path
= os
.path
.join(config
["srcBase"], name
)
129 fileConfig
["path"] = path
130 fileConfig
["incPath"] = incPath
132 fp
.write(fileConfig
["fileHeader"] % fileConfig
)
134 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")
167 includeGuard
= config
["guardBase"] + " " + name
.replace("/", "_")
168 includeGuard
= includeGuard
.replace("::", "_")
170 index
= includeGuard
.find(" ")
171 if index
== -1: break
173 includeGuard
= includeGuard
[:index
] + includeGuard
[index
+1].upper() + includeGuard
[index
+2:]
178 fileConfig
["path"] = filepath
179 fileConfig
["includeGuard"] = includeGuard
181 fp
.write(config
["fileHeader"] % fileConfig
)
182 fp
.write(config
["cppHeader"] % fileConfig
)
184 namespaceList
= name
.split("::")
185 if len(namespaceList
) != 1:
186 className
= namespaceList
[-1]
187 namespaceList
= namespaceList
[:-1]
188 for namespace
in namespaceList
:
189 fileConfig
["namespace"] = namespace
190 fp
.write(fileConfig
["openNamespace"] % fileConfig
)
192 fileConfig
["className"] = className
193 fp
.write(fileConfig
["cppClassDef"] % fileConfig
)
195 for namespace
in namespaceList
[::-1]:
196 fileConfig
["namespace"] = namespace
197 fp
.write(fileConfig
["closeNamespace"] % fileConfig
)
199 fp
.write(config
["cppHeaderEnd"] % fileConfig
)
205 class CppSource(Generator
):
207 Generator
.__init
__(self
)
208 self
.setName("cppsource")
210 def generate(self
, name
, incPath
=""):
211 path
= os
.path
.join(config
["srcBase"], name
)
212 path
= path
.replace("::", "/")
213 last
= path
.rfind("/")
215 path
= path
[:last
].lower() + path
[last
:]
221 fileConfig
["path"] = path
222 fileConfig
["incPath"] = incPath
224 fp
.write(fileConfig
["fileHeader"] % fileConfig
)
226 fp
.write(fileConfig
["cSource"] % fileConfig
)
228 namespaceList
= name
.split("::")
229 if len(namespaceList
) != 1:
230 className
= namespaceList
[-1]
231 namespaceList
= namespaceList
[:-1]
232 for namespace
in namespaceList
:
233 fileConfig
["namespace"] = namespace
234 fp
.write(fileConfig
["openNamespace"] % fileConfig
)
238 for namespace
in namespaceList
[::-1]:
239 fileConfig
["namespace"] = namespace
240 fp
.write(fileConfig
["closeNamespace"] % fileConfig
)
244 class CppGenerator(Generator
):
246 Generator
.__init
__(self
)
249 def generate(self
, name
):
250 incPath
= CppHeader().generate(name
)
251 CppSource().generate(name
, incPath
)
256 generatorMap
= dict()
257 def addGenerator(generator
):
258 generatorMap
[generator
.name()] = generator
260 addGenerator(CHeader())
261 addGenerator(CSource())
262 addGenerator(CGenerator())
264 addGenerator(CppHeader())
265 addGenerator(CppSource())
266 addGenerator(CppGenerator())
268 if len(sys
.argv
) < 3:
269 print "Usage:", sys
.argv
[0], "generator name1 [name2 name3 . . .]"
270 print "Where generator is one of:"
271 for g
in generatorMap
.values():
274 generator
= generatorMap
[sys
.argv
[1]]
276 for name
in sys
.argv
[2:]:
277 generator
.generate(name
)