Goby3  3.1.5a
2024.05.23
goby::util Namespace Reference

Namespaces

 ais
 
 gps
 
 groups
 
 logger
 
 logger_lock
 
 protobuf
 
 seawater
 
 tcolor
 Contains functions for adding color to Terminal window streams.
 
 units
 

Classes

class  bad_nmea_sentence
 
struct  Colors
 Represents the eight available terminal colors (and bold variants) More...
 
class  FlexNCurses
 Enables the Verbosity == gui mode of the Goby logger and displays an NCurses gui for the logger content. More...
 
class  FlexOstream
 Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf. More...
 
class  FlexOStreamBuf
 
class  FlexOStreamErrorCollector
 
class  LineBasedCommsThreadStub
 
class  LineBasedInterface
 basic interface class for all the derived serial (and networking mimics) line-based nodes (serial, tcp, udp, etc.) More...
 
class  NMEASentence
 
class  SerialClient
 provides a basic client for line by line text based communications over a 8N1 tty (such as an RS-232 serial link) without flow control More...
 
class  TCPClient
 provides a basic TCP client for line by line text based communications to a remote TCP server More...
 
class  TCPServer
 provides a basic TCP server for line by line text based communications to a one or more remote TCP clients More...
 
class  TermColor
 Converts between string, escape code, and enumeration representations of the terminal colors. More...
 
class  TermColorDeleter
 
class  UTMGeodesy
 

Functions

