本文整理汇总了C++中boost::split方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::split方法的具体用法?C++ boost::split怎么用?C++ boost::split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost
的用法示例。
在下文中一共展示了boost::split方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_command
string Worker::process_command (string command)
{
DEBUG(cout << command << endl);
trim (command);
vector <string> parts;
split (parts, command, is_any_of (L" "), boost::token_compress_on);
const size_t command_p = 0;
if (parts.size() < 1)
{
return string ("error \"bad command format\"");
}
if (parts [0] == "get")
{
const size_t key_p = 1;
if (parts.size() != 2)
{
return string ("error \"bad get format\"");
}
return process_get (parts [key_p]);
}
if (parts [0] == "set")
{
const size_t ttl_p = 1;
const size_t key_p = 2;
const size_t value_p = 3;
if (parts.size () != 4)
{
return string ("error \"bad set format\"");
}
ttl_t ttl = 0;
try
{
ttl = boost::lexical_cast<ttl_t> (parts [ttl_p]);
}
catch(boost::bad_lexical_cast& e)
{
return string ("error \"bad set format (ttl format)\"");
}
return process_set (parts [key_p], ttl, parts [value_p]);
}
return string ("error \"bad command format\"");
}
示例2: parse_command
command_s Command::parse_command (string command)
{
command_s result;
trim (command);
parse_redirect (command, result);
trim (command);
split (result.params, command, is_any_of (L" "), boost::token_compress_on);
result.name = result.params [0];
//result.params.erase (result.params.begin ());
return result;
}
示例3: ContactCondition
//.........这里部分代码省略.........
std::function<void(CalcNode&)> setter;
if (useValues)
{
xml::Node valuesNode = valuesNodes.front();
vector<string> names = {"vx", "vy", "vz", "sxx", "sxy", "sxz", "syy", "syz", "szz"};
int i = 0;
for (auto value_name: names)
{
string v = valuesNode.getAttributes()[value_name];
values[i++] = v.empty() ? 0.0 : lexical_cast<real>(v);
}
LOG_DEBUG("Initial state values: "
<< values[0] << " " << values[1] << " " << values[2] << " "
<< values[3] << " " << values[4] << " " << values[5] << " "
<< values[6] << " " << values[7] << " " << values[8] );
}
else
{
xml::Node pWaveNode = pWaveNodes.front();
auto attrs = pWaveNode.getAttributes();
auto direction = attrs["direction"];
if (direction.empty())
THROW_INVALID_INPUT("P-wave direction is not specified");
vector<string> _direction;
split(_direction, direction, is_any_of(";"));
if (_direction.size() != 3)
THROW_INVALID_INPUT("Invalid P-wave direction specified");
auto dx = lexical_cast<real>(_direction[0]);
auto dy = lexical_cast<real>(_direction[1]);
auto dz = lexical_cast<real>(_direction[2]);
Vector3 dir({dx, dy, dz});
if (dx == 0.0 && dy == 0.0 && dz == 0.0)
THROW_INVALID_INPUT("Invalid P-wave direction specified");
auto scale = attrs["amplitudeScale"];
if (scale.empty())
THROW_INVALID_INPUT("P-wave amplitude scale is not specified");
auto amplitudeScale = lexical_cast<real>(scale);
if (amplitudeScale <= 0.0)
THROW_INVALID_INPUT("P-wave amplitude must be positive");
auto type = attrs["type"];
if (type.empty())
THROW_INVALID_INPUT("P-wave type is not specified");
if (type != "compression" && type != "rarefaction")
THROW_INVALID_INPUT("Invalid P-wave type specified");
auto compression = type == "compression";
setter = [=](CalcNode& node)
{
setIsotropicElasticPWave(node, dir, amplitudeScale, compression);
};
示例4: 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();
}
示例5: 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();
}