functions.h File Reference

Contains mainly string conversation methods. More...

Go to the source code of this file.

Functions

DECLSPEC const char * intToStr (int i, int base=10)
DECLSPEC char * intToStr (int i, char *buf, int base=10)
DECLSPEC char * uintToStr (unsigned int i, char *buf, unsigned int base=10)
DECLSPEC Uint32 xStrToUL (const char *str, bool *err=NULL)
DECLSPEC SDL_Rect strToRect (const char *str)
DECLSPEC bool strToBool (const char *s)
DECLSPEC Uint32 strToIP (const char *str)
DECLSPEC IPaddress strToIPaddress (const char *str)
DECLSPEC SDLKey strToKey (const char *str)
DECLSPEC SDLMod strToMod (const char *str)
DECLSPEC int byteToStr (Uint8 b, char *buf)
DECLSPEC const char * IPToStr (Uint32 ip, char *buf)
DECLSPEC const char * IPToStr (const IPaddress &ip, char *buf)
DECLSPEC SDL_Color ULToColor (Uint32 v)
DECLSPEC const char * getUserDirectory ()
DECLSPEC std::string makeEnvStr (const char *str)
DECLSPEC std::string makeEnvPath (const char *str)
DECLSPEC bool patMatch (const char *pattern, const char *string)
DECLSPEC bool patiMatch (const char *pattern, const char *string)
char * getLocalIP (bool bIPv4=true)


Detailed Description

Contains mainly string conversation methods.

Required header file:

 #include <functions.h> 

With including this file you get all important string conversation methods, that are used by the Netrinjo engine. You can convert numbers, boolean expressions, IP-addresses and colors in both ways to a string and from a string.

Furthermore the function getUserDirectory is declared here.

Used Abbreviation:
NBO: Network Byte Order


Function Documentation

DECLSPEC int byteToStr ( Uint8  b,
char *  buf 
)

Converts a byte to a string.

Parameters:
b The number to convert
buf Pointer to reserved space, where the number will be stored in form of a string
Returns:
the number of affected chars in buf

char* getLocalIP ( bool  bIPv4 = true  ) 

Gets the local IP-address (only for UNIX-based platforms).

Parameters:
bIPv4 if true, IPv4-addresses are prefered; otherwise IPv6-addresses this does not guarantee, that the result is of that kind.
Returns:
a NUL-terminated string, containing the local IP-address.
Note:
the result will never be "127.0.0.1". If the computer is connected to more than one network, the result is one of the assigned addresses.
Author:
code taken from http://www.hungry.com/~alves/local-ip-in-C.html, but modified a little.

DECLSPEC const char* getUserDirectory (  ) 

Returns:
the directory of the user, who executes the app (e.g.: "/home/username")

DECLSPEC char* intToStr ( int  i,
char *  buf,
int  base = 10 
)

Converts an integer value to a string. This function is thread safe.

Warning:
intToStr does mostly not return the param buf!
Parameters:
i The number to convert
buf A pointer to reserved space of at least 33 characters
base The base to use, if it's less than 2, 2 will be used; if it's above 36, 36 will be used.
Returns:
a pointer to the string with the converted number, usually not equal to buf.

DECLSPEC const char* intToStr ( int  i,
int  base = 10 
)

Converts an integer value to a string.

Warning:
This is not thread-safe, use intToStr( int i, char *buf, int base ) instead, if you need thread safity.
Parameters:
i The number to convert
base The base to use, if it's less than 2, 2 will be used; if it's above 36, 36 will be used.
Returns:
a pointer to the string with the converted number; the result points to a static variable, so you have to use the result before calling this function again.

DECLSPEC const char* IPToStr ( const IPaddress &  ip,
char *  buf 
)

Converts an IP address (in NBO) with the portnumber to a string in the following format:

 <a>.<b>.<c>.<d>:<Port> 
Parameters:
ip The IP address to convert
buf Pointer to reserved space, where the IP address will be stored
Returns:
buf

