Scopira 20080306

scopira::tool Namespace Reference

Classes

class  archiveiflow
class  archiveoflow
class  array_view
class  const_array_view
class  basic_array
class  basic_matrix
class  fixed_array
class  hybrid_array
class  biniflow
class  binoflow
class  bin64iflow
class  bin64oflow
class  bufferflow
class  bufferiflow
class  bufferoflow
class  circular_vector
class  cacheiflow
class  cacheoflow
class  const_mod
class  const_mod< unsigned int, 0 >
class  const_mod< unsigned long, 0 >
class  const_mod< uint64_t, uint64_t(1)<< 48 >
class  dir_iterator
class  teeoflow
class  distoflow
class  uni01_dist
class  unireal_dist
class  unismallint_dist
class  uniint_dist
class  dll
class  file
class  fileflow
class  read_flocker
class  write_flocker
class  filememory
class  flow_i
class  iflow_i
class  oflow_i
class  itflow_i
class  otflow_i
class  iobjflow_i
class  oobjflow_i
class  hashoflow
class  hexiflow
class  hexoflow
class  iterator_imp_g
class  null_iterator_imp_g
class  iterator_g
struct  deref
struct  deref_first
struct  deref_second
struct  deref_ptr
struct  deref_objauto
class  stl_iterator_imp_g
class  lincon_gen
class  rand48
class  mutex
class  locker
class  netaddr
class  nethostrec
class  netflow
class  net_loop
class  udpflow
class  unixflow
class  nullflow
class  countoflow
class  object
class  count_ptr
class  count2_ptr
class  objrefcounter
class  objflowloader
class  register_flow
class  output_stack
class  polyiflow
class  polyoflow
class  isoiflow
class  isooflow
class  printiflow
class  printoflow
class  property
class  property_node
class  commentiflow
class  propiflow
class  propoflow
class  sysdev_gen
class  sysrand_gen
class  sysrandom_gen
class  destroy_reactor_i
class  update_reactor_i
class  rename_reactor_i
class  regmatch
class  regex
class  singleton
class  stringflow
class  stringiflow
class  stringoflow
class  textiflow
class  textoflow
class  runnable_i
class  job_i
class  thread
class  condition
class  rwlock
class  read_locker
class  write_locker
class  shared_area
class  event_area
class  rw_area
class  area_ptr
class  const_area_ptr
class  locker_ptr
class  event_ptr
class  read_locker_ptr
class  write_locker_ptr
class  timespan
class  timestamp
class  chrono
class  flowtraits_base_g
class  flowtraits_g
class  flowtraits_g< bool >
 specialization: bool More...
class  flowtraits_g< unsigned char >
 specialization: unsigned char More...
class  flowtraits_g< char >
 specialization: char More...
class  flowtraits_g< short >
 specialization: short More...
class  flowtraits_g< int >
 specialization: int More...
class  flowtraits_g< int64_t >
 specialization: long More...
class  flowtraits_g< float >
 specialization: float More...
class  flowtraits_g< double >
 specialization: double More...
class  flowtraits_g< std::string >
class  flowtraits_g< std::vector< EE > >
class  treenode
class  url
class  uuid
class  uuid_generator
class  xml_doc
class  xml_node
class  xml_attrib

Typedefs

typedef uni01_dist< lincon_corelincon_01
typedef unireal_dist< lincon_corelincon_real
typedef unismallint_dist
< lincon_core
lincon_smallint
typedef uniint_dist< lincon_corelincon_int
typedef uni01_dist
< scopira::tool::rand48
rand48_01
typedef unireal_dist
< scopira::tool::rand48
rand48_real
typedef unismallint_dist
< scopira::tool::rand48
rand48_smallint
typedef uniint_dist
< scopira::tool::rand48
rand48_int
typedef unsigned char byte_t
typedef lincon_gen< int, 16807, 0, 2147483647, 1043618065 > minstd_rand0
typedef lincon_gen< int, 48271, 0, 2147483647, 399268537 > minstd_rand
typedef minstd_rand0 lincon_core
 a typical random core