template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_same< To, double >, boost::is_same< From, boost::posix_time::ptime > >, To >::type as (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_same< To, boost::posix_time::ptime >, boost::is_same< From, double > >, To >::type as (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_same< To, std::uint64_t >, boost::is_same< From, boost::posix_time::ptime > >, To >::type as (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_same< To, boost::posix_time::ptime >, boost::is_same< From, std::uint64_t > >, To >::type as (const From &from)
 
void base_convert (const std::string &source, std::string *sink, int source_base, int sink_base)
 
std::ostream & operator<< (FlexOstream &out, char c)
 
std::ostream & operator<< (FlexOstream &out, signed char c)
 
std::ostream & operator<< (FlexOstream &out, unsigned char c)
 
std::ostream & operator<< (FlexOstream &out, const char *s)
 
std::ostream & operator<< (FlexOstream &out, const signed char *s)
 
std::ostream & operator<< (FlexOstream &out, const unsigned char *s)
 
template<typename _CharT , typename _Traits , typename _Alloc >
std::ostream & operator<< (FlexOstream &out, const std::basic_string< _CharT, _Traits, _Alloc > &s)
 
util::FlexOstreamglogger ()
 

Variables

template<class T >
constexpr T pi = T(3.1415926535897932385L)
 
template<class T >
constexpr T e = T(2.7182818284590452354L)
 
template<class T >
constexpr T NaN {std::numeric_limits<T>::quiet_NaN()}
 
const std::string esc_red = "\33[31m"
 
const std::string esc_lt_red = "\33[91m"
 
const std::string esc_green = "\33[32m"
 
const std::string esc_lt_green = "\33[92m"
 
const std::string esc_yellow = "\33[33m"
 
const std::string esc_lt_yellow = "\33[93m"
 
const std::string esc_blue = "\33[34m"
 
const std::string esc_lt_blue = "\33[94m"
 
const std::string esc_magenta = "\33[35m"
 
const std::string esc_lt_magenta = "\33[95m"
 
const std::string esc_cyan = "\33[36m"
 
const std::string esc_lt_cyan = "\33[96m"
 
const std::string esc_white = "\33[37m"
 
const std::string esc_lt_white = "\33[97m"
 
const std::string esc_nocolor = "\33[0m"
 

goby::util::as, a "do-the-right-thing" type casting tool

enum  FloatRepresentation { FLOAT_DEFAULT, FLOAT_FIXED, FLOAT_SCIENTIFIC }
 
template<typename To >
boost::enable_if< boost::is_arithmetic< To >, To >::type _as_from_string (const std::string &from)
 
template<typename To >
boost::enable_if< boost::is_enum< To >, To >::type _as_from_string (const std::string &from)
 
template<typename To >
boost::enable_if< boost::is_class< To >, To >::type _as_from_string (const std::string &from)
 
template<>
bool _as_from_string< bool > (const std::string &from)
 
template<>
std::string _as_from_string< std::string > (const std::string &from)
 
template<typename To , typename From >
std::string _as_to_string (const From &from)
 
template<>
std::string _as_to_string< std::string, bool > (const bool &from)
 specialization of as() for bool -> string More...
 
template<>
std::string _as_to_string< std::string, std::string > (const std::string &from)
 
template<typename To , typename From >
boost::disable_if< boost::is_same< To, From >, To >::type _as_numeric (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::is_same< To, From >, To >::type _as_numeric (const From &from)
 
template<typename To >
To as (const std::string &from)
 
template<typename To , typename From >
boost::enable_if< boost::is_same< To, std::string >, To >::type as (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_arithmetic< To >, boost::is_arithmetic< From > >, To >::type as (const From &from)
 
template<typename To , typename From >
boost::enable_if< boost::mpl::and_< boost::is_enum< To >, boost::is_arithmetic< From > >, To >::type as (const From &from)
 
template<typename To , typename From >
To as (const From &from, int precision, FloatRepresentation rep=FLOAT_DEFAULT)
 
template<>
std::string as< std::string, double > (const double &from, int precision, FloatRepresentation rep)
 
template<>
std::string as< std::string, float > (const float &from, int precision, FloatRepresentation rep)
 

Enumeration Type Documentation

◆ FloatRepresentation

Enumerator
FLOAT_DEFAULT 
FLOAT_FIXED 
FLOAT_SCIENTIFIC 

Definition at line 172 of file as.h.

Function Documentation

◆ _as_from_string() [1/3]

template<typename To >
boost::enable_if<boost::is_arithmetic<To>, To>::type goby::util::_as_from_string ( const std::string &  from)

Definition at line 52 of file as.h.

◆ _as_from_string() [2/3]

template<typename To >
boost::enable_if<boost::is_enum<To>, To>::type goby::util::_as_from_string ( const std::string &  from)

Definition at line 68 of file as.h.

◆ _as_from_string() [3/3]

template<typename To >
boost::enable_if<boost::is_class<To>, To>::type goby::util::_as_from_string ( const std::string &  from)

Definition at line 81 of file as.h.

◆ _as_from_string< bool >()

template<>
bool goby::util::_as_from_string< bool > ( const std::string &  from)
inline

Definition at line 93 of file as.h.

◆ _as_from_string< std::string >()

template<>
std::string goby::util::_as_from_string< std::string > ( const std::string &  from)
inline

Definition at line 98 of file as.h.

◆ _as_numeric() [1/2]

template<typename To , typename From >
boost::disable_if<boost::is_same<To, From>, To>::type goby::util::_as_numeric ( const From &  from)

Definition at line 127 of file as.h.

◆ _as_numeric() [2/2]

template<typename To , typename From >
boost::enable_if<boost::is_same<To, From>, To>::type goby::util::_as_numeric ( const From &  from)

Definition at line 142 of file as.h.

◆ _as_to_string()

template<typename To , typename From >
std::string goby::util::_as_to_string ( const From &  from)

Definition at line 103 of file as.h.

◆ _as_to_string< std::string, bool >()

template<>
std::string goby::util::_as_to_string< std::string, bool > ( const bool from)
inline

specialization of as() for bool -> string

Definition at line 116 of file as.h.

◆ _as_to_string< std::string, std::string >()

template<>
std::string goby::util::_as_to_string< std::string, std::string > ( const std::string &  from)
inline

Definition at line 121 of file as.h.

◆ as() [1/9]

template<typename To , typename From >
boost::enable_if< boost::mpl::and_<boost::is_same<To, double>, boost::is_same<From, boost::posix_time::ptime> >, To>::type goby::util::as ( const From &  from)

Definition at line 74 of file legacy.h.

◆ as() [2/9]

template<typename To , typename From >
boost::enable_if< boost::mpl::and_<boost::is_same<To, boost::posix_time::ptime>, boost::is_same<From, double> >, To>::type goby::util::as ( const From &  from)

Definition at line 83 of file legacy.h.

◆ as() [3/9]

template<typename To , typename From >
boost::enable_if<boost::mpl::and_<boost::is_same<To, std::uint64_t>, boost::is_same<From, boost::posix_time::ptime> >, To>::type goby::util::as ( const From &  from)

Definition at line 93 of file legacy.h.

◆ as() [4/9]

template<typename To , typename From >
boost::enable_if<boost::mpl::and_<boost::is_same<To, boost::posix_time::ptime>, boost::is_same<From, std::uint64_t> >, To>::type goby::util::as ( const From &  from)

Definition at line 103 of file legacy.h.

◆ as() [5/9]

template<typename To , typename From >
boost::enable_if<boost::is_same<To, std::string>, To>::type goby::util::as ( const From &  from)

Definition at line 150 of file as.h.

◆ as() [6/9]

template<typename To , typename From >
boost::enable_if<boost::mpl::and_<boost::is_arithmetic<To>, boost::is_arithmetic<From> >, To>::type goby::util::as ( const From &  from)

Definition at line 158 of file as.h.

◆ as() [7/9]

template<typename To , typename From >
boost::enable_if<boost::mpl::and_<boost::is_enum<To>, boost::is_arithmetic<From> >, To>::type goby::util::as ( const From &  from)

Definition at line 167 of file as.h.

◆ as() [8/9]

template<typename To , typename From >
To goby::util::as ( const From &  from,
int  precision,
FloatRepresentation  rep = FLOAT_DEFAULT 
)

Definition at line 180 of file as.h.

◆ as() [9/9]

template<typename To >
To goby::util::as ( const std::string &  from)

Definition at line 147 of file as.h.

◆ as< std::string, double >()

template<>
std::string goby::util::as< std::string, double > ( const double from,
int  precision,
FloatRepresentation  rep 
)
inline

Definition at line 186 of file as.h.

◆ as< std::string, float >()

template<>
std::string goby::util::as< std::string, float > ( const float &  from,
int  precision,
FloatRepresentation  rep 
)
inline

Definition at line 203 of file as.h.

◆ base_convert()

void goby::util::base_convert ( const std::string &  source,
std::string *  sink,
int  source_base,
int  sink_base 
)

◆ ceil_log2() [1/3]

unsigned goby::util::ceil_log2 ( double  d)
inline

Definition at line 67 of file sci.h.

◆ ceil_log2() [2/3]

unsigned goby::util::ceil_log2 ( int  i)
inline

Definition at line 69 of file sci.h.

◆ ceil_log2() [3/3]

unsigned goby::util::ceil_log2 ( unsigned  v)
inline
Returns
ceil(log2(v))

Definition at line 59 of file sci.h.

◆ glogger()

util::FlexOstream& goby::util::glogger ( )
inline

Definition at line 214 of file flex_ostream.h.

◆ hex_decode() [1/2]

std::string goby::util::hex_decode ( const std::string &  in)
inline

Definition at line 82 of file binary.h.

◆ hex_decode() [2/2]

void goby::util::hex_decode ( const std::string &  in,
std::string *  out 
)
inline

Decodes a (little-endian) hexadecimal string to a byte string. Index 0 and 1 (first byte) of in are written to index 0 (first byte) of out

Parameters
inhexadecimal string (e.g. "544f4d" or "544F4D")
outpointer to string to store result (e.g. "TOM").

Definition at line 47 of file binary.h.

◆ hex_encode() [1/2]

std::string goby::util::hex_encode ( const std::string &  in)
inline

Definition at line 121 of file binary.h.

◆ hex_encode() [2/2]

void goby::util::hex_encode ( const std::string &  in,
std::string *  out,
bool  upper_case = false 
)
inline

Encodes a (little-endian) hexadecimal string from a byte string. Index 0 of in is written to index 0 and 1 (first byte) of out

Parameters
inbyte string to encode (e.g. "TOM")
outpointer to string to store result (e.g. "544f4d")
upper_caseset true to use upper case for the alphabet characters (i.e. A,B,C,D,E,F), otherwise lowercase is used (a,b,c,d,e,f).

Definition at line 94 of file binary.h.

◆ hex_string2number()

template<typename T >
bool goby::util::hex_string2number ( const std::string &  s,
T &  t 
)

attempts to convert a hex string into a numerical representation (of type T)

Returns
true if conversion succeeds, false otherwise

Definition at line 131 of file binary.h.

◆ linear_interpolate()

template<typename N1 , typename N2 >
N2 goby::util::linear_interpolate ( N1  a,
const std::map< N1, N2 > &  table 
)

Linear interpolation function.

Parameters
aValue to interpolate
tableTable of values to interpolate from
Returns
Interpolated value

Definition at line 78 of file sci.h.

◆ log2()

double goby::util::log2 ( double  d)
inline

Definition at line 71 of file sci.h.

◆ number2hex_string() [1/2]

template<typename T >
std::string goby::util::number2hex_string ( const T &  t,
unsigned int  width = 2 
)

converts a decimal number of type T into a hex string assuming success

Parameters
tdecimal number to convert
widthdesired width (in characters) of return string. Width should be twice the number of bytes
Returns
hex string

Definition at line 158 of file binary.h.

◆ number2hex_string() [2/2]

template<typename T >
bool goby::util::number2hex_string ( std::string &  s,
const T &  t,
unsigned int  width = 2 
)

converts a decimal number of type T into a hex string

Parameters
sstring reference to store result in
tdecimal number to convert
widthdesired width (in characters) of return string. Width should be twice the number of bytes
Returns
true if successful, false otherwise

Definition at line 145 of file binary.h.

◆ operator<<() [1/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
char  c 
)
inline

Definition at line 180 of file flex_ostream.h.

◆ operator<<() [2/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
const char s 
)
inline

Definition at line 186 of file flex_ostream.h.

◆ operator<<() [3/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
const signed char s 
)
inline

Definition at line 187 of file flex_ostream.h.

◆ operator<<() [4/7]

template<typename _CharT , typename _Traits , typename _Alloc >
std::ostream& goby::util::operator<< ( FlexOstream out,
const std::basic_string< _CharT, _Traits, _Alloc > &  s 
)
inline

Definition at line 198 of file flex_ostream.h.

◆ operator<<() [5/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
const unsigned char s 
)
inline

Definition at line 191 of file flex_ostream.h.

◆ operator<<() [6/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
signed char  c 
)
inline

Definition at line 181 of file flex_ostream.h.

◆ operator<<() [7/7]

std::ostream& goby::util::operator<< ( FlexOstream out,
unsigned char  c 
)
inline

Definition at line 182 of file flex_ostream.h.

◆ unbiased_round()

double goby::util::unbiased_round ( double  r,
double  dec 
)
inline

round 'r' to 'dec' number of decimal places we want no upward bias so round 5 up if odd next to it, down if even

Parameters
rvalue to round
decnumber of places past the decimal to round (e.g. dec=1 rounds to tenths)
Returns
r rounded

Definition at line 44 of file sci.h.

Variable Documentation

◆ e

template<class T >
constexpr T goby::util::e = T(2.7182818284590452354L)
constexpr

Definition at line 35 of file constants.h.

◆ esc_blue

const std::string goby::util::esc_blue = "\33[34m"

Definition at line 43 of file term_color.h.

◆ esc_cyan

const std::string goby::util::esc_cyan = "\33[36m"

Definition at line 47 of file term_color.h.

◆ esc_green

const std::string goby::util::esc_green = "\33[32m"

Definition at line 39 of file term_color.h.

◆ esc_lt_blue

const std::string goby::util::esc_lt_blue = "\33[94m"

Definition at line 44 of file term_color.h.

◆ esc_lt_cyan

const std::string goby::util::esc_lt_cyan = "\33[96m"

Definition at line 48 of file term_color.h.

◆ esc_lt_green

const std::string goby::util::esc_lt_green = "\33[92m"

Definition at line 40 of file term_color.h.

◆ esc_lt_magenta

const std::string goby::util::esc_lt_magenta = "\33[95m"

Definition at line 46 of file term_color.h.

◆ esc_lt_red

const std::string goby::util::esc_lt_red = "\33[91m"

Definition at line 38 of file term_color.h.

◆ esc_lt_white

const std::string goby::util::esc_lt_white = "\33[97m"

Definition at line 50 of file term_color.h.

◆ esc_lt_yellow

const std::string goby::util::esc_lt_yellow = "\33[93m"

Definition at line 42 of file term_color.h.

◆ esc_magenta

const std::string goby::util::esc_magenta = "\33[35m"

Definition at line 45 of file term_color.h.

◆ esc_nocolor

const std::string goby::util::esc_nocolor = "\33[0m"

Definition at line 51 of file term_color.h.

◆ esc_red

const std::string goby::util::esc_red = "\33[31m"

Definition at line 37 of file term_color.h.

◆ esc_white

const std::string goby::util::esc_white = "\33[37m"

Definition at line 49 of file term_color.h.

◆ esc_yellow

const std::string goby::util::esc_yellow = "\33[33m"

Definition at line 41 of file term_color.h.

◆ NaN

template<class T >
constexpr T goby::util::NaN {std::numeric_limits<T>::quiet_NaN()}
constexpr

Definition at line 37 of file constants.h.

◆ pi

template<class T >
constexpr T goby::util::pi = T(3.1415926535897932385L)
constexpr

Definition at line 34 of file constants.h.