2 Module that defines CPPComponent for SALOME components implemented in C++
5 from gener import Component, Invalid
6 from cpp_tmpl import initService, cxxService, hxxCompo, cxxCompo
7 from cpp_tmpl import compoEXEMakefile, compoMakefile, exeCPP
9 class CPPComponent(Component):
10 def __init__(self, name, services=None, libs="", rlibs="", includes="",
11 kind="lib", exe_path=None):
12 self.exe_path = exe_path
13 Component.__init__(self, name, services, impl="CPP", libs=libs,
14 rlibs=rlibs, includes=includes, kind=kind)
17 """ validate component definition parameters"""
18 Component.validate(self)
19 kinds = ("lib", "exe")
20 if self.kind not in kinds:
21 raise Invalid("kind must be one of %s" % kinds)
23 if self.kind == "exe" :
25 raise Invalid("exe_path must be defined for component %s" % self.name)
27 def makeCompo(self, gen):
28 """generate files for C++ component
30 return a dict where key is the file name and value is the content of the file
32 cxxfile = "%s.cxx" % self.name
33 hxxfile = "%s.hxx" % self.name
34 if self.kind == "lib":
35 return {"Makefile.am":compoMakefile.substitute(module=gen.module.name,
39 includes=self.includes),
40 cxxfile:self.makecxx(gen), hxxfile:self.makehxx(gen)}
41 if self.kind == "exe":
42 return {"Makefile.am":compoEXEMakefile.substitute(module=gen.module.name,
46 includes=self.includes),
47 self.name+".exe":exeCPP.substitute(compoexe=self.exe_path),
48 cxxfile:self.makecxx(gen, 1), hxxfile:self.makehxx(gen)}
50 def makehxx(self, gen):
51 """return a string that is the content of .hxx file
54 for serv in self.services:
55 service = " void %s(" % serv.name
56 service = service+gen.makeArgs(serv)+");"
57 services.append(service)
58 servicesdef = "\n".join(services)
59 return hxxCompo.substitute(component=self.name, module=gen.module.name,
60 servicesdef=servicesdef)
62 def makecxx(self, gen, exe=0):
63 """return a string that is the content of .cxx file
68 for serv in self.services:
69 defs.append(serv.defs)
70 service = cxxService.substitute(component=self.name, service=serv.name,
71 parameters=gen.makeArgs(serv),
72 body=serv.body, exe=exe)
74 for name, typ, dep in serv.instream:
75 streams.append(' create_calcium_port(this,"%s","%s","IN","%s");'% (name, typ, dep))
76 instream = "\n".join(streams)
78 for name, typ, dep in serv.outstream:
79 streams.append(' create_calcium_port(this,"%s","%s","OUT","%s");'% (name, typ, dep))
80 outstream = "\n".join(streams)
82 init = initService.substitute(component=self.name, service=serv.name,
83 instream=instream, outstream=outstream)
84 services.append(service)
86 return cxxCompo.substitute(component=self.name, module=gen.module.name,
87 exe=exe, exe_path=self.exe_path,
88 servicesdef="\n".join(defs),
89 servicesimpl="\n".join(services),
90 initservice='\n'.join(inits))