現在、Boost C++ ライブラリを利用する Microsoft (アンマネージ) C++ プロジェクトに取り組んでいます。C++ を使用してからかなりの時間が経ちましたが、Boost ライブラリを使用した経験はありません。
Boost 1.55 と MSVC 2013 を使用しています。CMake を使用して、元のプロジェクト レイアウトに基づいて Visual Studio ソリューションとプロジェクトを生成しました。
他の環境での構築とテストに成功しています。MSVC - Windows 環境では、Boost のプロパティ ツリー サポートを使用して問題が発生しました。具体的には、問題はプロパティを PTNodes に入れようとすることに集中しているようです。
次のコード スニペットを検討してください。
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);
}
::SetResult() では、ツリーに挿入した値をすぐに取得しようとします。そのノードが見つからないため、Boost は例外をスローします (ツリーは実際には空です)。
コール スタックは次のようになります。
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++
実際に例外をスローするブースト コード: template basic_ptree & basic_ptree::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("そのようなノードはありません", path)); *nを返します。}
この問題の回避策が見つかりました。ハック/修正は、パスを構築し、put() を介してツリーに直接挿入することです。
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);
}
この回避策は、ノードをツリーに正常に挿入するようです。::SetResult() で挿入されたアイテムを見つけることで確認できます。
これが VisualStudio C++ で失敗する理由について何か考えはありますか?
これはコンパイラフラグの問題ですか?
プリコンパイラ定義?
リンカーオプション??
メモリモード/モデル??
MSVC C++ とその他の C++ 環境で、認識されていない基本的な動作の違いはありますか?
ノード挿入パターンのすべてのインスタンスを特定し、回避策を使用しようとしました。しかし、問題が何であるかを突き止める必要があります (他の兆候がある可能性があるため)。
考え、ガイダンス、アイデアはありますか?この問題に対する回答を検索する他の場所はありますか?
前もって感謝します、ジョンB