/*++ * @method: twitCurl::performPost * * @description: method to send http POST request. this is an internal method. * twitcurl users should not use this method. * * @input: postUrl - url, * dataStr - data to be posted * * @output: none * * @remarks: internal method * *--*/ bool twitCurl::performPost( const std::string& postUrl, std::string dataStr ) { std::string oAuthHttpHeader( "" ); struct curl_slist* pOAuthHeaderList = NULL; /* Prepare standard params */ prepareStandardParams(); /* urlencode data */ if( dataStr.length() > 0 ) { /* Data should already be urlencoded once */ std::string dataKey( "" ); std::string dataValue( "" ); size_t nPos = dataStr.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataStr.substr( 0, nPos ); dataValue = dataStr.substr( nPos + 1 ); dataValue = urlencode( dataValue ); dataStr.assign( dataKey ); dataStr.append( "=" ); dataStr.append( dataValue ); } } /* Set OAuth header */ m_oAuth.getOAuthHeader( eOAuthHttpPost, postUrl, dataStr, oAuthHttpHeader ); if( oAuthHttpHeader.length() > 0 ) { pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() ); if( pOAuthHeaderList ) { curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList ); } } /* Set http request, url and data */ curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 ); curl_easy_setopt( m_curlHandle, CURLOPT_URL, postUrl.c_str() ); if( dataStr.length() ) { curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str() ); } /* Send http request */ if( CURLE_OK == curl_easy_perform( m_curlHandle ) ) { if( pOAuthHeaderList ) { curl_slist_free_all( pOAuthHeaderList ); } return true; } if( pOAuthHeaderList ) { curl_slist_free_all( pOAuthHeaderList ); } return false; }
void cDialogueList::LoadScript() { CMHFile file; file.Init( "Data/Script/Npc/Npc_Msg.bin", "rb"); DWORD messageIndex = 0; WORD wLineIdx = 0; while(FALSE == file.IsEOF()) { // 091207 LUJ, 1K 이하로 선언하면 메모리 오류가 발생한다... 그런데 파싱 코드가 겁나게 복잡하다. TCHAR buffer[1024] = {0}; file.GetLine( buffer, sizeof(buffer) / sizeof(*buffer)); TCHAR textLine[1024] = {0}; SafeStrCpy( textLine, buffer, sizeof(textLine) / sizeof(*textLine)); LPCTSTR seperator = " \t#"; LPCTSTR token = _tcstok(buffer, seperator); LPCTSTR comment = "@"; LPCTSTR openMark = "{"; LPCTSTR closeMark = "}"; if(0 == token) { continue; } else if(0 == _tcsnicmp(comment, token, _tcslen(comment))) { continue; } else if(0 == _tcsnicmp(openMark, token, _tcslen(openMark))) { continue; } else if(0 == _tcsnicmp(closeMark, token, _tcslen(closeMark))) { continue; } else if(0 == _tcsicmp("msg", token)) { LPCTSTR textMessageIndex = _tcstok(0, seperator); messageIndex = _ttoi(textMessageIndex ? textMessageIndex : ""); wLineIdx = 0; continue; } // 091216 ShinJS --- Npc_Msg.bin의 Data를 저장(인덱스,라인,메세지) NpcMsgDataKey dataKey( messageIndex, wLineIdx ); m_NpcMsgData.insert( std::make_pair( dataKey, textLine ) ); ++wLineIdx; } }
Status Wallet::nameSet(const std::string &name) { std::lock_guard<std::mutex> lock(mutex_); name_ = name; NameJson json; ABC_CHECK(json.nameSet(name)); ABC_CHECK(json.save(syncDir() + WALLET_NAME_FILENAME, dataKey())); return Status(); }
Status Wallet::currencySet(int currency) { std::lock_guard<std::mutex> lock(mutex_); currency_ = currency; CurrencyJson currencyJson; ABC_CHECK(currencyJson.currencySet(currency)); ABC_CHECK(currencyJson.save(syncDir() + WALLET_CURRENCY_FILENAME, dataKey())); return Status(); }
Status Wallet::loadSync() { ABC_CHECK(fileEnsureDir(gContext->paths.walletsDir())); ABC_CHECK(fileEnsureDir(dir())); ABC_CHECK(syncEnsureRepo(syncDir(), dir() + "tmp/", syncKey_)); // Load the currency: CurrencyJson currencyJson; currencyJson.load(syncDir() + WALLET_CURRENCY_FILENAME, dataKey()); ABC_CHECK(currencyJson.currencyOk()); currency_ = currencyJson.currency(); // Load the name (failure is acceptable): NameJson json; json.load(syncDir() + WALLET_NAME_FILENAME, dataKey()); name_ = json.name(); // Load the databases: ABC_CHECK(addresses.load()); ABC_CHECK(txs.load()); return Status(); }
void ResourceManagerTest::manualPolicy() { ResourceManager rm; ResourceKey dataKey("data"); /* Manual free */ { rm.set(dataKey, new Data, ResourceDataState::Mutable, ResourcePolicy::Manual); Resource<Data> data = rm.get<Data>(dataKey); rm.free(); } CORRADE_COMPARE(rm.count<Data>(), 1); CORRADE_COMPARE(Data::count, 1); rm.free(); CORRADE_COMPARE(rm.count<Data>(), 0); CORRADE_COMPARE(Data::count, 0); rm.set(dataKey, new Data, ResourceDataState::Mutable, ResourcePolicy::Manual); CORRADE_COMPARE(rm.count<Data>(), 1); CORRADE_COMPARE(Data::count, 1); }
DIALOGUE* cDialogueList::GetDialogue( DWORD dwMsgId, WORD wLine ) // 다이얼로그 정보를 반환하는 함수. { MessageMap::iterator messageIterator = mMessageMap.find(dwMsgId); if(mMessageMap.end() == messageIterator) { // 091216 ShinJS --- Pasring 되어 있지 않은 경우 저장된 NpcMsgData를 Parsing 한다. NpcMsgDataKey dataKey( dwMsgId, 0 ); NpcMsgData::const_iterator iter = m_NpcMsgData.find( dataKey ); while( iter != m_NpcMsgData.end() ) { const std::string &npcMsg = iter->second; ParsingLine( dwMsgId, npcMsg.c_str()); dataKey.second = dataKey.second + 1; iter = m_NpcMsgData.find( dataKey ); } messageIterator = mMessageMap.find( dwMsgId ); if(mMessageMap.end() == messageIterator) return 0; } DialogMap& dialogMap = messageIterator->second; DialogMap::iterator dialogIteartor = dialogMap.find(wLine); if(dialogMap.end() == dialogIteartor) { return 0; } return &(dialogIteartor->second); }
/***************************************************************************************** * vector< int > K_MeansPredict::Train( const vector< vector< float > >& Data, const float stopDist, const int stopIter, const int fast ) * * Purpose: Train predictor * input: * Data: vector of data * stopDist: Distance stopping criteria * stopIter: Max Iteration stopping criteria * * return: * vector of cluster membership * * 01.07.2006 djh added stoping criterion parameters * stopDist minimum euclidean distance * stopIter maximum iterations * extra error output * 03.06.2006 djh replaced _totalUpper/_totalLowerConfBound with _totalBoundStub * ******************************************************************************************/ vector< int > K_MeansPredict::Train( const vector< vector< float > >& Data, const float stopDist, const int stopIter, const int fast ){ // create vector of example coordinates vector< Coord< float > > coordData( Data.size() ); // create vector of example key values vector< float > dataKey( Data.size() ); // for( int i=0; i<Data.size(); i++) { vector< float > tempCoords( Data[i].size()-1 ); dataKey[i]=Data[i][0]; for( int j=1; j<Data[i].size(); j++ ) { tempCoords[j-1] = Data[i][j]; } coordData[i] = Coord< float >( tempCoords ); } // calculate clusters float dist; int numIter; vector<int> clusterMap = CreateClusters( coordData, stopDist, stopIter, dist, numIter ); if( fast == 1 ){ return( clusterMap ); } cout << "# Training:\n"; cout << "# Training required " << numIter << " rounds, the max Euclid. Dist. is: " << dist << endl; // calculate cluster stats vector< float > sum_x( _k, 0. ); vector< float > sum_x2( _k, 0. ); _key_supports = vector< int >( _k, 0); // find n and sums for( int i=0; i<Data.size(); i++ ){ _key_supports[ clusterMap[i] ]++; sum_x[ clusterMap[i] ] += dataKey[ clusterMap[i] ]; sum_x2[ clusterMap[i] ] += pow( dataKey[ clusterMap[i] ], 2); } // compute mean and variance _key_means = vector< float >(_k,0.); _key_variances = vector< float >(_k,0.); for( int i=0; i<_k; i++ ){ _key_means[i]=sum_x[i]/_key_supports[i]; _key_variances[i] = ( sum_x2[i] - (sum_x[i]/float(_key_supports[i])) )/float( _key_supports[i]-1 ); } // // Calc error means and variances sum_x = vector<float>( _k, 0.); sum_x2 = vector<float>( _k, 0.); float tot_sum_x = 0.0; float tot_sum_x2 = 0.0; for( int i=0; i<coordData.size(); i++ ){ int clusterIdx = FindClusterIdx( coordData[i] ); float err = _key_means[ clusterIdx ] - dataKey[i]; sum_x[ clusterIdx ] += err; sum_x2[ clusterIdx ] += pow( err, 2 ); tot_sum_x += err; tot_sum_x2 += pow( err, 2 ); } _errMean = vector< float >( _k ); _lowerConfBound = vector< float >( _k ); _upperConfBound = vector< float >( _k ); for( int i=0; i< _k; i++ ){ _errMean[i] = sum_x[i]/( float( _key_supports[i] ) ); float errVar = ( sum_x2[i] - (sum_x[i]/float(_key_supports[i])) )/float( _key_supports[i]-1 ); float t_val = TDist( _key_supports[i] ); _lowerConfBound[i] = _errMean[i] - t_val*sqrt( errVar * (1.0+( 1.0/float(_key_supports[i]) )) ); _upperConfBound[i] = _errMean[i] + t_val*sqrt( errVar * (1.0+( 1.0/float(_key_supports[i]) )) ); } // _totalErrMean = tot_sum_x / coordData.size(); float totalErrVar = ( tot_sum_x2 - (tot_sum_x/float(coordData.size())) )/float( coordData.size()-1 ); _totalBoundStub = sqrt( totalErrVar * (1.0+( 1.0/float(coordData.size()) )) ); //_totalLowerConfBound = _totalErrMean - TDist( coordData.size() )*sqrt( totalErrVar * (1.0+( 1.0/float(coordData.size()) )) ); //_totalUpperConfBound = _totalErrMean + TDist( coordData.size() )*sqrt( totalErrVar * (1.0+( 1.0/float(coordData.size()) )) ); // return labels cout << "# Error:\n"; cout << "# Mean Squared Error (MSE) is: " << tot_sum_x2/float(coordData.size() ) << endl; cout << "# Error Mean is : " << _totalErrMean << endl; cout << "# Error Variance is : " << totalErrVar << endl; // return( clusterMap ); }