//##ModelId=4A2B758102CE floatpoint cls_ai::GetNewPos(floatpoint src_point, int mode) { // TODO: Add your specialized code here. // NOTE: Requires a correct return value to compile. lua_settop(L,0);//重置栈索引 lua_getglobal(L,"GetNewPos"); if(!lua_isfunction(L,-1)){ MessageBox(globalhwnd,"脚本里没有GetNewPos函数","",MB_OK); } lua_pushnumber(L,src_point.x); lua_pushnumber(L,src_point.y); lua_pushnumber(L,mode); lua_call(L,3,1); string str=lua_tostring(L,-1); vector<string > v=explode(",",str); //MessageBox(NULL,v[0].c_str(),"坐标",MB_OK); //MessageBox(NULL,v[1].c_str(),"坐标",MB_OK); int new_x=string2int(v[0].c_str()); int new_y=string2int(v[1].c_str()); /*int ints=(int)lua_tonumber(L,-1); char buf[20]; sprintf(buf,"%d",ints); MessageBox(NULL,buf,"",MB_OK);*/ floatpoint pt; //pt.x=0; //pt.y=0; pt.x=new_x; pt.y=new_y; return pt; }
int main(const int argc, const char* const argv[]) { // Reading the parameters if (argc < 4) { std::cerr << "ERROR[Gamber]: At least three arguments are expected (stake," " goal, and the number of repetitions).\n"; return too_few_arguments; } if (argc > 5) { std::cerr << "ERROR[Gamber]: At most four arguments are expected (stake," " goal, number of repetitions, and the seed for the random generator).\n"; return too_many_arguments; } const unsigned int stake = string2int(argv[1]); const unsigned int goal = string2int(argv[2]); if (stake == 0) { std::cerr << "ERROR[Gamber]: The stake must not be zero.\n"; return invalid_parameters; } if (stake > goal) { std::cerr << "ERROR[Gamber]: The stake can be at most the goal.\n"; return invalid_parameters; } const unsigned int N = string2int(argv[3]); if (N == 0) return 0; if (argc == 5) std::srand(string2int(argv[4])); // Performing the experiment unsigned int wins = 0; double max_steps = 0; double sum_steps = 0; double sum_square_steps = 0; for (unsigned int t = 0; t < N; ++t) { unsigned int cash = stake; double steps = 0; while (cash != 0 and cash != goal) { if (random_bit()) ++cash; else --cash; ++steps; } if (cash == goal) ++wins; if (steps > max_steps) max_steps = steps; sum_steps += steps; sum_square_steps += steps*steps; } // Analysing the outcome std::cout << "Stake = " << stake << ", goal = " << goal << ", number of trials = " << N << ".\n"; std::cout << "Probability of winning = " << double (stake) / goal << ".\n"; std::cout << "Expected number of repetitions = " << double (stake) * (goal - stake) << ".\n"; std::cout << "Number of wins = " << wins << "; the frequency is " << double (wins) / N << ".\n"; std::cout << "Average number of steps = " << sum_steps / N << ", while " "the maximum is " << max_steps << ".\n"; if (N > 1) std::cout << "The standard deviation is " << std::sqrt((N * sum_square_steps - sum_steps*sum_steps) / N / (N-1)) << ".\n"; }
/* * 初始化函数,从cache里面加载上次同步的时间信息等 */ void CSyncCenter::init() { // Load total update time CacheManager* pCacheManager = CacheManager::getInstance(); // increase message count CacheConn* pCacheConn = pCacheManager->GetCacheConn("unread"); if (pCacheConn) { string strTotalUpdate = pCacheConn->get("total_user_updated"); string strLastUpdateGroup = pCacheConn->get("last_update_group"); pCacheManager->RelCacheConn(pCacheConn); if(strTotalUpdate != "") { m_nLastUpdate = string2int(strTotalUpdate); } else { updateTotalUpdate(time(NULL)); } if(strLastUpdateGroup.empty()) { m_nLastUpdateGroup = string2int(strLastUpdateGroup); } else { updateLastUpdateGroup(time(NULL)); } } else { log("no cache connection to get total_user_updated"); } }
void pData(char* data) { // Print out each char that we get Serial.printf("%d\n", string2int(data)); // Set the value to the LED analogWrite(led, string2int(data)); }
// ******************* main int main(int argc,char *argv[]) { int numThreads = 0; if ( 3 == argc ){ numThreads = string2int( argv[ 1 ] ); n = string2int( argv[2] ); } else // if number of args illegal { std::cerr << "Usage: " << argv[0] << " number-of-threads" << argv[1] << " value n" << std::endl; return( -1 ); }; // end argc check assert( 0 < numThreads ); assert( numThreads <= maxNumThreads ); std::chrono::system_clock::time_point startTime = std::chrono::system_clock::now(); std::thread threads[ numThreads ]; // Note: No REAL threads yet... double partials[ numThreads ]; //Launch the threads for (int i = 0; i < numThreads; ++i) { threads[i] = std::thread( pi_thread, i, numThreads, &(partials[i]) ); } ////Join the threads with the main thread double pi = 0; for (int i = 0; i < numThreads; ++i) { threads[i].join(); pi += partials[i]; } std::chrono::system_clock::time_point endTime = std::chrono::system_clock::now(); std::chrono::microseconds microRunTime = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime); double runTime = microRunTime.count() / 1000000.0; std::cout << std::setprecision( 16 ) << "Pi is approximately " << pi << ", Error is " << std::fabs(pi - PI25DT) << std::endl; std::cout << std::setprecision( 8 ) << "Wall clock time = " << runTime << " seconds." << std::endl << std::flush; return 0; }
double string2date(const std::string &str, Node::ErrorCode &error) { std::string str1(trim(str)); // Validate if (str1.find('-') != std::string::npos) { error = Node::InvalidFormat; return 0; } // Year error = Node::NoError; int year = string2int(str1.substr(0, 2).c_str(), error); if (error != Node::NoError) return 0; year += (year < (UNIX_FIRST_YEAR - (UNIX_FIRST_YEAR / 100) * 100)) ? 2000 : 1900; double res = 0; for (int y = UNIX_FIRST_YEAR; y < year; y++) { // If current year is leap bool leap = !(y % 4) && ((y % 100) || !(y % 400)); res += leap ? 366 : 365; } // Years -> seconds res *= 86400; // Additional part res += (string2double(str1.substr(2, str1.length() - 2), error) - 1) * 86400; return res; }
void VehicleRouteProblem::readDemandFromFile( std::ifstream& file_with_cities) { std::string readChar; std::pair<int, int> cordinate; for (int i = 0; i < cityCounts; i++) { file_with_cities >> readChar; file_with_cities >> cordinate.first; file_with_cities >> cordinate.second; cityCordinate.push_back(cordinate); file_with_cities >> readChar; if (i == 0) { cityDemand.push_back(0); } else { cityDemand.push_back(string2int(readChar)); } } }
w32 h2w32(char *abcdef) { int rcerr; w32 num; rcerr= string2int(abcdef, strlen(abcdef), &num, 'h'); if(rcerr!=0) { printf("Error in string2int(%s,...)\n", abcdef); num=0xffffffff; }; return(num); }
void CClient::connect() { CHttpClient httpClient; string strUrl = m_strLoginDomain + "/msg_server"; string strResp; CURLcode nRet = httpClient.Get(strUrl, strResp); if(nRet != CURLE_OK) { printf("login falied. access url:%s error\n", strUrl.c_str()); g_configReturn = false; PROMPTION; return; } Json::Reader reader(Json::Features::strictMode()); Json::Value value; if(!reader.parse(strResp, value)) { printf("login falied. parse response error:%s\n", strResp.c_str()); g_configReturn = false; PROMPTION; return; } string strPriorIp, strBackupIp; uint16_t nPort; try { uint32_t nRet = value["code"].asUInt(); if(nRet != 0) { string strMsg = value["msg"].asString(); printf("login falied. errorMsg:%s\n", strMsg.c_str()); g_configReturn = false; PROMPTION; return; } strPriorIp = value["priorIP"].asString(); strBackupIp = value["backupIP"].asString(); nPort = string2int(value["port"].asString()); } catch (std::runtime_error msg) { printf("login falied. get json error:%s\n", strResp.c_str()); g_configReturn = false; PROMPTION; return; } g_pConn = new ClientConn(this); m_nHandle = g_pConn->connect(strBackupIp.c_str(), nPort, m_strName, m_strPass); if(m_nHandle != INVALID_SOCKET) { netlib_register_timer(CClient::TimerCallback, (void*)this, 1000); g_configReturn = true; } else { printf("invalid socket handle\n"); } }
byte SonosEsp::getVolume(int device) { const char url[] = "/RenderingControl/Control"; const char service[] = "RenderingControl:1"; const char action[] = "GetVolume"; const char arguments[] = "<InstanceID>0</InstanceID><Channel>Master</Channel>"; sonosAction(url,service,action,arguments,device); filter("<CurrentVolume>","</CurrentVolume>"); return string2int(_filtered); }
//##ModelId=4A2B758102CE movedata cls_ai::GetNewAnglePos(floatpoint src_point, int speed,int mode,float angle) { // TODO: Add your specialized code here. // NOTE: Requires a correct return value to compile. lua_settop(L,0);//重置栈索引 lua_getglobal(L,"GetNewAnglePos"); if(!lua_isfunction(L,-1)){ MessageBox(globalhwnd,"脚本里没有GetNewAnglePos函数","",MB_OK); } lua_pushnumber(L,(float)src_point.x); lua_pushnumber(L,(float)src_point.y); lua_pushnumber(L,speed); lua_pushnumber(L,mode); lua_pushnumber(L,(float)angle); lua_call(L,5,1); string str=lua_tostring(L,-1); vector<string > v=explode(",",str); //MessageBox(NULL,v[0].c_str(),"坐标",MB_OK); //MessageBox(NULL,v[1].c_str(),"坐标",MB_OK); int new_x=string2int(v[0].c_str()); int new_y=string2int(v[1].c_str()); float new_angle; if (v.size()==3)//代表有3个未劈开的字符 { new_angle=string2float(v[2].c_str()); } /*int ints=(int)lua_tonumber(L,-1); char buf[20]; sprintf(buf,"%d",ints); MessageBox(NULL,buf,"",MB_OK);*/ //POINT pt; //pt.x=0; //pt.y=0; //pt.x=new_x; //pt.y=new_y; movedata mdata; mdata.x=new_x; mdata.y=new_y; mdata.angle=new_angle; return mdata; }
int evalRPN(vector<string> &tokens) { stack<int> nums; for(auto it = tokens.begin();it!=tokens.end();it++){ if(isOperator(*it)){ operate(nums, (*it)[0]); }else{ nums.push(string2int(*it)); } } return nums.top(); }
void config(int *maxLoglines, int *inquiry_len,char **logname) { char *env; env = getenv("LOG_MAX_LINES"); *maxLoglines = string2int(env); if(0 == *maxLoglines) { *maxLoglines = DEFAULT_LOG_MAX_LINES; } env = getenv("INQUIRY_LEN"); *inquiry_len = string2int(env); if(0 == *inquiry_len) { *inquiry_len = DEFAULT_INQUIRY_LEN; } *logname = getenv("LOGFILE"); if(!(*logname)) { *logname = DEFAULT_LOG_FILE; printf("logname %s\n",*logname); } }
int parseInt(const std::string *line, const std::size_t start, const std::size_t length, Node::ErrorCode &error) { if (!line) return 0; if (line->length() < start + length) { error = Node::TooShortString; return 0; } return string2int(trim(line->substr(start, length)), error); }
// ******************* main int main(int argc,char *argv[]) { int numThreads = 0; if ( 2 == argc ) numThreads = string2int( argv[ 1 ] ); else // if number of args illegal { std::cerr << "Usage: " << argv[0] << " number-of-threads" << std::endl; return( -1 ); }; // end argc check assert( 0 < numThreads ); assert( numThreads <= maxNumThreads ); std::chrono::system_clock::time_point startTime = std::chrono::system_clock::now(); omp_set_num_threads( numThreads ); double sum = 0; int i, real_numThreads; double x; #pragma omp parallel for \ private(i,x) lastprivate(real_numThreads) \ reduction(+:sum) for ( int i = 1; i <= n; i += 1 ) { x = h * ((double)i - 0.5); sum += f(x); real_numThreads = omp_get_num_threads(); } double pi = h * sum; std::chrono::system_clock::time_point endTime = std::chrono::system_clock::now(); std::chrono::microseconds microRunTime = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime); double runTime = microRunTime.count() / 1000000.0; std::cout << std::setprecision( 16 ) << "Pi is approximately " << pi << ", Error is " << std::fabs(pi - PI25DT) << std::endl; std::cout << std::setprecision( 8 ) << "Wall clock time = " << runTime << " seconds." << std::endl << std::flush; std::cout << "There were " << real_numThreads << " threads." << std::endl; return 0; }
/* * Parse the size= parameter. It currently accpets * size=8k, size=8192 or size=rand(1,8k) * Return a +ve number on success; else -1 */ static int parse_size(flowop_t *f, char *value) { int size = 0; assert(value); size = string_to_int(value); if (size > 0) return (size); if (strncasecmp(value, "rand(", 5) == 0) { char *cmin, *cmax; cmin = strtok(value, "("); cmin = strtok(NULL, ","); cmax = strtok(NULL, ")"); f->options.rand_sz_min = string2int(strip(cmin)); f->options.rand_sz_max = string2int(strip(cmax)); f->options.flag |= O_SIZE_RAND; /* Seed the random generator here */ srand(GETHRTIME()); if (f->options.rand_sz_min > 0 && f->options.rand_sz_max > 0) return (0); } return (-1); }
//----------------------------------------------------------------------- int converth2i(w32 *numm,int ic,char counters[][MAXWORD]){ char number[20]; w32 num; int j,len; len=(int)strlen(counters[ic]); for(j=0;j<len;j++){ //number[len-j-1]=counters[ic][j]; number[j]=counters[ic][j]; } number[len]='\0'; len=strlen(number); if(len>0) { if(string2int(number,len,&num,'h')) { printf("DEBUG num=%s %x %u \n",counters[ic],num,num); return(1); }; } *numm=num; return 0; }
constexpr unsigned int string2int(const char* str, int h) { return !str[h] ? 5381 : (string2int(str, h + 1) * 33) ^ str[h]; }
int string2int(const char *s){ std::string number = s; return string2int(number); }
static workorder_t * build_worklist(struct symbol *list) { static workorder_t w; group_t *curr_grp = NULL; txn_t *curr_txn = NULL; flowop_t *curr_flowop = NULL; char err[1024]; int txnid = 0; int fid = 0; w.ngrp = 0; bzero(&w, sizeof (workorder_t)); while (list) { switch (list->type) { case TOKEN_PROFILE_START: break; case TOKEN_PROFILE_END: break; case TOKEN_GROUP_START: curr_grp = &w.grp[w.ngrp++]; bzero(curr_grp, sizeof (group_t)); curr_grp->endian = UPERF_ENDIAN_VALUE; curr_txn = 0; curr_flowop = 0; txnid = 0; snprintf(curr_grp->name, UPERF_NAME_LEN, "Group%d", w.ngrp - 1); break; case TOKEN_GROUP_END: break; case TOKEN_TXN_START: curr_grp->ntxn++; if (curr_txn == 0) { curr_grp->tlist = calloc(1, sizeof (txn_t)); curr_txn = curr_grp->tlist; } else { curr_txn->next = calloc(1, sizeof (txn_t)); curr_txn = curr_txn->next; } snprintf(curr_txn->name, UPERF_NAME_LEN, "Txn%d", txnid); curr_txn->txnid = txnid++; curr_txn->iter = 1; curr_flowop = 0; fid = 0; break; case TOKEN_TXN_END: break; case TOKEN_FLOWOP_START: curr_txn->nflowop++; if (curr_flowop == NULL) { curr_txn->flist = calloc(1, sizeof (flowop_t)); curr_flowop = curr_txn->flist; } else { curr_flowop->next = calloc(1, sizeof (flowop_t)); curr_flowop = curr_flowop->next; } curr_flowop->options.count = 1; curr_flowop->id = fid++; break; case TOKEN_XML_END: break; case TOKEN_NAME: strlcpy(w.name, list->symbol, NAMELEN); break; case TOKEN_ITERATIONS: curr_txn->iter = string2int(list->symbol); break; case TOKEN_TYPE: curr_flowop->type = flowop_type(list->symbol); if (curr_flowop->type == FLOWOP_ERROR) { snprintf(err, sizeof (err), "Unknown flowop %s\n", list->symbol); add_error(err); return (NULL); } curr_flowop->execute = flowop_get_execute_func( curr_flowop->type); snprintf(curr_flowop->name, sizeof (curr_flowop->name), "%s", list->symbol); break; case TOKEN_OPTIONS: flowop_parse_options(list->symbol, curr_flowop); break; case TOKEN_RATE: strlcpy(curr_txn->rate_str, list->symbol, NAMELEN); curr_txn->rate_count = string2int(list->symbol); break; case TOKEN_DURATION: curr_txn->duration = string2nsec(list->symbol); curr_txn->iter = 1; break; case TOKEN_NTHREADS: curr_grp->nthreads = string2int(list->symbol); curr_grp->strand_flag |= STRAND_TYPE_THREAD; break; case TOKEN_NPROCESSES: #ifdef STRAND_THREAD_ONLY snprintf(err, sizeof (err), "Processes are not supported on this platform"); add_error(err); return (NULL); #else curr_grp->nthreads = string2int(list->symbol); curr_grp->strand_flag |= STRAND_TYPE_PROCESS; break; #endif /* STRAND_THREAD_ONLY */ case TOKEN_ERROR: snprintf(err, sizeof (err), "Unknown symbol: %s\n", list->symbol); add_error(err); return (NULL); } list = list->next; } return (&w); }
static int parse_option(char *option, flowop_t *flowop) { char *key; /* Key option */ char *value; /* Value for the key */ char *tmp; char err[128]; if (strcasecmp(option, "tcp_nodelay") == 0) { flowop->options.flag |= O_TCP_NODELAY; return (UPERF_SUCCESS); } else if (strcasecmp(option, "busy") == 0) { flowop->options.flag |= O_THINK_BUSY; return (UPERF_SUCCESS); } else if (strcasecmp(option, "idle") == 0) { flowop->options.flag |= O_THINK_IDLE; return (UPERF_SUCCESS); } else if (strcasecmp(option, "canfail") == 0) { flowop->options.flag |= O_CANFAIL; return (UPERF_SUCCESS); } else if (strcasecmp(option, "non_blocking") == 0) { flowop->options.flag |= O_NONBLOCKING; return (UPERF_SUCCESS); } else { key = strtok(option, "="); value = strtok(NULL, " "); if (value == NULL) { snprintf(err, sizeof (err), "option %s is not of type key=value\n", option); add_error(err); return (1); } if (value[0] == '$') { tmp = getenv(&value[1]); if (tmp == NULL) { snprintf(err, sizeof (err), "Env variable %s = %s not set\n", key, value); add_error(err); return (1); } value = tmp; } if (strcasecmp(key, "size") == 0) { flowop->options.size = parse_size(flowop, value); if (flowop->options.size == -1) { snprintf(err, sizeof (err), "Could not parse %s\n", value); add_error(err); return (1); } } else if (strcasecmp(key, "rsize") == 0) { flowop->options.rsize = string2int(value); } else if (strcasecmp(key, "nfiles") == 0) { flowop->options.nfiles = string2int(value); } else if (strcasecmp(key, "dir") == 0) { strlcpy(flowop->options.dir, value, PATHMAX); if (sendfile_init(value) != 0) { snprintf(err, sizeof (err), "Error initializing dir: %s\n", value); add_error(err); return (1); } } else if (strcasecmp(key, "count") == 0) { flowop->options.count = atoi(value); } else if (strcasecmp(key, "port") == 0) { flowop->options.port = atoi(value); } else if (strcasecmp(key, "protocol") == 0) { flowop->options.protocol = protocol_type(value); if (protocol_type(value) == PROTOCOL_UNSUPPORTED) { snprintf(err, sizeof (err), "Protocol %s not supported\n", value); add_error(err); return (1); } } else if (strcasecmp(key, "conn") == 0) { if ((flowop->p_id = atoi(value)) <= 0) { snprintf(err, sizeof (err), "connection id (conn=%s) should be > 0\n", value); add_error(err); return (1); } } else if (strcasecmp(key, "remotehost") == 0) { strlcpy(flowop->options.remotehost, value, 256); } else if (strcasecmp(key, "localhost") == 0) { strlcpy(flowop->options.localhost, value, 256); } else if (strcasecmp(key, "wndsz") == 0) { flowop->options.wndsz = string2int(value); } else if (strcasecmp(key, "timeout") == 0) { flowop->options.poll_timeout = string2nsec(value); if (flowop->options.poll_timeout == 0) { snprintf(err, sizeof (err), "Cannot understand timeout:%s\n", value); add_error(err); return (1); } } else if (strcasecmp(key, "duration") == 0) { flowop->options.duration = string2nsec(value); if (flowop->options.duration == 0) { snprintf(err, sizeof (err), "Cannot understand duration:%s\n", value); add_error(err); return (1); } } #ifdef HAVE_SSL else if (strcasecmp(key, "engine") == 0) { strlcpy(flowop->options.engine, value, sizeof (flowop->options.engine)); } else if (strcasecmp(key, "cipher") == 0) { strcpy(flowop->options.cipher, value); } else if (strcasecmp(key, "method") == 0) { strcpy(flowop->options.method, value); } #endif else { snprintf(err, sizeof (err), "parser - Option unrecognized %s=%s", key, value); add_error(err); return (1); } } return (0); }
std::string double2string(const double val, const std::size_t fieldLength, const std::size_t precission, const bool scientific, const bool decimalPointAssumed, const bool leftAlign) { char str[fieldLength]; double val1 = val; if (decimalPointAssumed) { double val3; val1 = modf(val, &val3); } sprintf(str, ("%" + int2string(fieldLength) + "." + int2string(precission + (scientific ? 1 : 0)) + (scientific ? "e" : "f")).c_str(), val1); std::string res(str); // Remove decimal point std::size_t pos = res.find("."); int n = 0; if (decimalPointAssumed && pos != std::string::npos && scientific) { n = -pos; res.replace(pos, 1, ""); } else if (decimalPointAssumed && !scientific) { pos = res.find("0."); if (pos != std::string::npos) res.replace(pos, 2, ""); } // Remove point from scientific format if (scientific) { std::size_t e_pos = res.find("e"); std::string base = res.substr(0, e_pos); std::string a = res.substr(e_pos + 1, res.length() - e_pos - 1); std::size_t pos1 = base.find("."); if (pos1 != std::string::npos) { n = base.length() - pos1 - 1; base.replace(pos1, 1, ""); } Node::ErrorCode error; int new_a = string2int(a, error) - n; if (string2double(base, error) == 0) new_a = 0; res = base + (new_a > 0 ? "+" : "-") + int2string(abs(new_a)); } res = trim(res); // Correct "0." or "-0." if (res.substr(0, 2) == "0.") res = res.substr(1, res.length() - 1); else if (res.substr(0, 3) == "-0.") res = "-" + res.substr(2, res.length() - 2); return string2string(res, fieldLength, leftAlign, false); }
void iLedlif::xmlParseDevice(XMLNode deviceNode) { std::string name; std::string deviceClass; std::string deviceName; std::string deviceType; std::string devicePortName; std::string deviceBaudRate; std::string elementName; std::string deviceFilePath; std::string val; std::string deviceFilename; std::string helpedDevice; std::string deviceCommType; std::vector<lifLED*> leds; std::vector<lifTSDIOPin*> pins; //Variables for pin std::string pinName; std::string dirBase; std::string dirOffset; std::string valBase; std::string valOffset; std::string bitNum; std::string enLow; //Variables for LED std::string ledName; std::string ledWL; std::string LEDPower; //Start reading in device information deviceClass = deviceNode.getChildNode("Class").getText(); deviceName = deviceNode.getChildNode("Name").getText(); deviceType = deviceNode.getChildNode("Type").getText(); deviceFilePath = deviceNode.getChildNode("Path_Name").getText(); helpedDevice = deviceNode.getChildNode("Helped_Device").getText(); //Check if there is a communication port entry for device if (deviceNode.nChildNode("Com_Port") > 0) { deviceCommType = deviceNode.getChildNode("Com_Port").getChildNode("Type").getText(); if (deviceCommType == "Serial") { devicePortName = deviceNode.getChildNode("Com_Port").getChildNode("Port").getText(); std::cout << deviceName << " " << devicePortName << std::endl; deviceBaudRate = deviceNode.getChildNode("Com_Port").getChildNode("Baud").getText(); } } //Load any defined pins for (int i = 0; i < deviceNode.nChildNode("Pin"); i++) { pinName = deviceNode.getChildNode("Pin", i).getChildNode("Name").getText(); dirBase = deviceNode.getChildNode("Pin", i).getChildNode("DirectionAddressBase").getText(); dirOffset = deviceNode.getChildNode("Pin", i).getChildNode("DirectionAddressOffset").getText(); valBase = deviceNode.getChildNode("Pin", i).getChildNode("ValueAddressBase").getText(); valOffset = deviceNode.getChildNode("Pin", i).getChildNode("ValueAddressOffset").getText(); bitNum = deviceNode.getChildNode("Pin", i).getChildNode("BitNumber").getText(); enLow = deviceNode.getChildNode("Pin", i).getChildNode("EnabledLow").getText(); pins.push_back(new lifTSDIOPin(pinName, string2int(bitNum), hexstring2int(dirBase), hexstring2int(dirOffset), hexstring2int(valBase), hexstring2int(valOffset), string2bool(enLow))); } //Load any LEDs for (int i = 0; i < deviceNode.nChildNode("LED"); i++) { ledName = deviceNode.getChildNode("LED", i).getChildNode("Name").getText(); ledWL = deviceNode.getChildNode("LED", i).getChildNode("Wavelength").getText(); LEDPower = deviceNode.getChildNode("LED", i).getChildNode("PowerSource").getText(); leds.push_back(new lifLED(ledName, string2int(ledWL), LEDPower)); } //declare device if (deviceClass == "Spectrometer") { std::cout << "iLedlif: Starting to load Spectrometer " << deviceName << std::endl; lifDevices.push_back((lifDevice*) (new lifSpectrometer(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, deviceFilePath, devicePortName, string2int(deviceBaudRate), *pins.front()))); std::cout << "iLedlif: Loaded Spectrometer " << deviceName << std::endl; } else if (deviceClass == "Main Com") { lifDevices.push_back((lifDevice*) (new lifMainComm(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, devicePortName, string2int(deviceBaudRate)))); std::cout << "iLedlif: Loaded Main Comm " << deviceName << std::endl; } else if (deviceClass == "LED Array") { lifDevices.push_back((lifDevice*) (new lifLEDArray(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, leds))); std::cout << "iLedlif: Loaded LED Array " << deviceName << std::endl; } else if (deviceClass == "Spec Helper") { lifDevices.push_back((lifDevice*) (new lifSpecHelper(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, helpedDevice))); std::cout << "iLedlif: Loaded Spec Helper " << deviceName << std::endl; } else if (deviceClass == "DIO Device") { lifDevices.push_back((lifDevice*) (new lifDIODevice(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, pins))); std::cout << "iLedlif: Loaded DIO Device " << deviceName << std::endl; } else if (deviceClass == "SSP Controller") { lifDevices.push_back((lifDevice*) (new lifSSPController(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed))); std::cout << "iLedlif: Loaded SSP Controller " << deviceName << std::endl; } else if (deviceClass == "Generic Device") { lifDevices.push_back(new lifDevice(deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed)); std::cout << "Generic Device added" << std::endl; } else if (deviceClass == "Program Runner") { lifDevices.push_back((lifDevice*) (new lifProgramRunner( deviceName, deviceType, &mainMsgQueue, &mainMsgMutex, &mainMsgQueuePushed, deviceFilename))); std::cout << "iLedlif: Loaded ProgramRunner " << deviceName << std::endl; } }
/** * Method to implement iLedlif responses to messages * @param msg The lifMsg to respond to */ void iLedlif::iLedlifMsgHandle(lifMsg msg) { int i; lifMsg rMsg; rMsg.set_target("MainComm"); rMsg.set_command("Output"); rMsg.set_source("iLedlif"); //When iLedlif receives the "Exit" command, it issues the "Stop" command to all devices if (msg.get_command() == "Exit") { int ex = 10; if (msg.get_num_params() == 0) { pushMsgQueue((std::string)"MainComm Output Exiting iLEDLIF. Issuing STOP to all devices."); pushMsgQueue((std::string)"ALL Stop"); #ifdef DSAAV std::vector<lifDevice*>::iterator ditr = getDeviceIteratorByName("DSAAVComm1"); std::cout << "iLedlif: " << (*ditr)->GetDeviceName() << " has exited." << std::endl; delete (*ditr); lifDevices.erase(ditr); #endif } else { ex = string2int(msg.get_param_at(0)) - 1; if (ex == 0) { for (i = 0; i < lifDevices.size(); i++) { lifDevices.at(i)->cancelDeviceThread(); } std::cout << "Exiting iLEDLIF" << std::endl; pthread_exit(NULL); } } rMsg.set_target("iLedlif"); rMsg.add_param(toString(ex)); std::cout << "Canceling remaining threads in " << ex << std::endl; rMsg.set_command("Exit"); pushMsgQueue(rMsg); lifDevice ld; ld.lifSleep(1000); //This command is issued by a device after being told to "Stop" //When iLedlif receives this command, it removes the device from the device vector //When the device vector is empty, iLedlif exits } else if (msg.get_command() == "Exited") { try { std::vector<lifDevice*>::iterator itr = getDeviceIteratorByName(msg.get_param_at(0)); std::cout << "iLedlif: " << (*itr)->GetDeviceName() << " has exited." << std::endl; delete (*itr); lifDevices.erase(itr); } catch (std::string s) { std::cout << s << std::endl; } if (lifDevices.empty()) { std::cout << "Exiting iLEDLIF" << std::endl; pthread_exit(NULL); } } else if (msg.get_command() == "ListDevices") { std::string devStr; devStr = ""; for (i = 0; i < lifDevices.size(); i++) { devStr = devStr + lifDevices.at(i)->GetDeviceName() + " "; } rMsg.add_params(devStr); pushMsgQueue(rMsg); } else { std::string msgStr; msgStr = "No command \"" + msg.get_command() + "\" defined."; rMsg.add_params(msgStr); pushMsgQueue(rMsg); } }
void getDevicesToken(CImPdu* pPdu, uint32_t conn_uuid) { IM::Server::IMGetDeviceTokenReq msg; IM::Server::IMGetDeviceTokenRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CacheManager* pCacheManager = CacheManager::getInstance(); CacheConn* pCacheConn = pCacheManager->GetCacheConn("token"); CImPdu* pPduResp = new CImPdu; uint32_t nCnt = msg.user_id_size(); if (pCacheConn) { vector<string> vecTokens; for (uint32_t i=0; i<nCnt; ++i) { string strKey = "device_"+int2string(msg.user_id(i)); vecTokens.push_back(strKey); } map<string, string> mapTokens; bool bRet = pCacheConn->mget(vecTokens, mapTokens); pCacheManager->RelCacheConn(pCacheConn); if(bRet) { for (auto it=mapTokens.begin(); it!=mapTokens.end(); ++it) { string strKey = it->first; size_t nPos = strKey.find("device_"); if( nPos != string::npos) { string strUserId = strKey.substr(nPos + strlen("device_")); uint32_t nUserId = string2int(strUserId); string strValue = it->second; nPos = strValue.find(":"); if(nPos!=string::npos) { string strType = strValue.substr(0, nPos); string strToken = strValue.substr(nPos + 1); IM::BaseDefine::ClientType nClientType = IM::BaseDefine::ClientType(0); if(strType == "ios") { nClientType = IM::BaseDefine::CLIENT_TYPE_IOS; } else if(strType == "android") { nClientType = IM::BaseDefine::CLIENT_TYPE_ANDROID; } if(IM::BaseDefine::ClientType_IsValid(nClientType)) { IM::BaseDefine::UserTokenInfo* pToken = msgResp.add_user_token_info(); pToken->set_user_id(nUserId); pToken->set_token(strToken); pToken->set_user_type(nClientType); uint32_t nTotalCnt = 0; CMessageModel::getInstance()->getUnReadCntAll(nUserId, nTotalCnt); CGroupMessageModel::getInstance()->getUnReadCntAll(nUserId, nTotalCnt); pToken->set_push_count(nTotalCnt); pToken->set_push_type(1); } else { log("invalid clientType.clientType=%u", nClientType); } } else { log("invalid value. value=%s", strValue.c_str()); } } else { log("invalid key.key=%s", strKey.c_str()); } } } else { log("mget failed!"); } } else { log("no cache connection for token"); } log("req devices token.reqCnt=%u, resCnt=%u", nCnt, msgResp.user_token_info_size()); msgResp.set_attach_data(msg.attach_data()); pPduResp->SetPBMsg(&msgResp); pPduResp->SetSeqNum(pPdu->GetSeqNum()); pPduResp->SetServiceId(IM::BaseDefine::SID_OTHER); pPduResp->SetCommandId(IM::BaseDefine::CID_OTHER_GET_DEVICE_TOKEN_RSP); CProxyConn::AddResponsePdu(conn_uuid, pPduResp); } else { log("parse pb failed"); } }
void Coordinator::processResults() { while (true) { { boost::mutex::scoped_lock lock(results_mutex); // We can improve this later. bool empty = true; while (empty) { for (int i = 0; i < results.size(); ++i) { if (!results[i].empty()) { empty = false; break; } } if (empty) results_con.wait(lock); } Debug("Server process results.\n"); for (int i = 0; i < results.size(); ++i) { if (!((results[i]).empty())) { --num; } while (!((results[i]).empty())) { string str = results[i].front(); Debug("Server Processing " << str << " \n"); results[i].pop(); istringstream iss(str); vector<string> tokens; copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens)); if ("get" == tokens[0]) { reGet[string2int(tokens[1])] = tokens[2]; } else if ("put" == tokens[0]) { // nothing to do } else if ("getRange" == tokens[0]) { vector<string> getRangeValues (tokens.begin() + 3, tokens.end()); reGetRange[make_pair(string2int(tokens[1]), string2int(tokens[2]))] = getRangeValues; } } // end while results[i].empty() } // end for results.size() for (int i = 0; i < minMaxV.size(); ++i) { pair<int, int> mmv = minMaxV[i]; // Across worker if (0 == reGetRange.count(mmv)) { int minKey = mmv.first; int maxKey = mmv.second; int posMin = getPos(minKey); int posMax = getPos(maxKey); num += posMax - posMin + 1; pair<int, int> p = make_pair(minKey, (posMin * size - 1)); vector<string> getRangeValues(reGetRange[p].begin(), reGetRange[p].end()); for (int i = posMin + 1; i < posMax; ++i) { p = make_pair((i - 1) * size, i * size - 1); getRangeValues.insert(getRangeValues.end(), reGetRange[p].begin(), reGetRange[p].end()); } p = make_pair((posMax - 1) * size, maxKey); getRangeValues.insert(getRangeValues.end(), reGetRange[p].begin(), reGetRange[p].end()); reGetRange[mmv] = getRangeValues; } // end reGetRange.count(mmv) } request_con.notify_all(); Debug("Server process done\n"); } } }
_d = d ? d : default_date._d; _m = m ? m : default_date._m; _y = y ? y : default_date._y; validate(); } Date::Date(std::string d) { boost::regex dateRE(R"(^\s*(\d{1,2})\s*/\s*(\d{1,2})\s*/\s*(\d{1,4})\s*$)"); boost::cmatch results; if (!boost::regex_match(d.c_str(), results, dateRE)) { throw new Date::Ex("invalid date string format"); } _d = string2int(results[1].str()); _m = string2int(results[2].str()); _y = string2int(results[3].str()); std::cout << "Date::Date(string) _d=" << _d << " _m=" << _m << " _y=" << _y << "\n"; validate(); } Date::~Date() { std::cout << "implement Date::~Date()\n"; } uint16_t Date::string2int(std::string d) { std::istringstream iss(d); uint16_t t;
void MainWindow::on_action_triggered() { fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Text Files (*.txt)")).toStdString(); if (!fileName.empty()) { std::ifstream file; std::ofstream mainTable; std::string buffer {}; file.open(fileName); mainTable.open(nameOfMainTable, std::ios_base::trunc); mainTable << std::setw(20) <<"Process" << std::setw(8) << "Memory" << std::setw(10) << "Priority" << std::setw(15) << "User" << std::setw(5) << "id" << std::endl; while (file) { std::getline(file,buffer); std::string command = buffer.substr(0,buffer.find(' ')); buffer.erase(0,buffer.find(' ')); char chars[] = "{}- "; for (unsigned int i = 0; i < strlen(chars); ++i) { buffer.erase (std::remove(buffer.begin(), buffer.end(), chars[i]), buffer.end()); } switch (string2int(command.c_str())) { case (string2int("add")): { //add process in MAIN table. example syntax: add { ie.exe , 800, 1, user, 2034 } std::vector <std::string> code = add(buffer); //std::reverse(std::begin(code), std::end(code)); mainTable << std::setw(20) << code[code.size()-5]<< std::setw(8) << code[code.size()-4] << std::setw(10) << code[code.size()-3] << std::setw(15) << code[code.size()-2] << std::setw(5) << code[code.size()-1]<< std::endl; break; }; case (string2int("delete")): { // deletes a row with specified ID. example syntax: delete 2034 std::ifstream fin(nameOfMainTable.c_str()); std::ofstream fout("temporary_file.txt"); std::string line {}; while (fin) { std::getline(fin,line); if (line.find(buffer.c_str()) == std::string::npos) fout << line << std::endl; else continue; } fin.close(); fout.close(); remove(nameOfMainTable.c_str()); rename("temporary_file.txt", nameOfMainTable.c_str()); break; } case (string2int("sort")): { std::ifstream fin(nameOfMainTable); std::ofstream fout("temporary_file.txt"); std::string line {}; std::vector <std::string> xz ; QString priority = "priority"; QString process = "process"; QString memory = "memory"; QString user = "******"; QString id = "id"; QString column = trim(buffer).c_str(); std::string header_data{}; std::string code {}; std::string temp {}; std::getline(fin,header_data); // read header data in main table while (fin) { std::getline(fin,line); code.clear(); for (int i = 0; i< 5; i++) { if ( i < 4) { temp.append(trim(line)); line.clear(); line.append(temp); temp.clear(); code.append(line.substr(0,line.find(" ")+1)); line.erase(0,line.find(" ")+1); //line.erase(std::remove_if(line.begin(), line.end(), ::isspace), line.end()); //std::cout<<line<<" line after remove"<<std::endl; temp.append(trim(line)); line.clear(); line.append(temp); temp.clear(); } if (i ==4) { temp.append(trim(line)); line.clear(); line.append(temp); temp.clear(); code.append(line.substr(0,line.length())); line.clear(); } } if (!code.empty()) xz.push_back(code); } std::vector <std::string> xz_rezerv; for (int i = 0; i < xz.size();i++) { xz_rezerv.push_back(xz.at(i)); } if (column == process) { std::sort(xz.begin(), xz.end()); for (int i = 0; i < xz.size(); i++) { std::cout << xz.at(i) << std::endl; } std::cout<<"column: process"<<std::endl; } if (column == memory) { for (int i = 0; i<xz.size();i++){ std::string temp {}; temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); } std::sort(xz.begin(), xz.end()); for (int i = 0; i < xz_rezerv.size(); i++) { std::string buffer = trim(xz_rezerv.at(i)); xz_rezerv.at(i).clear(); xz_rezerv.at(i).append(buffer); buffer.clear(); } for (int i = 0; i < xz.size(); i++) { std::string buffer = trim(xz.at(i)); xz.at(i).clear(); xz.at(i).append(buffer); buffer.clear(); } std::string buffer {}; for (int i = 0; i<xz_rezerv.size(); i++) { for (int j = 0; j<xz.size(); j++) { if (xz_rezerv.at(i).find(xz.at(j).c_str()) != std::string::npos) { buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); buffer.append(xz.at(j)); xz.at(j).clear(); xz.at(j).append(buffer); buffer.clear(); break; } } } for (int i = 0; i< xz.size(); i++) { std::cout << xz.at(i) << std::endl; } std::cout << "memory" <<std::endl; } if (column == priority) { for (int i = 0; i<xz.size();i++){ std::string temp {}; temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); } std::sort(xz.begin(), xz.end()); for (int i = 0; i < xz_rezerv.size(); i++) { std::string buffer = trim(xz_rezerv.at(i)); xz_rezerv.at(i).clear(); xz_rezerv.at(i).append(buffer); buffer.clear(); } for (int i = 0; i < xz.size(); i++) { std::string buffer = trim(xz.at(i)); xz.at(i).clear(); xz.at(i).append(buffer); buffer.clear(); } std::string buffer {}; for (int i = 0; i<xz.size(); i++) { for (int j = 0; j<xz.size(); j++) { if (xz_rezerv.at(i).find(xz.at(j).c_str()) != std::string::npos) { buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); buffer.append(xz.at(j)); xz.at(j).clear(); xz.at(j).append(buffer); buffer.clear(); break; } } } for (int i = 0; i< xz.size(); i++) { std::cout << xz.at(i) << std::endl; } std::cout <<"priority"<< std::endl; } if (column == user) { for (int i = 0; i<xz.size();i++){ std::string temp {}; temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); } std::sort(xz.begin(), xz.end()); for (int i = 0; i < xz_rezerv.size(); i++) { std::string buffer = trim(xz_rezerv.at(i)); xz_rezerv.at(i).clear(); xz_rezerv.at(i).append(buffer); buffer.clear(); } for (int i = 0; i < xz.size(); i++) { std::string buffer = trim(xz.at(i)); xz.at(i).clear(); xz.at(i).append(buffer); buffer.clear(); } std::string buffer {}; for (int i = 0; i<xz.size(); i++) { for (int j = 0; j<xz.size(); j++) { if (xz_rezerv.at(i).find(xz.at(j).c_str()) != std::string::npos) { buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); buffer.append(xz.at(j)); xz.at(j).clear(); xz.at(j).append(buffer); buffer.clear(); break; } } } for (int i = 0; i< xz.size(); i++) { std::cout << xz.at(i) << std::endl; } std::cout << "user" <<std::endl; } if (column == id) { for (int i = 0; i<xz.size();i++){ std::string temp {}; temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); xz.at(i).erase(0, xz.at(i).find(" ") + 1); temp.append(trim(xz.at(i))); xz.at(i).clear(); xz.at(i).append(temp); temp.clear(); } std::sort(xz.begin(), xz.end()); std::string buffer {}; for (int i = 0; i<xz.size(); i++) { for (int j = 0; j<xz.size(); j++) { if (xz_rezerv.at(i).find(xz.at(j).c_str()) != std::string::npos) { buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz_rezerv.at(i).substr(0, xz_rezerv.at(i).find(" ") + 1)); xz_rezerv.at(i).erase(0, xz_rezerv.at(i).find(" ") + 1); buffer.append(xz.at(j).c_str()); xz.at(j).clear(); xz.at(j).append(buffer.c_str()); buffer.clear(); break; } } } for (int i = 0; i< xz.size(); i++) { std::cout << xz.at(i) << std::endl; } std::cout << "id"<<std::endl; } fin.close(); fout.close(); break; }; case (string2int("filter")): { break; }; case (string2int("erase")): { if (buffer == "mainTable") break; else { buffer.append(".txt"); remove(buffer.c_str()); } break; }; case (string2int("copy")): { //copy table from mainTable to %nameOfNewTable%. example syntax: copy table2 std::ifstream fin(nameOfMainTable); buffer.append(".txt"); std::ofstream fout(buffer, std::ios_base::trunc); while( std::getline( fin, buffer) ) fout << buffer << std::endl; fin.close(); fout.close(); break; }; case (string2int("show")): { //show %tableName% in qTextBrowser. example syntax: show table1 buffer.append(".txt"); std::ifstream fin(buffer); std::string code; while (fin) { std::getline(fin,buffer); code.append(buffer); code.append("\n"); } ui->textBrowser->setText(code.c_str()); fin.close(); break; }; case (string2int("append")): { //append %table2% with %table1%. example syntax: append table1,table2 std::string outputBuffer {}; std::string name = buffer.substr(0,buffer.find(',')); name.append(".txt"); std::ifstream fin(name, std::ios_base::binary); buffer.erase(0,buffer.find(',')+1); buffer.append(".txt"); std::ofstream fout(buffer, std::ios_base::binary | std::ios_base::app); fout.seekp(0, std::ios_base::end); std::getline(fin,buffer); while (std::getline(fin, outputBuffer)) { fout << outputBuffer << std::endl; } fin.close(); fout.close(); break; }; default: { break;} } } file.close(); mainTable.close(); } }
bool XMLBBoxReader::getNextFrameResult(vector<Result2D>& result) { bool rt=false; result.clear(); while (frame!=NULL) { if (!xmlStrcmp(frame->name,BAD_CAST"frame")) { rt=true;//get the successive frame xmlNodePtr objectList; objectList=frame->children; while (objectList!=NULL)//objectlist level { if (!xmlStrcmp(objectList->name,BAD_CAST"objectlist")) { xmlNodePtr object=objectList->children; while (object!=NULL)//object level { if (!xmlStrcmp(object->name,BAD_CAST"object")) { Result2D res; temp=xmlGetProp(object,BAD_CAST"id"); res.id=string2int((char*)temp); xmlFree(temp); xmlNodePtr box=object->children; while (box!=NULL) { if (!xmlStrcmp(box->name,BAD_CAST"box")) { temp=xmlGetProp(box,BAD_CAST"h"); res.h=(float)string2float((char*)temp); xmlFree(temp); temp=xmlGetProp(box,BAD_CAST"w"); res.w=(float)string2float((char*)temp); xmlFree(temp); temp=xmlGetProp(box,BAD_CAST"xc"); res.xc=(float)string2float((char*)temp); xmlFree(temp); temp=xmlGetProp(box,BAD_CAST"yc"); res.yc=(float)string2float((char*)temp); xmlFree(temp); break; } box=box->next; } result.push_back(res); } object=object->next; } break; } objectList=objectList->next; } break; } frame=frame->next; } if (frame!=NULL) { frame=frame->next; } return rt; }