[Nut-upsdev] libnutconf: specific C++ accessors technique proposition

Emilien Kia kiae.dev at gmail.com
Tue Dec 4 09:22:06 UTC 2012


Hi Vasek, Hi all,

although your technical proposition is funny, I am not sure it makes a
serious difference and a big advantage compared to simple getter/setter
function calling.
Moreover, I am not sure that this code will be really used widely. So the
user can call methods instead of using variable assignation.

Regards,

Emilien

PS: Sure your example/way is very interesting for C++ theory and exercises
;)


2012/12/4 <VaclavKrpec at eaton.com>

> Hello fellow developers,
>
> yesterday, I was thinking about how to implement specific config.
> attributes accessors in section-based nut config. files so that
> it's nice to use and consistent with NutConfiguration, UpsmonConfiguration
> and UpsdConfiguration config. classes (where it's done via Settable
> attributes).
>
> The GenericConfiguration class provides generic access to name/value
> items of config. sections. The specialised classes (like e.g.
> UpsConfiguration)
> shall inherit the mechanism from GenericConfiguration and are supposed to
> provide specialised (and typed) access to the config. attributes.
> Now, the obvious choice is to write getters/setters for them; however,
> this way, the access will be different than access to section-less config.
> files attributes.
> What I came with is a template class (see "redirect" in the sample code
> attached)
> that overloads the cast operator and the assignment operator (and possibly
> others)
> and therefore gives the user the possibility to execute code (the
> getters/setters)
> while the code looks just like r/w access to a variable (with certain
> restrictions, though).
>
> Now, the mechanism looks kind of cool, but is also a bit technically
> complex,
> not to mention that it's disputable whether such masking of code execution
> is a good idea.  I can imagine that it can be quite confusing for an
> outsider...
> So, do you think that it's worth it or should I better keep the code less
> "smart"
> but more simple (now, when I'm writing that, it seems to answer itself...)?
>
> Thanks for the consult,
>
> Regards,
>
> --
> Václav Krpec
> Network UPS Tools project
> Eaton Opensource Team
>
>
-------------- section suivante --------------
Une pi�ce jointe HTML a �t� enlev�e...
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20121204/4bc0550e/attachment.html>


More information about the Nut-upsdev mailing list