ug4

Classes

class  ug::Base64FileWriter
 File writer allowing selective base64 encoding of arbitrary data. More...
 
class  ug::BinaryBuffer
 A Buffer for binary data. More...
 
class  ug::BinaryStream
 a specialzation of std::iostream, that uses a More...
 
class  ug::BinaryStreamBuffer
 A special version of a std::streambuf, writes data directly into a buffer that is accessible at any time. More...
 
class  ug::EmptyOStream
 a specialization of std::ostream, which doesn't write anything More...
 
class  ug::EmptyStreamBuffer
 Used by EmptyStream, to send tokens into nirvana! More...
 
class  ug::OStreamBufferSplitter
 forwards data written to this stream-buffer to other stream buffers. More...
 

Enumerations

enum  ug::Base64FileWriter::fmtflag { ug::Base64FileWriter::base64_ascii , ug::Base64FileWriter::base64_binary , ug::Base64FileWriter::normal }
 Format flags to enable deactivation of base64 encoding selectivly. More...
 

Functions

void ug::Base64FileWriter::assertFileOpen ()
 Check on readiness of the file stream. More...
 
 ug::Base64FileWriter::Base64FileWriter ()
 
 ug::Base64FileWriter::Base64FileWriter (const char *filename, const std::ios_base::openmode mode=(std::ios_base::out|std::ios_base::trunc))
 Constructor with name of file to write to. More...
 
UG_API void ug::ChangeDirectory (std::string dir)
 Changes the current directory. More...
 
void ug::Base64FileWriter::close ()
 Closes the file writer properly and encodes any remaining buffer content. More...
 
UG_API bool ug::CreateDirectory (const char *directory)
 Creates a directory. More...
 
UG_API bool ug::CreateDirectory (const char *directory, int mode)
 Creates a directory. More...
 
static bool ug::CreateDirectory (std::string directory)
 Creates a directory. More...
 
UG_API bool ug::CreateDirectoryTMP (const char *directory)
 Creates a directory. More...
 
std::string ug::CurrentWorkingDirectory ()
 
UG_API bool ug::DirectoryExists (const char *dirname)
 Checks the existence of a given directory. More...
 
static bool ug::DirectoryExists (std::string filename)
 
template<typename T >
void ug::Base64FileWriter::dispatch (const T &value)
 Writes given data to the output file and encodes it if Base64FileWriter::base64 is set. More...
 
UG_API bool ug::FileCompare (const char *file1, const char *file2)
 !!! Serial i/o version !!! More...
 
UG_API bool ug::FileExists (const char *filename)
 !!! Serial i/o version !!! More...
 
static bool ug::FileExists (std::string filename)
 
UG_API size_t ug::FileSize (const char *filename)
 Returns size of the specified file in bytes. More...
 
static size_t ug::FileSize (std::string filename)
 
bool ug::FileTypeIs (const char *filename, const char *extension)
 !!! Serial i/o version !!! More...
 
std::string ug::FindDirInStandardPaths (const char *dirname)
 searches the directory in the standard paths. More...
 
std::string ug::FindFileInStandardPaths (const char *filename)
 searches the file in the standard paths. More...
 
void ug::Base64FileWriter::flushInputBuffer (bool force=false)
 Flushes input buffer. More...
 
fmtflag ug::Base64FileWriter::format () const
 gets the current set format More...
 
UG_API bool ug::GetDirectoriesInDirectory (std::vector< std::string > &dirsOut, const char *dir)
 Returns a list of all directories in a directory. More...
 
UG_API bool ug::GetFilesInDirectory (std::vector< std::string > &filesOut, const char *dir)
 Returns a list of all files in a directory. More...
 
UG_API std::string ug::GetTmpPath ()
 Returns a path to which an application may write temporary files. More...
 
UG_API std::string ug::MakeTmpFile (std::string filename, const std::string &extension, bool &bSuccess)
 
