Utils Namespace Reference


Detailed Description

Various utility functions.


Classes

class  ReadError
 Exception class, thrown when read methods detect attempt to read past end of stream. More...
class  StopWatch
 Simple time measuring class, wrapped around getTick() method. More...
struct  PtrLess
 Simple generic function object for usage in standard containers, where pointer types are stored, but actual object comparisons are needed. More...

Specializations for reading various datas

template<class T>
getVal (std::istream &i)
 Primary template is not implemented, and causes compile-time error if instanciated.
template<class T>
getVal (std::istream &i, uint16_t len)

Writing function template specializations.

template<>
void putVal (std::ostream &o, uint8_t val)
template<>
void putVal (std::ostream &o, uint16_t val)
template<>
void putVal (std::ostream &o, uint32_t val)
template<>
void putVal (std::ostream &o, uint64_t val)
template<>
void putVal (std::ostream &o, float val)
template<>
void putVal (std::ostream &o, const std::string &str)
template<>
void putVal (std::ostream &o, std::string str)
void putVal (std::ostream &o, const std::string &str, uint16_t len)
void putVal (std::ostream &o, const char *const str, uint16_t len)
void putVal (std::ostream &o, const uint8_t *const str, uint16_t len)
void putVal (std::ostream &o, const boost::shared_array< char > &str, uint16_t len)

Functions

unsigned char hex2dec (unsigned char c)
 Converts passed character to decimal notation.
std::string decode (const char *data, uint32_t length)
 Convert passed data into hexadecimal notation.
std::string encode (const char *data, uint32_t length)
 Convert hexadecimal character string into binary format.
void hexDump (std::ostream &o, const std::string &data)
 Print hexadecimal dump of specified data into specified stream.
std::string hexDump (const std::string &data)
 Convert passed string into formatted hexadecimal string.
uint64_t getTick ()
 getTick() function copied from wxWidgets library wxGetLocalTimeMillis() function (from src/common/timercmn.cpp)
std::string decode (const std::string &data)
std::string decode (const std::string &data, uint32_t length)
std::string decode (boost::shared_array< char > data, uint32_t len)
std::string encode (const std::string &data)
std::string encode (const std::string &data, uint32_t length)
std::string encode (boost::shared_array< char > data, uint32_t len)
void copyString (const char *src, char *&dest)
 Copy string from source to destination, overwriting destination memory.
uint64_t getFileSize (const boost::filesystem::path &loc)
 Retrieve the size of a file.
uint32_t getModDate (const boost::filesystem::path &loc)
 Retrieve the last modification date of a file.
template<class T>
void putVal (std::ostream &o, T val)
 Write.
template<class T>
std::ostream & hexDump (std::ostream &o, T val)
 Dumps the hexadecimal representation of a value to stream.
template<typename T>
std::string hexDump (T val)
 Creates hexadecimal dump of value into a string.
template<typename T>
std::string hexDump (T *val)
 Specalization - for dumping pointer types.
std::string bytesToString (uint64_t bytes)
 Convert bytes to string representation.

Function Documentation

std::string bytesToString uint64_t  bytes  )  [inline]
 

Convert bytes to string representation.

Parameters:
bytes Amount of bytes to check
Returns:
Human-readable string, e.g. "4.56 GB"

Definition at line 392 of file utils.h.

Referenced by SchedBase::handleEvents(), PartData::printCompleted(), and FilesList::~FilesList().

void copyString const char *  src,
char *&  dest
[inline]
 

Copy string from source to destination, overwriting destination memory.

This function assumes source string is null-terminated, and copies until the terminating zero (including it). The destination pointer is passed by reference and modified as neccesery during memory reallocations to point to newly allocated memory region.

Parameters:
src Source, null-terminated string
dest Destination

Definition at line 90 of file utils.h.

Referenced by AudioMetaData::setAlbum(), AudioMetaData::setArtist(), ImageMetaData::setComment(), ArchiveMetaData::setComment(), AudioMetaData::setComment(), AudioMetaData::setComposer(), AudioMetaData::setCopyright(), AudioMetaData::setEncoded(), AudioMetaData::setGenre(), AudioMetaData::setOrigArtist(), AudioMetaData::setTitle(), and AudioMetaData::setUrl().

std::string decode boost::shared_array< char >  data,
uint32_t  len
[inline]
 

Definition at line 67 of file utils.h.

References decode().

Here is the call graph for this function:

std::string decode const std::string &  data,
uint32_t  length
[inline]
 

Definition at line 64 of file utils.h.

References decode().

Here is the call graph for this function:

std::string decode const std::string &  data  )  [inline]
 

Definition at line 61 of file utils.h.

References decode().

Here is the call graph for this function:

std::string DLLEXPORT Utils::decode const char *  data,
uint32_t  length
 

Convert passed data into hexadecimal notation.

Parameters:
data Data to be decoded.
length Length of data.
Returns:
Hexadecimal notation of the data.

Definition at line 46 of file utils.cpp.

References CHECK_THROW.

Referenced by HashSetBase::compare(), decode(), HashBase::decode(), and PartData::onHashEvent().

std::string encode boost::shared_array< char >  data,
uint32_t  len
[inline]
 

Definition at line 76 of file utils.h.

References encode().

Here is the call graph for this function:

std::string encode const std::string &  data,
uint32_t  length
[inline]
 

Definition at line 73 of file utils.h.

References encode().

Here is the call graph for this function:

std::string encode const std::string &  data  )  [inline]
 

Definition at line 70 of file utils.h.

