int main() { using std::cout; using std::locale; using namespace boost; using namespace boost::chrono; #if BOOST_CHRONO_VERSION==2 cout.imbue(locale(locale(), new duration_units_fr<>())); #else cout.imbue(locale(locale(), new duration_punct<char> ( duration_punct<char>::use_long, "secondes", "minutes", "heures", "s", "m", "h" ))); #endif hours h(5); minutes m(45); seconds s(15); milliseconds ms(763); cout << h << ", " << m << ", " << s << " et " << ms << '\n'; cout << hours(0) << ", " << minutes(0) << ", " << s << " et " << ms << '\n'; return 0; }
int main() { using std::cout; using std::locale; using namespace boost; using namespace boost::chrono; cout.imbue(locale(locale(), new duration_punct<char> ( duration_punct<char>::use_long, "secondes", "minutes", "heures", "s", "m", "h" ))); hours h(5); minutes m(45); seconds s(15); milliseconds ms(763); cout << h << ", " << m << ", " << s << " et " << ms << '\n'; }
int test_main(int argc, char *argv[]) { using namespace boost::property_tree; test_xml_parser<ptree>(); test_xml_parser<iptree>(); #ifndef BOOST_NO_CWCHAR using std::locale; // We need a UTF-8-aware global locale now. locale loc(locale(), new utf8_codecvt_facet); locale::global(loc); test_xml_parser<wptree>(); test_xml_parser<wiptree>(); #endif return 0; }
void ReportEntity::save(std::string filepath) { using std::locale; //locale &loc=locale::global(locale(locale(),"",LC_CTYPE)); locale &loc=locale::global(locale("chs", locale::ctype)); std::ofstream fs(filepath, std::ios::out|std::ios::binary); for(ReportHeader::iterator iter = this->m_header.begin(); iter != this->m_header.end(); ++iter) { const char * header_colname = iter->second.c_str(); fs << header_colname; ReportHeader::iterator iter_check = iter; if(++iter_check == this->m_header.end()){ fs << std::endl; }else{ fs << ","; } } for(Content::iterator iter = this->m_content.begin(); iter != this->m_content.end(); ++iter) { ReportRow& row = *iter; for(ReportRow::iterator iter_r = row.begin(); iter_r != row.end(); ++ iter_r) { fs << iter_r->get()->toString(); if(iter_r+1 == row.end()){ fs << std::endl; }else{ fs << ","; } } } locale::global(loc); fs.close(); };
int main(int argc,char *argv[]) { { #ifdef MULTITHREAD_STDLOCALE_WORKAROUND // Note: there's a known threading bug regarding std::locale with MSVC according to // http://connect.microsoft.com/VisualStudio/feedback/details/492128/std-locale-constructor-modifies-global-locale-via-setlocale int iPreviousFlag = ::_configthreadlocale(_ENABLE_PER_THREAD_LOCALE); #endif using std::locale; locale::global(locale(locale::classic(), "", locale::collate | locale::ctype)); #ifdef MULTITHREAD_STDLOCALE_WORKAROUND if (iPreviousFlag > 0 ) ::_configthreadlocale(iPreviousFlag); #endif } TASPlayer::Init(); SetThreadAffinityMask(GetCurrentThread(),1); //printf("%08x",opsize); //AGAIN?! char *t; initArchiveSystem(); if(timeBeginPeriod(1) != TIMERR_NOERROR) { AddLogText("Error setting timer granularity to 1ms.", DO_ADD_NEWLINE); } InitCommonControls(); debugSystem = new DebugSystem(); if(!FCEUI_Initialize()) { do_exit(); return 1; } ApplyDefaultCommandMapping(); fceu_hInstance = GetModuleHandle(0); fceu_hAccel = LoadAccelerators(fceu_hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1)); // Get the base directory GetBaseDirectory(); // load fceux.cfg sprintf(TempArray,"%s\\%s",BaseDirectory.c_str(),cfgFile.c_str()); LoadConfig(TempArray); //initDirectories(); // Parse the commandline arguments t = ParseArgies(argc, argv); int saved_pal_setting = !!pal_emulation; if (ConfigToLoad) { // alternative config file specified cfgFile.assign(ConfigToLoad); // Load the config information sprintf(TempArray,"%s\\%s",BaseDirectory.c_str(),cfgFile.c_str()); LoadConfig(TempArray); } //Bleh, need to find a better place for this. { FCEUI_SetGameGenie(genie!=0); fullscreen = !!fullscreen; soundo = !!soundo; frame_display = !!frame_display; allowUDLR = !!allowUDLR; pauseAfterPlayback = !!pauseAfterPlayback; closeFinishedMovie = !!closeFinishedMovie; EnableBackgroundInput = !!EnableBackgroundInput; KeyboardSetBackgroundAccess(EnableBackgroundInput!=0); JoystickSetBackgroundAccess(EnableBackgroundInput!=0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundquality); FCEUI_SetTriangleVolume(soundTrianglevol); FCEUI_SetSquare1Volume(soundSquare1vol); FCEUI_SetSquare2Volume(soundSquare2vol); FCEUI_SetNoiseVolume(soundNoisevol); FCEUI_SetPCMVolume(soundPCMvol); } //Since a game doesn't have to be loaded before the GUI can be used, make //sure the temporary input type variables are set. ParseGIInput(NULL); // Initialize default directories CreateDirs(); SetDirs(); DoVideoConfigFix(); DoTimingConfigFix(); if(eoptions & EO_CPALETTE) { FCEUI_SetPaletteArray(cpalette); } if(!t) { fullscreen=0; } CreateMainWindow(); // Do single instance coding, since we now know if the user wants it, // and we have a source window to send from // http://wiki.github.com/ffi/ffi/windows-examples if (SingleInstanceOnly) { // Checks window names / hWnds, decides if there's going to be a conflict. EnumDesktopWindows(NULL, EnumCallbackFCEUXInstantiated, (LPARAM)0); if (DoInstantiatedExit) { if(t) { COPYDATASTRUCT cData; DATA tData; sprintf(tData.strFilePath,"%s",t); cData.dwData = 1; cData.cbData = sizeof ( tData ); cData.lpData = &tData; SendMessage(DoInstantiatedExitWindow,WM_COPYDATA,(WPARAM)(HWND)hAppWnd, (LPARAM)(LPVOID) &cData); do_exit(); return 0; } } } if(!InitDInput()) { do_exit(); return 1; } if(!DriverInitialize()) { do_exit(); return 1; } InitSpeedThrottle(); if (t) { ALoad(t); } else { if (AutoResumePlay && romNameWhenClosingEmulator && romNameWhenClosingEmulator[0]) ALoad(romNameWhenClosingEmulator, 0, true); if (eoptions & EO_FOAFTERSTART) LoadNewGamey(hAppWnd, 0); } if (pal_setting_specified) { // Force the PAL setting specified in the command line pal_emulation = saved_pal_setting; FCEUI_SetVidSystem(pal_emulation); } if(PaletteToLoad) { SetPalette(PaletteToLoad); free(PaletteToLoad); PaletteToLoad = NULL; } if(GameInfo && MovieToLoad) { //switch to readonly mode if the file is an archive if(FCEU_isFileInArchive(MovieToLoad)) replayReadOnlySetting = true; FCEUI_LoadMovie(MovieToLoad, replayReadOnlySetting, replayStopFrameSetting != 0); FCEUX_LoadMovieExtras(MovieToLoad); free(MovieToLoad); MovieToLoad = NULL; } if(GameInfo && StateToLoad) { FCEUI_LoadState(StateToLoad); free(StateToLoad); StateToLoad = NULL; } if(GameInfo && LuaToLoad) { FCEU_LoadLuaCode(LuaToLoad); free(LuaToLoad); LuaToLoad = NULL; } //Initiates AVI capture mode, will set up proper settings, and close FCUEX once capturing is finished if(AVICapture && AviToLoad) //Must be used in conjunction with AviToLoad { //We want to disable flags that will pause the emulator PauseAfterLoad = 0; pauseAfterPlayback = 0; KillFCEUXonFrame = AVICapture; } if(AviToLoad) { FCEUI_AviBegin(AviToLoad); free(AviToLoad); AviToLoad = NULL; } TASPlayer::Init_Loaded(); if (MemWatchLoadOnStart) CreateMemWatch(); if (PauseAfterLoad) FCEUI_ToggleEmulationPause(); SetAutoFirePattern(AFon, AFoff); UpdateCheckedMenuItems(); doloopy: UpdateFCEUWindow(); if(GameInfo) { while(GameInfo) { uint8 *gfx=0; ///contains framebuffer int32 *sound=0; ///contains sound data buffer int32 ssize=0; ///contains sound samples count if (turbo) { if (!frameSkipCounter) { frameSkipCounter = frameSkipAmt; skippy = 0; } else { frameSkipCounter--; if (muteTurbo) skippy = 2; //If mute turbo is on, we want to bypass sound too, so set it to 2 else skippy = 1; //Else set it to 1 to just frameskip } } else skippy = 0; TASPlayer::Run(&gfx, &sound, &ssize, skippy); //FCEUI_Emulate(&gfx, &sound, &ssize, skippy); //emulate a single frame -- THIS IS NOW HANDLED BY TASPLAYER //FCEUD_Update(gfx, sound, ssize); //update displays and debug tools -- THIS IS NOW HANDLED BY TASPLAYER //mbg 6/30/06 - close game if we were commanded to by calls nested in FCEUI_Emulate() if (closeGame) { FCEUI_CloseGame(); GameInfo = NULL; } } //xbsave = NULL; RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); } else UpdateRawInputAndHotkeys(); if(!TASPlayer::SimulMode) { Sleep(50); } if(!exiting) goto doloopy; DriverKill(); timeEndPeriod(1); FCEUI_Kill(); delete debugSystem; return(0); }
int RP_C_API main(int argc, char *argv[]) { #ifdef _WIN32 // Set Win32 security options. secoptions_init(); #endif /* _WIN32 */ // Set the C and C++ locales. locale::global(locale("")); #if defined(_MSC_VER) && defined(ENABLE_NLS) // Delay load verification. // TODO: Only if linked with /DELAYLOAD? if (DelayLoad_test_textdomain() != 0) { // Delay load failed. // TODO: Use a CMake macro for the soversion? #define LIBGNUINTL_DLL "libgnuintl-8.dll" fputs("*** ERROR: " LIBGNUINTL_DLL " could not be loaded.\n\n" "This build of rom-properties has localization enabled,\n" "which requires the use of GNU gettext.\n\n" "Please redownload rom-properties and copy the\n" LIBGNUINTL_DLL " file to the installation directory.\n", stderr); return EXIT_FAILURE; } #endif /* defined(_MSC_VER) && defined(ENABLE_NLS) */ // Initialize i18n. rp_i18n_init(); if(argc < 2){ #ifdef ENABLE_DECRYPTION cerr << C_("rpcli", "Usage: rpcli [-k] [-c] [-j] [[-x[b]N outfile]... [-a apngoutfile] filename]...") << endl; cerr << " -k: " << C_("rpcli", "Verify encryption keys in keys.conf.") << endl; #else /* !ENABLE_DECRYPTION */ cerr << C_("rpcli", "Usage: rpcli [-j] [[-x[b]N outfile]... [-a apngoutfile] filename]...") << endl; #endif /* ENABLE_DECRYPTION */ cerr << " -c: " << C_("rpcli", "Print system region information.") << endl; cerr << " -j: " << C_("rpcli", "Use JSON output format.") << endl; cerr << " -xN: " << C_("rpcli", "Extract image N to outfile in PNG format.") << endl; cerr << " -a: " << C_("rpcli", "Extract the animated icon to outfile in APNG format.") << endl; cerr << endl; cerr << C_("rpcli", "Examples:") << endl; cerr << "* rpcli s3.gen" << endl; cerr << "\t " << C_("rpcli", "displays info about s3.gen") << endl; cerr << "* rpcli -x0 icon.png pokeb2.nds" << endl; cerr << "\t " << C_("rpcli", "extracts icon from pokeb2.nds") << endl; } assert(RomData::IMG_INT_MIN == 0); // DoFile parameters bool json = false; vector<ExtractParam> extract; for (int i = 1; i < argc; i++) { // figure out the json mode in advance if (argv[i][0] == '-' && argv[i][1] == 'j') { json = true; } } if (json) cout << "[\n"; bool first = true; int ret = 0; for(int i=1;i<argc;i++){ if(argv[i][0] == '-'){ switch (argv[i][1]) { #ifdef ENABLE_DECRYPTION case 'k': { // Verify encryption keys. static bool hasVerifiedKeys = false; if (!hasVerifiedKeys) { hasVerifiedKeys = true; ret = VerifyKeys(); } break; } #endif /* ENABLE_DECRYPTION */ case 'c': { // Print the system region information. PrintSystemRegion(); break; } case 'x': { ExtractParam ep; long num = atol(argv[i] + 2); if (num<RomData::IMG_INT_MIN || num>RomData::IMG_INT_MAX) { cerr << rp_sprintf(C_("rpcli", "Warning: skipping unknown image type %ld"), num) << endl; i++; continue; } ep.image_type = num; ep.filename = argv[++i]; extract.push_back(ep); break; } case 'a': { ExtractParam ep; ep.image_type = -1; ep.filename = argv[++i]; extract.push_back(ep); break; } case 'j': // do nothing break; default: cerr << rp_sprintf(C_("rpcli", "Warning: skipping unknown switch '%c'"), argv[i][1]) << endl; break; } } else{ if (first) first = false; else if (json) cout << "," << endl; DoFile(argv[i], json, extract); extract.clear(); } } if (json) cout << "]\n"; return ret; }
int main () { std::cout << "Nonfinite_num_facet very simple example." << std::endl; if((std::numeric_limits<double>::has_infinity == 0) || (std::numeric_limits<double>::infinity() == 0)) { std::cout << "Infinity not supported on this platform." << std::endl; return 0; } if((std::numeric_limits<double>::has_quiet_NaN == 0) || (std::numeric_limits<double>::quiet_NaN() == 0)) { std::cout << "NaN not supported on this platform." << std::endl; return 0; } std::locale default_locale (std::locale::classic ()); // Note the currrent (default C) locale. // Create plus and minus infinity. double plus_infinity = +std::numeric_limits<double>::infinity(); double minus_infinity = -std::numeric_limits<double>::infinity(); // and create a NaN (NotANumber) double NaN = +std::numeric_limits<double>::quiet_NaN (); double negated_NaN = (boost::math::changesign)(std::numeric_limits<double>::quiet_NaN ()); // Output the nonfinite values using the current (default C) locale. // The default representations differ from system to system, // for example, using Microsoft compilers, 1.#INF, -1.#INF, and 1.#QNAN. cout << "Using C locale" << endl; cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl; cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl; cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl; // Display negated NaN. cout << "negated NaN " << negated_NaN << endl; // "-1.IND" // Create a new output locale, and add the nonfinite_num_put facet std::locale C99_out_locale (default_locale, new boost::math::nonfinite_num_put<char>); // and imbue the cout stream with the new locale. cout.imbue (C99_out_locale); // Or for the same effect more concisely: cout.imbue (locale(locale(), new boost::math::nonfinite_num_put<char>)); // Output using the new locale cout << "Using C99_out_locale " << endl; cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl; cout << "-std::numeric_limits<double>::infinity() = " << minus_infinity << endl; cout << "+std::numeric_limits<double>::quiet_NaN () = " << NaN << endl; // Display negated NaN. cout << "negated NaN " << negated_NaN << endl; // -nan // Create a string with the expected C99 representation of plus infinity. std::string inf = "inf"; { // Try to read an infinity value using the default C locale. // Create an input stream which will provide "inf" std::istringstream iss (inf); // Create a double ready to take the input, double infinity; // and read "inf" from the stringstream: iss >> infinity; // This will not work on all platforms! if (! iss) { // Reading infinity went wrong! std::cerr << "C locale input format error!" << std::endl; } } // Using default C locale. { // Now retry using C99 facets. // Create a new input locale and add the nonfinite_num_get facet. std::locale C99_in_locale (default_locale, new boost::math::nonfinite_num_get<char>); // Create an input stream which will provide "inf". std::istringstream iss (inf); // Imbue the stream with the C99 input locale. iss.imbue (C99_in_locale); // Create a double ready to take the input, double infinity; // and read from the stringstream: iss >> infinity; if (! iss) { // Reading infinity went wrong! std::cout << "C99 input format error!" << std::endl; } // Expect to get an infinity, which will display still using the C99 locale as "inf" cout << "infinity in C99 representation is " << infinity << endl; // To check, we can switch back to the default C locale. cout.imbue (default_locale); cout << "infinity in default C representation is " << infinity << endl; } // using C99 locale. { // A 'loop-back example, output to a stringstream, and reading it back in. // Create C99 input and output locales. std::locale C99_out_locale (default_locale, new boost::math::nonfinite_num_put<char>); std::locale C99_in_locale (default_locale, new boost::math::nonfinite_num_get<char>); std::ostringstream oss; oss.imbue(C99_out_locale); oss << plus_infinity; std::istringstream iss(oss.str()); // So stream contains "inf". iss.imbue (C99_in_locale); std::string s; iss >> s; cout.imbue(C99_out_locale); if (oss.str() != s) { cout << plus_infinity << " != " << s << " loopback failed!" << endl; } else { cout << plus_infinity << " == " << s << " as expected." << endl; } } // Example varying the width and position of the nonfinite representations. // With the nonfinite_num_put and _get facets, the width of the output is constant. #ifdef BOOST_NO_CXX11_NUMERIC_LIMITS cout << "BOOST_NO_CXX11_NUMERIC_LIMITS is defined, so no max_digits10 available." << endl; std::streamsize max_digits10 = 2 + std::numeric_limits<double>::digits * 30103UL / 100000UL; #else // Can use new C++0X max_digits10 (the maximum potentially significant digits). std::streamsize max_digits10 = std::numeric_limits<double>::max_digits10; #endif cout << "std::numeric_limits<double>::max_digits10 is " << max_digits10 << endl; cout.precision(max_digits10); double pi = 3.141592653589793238462643383279502884197169399375105820974944; // Expect 17 (probably) decimal digits (regardless of locale). // cout has the default locale. cout << "pi = " << pi << endl; // pi = 3.1415926535897931 cout.imbue (C99_out_locale); // Use cout with the C99 locale // (expect the same output for a double). cout << "pi = " << pi << endl; // pi = 3.1415926535897931 cout << "infinity in C99 representation is " << plus_infinity << endl; //int width = 2; // Check effect if width too small is OK. // (There was a disturbed layout on older MSVC?). int width = 20; // Similarly if we can switch back to the default C locale. cout.imbue (default_locale); cout << "infinity in default C representation is " << plus_infinity << endl; cout << "infinity in default C representation (setw(" << width << ") is |" << setw(width) << plus_infinity <<'|' << endl; cout << "infinity in default C representation (setw(" << width << ") is |" << left << setw(width) << plus_infinity <<'|' << endl; cout << "infinity in default C representation (setw(" << width << ") is |" << internal << setw(width) << plus_infinity <<'|' << endl; cout.imbue (C99_out_locale); cout << "infinity in C99 representation (setw(" << width << ") is |" << right << setw(width) << plus_infinity <<'|'<< endl; cout << "infinity in C99 representation (setw(" << width << ") is |" << left << setw(width) << plus_infinity <<'|'<< endl; cout << "infinity in C99 representation (setw(" << width << ") is |" << internal << setw(width) << plus_infinity <<'|'<< endl; return 0; } // int main()