Boost logo

Boost Users :

Subject: [Boost-users] [Property Message] How to store variant in property tree
From: Elizabeta (elizabeta.petreska_at_[hidden])
Date: 2012-12-21 02:27:28


Hi
I want to store variant object in my property tree. The variant for now
will have only 3dPoint object, but it should vary multiple types in future.
I tried the following code , and I am getting compiler errors. I know
that maybe I need to write some kind of translation code for this to
work,but don't know how to do that exactly and having hard time to grasp
the concept. So how can I do this if possibly at all ? A code example
would be great

      class 3dPoint
      {
        public:
           3dPoint(double,double,double);
           double x;
           double y;
           double z;
      };

     typedef boost::variant<ON_3dPoint> MyVariant;

     using namespace boost::property_tree;

     typedef basic_ptree<std::string,MyVariant> my_ptree;
     my_ptree pt;

     MyVariant point_variant = 3dPoint(1,2,3);
     pt.put("point",point_variant);

     MyVariant point_variant2 = pt.get("point");

     boost::property_tree::xml_writer_settings<char> settings('\t', 1);
     write_xml("C:\\property.xml",pt,std::locale(),settings);


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net