void ug::Base64FileWriter::open (const char *filename, const std::ios_base::openmode mode=std::ios_base::out)
 
Base64FileWriterug::Base64FileWriter::operator<< (char c)
 
Base64FileWriterug::Base64FileWriter::operator<< (const char *cstr)
 
Base64FileWriterug::Base64FileWriter::operator<< (const fmtflag format)
 Switch between normal and base64 encoded output. More...
 
Base64FileWriterug::Base64FileWriter::operator<< (const std::string &str)
 
Base64FileWriterug::Base64FileWriter::operator<< (double d)
 
Base64FileWriterug::Base64FileWriter::operator<< (float f)
 
Base64FileWriterug::Base64FileWriter::operator<< (int i)
 
Base64FileWriterug::Base64FileWriter::operator<< (long l)
 
Base64FileWriterug::Base64FileWriter::operator<< (size_t s)
 
UG_API bool ug::ReadFile (const char *filename, std::vector< char > &file, bool bText)
 
static std::ios_base & ug::reset_floats (std::ios_base &o)
 used to unset flags set by std::scientific or std::fixed. More...
 
 ug::Base64FileWriter::~Base64FileWriter ()
 Destructor, which properly flushs encoder's internal buffer and closes file stream. More...
 

Variables

fmtflag ug::Base64FileWriter::m_currFormat
 Current write format (base64 or normal) More...
 
std::fstream ug::Base64FileWriter::m_fStream
 File stream to write everything to. More...
 
std::stringstream ug::Base64FileWriter::m_inBuffer
 Internal input buffer for the encoder. More...
 
size_t ug::Base64FileWriter::m_lastInputByteSize
 
size_t ug::Base64FileWriter::m_numBytesWritten
 
std::vector< char > ug::Base64FileWriter::m_tmpBuff
 

Detailed Description

Enumeration Type Documentation

◆ fmtflag

Format flags to enable deactivation of base64 encoding selectivly.

Enumerator
base64_ascii 

enables base64 encoding of all following data until Base64FileWriter::normal is set

base64_binary 

encode given values in binary base64

normal 

behaves as usual std::ofstream

Function Documentation

◆ assertFileOpen()

void ug::Base64FileWriter::assertFileOpen ( )
inlineprivate

Check on readiness of the file stream.

Exceptions
UGErrorif either the filestream's badbit is set or the file stream is not open.

References ug::Base64FileWriter::m_fStream, and UG_THROW.

Referenced by ug::Base64FileWriter::dispatch().

◆ Base64FileWriter() [1/2]

ug::Base64FileWriter::Base64FileWriter ( )

◆ Base64FileWriter() [2/2]

ug::Base64FileWriter::Base64FileWriter ( const char *  filename,
const std::ios_base::openmode  mode = (std::ios_base::out|std::ios_base::trunc) 
)

Constructor with name of file to write to.

Parameters
[in]filenamename of the output file
[in]modeopenmode for the file as defined in std::ios_base. Defaults to out | trunc, i.e. create new file or truncate existing.
Exceptions
UGErrorif filename can not be opened or is not writeable

◆ ChangeDirectory()

void ug::ChangeDirectory ( std::string  dir)

Changes the current directory.

References UG_THROW.

Referenced by ug::bridge::RegisterBridge_Util().

◆ close()

void ug::Base64FileWriter::close ( )

Closes the file writer properly and encodes any remaining buffer content.

References ug::Base64FileWriter::flushInputBuffer(), ug::Base64FileWriter::m_fStream, PROFILE_FUNC, and UG_ASSERT.

◆ CreateDirectory() [1/3]

bool ug::CreateDirectory ( const char *  directory)

Creates a directory.

Parameters
[in]directoryname of the directory
[in]mode(optional, default 0777) Sets ownership options for the file. Ignored on windows.
Returns
true if successfull

Referenced by ug::DebugWriterContext::compose_file_path(), ug::bridge::LUACompiler::createC(), ug::CreateDirectoryTMP(), and ug::SchurComplementOperator< TAlgebra >::set_debug_dim().

