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
)
138 class CGenerator(Generator
):
140 Generator
.__init
__(self
)
143 def generate(self
, name
):
144 CHeader().generate(name
)
145 CSource().generate(name
, True)
149 class CppHeader(Generator
):
151 Generator
.__init
__(self
)
152 self
.setName("cppheader")
154 def generate(self
, name
):
156 path
= path
.replace("::", "/")
157 last
= path
.rfind("/")
159 path
= path
[:last
].lower() + path
[last
:]
161 filepath
= os
.path
.join(config
["incBase"], path
)
163 fp
= file(filepath
, "w")
165 includeGuard
= config
["guardBase"] + " " + name
.replace("/", "_")
166 includeGuard
= includeGuard
.replace("::", "_")
168 index
= includeGuard
.find(" ")
169 if index
== -1: break
171 includeGuard
= includeGuard
[:index
] + includeGuard
[index
+1].upper() + includeGuard
[index
+2:]
176 fileConfig
["path"] = filepath
177 fileConfig
["includeGuard"] = includeGuard
179 fp
.write(config
["fileHeader"] % fileConfig
)
180 fp
.write(config
["cppHeader"] % fileConfig
)
182 namespaceList
= name
.split("::")
183 if len(namespaceList
) != 1:
184 className
= namespaceList
[-1]
185 namespaceList
= namespaceList
[:-1]
186 for namespace
in namespaceList
:
187 fileConfig
["namespace"] = namespace
188 fp
.write(fileConfig
["openNamespace"] % fileConfig
)
190 fileConfig
["className"] = className
191 fp
.write(fileConfig
["cppClassDef"] % fileConfig
)
193 for namespace
in namespaceList
[::-1]:
194 fileConfig
["namespace"] = namespace
195 fp
.write(fileConfig
["closeNamespace"] % fileConfig
)
197 fp
.write(config
["cppHeaderEnd"] % fileConfig
)
203 class CppSource(Generator
):
205 Generator
.__init
__(self
)
206 self
.setName("cppsource")
208 def generate(self
, name
, incPath
=""):
209 path
= os
.path
.join(config
["srcBase"], name
)
210 path
= path
.replace("::", "/")
211 last
= path
.rfind("/")
213 path
= path
[:last
].lower() + path
[last
:]
219 fileConfig
["path"] = path
220 fileConfig
["incPath"] = incPath
222 fp
.write(fileConfig
["fileHeader"] % fileConfig
)
224 fp
.write(fileConfig
["cSource"] % fileConfig
)
226 namespaceList
= name
.split("::")
227 if len(namespaceList
) != 1:
228 className
= namespaceList
[-1]
229 namespaceList
= namespaceList
[:-1]
230 for namespace
in namespaceList
:
231 fileConfig
["namespace"] = namespace
232 fp
.write(fileConfig
["openNamespace"] % fileConfig
)
236 for namespace
in namespaceList
[::-1]:
237 fileConfig
["namespace"] = namespace
238 fp
.write(fileConfig
["closeNamespace"] % fileConfig
)
242 class CppGenerator(Generator
):
244 Generator
.__init
__(self
)
247 def generate(self
, name
):
248 incPath
= CppHeader().generate(name
)
249 CppSource().generate(name
, incPath
)
254 generatorMap
= dict()
255 def addGenerator(generator
):
256 generatorMap
[generator
.name()] = generator
258 addGenerator(CHeader())
259 addGenerator(CSource())
260 addGenerator(CGenerator())
262 addGenerator(CppHeader())
263 addGenerator(CppSource())
264 addGenerator(CppGenerator())
266 if len(sys
.argv
) < 3:
267 print "Usage:", sys
.argv
[0], "generator name1 [name2 name3 . . .]"
268 print "Where generator is one of:"
269 for g
in generatorMap
.values():
272 generator
= generatorMap
[sys
.argv
[1]]
274 for name
in sys
.argv
[2:]:
275 generator
.generate(name
)