Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi:

I'm currently working on a Microsoft (unmanaged) C++ project which utilitizes
Boost C++ libraries. It's been quite a while since I've done C++ and I have no
previous experience using the Boost libraries.

We are using Boost 1.55 and MSVC 2013.
We used CMake to generate the Visual Studio solutions and projects based on the original project layout.

We've successfully built and tested on other environments. In the MSVC - Windows environment, we've run into issues using Boost's Property Tree support. Specifically, the issue seem to center around trying to put properties into PTNodes.

Consider the following code snippet:
C++
void XXX:: SomeFunction()
{
    PTnode ptNode;
    ptNode(Mapper::KEY_INPUT, Tracer::SOME_VALUE);
    ptNode(Mapper::KEY_OUTPUT)(Tracer::SOME_OTHER_VALUE, Tracer::ADDITIONAL_VALUE);

    SetResults(ptNode);
}

void XXX::SetResults(const PTree& pTree)
{
    std::string results = pTree.get_child(Mapper::KEY_OUTPUT).get<string>(Tracer::SOME_OTHER_VALUE);
}


In ::SetResult(), we immediately attempt to retrieve the value we inserted in the tree. Boost throws an exception as it cannot find that node (the tree is actually empty)

This is what the call stack looks like:
SomeDLL.dll!boost::property_tree::basic_ptree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::get_child(const boost::property_tree::string_path<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::property_tree::id_translator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & path) Line 557  C++
SomeDLL.dll!boost::property_tree::basic_ptree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::get_child(const boost::property_tree::string_path<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::property_tree::id_translator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & path) Line 567  C++
SomeDLL.dll!boost::property_tree::basic_ptree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::get<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(const boost::property_tree::string_path<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::property_tree::id_translator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & path) Line 732 C++


The Boost Code that actually throws the exception:
C++
template<class K, class D, class C>
basic_ptree<K, D, C> &
    basic_ptree<K, D, C>::get_child(const path_type &path)
{
    path_type p(path);
    self_type *n = walk_path(p);
    if (!n) {
        BOOST_PROPERTY_TREE_THROW(ptree_bad_path("No such node", path));
    }
    return *n;
}

We found a work around for this issue. The hack/fix is to construct the path and directly insert it into the tree via put().
C++
void XXX:: SomeFunction()
{
    PTree pTree;

    pTree.put(Mapper::KEY_INPUT, Tracer::SOME_VALUE);
    pTree.put(Mapper::KEY_OUTPUT + "." + Tracer::SOME_OTHER_VALUE, Tracer::ADDITIONAL_VALUE);

    SetResults(pTree);
}

void XXX::SetResults(const PTree& pTree)
{

    std::string results = pTree.get_child(Mapper::KEY_OUTPUT).get<string>(Tracer::SOME_OTHER_VALUE);
}


This work around seems insert the nodes successfully into the tree.
We are able to verify by finding the inserted items in ::SetResult().

Any thought as to why this might be failing in VisualStudio C++?

Is this an issue of compiler flags?

precompiler definitions?

Linker options??

Memory mode/model??

Are there some basic behaviour differences in MSVC C++ and other C++ environments
which we are unaware of?

I've tried to identify all instances of the node insert pattern and use the work around.
But, we really need to find out what the issue is (as there could be other manifestations).

Any thoughts, guidance, ideas?
Other places to search for an answer to this issue?

Thanks in advance,
JohnB
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900