//------------------------------------------------------------------------------------------------- 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 Config::keyWriteFloat( std::ctstring_t &a_key, cdouble_t &a_value ) { xTEST_NA(a_key); xTEST_NA(a_value); keyWriteString(a_key, String::cast(a_value)); }
//------------------------------------------------------------------------------------------------- inline double Config::keyReadFloat( std::ctstring_t &a_key, cdouble_t &a_defaultValue ) { xTEST_NA(a_key); xTEST_NA(a_defaultValue); return String::cast<double>( keyReadString(a_key, String::cast(a_defaultValue)) ); }
//------------------------------------------------------------------------------------------------- inline long_t Config::keyReadInt( std::ctstring_t &a_key, clong_t &a_defaultValue ) { xTEST_NA(a_key); xTEST_NA(a_defaultValue); return String::cast<long_t>( keyReadString(a_key, String::cast(a_defaultValue)) ); }
//------------------------------------------------------------------------------------------------- inline void_t File::setPosition( clong_t &a_offset, const ExPointerPosition &a_pos ) const { xTEST_NA(a_offset); xTEST_NA(a_pos); int_t iRv = std::fseek(get(), a_offset, a_pos); xTEST_DIFF(iRv, - 1); }
//------------------------------------------------------------------------------------------------- inline void_t File::setVBuff( char *a_buff, const ExBufferingMode &a_mode, std::csize_t &a_size ) const { xTEST_NA(a_buff); xTEST_NA(a_mode); xTEST_NA(a_size); int_t iRv = std::setvbuf(get(), a_buff, a_mode, a_size); xTEST_DIFF(iRv, - 1); }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyWriteBool( std::ctstring_t &a_key, cbool_t &a_value ) { xTEST_NA(a_key); xTEST_NA(a_value); std::tstring_t value; value = String::castBool(a_value); keyWriteString(a_key, value); }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyWriteBin( std::ctstring_t &a_key, std::custring_t &a_value ) { xTEST_NA(a_key); xTEST_NA(a_value); // value (std::ustring_t) -> hexStr (std::tstring_t) std::tstring_t hexStr; hexStr = String::cast( std::tstring_t(a_value.begin(), a_value.end()), 16); keyWriteString(a_key, hexStr); }
//------------------------------------------------------------------------------------------------- inline bool_t Config::keyReadBool( std::ctstring_t &a_key, cbool_t &a_defaultValue ) { xTEST_NA(a_key); xTEST_NA(a_defaultValue); std::tstring_t str; str = keyReadString(a_key, String::castBool(a_defaultValue)); bool_t bRv = String::castBool(str); return bRv; }
//------------------------------------------------------------------------------------------------- inline bool_t File::isError() const { bool_t bRv = xINT_TO_BOOL( std::ferror(get()) ); xTEST_NA(bRv); return bRv; }
//------------------------------------------------------------------------------------------------- inline void_t Config::createDefault( std::ctstring_t &a_content ) const { xTEST_NA(a_content); File::textWrite(path(), a_content, File::omWrite); }
//------------------------------------------------------------------------------------------------- inline void_t File::locking( const ExLockingMode &a_mode, clong_t &a_bytes ) { xTEST_NA(a_mode); xTEST_NA(a_bytes); #if xENV_WIN clong_t bytes = a_bytes; #elif xENV_UNIX const off_t bytes = static_cast<off_t>( a_bytes ); #endif int_t iRv = xLOCKING(_nativeHandle(get()), a_mode, bytes); xTEST_DIFF(iRv, - 1); }
//------------------------------------------------------------------------------------------------- inline std::ustring_t Config::keyReadBin( std::ctstring_t &a_key, std::custring_t &a_defaultValue ) { xTEST_NA(a_key); xTEST_NA(a_defaultValue); std::tstring_t sRv; std::tstring_t hexStr = keyReadString(a_key, std::tstring_t(a_defaultValue.begin(), a_defaultValue.end())); // hexStr -> usRv sRv = String::cast(hexStr, 16); return std::ustring_t(sRv.begin(), sRv.end()); }
//------------------------------------------------------------------------------------------------- void_t IpcSemaphore::wait( culong_t &a_timeoutMsec ) const { xTEST_EQ(_isValid(), true); xTEST_NA(a_timeoutMsec); _wait_impl(a_timeoutMsec); }
//------------------------------------------------------------------------------------------------- inline void_t File::writeLine( std::ctstring_t &a_str ) const { xTEST_NA(a_str); int_t iRv = xTFPUTS((a_str + Const::eol()).c_str(), get()); xTEST_DIFF(iRv, - 1); }
//------------------------------------------------------------------------------------------------- inline Com::Com( const COINIT &a_concurrencyModel ) { xTEST_NA(a_concurrencyModel); HRESULT hrRv = ::CoInitializeEx(xPTR_NULL, a_concurrencyModel); xTEST_EQ(SUCCEEDED(hrRv), true); }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyWriteString( std::ctstring_t &a_key, std::ctstring_t &a_value ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_value); _write(a_key, a_value); }
//------------------------------------------------------------------------------------------------- inline void_t File::write( std::custring_t &a_buff ) const { xTEST_NA(a_buff); size_t uiRv = std::fwrite(&a_buff.at(0), 1, a_buff.size() * sizeof(std::ustring_t::value_type), get()); xTEST_EQ(uiRv, a_buff.size()); }
//------------------------------------------------------------------------------------------------- inline void_t File::ungetChar( ctchar_t &a_ch ) const { xTEST_NA(a_ch); twint_t iRv = xTUNGETC(a_ch, get()); xTEST_DIFF(iRv, xTEOF); xTEST_EQ(static_cast<tchar_t>( iRv ), a_ch); }
//------------------------------------------------------------------------------------------------- inline void_t File::attach( std::FILE *a_file ) { xTEST_NA(a_file); close(); _handle = a_file; _filePath = Const::strEmpty(); }
//------------------------------------------------------------------------------------------------- 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 void_t Console::setTitle( std::ctstring_t &a_title ) const { #if xENV_WIN xTEST_NA(_wnd); xTEST_EQ(_stdIn.isValid(), true); xTEST_EQ(_stdOut.isValid(), true); #endif _setTitle_impl(a_title); }
//------------------------------------------------------------------------------------------------- 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::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 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; } }
//------------------------------------------------------------------------------------------------- inline std::tstring_t Config::keyReadString( std::ctstring_t &a_key, std::ctstring_t &a_defaultValue ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_defaultValue); std::tstring_t sRv; _read(a_key, a_defaultValue, &sRv); return sRv; }
//------------------------------------------------------------------------------------------------- inline void_t File::resize( clonglong_t &a_size ) const { xTEST_NA(a_size); #if xENV_WIN clonglong_t _size = a_size; #elif xENV_UNIX const off_t _size = static_cast<off_t>( a_size ); #endif int_t iRv = xCHSIZE(_nativeHandle( get() ), _size); xTEST_EQ(iRv, 0); xTEST_EQ(a_size, size()); }
//------------------------------------------------------------------------------------------------- inline void_t Config::_write( std::ctstring_t &a_key, std::ctstring_t &a_value ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_value); // write to std::map_tstring_t std::map_tstring_t::iterator it = _config.find(a_key); if (it == _config.end()) { _config.insert( std::pair<std::tstring_t, std::tstring_t>(a_key, a_value) ); } else { it->second = a_value; } // write to file File::textWrite(path(), _separator, _config, File::omWrite); }
//------------------------------------------------------------------------------------------------- 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); }