typedef int socket_handle_t
typedef scopira::tool::oflow_i &(* output_func )(void)
typedef void *(* runfunc_t )(void *)

Enumerations

enum  { copy_c = 0, copysoftlink_c = 1, copyhardlink_c = 2 }

Functions

const char * get_username (void)
 gets the username of the logged in system, may return "" (but never null)
const char * get_homedir (void)
 gets the user's home directory, may return "." (but never null)
bool copy_file (const std::string &srcfile, const std::string &destfile, short copytype=copy_c)
std::string hexhash (const scopira::tool::basic_array< byte_t > &hash)
std::string close_and_hexhash (hashoflow &o)
std::string hexhash_string (const std::string &s, int type=scopira::tool::hashoflow::sha1_c)
bool is_hex (char c)
 returns true if this is a hex char
byte_t char_to_hex (char c)
 converts a '0'..'F' (or '0'..'f') to 0-15
std::string get_hostname (void)
 gets the hostname of this machine
bool hostname_to_hostrec (const std::string &hname, nethostrec &rec)
 looks up the hname, and saves into rec, returns true on success
template<class T >
objectobjloadfunc_g (void)
void flow_reg_imp (const std::type_info &id, const char *name, scopira::tool::objflowloader::loadfunc_t loader)
scopira::tool::oflow_itool_output (void)
void flow_printf (oflow_i &o, const char *fmt,...)
 printf style
int time_seed (void)
template<class GEN >
double next_double (GEN &g, double mx)
template<class GEN >
double next_double (GEN &g)
template<class T >
void qsort (T &s, int lo0, int hi0)
int num_system_cpus (void)
intptr_t ptr_to_int (const void *ptr)
template<class C >
C * int_to_ptr (intptr_t x)
void * int_to_void (intptr_t x)
std::string bool_to_string (bool val)
void int_to_string (bool val, std::string &out)
std::string int_to_string (int i)
void int_to_string (int i, std::string &out)
int int_to_string (int i, char *out, int buflen)
int string_to_int (const std::string &s)
bool string_to_int (const std::string &s, int &outint)
std::string long_to_string (long i)
void long_to_string (long i, std::string &out)
long string_to_long (const std::string &s)
bool string_to_long (const std::string &s, long &outlong)
std::string size_t_to_string (size_t i)
void size_t_to_string (size_t i, std::string &out)
size_t string_to_size_t (const std::string &s)
bool string_to_size_t (const std::string &s, size_t &outsize_t)
std::string int64_t_to_string (int64_t i)
void int64_t_to_string (int64_t i, std::string &out)
int64_t string_to_int64_t (const std::string &s)
bool string_to_int64_t (const std::string &s, int64_t &outint64_t)
std::string double_to_string (double i)
void double_to_string (double i, std::string &out)
std::string double_to_string (double i, int pres)
int double_to_string (double i, char *out, int buflen)
std::string double_to_exp_string (double i, int pres=25)
double string_to_double (const std::string &s)
bool string_to_double (const std::string &s, double &outdouble)
template<class T >
char compare (const T &lhs, const T &rhs)
void uppercase (const std::string &s, std::string &upper)
std::string uppercase (const std::string &s)
void lowercase (const std::string &s, std::string &lower)
std::string lowercase (const std::string &s)
std::string pad_left (const std::string &s, int width, char padchar= ' ')
void impl_cstring_to_fixed_array_impl (const char *in, size_t srclen, char *out, size_t N) throw ()
template<size_t N>
void string_to_fixed_array (const std::string &src, fixed_array< char, N > &out) throw ()
template<size_t N>
void c_string_to_fixed_array (const char *in, fixed_array< char, N > &out) throw ()
bool split_char (const std::string &src, char split, std::string &left_out, std::string &right_out)
std::string filename_number (const std::string &fname, int num)
void trim_left (std::string &str)
void trim_right (std::string &str)
template<class container >
void string_tokenize_word (const std::string &src, container &result, const std::string &substr)
template<class container >
void string_tokenize (const std::string &src, container &result, const std::string &delimiters=" \t\n")
template<class T >
byte_swap (T x)
template<>
short byte_swap< short > (short x)
template<>
int byte_swap< int > (int x)
template<>
int64_t byte_swap< int64_t > (int64_t x)
template<>
uint64_t byte_swap< uint64_t > (uint64_t x)
template<>
float byte_swap< float > (float x)
template<>
double byte_swap< double > (double x)
template<class ITER >
void byte_swap_all (ITER head, ITER tail)

