boost

How to create a folder in the home directory?

…衆ロ難τιáo~ 提交于 2020-01-21 04:36:12
问题 I want to create a directory path = "$HOME/somedir" . I've tried using boost::filesystem::create_directory(path) , but it fails - apparently the function doesn't expand system variables. How can I do it the simplest way? (note: in my case the string path is constant and I don't know for sure if it contains a variable) edit: I'm working on Linux (although I'm planning to port my app to Windows in the near future). 回答1: Use getenv to get environment variables, including HOME . If you don't know

YAML serialization library for C++?

蹲街弑〆低调 提交于 2020-01-20 18:48:08
问题 YAML seems like a great format for configuration files & data binding persistent objects in human-readable form... Is there a C++ library that handles YAML? Does Boost::Serialization have plans for a YAML option? EDIT: I would prefer an OO library. 回答1: A quick search gave me this: yaml-cpp 回答2: Try the YAML component from the BOOST vault serialization library. EDIT 2014 : A recent development, https://groups.google.com/d/msg/boost-devel-archive/mhT7qIh1nsI/uXAuXFAWrxQJ EDIT 2019 : Didn't try

How to pass class template argument to boost::variant?

 ̄綄美尐妖づ 提交于 2020-01-20 08:46:12
问题 I have a template method that uses boost::get of boost:variant module: typedef boost::variant<int, std::string, bool, uint8_t> Variant; template <class T> void write(const Variant& t) { size_t sizeT = boost::apply_visitor(SizeOfVisitor(), t); memcpy(&v[offset], &boost::get<T>(t), sizeT); } The problem is I know the underlying type of Variant only at runtime. And AFAIK I can query for it only with which() method. Is there any way I can pass the type T, which is the underlying type of Variant

How to check if path is valid in boost::filesystem?

拈花ヽ惹草 提交于 2020-01-20 07:57:26
问题 I am setting a boost::filesystem::path from an edit field. I notice that the constructor is happy to accept invalid characters for the filename. How can I use boost::filesystem to check if the boost::filesystem::path object represents a valid filename? 回答1: Have a look here: http://www.boost.org/doc/libs/release/libs/filesystem/doc/portability_guide.htm This describes various functions for checking whether filenames are valid or not. 来源: https://stackoverflow.com/questions/10426671/how-to

Dijkstra graph with a table of weights on each edge

混江龙づ霸主 提交于 2020-01-19 05:19:27
问题 I have a boost graph with multiples weights for each edges (imagine one set of weights per hour of the day). Every one of those weights values is stored in a propretyEdge class : class propretyEdge { std::map<std::string,double> weights; // Date indexed } I created a graph with those properties, and then filled it with the right values. The problem is now that I want to launch the Dijkstra algorithm over a particular set of weight on the graph : for example a function that could be : void

Rule of thumb: size of boost archive in relation to original serialized object?

…衆ロ難τιáo~ 提交于 2020-01-17 13:15:30
问题 For reasons that I will gloss over, I need to set aside space of a fixed size, and then use boost serialization to store an object there. The choice of archive format is arbitrary, and portability is not a concern. The class is fairly complex (members include fundamental types, arrays, pointers, and child classes) and guaranteed to grow over time. Does anyone have worthwhile sizing guestimates they trust? Space is important, but it's not at a premium. I'm looking for relatively simple answers

C++ - How do I revive a thread with boost?

落爺英雄遲暮 提交于 2020-01-17 07:54:48
问题 SUMMARY: Client is in Teamspeak server with other users. When other users begin speaking, this plugin runs a function setSpeakerPosition() on the user every 500ms until they stop speaking. It should do it again if they start speaking again. PROBLEM: If I simply do a .reset(new boost::thread(...)) every time they start speaking, it seems to overwrite an existing thread (if they've spoken before) and leads to a crash. I believe I need to 'revive' an existing thread, or kill it properly. //

Pass std::list to constructor using boost's list_of doesn't compile

梦想的初衷 提交于 2020-01-17 07:36:07
问题 I am trying to do this: class bbb { public: bbb(std::list<int> lst) { } }; int main() { bbb b((std::list<int>)boost::assign::list_of<int>(10)(10)); return 0; } and get following error from g++: some.cc:35: error: call of overloaded 'bbb(boost::assign_detail::generic_list<int>&)' is ambiguous some.cc:15: note: candidates are: bbb::bbb(std::list<int, std::allocator<int> >) some.cc:13: note: bbb::bbb(const bbb&) Is there any way to work around this problem? Note that I am using gcc 4.4.6. It

boost filename extension with multiple “.”

你离开我真会死。 提交于 2020-01-17 06:57:13
问题 I have filenames like this : 09.04.201115_09_ch_4.txt I would like to extract the filestem only. I tried using boost filesystem path, but it has problems with the multiple dots in the filename. (I didn't come up with the naming). Is there a way around that? Can I get only the filename without the extension? My code looks like this: std::string stringtmp = path.parent_path().string() +"/"+path.stem().string()+".png" ; Ok here's the code (it's using the ROOT framework): #include "TH1F.h"

Deserializing STL container of type with no default constructor

落爺英雄遲暮 提交于 2020-01-17 05:13:25
问题 I've recently learned the pattern of the deserializing constructor (Deserializing constructor doesn't read data correctly) to use serialization with types that do not have default constructors. Now I'm trying to serialize an STL container of these objects, as in the example below: #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/split_member.hpp> #include <boost/serialization/vector.hpp> #include <fstream> class Point { public