◆ CreateDirectory() [2/3]

bool ug::CreateDirectory ( const char *  directory,
int  mode 
)

Creates a directory.

Parameters
[in]directoryname of the directory
[in]mode(optional, default 0777) Sets ownership options for the file. Ignored on windows.
Returns
true if successfull

◆ CreateDirectory() [3/3]

static bool ug::CreateDirectory ( std::string  directory)
inlinestatic

Creates a directory.

Parameters
[in]directoryname of the directory
Returns
true if successfull

References ug::CreateDirectoryTMP().

◆ CreateDirectoryTMP()

bool ug::CreateDirectoryTMP ( const char *  directory)

Creates a directory.

This is a hack. This function does the same as CreateDirectory. But there is a linking problem in MS VC, so that the name CreateDirectory cannot be used.

Parameters
[in]directoryname of the directory
Returns
true if successfull

References ug::CreateDirectory().

Referenced by ug::CreateDirectory(), and ug::bridge::RegisterBridge_Util().

◆ CurrentWorkingDirectory()

std::string ug::CurrentWorkingDirectory ( )

Current working directory

Returns
the current working directory as a string

References PATH_MAX, and UG_THROW.

Referenced by ug::bridge::RegisterBridge_Util().

◆ DirectoryExists() [1/2]

bool ug::DirectoryExists ( const char *  dirname)

Checks the existence of a given directory.

Parameters
[in]nameof the directory to be checked
Returns
true if the specified directory exists, false otherwise

Referenced by ug::bridge::LUACompiler::createC(), ug::DirectoryExists(), ug::FindDirInStandardPaths(), ug::PathProvider::get_dirname_relative_to_current_path(), ug::PathProvider::get_dirname_relative_to_path(), and ug::bridge::RegisterBridge_Util().

◆ DirectoryExists() [2/2]

static bool ug::DirectoryExists ( std::string  filename)
inlinestatic

References ug::DirectoryExists().

◆ dispatch()

template<typename T >
void ug::Base64FileWriter::dispatch ( const T &  value)
private

Writes given data to the output file and encodes it if Base64FileWriter::base64 is set.

Parameters
valuearbitrary data to write to the output file
Template Parameters
Ttype of the data to write
Exceptions
UGErrorif Base64FileWriter::fmtflag is not set to Base64FileWriter::normal or Base64FileWriter::base64

References ug::Base64FileWriter::assertFileOpen(), ug::Base64FileWriter::base64_ascii, ug::Base64FileWriter::base64_binary, ug::Base64FileWriter::flushInputBuffer(), ug::Base64FileWriter::m_currFormat, ug::Base64FileWriter::m_fStream, ug::Base64FileWriter::m_inBuffer, ug::Base64FileWriter::m_lastInputByteSize, ug::Base64FileWriter::m_numBytesWritten, ug::Base64FileWriter::normal, and UG_ASSERT.

◆ FileCompare()

UG_API bool ug::FileCompare ( const char *  file1,
const char *  file2 
)

!!! Serial i/o version !!!

Compares two files by their content.

Comparison is first done on file size using ug::FileSize. If the two files have same size, then the comparison is done line wise based on std::string comparison.

Parameters
[in]file1Path and name of the first file
[in]file2Path and name of the second file
Returns
true if they are the same one or different ones but with same content; false otherwise
Exceptions
std::runtim_errorif one or both files can not be found or opened for reading.

References ug::FileExists(), ug::FileSize(), PROFILE_FUNC, and UG_THROW.

Referenced by ug::bridge::RegisterBridge_Util().

◆ FileExists() [1/2]

UG_API bool ug::FileExists ( const char *  filename)

◆ FileExists() [2/2]

static bool ug::FileExists ( std::string  filename)
inlinestatic

References ug::FileExists().

◆ FileSize() [1/2]

size_t ug::FileSize ( const char *  filename)

Returns size of the specified file in bytes.

Parameters
[in]filenamePath and name of the file
Returns
Size of filename in bytes
Exceptions
std::runtime_errorif the specified file does not exist or could not be opened for reading.

References ug::FileExists(), PROFILE_FUNC, and UG_THROW.

Referenced by ug::FileCompare(), ug::FileSize(), and ug::ReadFile().

◆ FileSize() [2/2]

static size_t ug::FileSize ( std::string  filename)
inlinestatic

References ug::FileSize().

◆ FileTypeIs()

UG_API bool ug::FileTypeIs ( const char *  filename,
const char *  extension 
)

!!! Serial i/o version !!!

Check filename extension.

Parameters
[in]filenamepath and anme of the file
[in]extensiondesired file extension (including leading dot)
Returns
true if filename has given extension, false otherwise

References name, and PROFILE_FUNC.

Referenced by ug::SaveMatrixToMTX(), ug::AlgebraDebugWriter< TAlgebra >::write_matrix(), ug::GridFunctionDebugWriter< TDomain, TAlgebra >::write_matrix(), ug::GridFunctionDebugWriter< TDomain, TAlgebra >::write_vector_to_conn_viewer(), ug::WriteMatrixToConnectionViewer(), ug::WriteVectorCSV(), and ug::WriteVectorToConnectionViewer().

◆ FindDirInStandardPaths()

std::string ug::FindDirInStandardPaths ( const char *  dirname)

searches the directory in the standard paths.

The checking order is the following:

Returns
the full path (including the dir name) at which the dir was found, or an empty string if no matching file was found.

References ug::APPS_PATH, ug::DirectoryExists(), ug::ROOT_PATH, and ug::SCRIPT_PATH.

◆ FindFileInStandardPaths()

std::string ug::FindFileInStandardPaths ( const char *  filename)

searches the file in the standard paths.

The checking order is the following:

Returns
the full path (including the filename) at which the file was found, or an empty string if no matching file was found.

References ug::APPS_PATH, ug::FileExists(), ug::ROOT_PATH, and ug::SCRIPT_PATH.

Referenced by ug::Raster< T, TDIM >::load_from_asc(), ug::LoadGrid(), ug::LoadHeightfieldFromASC(), ug::UGXFileInfo::parse_file(), and ug::bridge::RegisterBridge_Util().

◆ flushInputBuffer()

void ug::Base64FileWriter::flushInputBuffer ( bool  force = false)
private

◆ format()

Base64FileWriter::fmtflag ug::Base64FileWriter::format ( ) const

gets the current set format

◆ GetDirectoriesInDirectory()

bool ug::GetDirectoriesInDirectory ( std::vector< std::string > &  dirsOut,
const char *  dir 
)

Returns a list of all directories in a directory.

The returned list contains as well the directory scanned as . and its parent directory as ...

Parameters
[out]dirsOutstring vector for holding the list of directories
[in]dirpath and name of the directory to scan
Note
The implementation relies on OS specific instructions. Implementations for POSIX-UNIX and Windows are available.

References PROFILE_FUNC.

Referenced by ug::bridge::GetDirsInDir().

◆ GetFilesInDirectory()

bool ug::GetFilesInDirectory ( std::vector< std::string > &  filesOut,
const char *  dir 
)

Returns a list of all files in a directory.

Parameters
[out]filesOutstring vector for holding the list of files
[in]dirpath and name of the directory to scan
Note
The implementation relies on OS specific instructions. Implementations for POSIX-UNIX and Windows are available.

References PROFILE_FUNC.

Referenced by ug::bridge::GetFilesInDir(), and ug::LoadPlugins().

◆ GetTmpPath()

std::string ug::GetTmpPath ( )

Returns a path to which an application may write temporary files.

On unix systems, this is normally "/tmp". On windows the users AppData path or something similar is returned.

Referenced by ug::bridge::RegisterBridge_Util().

◆ MakeTmpFile()