DECLSPEC const char* IPToStr ( Uint32  ip,
char *  buf 
)

Converts an IP address (in NBO) without the portnumber to a string in the following format:

 <a>.<b>.<c>.<d> 
Parameters:
ip The IP address to convert
buf Pointer to reserved space, where the IP address will be stored
Returns:
buf

DECLSPEC std::string makeEnvPath ( const char *  str  ) 

Does the same as makeEnvStr(), but replaces a leading "~/" by the user's home directory. E.g: "~/.netrinjo" will become "/home/username/.netrinjo", if the user's home is at "/home/username".

Parameters:
str the string to parse
Returns:
the string with the replaced data

DECLSPEC std::string makeEnvStr ( const char *  str  ) 

Replaces the ocurrencies of "$(...)" with the content of the specified environment variable. E.g.: "$(USERNAME)" will be replaced by the user's name.

Parameters:
str the string to parse
Returns:
the string with the replaced data

DECLSPEC bool patiMatch ( const char *  pattern,
const char *  string 
)

Case-insensitive pattern match

Parameters:
pattern the pattern
string the string, that is checked to match the pattern
Returns:
true if string matches the pattern, false if not
Author:
member "Mik" at http://www.linuxquestions.org/

DECLSPEC bool patMatch ( const char *  pattern,
const char *  string 
)

Case-sensitive pattern match

Parameters:
pattern the pattern
string the string, that is checked to match the pattern
Returns:
true if string matches the pattern, false if not
Author:
member "Mik" at http://www.linuxquestions.org/

DECLSPEC bool strToBool ( const char *  s  ) 

Converts a string to a boolean value.

Parameters:
s The string to read (case insensitive)
Returns:
true if s is: "+", "1", "true", "yes" or "y", false otherwise

DECLSPEC Uint32 strToIP ( const char *  str  ) 

Converts a string to an IPv4-value (in NBO),

Parameters:
str can either be a single decimal number or consist of 4 decimal byte-numbers, separated by a '.' (no spaces/tabs allowed)
Returns:
the IP address in network-byte-order

DECLSPEC IPaddress strToIPaddress ( const char *  str  ) 

Converts a string to an IPv4-address-value (in NBO) like strToIP(..) if there is a ':' in the string, the number behind the ':' is read as the port.

Parameters:
str The string to convert.
Returns:
The IP address, represented by str.

DECLSPEC SDLKey strToKey ( const char *  str  ) 

Converts a string to a SDLKey value.

Parameters:
str The string to convert.
Returns:
The SDL_Key, represented by str.

DECLSPEC SDLMod strToMod ( const char *  str  ) 

Converts a string to a key modifier (may be a combination, separated by '+').

Parameters:
str The string to convert.
Returns:
The key modifier, represented by str.

DECLSPEC SDL_Rect strToRect ( const char *  str  ) 

Todo:
verify ',' as separator

DECLSPEC char* uintToStr ( unsigned int  i,
char *  buf,
unsigned int  base = 10 
)

Converts an unsigned integer value to a string. This function is thread safe. See intToStr( int i, char *buf, int base ) for more information.

DECLSPEC SDL_Color ULToColor ( Uint32  v  ) 

Converts an unsigned integer value to a SDL_Color-value.

Parameters:
v The number to convert: the blue-value is the lowest byte, green is middle-value, red-value is 2nd-highest (bits 16..23), the highest byte is ignored
Returns:
The value in form of a color

DECLSPEC Uint32 xStrToUL ( const char *  str,
bool *  err = NULL 
)

Converts a string to an unsigned long value, the base is usually 10, but it changes, if the number-string has a special prefix:

prefix => base
0q, q => 4
0, 0o, o => 8
0x, x, #, h, $ => 16
0b, b => 2
0d, d => 10
Parameters:
str The string to convert.
err is assigned true, if the string could not be converted, otherwise false is assigned; if it is NULL, it is ignored
Returns:
The number, that str represents.


Generated on Wed May 9 17:35:57 2007 for netrinjo by  doxygen 1.5.1