forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
forest::Misc Class Reference

Static Public Member Functions

static char cflush (istream &, char)
 Read up to first occurrence of a given character. More...
 
static char rflush (istream &, char)
 Read up to first character c1 not equal to a specified character. More...
 
static bool verify (istream &, char)
 If next character on input stream is the character c, read it and return true. More...
 
static bool skipBlank (istream &)
 Advance to the first non-blank character, skipping over comments. More...
 
static bool readNum (istream &, int &)
 If next thing on current line is a number, read it into i and return true. More...
 
static bool readNum (istream &, char &)
 
static bool readNum (istream &, uint16_t &)
 
static bool readNum (istream &, uint32_t &)
 If next thing on current line is an unsigned number, read it into i and return true. More...
 
static bool readWord (istream &, string &)
 Read next word (string containing letters, numbers, underscores, @-signs, periods, slashes) on the current line and return it in s. More...
 
static bool readName (istream &, string &)
 Read next name (string containing letters, numbers, underscores, starting with a letter) on the current line and return it in s. More...
 
static bool readString (istream &, string &)
 Read next string (enclosed in double quotes). More...
 
static void addNum2string (string &, int)
 Add the string representation of an integer to the end of a given string. More...
 
static void addNum2string (string &, uint64_t)
 
static string num2string (int)
 Create a string representation of a numeric value. More...
 
static string num2string (uint64_t)
 
static string nstime2string (uint64_t)
 Create a string representation of a time value based on a ns time value. More...
 
static char nam (int)
 Convert a small integer to a lower-case letter. More...
 
static int num (char)
 Convert a lower-case letter to a small integer. More...
 
static bool readNode (istream &, int &, int)
 Read a graph "node" from the input. More...
 
static void writeNode (ostream &, int, int)
 
static bool readAlpha (istream &, int &)
 Read the next non-whitespace character from in. More...
 
static void writeAlpha (ostream &, int)
 Output the character corresponding to the integer x. More...
 
static void addNode2string (string &, int, int)
 Add the string representation of a data structure node to the end of a given string. More...
 
static string node2string (int, int)
 Create a string representation of a data structure node. More...
 
static bool prefix (string, string)
 Return true if s1 is a non-empty substring of s2. More...
 
static void genPerm (int, int *)
 Create random permutation on integers 1..n and return in p.
 
static int strnlen (char *, int)
 Replacement for the missing strnlen function.
 
static time_t currentTime ()
 Return the current time in number of seconds since epoch. More...
 
static uint32_t getTime ()
 Return time expressed as a free-running microsecond clock. More...
 
static uint64_t getTimeNs ()
 Return time expressed as a free-running nanosecond clock. More...
 

Detailed Description

Definition at line 17 of file MiscX.h.

Member Function Documentation

void forest::Misc::addNode2string ( string &  s,
int  u,
int  n 
)
inlinestatic

Add the string representation of a data structure node to the end of a given string.

Parameters
spoints to the string to be extended
uis the node to be added to the end of the string
nis the number of nodes in the data structure; if 1 <= n <= 26, a single lower case character is added to the string; otherwise, the numeric value of u is added

Definition at line 123 of file MiscX.h.

Here is the call graph for this function:

void forest::Misc::addNum2string ( string &  s,
int  i 
)
inlinestatic

Add the string representation of an integer to the end of a given string.

Parameters
spoints to the string to be extended
iis the integer whose value is to be appended to *s

Definition at line 75 of file MiscX.h.

char forest::Misc::cflush ( istream &  in,
char  c 
)
static

Read up to first occurrence of a given character.

Parameters
inis the input stream to read from
cis character to look for
Returns
c or 0, on end-of-file

Definition at line 18 of file Misc.cpp.

Here is the caller graph for this function:

time_t forest::Misc::currentTime ( )
static

Return the current time in number of seconds since epoch.

Definition at line 262 of file Misc.cpp.

Here is the caller graph for this function:

uint32_t forest::Misc::getTime ( )
static

Return time expressed as a free-running microsecond clock.

Uses the gettimeofday system call, but converts result to simple microsecond clock for greater convenience.

Definition at line 274 of file Misc.cpp.

Here is the caller graph for this function:

uint64_t forest::Misc::getTimeNs ( )
static

Return time expressed as a free-running nanosecond clock.

Uses the gettimeofday system call, but converts result to simple nanosecond clock for greater convenience. Would be better if we used Linux clock_gettime functions, but these functions not available on all systems. As a result, we really only get microsecond resolution.

Definition at line 310 of file Misc.cpp.

Here is the caller graph for this function:

char forest::Misc::nam ( int  u)
inlinestatic

Convert a small integer to a lower-case letter.

Parameters
uis an integer in the range 1..26
Returns
the corresponding lower-case letter (1 becomes 'a', 2 becomes 'b', etc)