UG_API std::string ug::MakeTmpFile ( std::string  filename,
const std::string &  extension,
bool &  bSuccess 
)
Parameters
filenamefilename including path (e.g. /Users/horst/file1)
extensionthe extension to be added to the file e.g. txt
bSuccesstrue if successful, false otherwise
Returns
filenameXXXXXX.extension, where XXXXXX is some number between 1 and 999999, so that the file doesn't exist yet.

◆ open()

void ug::Base64FileWriter::open ( const char *  filename,
const std::ios_base::openmode  mode = std::ios_base::out 
)

◆ operator<<() [1/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( char  c)

◆ operator<<() [2/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( const char *  cstr)

◆ operator<<() [3/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( const fmtflag  format)

Switch between normal and base64 encoded output.

Parameters
formatone of the values defined in Base64FileWriter::fmtflag

References PROFILE_FUNC.

◆ operator<<() [4/9]

Base64FileWriter& ug::Base64FileWriter::operator<< ( const std::string &  str)

◆ operator<<() [5/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( double  d)

◆ operator<<() [6/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( float  f)

◆ operator<<() [7/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( int  i)

◆ operator<<() [8/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( long  l)

◆ operator<<() [9/9]

Base64FileWriter & ug::Base64FileWriter::operator<< ( size_t  s)

◆ ReadFile()

UG_API bool ug::ReadFile ( const char *  filename,
vector< char > &  file,
bool  bText 
)
Parameters
filenamefilename to read
filevector to put whole file into
bTextif true, open file with r, otherwise rb used in
See also
ParallelReadFile and Script

!!! Serial i/o version !!! in parallel, see ParallelReadFile.

References ug::FileSize(), PROFILE_FUNC, and UG_COND_THROW.

Referenced by ug::script::LoadUGScript(), and pcl::ParallelReadFile().

◆ reset_floats()

static std::ios_base& ug::reset_floats ( std::ios_base &  o)
inlinestatic

used to unset flags set by std::scientific or std::fixed.

example: std::cout << std::scienfitic << myDouble << "\n"; std::cout << reset_floats << myPrecentage << "\n"; also in UG_LOG: UG_LOG(reset_floats << myValue);

Note
use ug::reset_floats if not in namespace ug.

Referenced by ug::AutoLinearSolver< TVector >::apply_return_defect(), ug::checksub(), ug::PILUTPreconditioner< TAlgebra >::preprocess(), ug::ILUTPreconditioner< TAlgebra >::preprocess_mat2(), ug::AutoLinearSolver< TVector >::print_information(), ug::Progress::stop(), and ug::ParallelProgress::stop().

◆ ~Base64FileWriter()

ug::Base64FileWriter::~Base64FileWriter ( )

Destructor, which properly flushs encoder's internal buffer and closes file stream.

References ug::Base64FileWriter::flushInputBuffer(), and ug::Base64FileWriter::m_fStream.

Variable Documentation

◆ m_currFormat

fmtflag ug::Base64FileWriter::m_currFormat
private

Current write format (base64 or normal)

Referenced by ug::Base64FileWriter::dispatch().

◆ m_fStream

◆ m_inBuffer

std::stringstream ug::Base64FileWriter::m_inBuffer
private

Internal input buffer for the encoder.

Referenced by ug::Base64FileWriter::dispatch(), and ug::Base64FileWriter::flushInputBuffer().

◆ m_lastInputByteSize

size_t ug::Base64FileWriter::m_lastInputByteSize
private

◆ m_numBytesWritten

size_t ug::Base64FileWriter::m_numBytesWritten
private

number of bytes written between flushes

Referenced by ug::Base64FileWriter::dispatch(), and ug::Base64FileWriter::flushInputBuffer().

◆ m_tmpBuff

std::vector<char> ug::Base64FileWriter::m_tmpBuff
private

buffer used while flushing

Referenced by ug::Base64FileWriter::flushInputBuffer().