Re: Inhomogeneous containers as parameter lists
On 29/10/2010 13:32, Jonathan Lee wrote:
On Oct 29, 3:54 am, "d.avitab...@gmail.com"<d.avitab...@gmail.com>
wrote:
What I would like to do is having a container that I can easily pass
to the facilitator. Let us say that the facilitator should be able to
make contact with the firm and get these information via the
container, so that I could do something like
container.get("Name", firmName);
container.get("Number Of contracts", numberOfContracts)
etc. to access the firm parameters. Do you know whether such container
exist in any libraries, or if I should code it from scratch?
As already mentioned you could use a std::map with a "variant" type.
But is there some reason why you can't just use something like
void Facilitator::getParams(const Firm& firm) {
firmName = firm.getName();
..
}
or
Firm::Params container = firm.params();
..
firmName = container.getName();
?
The only times I've used the approach you suggested was when I had
an unknown number of parameters with unknown names (unknown at
compile time). From what you've mentioned, that doesn't seem to
be your case.
--Jonathan
When I used the code I posted, it was also in that sort of context
actually -- I was defining game entity components in an XML file like this:
<component name="Inventory">
<property name="ActiveItem" type="ObjectID"/>
<property name="Consumables" type="string -> int"/>
<property name="Items" type="{ObjectID}"/>
</component>
And then using the std::map<std::string,boost::any> approach to store
the actual properties as they were loaded in.
Cheers,
Stu