Variables

const char * dll_ext_c
 either .DLL or .SO
const char dir_seperator_c = '/'
const char * hexchars
 array of the 16 digits of hex
const char * lowerhexchars
 array of the 16 digits of hex (lowercase, which you should probably prefer)
scopira::tool::output_func gm_tool_output
scopira::tool::oflow_igm_tool_output_stream

Detailed Description

The scopira::tool namespace contains scopira-independant utitlies, like autopointers, virtual stream system (with file and network support), threads, property files and a simple vector template.

Author:
Aleksander Demko

Typedef Documentation

typedef lincon_gen<int, 48271, 0, 2147483647, 399268537> scopira::tool::minstd_rand

cycle length: 2^31-2 a typical generator type (lincon_gen + some template paramters)

typedef lincon_gen<int, 16807, 0, 2147483647, 1043618065> scopira::tool::minstd_rand0

a typical generator type (lincon_gen + some template paramters) cycle length: 2^31-2

A function type that returns an output stream

Author:
Aleksander Demko
typedef void *(* scopira::tool::runfunc_t)(void *)

a function thet can be called by a thread run routine you should return 0, i guess


Function Documentation

std::string scopira::tool::bool_to_string ( bool  val) [inline]

Converts a bool to a string

Parameters:
valthe bool value
Returns:
the string representation of the bool
Author:
Rodrigo Vivanco
template<class T >
T scopira::tool::byte_swap ( x) [inline]

Generic byte swapper. Does nothing.

Author:
Aleksander Demko

Referenced by byte_swap_all().

template<>
double scopira::tool::byte_swap< double > ( double  x) [inline]

Swaps the byte (endianess) of an double.

Author:
Aleksander Demko
template<>
float scopira::tool::byte_swap< float > ( float  x) [inline]

Swaps the byte (endianess) of an float.

Author:
Aleksander Demko
template<>
int scopira::tool::byte_swap< int > ( int  x) [inline]

Swaps the byte (endianess) of an int. Currently only used in binflow.

Author:
Aleksander Demko
template<>
int64_t scopira::tool::byte_swap< int64_t > ( int64_t  x) [inline]

Swaps the byte (endianess) of an int64_t.

Author:
Aleksander Demko
template<>
short scopira::tool::byte_swap< short > ( short  x) [inline]

Swaps the byte (endianess) of a short. Currently only used in binflow.

Author:
Aleksander Demko
template<>
uint64_t scopira::tool::byte_swap< uint64_t > ( uint64_t  x) [inline]

Swaps the byte (endianess) of an uint64_t.

Author:
Aleksander Demko
template<class ITER >
void scopira::tool::byte_swap_all ( ITER  head,
ITER  tail 
)
template<size_t N>
void scopira::tool::c_string_to_fixed_array ( const char *  in,
fixed_array< char, N > &  out 
) throw () [inline]

Copies null terminated C string to a fixed_array<char, N>. The destination will always be null terminated and well formed.

Author:
Aleksander Demko
std::string scopira::tool::close_and_hexhash ( hashoflow &  o)

Closes the given hashoflow and returns the hash, as a hex string

Author:
Aleksander Demko
template<class T >
char scopira::tool::compare ( const T &  lhs,
const T &  rhs 
)

A generic "compare" method. returns -1 if lhs is < than rhs, -1 of rhs<lhs else 0. (so you only need to implement <)

Author:
Aleksander Demko
bool scopira::tool::copy_file ( const std::string &  srcfile,
const std::string &  destfile,
short  copytype = copy_c 
)

Copies the given srcfile to the given destination (file or dir). Copytype can be linking instead (only used under UNIX)