Definition at line 62 of file MiscX.h.

Here is the caller graph for this function:

string forest::Misc::node2string ( int  u,
int  n 
)
inlinestatic

Create a string representation of a data structure node.

Parameters
uis the node
nis the number of nodes in the data structure; if 1 <= n <= 26, a single lower case character is returned as the string; otherwise, the numeric value of u is added
spoints to the string to be in which the value is returned
returna reference to the modified string

Definition at line 136 of file MiscX.h.

Here is the call graph for this function:

string forest::Misc::nstime2string ( uint64_t  t)
inlinestatic

Create a string representation of a time value based on a ns time value.

The returned string gives the time as seconds and fractions of a second.

Parameters
tis the ns time
sis the string in which the value is to be returned
Returns
a reference to s

Definition at line 105 of file MiscX.h.

Here is the caller graph for this function:

int forest::Misc::num ( char  c)
inlinestatic

Convert a lower-case letter to a small integer.

Parameters
cis a lower-case letter
Returns
the corresponding integer ('a' becomes 1, 'b' becomes 2, etc)

Definition at line 69 of file MiscX.h.

Here is the caller graph for this function:

string forest::Misc::num2string ( int  i)
inlinestatic

Create a string representation of a numeric value.

Parameters
iis the integer whose value to be converted to a string
sis the string in which the value is returned
Returns
a reference to the string

Definition at line 90 of file MiscX.h.

bool forest::Misc::prefix ( string  s1,
string  s2 
)
static

Return true if s1 is a non-empty substring of s2.

Definition at line 67 of file Misc.cpp.

bool forest::Misc::readAlpha ( istream &  in,
int &  x 
)
static

Read the next non-whitespace character from in.

If it is a lower case letter c, make x = (c+1) - 'a'. Otherwise return false. If reach the end of line before finding a non-whitespace character, return false without reading the newline character.

Definition at line 77 of file Misc.cpp.

Here is the call graph for this function:

bool forest::Misc::readName ( istream &  in,
string &  s 
)
static

Read next name (string containing letters, numbers, underscores, starting with a letter) on the current line and return it in s.

Return true on success, false on failure.

Definition at line 126 of file Misc.cpp.

Here is the caller graph for this function:

bool forest::Misc::readNode ( istream &  in,
int &  u,
int  n 
)
static

Read a graph "node" from the input.

Parameters
inis the input stream to read from
cis character to look for
Returns
c1 or 0, on end-of-file

Definition at line 46 of file Misc.cpp.

Here is the call graph for this function:

bool forest::Misc::readNum ( istream &  in,
int &  i 
)
static

If next thing on current line is a number, read it into i and return true.

Otherwise return false.

Definition at line 169 of file Misc.cpp.

Here is the caller graph for this function:

bool forest::Misc::readNum ( istream &  in,
uint32_t &  i 
)
static

If next thing on current line is an unsigned number, read it into i and return true.

Otherwise return false.

Definition at line 185 of file Misc.cpp.

bool forest::Misc::readString ( istream &  in,
string &  s 
)
static

Read next string (enclosed in double quotes).

The string may not contain double quotes.

Parameters
inis an open input string
sis a reference to a string in which result is returned
Returns
true on success, false on failure

Definition at line 152 of file Misc.cpp.

Here is the caller graph for this function:

bool forest::Misc::readWord ( istream &  in,
string &  s 
)
static

Read next word (string containing letters, numbers, underscores, @-signs, periods, slashes) on the current line and return it in s.

Return true on success, false on failure.

Definition at line 104 of file Misc.cpp.

Here is the caller graph for this function:

char forest::Misc::rflush ( istream &  in,
char  c 
)
static

Read up to first character c1 not equal to a specified character.

Parameters
inis the input stream to read from
cis character to look for
Returns
c1 or 0, on end-of-file

Definition at line 32 of file Misc.cpp.

Here is the caller graph for this function:

bool forest::Misc::skipBlank ( istream &  in)
static

Advance to the first non-blank character, skipping over comments.

Leave the non-blank character in the input stream. A comment is anything that starts with the sharp sign '#' and continues to the end of the line. Return false on error or eof.

Definition at line 215 of file Misc.cpp.

Here is the caller graph for this function:

bool forest::Misc::verify ( istream &  in,
char  c 
)
static

If next character on input stream is the character c, read it and return true.

Otherwise, put it back and return false;

Definition at line 230 of file Misc.cpp.

Here is the caller graph for this function:

void forest::Misc::writeAlpha ( ostream &  out,
int  x 
)
static

Output the character corresponding to the integer x.

That is, output ('a'-1)+x. X is assumed to be in [0,26]. If x==0, output "Null".

Definition at line 93 of file Misc.cpp.

Here is the call graph for this function:


The documentation for this class was generated from the following files: