-
Notifications
You must be signed in to change notification settings - Fork 38
About feature and namespace selection
Boost.Application supports use of some features from std or boost.
This is handled by "application/config.hpp" config file.
The features that can be selected are:
- shared_ptr
- make_shared
- static_pointer_cast
From # in "std" selection or #<boost/shared_ptr.hpp>, #<boost/make_shared.hpp> in "boost" selection.
- unordered_map
From #<unordered_map> in "std" selection or #<boost/unordered_map.hpp> in "boost" selection.
- type_index
From # in "std" selection or #<boost/type_index.hpp> in "boost" selection.
User can force the selection using theses macros:
BOOST_APPLICATION_FEATURE_NS_SELECT_STD
In this case "std" are used, like:
- std::shared_ptr
- std::make_shared
- std::static_pointer_cast
Note that some of this features are available only on C++11, if your compiler don't support C++11 use boost.
BOOST_APPLICATION_FEATURE_NS_SELECT_BOOST
In this case "boost" are used, like:
- boost::shared_ptr
- boost::make_shared
- boost::static_pointer_cast
e.g:
#define BOOST_APPLICATION_FEATURE_NS_SELECT_BOOST
// -
#include <iostream>
#include <boost/application.hpp>
#include <boost/uuid/string_generator.hpp>
// -
using namespace boost;
// -
class myapp
{
public:
// -
myapp(application::context& context)
: context_(context)
{
}
// -
int operator()()
{
boost::shared_ptr<application::args> args =
context_.find<application::args>();
if(args)
{
const std::vector<std::string> &arg_vector = args->arg_vector();
// only print args on screen
for(std::vector<std::string>::const_iterator it = arg_vector.begin();
it != arg_vector.end(); ++it) {
std::cout << *it << std::endl;
}
}
// -
context_.find<application::wait_for_termination_request>()->wait();
return 0;
}
private:
application::context& context_;
};
// -
// main
// -
int main(int argc, char *argv[])
{
application::context app_context;
myapp app(app_context);
// -
boost::uuids::string_generator gen;
// -
app_context.insert<application::limit_single_instance>(
boost::make_shared<application::limit_single_instance_default_behaviour>(
gen("{2F66E4AD-ECA5-475D-8784-4BAA329EF9F1}")));
// -
return application::launch<application::common>(app, app_context);
}
If any of this are not defined, the default behaviour of selection is "automatic detect" that will try use better option for current system, in this case the user can use "csbl" namespace provided by Application.
The "csbl" will select current system option automatically, e.g:
int main(int argc, char *argv[])
{
application::context app_context;
myapp app(app_context);
app_context.insert<application::args>(
application::csbl::make_shared<application::args>(argc, argv));
return application::launch<application::common>(app, app_context);
}
If system auto select std, the "application::csbl::make_shared" will be "converted" to std::make_shared, if boost will be boost::make_shared