[Ns-developers] get value of a GlobalVariable
Nicola Baldo
nbaldo at cttc.es
Thu Jul 2 09:39:42 PDT 2009
I'm moving this to ns-dev since it has become a dev issue...
On Jul 2, 3:27 pm, Mathieu Lacage <mathieu.lac... at sophia.inria.fr> wrote:
> On Thu, 2009-07-02 at 14:48 +0200, Nicola Baldo wrote:
>> How can I get of the value of a GlobalVariable?
>
>> Example: in the main() of my simulation, I need know the value of
>> RngRun which was passed to the command line. I am currently doing
>> it in the following way:
>
>> #include "ns3/core-module.h"
>
>> using namespace ns3;
>
>> int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse
>> (argc, argv);
>
>> int run; IntegerValue runValue; GlobalValue::Iterator gvit;
>> for (gvit = GlobalValue::Begin (); gvit != GlobalValue::End ();
>> ++gvit)
>> { if ((*gvit)->GetName () == "RngRun") { (*gvit)->GetValue
>> (runValue); run = runValue.Get (); } }
>
>> std::cout<< "rngRun = " << run << std::endl;
>
>> return 0; }
>
>> Is there any nicer way to do it?
>
> I don't think so but I guess we could add void
> GlobalValue::GetValueByName (std::string name, AttributeValue
> &value). Care to cook a patch ?
Patch attached. If it is ok I can commit it to ns-3-dev.
>
> Another nice thing would be to fix bug
> http://www.nsnam.org/bugzilla/show_bug.cgi?id=184
I'm sorry but I do not understand why this is related.
>
> Are you aware that ns3::ConfigStore can be used to save/load a file
> (raw text or xml) which contains the value, among others, of the
> RngRun/RngSeed global value ?
Yes that's cool, though poorly documented... a couple of weeks ago I was
looking at it, but I couldn't find any example code, so it took me a
while to figure it out how to use it!
Still, for this particular case I really needed to get the value within
the sim program (I just wanted to name some pcap traces according to
RngRun) so I do not see how ConfigStore could have been useful.
Nicola
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ns-3-global-value-get-value-by-name.patch
Type: text/x-patch
Size: 1411 bytes
Desc: not available
Url : http://mailman.isi.edu/pipermail/ns-developers/attachments/20090702/48736624/ns-3-global-value-get-value-by-name.bin
More information about the Ns-developers
mailing list