Author:
Aleksander Demko
std::string scopira::tool::double_to_exp_string ( double  i,
int  pres = 25 
)

Converts a double to string - exponential edition

Parameters:
ithe double
presthe number digits, 25 by default
Returns:
a string version of the double
Author:
Aleksander Demko
std::string scopira::tool::double_to_string ( double  i)

Converts a double to string

Parameters:
ithe double
Returns:
a string version of the double
Author:
Aleksander Demko

Referenced by double_to_string().

void scopira::tool::double_to_string ( double  i,
std::string &  out 
) [inline]

Converts a double to string

Parameters:
ithe double
outthe string to write out to
Author:
Aleksander Demko

References double_to_string().

int scopira::tool::double_to_string ( double  i,
char *  out,
int  buflen 
)

Converts a double to string.

Parameters:
ithe double in question
outthe output buffer, must be non-null
buflenthe length of the buffer, including null
Returns:
the actualy length written, including null
Author:
Aleksander Demko
std::string scopira::tool::double_to_string ( double  i,
int  pres 
)

Converts a double to string, with precision

Parameters:
ithe double
presthe number of post-decimal point digits
Returns:
a string version of the double
Author:
Aleksander Demko
std::string scopira::tool::filename_number ( const std::string &  fname,
int  num 
)

Meshes a number into a filename mast. For example, "blah###" and 20 produces "blah020".

Parameters:
fnamethe input string, possibly containing the ## mast
numthe number to mesh in
Returns:
the result of the mesh
Author:
Aleksander Demko
std::string scopira::tool::hexhash ( const scopira::tool::basic_array< byte_t > &  hash)

Returns the string representation of the given hash.

Author:
Aleksander Demko
std::string scopira::tool::hexhash_string ( const std::string &  s,
int  type = scopira::tool::hashoflow::sha1_c 
)

Returns a hex hash of the given string

Author:
Aleksander Demko
std::string scopira::tool::int64_t_to_string ( int64_t  i)

Converts an int64_t to a string

Parameters:
ithe int64_t
Returns:
the string representation of the int64_t
Author:
Aleksander Demko

Referenced by int64_t_to_string().

void scopira::tool::int64_t_to_string ( int64_t  i,
std::string &  out 
) [inline]

Converts an int64_t to a string. Write out to an existing string

Parameters:
ithe int64_t
outthe string to save the convertion to
Author:
Aleksander Demko

References int64_t_to_string().

template<class C >
C* scopira::tool::int_to_ptr ( intptr_t  x) [inline]

Converts a int to a pointer. See glib's GINT_TO_POINTER.

Author:
Aleksander Demko
int scopira::tool::int_to_string ( int  i,
char *  out,
int  buflen 
)

Converts a int to string.

Parameters:
ithe int in question
outthe output buffer, must be non-null
buflenthe length of the buffer, including null
Returns:
the actualy length written, including null
Author:
Aleksander Demko
void scopira::tool::int_to_string ( bool  val,
std::string &  out 
) [inline]

Converts a bool to a string. Write out to an existing string

Parameters:
valthe bool value
outthe string to save the convertion to
Author:
Rodrigo Vivanco

Referenced by int_to_string().

std::string scopira::tool::int_to_string ( int  i)

Converts an int to a string

Parameters:
ithe integer
Returns:
the string representation of the integer
Author:
Aleksander Demko
void scopira::tool::int_to_string ( int  i,
std::string &  out 
) [inline]

Converts an int to a string. Write out to an existing string

Parameters:
ithe integer
outthe string to save the convertion to
Author:
Aleksander Demko

References int_to_string().

void* scopira::tool::int_to_void ( intptr_t  x) [inline]

See glib's GINT_TO_POINTER - fixed to void*.

Author:
Aleksander Demko
std::string scopira::tool::long_to_string ( long  i)

Converts an long to a string

Parameters:
ithe long
Returns:
the string representation of the long
Author:
Aleksander Demko

Referenced by long_to_string().

void scopira::tool::long_to_string ( long  i,
std::string &  out 
) [inline]

