本文整理汇总了C++中boost::str方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::str方法的具体用法?C++ boost::str怎么用?C++ boost::str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost
的用法示例。
在下文中一共展示了boost::str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char* [])
{
using boost::format;
using boost::str;
#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF)
using boost::wformat;
wformat wfmter(L"%%##%%##%%1 %1%00");
if(str( wfmter % L"Escaped OK" ) != L"%##%##%1 Escaped OK00")
BOOST_ERROR("Basic w-parsing Failed");
if(str( wformat(L"%%##%#x ##%%1 %s00") % 20 % L"Escaped OK" ) != L"%##0x14 ##%1 Escaped OK00")
BOOST_ERROR("Basic wp-parsing Failed") ;
// testcase for https://svn.boost.org/trac10/ticket/7379 (for valgrind)
wformat wfmt(L"%1$.1f");
std::wstring ws = str(wfmt % 123.45f);
BOOST_TEST_EQ(ws.compare(L"123.4"), 0);
wformat wfmt2(L"%1$.0f %%");
std::wstring ws2 = (wfmt2 % 123.45f).str();
BOOST_TEST_EQ(ws2.compare(L"123 %"), 0);
#endif // wformat tests
return boost::report_errors();
}
示例2: write_to_dimacs
void write_to_dimacs( const circuit& circ, const std::string& filename )
{
using boost::format;
using boost::str;
std::vector<unsigned> line_to_var( circ.lines() );
boost::iota( line_to_var, 1u );
auto next_var = circ.lines() + 1u;
std::ofstream os( filename.c_str() );
for ( const auto& g : circ )
{
assert( is_toffoli( g ) );
const auto target = g.targets().front();
switch ( g.controls().size() )
{
case 0u:
os << format( "x%d %d 0" ) % line_to_var[target] % next_var << std::endl;
line_to_var[target] = next_var++;
break;
case 1u:
{
const auto c = g.controls().front();
os << format( "x%s%d %d -%d 0" ) % ( c.polarity() ? "" : "-" ) % line_to_var[c.line()] % line_to_var[target] % next_var << std::endl;
line_to_var[target] = next_var++;
}
break;
default:
{
std::string all;
for ( const auto& c : g.controls() )
{
os << format( "%s%d -%d 0" ) % ( c.polarity() ? "" : "-" ) % line_to_var[c.line()] % next_var << std::endl;
all += str( format( "%s%d " ) % ( c.polarity() ? "-" : "" ) % line_to_var[c.line()] );
}
os << format( "%s%d 0" ) % all % next_var << std::endl;
os << format( "x%d %d -%d 0" ) % next_var % line_to_var[target] % ( next_var + 1 ) << std::endl;
line_to_var[target] = next_var + 1;
next_var += 2u;
}
break;
}
}
std::string ors;
for ( auto i = 0u; i < circ.lines(); ++i )
{
os << format( "x-%d %d %d 0" ) % ( next_var + i ) % ( i + 1 ) % line_to_var[i] << std::endl;
ors += str( format( "%d " ) % ( next_var + i ) );
}
os << ors << "0" << std::endl;
os.close();
}
示例3: writeData
void writeData()
{
std::string defs;
fs::path defs_path = out_dir / (out_file_prepend + ".defs");
print(format("write directory = %s\n") % out_dir);
print(format("write file prefix = \"%s\"\n") % out_file_prepend);
if(!dry_run) fs::create_directories(out_dir);
for(int i = 0; i < packer.numSheets(); i++)
{
Sheet *s = packer.getSheet(i);
fs::path dst = out_dir / str(format("%s%03d.%s") % out_file_prepend % i % "png");
print(format("writing sheet to %s\n") % dst);
s->saveImage(dst);
defs += getSheetDefinitions(dst, s);
}
print(format("writing definitions to %s\n") % defs_path);
if(!dry_run)
{
fs::ofstream out(defs_path);
out << defs;
if(out.fail())
print(format("failed to write %s\n") % defs_path, VERBOSE);
}
}
示例4: getSheetDefinitions
std::string getSheetDefinitions(const fs::path &path, Sheet *s)
{
std::string out;
for(size_t i = 0; i < s->images.size(); i++)
{
Image *img = s->images[i];
for(size_t j = 0; j < img->names.size(); j++)
{
out += str(format("%s\n") % img->names[j]);
out += str(format("%s\n") % path.string());
out += str(format("%d %d %d %d\n") % (img->sheet_x + img->source_x_offset) % (img->sheet_y + img->source_y_offset) % img->source_width % img->source_height);
out += str(format("%f %f %f %f\n") % img->s0 % img->s1 % img->t0 % img->t1);
}
}
return out;
}
示例5: VersionString
std::string Version::VersionString()
{
using boost::format;
using boost::str;
std::string version = str(format("%d.%d.%d") % API_MAJOR % API_MINOR % API_PATCH);
#ifndef NDEBUG
version += "-DEBUG";
#endif // !NDEBUG
return version;
}
示例6: exception
FileWriter::FileWriter(std::wstring fileName, const std::shared_ptr<concurrent_queue<std::string>>& queue) :
queue_(queue),
exit_(false)
{
file_ = CreateFile(fileName.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (file_ == INVALID_HANDLE_VALUE)
{
throw new exception(str(format("Could not create file %1%") % string(fileName.begin(), fileName.end())).c_str());
}
thread_ = unique_ptr<thread>(new thread(&FileWriter::ThreadFunc, this));
}
示例7: getChannelData
FloatVectorDataPtr ImageCompositeOp::getChannelData( ImagePrimitive * image, const std::string &channelName, bool mustExist )
{
assert( image );
PrimitiveVariableMap::iterator it = image->variables.find( channelName );
if( it==image->variables.end() )
{
if ( mustExist )
{
throw Exception( str( format( "ImageCompositeOp: Channel \"%s\" does not exist." ) % channelName ) );
}
else
{
return 0;
}
}
if( it->second.interpolation!=PrimitiveVariable::Vertex &&
it->second.interpolation!=PrimitiveVariable::Varying &&
it->second.interpolation!=PrimitiveVariable::FaceVarying )
{
throw Exception( str( format( "ImageCompositeOp: Primitive variable \"%s\" has inappropriate interpolation." ) % channelName ) );
}
if( !it->second.data )
{
throw Exception( str( format( "ImageCompositeOp: Primitive variable \"%s\" has no data." ) % channelName ) );
}
ChannelConverter converter( channelName );
return despatchTypedData<
ChannelConverter,
TypeTraits::IsNumericVectorTypedData,
ChannelConverter::ErrorHandler
>( it->second.data.get(), converter );
}
示例8: connected
void SslConnector::connected(const Socket&) {
connector = 0;
aio = AsynchIO::create(socket,
boost::bind(&SslConnector::readbuff, this, _1, _2),
boost::bind(&SslConnector::eof, this, _1),
boost::bind(&SslConnector::disconnected, this, _1),
boost::bind(&SslConnector::socketClosed, this, _1, _2),
0, // nobuffs
boost::bind(&SslConnector::writebuff, this, _1));
aio->createBuffers(maxFrameSize);
identifier = str(format("[%1%]") % socket.getFullAddress());
ProtocolInitiation init(version);
writeDataBlock(init);
aio->start(poller);
}
示例9: thumb_lightmap
void utils::thumb_lightmap(Params params) {
illum::GrayLightfield lightmap(params.alt_spacing);
if(params.lightmap_dir.empty())
throw std::runtime_error("no lightmap directory specified");
log("LOADING lightmap ...");
lightmap.load(params.lightmap_dir);
for(double alt = 0; alt < 1000; alt += params.alt_spacing) {
try {
Mat raw_avg;
lightmap.getAverage(raw_avg, alt);
// now do a quick-and-dirty conversion to color
Mat bgr_avg = demosaic_thumb_lq(raw_avg, params.bayer_pattern);
// now convert to 8u
bgr_avg *= 255.0 / 65535.0;
fs::path p(params.lightmap_dir);
p /= str(boost::format("thumb_slice_%.02f.jpg") % alt);
log("SAVING thumbnail %s") % p.string();
imwrite(p.string(), bgr_avg);
} catch(std::exception const &e) {
log_error("ERROR thumbnailing: %s") % e.what();
}
}
}
示例10: notifyConnection
void LinkRegistry::notifyConnection(const std::string& key, amqp_0_10::Connection* c)
{
// find a link that is attempting to connect to the remote, and
// create a mapping from connection id to link
QPID_LOG(debug, "LinkRegistry::notifyConnection(); key=" << key );
std::string host;
Link::shared_ptr link;
{
Mutex::ScopedLock locker(lock);
LinkMap::iterator l = pendingLinks.find(key);
if (l != pendingLinks.end()) {
link = l->second;
pendingLinks.erase(l);
connections[key] = link->getName();
QPID_LOG(debug, "LinkRegistry:: found pending =" << link->getName());
}
}
if (link) {
link->established(c);
c->setUserId(str(format("%1%@%2%") % link->getUsername() % realm));
}
}
示例11: parseCmdLine
void parseCmdLine(int argc, char *argv[])
{
opts::options_description desc("Options");
desc.add_options()
("help,h", "Print this message.\n")
("output,o",
opts::value<std::string>(&cmd_output)->required(),
"Path to prepend to all files written.\n")
("input,i",
opts::value< std::vector<std::string> >(&input_paths),
"Path a files or folder to pack. Multiple inputs can be specified as positional arguments.\n")
("stdin",
opts::bool_switch(&read_stdin),
"Read input paths from the standard input. Any paths read are appended to those specified by --input.\n")
("recursive,r",
opts::bool_switch(&recursive),
"Recurse into any directories specified.\n")
("image-size,s",
opts::value<std::string>(&cmd_img_size),
str(format("Size of the packed images. This is a maximum size if --compact is specified and a minimum size if --power-of-two is specified. Default size is set to %s. Example: --image-size 1024x1024\n") % cmd_img_size).c_str())
("power-of-two,p",
opts::bool_switch(&power_of_two),
"Keep sheet sizes a power of two. If a dimension in --image-size is not a power of two it is rounded up to the nearst power.\n")
("extrude,e",
opts::value<int>(&extrude),
"Number of pixels to extrude the edges of source images by. Example: --extrude 1. default = 0.\n")
("compact,c",
opts::bool_switch(&compact),
"Create sheets smaller than --image-size if possible.\n")
("tex-coord-origin,t",
opts::value<std::string>(&cmd_tex_coord_origin),
"Origin to use when computing sprite texture coordinates. Either bottom-left or top-left.\n")
("dry-run,d",
opts::bool_switch(&dry_run),
"Don't write any files.\n")
("no-cache",
opts::bool_switch(&no_cache),
"Disables caching of image data and causes images to be loaded and unloaded on demand. Useful when packing more images than can fit into memory.\n")
("silent,S",
opts::bool_switch(&silent),
"Disables printing.\n")
("verbose,v",
opts::bool_switch(&verbose),
"Print detailed information.\n")
;
opts::positional_options_description p;
p.add("input", -1);
opts::variables_map vars;
try
{
opts::store(opts::command_line_parser(argc, argv).options(desc).positional(p).run(), vars);
if(vars.count("help"))
{
print(cmd_help);
print(format("%1%") % desc);
exit(EXIT_SUCCESS);
}
opts::notify(vars);
}
catch(const opts::error &e)
{
print(format("%1%\n\n") % e.what());
print(cmd_help);
fatal(format("%1%") % desc);
}
std::vector<std::string> strs;
boost::split(strs, cmd_img_size, boost::is_any_of("x"));
if(strs.size() != 2)
fatal("error parsing image-size\n");
try
{
cmd_sheet_width = boost::lexical_cast<int>(strs[0]);
cmd_sheet_height = boost::lexical_cast<int>(strs[1]);
}
catch(const boost::bad_lexical_cast&)
{
fatal("error parsing image-size\n");
//.........这里部分代码省略.........
示例12: str
DicomConfig::DicomConfig( const std::string &configFileName ):config_( new DcmQueryRetrieveConfig ) {
if (config_->init( configFileName.c_str() )!=1) throw runtime_error(
str( format("error reading config file:%1%") % configFileName ) );
readDBMap( config_, dbMap_ );
maxPDU_ = config_->getMaxPDUSize();
}
示例13: test_main
int test_main(int, char* [])
{
using namespace std;
using boost::format;
using boost::io::group;
using boost::str;
string s, s2;
// special paddings
s = str( format("[%=6s] [%+6s] [%+6s] [% 6s] [%+6s]\n")
% 123
% group(internal, setfill('W'), 234)
% group(internal, setfill('X'), -345)
% group(setfill('Y'), 456)
% group(setfill('Z'), -10 ) );
if(s != "[ 123 ] [+WW234] [-XX345] [YY 456] [ZZZ-10]\n" ) {
cerr << s ;
BOOST_ERROR("formatting error. (with special paddings)");
}
s = str( format("[% 6.8s] [% 8.6s] [% 7.7s]\n")
% group(internal, setfill('x'), Rational(12345,54321))
% group(internal, setfill('x'), Rational(123,45))
% group(internal, setfill('x'), Rational(123,321))
);
if(s != (s2="[ 12345/5] [ xx123/4] [ 123/32]\n" )) {
cerr << s << s2;
BOOST_ERROR("formatting error. (with special paddings)");
}
s = str( format("[% 6.8s] [% 6.8s] [% 6.8s] [% 6.8s] [%6.8s]\n")
% 1234567897
% group(setfill('x'), 12)
% group(internal, setfill('x'), 12)
% group(internal, setfill('x'), 1234567890)
% group(internal, setfill('x'), 123456)
);
if(s != (s2="[ 1234567] [xxx 12] [ xxx12] [ 1234567] [123456]\n") ) {
cerr << s << s2;
BOOST_ERROR("formatting error. (with special paddings)");
}
s = str( format("[% 8.6s] [% 6.4s] [% 6.4s] [% 8.6s] [% 8.6s]\n")
% 1234567897
% group(setfill('x'), 12)
% group(internal, setfill('x'), 12)
% group(internal, setfill('x'), 1234567890)
% group(internal, setfill('x'), 12345)
);
if(s != (s2="[ 12345] [xxx 12] [ xxx12] [ xx12345] [ xx12345]\n") ) {
cerr << s << s2;
BOOST_ERROR("formatting error. (with special paddings)");
}
// nesting formats :
s = str( format("%2$014x [%1%] %|2$05|\n") % (format("%05s / %s") % -18 % 7)
%group(showbase, -100)
);
if( s != "0x0000ffffff9c [-0018 / 7] -0100\n" ){
cerr << s ;
BOOST_ERROR("nesting did not work");
}
// testcase for bug reported at
// http://lists.boost.org/boost-users/2006/05/19723.php
format f("%40t%1%");
int x = 0;
f.bind_arg(1, x);
f.clear();
// testcase for bug reported at
// http://lists.boost.org/boost-users/2005/11/15454.php
std::string l_param;
std::string l_str = (boost::format("here is an empty string: %1%") % l_param).str();
// testcase for SourceForge bug #1506914
std::string arg; // empty string
s = str(format("%=8s") % arg);
return 0;
}
示例14: main
int main(int argc, char **argv)
{
std::string environment_uri;
std::string robot_name;
std::string plugin_name;
size_t num_trials;
bool self = false;
bool profile = false;
// Parse arguments.
po::options_description desc("Profile OpenRAVE's memory usage.");
desc.add_options()
("num-samples", po::value<size_t>(&num_trials)->default_value(10000),
"number of samples to run")
("self", po::value<bool>(&self)->zero_tokens(),
"run self-collision checks")
("profile", po::value<bool>(&profile)->zero_tokens(),
"remove objects from environment")
("environment_uri",
po::value<std::string>(&environment_uri)->required(),
"number of samples to run")
("robot", po::value<std::string>(&robot_name)->required(),
"robot_name")
("collision_checker",
po::value<std::string>(&plugin_name)->required(),
"collision checker name")
("help",
"print usage information")
;
po::positional_options_description pd;
pd.add("environment_uri", 1);
pd.add("robot", 1);
pd.add("collision_checker", 1);
po::variables_map vm;
po::store(
po::command_line_parser(argc, argv)
.options(desc)
.positional(pd).run(),
vm
);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
// Create the OpenRAVE environment.
RaveInitialize(true);
EnvironmentBasePtr const env = RaveCreateEnvironment();
CollisionCheckerBasePtr const collision_checker
= RaveCreateCollisionChecker(env, plugin_name);
env->SetCollisionChecker(collision_checker);
env->StopSimulation();
// "/usr/share/openrave-0.9/data/wamtest1.env.xml"
env->Load(environment_uri);
KinBodyPtr const body = env->GetKinBody(robot_name);
// Generate random configuations.
std::vector<OpenRAVE::dReal> lower;
std::vector<OpenRAVE::dReal> upper;
body->GetDOFLimits(lower, upper);
std::vector<std::vector<double> > data;
data = benchmarks::DataUtils::GenerateRandomConfigurations(
num_trials, lower, upper);
//
RAVELOG_INFO("Running %d collision checks.\n", num_trials);
boost::timer const timer;
if (profile) {
std::string const prof_name = str(
format("CheckCollision.%s.prof") % plugin_name);
RAVELOG_INFO("Writing gperftools information to '%s'.\n",
prof_name.c_str()
);
ProfilerStart(prof_name.c_str());
}
size_t num_collision = 0;
for (size_t i = 0; i < num_trials; ++i) {
body->SetDOFValues(data[i]);
bool is_collision;
if (self) {
is_collision = body->CheckSelfCollision();
} else {
is_collision = env->CheckCollision(body);
}
num_collision += !!is_collision;
}
if (profile) {
ProfilerStop();
//.........这里部分代码省略.........
示例15: ImportMolproLib
void FBasisSetLibraryImpl::ImportMolproLib(std::string const &FileName, std::ostream *pxout)
{
// how this files look:
// Note: Lines with * are comments.
// He s STO-3G STO3G : 3 1 1.3
// STO-3G
// 6.3624214 1.158923 0.31364979 0.15432897 0.53532814 0.44463454
// Li s STO-3G STO3G : 6 2 1.3 4.6
// STO-3G
// 16.119575 2.9362007 0.7946505 0.6362897 0.1478601 0.0480887 0.15432897
// 0.53532814 0.44463454 -0.09996723 0.39951283 0.70011547
// Li p STO-3G STO3G : 3 1 1.3
// STO-3G
// 0.6362897 0.1478601 0.0480887 0.15591627 0.60768372 0.39195739
// B s cc-pVDZ VDZ : 9 3 1.9 1.9 9.9
// cc-pVDZ
// 4570 685.9 156.5 44.47 14.48 5.131 1.898 0.3329 0.1043 0.000696
// 0.005353 0.027134 0.10138 0.272055 0.448403 0.290123 0.014322 -0.003486
// -0.000139 -0.001097 -0.005444 -0.021916 -0.059751 -0.138732 -0.131482
// 0.539526 0.580774 1
// interpretation: First Line:
// ElementName OrbitalType N*[AlternativeNameI] :
// #PrimOrbitals #OrbitalsTheyAreContractedTo N*[ContractFrom.ContractTo]
// Any string, usually reference to be cited for the basis set
// M*[PrimitiveOrbitalExponents] L*[PrimitiveOrbitalCoefficients]
// for each contraction contraction length coefficients are supplied.
// and data sets like this are also seen:
// H P 6-311G2P : 2 0
// G92 6-311G polarization
// .15000000D+01 .37500000D+00
// H P 6-311G3P : 3 0
// G92 6-311G polarization
// .30000000D+01 .75000000D+00 .18750000D+00
// H S 6-31G** 6-31G* 6-31G : 4 1 1.3
// G92 6-31G**
// .18731137D+02 .28253944D+01 .64012169D+00 .16127776D+00 .33494604D-01
// .23472695D+00 .81375733D+00
// all/some primitive orbitals are probably left uncontracted. Therefore no
// contraction coefficients are supplied for these (only exponents).
// Also I originally tought that the names of the basis set after the first
// one were alternative Names of the set (like cc-pVDZ = VDZ). This is
// however not how it works, at least not in all cases: It seems that names
// which are supplied actually mean that the currently described elements
// have to be inserted into the basis sets of ALL names provided, which
// may or may not be identical basis sets (for example, for the s and p
// orbitals of the 931G basis set, also the starred names are listed, which
// means that these basis sets share these orbitals, altough in general they
// are different).
// so.. let's begin the mess.
// read the entire file into a stringstream object (we need to modify it).
TArray<char>
pFileContent;
if (!LoadFileIntoMemory(pFileContent, FileName))
throw std::runtime_error( "FBasisSetLibraryImpl: Failed to open file '"+FileName+"' for basis library import." );
// okay, now this is very bad. This FORTRAN stuff (sometimes) denotes
// exponents in scientific notation not as "23423e-3" but as "23423D-03". We
// do a lame attempt to convert that. This might break in some situations.
// FIXME: correct this somehow.
for (uint i = 0; i < pFileContent.size() - 2; ++i) {
if (pFileContent[i]=='D' &&
(pFileContent[i+1]=='+' || pFileContent[i+1]=='-') &&
pFileContent[i+2]=='0')
pFileContent[i] = 'E';
}
FBasisNameSet
AllBasisNames;
std::stringstream
str(&pFileContent[0], std::stringstream::in);
// ^- NOTE: "in" means from stream, into local data, not
// into stream (file naming convention)
try {
while(str.good())
{
// clear exception mask, now stream will not throw() when something
// unexpected happens.
str.exceptions(std::ios::goodbit);
std::string
s;
std::getline( str, s );
if (s.size() == 0 || s[0] == '*' || s[0] == '!')
// empty or comment line, throw it away and go on with the next
continue;
if (!str.good()) // eof, bad etc.
break;
str.exceptions(std::ios::failbit);
// ^- when something fails, throw an exception. this will happen
// if the actual file format does not match the one I had in mind
// when coding this.
// expected format: ElementName[w]OrbitalType[w]AlternativeNames[w] :
// using namespace std;
// cout << "** read line: '" << s << "'" << endl;
std::stringstream
line(s, std::stringstream::in);
line.exceptions(std::ios::badbit | std::ios::failbit);
//.........这里部分代码省略.........