[Nut-upsdev] libnutconf: specific C++ accessors technique proposition
VaclavKrpec at Eaton.com
VaclavKrpec at Eaton.com
Tue Dec 4 08:36:50 UTC 2012
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
-----------------------------
Eaton Elektrotechnika s.r.o. ~ S�dlo spolecnosti, jak je zaps�no v rejstr�ku: Kom�rovsk� 2406, Praha 9 - Horn� Pocernice, 193 00, Cesk� Republika ~ Jm�no, m�sto, kde byla spolecnost zaregistrov�na: Praha ~ Identifikacn� c�slo (ICO): 498 11 894
-----------------------------
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: redirect.cpp
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20121204/9793d3d6/attachment.ksh>
More information about the Nut-upsdev
mailing list