ANNA Suite
2020b
Multipurpose development suite for Telco applications
|
#include <functions.hpp>
Classes | |
struct | IPv4Type |
struct | TextHighlightMode |
struct | TextJustifyMode |
Static Public Member Functions | |
static std::string | getVersion () |
static std::string | getArchitecture () |
static std::string | asString (const int number) |
static std::string | asString (const unsigned int number) |
static std::string | asString (const S64 number) |
static std::string | asString (const U64 number) |
static const char * | asString (const bool _bool) |
static std::string | asString (const DataBlock &dataBlock, const int characterByLine=16) |
static std::string | asString (const double v, const char *format="%e") |
static std::string | asString (const float v, const char *format="%f") |
static std::string | asText (const char *comment, const int number) |
static std::string | asText (const char *comment, const S64 number) |
static std::string | asText (const char *comment, const bool _bool) |
static std::string | asText (const char *comment, const DataBlock &dataBlock, const int characterByLine=16) |
static std::string | asText (const char *comment, const float value, const char *format="%f") |
static std::string | asText (const char *comment, const double value, const char *format="%e") |
static std::string | asHexString (const int number) |
static std::string | asHexString (const S64 number) |
static std::string | asHexString (const U64 number) |
static std::string | asHexText (const char *comment, const int number) |
static std::string | asHexText (const char *comment, const S64 number) |
static std::string | asHexString (const DataBlock &dataBlock) |
static DataBlock & | fromHexString (const std::string &hexString, DataBlock &target) noexcept(false) |
static std::string | asDateTime (const Second &second) |
static const char * | asDateTime (const Second &second, char *result) |
static S64 | hash (const char *str) |
static S64 | hash (const std::string &str) |
static std::string | asString (const char *format,...) |
template<typename T > | |
static std::string | asString (const T *t) |
static const std::string & | asString (const std::string &str) |
static void | sleep (const Millisecond &millisecond) |
static Second | second () |
static Microsecond | microsecond () |
static Millisecond | millisecond () |
static Microsecond | hardwareClock () |
static bool | asBool (const char *str) noexcept(false) |
static int | asInteger (const char *str) |
static S64 | asInteger64 (const char *str) |
static pthread_t | getCurrentThread () |
static bool | supportMultithread () |
static bool | isLike (const char *pattern, const std::string &value) noexcept(false) |
static int | bitsize (const int n) |
static int | bitsize (const S64 n) |
static S64 | merge (const char *whatis, const int n1, const int n2, const int bitShift) noexcept(false) |
static int | log2 (const unsigned int v) |
static std::string | entriesAsString (int number, const char *wordForSingular=NULL, const char *wordForPlural=NULL) |
static std::string | justify (const std::string &title, TextJustifyMode::_v mode=TextJustifyMode::Left, char filler=' ') |
static std::string | highlight (const std::string &title, TextHighlightMode::_v mode=TextHighlightMode::Underline, char filler='-', bool appendCR=true) |
static std::string | highlightJustify (const std::string &title, TextHighlightMode::_v hMode=TextHighlightMode::OverAndUnderline, TextJustifyMode::_v jMode=TextJustifyMode::Center, char highlightFiller='=', char justifyFiller=' ', bool appendCR=true) |
static std::string | tab (const std::string &text, int tabSpaces=3) |
template<typename T > | |
static T * | componentByName (const char *className, const char *fromFile, const int fromLine) noexcept(false) |
template<typename T > | |
static T * | component (const char *fromFile, const int fromLine) noexcept(false) |
static bool | endsWith (const std::string &pattern, const std::string &suffix) |
static bool | endsWith (const std::string &pattern, const std::string &suffix, std::string &preffix) |
static bool | startsWith (const std::string &pattern, const std::string &preffix) |
static bool | startsWith (const std::string &pattern, const std::string &preffix, std::string &suffix) |
static std::string | replace (const std::string &text, const char *item, const char *target, bool all=true) |
static std::string | addQuotationMarks (const std::string &str) |
static std::string | addQuotationMarks (const char *str) |
static std::string | addQuotationMarks (const int &integer) |
static std::string | vectorToStringRepresentation (const std::vector< int > &v, const char separator=' ') |
static std::string | vectorToStringRepresentation (const std::vector< std::string > &v, const char separator=' ') |
static std::string | socketLiteralAsString (const std::string &address, int port) |
static std::string | asAsciiString (const char *buffer, int size, bool &isFullyPrintable) |
static std::string | asAsciiString (const char *buffer, int size) |
static std::string | asAsciiString (const DataBlock &db, bool &isFullyPrintable) |
static std::string | asAsciiString (const DataBlock &db) |
static DataBlock | rawIpPresentationAsRaw (const std::string &rawPresentation) noexcept(false) |
static std::string | rawIpPresentationToIpAsString (const std::string &rawPresentation, bool normalize=false) noexcept(false) |
static std::string | rawIpAsRawIpPresentation (const DataBlock &db) noexcept(false) |
static std::string | getHostname () |
static std::string | getDomainname () |
static std::string | getFQDN (const char *hostname=NULL, const char *domainname=NULL) |
static std::string | getHostnameIP () |
static bool | isIPv4 (const std::string &ip, IPv4Type::_v ipv4Type=IPv4Type::Estrict) |
static bool | isIPv6 (const std::string &ip) |
static std::string | IPv4To6 (const std::string &ipv4) noexcept(false) |
static std::string | normalizeIP (const std::string &ip) noexcept(false) |
static bool | sameIP (const std::string &ip1, const std::string &ip2) noexcept(false) |
static bool | matchIPv6 (const std::string &ipv6, const std::string &preffixedIpv6) noexcept(false) |
static DataBlock | ipAsRaw (const std::string &ip) noexcept(false) |
static std::string | rawIpAsString (const DataBlock &db, bool normalize=false) noexcept(false) |
static std::string | rawIpAsString (const char *buffer, int bufferLength, bool normalize=false) noexcept(false) |
static std::string | abbreviateIP (const std::string &ip) noexcept(false) |
static void | getAddressAndPortFromSocketLiteral (const std::string &literal, std::string &address, int &port) |
static socket_v | getSocketVectorFromString (const std::string &list) |
static std::string | socketVectorAsString (const socket_v &socketVector) |
static bool | littleEndian () |
static const char * | codeInteger (char *result, const int n) |
static const char * | codeShort (char *result, const short int n) |
static const char * | codeInteger64 (char *result, const S64 n) |
static const char * | codeFloat (char *result, const float n) |
static const char * | codeDouble (char *result, const double n) |
static int | decodeInteger (const char *data) |
static short int | decodeShort (const char *data) |
static S64 | decodeInteger64 (const char *data) |
static float | decodeFloat (const char *data) |
static double | decodeDouble (const char *data) |
static void | decodeIsupNumber (const char *buffer, int length, isup_number_t &isupNumber, bool calledOrCalling) noexcept(false) |
static void | codeIsupNumber (const isup_number_t &isupNumber, bool calledOrCalling, char *buffer, int &length) noexcept(false) |
static void | codeIsupNumber (const isup_number_t &isupNumber, bool calledOrCalling, std::string &target) noexcept(false) |
static std::string | encodeBase64 (const U8 *buf, unsigned int bufLen) |
static std::string | encodeBase64 (const std::string &str) |
static std::string | decodeBase64 (const std::string &encodedString) |
static bool | getContentFromFile (const std::string &pathfile, std::string &content) noexcept(false) |
Static Public Attributes | |
static const int | DateTimeSizeString = 21 |
static const int | intBitSize = sizeof(int) * 8 |
static const int | int64BitSize = sizeof(S64) * 8 |
functions - Métodos y variables
|
inlinestaticnoexcept |
Abbreviates an IP address. Specially used for IPv6, but valid for IPv4.
Examples: 0000:0000:0000:0000:0000:0000:0000:0001 -> ::1 2001:0db8:85a3:0000:0000:8a2e:0370:7334 -> 2001:db8:85a3::8a2e:370:7334
ip | Input IP address |
|
static |
Coverts original string without quotation into quoted one: '%s'
|
static |
|
static |
|
static |
Ascii string for buffer/size data block
buffer | Octet string buffer |
size | Buffer size |
isFullyPrintable | Returned by reference |
|
inlinestatic |
Same as asAsciiString but without interest about if is printable or not
|
inlinestatic |
Same as asAsciiString providing anna::DataBlock
|
inlinestatic |
Same as asAsciiString providing DataBlock and without interest about if is printable or not
|
staticnoexcept |
Interpreta la cadena recibida como parametro como un dato de tipo boolean.
Si la cadena vale NULL, o contiene los literales "false" o "0" devolvera false, si contiene los literales "true" o "1" devolvera true, en otro caso devolvera un excepcion.
str | Cadena a interpretar. |
|
static |
Devuelve una cadena con la hora en formato 'dd/mm/yyyy hh:mm:ss'.
second | Hora que deseamos traducir. |
|
static |
Devuelve una cadena con la hora en formato 'dd/mm/yyyy hh:mm:ss'.
second | Hora que deseamos traducir. |
result | Puntero donde vamos a guardar el resultado de la conversin. Debe tener espacio reservado para contener #TimeSizeAsString caracteres. |
|
static |
number | Numero a convertir. |
|
static |
number | Numero a convertir. |
|
inlinestatic |
number | Numero a convertir. |
|
static |
Devuelve un cadena con el contenido del bloque de datos interpretado como BCD, pero pasa cada valor binario a su correspondiente carácter. Por ejemplo, el buffer aa210c quedará como una cadena "AA210C".
dataBlock | Bloque a codificar. |
|
inlinestatic |
comment | Comentario que precede al valor. |
number | Numero a convertir. |
|
inlinestatic |
comment | Comentario que precede al valor. |
number | Numero a convertir. |
|
inlinestatic |
|
static |
Interpreta la cadena recibida como parametro como un entero de 32 bits.
|
static |
number | Numero a convertir. |
|
static |
number | Numero a convertir. |
|
static |
Devuelve un literal con tel numero convertido a cadena decimal
|
static |
Devuelve un literal con tel numero convertido a cadena decimal
|
inlinestatic |
|
static |
Devuelve una cadena con el bloque de datos decodificado en grupos de 16 bytes.
dataBlock | Bloque de datos a interpretar. |
characterByLine | Número de caracteres en cada línea. |
|
static |
Devuelve una cadena con el numero en coma flotante.
v | Numero a tratar. |
format | Formato aplicado para convertir el numero a cadena. Ver man printf. |
|
static |
Devuelve una cadena con el numero en coma flotante.
v | Numero a tratar. |
format | Formato aplicado para convertir el numero a cadena. Ver man printf. |
|
static |
Devuelve la cadena que contiene el resultado de aplicar la especificacion format sobre el resto de los parametros.
format | especificacion de formato similiar al empleado en las funciones printf, scanf, etc. |
|
inlinestatic |
Devuelve el resultado de invocar a metodo asString de la clase recibida como parametro. Si t es NULL devolvera el texto indicando la sitacion.
t | Instancia de la clase a usar. Puede ser NULL. |
|
inlinestatic |
|
inlinestatic |
comment | Comentario que precede al valor. |
number | Numero a convertir. |
|
inlinestatic |
comment | Comentario que precede al valor. |
number | Numero a convertir. |
|
inlinestatic |
comment | Comentario que precede al valor. |
_bool | Booleano a convertir. |
|
inlinestatic |
comment | Comentario que precede al valor. |
dataBlock | Bloque de datos a interpretar. |
characterByLine | Número de caracteres en cada línea. |
|
inlinestatic |
comment | Comentario que precede al valor. |
value | Numero a tratar. |
format | Formato aplicado para convertir el numero a cadena. Ver man printf. |
|
inlinestatic |
comment | Comentario que precede al valor. |
value | Numero a tratar. |
format | Formato aplicado para convertir el numero a cadena. Ver man printf. |
|
inlinestatic |
Devuelve el número de bits necesarios para representar el valor recibido como parámetro.
n | Valor a estudiar. |
|
inlinestatic |
Devuelve el número de bits necesarios para representar el valor recibido como parámetro.
n | Valor a estudiar. |
|
static |
Encodes a floating number with 64 bits (according to the standard IEEE-754) over a buffer with at least 8 bytes of length.
result | Buffer where the number is encoded. |
n | Number to encode. |
|
static |
Encodes a floating number with 32 bits (according to the standard IEEE-754) over a buffer with at least 4 bytes of length.
result | Buffer where the number is encoded. |
n | Number to encode. |
|
static |
Encodes an integer number with 32 bits over a buffer with at least 4 bytes of length.
result | Buffer where the number is encoded. |
n | Number to encode. |
|
static |
Encodes an integer number with 64 bits over a buffer with at least 8 bytes of length.
result | Buffer where the number is encoded. |
n | Number to encode. |
|
staticnoexcept |
Encodes an ISUP Number (called or calling party number).
isupNumber | Isup number. |
calledOrCalling | True for called party number, false for calling |
buffer | Isup number content encoded buffer. |
length | Isup number content encoded length. |
|
staticnoexcept |
Encodes an ISUP Number (called or calling party number).
isupNumber | Isup number. |
calledOrCalling | True for called party number, false for calling |
target | Isup number octet string. |
|
static |
Encodes an integer number with 16 bits over a buffer with at least 2 bytes of length.
result | Buffer where the number is encoded. |
n | Number to encode. |
|
inlinestaticnoexcept |
Pattern to obtain a single named component instance easily. Parameters are usually replaced by the macro C FILE_LOCATION.
fromFile | File which called the method |
fromLine | Line number within the file from where the method is called. |
|
inlinestaticnoexcept |
Pattern to obtain a multi named component instance easily. Parameters are usually replaced by the macro C FILE_LOCATION.
className | Component class name |
fromFile | File which called the method |
fromLine | Line number within the file from where the method is called. |
|
static |
Base64 decoding
encodedString | Encoded base64 representation |
|
static |
Decodes an 64 bits floating number (according to the standard IEEE-754) contained in a 8-bytes buffer.
data | Buffer with the encoded number. |
|
static |
Decodes an 32 bits floating number (according to the standard IEEE-754) contained in a 4-bytes buffer.
data | Buffer with the encoded number. |
|
static |
Decodes an 32 bits integer number contained in a 4-bytes buffer.
data | Buffer with the encoded number. |
|
static |
Decodes an 64 bits integer number contained in a 8-bytes buffer.
data | Buffer with the encoded number. |
|
staticnoexcept |
Decodes an ISUP Number (called or calling party number).
buffer | Isup number content buffer. |
length | Isup number content length. |
isupNumber | Isup number decoded by reference. |
calledOrCalling | True for called party number, false for calling |
|
static |
Decodes an 16 bits integer number contained in a 2-bytes buffer.
data | Buffer with the encoded number. |
|
static |
|
inlinestatic |
|
inlinestatic |
Finds string at the end of another
pattern | String where we find |
suffix | Searched string |
|
static |
Similar to endsWith but returning additional preffix string by reference (pattern without suffix)
|
static |
Solve singular/plural literal expression for any number.
Provide (0): returns "no entries" Provide (1): returns "1 entry" Provide (2): returns "2 entries"
Provide (0, 'table'): returns "no tables" Provide (1, 'table'): returns "1 table" Provide (2, 'table'): returns "2 tables"
Provide (0, 'query', 'queries'): returns "no queries" Provide (1, 'query', 'queries'): returns "1 query" Provide (2, 'query', 'queries'): returns "2 queries"
number | Amount processed |
wordForSingular | Word used as singular, 'entry' by default. |
wordForPlural | Word used as plural, 'entries' by default. |
|
staticnoexcept |
Obtiene el valor original de una cadena obtenido con asHexString (const DataBlock&).
hexString | Cadena que contiene el búfer. |
target | Bloque de datos sobre el que decodificar la cadena. |
|
static |
Extract ADDRESS (ip or hostname ro resolve) and PORT from socket literal description ('<ip|hostname>:<port>').
literal | Socket literal in format '<ip|hostname>:<port>' |
address | Address extracted by reference |
port | Port extracted by reference |
|
static |
|
staticnoexcept |
|
static |
Devuelve el identificador de thread desde el que es invocado este metodo. Si el programa no tuviera soporta para MT siempre devolvera 0.
|
static |
Gets the domain name
|
static |
Gets the FQDN (Fully Qualified Domain Name)
hostname | Specific provided hostname. Automatically solved if missing. Empty string implies exclusion from FQDN. |
domainname | Specific provided domainname. Automatically solved if missing. Empty string implies exclusion from FQDN. |
|
static |
Gets the host name (system name)
|
static |
Gets the IP based on hostname (getHostname)
|
static |
Translate pipe-separated socket literal list into Address/Port vector.
list | Comma-separated Address/Port list. I.e.: '10.95.10.25:4000,10.95.10.25:4001', or 'fed1:4000,fed2:4001' |
|
static |
|
inlinestatic |
Devuelve la referencia interna de los microsegundos transcurrido en el procesador.
|
static |
Calcula la funcion hash de la cadena recibida como parametro.
str | Cadena a la que aplicar la funcion hash. |
|
inlinestatic |
Calcula la funcion hash de la cadena recibida como parametro.
str | Cadena a la que aplicar la funcion hash. |
|
static |
Highligth text (traces and output improvement)
title | Title processed |
mode | Highlight mode: Overline, Underline(default), OverAndUnderline, Leftline, Rightline, LeftAndRightline |
filler | Filler character used (dash by default) |
appendCR | Carriage return inclusion (true by default) |
|
inlinestatic |
Highligth and justify text (traces and output improvement)
title | Title processed |
hMode | Highlight mode: Overline, Underline(default), OverAndUnderline, Leftline, Rightline, LeftAndRightline |
jMode | Justify mode: Left (default), Center, Right |
highlightFiller | Filler character used (double dash ('=') by default) |
justifyFiller | Filler character used when justify (space by default) |
appendCR | Carriage return inclusion (true by default) |
|
staticnoexcept |
|
staticnoexcept |
Convert an IPv4 address to IPv6. Also removes dots from IPv4-mapped format.
ipv4 | IP Address in dot notation (192.168.1.100) |
|
static |
IPv4 address family detection
ip | IP address |
ipv4Type | Check for IPv4-compatible (i.e. '::192.168.0.1'), IPv4-mapped (i.e. '2001:0db8:85a3:0000:0000:8a2e:192.168.0.1') or estrict IPv4 format. |
|
static |
IPv6 address family detection
ip | IP address |
|
staticnoexcept |
Devuelve true si el valor recibido cumple el patron establecido o false en otro caso.
pattern | Expresion regular que describe el patron a cumplir. |
value | Cadena a comparar con el patron. |
|
static |
Justify text (traces and output improvement)
title | Title processed |
mode | Justify mode: Left (default), Center, Right |
filler | Filler character used (space by default) |
|
static |
Endianess of the system
|
static |
Calcula el logaritmo en base 2 del número recibo como parámetro.
v | Valor a calcular. |
|
staticnoexcept |
Compare two IP addresses by mean internal comparison after ipv6 preffix restriction
ipv6 | IPv6 address matched |
preffixedIpv6 | Preffixed IPv6 address (<ipv6>/<preffix length>="">: only values from 0 (always match) to 128 (maximum restriction) are allowed). |
|
staticnoexcept |
Calcula la operación (n1 << bitShit) | n2. Establece las comprobaciones necesarias para verificar que la operación se realiza correctamente, teniendo especial cuidado de que no se puedan solapar ninguno de los valores.
whatis | Literal que debería identificar el punto de invocación en caso de que haya algún error. |
n1 | Número a desplazar el nº de bits indicado por bitShift. |
bitShift | Número de bits a desplazar. |
n2 | Número a combinar con el resultado de la operación (n1 << bitShift). |
|
inlinestatic |
Obtiene el numero de microsegundos transcurridos desde el 1 del 1 de 1970.
|
inlinestatic |
Obtiene el numero de milisegundos transcurridos desde el 1 del 1 de 1970.
|
staticnoexcept |
Normalizes an IP address to long notation. Specially used for IPv6, but valid for IPv4 (via IPv4To6 conversion).
Examples: ::1 -> 0000:0000:0000:0000:0000:0000:0000:0001 2001:db8:85a3::8a2e:370:7334 -> 2001:0db8:85a3:0000:0000:8a2e:0370:7334
ip | Input IP address |
|
staticnoexcept |
IP Address decoding to 'human-readable raw presentation':
Example for IPv4: DataBlock for '170.187.204.221' will be 'AABBCCDD' (a pure IPv4 will never contain leading zeros outside of its scope (i.e., 24 zeros on a 32-character presentation) Example for IPv6: DataBlock for '2001:0db8:85a3:0000:0000:8a2e:0370:7334' will be '20010DB885A3000000008A2E03707334'
DataBlock for '::170.187.204.221' will be represented as IPv4 compatible: '000000000000000000000000AABBCCDD'
db | Encoded DataBlock with 4 or 16 bytes to represent Ipv4 or Ipv6. |
|
inlinestaticnoexcept |
IP Address decoding
db | Encoded DataBlock with 4 or 16 bytes to represent Ipv4 or Ipv6. |
normalize | Normalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion) |
|
staticnoexcept |
IP Address decoding
buffer | Encoded buffer with 4 or 16 bytes to represent Ipv4 or Ipv6. |
bufferLength | Encoded buffer length with 4 or 16 bytes to represent Ipv4 or Ipv6. |
normalize | Normalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion) |
|
staticnoexcept |
IP Address enconding based on common database 'human-readable raw presentation':
Example for IPv4: 'AABBCCDD' will be DataBlock for '170.187.204.221' Example for IPv6: '20010DB885A3000000008A2E03707334' will be DataBlock for '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
'000000000000000000000000AABBCCDD' will be encoded as 16-sized Datablock, not IPv4 (4 bytes). Is not recommended to put IPv4 on this way because of ambiguity regarding IPv4-compatible format. It is application responsability to trim leading zeros in order to use this method for IPv4 source.
rawPresentation | Input IP address as raw presentation. Must be 8 or 32 sized for IPv4 and IPv6 respectively. |
|
inlinestaticnoexcept |
IP Address decoding from raw presentation:
Example for IPv4: 'AABBCCDD' will be '170.187.204.221' Example for IPv6: '20010DB885A3000000008A2E03707334' will be '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
'000000000000000000000000AABBCCDD' will be internally encoded as 16-sized Datablock, not IPv4 (4 bytes). Is not recommended to put IPv4 on this way because of ambiguity regarding IPv4-compatible format. It is application responsability to trim leading zeros in order to use this method for IPv4 source.
rawPresentation | Input IP address as raw presentation. Must be 8 or 32 sized for IPv4 and IPv6 respectively. |
normalize | Normalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion) |
|
static |
Finds 'item' and replaces it with 'target' within the string provided ('text'). The result is returned.
text | Original string |
item | Searched string |
target | String which replaces the item |
all | Boolean about replace all items or only the first found. True by default. |
|
staticnoexcept |
Compare two IP addresses by mean normalization
ip1 | First IP address compared |
ip2 | Second IP address compared |
|
inlinestatic |
|
static |
Detiene la ejecucion del thread durante el numero de milisegundos indicados.
millisecond | Numero de milisegundos que vamos a detener la ejecucion de este thread. |
|
static |
Returns socket notation 'Address:Port'
|
static |
Translate Address/Port vector into comma-separated Address/Port list.
socketVector | Address/Port vector |
|
inlinestatic |
Finds string at the begining of another
pattern | String where we find |
preffix | Searched string |
|
static |
Similar to startsWith but returning additional suffix string by reference (pattern without preffix)
|
inlinestatic |
Devuelve true si la version de nucleo que estamos ejecutado soporta multithread o false en otro caso.
|
static |
Tabulate text (traces and output improvement)
text | Text processed |
tabSpaces | Tab spaces (three by default) |
|
static |
Generates space-separated string lists based on integer elements Also, another separator could be used.
|
static |
Generates space-separated string lists based on string elements. Also, another separator could be used.
|
static |
Tamao de la memoria reservada que debe tener la variable usada para guardar el resultado de convertir el 'time' en texto.
|
static |
|
static |
Indica el número de bits de un entero.