ANNA Suite  2020b
Multipurpose development suite for Telco applications
Classes | Static Public Member Functions | Static Public Attributes | List of all members
anna::functions Struct Reference

#include <functions.hpp>

Inheritance diagram for anna::functions:
Inheritance graph
[legend]

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 DataBlockfromHexString (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
 

Detailed Description

functions - Métodos y variables

Member Function Documentation

◆ abbreviateIP()

static std::string anna::functions::abbreviateIP ( const std::string &  ip)
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

Parameters
ipInput IP address
Returns
Abbreviated IP address
953  {
954  return (rawIpAsString(ipAsRaw(ip)));
955  }
static std::string rawIpAsString(const DataBlock &db, bool normalize=false) noexcept(false)
Definition: functions.hpp:927
static DataBlock ipAsRaw(const std::string &ip) noexcept(false)
Here is the call graph for this function:

◆ addQuotationMarks() [1/3]

static std::string anna::functions::addQuotationMarks ( const std::string &  str)
static

Coverts original string without quotation into quoted one: '%s'

◆ addQuotationMarks() [2/3]

static std::string anna::functions::addQuotationMarks ( const char *  str)
static

◆ addQuotationMarks() [3/3]

static std::string anna::functions::addQuotationMarks ( const int &  integer)
static

◆ asAsciiString() [1/4]

static std::string anna::functions::asAsciiString ( const char *  buffer,
int  size,
bool &  isFullyPrintable 
)
static

Ascii string for buffer/size data block

Parameters
bufferOctet string buffer
sizeBuffer size
isFullyPrintableReturned by reference
Returns
Ascii string representation, and dots for non-printable cheracters

◆ asAsciiString() [2/4]

static std::string anna::functions::asAsciiString ( const char *  buffer,
int  size 
)
inlinestatic

Same as asAsciiString but without interest about if is printable or not

725  {
726  bool isFullyPrintable;
727  return asAsciiString(buffer, size, isFullyPrintable);
728  }
static std::string asAsciiString(const char *buffer, int size, bool &isFullyPrintable)
Here is the call graph for this function:

◆ asAsciiString() [3/4]

static std::string anna::functions::asAsciiString ( const DataBlock db,
bool &  isFullyPrintable 
)
inlinestatic

Same as asAsciiString providing anna::DataBlock

733  {
734  return asAsciiString(db.getData(), db.getSize(), isFullyPrintable);
735  }
static std::string asAsciiString(const char *buffer, int size, bool &isFullyPrintable)
Here is the call graph for this function:

◆ asAsciiString() [4/4]

static std::string anna::functions::asAsciiString ( const DataBlock db)
inlinestatic

Same as asAsciiString providing DataBlock and without interest about if is printable or not

740  {
741  bool isFullyPrintable;
742  return asAsciiString(db.getData(), db.getSize(), isFullyPrintable);
743  }
static std::string asAsciiString(const char *buffer, int size, bool &isFullyPrintable)
Here is the call graph for this function:

◆ asBool()

static bool anna::functions::asBool ( const char *  str)
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.

Parameters
strCadena a interpretar.
Returns
El valor booleano correspondiente a la cadena recibida.

◆ asDateTime() [1/2]

static std::string anna::functions::asDateTime ( const Second second)
static

Devuelve una cadena con la hora en formato 'dd/mm/yyyy hh:mm:ss'.

Parameters
secondHora que deseamos traducir.
Returns
Un literal con la hora en el formato 'dd/mm/yyyy hh:mm:ss'.

◆ asDateTime() [2/2]

static const char* anna::functions::asDateTime ( const Second second,
char *  result 
)
static

Devuelve una cadena con la hora en formato 'dd/mm/yyyy hh:mm:ss'.

Parameters
secondHora que deseamos traducir.
resultPuntero donde vamos a guardar el resultado de la conversin. Debe tener espacio reservado para contener #TimeSizeAsString caracteres.
Returns
El puntero recibido como parametro conteniendo el literal con la hora en el formato 'dd/mm/yyyy hh:mm:ss'.

◆ asHexString() [1/4]

static std::string anna::functions::asHexString ( const int  number)
static
Parameters
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena hexadecimal.

◆ asHexString() [2/4]

static std::string anna::functions::asHexString ( const S64  number)
static
Parameters
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena hexadecimal.

◆ asHexString() [3/4]

static std::string anna::functions::asHexString ( const U64  number)
inlinestatic
Parameters
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena hexadecimal.
233 { return asHexString((S64) number); }
int64_t S64
Definition: defines.hpp:84
static std::string asHexString(const int number)
Here is the call graph for this function:

◆ asHexString() [4/4]

static std::string anna::functions::asHexString ( const DataBlock dataBlock)
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".

Parameters
dataBlockBloque a codificar.
Returns
La cadena que contiene el valor literal del buffer de datos.

◆ asHexText() [1/2]

static std::string anna::functions::asHexText ( const char *  comment,
const int  number 
)
inlinestatic
Parameters
commentComentario que precede al valor.
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena decimal.
241  {
242  std::string result(comment);
243  return result += asHexString(number);
244  }
static std::string asHexString(const int number)
Here is the call graph for this function:

◆ asHexText() [2/2]

static std::string anna::functions::asHexText ( const char *  comment,
const S64  number 
)
inlinestatic
Parameters
commentComentario que precede al valor.
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena decimal.
252  {
253  std::string result(comment);
254  return result += asHexString(number);
255  }
static std::string asHexString(const int number)
Here is the call graph for this function:

◆ asInteger()

static int anna::functions::asInteger ( const char *  str)
inlinestatic

Interpreta la cadena recibida como parametro como un entero de 32 bits.

Returns
420 { return atoi(str); }
Here is the call graph for this function:

◆ asInteger64()

static S64 anna::functions::asInteger64 ( const char *  str)
static

Interpreta la cadena recibida como parametro como un entero de 32 bits.

Returns

◆ asString() [1/11]

static std::string anna::functions::asString ( const int  number)
static
Parameters
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena decimal.

◆ asString() [2/11]

static std::string anna::functions::asString ( const unsigned int  number)
static
Parameters
numberNumero a convertir.
Returns
Un literal con el numero sin signo convertido a cadena decimal.

◆ asString() [3/11]

static std::string anna::functions::asString ( const S64  number)
static

Devuelve un literal con tel numero convertido a cadena decimal

Returns
Un literal con el numero signo convertido a cadena decimal.

◆ asString() [4/11]

static std::string anna::functions::asString ( const U64  number)
static

Devuelve un literal con tel numero convertido a cadena decimal

Returns
Un literal con el numero signo convertido a cadena decimal.

◆ asString() [5/11]

static const char* anna::functions::asString ( const bool  _bool)
inlinestatic
Parameters
_boolBooleano a convertir.
Returns
Un literal con el boolean convertido a cadena.
122 { return (_bool == true) ? "true" : "false"; }
Here is the call graph for this function:

◆ asString() [6/11]

static std::string anna::functions::asString ( const DataBlock dataBlock,
const int  characterByLine = 16 
)
static

Devuelve una cadena con el bloque de datos decodificado en grupos de 16 bytes.

Parameters
dataBlockBloque de datos a interpretar.
characterByLineNúmero de caracteres en cada línea.
Returns
Devuelve una cadena con el bloque de datos decodificado en grupos de 16 bytes.

◆ asString() [7/11]

static std::string anna::functions::asString ( const double  v,
const char *  format = "%e" 
)
static

Devuelve una cadena con el numero en coma flotante.

Parameters
vNumero a tratar.
formatFormato aplicado para convertir el numero a cadena. Ver man printf.
Returns
una cadena con el numero en coma flotante.

◆ asString() [8/11]

static std::string anna::functions::asString ( const float  v,
const char *  format = "%f" 
)
static

Devuelve una cadena con el numero en coma flotante.

Parameters
vNumero a tratar.
formatFormato aplicado para convertir el numero a cadena. Ver man printf.
Returns
una cadena con el numero en coma flotante.

◆ asString() [9/11]

static std::string anna::functions::asString ( const char *  format,
  ... 
)
static

Devuelve la cadena que contiene el resultado de aplicar la especificacion format sobre el resto de los parametros.

Parameters
formatespecificacion de formato similiar al empleado en las funciones printf, scanf, etc.
Returns
la cadena que contiene el resultado de aplicar la especificacion format sobre el resto de los parametros.

◆ asString() [10/11]

template<typename T >
static std::string anna::functions::asString ( const T *  t)
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.

Parameters
tInstancia de la clase a usar. Puede ser NULL.
Returns
el resultado de invoca a T::asString () si t es distinto de NULL.
Warning
La clase T debe tener un metodo estatico con la signatura:
static const char* className () ;
330  {
331  if(t == NULL) {
332  std::string result(T::className());
333  result += " { <null> }";
334  return result;
335  }
336 
337  return t->asString();
338  }

◆ asString() [11/11]

static const std::string& anna::functions::asString ( const std::string &  str)
inlinestatic

Metodo identididad. Facilita la implementacion de patrones donde no se conoce el tipo de dato recibido.

Parameters
strInstancia de la cadena.
Returns
La misma instancia recibida como parametro.
346 { return str; }
Here is the call graph for this function:

◆ asText() [1/6]

static std::string anna::functions::asText ( const char *  comment,
const int  number 
)
inlinestatic
Parameters
commentComentario que precede al valor.
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena decimal.
154  {
155  std::string result(comment);
156  return result += asString(number);
157  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ asText() [2/6]

static std::string anna::functions::asText ( const char *  comment,
const S64  number 
)
inlinestatic
Parameters
commentComentario que precede al valor.
numberNumero a convertir.
Returns
Un literal con el numero convertido a cadena decimal.
165  {
166  std::string result(comment);
167  return result += asString(number);
168  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ asText() [3/6]

static std::string anna::functions::asText ( const char *  comment,
const bool  _bool 
)
inlinestatic
Parameters
commentComentario que precede al valor.
_boolBooleano a convertir.
Returns
Un literal con el numero convertido a cadena decimal.
176  {
177  std::string result(comment);
178  return result += asString(_bool);
179  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ asText() [4/6]

static std::string anna::functions::asText ( const char *  comment,
const DataBlock dataBlock,
const int  characterByLine = 16 
)
inlinestatic
Parameters
commentComentario que precede al valor.
dataBlockBloque de datos a interpretar.
characterByLineNúmero de caracteres en cada línea.
Returns
Un literal con el numero convertido a cadena decimal.
188  {
189  std::string result(comment);
190  return result += asString(dataBlock, characterByLine);
191  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ asText() [5/6]

static std::string anna::functions::asText ( const char *  comment,
const float  value,
const char *  format = "%f" 
)
inlinestatic
Parameters
commentComentario que precede al valor.
valueNumero a tratar.
formatFormato aplicado para convertir el numero a cadena. Ver man printf.
Returns
Un literal con el numero convertido a cadena.
200  {
201  std::string result(comment);
202  return result += asString(value, format);
203  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ asText() [6/6]

static std::string anna::functions::asText ( const char *  comment,
const double  value,
const char *  format = "%e" 
)
inlinestatic
Parameters
commentComentario que precede al valor.
valueNumero a tratar.
formatFormato aplicado para convertir el numero a cadena. Ver man printf.
Returns
Un literal con el numero convertido a cadena.
212  {
213  std::string result(comment);
214  return result += asString(value, format);
215  }
static std::string asString(const int number)
Here is the call graph for this function:

◆ bitsize() [1/2]

static int anna::functions::bitsize ( const int  n)
inlinestatic

Devuelve el número de bits necesarios para representar el valor recibido como parámetro.

Parameters
nValor a estudiar.
Returns
el número de bits necesarios para representar el valor recibido como parámetro.
460 { return (n == 0) ? 1 : functions::log2(n) + 1; }
static int log2(const unsigned int v)
Here is the call graph for this function:

◆ bitsize() [2/2]

static int anna::functions::bitsize ( const S64  n)
inlinestatic

Devuelve el número de bits necesarios para representar el valor recibido como parámetro.

Parameters
nValor a estudiar.
Returns
el número de bits necesarios para representar el valor recibido como parámetro.
467  {
468  int aux = n >> intBitSize;
469  return (aux != 0) ? (bitsize(aux) + intBitSize) : bitsize((int) n);
470  }
static int bitsize(const int n)
Definition: functions.hpp:460
static const int intBitSize
Definition: functions.hpp:87
Here is the call graph for this function:

◆ codeDouble()

static const char* anna::functions::codeDouble ( char *  result,
const double  n 
)
static

Encodes a floating number with 64 bits (according to the standard IEEE-754) over a buffer with at least 8 bytes of length.

Parameters
resultBuffer where the number is encoded.
nNumber to encode.
Returns
Buffer with the encoded number.

◆ codeFloat()

static const char* anna::functions::codeFloat ( char *  result,
const float  n 
)
static

Encodes a floating number with 32 bits (according to the standard IEEE-754) over a buffer with at least 4 bytes of length.

Parameters
resultBuffer where the number is encoded.
nNumber to encode.
Returns
Buffer with the encoded number.

◆ codeInteger()

static const char* anna::functions::codeInteger ( char *  result,
const int  n 
)
static

Encodes an integer number with 32 bits over a buffer with at least 4 bytes of length.

Parameters
resultBuffer where the number is encoded.
nNumber to encode.
Returns
Buffer with the encoded number.

◆ codeInteger64()

static const char* anna::functions::codeInteger64 ( char *  result,
const S64  n 
)
static

Encodes an integer number with 64 bits over a buffer with at least 8 bytes of length.

Parameters
resultBuffer where the number is encoded.
nNumber to encode.
Returns
Buffer with the encoded number.

◆ codeIsupNumber() [1/2]

static void anna::functions::codeIsupNumber ( const isup_number_t isupNumber,
bool  calledOrCalling,
char *  buffer,
int &  length 
)
staticnoexcept

Encodes an ISUP Number (called or calling party number).

Parameters
isupNumberIsup number.
calledOrCallingTrue for called party number, false for calling
bufferIsup number content encoded buffer.
lengthIsup number content encoded length.

◆ codeIsupNumber() [2/2]

static void anna::functions::codeIsupNumber ( const isup_number_t isupNumber,
bool  calledOrCalling,
std::string &  target 
)
staticnoexcept

Encodes an ISUP Number (called or calling party number).

Parameters
isupNumberIsup number.
calledOrCallingTrue for called party number, false for calling
targetIsup number octet string.

◆ codeShort()

static const char* anna::functions::codeShort ( char *  result,
const short int  n 
)
static

Encodes an integer number with 16 bits over a buffer with at least 2 bytes of length.

Parameters
resultBuffer where the number is encoded.
nNumber to encode.
Returns
Buffer with the encoded number.

◆ component()

template<typename T >
static T* anna::functions::component ( const char *  fromFile,
const int  fromLine 
)
inlinestaticnoexcept

Pattern to obtain a single named component instance easily. Parameters are usually replaced by the macro C FILE_LOCATION.

Parameters
fromFileFile which called the method
fromLineLine number within the file from where the method is called.
Returns
Component instance for the class provided at the pattern
Warning
T class must implement a method in the form:
static const char* getClassName () ;
See also
Component
634  {
635  return functions::componentByName<T> (T::getClassName(), fromFile, fromLine);
636  }

◆ componentByName()

template<typename T >
static T* anna::functions::componentByName ( const char *  className,
const char *  fromFile,
const int  fromLine 
)
inlinestaticnoexcept

Pattern to obtain a multi named component instance easily. Parameters are usually replaced by the macro C FILE_LOCATION.

Parameters
classNameComponent class name
fromFileFile which called the method
fromLineLine number within the file from where the method is called.
Returns
Component instance for the class provided at the pattern
See also
Component
606  {
607  ComponentManager &cm = ComponentManager::instantiate();
608  T* result = static_cast <T*>(cm.find(className));
609 
610  if(result == NULL) {
611  std::string msg(className);
612  msg += " | Unregistered component";
613  throw RuntimeException(msg, fromFile, fromLine);
614  }
615 
616  return result;
617  }
static ComponentManager & instantiate()
Definition: Singleton.hpp:81
Here is the call graph for this function:

◆ decodeBase64()

static std::string anna::functions::decodeBase64 ( const std::string &  encodedString)
static

Base64 decoding

Parameters
encodedStringEncoded base64 representation
Returns
Returns decoded representation

◆ decodeDouble()

static double anna::functions::decodeDouble ( const char *  data)
static

Decodes an 64 bits floating number (according to the standard IEEE-754) contained in a 8-bytes buffer.

Parameters
dataBuffer with the encoded number.
Returns
Value for the number contained in the buffer.

◆ decodeFloat()

static float anna::functions::decodeFloat ( const char *  data)
static

Decodes an 32 bits floating number (according to the standard IEEE-754) contained in a 4-bytes buffer.

Parameters
dataBuffer with the encoded number.
Returns
Value for the number contained in the buffer.

◆ decodeInteger()

static int anna::functions::decodeInteger ( const char *  data)
static

Decodes an 32 bits integer number contained in a 4-bytes buffer.

Parameters
dataBuffer with the encoded number.
Returns
Value for the number contained in the buffer.

◆ decodeInteger64()

static S64 anna::functions::decodeInteger64 ( const char *  data)
static

Decodes an 64 bits integer number contained in a 8-bytes buffer.

Parameters
dataBuffer with the encoded number.
Returns
Value for the number contained in the buffer.

◆ decodeIsupNumber()

static void anna::functions::decodeIsupNumber ( const char *  buffer,
int  length,
isup_number_t isupNumber,
bool  calledOrCalling 
)
staticnoexcept

Decodes an ISUP Number (called or calling party number).

Parameters
bufferIsup number content buffer.
lengthIsup number content length.
isupNumberIsup number decoded by reference.
calledOrCallingTrue for called party number, false for calling

◆ decodeShort()

static short int anna::functions::decodeShort ( const char *  data)
static

Decodes an 16 bits integer number contained in a 2-bytes buffer.

Parameters
dataBuffer with the encoded number.
Returns
Value for the number contained in the buffer.

◆ encodeBase64() [1/2]

static std::string anna::functions::encodeBase64 ( const U8 buf,
unsigned int  bufLen 
)
static

Base64 encoding

Parameters
strString to be encoded
Returns
Returns encoded representation

◆ encodeBase64() [2/2]

static std::string anna::functions::encodeBase64 ( const std::string &  str)
inlinestatic
1110  {
1111  return encodeBase64((const U8 *)str.c_str(), str.size());
1112  }
unsigned char U8
Definition: defines.hpp:62
static std::string encodeBase64(const U8 *buf, unsigned int bufLen)
Here is the call graph for this function:

◆ endsWith() [1/2]

static bool anna::functions::endsWith ( const std::string &  pattern,
const std::string &  suffix 
)
inlinestatic

Finds string at the end of another

Parameters
patternString where we find
suffixSearched string
Returns
Boolean about ocurrency
646  {
647  std::string dummy;
648  return endsWith(pattern, suffix, dummy);
649  }
static bool endsWith(const std::string &pattern, const std::string &suffix)
Definition: functions.hpp:646

◆ endsWith() [2/2]

static bool anna::functions::endsWith ( const std::string &  pattern,
const std::string &  suffix,
std::string &  preffix 
)
static

Similar to endsWith but returning additional preffix string by reference (pattern without suffix)

◆ entriesAsString()

static std::string anna::functions::entriesAsString ( int  number,
const char *  wordForSingular = NULL,
const char *  wordForPlural = NULL 
)
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"
Parameters
numberAmount processed
wordForSingularWord used as singular, 'entry' by default.
wordForPluralWord used as plural, 'entries' by default.
Returns
Coherent literal as 'd <singular word/plural word>'

◆ fromHexString()

static DataBlock& anna::functions::fromHexString ( const std::string &  hexString,
DataBlock target 
)
staticnoexcept

Obtiene el valor original de una cadena obtenido con asHexString (const DataBlock&).

Parameters
hexStringCadena que contiene el búfer.
targetBloque de datos sobre el que decodificar la cadena.
Returns
El bloque de datos original correspondiente a la cadena recibida.

◆ getAddressAndPortFromSocketLiteral()

static void anna::functions::getAddressAndPortFromSocketLiteral ( const std::string &  literal,
std::string &  address,
int &  port 
)
static

Extract ADDRESS (ip or hostname ro resolve) and PORT from socket literal description ('<ip|hostname>:<port>').

Parameters
literalSocket literal in format '<ip|hostname>:<port>'
addressAddress extracted by reference
portPort extracted by reference

◆ getArchitecture()

static std::string anna::functions::getArchitecture ( )
static
Returns
Un literal con la arquitectura sobre la que hemos compilado nuestra aplicacion.

◆ getContentFromFile()

static bool anna::functions::getContentFromFile ( const std::string &  pathfile,
std::string &  content 
)
staticnoexcept

◆ getCurrentThread()

static pthread_t anna::functions::getCurrentThread ( )
static

Devuelve el identificador de thread desde el que es invocado este metodo. Si el programa no tuviera soporta para MT siempre devolvera 0.

Returns
el identificador de thread desde el que es invocado este metodo.

◆ getDomainname()

static std::string anna::functions::getDomainname ( )
static

Gets the domain name

Returns
Domainname

◆ getFQDN()

static std::string anna::functions::getFQDN ( const char *  hostname = NULL,
const char *  domainname = NULL 
)
static

Gets the FQDN (Fully Qualified Domain Name)

Parameters
hostnameSpecific provided hostname. Automatically solved if missing. Empty string implies exclusion from FQDN.
domainnameSpecific provided domainname. Automatically solved if missing. Empty string implies exclusion from FQDN.
Returns
FQDN (<hostname>.<domainname>)

◆ getHostname()

static std::string anna::functions::getHostname ( )
static

Gets the host name (system name)

Returns
Hostname

◆ getHostnameIP()

static std::string anna::functions::getHostnameIP ( )
static

Gets the IP based on hostname (getHostname)

Returns
Hostname-based IP

◆ getSocketVectorFromString()

static socket_v anna::functions::getSocketVectorFromString ( const std::string &  list)
static

Translate pipe-separated socket literal list into Address/Port vector.

Parameters
listComma-separated Address/Port list. I.e.: '10.95.10.25:4000,10.95.10.25:4001', or 'fed1:4000,fed2:4001'
Returns
Address/Port socket items vector

◆ getVersion()

static std::string anna::functions::getVersion ( )
static
Returns
La versin de functions con la que hemos linkado nuestra aplicacion.

◆ hardwareClock()

static Microsecond anna::functions::hardwareClock ( )
inlinestatic

Devuelve la referencia interna de los microsegundos transcurrido en el procesador.

Returns
la referencia interna de los microsegundos transcurrido en el procesador.
390  {
391  timespec ts;
392  //clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); // DONT works (original)
393  //clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); // DONT works
394  //clock_gettime(CLOCK_MONOTONIC, &ts); // works
395  // Note that CLOCK_MONOTONIC is subject to discontinuities from system time
396  // adjustment in Linux. CLOCK_MONOTONIC_RAW was defined to get around this
397  // (gets hardware time not adjusted by NTP).
398  clock_gettime(CLOCK_MONOTONIC, &ts); // works
399 
400  Microsecond result((Microsecond::type_t)1000000 * ts.tv_sec + ts.tv_nsec / 1000);
401  return result;
402  }
S64 type_t
Definition: Microsecond.hpp:24
Here is the call graph for this function:

◆ hash() [1/2]

static S64 anna::functions::hash ( const char *  str)
static

Calcula la funcion hash de la cadena recibida como parametro.

Parameters
strCadena a la que aplicar la funcion hash.

◆ hash() [2/2]

static S64 anna::functions::hash ( const std::string &  str)
inlinestatic

Calcula la funcion hash de la cadena recibida como parametro.

Parameters
strCadena a la que aplicar la funcion hash.
305 { return hash(str.c_str()); }
static S64 hash(const char *str)
Here is the call graph for this function:

◆ highlight()

static std::string anna::functions::highlight ( const std::string &  title,
TextHighlightMode::_v  mode = TextHighlightMode::Underline,
char  filler = '-',
bool  appendCR = true 
)
static

Highligth text (traces and output improvement)

Parameters
titleTitle processed
modeHighlight mode: Overline, Underline(default), OverAndUnderline, Leftline, Rightline, LeftAndRightline
fillerFiller character used (dash by default)
appendCRCarriage return inclusion (true by default)
Returns
Processed text

◆ highlightJustify()

static std::string anna::functions::highlightJustify ( const std::string &  title,
TextHighlightMode::_v  hMode = TextHighlightMode::OverAndUnderline,
TextJustifyMode::_v  jMode = TextJustifyMode::Center,
char  highlightFiller = '=',
char  justifyFiller = ' ',
bool  appendCR = true 
)
inlinestatic

Highligth and justify text (traces and output improvement)

Parameters
titleTitle processed
hModeHighlight mode: Overline, Underline(default), OverAndUnderline, Leftline, Rightline, LeftAndRightline
jModeJustify mode: Left (default), Center, Right
highlightFillerFiller character used (double dash ('=') by default)
justifyFillerFiller character used when justify (space by default)
appendCRCarriage return inclusion (true by default)
Returns
Processed text
577  {
578  return(highlight(justify(title, jMode, justifyFiller), hMode, highlightFiller, appendCR));
579  }
static std::string highlight(const std::string &title, TextHighlightMode::_v mode=TextHighlightMode::Underline, char filler='-', bool appendCR=true)
static std::string justify(const std::string &title, TextJustifyMode::_v mode=TextJustifyMode::Left, char filler=' ')
Here is the call graph for this function:

◆ ipAsRaw()

static DataBlock anna::functions::ipAsRaw ( const std::string &  ip)
staticnoexcept

IP Address serialization

Parameters
ipInput IP address
Returns
Encoded DataBlock

◆ IPv4To6()

static std::string anna::functions::IPv4To6 ( const std::string &  ipv4)
staticnoexcept

Convert an IPv4 address to IPv6. Also removes dots from IPv4-mapped format.

Parameters
ipv4IP Address in dot notation (192.168.1.100)
Returns
string IPv6 formatted address or launch exception if invalid input

◆ isIPv4()

static bool anna::functions::isIPv4 ( const std::string &  ip,
IPv4Type::_v  ipv4Type = IPv4Type::Estrict 
)
static

IPv4 address family detection

Parameters
ipIP address
ipv4TypeCheck 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.
Returns
Boolean for IPv4 nature

◆ isIPv6()

static bool anna::functions::isIPv6 ( const std::string &  ip)
static

IPv6 address family detection

Parameters
ipIP address
Returns
Boolean for IPv6 nature

◆ isLike()

static bool anna::functions::isLike ( const char *  pattern,
const std::string &  value 
)
staticnoexcept

Devuelve true si el valor recibido cumple el patron establecido o false en otro caso.

Parameters
patternExpresion regular que describe el patron a cumplir.
valueCadena a comparar con el patron.
Returns
true si el valor recibido cumple el patron establecido o false en otro caso.
See also
regexec para mas informacion sobre las expresiones regulares.

◆ justify()

static std::string anna::functions::justify ( const std::string &  title,
TextJustifyMode::_v  mode = TextJustifyMode::Left,
char  filler = ' ' 
)
static

Justify text (traces and output improvement)

Parameters
titleTitle processed
modeJustify mode: Left (default), Center, Right
fillerFiller character used (space by default)
Returns
Processed text

◆ littleEndian()

static bool anna::functions::littleEndian ( )
static

Endianess of the system

Returns
Returns true when the system is little endian, false if big endian

◆ log2()

static int anna::functions::log2 ( const unsigned int  v)
static

Calcula el logaritmo en base 2 del número recibo como parámetro.

Parameters
vValor a calcular.
Returns
El algoritmo en base 2 del número recibido como parámetro o -1 si el parámetro recibido es 0.

◆ matchIPv6()

static bool anna::functions::matchIPv6 ( const std::string &  ipv6,
const std::string &  preffixedIpv6 
)
staticnoexcept

Compare two IP addresses by mean internal comparison after ipv6 preffix restriction

Parameters
ipv6IPv6 address matched
preffixedIpv6Preffixed IPv6 address (<ipv6>/<preffix length>="">: only values from 0 (always match) to 128 (maximum restriction) are allowed).
Returns
Boolean about subnet matching

◆ merge()

static S64 anna::functions::merge ( const char *  whatis,
const int  n1,
const int  n2,
const int  bitShift 
)
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.

Parameters
whatisLiteral que debería identificar el punto de invocación en caso de que haya algún error.
n1Número a desplazar el nº de bits indicado por bitShift.
bitShiftNúmero de bits a desplazar.
n2Número a combinar con el resultado de la operación (n1 << bitShift).

◆ microsecond()

static Microsecond anna::functions::microsecond ( )
inlinestatic

Obtiene el numero de microsegundos transcurridos desde el 1 del 1 de 1970.

Returns
El numero de microsegundos transcurridos desde el 1 del 1 de 1970.
368  {
369  struct timeval tv;
370  gettimeofday(&tv, NULL);
371  Microsecond result((Microsecond::type_t)1000000 * tv.tv_sec + tv.tv_usec);
372  return result;
373  }
S64 type_t
Definition: Microsecond.hpp:24

◆ millisecond()

static Millisecond anna::functions::millisecond ( )
inlinestatic

Obtiene el numero de milisegundos transcurridos desde el 1 del 1 de 1970.

Returns
El numero de milisegundos transcurridos desde el 1 del 1 de 1970.
379  {
380  struct timeval tv;
381  gettimeofday(&tv, NULL);
382  Millisecond result((Millisecond::type_t)1000 * tv.tv_sec + tv.tv_usec / 1000);
383  return result;
384  }
S64 type_t
Definition: Millisecond.hpp:26

◆ normalizeIP()

static std::string anna::functions::normalizeIP ( const std::string &  ip)
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

Parameters
ipInput IP address
Returns
Normalized IP address

◆ rawIpAsRawIpPresentation()

static std::string anna::functions::rawIpAsRawIpPresentation ( const DataBlock db)
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'
Parameters
dbEncoded DataBlock with 4 or 16 bytes to represent Ipv4 or Ipv6.
Returns
Human-readable raw IP presentation

◆ rawIpAsString() [1/2]

static std::string anna::functions::rawIpAsString ( const DataBlock db,
bool  normalize = false 
)
inlinestaticnoexcept

IP Address decoding

Parameters
dbEncoded DataBlock with 4 or 16 bytes to represent Ipv4 or Ipv6.
normalizeNormalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion)
Returns
Decoded IP address
927  {
928  return (rawIpAsString(db.getData(), db.getSize(), normalize));
929  }
static std::string rawIpAsString(const DataBlock &db, bool normalize=false) noexcept(false)
Definition: functions.hpp:927
Here is the call graph for this function:

◆ rawIpAsString() [2/2]

static std::string anna::functions::rawIpAsString ( const char *  buffer,
int  bufferLength,
bool  normalize = false 
)
staticnoexcept

IP Address decoding

Parameters
bufferEncoded buffer with 4 or 16 bytes to represent Ipv4 or Ipv6.
bufferLengthEncoded buffer length with 4 or 16 bytes to represent Ipv4 or Ipv6.
normalizeNormalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion)
Returns
Decoded IP address

◆ rawIpPresentationAsRaw()

static DataBlock anna::functions::rawIpPresentationAsRaw ( const std::string &  rawPresentation)
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.
Parameters
rawPresentationInput IP address as raw presentation. Must be 8 or 32 sized for IPv4 and IPv6 respectively.
Returns
Encoded DataBlock

◆ rawIpPresentationToIpAsString()

static std::string anna::functions::rawIpPresentationToIpAsString ( const std::string &  rawPresentation,
bool  normalize = false 
)
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.
Parameters
rawPresentationInput IP address as raw presentation. Must be 8 or 32 sized for IPv4 and IPv6 respectively.
normalizeNormalize returned address representation, 'false' by default (to avoid IPv4 to IPv6 conversion)
Returns
Decoded IP address
780  {
781  return rawIpAsString(rawIpPresentationAsRaw(rawPresentation), normalize);
782  }
static std::string rawIpAsString(const DataBlock &db, bool normalize=false) noexcept(false)
Definition: functions.hpp:927
static DataBlock rawIpPresentationAsRaw(const std::string &rawPresentation) noexcept(false)
Here is the call graph for this function:

◆ replace()

static std::string anna::functions::replace ( const std::string &  text,
const char *  item,
const char *  target,
bool  all = true 
)
static

Finds 'item' and replaces it with 'target' within the string provided ('text'). The result is returned.

Parameters
textOriginal string
itemSearched string
targetString which replaces the item
allBoolean about replace all items or only the first found. True by default.
Returns
Modified string

◆ sameIP()

static bool anna::functions::sameIP ( const std::string &  ip1,
const std::string &  ip2 
)
staticnoexcept

Compare two IP addresses by mean normalization

Parameters
ip1First IP address compared
ip2Second IP address compared
Returns
Boolean about IP's comparison

◆ second()

static Second anna::functions::second ( )
inlinestatic

Obtiene el numero de segundos transcurridos desde el 1 del 1 de 1970.

Returns
El numero de segundos transcurridos desde el 1 del 1 de 1970.
359  {
360  Second result(::time(NULL));
361  return result;
362  }

◆ sleep()

static void anna::functions::sleep ( const Millisecond millisecond)
static

Detiene la ejecucion del thread durante el numero de milisegundos indicados.

Parameters
millisecondNumero de milisegundos que vamos a detener la ejecucion de este thread.

◆ socketLiteralAsString()

static std::string anna::functions::socketLiteralAsString ( const std::string &  address,
int  port 
)
static

Returns socket notation 'Address:Port'

◆ socketVectorAsString()

static std::string anna::functions::socketVectorAsString ( const socket_v socketVector)
static

Translate Address/Port vector into comma-separated Address/Port list.

Parameters
socketVectorAddress/Port vector
Returns
Comma-separated Address/Port list. I.e.: '10.95.10.25:4000,10.95.10.25:4001', or 'fed1:4000,fed2:4001'

◆ startsWith() [1/2]

static bool anna::functions::startsWith ( const std::string &  pattern,
const std::string &  preffix 
)
inlinestatic

Finds string at the begining of another

Parameters
patternString where we find
preffixSearched string
Returns
Boolean about ocurrency
664  {
665  std::string dummy;
666  return startsWith(pattern, preffix, dummy);
667  }
static bool startsWith(const std::string &pattern, const std::string &preffix)
Definition: functions.hpp:664
Here is the call graph for this function:

◆ startsWith() [2/2]

static bool anna::functions::startsWith ( const std::string &  pattern,
const std::string &  preffix,
std::string &  suffix 
)
static

Similar to startsWith but returning additional suffix string by reference (pattern without preffix)

◆ supportMultithread()

static bool anna::functions::supportMultithread ( )
inlinestatic

Devuelve true si la version de nucleo que estamos ejecutado soporta multithread o false en otro caso.

Returns
true si la version de nucleo que estamos ejecutado soporta multithread o false en otro
440  {
441  WHEN_SINGLETHREAD(return false);
442  WHEN_MULTITHREAD(return true);
443  }
#define WHEN_MULTITHREAD(a)
Definition: defines.hpp:96
#define WHEN_SINGLETHREAD(a)
Definition: defines.hpp:97
Here is the call graph for this function:

◆ tab()

static std::string anna::functions::tab ( const std::string &  text,
int  tabSpaces = 3 
)
static

Tabulate text (traces and output improvement)

Parameters
textText processed
tabSpacesTab spaces (three by default)

◆ vectorToStringRepresentation() [1/2]

static std::string anna::functions::vectorToStringRepresentation ( const std::vector< int > &  v,
const char  separator = ' ' 
)
static

Generates space-separated string lists based on integer elements Also, another separator could be used.

◆ vectorToStringRepresentation() [2/2]

static std::string anna::functions::vectorToStringRepresentation ( const std::vector< std::string > &  v,
const char  separator = ' ' 
)
static

Generates space-separated string lists based on string elements. Also, another separator could be used.

Member Data Documentation

◆ DateTimeSizeString

const int anna::functions::DateTimeSizeString = 21
static

Tamao de la memoria reservada que debe tener la variable usada para guardar el resultado de convertir el 'time' en texto.

See also
asString

◆ int64BitSize

const int anna::functions::int64BitSize = sizeof(S64) * 8
static

◆ intBitSize

const int anna::functions::intBitSize = sizeof(int) * 8
static

Indica el número de bits de un entero.


The documentation for this struct was generated from the following file: