Le 07/12/2012 09:53, Jean-Michel Caricand a écrit :
> Le 07/12/2012 09:25, Jean-Michel Caricand a écrit :
>> Le 06/12/2012 23:17, Tommi Mäkitalo a écrit :
>>> Am 06.12.2012 22:48, schrieb Jean-Michel Caricand:
>>>> Hello,
>>>>
>>>> I want to use variables defined in tntnet.xml outside a component. How
>>>> to get an instance of tnt :: Config? Is it possible?
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Jean-Michel
>>> tnt::Config is handled as a singleton. You get a reference to the static
>>> instance using:
>>>
>>> tnt::TntConfig::it()
>>>
>>> So if you for example want to get the session timeout, you use:
>>>
>>> unsigned sessionTimeout = tnt::TntConfig::it().sessionTimeout;
>>>
>>> TntConfig is a structure, where all settings are stored in public variables.
>>>
>>> Tommi
>>>
>>> ------------------------------------------------------------------------------
>>> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
>>> Remotely access PCs and mobile devices and provide instant support
>>> Improve your efficiency, and focus on delivering more value-add services
>>> Discover what IT Professionals Know. Rescue delivers
>>> http://p.sf.net/sfu/logmein_12329d2d
>>> _______________________________________________
>>> Tntnet-general mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/tntnet-general
>> Hi Tommi,
>>
>> And if I want to access my variables, not predefined variables ?
>>
>> Jean-Michel
>>
>>
>> ------------------------------------------------------------------------------
>> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
>> Remotely access PCs and mobile devices and provide instant support
>> Improve your efficiency, and focus on delivering more value-add services
>> Discover what IT Professionals Know. Rescue delivers
>> http://p.sf.net/sfu/logmein_12329d2d
>> _______________________________________________
>> Tntnet-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/tntnet-general
> Hello,
>
> std::string v;
> tnt::TntConfig::it().config.getMember<std::string>("myvariable", v);
> log_info(v);
>
> That works :) !
>
> Jean-Michel
>
>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Tntnet-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/tntnet-general

Hello,

I have a Foo class and I can serialize it with JsonSerializer class :

{"integer":1,"str":"str1"}


Now, I want to add an extra field ("other" for example) :

{"integer":1,"str":"str1", other: "10.5"}


How can I do that ?

Thanks,

Jean-Michel

#include <iostream>
#include <sstream>
#include <cxxtools/jsonserializer.h>
#include <cxxtools/jsondeserializer.h>

class Foo {
public:
     int integer;
     std::string str;
};

void operator<<= (cxxtools::SerializationInfo& si, const Foo& obj)
{
     si.addMember("integer") <<= obj.integer;
     si.addMember("str") <<= obj.str;
}

void operator>>= (const cxxtools::SerializationInfo& si, Foo& obj)
{
     si.getMember("integer") >>= obj.integer;
     si.getMember("str") >>= obj.str;
}

int main()
{

     {
         std::stringstream is;
         Foo foo1;

         foo1.integer = 1;
         foo1.str = "str1";

         cxxtools::JsonSerializer s(is);
         s.serialize(foo1);

         // HOWTO TO ADD ANOTHER FIELD ?
          "other" = 10.5;

         s.finish();

         std::cout << is.str() << std::endl;
     }

     return 0;
}

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to