Need to parse an "ini" file which configures one or more sensors. The sensors can be of the same type and are identified by "name", "type" and an "id" Some configuration items are for all sensors Other configuration tiems are only for some sensors. [sensor] SensorName="Outdoor Temp" SensorType=1 # Temp Sensor SensorID=1000 SerialNumber="12344" Active=1 Device="/dev/ttyUSB01" [sensor] SensorName="Indoor Temp" SensorType=1 # Temp Sensor SensorID=1001 SerialNumber="12345" Active=1 Device="/dev/USB02" [sensor] SensorName="Light" SensorType=2 # Light Sensor SensorID=1002 SerialNumber="12349" Active=1 Device="/dev/ttyUSB02" MaxLumen="500" Is having multiple identical section names possible with boost program options? It is of course possible to do [sensor_1] ... [sensor_2] ... [sensor_3] ... but that is not so nice looking, and you get a hard limit on the number of sensors you can attach. Ideas? BR Ulf Samuelsson
I don't think that can work. Although I use Windows functions (GetPrivateProfileString etc) to do this I've had a quick look at the Boost documentation and it looks like what I'm about to say is the same for Boost's handing of property maps and ini files. You can't duplicate the [sensor] section as you then have no way of selecting which one you want. The functions take section name and key name and return a value, so if a section name is duplicated the system doesn't know which section you want. Should sensor.SensorName return "Outdoor Temp" or "Indoor Temp" ? In similar cases we do it like this : [sensor_1] ... [sensor_2] ... [sensor_3] ... This means you've got unique section names. "you get a hard limit" Why do you think that ? Either hold a separate value for the number of sensors, or attempt to read in order and stop when one is missing (this adds a rule that the ones you're using must be consecutive). Regards, Richard. Richard Kerry BNCS Engineer, SI SOL Telco & Media Vertical Practice T: +44 (0)20 82259063 M: +44 (0)7812 325518 G300, Stadium House, Wood Lane, London, W12 7TA richard.kerry@atos.nethttps://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitte ________________________________ From: Boost-users [boost-users-bounces@lists.boost.org] on behalf of Ulf Samuelsson [boost-user@emagii.com] Sent: 18 September 2013 17:28 To: boost-users@lists.boost.org Subject: [Boost-users] Multiple instance of options Need to parse an "ini" file which configures one or more sensors. The sensors can be of the same type and are identified by "name", "type" and an "id" Some configuration items are for all sensors Other configuration tiems are only for some sensors. [sensor] SensorName="Outdoor Temp" SensorType=1 # Temp Sensor SensorID=1000 SerialNumber="12344" Active=1 Device="/dev/ttyUSB01" [sensor] SensorName="Indoor Temp" SensorType=1 # Temp Sensor SensorID=1001 SerialNumber="12345" Active=1 Device="/dev/USB02" [sensor] SensorName="Light" SensorType=2 # Light Sensor SensorID=1002 SerialNumber="12349" Active=1 Device="/dev/ttyUSB02" MaxLumen="500" Is having multiple identical section names possible with boost program options? It is of course possible to do [sensor_1] ... [sensor_2] ... [sensor_3] ... but that is not so nice looking, and you get a hard limit on the number of sensors you can attach. Ideas? BR Ulf Samuelsson _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 2013-09-20 09:34, Kerry, Richard wrote:
I don't think that can work.
Although I use Windows functions (GetPrivateProfileString etc) to do this I've had a quick look at the Boost documentation and it looks like what I'm about to say is the same for Boost's handing of property maps and ini files.
You can't duplicate the [sensor] section as you then have no way of selecting which one you want.
If I look at an xorg.conf file I find: Section "Monitor" Identifier "VG2021m" Option "DPMS" HorizSync 28-65 VertRefresh 57-63 VendorName "Viewsonic" # More Options... EndSection Section "Monitor" Identifier "SyncMaster-245B" Option "DPMS" HorizSync 30-81 VertRefresh 56-75 VendorName "Samsung" # More Options EndSection so it is not impossible. The "Identifier" allows you to differentiate between the two.
The functions take section name and key name and return a value, so if a section name is duplicated the system doesn't know which section you want.
Should sensor.SensorName return "Outdoor Temp" or "Indoor Temp" ?
In similar cases we do it like this :
[sensor_1] ... [sensor_2] ... [sensor_3] ...
This means you've got unique section names.
"you get a hard limit"
Why do you think that ?
Either hold a separate value for the number of sensors, or attempt to read in order and stop when one is missing (this adds a rule that the ones you're using must be consecutive).
Have not read all documentation yet, but don't I have to determine at compile time which sections that can be in the ini file. Regards, Ulf
Regards,
Richard.
*Richard Kerry*
BNCS Engineer, SI SOL Telco & Media Vertical Practice
T: +44 (0)20 82259063
M: +44 (0)7812 325518
G300, Stadium House, Wood Lane, London, W12 7TA
richard.kerry@atos.net https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net
This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitte
------------------------------------------------------------------------ *From:* Boost-users [boost-users-bounces@lists.boost.org] on behalf of Ulf Samuelsson [boost-user@emagii.com] *Sent:* 18 September 2013 17:28 *To:* boost-users@lists.boost.org *Subject:* [Boost-users] Multiple instance of options
Need to parse an "ini" file which configures one or more sensors.
The sensors can be of the same type and are identified by "name", "type" and an "id"
Some configuration items are for all sensors Other configuration tiems are only for some sensors.
[sensor] SensorName="Outdoor Temp" SensorType=1 # Temp Sensor SensorID=1000 SerialNumber="12344" Active=1 Device="/dev/ttyUSB01"
[sensor] SensorName="Indoor Temp" SensorType=1 # Temp Sensor SensorID=1001 SerialNumber="12345" Active=1 Device="/dev/USB02"
[sensor] SensorName="Light" SensorType=2 # Light Sensor SensorID=1002 SerialNumber="12349" Active=1 Device="/dev/ttyUSB02" MaxLumen="500"
Is having multiple identical section names possible with boost program options?
It is of course possible to do
[sensor_1] ... [sensor_2] ... [sensor_3] ...
but that is not so nice looking, and you get a hard limit on the number of sensors you can attach.
Ideas?
BR Ulf Samuelsson
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 9/20/2013 9:48 PM, Quoth Ulf Samuelsson:
You can't duplicate the [sensor] section as you then have no way of selecting which one you want.
If I look at an xorg.conf file I find: [...] so it is not impossible. The "Identifier" allows you to differentiate between the two.
Sure, because that uses a custom parser and builds up data structures from the entire file in one pass, using such domain-specific knowledge to validate content and generate the links between entries. You're welcome to do the same, but you're unlikely to find something off the shelf that does it that way.
participants (3)
-
Gavin Lambert
-
Kerry, Richard
-
Ulf Samuelsson