//------------------------------------------------------------------------------------------------- inline void_t File::reopen( std::ctstring_t &a_filePath, const ExOpenMode &a_mode, cbool_t &a_isUseBuffering ) { xTEST_EQ(a_filePath.empty(), false); xTEST_NA(a_mode); xTEST_NA(a_isUseBuffering); // create dir Dir( Path(a_filePath).dir() ).pathCreate(); // create, reopen file { std::FILE *file = xTFREOPEN(a_filePath.c_str(), _openMode(a_mode).c_str(), get()); xTEST_PTR(file); _handle = file; _filePath = a_filePath; } // buffering if (!a_isUseBuffering) { setVBuff(xPTR_NULL, bmNo, 0); } else { setVBuff(xPTR_NULL, bmFull, BUFSIZ); } }
//------------------------------------------------------------------------------------------------- inline void_t File::readLine( std::tstring_t *a_str, std::csize_t &a_maxCount ) const { xTEST_PTR(a_str); xTEST_NA(a_maxCount); std::tstring_t str; str.resize(a_maxCount + 1); // + 1 for 0 tchar_t *pszRv = xTFGETS(&str.at(0), static_cast<int_t>( str.size() ), get()); xTEST_PTR(pszRv); // trim xPTR_NULL's from string, remove EOL str = String::removeEol( str.c_str() ); // out a_str->swap(str); }
//------------------------------------------------------------------------------------------------- inline void_t Locale::setCurrent( std::ctstring_t &a_locale ) const { xTEST_NA(a_locale); ctchar_t *locale = a_locale.empty() ? xPTR_NULL : a_locale.c_str(); ctchar_t *pcszRv = xTSETLOCALE(LC_ALL, locale); xTEST_PTR(pcszRv); }
//------------------------------------------------------------------------------------------------- inline int_t File::writeV( ctchar_t *a_format, va_list a_args ) const { xTEST_PTR(a_format); xTEST_NA(a_args); int_t iRv = xTVFPRINTF(get(), a_format, a_args); xTEST_LESS(- 1, iRv); return iRv; }
//------------------------------------------------------------------------------------------------- inline size_t File::write( cvoid_t *a_buff, std::csize_t &a_count ) const { xTEST_PTR(a_buff); xTEST_NA(a_count); size_t uiRv = std::fwrite(a_buff, 1, a_count, get()); xTEST_EQ(uiRv, a_count); return uiRv; }
//------------------------------------------------------------------------------------------------- inline size_t File::read( void_t *a_buff, std::csize_t &a_count ) const { xTEST_PTR(a_buff); xTEST_NA(a_count); size_t uiRv = std::fread(a_buff, 1, a_count, get()); xTEST_GR_EQ(a_count, uiRv); return uiRv; }
//------------------------------------------------------------------------------------------------- inline int_t File::write( ctchar_t *a_format, ... ) const { xTEST_PTR(a_format); va_list args; xVA_START(args, a_format); int_t iRv = xTVFPRINTF(get(), a_format, args); xTEST_LESS(- 1, iRv); xVA_END(args); return iRv; }
//------------------------------------------------------------------------------------------------- inline void_t File::read( std::tstring_t *a_buff ) const { xTEST_PTR(a_buff); clonglong_t fileSize = size(); xTEST_DIFF(static_cast<longlong_t>( ppError ), fileSize); (*a_buff).clear(); (*a_buff).resize( static_cast<size_t>( fileSize) ); xCHECK_DO(fileSize == 0LL, return); size_t uiRv = std::fread(&a_buff->at(0), 1, a_buff->size() * sizeof(std::tstring_t::value_type), get()); xTEST_EQ(uiRv, a_buff->size()); }
//------------------------------------------------------------------------------------------------- inline void_t Console::prompt( std::ctstring_t &a_prompt, cbool_t &a_isVisible, std::tstring_t *a_answer ) const { #if xENV_WIN xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL); xTEST_EQ(_stdIn.isValid(), true); xTEST_EQ(_stdOut.isValid(), true); #endif xTEST_EQ(a_prompt.empty(), false); xTEST_PTR(a_answer); for ( ; ; ) { write(a_prompt + xT(": ")); for ( ; ; ) { ctchar_t letter = static_cast<tchar_t>( std::tcin.get() ); // asterisks xCHECK_DO(a_isVisible, write(xT("*"))); // ENTER xCHECK_DO(letter == 10, break); // BACKSPACE xCHECK_DO(letter == 0x8, a_answer->clear(); continue); a_answer->push_back(letter); } writeLine(Const::strEmpty()); xCHECK_DO(a_answer->empty(), continue); break; } }
//------------------------------------------------------------------------------------------------- inline void_t Process::create( std::ctstring_t &a_filePath, ctchar_t *a_params, ... ) { xTEST_EQ(a_filePath.empty(), false); xTEST_EQ(File::isExists(a_filePath), true); xTEST_PTR(a_params); std::tstring_t cmdLine; va_list args; xVA_START(args, a_params); cmdLine = String::formatV(a_params, args); xVA_END(args); // xTRACEV(xT("cmdLine: %s"), cmdLine.c_str()); _create_impl(a_filePath, cmdLine); }
//------------------------------------------------------------------------------------------------- inline void_t Config::_read( std::ctstring_t &a_key, std::ctstring_t &a_defaultValue, std::tstring_t *a_value ) { xTEST_NA(a_key); xTEST_NA(a_defaultValue); xTEST_PTR(a_value); // read from file File::textRead(path(), _separator, &_config); // read to std::map_tstring_t std::map_tstring_t::const_iterator it = _config.find(a_key); if (it == _config.end()) { _write(a_key, a_defaultValue); *a_value = a_defaultValue; } else { *a_value = it->second; } }