diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2016-10-15 10:38:54 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2016-10-20 15:59:30 -0500 |
| commit | ce8a467cade53b2cc88c86b9427a80ea7e526a78 (patch) | |
| tree | 7a56c63dd4dc04a79e9e7aeae169da4570838ef1 | |
| parent | 04e007f17c9f21cfee922d811a4433dd11243d39 (diff) | |
| download | sdbusplus-ce8a467cade53b2cc88c86b9427a80ea7e526a78.tar.gz sdbusplus-ce8a467cade53b2cc88c86b9427a80ea7e526a78.zip | |
sdbus++: use style-correct names for C++ methods
Add attribute conversions for 'name' to support camelCase,
CamelCase and snake_case naming styles. This is done using
the 'inflection' library. Convert server-header templates
to use these as appropriate.
Change-Id: I4cecaa0fc96de9b9156e9102ccb9bf0682c8a732
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | tools/sdbusplus/namedelement.py | 16 | ||||
| -rw-r--r-- | tools/templates/method.mako.prototype.hpp | 10 |
2 files changed, 21 insertions, 5 deletions
diff --git a/tools/sdbusplus/namedelement.py b/tools/sdbusplus/namedelement.py index ed989d1..24a2f1f 100644 --- a/tools/sdbusplus/namedelement.py +++ b/tools/sdbusplus/namedelement.py @@ -1,5 +1,21 @@ +import inflection + class NamedElement(object): def __init__(self, **kwargs): self.name = kwargs.pop('name', "unnamed") self.description = kwargs.pop('description', "") super(NamedElement, self).__init__(**kwargs) + + def __getattr__(self, name): + l = { 'CamelCase': lambda: inflection.camelize(self.name), + 'camelCase': lambda: inflection.camelize(self.name, False), + 'snake_case': lambda: inflection.underscore(self.name) }\ + .get(name) + + if l: + return l() + try: + return super(NamedElement,self).__getattr__(name) + except: + raise AttributeError("Attribute '%s' not found in %s.NamedElement" + % (name, self.__module__)) diff --git a/tools/templates/method.mako.prototype.hpp b/tools/templates/method.mako.prototype.hpp index 5055dbb..2718812 100644 --- a/tools/templates/method.mako.prototype.hpp +++ b/tools/templates/method.mako.prototype.hpp @@ -14,7 +14,7 @@ join([ parameter(p, defaultValue) for p in method.parameters ]) def parameter(p, defaultValue=False): - r = "%s %s" % (p.typeName, p.name) + r = "%s %s" % (p.typeName, p.camelCase) if defaultValue: r += default_value(p) return r @@ -34,17 +34,17 @@ % if len(method.parameters) != 0: * % for p in method.parameters: - * @param[in] ${p.name} - ${p.description.strip()} + * @param[in] ${p.camelCase} - ${p.description.strip()} % endfor % endif % if len(method.returns) != 0: * % for r in method.returns: - * @return ${r.name}[${r.typeName}] - ${r.description.strip()} + * @return ${r.camelCase}[${r.typeName}] - ${r.description.strip()} % endfor % endif */ - virtual ${cpp_return_type()} ${ method.name }( + virtual ${cpp_return_type()} ${ method.camelCase }( ${ parameters() }) = 0; ### ### Emit 'callback-header' @@ -52,6 +52,6 @@ % elif ptype == 'callback-header': /** @brief sd-bus callback for ${ method.name } */ - static int _callback_${ method.name }( + static int _callback_${ method.CamelCase }( sd_bus_message*, void*, sd_bus_error*); % endif |