Converts an long to a string. Write out to an existing string

Parameters:
ithe long
outthe string to save the convertion to
Author:
Aleksander Demko

References long_to_string().

std::string scopira::tool::lowercase ( const std::string &  s)

Converts a string to lowercase

Parameters:
sthe input string
Returns:
the lowercase'd string
Author:
Aleksander Demko
void scopira::tool::lowercase ( const std::string &  s,
std::string &  lower 
)

Converts a string to lower case. You may use the same string for both parameters

Parameters:
sthe input string
lowerthe lowercase'd string
Author:
Aleksander Demko
template<class GEN >
double scopira::tool::next_double ( GEN &  g,
double  mx 
)

Returns an double from [0..max).

Author:
Aleksander Demko
template<class GEN >
double scopira::tool::next_double ( GEN &  g)

Returns an double from [0..1).

Author:
Aleksander Demko
int scopira::tool::num_system_cpus ( void  )

Gets the number of processors in this system. 1 is returned on platforms where this could not be easily detected.

Author:
Aleksander Demko
std::string scopira::tool::pad_left ( const std::string &  s,
int  width,
char  padchar = ' ' 
)

Justifies a string. If the given string is not width characters long, it will (left) pad the string with padchar and return that.

Parameters:
sthe string to inspect
widthwith minimum width of the final string
padcharthe character to use for left padding
Returns:
the possibly padded string
Author:
Aleksander Demko
intptr_t scopira::tool::ptr_to_int ( const void *  ptr) [inline]

Converts a pointer to an int. Useful for unpacking ints where only a pointer could live. See glib's GPOINTER_TO_INT.

Author:
Aleksander Demko
template<class T >
void scopira::tool::qsort ( T &  s,
int  lo0,
int  hi0 
)

This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.

If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

The sortable object must have the following form: int compare_element(int lidx, int ridx) [const] void swap_element(int lidx, int ridx)

Parameters:
sthe sortable object
lo0left boundary of array partition, initially use 0
hi0right boundary of array partition, initially use size-1
Author:
Aleksander Demko

References qsort().

Referenced by qsort().

void scopira::tool::size_t_to_string ( size_t  i,
std::string &  out 
) [inline]

Converts an size_t to a string. Write out to an existing string

Parameters:
ithe size_t
outthe string to save the convertion to
Author:
Aleksander Demko

References size_t_to_string().

std::string scopira::tool::size_t_to_string ( size_t  i)

Converts an size_t to a string

Parameters:
ithe size_t
Returns:
the string representation of the size_t
Author:
Aleksander Demko

Referenced by size_t_to_string().

bool scopira::tool::split_char ( const std::string &  src,
char  split,
std::string &  left_out,
std::string &  right_out 
)

Splits a string into two along a split character.

Parameters:
srcthe string to inspect
splitthe character to use as the split marker
left_outon success, this will be the left side of the split
right_outon success, this will be the right side of the split
Returns:
true if the split character and the string was split
Author:
Aleksander Demko
bool scopira::tool::string_to_double ( const std::string &  s,
double &  outdouble 
)

Convert a string to a double (reports failure)

Parameters:
sthe string
outdoublethe decoded double
Returns:
true on success, false on failure
Author:
Aleksander Demko
double scopira::tool::string_to_double ( const std::string &  s)

