void TDTab::selectBtn(TDButton* btn){ if(btn->linkPanel.size()==0){ return; } clear(); btn->setEnable(false); m_pCurBtn=btn; vector<string>ret; splitStr(ret, btn->linkPanel, ","); for(unsigned int i=0;i<ret.size();i++){ TDPanel* item=getUI(ret[i].c_str()); if(item){ m_pCurPanel=(TDPanel*)item; } if(item && item->getParent()==NULL){ addChild(item,-1); } } if(m_pListener&& m_pfnSelector) (m_pListener->*m_pfnSelector)(btn); //if(m_uListener && func.size() > 0) { // FlashBuilderManager::sharedManager()->onPanelClicked(this, m_uListener, func.c_str()); //} }
void checkSpell(std::string wrong) { std::vector<std::string> temp; splitStr(wrong, &temp); for (int i = 0;i < temp.size();++i) { std::ifstream myIf("CT2 dict.txt"); std::string data; while (!myIf.eof()) { myIf >> data; int distance = edit_distance(temp[i], data); if (distance == 0) { continue; } else if (distance == 1) { temp[i] = temp[i] + " (" + data + ')'; } } } std::string result; for (int i = 0;i < temp.size() - 1;++i) { result = result + temp[i] + ' '; } result = result + temp[temp.size() - 1] + '.'; std::cout << result << '\n'; }
bool Web::parseXML(string xml) { int iter = 0; vector<string> lines; string rootName; splitStr(xml, '\n', lines); while(myUtil.match(lines[iter], IGNORE_TAG)) { iter++; } rootName = myUtil.getMatch(lines[iter], OPEN_TAG_NAME, 1); if(rootName == "concepts") { return parseConcepts(lines); } else if(rootName == "words") { return parseWords(lines); } else { fprintf(outFile, "Invalid root name in xml file\n"); return false; } }
int getUserName(char* deviceType) { char* request = createRequestStr("POST", NULL, deviceType); if(strcmp(request, EMPTY_STR) == 0) return 0; int countTime = 0; char* response = sendTcpRequest(request, 80, LAMP_BRIDGE_IP); while((strstr(response, USER_NAME_HEAD_FLAG) == NULL) || (strstr(response, PRESS_BTN_ERROR) != NULL) || (countTime >= WAIT_PUSH_BTN_TIME)) { free(response); printf("\nplease push the button on the lamp bridge in the next 10s!\n"); Sleep(3000); countTime ++; response = sendTcpRequest(request, 80, LAMP_BRIDGE_IP); } splitStr(response, USER_NAME_HEAD_FLAG, USER_NAME_TAIL_FLAG, USER_NAME); free(request); free(response); if((countTime >= WAIT_PUSH_BTN_TIME) && (strcmp(USER_NAME, EMPTY_STR) == 0)) { printf("wait for push bridge link button timeout ......\n"); return 0; } else { printf("get username succeed, username now is :%s\n", USER_NAME); return 1; } }
bool Trie::_trieInsert(const char * const filePath) { ifstream ifile(filePath); string line; vector<string> vecBuf; TrieNodeInfo nodeInfo; while(getline(ifile, line)) { vecBuf.clear(); splitStr(line, vecBuf, " "); if(3 < vecBuf.size()) { LogError("line[%s] illegal.", line.c_str()); return false; } if(!TransCode::decode(vecBuf[0], nodeInfo.word)) { return false; } nodeInfo.freq = atoi(vecBuf[1].c_str()); if(3 == vecBuf.size()) { nodeInfo.tag = vecBuf[2]; } //insert node if(!insert(nodeInfo)) { LogError("insert node failed!"); } } return true; }
string Tree::generateTree(string nextString) { srand(randomSeed++); string finalString = ""; list<string> tokens = splitStr(nextString, " "); for(list<string>::iterator iter = tokens.begin(); iter != tokens.end(); iter++) { if( !(iter->compare("t")) ) { finalString += "t "; continue; } if( !(iter->compare("s")) ) { finalString += generateTree("t t t t0"); continue; } if( !(iter->compare("t0")) ) { switch(rand()%4) { case 0: finalString += generateTree("t b b t1"); break; case 1: finalString += generateTree("t b t1"); break; case 2: finalString += generateTree("t b t1 b"); break; case 3: finalString += generateTree("t t1"); break; } continue; } if( !(iter->compare("t1")) ) { switch(rand()%2) { case 0: finalString += "t b b b b "; break; case 1: finalString += "t b b b "; break; } continue; } finalString += *iter + " "; } return finalString; }
string scannar::returnToGUI(){ err=new error(); int getMsg= splitStr(); if(getMsg==0&&tokenize.size()>0){ parse= new parser(); getMsg= parse->startParsing(tokenize); } return consoleMessage(getMsg); }
std::string safePath(const std::string &unsafe) { std::vector<std::string> walking; for (auto path : splitStr(unsafe, "/")) { if (path == ".") // current directory continue; // skip it if (path == "..") // parent directory walking.pop_back(); else walking.push_back(path); } if (walking.size() == 1) return std::string("/"); return joinStr(walking, "/"); }
TDButton* TDTab::getBtnByTag(int tag){ for(unsigned int i=0;i<gBtns.size();i++){ vector<string>ret; splitStr(ret, gBtns[i]->linkPanel, ","); for(unsigned int j=0;j<ret.size();j++){ TDPanel* item=getUI(ret[j].c_str()); if(tag==item->getTag()){ return (gBtns[i]); } } } return NULL; }
int getBridgeIP() { struct sockaddr_in si_other; int s; // client udp socket int slen = sizeof(si_other); char response[RECV_BUFLEN]; WSADATA wsa; //Initialise winsock printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2,2),&wsa) != 0) { printf("Failed. Error Code : %d",WSAGetLastError()); return 0; } printf("Initialised.\n"); //create socket if ( (s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) { printf("socket() failed with error code : %d" , WSAGetLastError()); return 0; } //set socket as a broadcast type const int opt = 1; if(setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&opt, sizeof(opt)) == -1) { printf("set socket broadcast failed with error code : %d\n" , WSAGetLastError()); return 0; } //setup address structure memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(MULTI_CAST_PORT); si_other.sin_addr.S_un.S_addr = inet_addr(MULTI_CAST_SERVER); //htonl(INADDR_BROADCAST); //the broadcast request, ie "Any upnp devices out there?" char *request = "M-SEARCH * HTTP/1.1\r\nHOST:239.255.255.250:1900\r\nMAN:\"ssdp:discover\"\r\nST:ssdp:all\r\nMX:5\r\n\r\n"; printf("Search Lamp Bridge Request: \n%s", request); while(1) { if (sendto(s, request, strlen(request) , 0 , (struct sockaddr *) &si_other, slen) == SOCKET_ERROR) { printf("sendto() failed with error code : %d" , WSAGetLastError()); return 0; } //clear the buffer by filling null, it might have previously received data memset(response,'\0', RECV_BUFLEN); //try to receive some data, this is a blocking call if (recvfrom(s, response, RECV_BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == SOCKET_ERROR) { printf("recvfrom() failed with error code : %d" , WSAGetLastError()); return 0; } //parse the response, get bridge IP if(strstr(response, BRIDGE_TAG) != NULL) { printf("=========================== Response ==========================\n"); puts(response); splitStr(response, IP_HEAD_FLAG, IP_TAIL_FLAG, LAMP_BRIDGE_IP); closesocket(s); WSACleanup(); break; } } return 1; }
SCSGNode* Tree::buildTree() { generationString = generateTree("s"); int trunkIteration = 0; Matrix4 ident = Matrix4(); ident.identity(); Matrix4 rotateToUpright = Matrix4(); rotateToUpright.rotateX(-90); GLdouble baseParams[5]; /* * Trunk Params: * [0] - radius at base * [1] - radius at top * [2] - height * [3] - number of segments used to construct base * [4] - number of segments to render to construct height */ baseParams[0] = TRUNK_RADIUS_BOT; baseParams[1] = TRUNK_RADIUS_TOP; baseParams[2] = TRUNK_HEIGHT; baseParams[3] = TRUNK_SEGS; baseParams[3] = TRUNK_SEGS; SCSGNode* parent = new SCSGNode(Trunk, baseParams, rotateToUpright, ident); SCSGNode* current = parent; list<string> tokens = splitStr(generationString, " "); for(list<string>::iterator iter = tokens.begin(); iter != tokens.end(); iter++) { GLdouble trunkParams[5]; GLdouble branchParams[5]; if( !(iter->compare("t") ) ) { trunkIteration++; trunkParams[0] = baseParams[0] - trunkIteration*TRUNK_RADIUS_DELTA; trunkParams[1] = baseParams[1] - trunkIteration*TRUNK_RADIUS_DELTA; trunkParams[2] = baseParams[2] - trunkIteration*TRUNK_HEIGHT_DELTA; trunkParams[3] = TRUNK_SEGS; trunkParams[4] = TRUNK_SEGS; Matrix4 n = Matrix4(); n.translationMat(0,0,trunkParams[2]); SCSGNode* newTrunk = new SCSGNode(Trunk, trunkParams, ident, n); current->children.push_back(newTrunk); current = newTrunk; } if( !(iter->compare("b") ) ) { srand(randomSeed++); /* * Branch Params: * [0] - cone radius at base * [1] - height of cone * [2] - base segments * [3] - height segments * [4] - leaf radius */ /* trunkParams[0] = baseParams[0] - trunkIteration*TRUNK_HEIGHT_DELTA; trunkParams[1] = baseParams[1] - trunkIteration*TRUNK_RADIUS_DELTA; trunkParams[2] = baseParams[2] - trunkIteration*TRUNK_RADIUS_DELTA; trunkParams[3] = TRUNK_SEGS; trunkParams[4] = TRUNK_SEGS; */ branchParams[0] = BRANCH_RADIUS; branchParams[1] = BRANCH_LENGTH; branchParams[2] = BRANCH_SEGS; branchParams[3] = BRANCH_SEGS; branchParams[4] = BRANCH_LEAF_RADIUS; //Rotation Matrix4 *rotX = new Matrix4(); Vector3 axis = Vector3(); axis.set(rand()%AXIS_XY_RAND_RANGE+AXIS_XY_LOW, rand()%AXIS_XY_RAND_RANGE+AXIS_XY_LOW, rand()%100); axis.normalize(); double angle = rand()%AXIS_ANGLE_RAND_RANGE + AXIS_ANGLE_LOW; *rotX = rotX->rotate(axis, angle); /* Matrix4 offset = trans.multiply(rotX); */ SCSGNode* newBranch = new SCSGNode(Branch, branchParams, *rotX, ident); current->children.push_back(newBranch); } } return parent; }