本文整理汇总了C++中map::end方法的典型用法代码示例。如果您正苦于以下问题:C++ map::end方法的具体用法?C++ map::end怎么用?C++ map::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupShaders
void setupShaders(){
multimap<string,string> shaderPrograms;
vector<string> files;
scanDirectory(files,"Shaders");
for(int x=0;x<files.size();x++){
//cout<<files.at(x)<<endl;
int temp=files.at(x).find(".");
string id=files.at(x).substr(0,temp);
shaderPrograms.insert(pair<string,string>(id,files.at(x)));
}
GLuint prog=0, shad=0;
string last="";
for (multimap<string,string>::iterator it=shaderPrograms.begin(); it!=shaderPrograms.end(); ++it){
//std::cout << (*it).first << " => " << (*it).second << '\n';
if(it->second[0]=='.')
continue;
if(it->first!=last){
if(last!=""){
glBindAttribLocation(prog,0,"in_Position");
glBindAttribLocation(prog,1,"in_Color");
glBindAttribLocation(prog,2,"in_Tex");
glBindAttribLocation(prog,3,"in_Norm");
glLinkProgram(prog);
printLog(prog);
//printf("%s",gluErrorString(glGetError()));
}
prog=glCreateProgram();
shaders[it->first]=prog;
last=it->first;
}
if(it->second.find("vert")!=string::npos)
shad=loadShader("Shaders/"+it->second,GL_VERTEX_SHADER);
else if(it->second.find("frag")!=string::npos)
shad=loadShader("Shaders/"+it->second,GL_FRAGMENT_SHADER);
else if(it->second.find("geom")!=string::npos)
shad=loadShader("Shaders/"+it->second,GL_GEOMETRY_SHADER);
//
//else if(it->second.find("comp")!=string::npos)
//shad=loadShader("Shaders/"+it->second,GL_COMPUTE_SHADER);
else if(it->second.find("tess")!=string::npos)
shad=loadShader("Shaders/"+it->second,GL_TESS_CONTROL_SHADER);
else if(it->second.find("eval")!=string::npos)
shad=loadShader("Shaders/"+it->second,GL_TESS_EVALUATION_SHADER);
glAttachShader(prog,shad);
//printf("%s\n",gluErrorString(glGetError()));
subShaders.push_back(shad);
}
//link last program
if(last!=""){
glBindAttribLocation(prog,0,"in_Position");
glBindAttribLocation(prog,1,"in_Color");
glBindAttribLocation(prog,2,"in_Tex");
glBindAttribLocation(prog,3,"in_Norm");
glLinkProgram(prog);
printLog(prog);
}
//printf("%s\n",gluErrorString(glGetError()));
for(map<string,GLuint>::iterator it=shaders.begin();it!=shaders.end();it++){
cout<<"loaded program "<<it->first<<" : "<<it->second<<endl;
printLog(prog);
}
}
示例2: make_graph
void make_graph(){
// 1...line_num(49)
// 0 1 2 ... 48
// 1*49+0 1*49+1 1*49+2 ... 1*49+48
// 2*49+0 2*49+1 2*49+2 ... 2*49+48
ifstream fin("input_1_2.txt");
int line_pos = 0;
int temp_yuan;
double temp_time;
while(fin >> temp_time >> temp_yuan){
line_wait_time[line_pos] = temp_time;
line_yuan[line_pos] = temp_yuan;
string temp_line;
fin >> temp_line;
vector<string> split_line;
while(temp_line.size() > 5){
string temp = temp_line.substr(0, 5);
split_line.push_back(temp);
temp_line = temp_line.substr(6);
}
split_line.push_back(temp_line);
for(int i = 0; i < split_line.size(); i ++){
if(S_to_int.find(split_line[i]) == S_to_int.end()){
S_to_int.insert(pair<string, int>(split_line[i], S_to_int_size));
int_to_S.insert(pair<int, string>(S_to_int_size, split_line[i]));
S_to_int_size ++;
}
//add row edge
int current_s = S_to_int[split_line[i]];
for(int p = 0; p < line_num; p ++){
if(p != line_pos){
addEdge(current_s * line_num + p, current_s * line_num + line_pos, temp_time / 2, temp_yuan);
}
}
//add column edge
if(i){
int a, b;
a = S_to_int[split_line[i - 1]];
b = S_to_int[split_line[i]];
if(temp_yuan == 3){
addEdge(a * line_num + line_pos, b * line_num + line_pos, 5, 0);
addEdge(b * line_num + line_pos, a * line_num + line_pos, 5, 0);
}
else{
addEdge(a * line_num + line_pos, b * line_num + line_pos, 3, 0);
addEdge(b * line_num + line_pos, a * line_num + line_pos, 3, 0);
}
}
}
line_pos ++;
}
start_node = line_num * S_to_int_size;
}
示例3: ProcessAlert
bool CAlert::ProcessAlert(bool fThread)
{
if (!CheckSignature())
return false;
if (!IsInEffect())
return false;
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
printf("cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
printf("expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
printf("alert already cancelled by %d\n", alert.nID);
return false;
}
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI and -alertnotify if it applies to me
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
std::string strCmd = GetArg("-alertnotify", "");
if (!strCmd.empty())
{
// Alert text should be plain ascii coming from a trusted source, but to
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std::string singleQuote("'");
// safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
// even possibly remotely dangerous like & or >
std::string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:[email protected]");
std::string safeStatus;
for (std::string::size_type i = 0; i < strStatusBar.size(); i++)
{
if (safeChars.find(strStatusBar[i]) != std::string::npos)
safeStatus.push_back(strStatusBar[i]);
}
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
if (fThread)
boost::thread t(runCommand, strCmd); // thread runs free
else
runCommand(strCmd);
}
}
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
示例4: if
void
setupNextSubsession(RTSPClient* rtspClient) {
UsageEnvironment& env = rtspClient->envir(); // alias
StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
bool rtpOverTCP = false;
if(rtspconf->proto == IPPROTO_TCP) {
rtpOverTCP = true;
}
scs.subsession = scs.iter->next();
do if (scs.subsession != NULL) {
if (!scs.subsession->initiate()) {
env << *rtspClient << "Failed to initiate the \"" << *scs.subsession << "\" subsession: " << env.getResultMsg() << "\n";
setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
} else {
if(strcmp("video", scs.subsession->mediumName()) == 0) {
video_sess_fmt = scs.subsession->rtpPayloadFormat();
video_codec_name = strdup(scs.subsession->codecName());
if(port2channel.find(scs.subsession->clientPortNum()) == port2channel.end()) {
int cid = port2channel.size();
port2channel[scs.subsession->clientPortNum()] = cid;
#ifdef ANDROID
if(rtspconf->builtin_video_decoder != 0) {
video_codec_id = ga_lookup_codec_id(video_codec_name);
} else {
////// Work with ffmpeg
#endif
/*if(init_vdecoder(cid, scs.subsession->fmtp_spropparametersets()) < 0) {
rtsperror("cannot initialize video decoder(%d)\n", cid);
rtspParam->quitLive555 = 1;
return;
}*/
rtsperror("video decoder(%d) initialized (client port %d)\n",
cid, scs.subsession->clientPortNum());
#ifdef ANDROID
////////////////////////
}
#endif
}
} else if(strcmp("audio", scs.subsession->mediumName()) == 0) {
const char *mime = NULL;
audio_sess_fmt = scs.subsession->rtpPayloadFormat();
audio_codec_name = strdup(scs.subsession->codecName());
#ifdef ANDROID
if((mime = ga_lookup_mime(audio_codec_name)) == NULL) {
showToast(rtspParam->jnienv, "codec %s not supported", audio_codec_name);
rtsperror("rtspclient: unsupported audio codec: %s\n", audio_codec_name);
usleep(300000);
rtspParam->quitLive555 = 1;
return;
}
audio_codec_id = ga_lookup_codec_id(audio_codec_name);
if(android_prepare_audio(rtspParam, mime, rtspconf->builtin_audio_decoder != 0) < 0)
return;
if(rtspconf->builtin_audio_decoder == 0) {
//////////////////////////////////////
rtsperror("init software audio decoder.\n");
#endif
if(adecoder == NULL) {
if(init_adecoder() < 0) {
rtsperror("cannot initialize audio decoder.\n");
rtspParam->quitLive555 = 1;
return;
}
}
#ifdef ANDROID
//////////////////////////////////////
}
#endif
rtsperror("audio decoder initialized.\n");
}
env << *rtspClient << "Initiated the \"" << *scs.subsession
<< "\" subsession (client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << ")\n";
// Continue setting up this subsession, by sending a RTSP "SETUP" command:
rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP, False, rtpOverTCP ? True : False/*TCP?*/, False, NULL);
}
return;
} while(0);
//
// We've finished setting up all of the subsessions. Now, send a RTSP "PLAY" command to start the streaming:
scs.duration = scs.session->playEndTime() - scs.session->playStartTime();
rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY);
}
示例5: main
int main() {
int T = 0;
while( scanf( "%s", s1 ) != EOF ) {
scanf( "%d", &N );
if( T++ ) puts( "" );
printf( "Project %d\n", T );
M.clear();
for( int i = 0; i < N; ++i )
G[i].clear();
memset( R, -1, sizeof( R ) );
memset( visited, 0, sizeof( visited ) );
int X = 0;
for( int i = 0; i < N; ++i ) {
scanf( "%s%s", s1, s2 );
iter = M.find( s2 );
if( iter == M.end() )
y = M[s2] = X++;
else y = iter -> second;
iter = M.find( s1 );
if( iter == M.end() )
x = M[s1] = X++;
else x = iter -> second;
G[y].push_back( x );
R[x] = y;
}
tt = 0;
for( int i = 0; i < N; ++i ) {
if( !visited[i] ) {
v = i;
while( R[v] != -1 )
v = R[v];
top = 0;
p1[top] = v;
p2[top] = 0;
visited[v] = true;
in[v] = tt++;
while( top >= 0 ) {
if( p2[top] < G[p1[top]].size() ) {
y = G[p1[top]][p2[top]];
if( !visited[y] ) {
in[y] = tt++;
visited[y] = true;
++top;
p1[top] = y;
p2[top] = 0;
}
else ++p2[top];
}
else out[p1[top--]] = tt++;
}
}
}
for( scanf( "%d", &N ); N--; ) {
scanf( "%s%s", s1, s2 );
x = M[s1];
y = M[s2];
if( in[x] >= in[y] &&
out[x] <= out[y] )
puts( "Yes" );
else
puts( "No" );
}
}
}
示例6:
void xData::getMissing3 (map<int,pair<double,double> >& rcvd_gift, map<int,double>& bank, int depth, int maxdepth) {
if(depth == maxdepth) return;
map<int,pair<double,double> > my_gift;
double amt_gift=0;
for(map<int,pair<double,double> >::iterator it_rcvd = rcvd_gift.begin(); it_rcvd != rcvd_gift.end(); it_rcvd++) {
int id = it_rcvd->first;
double leader_gift = (it_rcvd->second).first;
double follower_gift = (it_rcvd->second).second;
if(depth != 0) {
amt_gift = (follower_gift + leader_gift * GIFT_RATE ) / (double)(graph_[id].leaders.size() + graph_[id].followers.size());
bank[id] += leader_gift * (1-GIFT_RATE);
} else {
amt_gift = ((follower_gift * GIFT_RATE) + (leader_gift * GIFT_RATE)) / (double)(graph_[id].leaders.size() + graph_[id].followers.size());
bank[id] += ((follower_gift * (1-GIFT_RATE)) + (leader_gift * (1-GIFT_RATE)));
}
for(set<int>::iterator it_l = graph_[id].leaders.begin(); it_l != graph_[id].leaders.end(); it_l++) {
my_gift[*it_l].first += amt_gift;
}
for(set<int>::iterator it_f = graph_[id].followers.begin(); it_f != graph_[id].followers.end(); it_f++) {
my_gift[*it_f].second += amt_gift;
}
}
getMissing3(my_gift, bank, depth+1, maxdepth);
}
示例7:
BBObj *_bbObjFromHandle( int handle,BBObjType *type ){
map<int,BBObj*>::const_iterator it=handle_map.find( handle );
if( it==handle_map.end() ) return 0;
BBObj *obj=it->second;
return obj->type==type ? obj : 0;
}
示例8: run
void run(std::istream& in)
{
vector<string> tokens;
string line;
int chromCol=0;
int posCol=1;
int idCol=2;
int refCol=3;
int altCol=4;
int sampleCol=-1;
while(getline(in,line,'\n'))
{
if(AbstractApplication::stopping()) break;
if(line.empty() || line[0]=='#') continue;
tokenizer.split(line,tokens);
string chrom=tokens[chromCol];
chat *p2;
int pos=(int)strtol(tokens[posCol].c_str(),&p2,10);
string id=tokens[idCol];
string ref=tokens[refCol];
string alt=tokens[altCol];
string sampleName=tokens[sampleCol];
Row* therow=NULL;
if(!rows.empty() &&
rows.back()->pos->chrom.compare(chrom)==0 &&
rows.back()->pos->pos==pos &&
rows.back()->ref.compare(ref)==0 &&
rows.back()->alt.compare(alt)==0
)
{
therow=rows.back();
}
else
{
therow=new Row;
therow->pos=new ChromPosition(chrom,pos);
therow->id.assign(id);
therow->ref.assign(ref);
therow->alt.assign(alt);
rows.push_back(therow);
}
int index_sample=0;
if(sampleCol==-1)
{
if(sample2col.empty())
{
Sample* sample=new Sample;
sample->name.assign("Sample");
sample->column_index=0;
samples.push_back(sample);
}
index_sample=0;
}
else
{
map<string,Sample*>::iterator r= sample2col.find(sampleName);
if(r==sample2col.end())
{
Sample* sample=new Sample;
sample->name.assign(sampleName);
sample->column_index=sample2col.size();
index_sample=sample->column_index;
samples.push_back(sample);
sample2col.put(sample->name,sample);
}
else
{
index_sample=r->second->column_index;
}
}
if(index_sample>=therow->data.size())
{
therow->data.resize(index_sample+1);
}
Data* data=new Data;
therow->data.assign(index_sample,data);
}
}
示例9: gameLoopCleanUp
void gameLoopCleanUp() {
delete background;
while(!colList.empty()) {
CollisionPair * tmp = colList.back();
colList.pop_back();
delete tmp;
}
cout<<"collist"<<colList.size()<<endl;
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
delete it->second;
heroGroup.erase(it);
}
// while (!heroGroup.empty()){
// Hero * tmp = heroGroup[0];
// heroGroup.erase(0);
// delete tmp;
// }
cout<<"hero"<<heroGroup.size()<<endl;
while(!blocks.empty()) {
Block * tmp = blocks.back();
blocks.pop_back();
delete tmp;
}
cout<<"block"<<blocks.size()<<endl;
while(!explosionGroup.empty()) {
Explosion * tmp = explosionGroup.back();
explosionGroup.pop_back();
delete tmp;
}
cout<<"exp"<<explosionGroup.size()<<endl;
// while(!enemyGroup.empty()){
// Enemy * tmp = enemyGroup.back();
// enemyGroup.pop_back();
// delete tmp;
// }
// cout<<"enemy"<<enemyGroup.size()<<endl;
while(!bombGroup.empty()) {
Bomb * tmp = bombGroup.back();
bombGroup.pop_back();
delete tmp;
}
cout<<"bomb"<<bombGroup.size()<<endl;
while(!upgradeGroup.empty()) {
Upgrade * tmp = upgradeGroup.back();
upgradeGroup.pop_back();
delete tmp;
}
cout<<"up"<<upgradeGroup.size()<<endl;
TTF_CloseFont(text_font);
delete tcpclient;
delete udpclient;
delete remoteip;
Mix_HaltMusic();
Mix_FreeMusic(mainMusic);
delete winScreen;
delete loseScreen;
}
示例10: draw
void MultiTouchApp::draw()
{
dx::enableAlphaBlending();
dx::setMatricesWindow( getWindowSize() );
dx::clear( Color( 0.1f, 0.1f, 0.1f ) );
for( map<uint32_t,TouchPoint>::const_iterator activeIt = mActivePoints.begin(); activeIt != mActivePoints.end(); ++activeIt ) {
activeIt->second.draw();
}
for( list<TouchPoint>::iterator dyingIt = mDyingPoints.begin(); dyingIt != mDyingPoints.end(); ) {
dyingIt->draw();
if( dyingIt->isDead() )
dyingIt = mDyingPoints.erase( dyingIt );
else
++dyingIt;
}
// draw yellow circles at the active touch points
dx::color( Color( 1, 1, 0 ) );
for( vector<TouchEvent::Touch>::const_iterator touchIt = getActiveTouches().begin(); touchIt != getActiveTouches().end(); ++touchIt )
dx::drawStrokedCircle( touchIt->getPos(), 20.0f );
}
示例11: callback
void callback(event *ev) {
map<string, bool>::iterator iter;
string hex_id;
string actual_identifier;
int ntohl_number_of_fragments;
int distance;
hex_id = chararray_to_hex(ev->id);
switch (ev->type) {
case SCOPE_PUBLISHED:
cout << "SCOPE_PUBLISHED: " << hex_id << endl;
delete ev;
break;
case SCOPE_UNPUBLISHED:
cout << "SCOPE_UNPUBLISHED: " << hex_id << endl;
delete ev;
break;
case START_PUBLISH:
cout << "START_PUBLISH: " << hex_id << endl;
/*I don't need to do anything here..The publisher will receive the backpath "hello" message implicitly when the first request for retransmission will be sent*/
delete ev;
break;
case STOP_PUBLISH:
cout << "STOP_PUBLISH: " << hex_id << endl;
delete ev;
break;
case PUBLISHED_DATA:
//cout << "PUBLISHED_DATA: " << hex_id << endl;
pthread_mutex_lock(&global_mutex);
iter = expectedInfo.find(ev->id.substr(0, ev->id.length() - PURSUIT_ID_LEN));
if (iter != expectedInfo.end()) {
/*this is not a retransmitted fragment*/
if ((*iter).second == false) {
(*iter).second = true;
/*this is the the first fragment I receive*/
/*start measuring*/
gettimeofday(&start_tv, &tz);
printf("START TIME: %ld,%ld \n", start_tv.tv_sec, start_tv.tv_usec);
create_random_ID(backchannel_id);
ba->publish_info(backchannel_id, ev->id.substr(0, ev->id.length() - 2 * PURSUIT_ID_LEN) + algid1, DOMAIN_LOCAL, NULL, 0);
ba->subscribe_info(backchannel_id, ev->id.substr(0, ev->id.length() - 2 * PURSUIT_ID_LEN) + algid2, DOMAIN_LOCAL, NULL, 0);
efs = new ExpectedFragmentSequence();
efs->firstID = ev->id.substr(0, ev->id.length() - PURSUIT_ID_LEN) + string((const char *) ev->id.substr(ev->id.length() - PURSUIT_ID_LEN, sizeof (int)).c_str(), sizeof (int)) + hex_to_chararray("00000000");
memcpy(&ntohl_number_of_fragments, ev->id.substr(ev->id.length() - PURSUIT_ID_LEN, sizeof (int)).c_str(), sizeof (int));
efs->number_of_fragments = ntohl(ntohl_number_of_fragments);
efs->fragments_so_far = 1;
efs->fragments_map = bitvector(efs->number_of_fragments);
distance = calculate_number_of_fragments(efs->firstID, ev->id) - 1; //e.g. from 0 to 1 distance = 1
efs->fragments_map[distance] = true;
efs->time_beat = 3;
efs->p_to_s_channel = ev->id.substr(0, ev->id.length() - 2 * PURSUIT_ID_LEN) + algid2 + backchannel_id;
efs->s_to_p_channel = ev->id.substr(0, ev->id.length() - 2 * PURSUIT_ID_LEN) + algid1 + backchannel_id;
retransmission_channel_map.insert(pair<string, string > (efs->p_to_s_channel, bin_item_identifier));
efs->printEFS();
//cout << efs->fragments_map.to_string().c_str() << endl;
pthread_create(&timeout_thread, NULL, timeout_handler, NULL);
} else {
distance = calculate_number_of_fragments(efs->firstID, ev->id) - 1; //e.g. from 0 to 1 distance = 1
if (bitvector::bit::unspecified_bool_type(efs->fragments_map[distance]) == false) {
efs->fragments_so_far++;
efs->fragments_map[distance] = true;
efs->time_beat = 3;
//cout << efs->fragments_map.to_string().c_str() << endl;
if (efs->fragments_so_far == efs->number_of_fragments) {
pthread_cancel(timeout_thread);
efs->printResult();
delete efs;
efs = NULL;
delete ev;
delete ba;
break;
}
} else {
cout << "Received a duplicate fragment: " << hex_id << endl;
}
}
} else {
/*A retransmission*/
actual_identifier = (*retransmission_channel_map.find(ev->id.substr(0, ev->id.length() - PURSUIT_ID_LEN))).second + ev->id.substr(ev->id.length() - PURSUIT_ID_LEN, PURSUIT_ID_LEN);
distance = calculate_number_of_fragments(efs->firstID, actual_identifier) - 1; //e.g. from 0 to 1 distance = 1
if (bitvector::bit::unspecified_bool_type(efs->fragments_map[distance]) == false) {
efs->fragments_so_far++;
efs->fragments_map[distance] = true;
efs->time_beat = 3;
//cout << efs->fragments_map.to_string().c_str() << endl;
if (efs->fragments_so_far == efs->number_of_fragments) {
pthread_cancel(timeout_thread);
efs->printResult();
delete efs;
efs = NULL;
delete ev;
delete ba;
break;
}
} else {
cout << "Received a duplicate fragment: " << hex_id << endl;
}
}
pthread_mutex_unlock(&global_mutex);
delete ev;
break;
//.........这里部分代码省略.........
示例12: testInsanity
void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
printf("testInsanity()\n");
Xtruct hello;
hello.string_thing = "Hello2";
hello.byte_thing = 2;
hello.i32_thing = 2;
hello.i64_thing = 2;
Xtruct goodbye;
goodbye.string_thing = "Goodbye4";
goodbye.byte_thing = 4;
goodbye.i32_thing = 4;
goodbye.i64_thing = 4;
Insanity crazy;
crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
crazy.xtructs.push_back(goodbye);
Insanity looney;
crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
crazy.xtructs.push_back(hello);
map<Numberz::type, Insanity> first_map;
map<Numberz::type, Insanity> second_map;
first_map.insert(make_pair(Numberz::TWO, crazy));
first_map.insert(make_pair(Numberz::THREE, crazy));
second_map.insert(make_pair(Numberz::SIX, looney));
insane.insert(make_pair(1, first_map));
insane.insert(make_pair(2, second_map));
printf("return");
printf(" = {");
map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
printf("%"PRId64" => {", i_iter->first);
map<Numberz::type,Insanity>::const_iterator i2_iter;
for (i2_iter = i_iter->second.begin();
i2_iter != i_iter->second.end();
++i2_iter) {
printf("%d => {", i2_iter->first);
map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
map<Numberz::type, UserId>::const_iterator um;
printf("{");
for (um = userMap.begin(); um != userMap.end(); ++um) {
printf("%d => %"PRId64", ", um->first, um->second);
}
printf("}, ");
vector<Xtruct> xtructs = i2_iter->second.xtructs;
vector<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
printf("{\"%s\", %d, %d, %"PRId64"}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
}
printf("}");
printf("}, ");
}
printf("}, ");
}
printf("}\n");
}
示例13: SIDReqStr
void *processRequest (void *socketid)
{
int n;
int *sock = (int*)socketid;
int acceptSock = *sock;
string videoName;
bool clientSignaledToClose = false;
while(!clientSignaledToClose){
char SIDReq[1024];
memset(SIDReq, 0, sizeof(SIDReq));
//Receive packet
say("Receiving packet...\n");
if ((n = Xrecv(acceptSock, SIDReq, sizeof(SIDReq), 0)) <= 0) {
cerr << "Xrecv failed!" << endl;
Xclose(acceptSock);
delete sock;
return NULL;
}
string SIDReqStr(SIDReq);
say("Got request: " + SIDReqStr);
// if the request is about number of chunks return number of chunks
// since this is first time, you would return along with header
// If Request contains "numchunks", return number of CID's.
if(isNumChunksRequest(SIDReqStr)){
// Get Video Name out of the request
string prefix = "get numchunks ";
videoName = SIDReqStr.substr(prefix.length());
say("Request asks for number of chunks: " + videoName);
//Figure out what video they would like
// Check to see if this video is the one that the user is looking for
if(CIDlist.find(videoName) != CIDlist.end()){
// Add the number of chunks to the string
stringstream yy;
yy << CIDlist[videoName]->size();
string response = yy.str();
// Add a character of whitespace to the response
response += " ";
// Append on the list of Server AD-HIDs to the response
for(vector<string>::iterator it = ContentServerXidList[videoName]->begin();
it != ContentServerXidList["BigBuckBunny"]->end();
++it){
response += *it + " ";
}
// Send back the number of CIDs followed by list of AD-HIDs
say("Sending back " + response, LVL_DEBUG);
Xsend(acceptSock,(void *) response.c_str(), response.length(), 0);
}
else{
cerr << "Invalid Video Name: " << videoName << endl;
Xclose(acceptSock);
delete sock;
return NULL;
}
}
else if(isTerminationRequest(SIDReqStr)){
clientSignaledToClose = true;
}
else if(isVideoSelectionRequest(SIDReqStr)){
ostringstream oss;
for(vector<string>::iterator it = videoList.begin(); it != videoList.end(); ++it){
oss << *it << " ";
}
Xsend(acceptSock,(void *) oss.str().c_str(), oss.str().length(), 0);
}
else {
// Otherwise, if the request was not about the number of chunks,
// it must be a request for a certain chunk
// Format of the request: start-offset:end-offset
// Each offset position corresponds to a CID (chunk)
say("Request is for a certain chunk span");
// Parse the Request, extract start and end offsets
int findpos = SIDReqStr.find(":");
// split around this position
string prefix = "block ";
string str = SIDReqStr.substr(prefix.length(), findpos);
int start_offset = atoi(str.c_str());
str = SIDReqStr.substr(findpos + 1);
int end_offset = atoi(str.c_str());
// construct the string from CIDlist
// return the list of CIDs, NOT including end_offset
string requestedCIDlist = "";
for(int i = start_offset; i < end_offset; i++){
requestedCIDlist += CIDlist[videoName]->at(i) + " ";
}
Xsend(acceptSock, (void *)requestedCIDlist.c_str(), requestedCIDlist.length(), 0);
//.........这里部分代码省略.........
示例14: while
bool // returns true if success
processTreeSection(FILE *fp,
string& theline,
bool& new_section)
{
string *tid = NULL;
TChain *t1 = NULL;
vector<string> v_tokens;
string treename;
if (gl_verbose)
cout << "Processing Tree section" << endl;
new_section=false;
while (getLine(fp,theline,"Tree")) {
if (!theline.size()) continue;
if (theline[0] == '#') continue; // comments are welcome
if (theline[0] == '[') {
new_section=true;
break;
}
string key, value;
if (!getKeyValue(theline,key,value)) continue;
//--------------------
if (key == "id") {
//--------------------
if (tid != NULL) {
cerr << "no more than one id per F1 section allowed " << value << endl;
break;
}
tid = new string(value);
map<string, TChain *>::const_iterator tit = glmap_id2chain.find(*tid);
if (tit != glmap_id2chain.end()) {
cerr << "Tree id " << *tid << " already defined" << endl;
break;
}
//------------------------------
} else if( key == "treename" ) {
//------------------------------
if( !tid ) {
cerr << "id key must be defined first in the section" << endl; continue;
}
if( t1 ) {
cerr << "Tree already defined" << endl; continue;
}
treename = value;
//------------------------------
} else if( key == "globslist" ) {
//------------------------------
t1 = getChainFromGlobslist(*tid,treename,value);
if( !t1 )
exit(-1);
//------------------------------
} else if( key == "copytree" ) {
//------------------------------
if( !tid ) {
cerr << "id key must be defined first in the section" << endl; continue; }
Tokenize(value,v_tokens,",");
if (v_tokens.size() != 2) {
cerr << "copytree syntax expected: copytree=treeid,cutstring: " << value << endl; continue; }
TChain *t2 = findChain(v_tokens[0]);
if (!t2) {
cerr << "tree " << v_tokens[0] << " must be defined previously" << endl; continue; }
if (gl_verbose)
cout<<"Begin CopyTree of "<<v_tokens[0]<<" with selection "<<v_tokens[1]<<flush;
t1 = (TChain *)(t2->CopyTree(v_tokens[1].c_str()));
if( !t1 ) {
cerr << "CopyTree failed" << endl; exit(-1); }
if (gl_verbose)
cout<<"...Done."<<endl;
//------------------------------
} else if( key == "save2file" ) {
//------------------------------
if( !t1 ) {
cerr << "save2file: must define tree first" << endl; continue; }
TFile *rootfile = openRootFile(value,"RECREATE");
t1->SetDirectory(rootfile);
t1->Write();
rootfile->Flush();
if (gl_verbose)
cout << "Tree written to file " << value << endl;
//.........这里部分代码省略.........
示例15: ProcessAlert
bool CAlert::ProcessAlert()
{
if (!CheckSignature())
return false;
if (!IsInEffect())
return false;
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
printf("cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
printf("expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
printf("alert already cancelled by %d\n", alert.nID);
return false;
}
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI if it applies to me
if(AppliesToMe())
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}