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, sources=None):
12 self.exe_path = exe_path
13 Component.__init__(self, name, services, impl="CPP", libs=libs,
14 rlibs=rlibs, includes=includes, kind=kind,
18 """ validate component definition parameters"""
19 Component.validate(self)
20 kinds = ("lib", "exe")
21 if self.kind not in kinds:
22 raise Invalid("kind must be one of %s" % kinds)
24 if self.kind == "exe" :
26 raise Invalid("exe_path must be defined for component %s" % self.name)
28 def makeCompo(self, gen):
29 """generate files for C++ component
31 return a dict where key is the file name and value is the content of the file
33 cxxfile = "%s.cxx" % self.name
34 hxxfile = "%s.hxx" % self.name
35 if self.kind == "lib":
36 sources = " ".join(self.sources)
37 return {"Makefile.am":compoMakefile.substitute(module=gen.module.name,
42 includes=self.includes),
43 cxxfile:self.makecxx(gen), hxxfile:self.makehxx(gen)}
44 if self.kind == "exe":
45 return {"Makefile.am":compoEXEMakefile.substitute(module=gen.module.name,
49 includes=self.includes),
50 self.name+".exe":exeCPP.substitute(compoexe=self.exe_path),
51 cxxfile:self.makecxx(gen, 1), hxxfile:self.makehxx(gen)}
53 def makehxx(self, gen):
54 """return a string that is the content of .hxx file
57 for serv in self.services:
58 service = " void %s(" % serv.name
59 service = service+gen.makeArgs(serv)+");"
60 services.append(service)
61 servicesdef = "\n".join(services)
62 return hxxCompo.substitute(component=self.name, module=gen.module.name,
63 servicesdef=servicesdef)
65 def makecxx(self, gen, exe=0):
66 """return a string that is the content of .cxx file
71 for serv in self.services:
72 defs.append(serv.defs)
73 service = cxxService.substitute(component=self.name, service=serv.name,
74 parameters=gen.makeArgs(serv),
75 body=serv.body, exe=exe)
77 for name, typ, dep in serv.instream:
78 streams.append(' create_calcium_port(this,"%s","%s","IN","%s");'% (name, typ, dep))
79 instream = "\n".join(streams)
81 for name, typ, dep in serv.outstream:
82 streams.append(' create_calcium_port(this,"%s","%s","OUT","%s");'% (name, typ, dep))
83 outstream = "\n".join(streams)
85 init = initService.substitute(component=self.name, service=serv.name,
86 instream=instream, outstream=outstream)
87 services.append(service)
89 return cxxCompo.substitute(component=self.name, module=gen.module.name,
90 exe=exe, exe_path=self.exe_path,
91 servicesdef="\n".join(defs),
92 servicesimpl="\n".join(services),
93 initservice='\n'.join(inits))