common algorithms, constants and functions More...
#include "types_nl.h"#include <cctype>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <vector>#include <cfloat>#include <cstdarg>#include <cstdlib>#include <algorithm>#include <unistd.h>#include <sys/types.h>#include "string_common.h"Go to the source code of this file.
Classes | |
| class | NLMISC::Exception |
| Base class for all NeL exception. More... | |
Namespaces | |
| namespace | NLMISC |
This namespace contains all miscellaneous classes used by other modules. | |
Defines | |
| #define | breakable switch(1) case 1: default: |
| Read the time stamp counter. | |
| #define | sizeofarray(v) (sizeof(v) / sizeof((v)[0])) |
| #define | nlisprint isprint |
| this wrapping is due to a visual bug when calling isprint with big value example of crash with VC6 SP4: int a = isprint(0x40e208); | |
Functions | |
| float | NLMISC::frand (float mod) |
| Return a float random inside the interval [0,mod]. | |
| sint | NLMISC::fsgn (double f) |
| Return -1 if f<0, 0 if f==0, 1 if f>1. | |
| template<class T > | |
| T | NLMISC::sqr (const T &v) |
| Return the square of a number. | |
| template<class T , class U , class V > | |
| void | NLMISC::clamp (T &v, const U &min, const V &max) |
| Force v to be inside the interval [min,max]. | |
| template<class T > | |
| T | NLMISC::minof (const T &a, const T &b, const T &c) |
| MIN/MAX extended functions. | |
| template<class T > | |
| T | NLMISC::minof (const T &a, const T &b, const T &c, const T &d) |
| template<class T > | |
| T | NLMISC::minof (const T &a, const T &b, const T &c, const T &d, const T &e) |
| template<class T > | |
| T | NLMISC::maxof (const T &a, const T &b, const T &c) |
| template<class T > | |
| T | NLMISC::maxof (const T &a, const T &b, const T &c, const T &d) |
| template<class T > | |
| T | NLMISC::maxof (const T &a, const T &b, const T &c, const T &d, const T &e) |
| template<class T > | |
| void | NLMISC::contReset (T &a) |
contReset take a container like std::vector or std::deque and put his size to 0 like clear() but free all buffers. | |
| uint | NLMISC::raiseToNextPowerOf2 (uint v) |
| Return the value maximized to the next power of 2 of v. | |
| uint | NLMISC::getPowerOf2 (uint v) |
| Return the power of 2 of v. | |
| bool | NLMISC::isPowerOf2 (sint32 v) |
Return true if the value is a power of 2. | |
| float | NLMISC::degToRad (float deg) |
| Converts from degrees to radians. | |
| float | NLMISC::radToDeg (float rad) |
| Converts from radians to degrees. | |
| double | NLMISC::isValidDouble (double v) |
| Return true if double is a valid value (not inf nor nan). | |
| std::string | NLMISC::toLower (const std::string &str) |
| Convert a string in lower case. | |
| void | NLMISC::toLower (char *str) |
| char | NLMISC::toLower (const char ch) |
| std::string | NLMISC::toUpper (const std::string &str) |
| Convert a string in upper case. | |
| void | NLMISC::toUpper (char *str) |
| template<class T > | |
| T | NLMISC::trim (const T &str) |
| template<class T > | |
| T | NLMISC::trimRightWhiteSpaces (const T &str) |
| std::string & | NLMISC::strlwr (std::string &str) |
| std::string | NLMISC::strlwr (const std::string &str) |
| char * | NLMISC::strlwr (char *str) |
| std::string & | NLMISC::strupr (std::string &str) |
| std::string | NLMISC::strupr (const std::string &str) |
| char * | NLMISC::strupr (char *str) |
| int | NLMISC::stricmp (const char *lhs, const char *rhs) |
| Compare 2 C-Style strings without regard to case. | |
| int | NLMISC::strnicmp (const char *lhs, const char *rhs, size_t n) |
| sint | NLMISC::nlstricmp (const char *lhs, const char *rhs) |
| sint | NLMISC::nlstricmp (const std::string &lhs, const std::string &rhs) |
| sint | NLMISC::nlstricmp (const std::string &lhs, const char *rhs) |
| sint | NLMISC::nlstricmp (const char *lhs, const std::string &rhs) |
| int | NLMISC::nlfseek64 (FILE *stream, sint64 offset, int origin) |
| Signed 64 bit fseek. | |
| sint64 | NLMISC::nlftell64 (FILE *stream) |
| void | NLMISC::nlSleep (uint32 ms) |
| Portable Sleep() function that suspends the execution of the calling thread for a number of milliseconds. | |
| uint | NLMISC::getThreadId () |
| Returns Process Id (note: on Linux, Process Id is the same as the Thread Id). | |
| std::string | NLMISC::stringFromVector (const std::vector< uint8 > &v, bool limited=true) |
| Returns a readable string from a vector of bytes. unprintable char are replaced by '?'. | |
| sint64 | NLMISC::atoiInt64 (const char *ident, sint64 base=10) |
| Convert a string into an sint64 (same as atoi() function but for 64 bits intergers). | |
| void | NLMISC::itoaInt64 (sint64 number, char *str, sint64 base=10) |
| Convert an sint64 into a string (same as itoa() function but for 64 bits intergers). | |
| std::string | NLMISC::bytesToHumanReadable (const std::string &bytes) |
| Convert a number in bytes into a string that is easily readable by an human, for example 105123 -> "102kb". | |
| std::string | NLMISC::bytesToHumanReadable (uint64 bytes) |
| uint32 | NLMISC::humanReadableToBytes (const std::string &str) |
| Convert a human readable into a bytes, for example "102kb" -> 105123. | |
| std::string | NLMISC::secondsToHumanReadable (uint32 time) |
| Convert a time into a string that is easily readable by an human, for example 3600 -> "1h". | |
| uint32 | NLMISC::fromHumanReadable (const std::string &str) |
| Get a bytes or time in string format and convert it in seconds or bytes. | |
| bool | NLMISC::launchProgram (const std::string &programName, const std::string &arguments) |
| This function executes a program in the background and returns instantly (used for example to launch services in AES). | |
| bool | NLMISC::killProgram (uint32 pid) |
| This function kills a program using his pid (on unix, it uses the kill() POSIX function). | |
| bool | NLMISC::abortProgram (uint32 pid) |
| This function kills a program using his pid with abort signal (on unix, it uses the kill() POSIX function). | |
| template<class T > | |
| void | NLMISC::explode (const T &src, const T &sep, std::vector< T > &res, bool skipEmpty=false) |
| Returns a string corresponding to the class T in string format. | |
| void | NLMISC::displayByteBits (uint8 b, uint nbits, sint beginpos, bool displayBegin, NLMISC::CLog *log) |
| Display the bits (with 0 and 1) composing a byte (from right to left). | |
| void | NLMISC::displayDwordBits (uint32 b, uint nbits, sint beginpos, bool displayBegin, NLMISC::CLog *log) |
| Display the bits (with 0 and 1) composing a number (uint32) (from right to left). | |
| bool | NLMISC::openURL (const char *url) |
| bool | NLMISC::openDoc (const char *document) |
| float | NLMISC::favoid0 (float x) |
| double | NLMISC::davoid0 (double x) |
| template<class T > | |
| T | NLMISC::iavoid0 (T x) |
Variables | |
| const double | NLMISC::Pi = 3.1415926535897932384626433832795 |
| Pi constant in double format. | |
common algorithms, constants and functions
Definition in file common.h.
| #define breakable switch(1) case 1: default: |
Read the time stamp counter.
Supports only Intel architectures for now breakable statement, used to allow break call inside parenthesis.
Definition at line 83 of file common.h.
Referenced by NLMISC::CI18N::_readTextFile(), and NLMISC::CSString::decodeXML().
| #define nlisprint isprint |
Definition at line 93 of file common.h.
Referenced by NL3D::CPSUtil::displayArrow(), NL3D::CPackedZone16::render(), NL3D::CPackedZone32::render(), and NLNET::CStdinMonitorThread::run().
1.6.1