Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:49:22+00:00 2026-06-13T12:49:22+00:00

Boost property tree seems like an excellent library to use for parsing config files.

  • 0

Boost property tree seems like an excellent library to use for parsing config files. However, I can’t figure out how to handle situations where there are multiple values per key. For example, let’s say I was specifying a box like this:

box
{
    x -1 1
    y -1 1
    z -1 1
}

where x, y, and z are the bounds of the box on the x, y, and z axes respectively, specified using property_tree’s INFO format. I see mention in the manual of using quotes for values that use spaces, but then I don’t see that I could import those values as numbers. I’d have to parse the string into numbers, which seems to defeat the purpose of using property_tree in the first place. I could certainly give each number a key:

box 
{
    xlo -1
    xhi 1
    ylo -1
    yhi 1
    zlo -1
    zhi 1
}    

but that seems cumbersome, and will inflate my config file. I also noted that I could handle this situation in program_options, but I lose the nested config file capabilities (yeah, I know I can use dot notation to “nest”, but it’s not the same).

Is there a way to import e.g. x as a list of numbers like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:49:23+00:00Added an answer on June 13, 2026 at 12:49 pm

    The standard property_tree handles only one string value per key since it is defined as:

    typedef basic_ptree<std::string, std::string> ptree;
    

    So, the only option is to use strings and parse them. I think the best method is to define a new class that stores the low and high values and then create a translator class for the get and set methods. For example:

    struct low_high_value
    {
      low_high_value() : m_low(0), m_high(0) { }
      low_high_value(double low, double high) : m_low(low), m_high(high) { }
      double m_low;
      double m_high;
    };
    

    The translator would be:

    struct low_high_value_translator
    {
      typedef std::string    internal_type;
      typedef low_high_value external_type;
      // Get a low_high_value from a string
      boost::optional<external_type> get_value(const internal_type& str)
      {
        if (!str.empty())
        {
          low_high_value val;
          std::stringstream s(str);
          s >> val.m_high >> val.m_low;
          return boost::optional<external_type>(val);
        }
        else
          return boost::optional<external_type>(boost::none);
      }
    
      // Create a string from a low_high_value
      boost::optional<internal_type> put_value(const external_type& b)
      {
        std::stringstream ss;
        ss << b.m_low << " " << b.m_high;
        return boost::optional<internal_type>(ss.str());
      }
    };
    

    The previous get_value method is very simple. It should be improved if the file could be written by the user.

    This class should be registered using:

    namespace boost { namespace property_tree 
    {
      template<typename Ch, typename Traits, typename Alloc> 
      struct translator_between<std::basic_string< Ch, Traits, Alloc >, low_high_value>
      {
        typedef low_high_value_translator type;
      };
    } }
    

    After you include the previous code, you can use property_tree as:

      pt.get<low_high_value>("box.x")
      pt.put("box.u", low_high_value(-110, 200));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning to use boost property tree for our application http://www.boost.org/doc/libs/1_41_0/doc/html/property_tree.html . Now
I'm struggling to compile some code that utilises the boost property tree. I'm using
I am using boost/property_tree to create an XML file. Unfortunately I cannot figure out
In the boost graph library, there are property maps used. For an example, consider
I use boost::property_tree object to parse xml like this: <?xml version=1.0 encoding=utf-8?> <root> <node
I'm iterating over an XML document using boost property tree and storing the results
I tried to work with the boost library to read/write configuration files but I
I am know approaching to boost property tree and saw that it is a
I am trying to use filenames as the key in boost::PropertyTree However, the '.'
I'd like to use boost::signals2 to handle event notification in my C++ app. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.