References encode().

Here is the call graph for this function:

std::string DLLEXPORT Utils::encode const char *  data,
uint32_t  length
 

Convert hexadecimal character string into binary format.

Parameters:
data Data to be encoded.
length Length of data.
Returns:
Binary representation of the passed data.
Note:
Throws std::runtime_error from hex2dec if passed data is not well-formed hexadecimal stream.

Definition at line 60 of file utils.cpp.

References CHECK_THROW, and hex2dec().

Referenced by encode().

Here is the call graph for this function:

uint64_t getFileSize const boost::filesystem::path &  loc  )  [inline]
 

Retrieve the size of a file.

Parameters:
path Full path to the file being interested in.
Returns:
Size of the file.

Definition at line 106 of file utils.h.

Referenced by SharedFile::findMetaData(), HashWork::finish(), and HashWork::initState().

uint32_t getModDate const boost::filesystem::path &  loc  )  [inline]
 

Retrieve the last modification date of a file.

Parameters:
path Full path to the file being interested in.
Returns:
Last modification time as reported by the OS.

Definition at line 118 of file utils.h.

Referenced by SharedFile::findMetaData(), HashWork::finish(), HydraNode::init(), PartData::PartData(), and SharedFile::read().

uint64_t getTick  )  [inline]
 

getTick() function copied from wxWidgets library wxGetLocalTimeMillis() function (from src/common/timercmn.cpp)

Definition at line 56 of file gettickcount.h.

Referenced by EventTable< Source, Event >::checkForDelayed(), SocketWatcher::doPoll(), Utils::StopWatch::elapsed(), SchedBase::handleEvents(), SocketClient::setTimeout(), and Utils::StopWatch::StopWatch().

template<class T>
std::string Utils::getVal std::istream &  i,
uint16_t  len
[inline]
 

Definition at line 208 of file utils.h.

template<class T>
std::string Utils::getVal std::istream &  i  )  [inline]
 

Primary template is not implemented, and causes compile-time error if instanciated.

Definition at line 137 of file utils.h.

unsigned char hex2dec unsigned char  c  )  [inline]
 

Converts passed character to decimal notation.

Parameters:
c Hexadecimal-compatible unsigned character
Returns:
Decimal notation of given input

Definition at line 32 of file utils.cpp.

Referenced by encode().

template<typename T>
std::string hexDump T *  val  ) 
 

Specalization - for dumping pointer types.

Note: using p argument at boost::format generally works better and is more readable for this purpose...

Parameters:
val Value to dump
Returns:
Hexadeciman representation of value

Definition at line 338 of file utils.h.

template<typename T>
std::string hexDump val  ) 
 

Creates hexadecimal dump of value into a string.

Parameters:
val Value to convert to hex
Returns:
String containing the hex representation of the value

Definition at line 321 of file utils.h.

template<class T>
std::ostream& hexDump std::ostream &  o,
val
 

Dumps the hexadecimal representation of a value to stream.

Parameters:
o Stream to write to
val Value to write
Returns:
The original stream

Definition at line 307 of file utils.h.

std::string DLLEXPORT Utils::hexDump const std::string &  data  ) 
 

Convert passed string into formatted hexadecimal string.

Parameters:
data Data to convert
Returns:
Formatted hex-dump of the data.

Definition at line 141 of file utils.cpp.

References hexDump().

Here is the call graph for this function:

void DLLEXPORT Utils::hexDump std::ostream &  o,
const std::string &  data
 

Print hexadecimal dump of specified data into specified stream.

Parameters:
o Stream to write to
data Data to be written

Definition at line 77 of file utils.cpp.

Referenced by hexDump(), and CGComm::invalidType().

void putVal std::ostream &  o,
const boost::shared_array< char > &  str,
uint16_t  len
[inline]
 

Definition at line 291 of file utils.h.

References CHECK_THROW.

void putVal std::ostream &  o,
const uint8_t *const   str,
uint16_t  len
[inline]
 

Definition at line 285 of file utils.h.

References CHECK_THROW.

void putVal std::ostream &  o,
const char *const   str,
uint16_t  len
[inline]
 

Definition at line 279 of file utils.h.

References CHECK_THROW.

void putVal std::ostream &  o,
const std::string &  str,
uint16_t  len
[inline]
 

Definition at line 274 of file utils.h.

template<>
void putVal std::ostream &  o,
std::string  str
[inline]
 

Definition at line 270 of file utils.h.

template<>
void putVal std::ostream &  o,
const std::string &  str
[inline]
 

Definition at line 265 of file utils.h.

template<>
void putVal std::ostream &  o,
float  val
[inline]
 

Definition at line 259 of file utils.h.

References SWAP32_ON_BE.

template<>
void putVal std::ostream &  o,
uint64_t  val
[inline]
 

Definition at line 253 of file utils.h.

References SWAP64_ON_BE.

template<>
void putVal std::ostream &  o,
uint32_t  val
[inline]
 

Definition at line 247 of file utils.h.

References SWAP32_ON_BE.

template<>
void putVal std::ostream &  o,
uint16_t  val
[inline]
 

Definition at line 241 of file utils.h.

References SWAP16_ON_BE.

template<>
void putVal std::ostream &  o,
uint8_t  val
[inline]
 

Definition at line 236 of file utils.h.

template<class T>
void putVal std::ostream &  o,
val
[inline]
 

Write.

Primary template not implemented and causes compile-time failure if instanciated.

Definition at line 229 of file utils.h.

Referenced by operator<<().