本文整理汇总了C++中boost类的典型用法代码示例。如果您正苦于以下问题:C++ boost类的具体用法?C++ boost怎么用?C++ boost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了boost类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: integrate_slowpath
long double integrate_slowpath(
boost::function<long double(long double)> const& f
, long double lower_bound
, long double upper_bound
, long double tolerance
, long double increment
) {
long double total_area = 0.0L, temp_increment = increment;
boost::uint64_t count_depth = 0
, last_count = 0
, iterations = 0
, rollbacks = 0
, refinements = 0;
for (long double i = lower_bound; i < upper_bound; ++iterations)
{
const long double fi = f(i);
boost::uint64_t count = 0;
// When the difference between the function value at the middle of the
// increment and the start of the increment is too big, decrease the
// increment by a factor of two and retry.
while ((abs(f(i + (temp_increment / 2.0L)) - fi)) > tolerance)
{
++count;
temp_increment /= 2.0L; // TODO: ensure that I am optimized away,
// as I am computed at the head of the while
// loop.
}
if (count != last_count)
cout << ( format("growth rate of increment changed from 1/2^%1% to "
"1/2^%2% at f(%3%)\n")
% (last_count + count_depth)
% (count + count_depth)
% group(setprecision(ld_precision), i));
refinements += count;
last_count = count;
count_depth += count;
total_area += fi * temp_increment;
i += temp_increment;
// Rollback one level of resolution at the end of each for-loop
// iteration to avoid unneeded resolution, if we were not within the
// tolerance.
if (count)
{
++rollbacks;
--count_depth;
temp_increment *= 2.0L;
}
}
cout << ( format("computation completed in %1% iterations\n"
"%2% refinements occurred\n"
"%3% rollbacks were performed\n")
% iterations
% refinements
% rollbacks);
return total_area;
}
开发者ID:STEllAR-GROUP,项目名称:hpx_historic,代码行数:67,代码来源:numerical_integration2.cpp
示例2: main
int main(){
using namespace std;
using boost::format;
using boost::io::group;
using boost::io::str;
string s;
stringstream oss;
//------------------------------------------------------------------------
// storing the parsed format-string in a 'formatter' :
// format objects are regular objects that can be copied, assigned,
// fed arguments, dumped to a stream, re-fed arguments, etc...
// So users can use them the way they like.
format fmter("%1% %2% %3% %1% \n");
fmter % 10 % 20 % 30;
cout << fmter;
// prints "10 20 30 10 \n"
// note that once the fmter got all its arguments,
// the formatted string stays available (until next call to '%')
// The result is available via function str() or stream's << :
cout << fmter;
// prints the same string again.
// once you call operator% again, arguments are cleared inside the object
// and it is an error to ask for the conversion string before feeding all arguments :
fmter % 1001;
try { cout << fmter; }
catch (boost::io::too_few_args& exc) {
cout << exc.what() << "***Dont worry, that was planned\n";
}
// we just need to feed the last two arguments, and it will be ready for output again :
cout << fmter % 1002 % 1003;
// prints "1001 1002 1003 1001 \n"
cout << fmter % 10 % 1 % 2;
// prints "10 1 2 10 \n"
//---------------------------------------------------------------
// using format objects
// modify the formatting options for a given directive :
fmter = format("%1% %2% %3% %2% %1% \n");
fmter.modify_item(4, group(setfill('_'), hex, showbase, setw(5)) );
cout << fmter % 1 % 2 % 3;
// prints "1 2 3 __0x2 1 \n"
// bind one of the argumets :
fmter.bind_arg(1, 18);
cout << fmter % group(hex, showbase, 20) % 30; // %2 is 20, and 20 == 0x14
// prints "18 0x14 30 _0x14 18 \n"
fmter.modify_item(4, setw(0)); // cancels previous width-5
fmter.bind_arg(1, 77); // replace 18 with 77 for first argument.
cout << fmter % 10 % 20;
// prints "77 10 20 0xa 77 \n"
try
{
cout << fmter % 6 % 7 % 8; // Aye ! too many args, because arg1 is bound already
}
catch (boost::io::too_many_args& exc)
{
cout << exc.what() << "***Dont worry, that was planned\n";
}
// clear() clears regular arguments, but not bound arguments :
fmter.clear();
cout << fmter % 2 % 3;
// prints "77 2 3 0x2 77 \n"
// use clear_binds() to clear both regular AND bound arguments :
fmter.clear_binds();
cout << fmter % 1 % 2 % 3;
// prints "1 2 3 0x2 1 \n"
// setting desired exceptions :
fmter.exceptions( boost::io::all_error_bits ^( boost::io::too_many_args_bit ) );
cout << fmter % 1 % 2 % 3 % 4 % 5 % 6 ;
// -----------------------------------------------------------
// misc:
// unsupported printf directives %n and asterisk-fields are purely ignored.
// do *NOT* provide an argument for them, it is an error.
cout << format("|%5d| %n") % 7 << endl;
// prints "| 7| "
cout << format("|%*.*d|") % 7 << endl;
// prints "|7|"
//.........这里部分代码省略.........
开发者ID:Karlan88,项目名称:xray,代码行数:101,代码来源:sample_advanced.cpp
示例3: log_add
bool Application::init()
{
//
// seed da rand
//
std::srand(static_cast<unsigned int>(timer.get_mms()));
//
// setup new old time
//
oldtime = timer.get_dt_s();
//
// init logger
//
f_log = std::fopen(BIN("planetz.log").c_str(),"w");
log_add(LOG_STREAM(f_log),LOG_PRINTER(std::vfprintf));
#ifdef _RELEASE
log_set_lev(INFO);
#endif
//
// init graphics
//
if( !gfx.window_init(window.getW(),window.getH()) ) return false;
plz.setMaterials( data_mgr.loadMaterials() );
plz.setTextures ( data_mgr.loadTextures () );
//
// init user interface
//
if( !ui.init() ) return false;
// FIXME: where should be this done?
ui.sigVideoResize.
connect( 0 , bind(&Window::reshape_window,&window,_1,_2));
ui.sigVideoResize.
connect( 1 , bind(&GFX::Gfx::reshape_window,&gfx,_1,_2) );
ui.sigVideoResize.
connect( 2 , bind(&UI::PlanetzPicker::resize,&picker,_1,_2) );
ui.add_listener( &setter , 1 );
ui.add_listener( &camera , 2 );
ui.sigKeyDown.
connect( bind(&GFX::Background::on_key_down,&bkg,_1) );
ui.sigMouseMotion.
connect( bind(&GFX::Background::on_mouse_motion,&bkg,_1,_2));
ui.sigMouseButtonUp.
connect( bind(&GFX::Background::on_button_up,&bkg,_1,_2,_3));
ui.sigMouseButtonDown.
connect(1,bind(&GFX::Background::on_button_down,&bkg,_1,_2,_3));
ui.sigMouseButtonDown.
connect( bind(&UI::PlanetzPicker::on_button_down,&picker,_1,_2,_3) );
camera.sigCamChanged.
connect( 2 , bind(&GFX::DeferRender::on_camera_angle_changed,&plz,_1) );
picker.sigPlanetPicked.
connect( bind(&Application::set_picked_planet,this,_1) );
#ifndef _RELEASE
picker.sigPlanetPicked.
connect( bind(&PlanetPrinter::print,&pprnt,_1));
#endif
#ifndef _NOGUI
//
// init graphical user interface
//
try {
pl = new PlanetzLayout( config );
} catch(CEGUI::InvalidRequestException e) {
log_printf(CRITICAL,"CEGUI exception: %s\n",e.getMessage().c_str());
return false;
}
ui.set_layout(pl);
// pl->on_cam_speed_changed.connect(
// bind( &UI::CameraMgr::update,&camera
// ,UI::CameraMgr::FREELOOK,&boost::lambda::_1) );
pl->on_cam_speed_changed.connect( bind(&Application::set_cam_speed,this,_1) );
pl->on_sim_speed_changed.connect( bind(&Application::set_phx_speed,this,_1) );
pl->on_pause_click.connect( bind(&Application::pause_toggle,this) );
pl->on_reset_click.connect( bind(&Application::reset,this) );
pl->on_save.connect( 1, bind(&MEM::DataFlowMgr::save,&data_mgr,_1) );
pl->on_save.connect( 0, bind(&MEM::MISC::PlanetHolderCleaner::forceFilter,&phcleaner) );
pl->on_load.connect( bind(&MEM::DataFlowMgr::load,&data_mgr,_1) );
pl->on_load.connect( bind(&Application::pause_anim,this) );
pl->on_load.connect( bind(&GFX::PlanetsTracer::clear,&trace) );
pl->on_load.connect( bind(&UI::CameraMgr::clear,&camera) );
pl->on_load.connect( bind(&UI::PlanetzSetter::clear,&setter) );
pl->on_load.connect( bind(&PlanetzLayout::hide_show_window,pl) );
pl->on_config_changed.connect(bind(&GFX::Gfx::update_configuration,&gfx,_1));
pl->on_config_changed.connect(bind(&Application::update_configuration,this,_1));
pl->on_planet_changed.connect( bind(&UI::PlanetzSetter::update,&setter,_1) );
pl->on_planet_change.connect( bind(&UI::PlanetzSetter::change,&setter,_1) );
//.........这里部分代码省略.........
开发者ID:jkotur,项目名称:planetz,代码行数:101,代码来源:application.cpp
示例4: test_main
int test_main(int, char* [])
{
using namespace std;
using boost::format;
using boost::io::group;
using boost::str;
Rational r(16,9);
string s;
s = str(format("%5%. %5$=6s . %1% format %5%, c'%3% %1% %2%.\n")
% "le" % "bonheur" % "est" % "trop" % group(setfill('_'), "bref") );
if(s != "bref. _bref_ . le format bref, c'est le bonheur.\n") {
cerr << s;
BOOST_ERROR("centered alignement : formatting result incorrect");
}
s = str(format("%+8d %-8d\n") % r % r );
if(s != " +16/+9 16/9 \n") {
cerr << s;
BOOST_ERROR("(user-type) formatting result incorrect");
}
s = str(format("[%0+4d %0+8d %-08d]\n") % 8 % r % r);
if(s != "[+008 +0016/+9 16/9 ]\n") {
cerr << s;
BOOST_ERROR("(zero-padded user-type) formatting result incorrect");
}
s = str( format("%1%, %20T_ (%|2$5|,%|3$5|)\n") % "98765" % 1326 % 88 ) ;
if( s != "98765, _____________ ( 1326, 88)\n" )
BOOST_ERROR("(tabulation) formatting result incorrect");
s = str( format("%s, %|20t|=") % 88 ) ;
if( s != "88, =" ) {
cout << s << endl;
BOOST_ERROR("(tabulation) formatting result incorrect");
}
s = str(format("%.2s %8c.\n") % "root" % "user" );
if(s != "ro u.\n") {
cerr << s;
BOOST_ERROR("(truncation) formatting result incorrect");
}
// width in format-string is overridden by setw manipulator :
s = str( format("%|1$4| %|1$|") % group(setfill('0'), setw(6), 1) );
if( s!= "000001 000001")
BOOST_ERROR("width in format VS in argument misbehaved");
s = str( format("%|=s|") % group(setfill('_'), setw(6), r) );
if( s!= "_16/9_") {
cerr << s << endl;
BOOST_ERROR("width in group context is not handled correctly");
}
// options that uses internal alignment : + 0 #
s = str( format("%+6d %0#6x %s\n") % 342 % 33 % "ok" );
if( s !=" +342 0x0021 ok\n")
BOOST_ERROR("(flags +, 0, or #) formatting result incorrect");
// flags in the format string are not sticky
// and hex in argument overrrides type-char d (->decimal) :
s = str( format("%2$#4d %|1$4| %|2$#4| %|3$|")
% 101
% group(setfill('_'), hex, 2)
% 103 );
if(s != "_0x2 101 _0x2 103")
BOOST_ERROR("formatting error. (not-restoring state ?)");
// flag '0' is tricky .
// left-align cancels '0':
s = str( format("%2$0#12X %2$0#-12d %1$0#10d \n") % -20 % 10 );
if( s != "0X000000000A 10 -000000020 \n") {
cerr << s;
BOOST_ERROR("formatting error. (flag 0)");
}
return 0;
}
开发者ID:iceberry,项目名称:flyffsf,代码行数:86,代码来源:format_test2.cpp
示例5: test
void test()
{
BOOST_TEST( UDT_use_count == 0 ); // reality check
// test scoped_ptr with a built-in type
long * lp = new long;
boost::scoped_ptr<long> sp ( lp );
BOOST_TEST( sp.get() == lp );
BOOST_TEST( lp == sp.get() );
BOOST_TEST( &*sp == lp );
*sp = 1234568901L;
BOOST_TEST( *sp == 1234568901L );
BOOST_TEST( *lp == 1234568901L );
ck( static_cast<long*>(sp.get()), 1234568901L );
ck( lp, *sp );
sp.reset();
BOOST_TEST( sp.get() == 0 );
// test scoped_ptr with a user defined type
boost::scoped_ptr<UDT> udt_sp ( new UDT( 999888777 ) );
BOOST_TEST( udt_sp->value() == 999888777 );
udt_sp.reset();
udt_sp.reset( new UDT( 111222333 ) );
BOOST_TEST( udt_sp->value() == 111222333 );
udt_sp.reset( new UDT( 333222111 ) );
BOOST_TEST( udt_sp->value() == 333222111 );
// test scoped_array with a build-in type
char * sap = new char [ 100 ];
boost::scoped_array<char> sa ( sap );
BOOST_TEST( sa.get() == sap );
BOOST_TEST( sap == sa.get() );
strcpy( sa.get(), "Hot Dog with mustard and relish" );
BOOST_TEST( strcmp( sa.get(), "Hot Dog with mustard and relish" ) == 0 );
BOOST_TEST( strcmp( sap, "Hot Dog with mustard and relish" ) == 0 );
BOOST_TEST( sa[0] == 'H' );
BOOST_TEST( sa[30] == 'h' );
sa[0] = 'N';
sa[4] = 'd';
BOOST_TEST( strcmp( sap, "Not dog with mustard and relish" ) == 0 );
sa.reset();
BOOST_TEST( sa.get() == 0 );
// test shared_ptr with a built-in type
int * ip = new int;
boost::shared_ptr<int> cp ( ip );
BOOST_TEST( ip == cp.get() );
BOOST_TEST( cp.use_count() == 1 );
*cp = 54321;
BOOST_TEST( *cp == 54321 );
BOOST_TEST( *ip == 54321 );
ck( static_cast<int*>(cp.get()), 54321 );
ck( static_cast<int*>(ip), *cp );
boost::shared_ptr<int> cp2 ( cp );
BOOST_TEST( ip == cp2.get() );
BOOST_TEST( cp.use_count() == 2 );
BOOST_TEST( cp2.use_count() == 2 );
BOOST_TEST( *cp == 54321 );
BOOST_TEST( *cp2 == 54321 );
ck( static_cast<int*>(cp2.get()), 54321 );
ck( static_cast<int*>(ip), *cp2 );
boost::shared_ptr<int> cp3 ( cp );
BOOST_TEST( cp.use_count() == 3 );
BOOST_TEST( cp2.use_count() == 3 );
BOOST_TEST( cp3.use_count() == 3 );
cp.reset();
BOOST_TEST( cp2.use_count() == 2 );
BOOST_TEST( cp3.use_count() == 2 );
cp.reset( new int );
*cp = 98765;
BOOST_TEST( *cp == 98765 );
*cp3 = 87654;
BOOST_TEST( *cp3 == 87654 );
BOOST_TEST( *cp2 == 87654 );
cp.swap( cp3 );
BOOST_TEST( *cp == 87654 );
BOOST_TEST( *cp2 == 87654 );
BOOST_TEST( *cp3 == 98765 );
cp.swap( cp3 );
BOOST_TEST( *cp == 98765 );
BOOST_TEST( *cp2 == 87654 );
BOOST_TEST( *cp3 == 87654 );
cp2 = cp2;
BOOST_TEST( cp2.use_count() == 2 );
BOOST_TEST( *cp2 == 87654 );
cp = cp2;
BOOST_TEST( cp2.use_count() == 3 );
BOOST_TEST( *cp2 == 87654 );
BOOST_TEST( cp.use_count() == 3 );
BOOST_TEST( *cp == 87654 );
//.........这里部分代码省略.........
开发者ID:LancelotGHX,项目名称:Simula,代码行数:101,代码来源:smart_ptr_test.cpp
示例6: BOOST_CHECK
void InputRule::unitTest() {
BOOST_CHECK(true);
sqlite3* db;
// // test Ruleset class
// path dbFileName = initial_path<path>()/"unitTest_InputRule.db3";
//
// if (exists(dbFileName))
// boost::filesystem::remove(dbFileName);
//
// if(sqlite3_open(dbFileName.file_string().c_str(), &db)) {
if(sqlite3_open(":memory:", &db)) {
sqlite3_close(db);
throw std::runtime_error("could not open database file");
}
BOOST_REQUIRE(db!=NULL);
BOOST_CHECKPOINT("create Tables");
InputRule::createTables(db);
Replacement::createTables(db);
Replacements::createTables(db);
Gem::createTables(db);
BOOST_CHECKPOINT("InputRule constructor(regex)");
InputRule ruleAlpha(db, regex("(.*)\\.avi"), -1);
InputRule ruleBeta(db, regex("(.*)\\.mpg"), -1);
InputRule ruleGamma(db, regex("(.*)\\.jpg"), -1);
ruleAlpha.updateGems("$fileName$");
ruleBeta.updateGems("$fileName$");
ruleGamma.updateGems("$fileName$");
BOOST_CHECK(ruleAlpha.getGems().size() == 1);
BOOST_CHECK(ruleBeta.getGems().size() == 1);
BOOST_CHECK(ruleGamma.getGems().size() == 1);
BOOST_CHECKPOINT("get gem");
BOOST_REQUIRE(ruleAlpha.getGems().size() == 1);
BOOST_CHECK(ruleAlpha.getGems()[0]->getName() == "fileName");
BOOST_CHECKPOINT("getRegex(), first time");
BOOST_CHECK( ruleAlpha.getRegex() == "(.*)\\.avi" );
BOOST_CHECK( ruleBeta.getRegex() == "(.*)\\.mpg" );
BOOST_CHECK( ruleGamma.getRegex() == "(.*)\\.jpg" );
BOOST_CHECKPOINT("getRegex(), second time");
BOOST_CHECK( ruleAlpha.getRegex() == "(.*)\\.avi" );
BOOST_CHECK( ruleBeta.getRegex() == "(.*)\\.mpg" );
BOOST_CHECK( ruleGamma.getRegex() == "(.*)\\.jpg" );
vector<GemValue> gems;
BOOST_CHECKPOINT("applyTo()");
BOOST_CHECK(ruleAlpha.getGems().size() == 1);
BOOST_CHECK_NO_THROW(ruleAlpha.applyTo("Test.avi", gems, true));
BOOST_CHECK_NO_THROW(!ruleAlpha.applyTo("Test.mpg", gems, true));
BOOST_CHECK_NO_THROW(!ruleAlpha.applyTo("Test.jpg", gems, true));
BOOST_CHECKPOINT("applyTo() 048f97dc");
BOOST_CHECK(!ruleBeta.applyTo("Test.avi", gems, true));
BOOST_CHECK(ruleBeta.applyTo("Test.mpg", gems, true));
BOOST_CHECK(!ruleBeta.applyTo("Test.jpg", gems, true));
BOOST_CHECKPOINT("applyTo() 092aed5a");
BOOST_CHECK(!ruleGamma.applyTo("Test.avi", gems, true));
BOOST_CHECK(!ruleGamma.applyTo("Test.mpg", gems, true));
BOOST_CHECK(ruleGamma.applyTo("Test.jpg", gems, true));
BOOST_CHECKPOINT("applyTo() 6d984e20");
BOOST_CHECK(ruleAlpha.applyTo("Name mit Blank.avi", gems, true));
BOOST_CHECK(!ruleAlpha.applyTo("Name mit Blank.mpg", gems, true));
BOOST_CHECK(!ruleAlpha.applyTo("Name mit Blank.jpg", gems, true));
BOOST_CHECK(!ruleBeta.applyTo("Name mit Blank.avi", gems, true));
BOOST_CHECK(ruleBeta.applyTo("Name mit Blank.mpg", gems, true));
BOOST_CHECK(!ruleBeta.applyTo("Name mit Blank.jpg", gems, true));
BOOST_CHECK(!ruleGamma.applyTo("Name mit Blank.avi", gems, true));
BOOST_CHECK(!ruleGamma.applyTo("Name mit Blank.mpg", gems, true));
BOOST_CHECK(ruleGamma.applyTo("Name mit Blank.jpg", gems, true));
BOOST_CHECKPOINT("setRegex()");
BOOST_CHECK(ruleAlpha.setRegex("([\\w ]*)\\.avi"));
BOOST_CHECK(!ruleAlpha.setRegex("([\\w ]*)\\.mpg"));
BOOST_CHECK(!ruleAlpha.setRegex("Test\\..*"));
BOOST_CHECK(!ruleBeta.setRegex("([\\w ]*)\\.avi"));
BOOST_CHECK(ruleBeta.setRegex("([\\w ]*)\\.mpg"));
BOOST_CHECK(!ruleBeta.setRegex("Test\\..*"));
BOOST_CHECK(ruleGamma.setRegex("([\\w ]*)\\.jpg"));
BOOST_CHECK(!ruleGamma.setRegex("([\\w ]*)\\.mpg"));
BOOST_CHECK(!ruleGamma.setRegex("Test\\..*"));
BOOST_CHECKPOINT("getRegex(), third time");
BOOST_CHECK( ruleAlpha.getRegex() == "([\\w ]*)\\.avi" );
BOOST_CHECK( ruleBeta.getRegex() == "([\\w ]*)\\.mpg" );
BOOST_CHECK( ruleGamma.getRegex() == "([\\w ]*)\\.jpg" );
//.........这里部分代码省略.........
开发者ID:arturh85,项目名称:Renamer.NET,代码行数:101,代码来源:inputRule.cpp
示例7: initialize
core::Error initialize()
{
git::initialize();
svn::initialize();
// http endpoints
using boost::bind;
using namespace module_context;
ExecBlock initBlock ;
initBlock.addFunctions()
(bind(registerRpcMethod, "vcs_clone", vcsClone));
Error error = initBlock.execute();
if (error)
return error;
// If VCS is disabled, or we're not in a project, do nothing
const projects::ProjectContext& projContext = projects::projectContext();
FilePath workingDir = projContext.directory();
if (!session::options().allowVcs() || !userSettings().vcsEnabled() || workingDir.empty())
return Success();
// If Git or SVN was explicitly specified, choose it if valid
projects::RProjectVcsOptions vcsOptions;
if (projContext.hasProject())
{
Error vcsError = projContext.readVcsOptions(&vcsOptions);
if (vcsError)
LOG_ERROR(vcsError);
}
if (vcsOptions.vcsOverride == kVcsIdNone)
{
return Success();
}
else if (vcsOptions.vcsOverride == git::kVcsId)
{
if (git::isGitInstalled() && git::isGitDirectory(workingDir))
return git::initializeGit(workingDir);
return Success();
}
else if (vcsOptions.vcsOverride == svn::kVcsId)
{
if (svn::isSvnInstalled() && svn::isSvnDirectory(workingDir))
return svn::initializeSvn(workingDir);
return Success();
}
if (git::isGitInstalled() && git::isGitDirectory(workingDir))
{
return git::initializeGit(workingDir);
}
else if (svn::isSvnInstalled() && svn::isSvnDirectory(workingDir))
{
return svn::initializeSvn(workingDir);
}
else
{
return Success(); // none specified or detected
}
}
开发者ID:AndreMikulec,项目名称:rstudio,代码行数:62,代码来源:SessionVCS.cpp
示例8: if
/// \brief Combine a dssp_file and pdb representing the same structure in a sensible protein object
///
/// \relates dssp_file
///
/// \TODO Consider taking an ostream_ref_opt argument rather than assuming cerr
/// (fix all errors, *then* provide default of boost::none)
protein cath::file::protein_from_dssp_and_pdb(const dssp_file &arg_dssp_file, ///< The dssp_file object for a given structure
const pdb &arg_pdb_file, ///< The dssp_file object for a given structure
const dssp_skip_policy &arg_dssp_skip_policy, ///< Whether to exclude residues that are in the PDB but not the DSSP
const string &arg_name, ///< The name to set as the title of the protein
const ostream_ref_opt &arg_ostream ///< An optional reference to an ostream to which any logging should be sent
) {
// Build a rough protein object from the pdb object
const auto pdb_protein = build_protein_of_pdb(
arg_pdb_file,
arg_ostream,
( arg_dssp_skip_policy == dssp_skip_policy::SKIP__BREAK_ANGLES )
? dssp_skip_policy::DONT_SKIP__BREAK_ANGLES
: arg_dssp_skip_policy
);
const auto pdb_skip_indices = get_protein_res_indices_that_dssp_might_skip( arg_pdb_file, arg_ostream );
// Grab the number of residues in the protein and dssp_file objects
const auto num_dssp_residues = arg_dssp_file.get_num_residues();
const auto num_pdb_residues = pdb_protein.get_length();
// Grab the residues names from the DSSP and PDB and then tally them up
const auto pdb_res_names = get_residue_ids ( pdb_protein );
const auto dssp_res_names = get_residue_ids ( arg_dssp_file, false );
const auto alignment = tally_residue_ids(
pdb_res_names,
dssp_res_names,
false,
true,
pdb_skip_indices
);
// Prepare a list of new residue to populate
residue_vec new_residues;
new_residues.reserve( ( arg_dssp_skip_policy == dssp_skip_policy::SKIP__BREAK_ANGLES ) ? num_dssp_residues : num_pdb_residues );
// Loop over the residues
size_t alignment_ctr = 0;
for (const size_t &pdb_residue_ctr : irange( 0_z, num_pdb_residues ) ) {
const residue &the_pdb_residue = pdb_protein.get_residue_ref_of_index( pdb_residue_ctr );
// If this PDB residue is in the alignment then it can be combined with the equivalent DSSP residue
const bool is_in_alignment = ( (alignment_ctr < alignment.size() ) && ( alignment[alignment_ctr].first == pdb_residue_ctr ) );
if ( is_in_alignment ) {
// Combine the two residues and add them to the back
const residue &the_dssp_residue = arg_dssp_file.get_residue_of_index( alignment[alignment_ctr].second );
new_residues.push_back(
combine_residues_from_dssp_and_pdb(
the_dssp_residue,
the_pdb_residue,
angle_skipping_of_dssp_skip_policy( arg_dssp_skip_policy )
)
);
// Increment the alignment counter
++alignment_ctr;
}
else if ( res_skipping_of_dssp_skip_policy( arg_dssp_skip_policy ) == dssp_skip_res_skipping::DONT_SKIP ) {
new_residues.push_back( the_pdb_residue );
}
}
// Construct a new protein from the new list of residues
return { arg_name, new_residues };
}
开发者ID:UCLOrengoGroup,项目名称:cath-tools,代码行数:70,代码来源:dssp_file.cpp
示例9: readFromMultilineAdjacencyList
void readFromMultilineAdjacencyList( const string& fname, GraphT& G ) {
typedef typename boost::graph_traits< GraphT >::vertex_descriptor Vertex;
typedef typename boost::graph_traits< GraphT >::edge_descriptor Edge;
typedef unordered_map<string,Vertex> svMap;
svMap namePosMap;
bool inserted;
Vertex u,v;
typename unordered_map<string,Vertex>::iterator pos;
bool headLine = false;
size_t remEdgeLine = 0;
string line;
typedef vector< string > splitVectorT;
ifstream gfile(fname);
if ( gfile.is_open() ) {
while( gfile.good() ) {
getline( gfile, line, '\n' );
if ( gfile.eof() ) { break; }
boost::algorithm::trim(line);
auto vline = line.substr( 0, line.find_first_of('#') );
if (vline.length() == 0) { continue; }
splitVectorT splitVec;
split( splitVec, vline, is_any_of(" \t"), token_compress_on );
if ( splitVec.size() > 0 and vline.size() > 0 ) {
auto fromVert = splitVec[0];
remEdgeLine = lexical_cast<size_t>(splitVec[1]);
boost::tie( pos, inserted ) = namePosMap.insert( std::make_pair(fromVert,Vertex()) );
if (inserted) {
u = add_vertex(G);
G[u].name = fromVert;
// This will happen later
// G[u].idx = nameMap[fromVert];
pos->second = u;
} else {
u = pos->second;
}
while ( remEdgeLine > 0 ) {
getline( gfile, line, '\n' );
boost::algorithm::trim(line);
vline = line.substr( 0, line.find_first_of('#') );
split( splitVec, vline, is_any_of(" \t"), token_compress_on );
auto toVert = splitVec[0];
double weight = lexical_cast<double>(splitVec[1]);
boost::tie(pos, inserted) = namePosMap.insert(std::make_pair(toVert, Vertex()));
if (inserted) {
v = add_vertex(G);
G[v].name = toVert;
// This will happen later
// G[v].idx = nameMap[toVert];
pos->second = v;
} else {
v = pos->second;
}
Edge e; bool i;
boost::tie(e,i) = add_edge(u,v,G);
G[e].weight = weight;
remEdgeLine--;
}
}
}
if ( namePosMap.size() != boost::num_vertices(G) ) {
std::cerr << "(namePosMap.size() = " << namePosMap.size() << ") != ("
<< "(order(G) = " << boost::num_vertices(G) << ") : Error building the graph, aborting\n";
std::abort();
}
}
gfile.close();
}
开发者ID:kingsfordgroup,项目名称:parana2,代码行数:83,代码来源:GraphUtils.hpp
示例10: auto_match_karaoke
karaoke_match_result auto_match_karaoke(std::vector<std::string> const& source_strings, std::string const& dest_string) {
karaoke_match_result result = { 0, 0 };
if (source_strings.empty()) return result;
using namespace boost::locale::boundary;
using boost::starts_with;
result.source_length = 1;
ssegment_index destination_characters(character, begin(dest_string), end(dest_string));
auto src = boost::to_lower_copy(source_strings[0]);
auto dst = destination_characters.begin();
auto dst_end = destination_characters.end();
// Eat all the whitespace at the beginning of the source and destination
// syllables and exit if either ran out.
auto eat_whitespace = [&]() -> bool {
size_t i = 0, first_non_whitespace = 0;
while (is_whitespace(next_codepoint(src.c_str(), &i)))
first_non_whitespace = i;
if (first_non_whitespace)
src = src.substr(first_non_whitespace);
while (dst != dst_end && is_whitespace(dst->str())) {
++dst;
++result.destination_length;
}
// If we ran out of dest then this needs to match the rest of the
// source syllables (this probably means the user did something wrong)
if (dst == dst_end) {
result.source_length = source_strings.size();
return true;
}
return src.empty();
};
if (eat_whitespace()) return result;
// We now have a non-whitespace character at the beginning of both source
// and destination. Check if the source starts with a romanized kana, and
// if it does then check if the destination also has the appropriate
// character. If it does, match them and repeat.
while (!src.empty()) {
// First check for a basic match of the first character of the source and dest
auto first_src_char = ssegment_index(character, begin(src), end(src)).begin()->str();
if (compare(first_src_char, dst->str()) == 0) {
++dst;
++result.destination_length;
src.erase(0, first_src_char.size());
if (eat_whitespace()) return result;
continue;
}
auto check = [&](kana_pair const& kp) -> bool {
if (!starts_with(&*dst->begin(), kp.kana)) return false;
src = src.substr(strlen(kp.romaji));
for (size_t i = 0; kp.kana[i]; ) {
i += dst->length();
++result.destination_length;
++dst;
}
return true;
};
bool matched = false;
for (auto const& match : romaji_to_kana(src)) {
if (check(match)) {
if (eat_whitespace()) return result;
matched = true;
break;
}
}
if (!matched) break;
}
// Source and dest are now non-empty and start with non-whitespace.
// If there's only one character left in the dest, it obviously needs to
// match all of the source syllables left.
if (std::distance(dst, dst_end) == 1) {
result.source_length = source_strings.size();
++result.destination_length;
return result;
}
// We couldn't match the current character, but if we can match the *next*
// syllable then we know that everything in between must belong to the
// current syllable. Do this by looking up to KANA_SEARCH_DISTANCE
// characters ahead in destination and seeing if we can match them against
// the beginning of a syllable after this syllable.
// If a match is found, make a guess at how much source and destination
// should be selected based on the distances it was found at.
// The longest kanji are 'uketamawa.ru' and 'kokorozashi', each with a
// reading consisting of five kana. This means each each character from
// the destination can match at most five syllables from the source.
static const int max_character_length = 5;
// Arbitrarily chosen limit on the number of dest characters to try
//.........这里部分代码省略.........
开发者ID:Leinad4Mind,项目名称:Aegisub,代码行数:101,代码来源:karaoke_matcher.cpp
示例11: readFromAdjacencyList
void readFromAdjacencyList( const string& fname, GraphT& G ) {
typedef typename boost::graph_traits< GraphT >::vertex_descriptor Vertex;
typedef typename boost::graph_traits< GraphT >::edge_descriptor Edge;
typedef unordered_map<string,Vertex> svMap;
svMap namePosMap;
bool inserted;
Vertex u,v;
typename unordered_map<string,Vertex>::iterator pos;
string line;
typedef vector< string > splitVectorT;
ifstream gfile(fname);
size_t numInsertedVerts = 0;
if ( gfile.is_open() ) {
while( gfile.good() ) {
getline( gfile, line, '\n' );
if ( gfile.eof() ) { break; }
boost::algorithm::trim(line);
auto vline = line.substr( 0, line.find_first_of('#') );
splitVectorT splitVec;
split( splitVec, vline, is_any_of(" \t"), token_compress_on );
if ( splitVec.size() > 0 and vline.size() > 0 ) {
auto fromVert = splitVec[0];
boost::tie( pos, inserted ) = namePosMap.insert( std::make_pair(fromVert,Vertex()) );
if (inserted) {
++numInsertedVerts;
u = add_vertex(G);
G[u].name = fromVert;
// This will happen later
// G[u].idx = nameMap[fromVert];
pos->second = u;
} else {
u = pos->second;
}
for( auto tgtIt = splitVec.begin() + 1; tgtIt != splitVec.end(); ++tgtIt ) {
auto& tgt = *tgtIt;
boost::tie(pos, inserted) = namePosMap.insert(std::make_pair(tgt, Vertex()));
if (inserted) {
++numInsertedVerts;
v = add_vertex(G);
G[v].name = tgt;
// This will happen later
// G[v].idx = nameMap[tgt];
pos->second = v;
} else {
v = pos->second;
}
Edge e; bool i;
boost::tie(e,i) = add_edge(u,v,G);
G[e].weight = 1.0;
}
}
}
if ( namePosMap.size() != boost::num_vertices(G) ) {
std::cerr << "(namePosMap.size() = " << namePosMap.size() << ") != ("
<< "(order(G) = " << boost::num_vertices(G) << ") : Error building the graph, aborting\n";
std::abort();
}
}
gfile.close();
}
开发者ID:kingsfordgroup,项目名称:parana2,代码行数:68,代码来源:GraphUtils.hpp
示例12: main
int main(int argc, char* argv[]){
// Configurable parameters
int max_events; // Maximum number of events to process
string filelist; // The file containing a list of files to use as input
string input_prefix; // A prefix that will be added to the path of each input file
string output_name; // Name of the ouput ROOT File
string output_folder; // Folder to write the output in
po::options_description config("Configuration");
po::variables_map vm;
po::notify(vm);
config.add_options()
("max_events", po::value<int>(&max_events)-> default_value(-1))
("filelist", po::value<string>(&filelist)->required())
("input_prefix", po::value<string>(&input_prefix)->default_value(""))
("output_name", po::value<string>(&output_name)->required())
("output_folder", po::value<string>(&output_folder)->default_value(""))
;
po::store(po::command_line_parser(argc, argv).
options(config).allow_unregistered().run(), vm);
po::notify(vm);
std::cout << "-------------------------------------" << std::endl;
std::cout << "JetTauFakeRateStudy" << std::endl;
std::cout << "-------------------------------------" << std::endl; string param_fmt = "%-25s %-40s\n";
// Load necessary libraries for ROOT I/O of custom classes
gSystem->Load("libFWCoreFWLite.dylib");
gSystem->Load("libUserCodeICHiggsTauTau.dylib");
AutoLibraryLoader::enable();
// Build a vector of input files
vector<string> files = ParseFileLines(filelist);
for (unsigned i = 0; i < files.size(); ++i) files[i] = input_prefix + files[i];
// Create ROOT output fileservice
fwlite::TFileService *fs = new fwlite::TFileService((output_folder+output_name).c_str());
//Optional configurable parameters with which you can filter the collection you are interested in.
double jet_pt, jet_eta, tau_pt, tau_eta;
jet_pt = 20.0;
jet_eta = 2.3;
tau_pt = 20.0;
tau_eta = 2.3;
std::cout << "** Kinematics **" << std::endl;
std::cout << boost::format(param_fmt) % "jet_pt" % jet_pt;
std::cout << boost::format(param_fmt) % "jet_eta" % jet_eta;
std::cout << boost::format(param_fmt) % "tau_pt" % tau_pt;
std::cout << boost::format(param_fmt) % "tau_eta" % tau_eta;
//Defining an analysis using this class removes all the need for any for loops through the events. An "analysis" loops through all the events up to max_events and runs the modules which you define at the end of this script using analysis.AddModule
ic::AnalysisBase analysis(
"JetTauFakeRateStudy",// Analysis name
files, // Input files
"icEventProducer/EventTree", // TTree name
max_events); // Max. events to process (-1 = all)
analysis.SetTTreeCaching(true);
analysis.StopOnFileFailure(true);
analysis.RetryFileAfterFailure(7, 3);
//For now, read in all the jets and taus within the pt and eta range of interest. Using Andrew's modules makes it much easier to
//add other things later, if we need a certain type of ID (or flavour selection) applied to the jets/taus
SimpleFilter<Tau> TauFilter = SimpleFilter<Tau>("TauFilter")
.set_input_label("taus")
.set_predicate(bind(MinPtMaxEta, _1, tau_pt, tau_eta));
SimpleFilter<PFJet> JetFilter = SimpleFilter<PFJet>("JetFilter")
.set_input_label("pfJetsPFlow")
.set_predicate(bind(MinPtMaxEta, _1, jet_pt, jet_eta));
JetTauFakeRateExample jetTauFakeRate = JetTauFakeRateExample("jetTauFakeRate")
.set_write_plots(false)
.set_write_tree(true);
//Add module here which reads in the filtered taus and jets and makes the plots/performs the fake rate study
analysis.AddModule(&TauFilter);
analysis.AddModule(&JetFilter);
analysis.AddModule(&jetTauFakeRate);
analysis.RunAnalysis();
delete fs;
return 0;
}
开发者ID:ICHiggsInv,项目名称:ICHiggsTauTau,代码行数:92,代码来源:JetTauFakeRateExample.cpp
示例13: main
int main()
{
using boost::mem_fn;
X x;
X const & rcx = x;
X const * pcx = &x;
boost::shared_ptr<X> sp(new X);
mem_fn(&X::f0)(x);
mem_fn(&X::f0)(&x);
mem_fn(&X::f0)(sp);
mem_fn(&X::g0)(x);
mem_fn(&X::g0)(rcx);
mem_fn(&X::g0)(&x);
mem_fn(&X::g0)(pcx);
mem_fn(&X::g0)(sp);
mem_fn(&X::f1)(x, 1);
mem_fn(&X::f1)(&x, 1);
mem_fn(&X::f1)(sp, 1);
mem_fn(&X::g1)(x, 1);
mem_fn(&X::g1)(rcx, 1);
mem_fn(&X::g1)(&x, 1);
mem_fn(&X::g1)(pcx, 1);
mem_fn(&X::g1)(sp, 1);
mem_fn(&X::f2)(x, 1, 2);
mem_fn(&X::f2)(&x, 1, 2);
mem_fn(&X::f2)(sp, 1, 2);
mem_fn(&X::g2)(x, 1, 2);
mem_fn(&X::g2)(rcx, 1, 2);
mem_fn(&X::g2)(&x, 1, 2);
mem_fn(&X::g2)(pcx, 1, 2);
mem_fn(&X::g2)(sp, 1, 2);
mem_fn(&X::f3)(x, 1, 2, 3);
mem_fn(&X::f3)(&x, 1, 2, 3);
mem_fn(&X::f3)(sp, 1, 2, 3);
mem_fn(&X::g3)(x, 1, 2, 3);
mem_fn(&X::g3)(rcx, 1, 2, 3);
mem_fn(&X::g3)(&x, 1, 2, 3);
mem_fn(&X::g3)(pcx, 1, 2, 3);
mem_fn(&X::g3)(sp, 1, 2, 3);
mem_fn(&X::f4)(x, 1, 2, 3, 4);
mem_fn(&X::f4)(&x, 1, 2, 3, 4);
mem_fn(&X::f4)(sp, 1, 2, 3, 4);
mem_fn(&X::g4)(x, 1, 2, 3, 4);
mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
mem_fn(&X::g4)(&x, 1, 2, 3, 4);
mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
mem_fn(&X::g4)(sp, 1, 2, 3, 4);
mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
//.........这里部分代码省略.........
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:101,代码来源:mem_fn_cdecl_test.cpp
示例14: connections
SetupDialog::SetupDialog(GraphBarImpl* barImpl)
: connections(barImpl->connections),
focusedGraphWidget(barImpl->focusedGraphWidget)
{
using boost::bind;
setWindowTitle(_("Graph Setup"));
QVBoxLayout* vbox = new QVBoxLayout();
setLayout(vbox);
QHBoxLayout* hbox = new QHBoxLayout();
hbox->addWidget(new QLabel(_("Line width")));
lineWidthSpin.setRange(1, 9);
lineWidthSpin.setValue(1);
connections.add(
lineWidthSpin.sigValueChanged().connect(
bind(&SetupDialog::onLineWidthChanged, this, _1)));
hbox->addWidget(&lineWidthSpin);
hbox->addStretch();
vbox->addLayout(hbox);
hbox = new QHBoxLayout();
hbox->addWidget(new QLabel(_("y-range, 10^")));
verticalValueRangeSpin.setDecimals(1);
verticalValueRangeSpin.setRange(-99.8, 99.8);
verticalValueRangeSpin.setSingleStep(0.1);
verticalValueRangeSpin.setValue(1.0);
connections.add(
verticalValueRangeSpin.sigValueChanged().connect(
bind(&SetupDialog::onVerticalValueRangeChanged, this, _1)));
hbox->addWidget(&verticalValueRangeSpin);
showLimitCheck.setText(_("Show limit values"));
showLimitCheck.setChecked(true);
connections.add(
showLimitCheck.sigToggled().connect(
bind(&SetupDialog::onShowLimitToggled, this, _1)));
hbox->addWidget(&showLimitCheck);
|
请发表评论