Convert a string to a double (doesn't report failure)

Parameters:
sthe string
Returns:
the decoded double
Author:
Aleksander Demko
template<size_t N>
void scopira::tool::string_to_fixed_array ( const std::string &  src,
fixed_array< char, N > &  out 
) throw () [inline]

Copies std::string to a fixed_array<char, N>. The destination will always be null terminated and well formed.

Author:
Aleksander Demko
bool scopira::tool::string_to_int ( const std::string &  s,
int &  outint 
)

Converts a string to an int, and reports failure, if any

Parameters:
sthe string to convert
outintthe int read from the string
Returns:
true on success
Author:
Aleksander Demko
int scopira::tool::string_to_int ( const std::string &  s)

Converts a string to an int (without reporting failure)

Parameters:
sthe string to convert
Returns:
the integer representation of the string
Author:
Aleksander Demko
int64_t scopira::tool::string_to_int64_t ( const std::string &  s)

Converts a string to an int64_t (without reporting failure)

Parameters:
sthe string to convert
Returns:
the int64_t representation of the string
Author:
Aleksander Demko
bool scopira::tool::string_to_int64_t ( const std::string &  s,
int64_t &  outint64_t 
)

Converts a string to an int64_t, and reports failure, if any

Parameters:
sthe string to convert
outint64_tthe int64_t read from the string
Returns:
true on success
Author:
Aleksander Demko
long scopira::tool::string_to_long ( const std::string &  s)

Converts a string to an long (without reporting failure)

Parameters:
sthe string to convert
Returns:
the long representation of the string
Author:
Aleksander Demko
bool scopira::tool::string_to_long ( const std::string &  s,
long &  outlong 
)

Converts a string to an long, and reports failure, if any

Parameters:
sthe string to convert
outlongthe long read from the string
Returns:
true on success
Author:
Aleksander Demko
size_t scopira::tool::string_to_size_t ( const std::string &  s)

Converts a string to an size_t (without reporting failure)

Parameters:
sthe string to convert
Returns:
the size_t representation of the string
Author:
Aleksander Demko
bool scopira::tool::string_to_size_t ( const std::string &  s,
size_t &  outsize_t 
)

Converts a string to an size_t, and reports failure, if any

Parameters:
sthe string to convert
outsize_tthe size_t read from the string
Returns:
true on success
Author:
Aleksander Demko
template<class container >
void scopira::tool::string_tokenize ( const std::string &  src,
container &  result,
const std::string &  delimiters = " \t\n" 
)

Splits and tokenizes a string into zero or more parts.

Parameters:
containingthe container type (often implicit)
srcthe string to tokenize
resultthe container of strings that will be filled with the output tokens. It will initially be cleared.
delimitersone or more delimiters to use. Default is space, tab and newline.
Author:
Aleksander Demko
template<class container >
void scopira::tool::string_tokenize_word ( const std::string &  src,
container &  result,
const std::string &  substr 
)

splits a string using the provided sub-string the string is only split using the sub-string provided

Author:
Aleksander Demko
int scopira::tool::time_seed ( void  )

returns a "random" number, usefull for initing (this is usually time(), so its not random at all. it might have some pid stuff thrown in

Author:
Aleksander Demko
scopira::tool::oflow_i& scopira::tool::tool_output ( void  )

Default tool_output stream handler.

This one simply returns gm_tool_output_stream. Since that's initially null, it will also set it if need be (while emitting a warning) just to simplify things.

Author:
Aleksander Demko

Referenced by scopira::tool::output_stack::output_stack().

void scopira::tool::trim_left ( std::string &  str)

trims whitespace from the left side of the string

Parameters:
strstring to trim whitespace from
Author:
Aleksander Demko
void scopira::tool::trim_right ( std::string &  str)

trims whitespace from the right side of the string

Parameters:
strstring to trim whitespace from
Author:
Aleksander Demko
void scopira::tool::uppercase ( const std::string &  s,
std::string &  upper 
)

Converts a string to upper case. You may use the same string for both parameters

Parameters:
sthe input string
upperthe uppercase'd string
Author:
Aleksander Demko
std::string scopira::tool::uppercase ( const std::string &  s)

Converts a string to uppercase

Parameters:
sthe input string
Returns:
the uppercase'd string
Author:
Aleksander Demko

Variable Documentation

General output string, useful for debug messages.

By default, this will be set to _tool_output(). You (well, engines) will often set this to something else.

This returns a general, global thread where you can send output to. Under a true engine, this will be engine::get_outflow(), but may be something else under different environments.

Author:
Aleksander Demko

Referenced by scopira::tool::output_stack::output_stack().

The stream pointer used by the default handler, tool_output.

You may set this (while leaving the default handler) if you'd like. Take care to clean up whatever instance you place here.

Author:
Aleksander Demko

Referenced by scopira::tool::output_stack::output_stack().