void StdStringTestCase::StdConversion() { std::string strStd("std::string value"); wxStdWideString strStdWide(L"std::wstring value"); wxString s1(strStd); CPPUNIT_ASSERT_EQUAL( "std::string value", s1 ); wxString s2(strStdWide); CPPUNIT_ASSERT_EQUAL( "std::wstring value", s2 ); wxString s3; s3 = strStd; CPPUNIT_ASSERT_EQUAL( "std::string value", s3 ); s3 = strStdWide; CPPUNIT_ASSERT_EQUAL( "std::wstring value", s3 ); wxString s4("hello"); // wxString -> std::string conversion is only available in wxUSE_STL case, // because it conflicts with conversion to const char*/wchar_t*: #if wxUSE_STL std::string s5 = s4; CPPUNIT_ASSERT_EQUAL( "hello", s5 ); wxStdWideString s6 = s4; CPPUNIT_ASSERT_EQUAL( "hello", s6 ); #endif std::string s7(s4); CPPUNIT_ASSERT( s7 == "hello" ); wxStdWideString s8(s4); CPPUNIT_ASSERT( s8 == "hello" ); }
std::string ImageRecordingConfiguration::getFullRecordingPathString() { CString fullPath = getFullRecordingPath(); CT2CA pszConvertedAnsiString(fullPath); std::string strStd(pszConvertedAnsiString); return strStd; }
string sConnector::ToString() { CT2CA pszConvertedAnsiString (text); std::string strStd (pszConvertedAnsiString); return name + "," + ltos(lineType) + "," + ltos(lineThickness) + "," + ltos(lineColor) + "," + strStd //formatted text + "," + ltos(start.x) + "," + ltos(start.y) + "," + ltos(end.x) + "," + ltos(end.y) + "\n"; }
void StdStringTestCase::StdConversion() { std::string strStd("std::string value"); wxStdWideString strStdWide(L"std::wstring value"); wxString s1(strStd); CPPUNIT_ASSERT_EQUAL( "std::string value", s1 ); wxString s2(strStdWide); CPPUNIT_ASSERT_EQUAL( "std::wstring value", s2 ); wxString s3; s3 = strStd; CPPUNIT_ASSERT_EQUAL( "std::string value", s3 ); s3 = strStdWide; CPPUNIT_ASSERT_EQUAL( "std::wstring value", s3 ); wxString s4("hello"); // notice that implicit wxString -> std::string conversion is only // available in wxUSE_STL case, because it conflicts with conversion to // const char*/wchar_t* #if wxUSE_STL && wxUSE_UNSAFE_WXSTRING_CONV std::string s5 = s4; #else std::string s5 = s4.ToStdString(); #endif CPPUNIT_ASSERT_EQUAL( "hello", s5 ); #if wxUSE_STL wxStdWideString s6 = s4; #else wxStdWideString s6 = s4.ToStdWstring(); #endif CPPUNIT_ASSERT_EQUAL( "hello", s6 ); #if wxUSE_UNSAFE_WXSTRING_CONV std::string s7(s4); CPPUNIT_ASSERT( s7 == "hello" ); #endif wxStdWideString s8(s4); CPPUNIT_ASSERT( s8 == "hello" ); std::string s9("\xF0\x9F\x90\xB1\0\xE7\x8C\xAB", 9); /* U+1F431 U+0000 U+732B */ wxString s10 = wxString::FromUTF8(s9); CPPUNIT_ASSERT_EQUAL( s9, s10.ToStdString(wxConvUTF8) ); std::string s11("xyz\0\xFF", 5); /* an invalid UTF-8 sequence */ CPPUNIT_ASSERT_EQUAL( wxString::FromUTF8(s11), "" ); }
bool PT_Network::ReadGTFFiles(GDRect network_rect) // Google Transit files { // // step 1: read route files string str0 = m_ProjectDirectory +"routes.txt"; //string str = "h:/routes.csv"; CT2CA pszConvertedAnsiString (str0.c_str()); // construct a std::string using the LPCSTR input std::string strStd (pszConvertedAnsiString); CCSVParser parser; if (parser.OpenCSVFile(strStd)) { // AfxMessageBox("Start reading Google Transit Feed files...", MB_ICONINFORMATION); int count =0; PT_Route route; while(parser.ReadRecord()) { if(parser.GetValueByFieldName("route_id",route.route_id ) == false) break; if(parser.GetValueByFieldName("route_long_name",route.route_long_name) == false) route.route_long_name=""; if(parser.GetValueByFieldName("route_short_name",route.route_short_name) == false) route.route_short_name=""; if(parser.GetValueByFieldName("route_url",route.route_url) == false) route.route_url=""; if(parser.GetValueByFieldName("route_type",route.route_type) == false) route.route_type=""; // make sure there is not duplicated key // If the requested key is not found, find() returns the end iterator for //the container, so: if(m_PT_RouteMap.find(route.route_id) == m_PT_RouteMap.end() ) { m_PT_RouteMap[route.route_id] = route; } else { AfxMessageBox("Duplicated Route ID!"); } count++; } parser.CloseCSVFile (); CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd(); pMainFrame->m_bShowLayerMap[layer_transit] = true; }else { return false; } CString missing_stops_message; // step 1: read stop information string str2 = m_ProjectDirectory +"stops.txt"; CT2CA pszConvertedAnsiString2 (str2.c_str()); // construct a std::string using the LPCSTR input std::string strStd2 (pszConvertedAnsiString2); if (parser.OpenCSVFile(strStd2)) { int count =0; while(parser.ReadRecord()) { PT_Stop stop; if(parser.GetValueByFieldName("stop_id",stop.stop_id ) == false) break; bool NonnegativeFlag = false; if(parser.GetValueByFieldName("stop_lat",stop.m_ShapePoint.y, NonnegativeFlag) == false) break; if(parser.GetValueByFieldName("stop_lon",stop.m_ShapePoint.x , NonnegativeFlag) == false) break; if(parser.GetValueByFieldName("direction",stop.direction ) == false) stop.direction=""; if(parser.GetValueByFieldName("location_type",stop.location_type) == false) stop.location_type=0; if(parser.GetValueByFieldName("position",stop.position ) == false) stop.position=""; if(parser.GetValueByFieldName("stop_code",stop.stop_code ) == false) stop.stop_code=0; parser.GetValueByFieldName("stop_desc",stop.stop_desc); if(parser.GetValueByFieldName("stop_name",stop.stop_name) == false) stop.stop_name=""; if(parser.GetValueByFieldName("zone_id",stop.zone_id) == false) stop.zone_id=0; if(m_PT_StopMap.find(stop.stop_id) == m_PT_StopMap.end()) { m_PT_StopMap[stop.stop_id] = stop; }else { CString msg; msg.Format("Duplicated Stop ID %d", stop.stop_id); AfxMessageBox(msg); } count++; } parser.CloseCSVFile (); } //read trip file string str3 = m_ProjectDirectory +"trips.txt"; CT2CA pszConvertedAnsiString3 (str3.c_str()); // construct a std::string using the LPCSTR input std::string strStd3 (pszConvertedAnsiString3); if (parser.OpenCSVFile(strStd3)) { int count =0; while(parser.ReadRecord()) { PT_Trip trip; if(parser.GetValueByFieldName("trip_id",trip.trip_id) == false) break; if(parser.GetValueByFieldName("route_id",trip.route_id) == false) break; if(parser.GetValueByFieldName("service_id",trip.service_id) == false) break; if(parser.GetValueByFieldName("block_id",trip.block_id) == false) trip.block_id=0; if(parser.GetValueByFieldName("direction_id",trip.direction_id) == false) trip.direction_id=0; if(parser.GetValueByFieldName("shape_id",trip.shape_id) == false) trip.shape_id=0; if(parser.GetValueByFieldName("trip_type",trip.trip_type) == false) trip.trip_type=0; if(m_PT_TripMap.find(trip.trip_id) == m_PT_TripMap.end()) { m_PT_TripMap[trip.trip_id] = trip; }else { AfxMessageBox("Duplicated Trip ID!"); } count++; } parser.CloseCSVFile (); } // read stop_times.txt int stop_times_count =0; int max_stop_times_record = 1000; string str4 = m_ProjectDirectory +"stop_times.txt"; CT2CA pszConvertedAnsiString4 (str4.c_str()); // construct a std::string using the LPCSTR input std::string strStd4 (pszConvertedAnsiString4); if (parser.OpenCSVFile(strStd4)) { while(parser.ReadRecord()) { PT_StopTime TransitStopTime; if(parser.GetValueByFieldName("stop_id",TransitStopTime.stop_id) == false) break; string time_string; char char_array[20]; if(parser.GetValueByFieldName("arrival_time",time_string) == false) break; int hour,min,second; sprintf(char_array,"%s",time_string.c_str ()); sscanf(char_array,"%d:%d:%d", &hour,&min,&second); TransitStopTime.arrival_time = hour*60+min; if(parser.GetValueByFieldName("departure_time",time_string) == false) break; sprintf(char_array,"%s",time_string.c_str ()); sscanf(char_array,"%d:%d:%d", &hour,&min,&second); TransitStopTime.departure_time = hour*60+min; if(parser.GetValueByFieldName("trip_id",TransitStopTime.trip_id) == false) break; if(parser.GetValueByFieldName("stop_sequence",TransitStopTime.stop_sequence) == false) break; /* if(parser.GetValueByFieldName("drop_off_type",TransitStopTime.drop_off_type) == false) TransitStopTime.drop_off_type=0; if(parser.GetValueByFieldName("pickup_type",TransitStopTime.pickup_type) == false) TransitStopTime.pickup_type=0; if(parser.GetValueByFieldName("shape_dist_traveled",TransitStopTime.shape_dist_traveled) == false) TransitStopTime.shape_dist_traveled=0; if(parser.GetValueByFieldName("stop_headsign",TransitStopTime.stop_headsign) == false) TransitStopTime.stop_headsign=0; if(parser.GetValueByFieldName("timepoint",TransitStopTime.timepoint) == false) TransitStopTime.timepoint=0;*/ if(m_PT_StopMap.find(TransitStopTime.stop_id)!= m_PT_StopMap.end()) { TransitStopTime.pt.x = m_PT_StopMap[TransitStopTime.stop_id].m_ShapePoint .x ; TransitStopTime.pt.y = m_PT_StopMap[TransitStopTime.stop_id].m_ShapePoint .y ; }else { if(missing_stops_message.GetLength ()<1000) { CString msg; msg.Format ("Mising stop %d\n",TransitStopTime.stop_id); missing_stops_message+=msg; } } // m_PT_StopTimeVector.push_back(TransitStopTime) ; stop_times_count++; //if(stop_times_count >=max_stop_times_record) // for testing purposes // break; if(m_PT_TripMap.find(TransitStopTime.trip_id) != m_PT_TripMap.end()) { m_PT_TripMap[TransitStopTime.trip_id].m_PT_StopTimeVector .push_back(TransitStopTime); } } parser.CloseCSVFile (); } CString message; int trip_size = m_PT_TripMap.size(); int stop_size = m_PT_StopMap.size(); int stop_time_size = stop_times_count; message.Format("%d transit trips, %d stops and %d stop time records are loaded.", trip_size, stop_size, stop_time_size); AfxMessageBox(message, MB_ICONINFORMATION); if(missing_stops_message.GetLength ()>0) { AfxMessageBox(missing_stops_message); } /* //read transfer file string str6 = m_ProjectDirectory +"transfers.txt"; CT2CA pszConvertedAnsiString6 (str6.c_str()); // construct a std::string using the LPCSTR input std::string strStd6 (pszConvertedAnsiString6); if (parser.OpenCSVFile(strStd6)) { int count =0; while(parser.ReadRecord()) { PT_transfers transfers; if(parser.GetValueByFieldName("from_stop_id",transfers.from_stop_id) == false) break; if(parser.GetValueByFieldName("to_stop_id",transfers.to_stop_id) == false) break; if(parser.GetValueByFieldName("transfer_type",transfers.transfer_type) == false) break; m_PT_transfers.push_back(transfers) ; count++; } parser.CloseCSVFile (); } */ // map matching return true; }
void CSQLiteConversion::SqliteStatementExecution(std::vector<CString> &statements, sqlite3 *&sqlitedatabase, int rc , wxGauge *&gauge, unsigned &nValue, wxTextCtrl *&PrgDlg, unsigned &nErrorCount, CString *sTableNames, unsigned &flag, unsigned &nTableCount, int *IndexTable, CString *sTableNames2) { char *zErrMsg = 0; unsigned index = 0; auto end_it = statements.end(); for( auto it = statements.begin(); it != end_it; ++it ) { ++nValue; gauge ->SetValue(nValue); std::string sB = ConvertToUTF8(*it); const char* pszC = _strdup(sB.c_str()); rc = sqlite3_exec(sqlitedatabase, pszC, NULL, 0, &zErrMsg); if( rc != SQLITE_OK ) { ++nErrorCount; PrgDlg->SetDefaultStyle(wxTextAttr (wxNullColour, *wxRED)); wxString ErrorMessage = wxT(""); ErrorMessage += wxString::FromUTF8(zErrMsg); ErrorMessage += " \n"; PrgDlg->WriteText(ErrorMessage); CT2CA pszConvertedAnsiString (*it); std::string strStd (pszConvertedAnsiString); ErrorMessage = wxString::FromUTF8(_strdup(strStd.c_str() ) ) + "\n"; PrgDlg->WriteText(ErrorMessage); if(flag & 1) { ErrorMessage = wxT("Table: "); sB = ConvertToUTF8(sTableNames[nValue-1]); ErrorMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); ErrorMessage += wxT(" wasnt created succesfully \n"); PrgDlg->WriteText(ErrorMessage); } PrgDlg->SetDefaultStyle(wxTextAttr (wxNullColour)); sqlite3_free(zErrMsg); } else { if(flag & ExecuteTables) { wxString sMessage = wxT("Table: "); sB = ConvertToUTF8(sTableNames[nValue-1]); sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); sMessage += wxT(" created succesfully \n"); PrgDlg->WriteText(sMessage); } else if(flag & ExecuteInserts) { if(*it == "END TRANSACTION") { sTableNames[index]; wxString sMessage = wxT("Table: "); sB = ConvertToUTF8(sTableNames[index]); sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); sMessage += wxT(" records inserted \n"); ++index; PrgDlg->WriteText(sMessage); } } else if(flag & ExecuteIndexes) { if( index < nTableCount ) { while( !IndexTable[index] ) { wxString sMessage = wxT("indexes of table: "); sB = ConvertToUTF8(sTableNames2[index]); sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); sMessage += wxT(" created \n"); PrgDlg->WriteText(sMessage); ++index; } } IndexTable[index]--; if( index < nTableCount ) { if( !IndexTable[index] ) { wxString sMessage = wxT("indexes of table: "); sB = ConvertToUTF8(sTableNames2[index]); sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); sMessage += wxT(" created \n"); PrgDlg->WriteText(sMessage); ++index; } } if(index < nTableCount ) { while( !IndexTable[index] ) { wxString sMessage = wxT("indexes of table: "); sB = ConvertToUTF8(sTableNames2[index]); sMessage += wxString::FromUTF8(_strdup(sB.c_str() ) ); sMessage += wxT(" created \n"); PrgDlg->WriteText(sMessage); ++index; } } } } } }
std::string ImageRecordingConfiguration::getFilePath() { CT2CA pszConvertedAnsiString(m_outputFolder); std::string strStd(pszConvertedAnsiString); return strStd; }
std::string ImageRecordingConfiguration::getFileNameString() { CT2CA pszConvertedAnsiString(m_fileName); std::string strStd(pszConvertedAnsiString); return strStd; }