本文整理汇总了C++中strings::size方法的典型用法代码示例。如果您正苦于以下问题:C++ strings::size方法的具体用法?C++ strings::size怎么用?C++ strings::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings
的用法示例。
在下文中一共展示了strings::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_volumes
void load_volumes(strings& s,grids& vols,int skip,bool verbose)
{
vols.resize(s.size()-skip); //first column is eigenvalue
for(int i=0;i<(s.size()-skip);i++)
{
/*if(verbose)
std::cout<<s[i+skip].c_str()<<" "<<std::flush;*/
minc_1_reader rdr;
rdr.open(s[i+skip].c_str());
load_simple_volume(rdr,vols[i]);
}
}
示例2: save_volumes
void save_volumes(strings& s,volumes& vols,const char *like,const std::string & append_history)
{
for(int i=0;i<s.size();i++)
{
save_volume(vols[i],s[i].c_str(),like,append_history);
}
}
示例3: ReverberateNetwork
RevKBCCTrainer::reverbdpoint RevKBCCTrainer::ReverberateNetwork( strings subView /*= strings(0)*/ )
{
//changing the clean reverb to only threshold the outputs.
//if the numcontexts is set above 0 then we'll get them from the dataset.
int inSize = revNet->GetNumIn();
if (revparams.numContexts > 0 || subView.size() > 0) {
//assert(revparams.numContexts > 0);
if(revparams.numContexts == 0) {
revparams.numContexts = subView.size();
}
inSize -= revparams.numContexts;
}
vecDouble tmpIn(inSize);
for (uint i = 0; i < tmpIn.size(); i++)
{
tmpIn[i] = revRand();
}
if (revparams.numContexts > 0) {
vecDouble randContext;
if (subView.size() > 0) {
randContext = dynamic_pointer_cast<CSMTLDataset>(data)->GetRandContext(subView);
}
else {
randContext = dynamic_pointer_cast<CSMTLDataset>(data)->GetRandContext();
}
tmpIn = ConcatVec(tmpIn,randContext);
}
revNet->Activate(tmpIn);
for (uint i = 1; i < revparams.numRev; i++)
{
tmpIn = revNet->GetAutoAssocLayer()->GetOutput();
revNet->Activate(tmpIn);
}
reverbdpoint retVal;
retVal.inPoint = tmpIn;
retVal.outPoint = revNet->GetNormOutLayer()->GetOutput();
if(revparams.cleanReverb) { //This shouldn't be used when the outputs are real.
retVal.outPoint = ApplyThreshold(retVal.outPoint);
}
#ifdef _DEBUG
cout << "in: " << retVal.inPoint << "out" << retVal.outPoint << endl;
#endif
return retVal;
}
示例4: runCmd
bool nsUtils::runCmd(const string& cmd,
const strings& input,
strings& output)
{
int childStdIn[2]; // child read 0, parent write 1
int childStdOut[2]; // parent read 0, child write 1
if (pipe(childStdIn) != 0) {
std::cerr << "Failed to create pipe 1\n";
return false;
}
if (pipe(childStdOut) != 0) {
std::cerr << "Failed to create pipe 2\n";
return false;
}
pid_t child(fork());
if (child == -1) {
std::cerr << "Failed to fork\n";
close(childStdIn[0]);
close(childStdIn[1]);
close(childStdOut[0]);
close(childStdOut[1]);
return false;
}
if (child == 0) {
// child
close(childStdIn[1]);
close(childStdOut[0]);
dup2(childStdIn[0], 0);
dup2(childStdOut[1], 1);
execl(cmd.c_str(), cmd.c_str(), NULL);
exit(1);
}
// parent
close(childStdIn[0]);
close(childStdOut[1]);
char lineEnd('\n');
for (size_t i = 0; i < input.size(); ++i) {
write(childStdIn[1], input[i].c_str(), input[i].length());
write(childStdIn[1], &lineEnd, 1);
}
close(childStdIn[1]);
ssize_t readCount;
const int bufferSize(512);
char buffer[bufferSize + 1];
while ((readCount = read(childStdOut[0], buffer, bufferSize)) > 0) {
buffer[readCount] = '\0';
if (buffer[readCount - 1] == '\n') {
buffer[readCount - 1] = '\0';
}
output.push_back(string(buffer));
}
close(childStdOut[0]);
wait(NULL);
return true;
}
示例5: sendSetVariable
void HttpInterface::sendSetVariable(const std::string nodeName, const strings& args)
{
// get node id, variable position and length
if (verbose)
cerr << "setVariables " << nodeName << " " << args[0];
unsigned nodePos, varPos;
const bool exists(getNodeAndVarPos(nodeName, args[0], nodePos, varPos));
if (!exists)
return;
if (verbose)
cerr << " (" << nodePos << "," << varPos << "):" << args.size()-1 << endl;
// send the message
SetVariables::VariablesVector data;
for (size_t i=1; i<args.size(); ++i)
data.push_back(atoi(args[i].c_str()));
SetVariables setVariables(nodePos, varPos, data);
setVariables.serialize(asebaStream);
asebaStream->flush();
}
示例6: emit
void Shell::emit(const strings& args)
{
// check that there are enough arguments
if (args.size() < 2)
{
wcerr << "missing argument, usage: emit EVENT_NAME EVENT_DATA*" << endl;
return;
}
size_t pos;
if (!commonDefinitions.events.contains(UTF8ToWString(args[1]), &pos))
{
wcerr << "event " << UTF8ToWString(args[1]) << " is unknown" << endl;
return;
}
// build event and emit
VariablesDataVector data;
for (size_t i=2; i<args.size(); ++i)
data.push_back(atoi(args[i].c_str()));
UserMessage userMessage(pos, data);
userMessage.serialize(targetStream);
targetStream->flush();
}
示例7: setVariable
void Shell::setVariable(const strings& args)
{
// check that there are enough arguments
if (args.size() < 4)
{
wcerr << "missing argument, usage: set NODE_NAME VAR_NAME VAR_DATA+" << endl;
return;
}
// get node id, variable position and length
unsigned nodeId, pos;
const bool exists(getNodeAndVarPos(args[1], args[2], nodeId, pos));
if (!exists)
return;
// send the message
VariablesDataVector data;
for (size_t i=3; i<args.size(); ++i)
data.push_back(atoi(args[i].c_str()));
SetVariables setVariables(nodeId, pos, data);
setVariables.serialize(targetStream);
targetStream->flush();
}
示例8: filterOnlyImages
void filterOnlyImages(strings& files)
{
strings out; // O(N)
for (size_t u = 0; u < files.size(); u++)
{
if (isSupportedImageType(files[u]))
{
out.push_back(files[u]);
}
}
files = out;
}
示例9: sendEvent
void HttpInterface::sendEvent(const std::string nodeName, const strings& args)
{
size_t eventPos;
if (commonDefinitions.events.contains(UTF8ToWString(args[0]), &eventPos))
{
// build event and emit
UserMessage::DataVector data;
for (size_t i=1; i<args.size(); ++i)
data.push_back(atoi(args[i].c_str()));
UserMessage userMessage(eventPos, data);
userMessage.serialize(asebaStream);
asebaStream->flush();
}
else if (verbose)
cerr << "sendEvent " << nodeName << ": no event " << args[0] << endl;
}
示例10: evSubscribe
void HttpInterface::evSubscribe(HttpRequest* req, strings& args)
{
// eventSubscriptions[conn] is an unordered set of strings
if (args.size() == 1)
eventSubscriptions[req].insert("*");
else
for (strings::iterator i = args.begin()+1; i != args.end(); ++i)
eventSubscriptions[req].insert(*i);
strings headers;
headers.push_back("Content-Type: text/event-stream");
headers.push_back("Cache-Control: no-cache");
headers.push_back("Connection: keep-alive");
addHeaders(req, headers);
appendResponse(req,200,true,"");
// connection must stay open!
}
示例11: run
void Shell::run(const strings& args)
{
// check arguments
if (args.size() != 2)
{
wcerr << "wrong number of arguments, usage: run NODE_NAME" << endl;
return;
}
bool ok;
const unsigned nodeId(getNodeId(UTF8ToWString(args[1]), 0, &ok));
if (!ok)
{
wcerr << "invalid node name " << UTF8ToWString(args[1]) << endl;
return;
}
// build run message and send
Run runMsg(nodeId);
runMsg.serialize(targetStream);
targetStream->flush();
}
示例12: inUnits
string inUnits(bigint const& _b, strings const& _units)
{
ostringstream ret;
u256 b;
if (_b < 0)
{
ret << "-";
b = (u256)-_b;
}
else
b = (u256)_b;
u256 biggest = 1;
for (unsigned i = _units.size() - 1; !!i; --i)
biggest *= 1000;
if (b > biggest * 1000)
{
ret << (b / biggest) << " " << _units.back();
return ret.str();
}
ret << setprecision(3);
u256 unit = biggest;
for (auto it = _units.rbegin(); it != _units.rend(); ++it)
{
auto i = *it;
if (i != _units.front() && b >= unit)
{
ret << (double(b / (unit / 1000)) / 1000.0) << " " << i;
return ret.str();
}
else
unit /= 1000;
}
ret << b << " " << _units.front();
return ret.str();
}
示例13: getVariable
void Shell::getVariable(const strings& args)
{
// check that there is the correct number of arguments
if (args.size() != 3)
{
wcerr << "wrong number of arguments, usage: get NODE_NAME VAR_NAME" << endl;
return;
}
// get node id, variable position and length
unsigned nodeId, pos;
const bool exists(getNodeAndVarPos(args[1], args[2], nodeId, pos));
if (!exists)
return;
bool ok;
const unsigned length(getVariableSize(nodeId, UTF8ToWString(args[2]), &ok));
if (!ok)
return;
// send the message
GetVariables getVariables(nodeId, pos, length);
getVariables.serialize(targetStream);
targetStream->flush();
}
示例14: interpretCapabilityPacket
//.........这里部分代码省略.........
unsigned itemCount = _r.itemCount();
LOG(m_logger) << "BlockHashes (" << dec << itemCount << " entries) "
<< (itemCount ? "" : " : NoMoreHashes") << " from " << _peerID;
if (itemCount > c_maxIncomingNewHashes)
{
disablePeer(_peerID, "Too many new hashes");
break;
}
vector<pair<h256, u256>> hashes(itemCount);
for (unsigned i = 0; i < itemCount; ++i)
hashes[i] = std::make_pair(_r[i][0].toHash<h256>(), _r[i][1].toInt<u256>());
m_peerObserver->onPeerNewHashes(_peerID, hashes);
break;
}
case GetNodeDataPacket:
{
unsigned count = static_cast<unsigned>(_r.itemCount());
if (!count)
{
LOG(m_loggerImpolite) << "Zero-entry GetNodeData: Not replying to " << _peerID;
m_host->updateRating(_peerID, -10);
break;
}
LOG(m_logger) << "GetNodeData (" << dec << count << " entries) from " << _peerID;
strings const data = m_hostData->nodeData(_r);
m_host->updateRating(_peerID, 0);
RLPStream s;
m_host->prep(_peerID, name(), s, NodeDataPacket, data.size());
for (auto const& element : data)
s.append(element);
m_host->sealAndSend(_peerID, s);
break;
}
case GetReceiptsPacket:
{
unsigned count = static_cast<unsigned>(_r.itemCount());
if (!count)
{
LOG(m_loggerImpolite) << "Zero-entry GetReceipts: Not replying to " << _peerID;
m_host->updateRating(_peerID, -10);
break;
}
LOG(m_logger) << "GetReceipts (" << dec << count << " entries) from " << _peerID;
pair<bytes, unsigned> const rlpAndItemCount = m_hostData->receipts(_r);
m_host->updateRating(_peerID, 0);
RLPStream s;
m_host->prep(_peerID, name(), s, ReceiptsPacket, rlpAndItemCount.second)
.appendRaw(rlpAndItemCount.first, rlpAndItemCount.second);
m_host->sealAndSend(_peerID, s);
break;
}
case NodeDataPacket:
{
if (peer.asking() != Asking::NodeData)
LOG(m_loggerImpolite)
<< "Peer " << _peerID << " giving us node data when we didn't ask for them.";
else
{
示例15: evVariableOrEvent
void HttpInterface::evVariableOrEvent(HttpRequest* req, strings& args)
{
string nodeName(args[0]);
size_t eventPos;
if ( ! commonDefinitions.events.contains(UTF8ToWString(args[1]), &eventPos))
{
// this is a variable
if (req->method.find("POST") == 0 || args.size() >= 3)
{
// set variable value
strings values;
if (args.size() >= 3)
values.assign(args.begin()+1, args.end());
else
{
// Parse POST form data
values.push_back(args[1]);
parse_json_form(req->content, values);
}
if (values.size() == 0)
{
finishResponse(req, 404, "");
if (verbose)
cerr << req << " evVariableOrEevent 404 can't set variable " << args[0] << ", no values" << endl;
return;
}
sendSetVariable(nodeName, values);
finishResponse(req, 200, "");
if (verbose)
cerr << req << " evVariableOrEevent 200 set variable " << values[0] << endl;
}
else
{
// get variable value
strings values;
values.assign(args.begin()+1, args.begin()+2);
unsigned source, start;
if ( ! getNodeAndVarPos(nodeName, values[0], source, start))
{
finishResponse(req, 404, "");
if (verbose)
cerr << req << " evVariableOrEevent 404 no such variable " << values[0] << endl;
return;
}
sendGetVariables(nodeName, values);
pendingVariables[std::make_pair(source,start)].insert(req);
if (verbose)
cerr << req << " evVariableOrEevent schedule var " << values[0]
<< "(" << source << "," << start << ") add " << req << " to subscribers" << endl;
return;
}
}
else
{
// this is an event
// arguments are args 1..N
strings data;
data.push_back(args[1]);
if (args.size() >= 3)
for (size_t i=2; i<args.size(); ++i)
data.push_back((args[i].c_str()));
else if (req->method.find("POST") == 0)
{
// Parse POST form data
parse_json_form(std::string(req->content, req->content.size()), data);
}
sendEvent(nodeName, data);
finishResponse(req, 200, ""); // or perhaps {"return_value":null,"cmd":"sendEvent","name":nodeName}?
return;
}
}