mksqlite  2.5
A MATLAB interface to SQLite
Functions
utils.hpp File Reference

Utilities used in all files. More...

#include "global.hpp"
#include <windows.h>
+ Include dependency graph for utils.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * utils_getString (const mxArray *str)
 Copy string characters into allocated memory. More...
 
size_t utils_elbytes (mxClassID classID)
 Get the size of one element in bytes. More...
 
void utils_destroy_array (mxArray *&pmxarr)
 Freeing memory allocated by mxCreateNumericMatrix() or mxCreateNumericArray(). More...
 
template<class T >
void utils_free_ptr (T *&pmxarr)
 Freeing memory allocated by mxAlloc() or mxRealloc() More...
 
int utils_utf2latin (const unsigned char *s, unsigned char *buffer=NULL)
 Convert UTF-8 string to char string. More...
 
int utils_latin2utf (const unsigned char *s, unsigned char *buffer=NULL)
 Convert char string to UTF-8 string. More...
 
char * utils_strnewdup (const char *s, int flagConvertUTF8)
 duplicate a string and recode from UTF8 to char due to flag flagConvertUTF8 More...
 
double utils_get_wall_time ()
 Returns current counter time in seconds. More...
 
double utils_get_cpu_time ()
 Returns user mode time of current process in seconds. More...
 
char * utils_strlwr (char *str)
 Change string to lowercase (inplace) More...
 

Detailed Description

Utilities used in all files.

Common utilities. (freeing mex memory, utf<->latin conversion, time measurement)

See also
http://note.sonots.com/Mex/Matrix.html
Authors
Martin Kortmann mail@.nosp@m.kort.nosp@m.mann..nosp@m.de, Andreas Martin andim.nosp@m.arti.nosp@m.n@use.nosp@m.rs.s.nosp@m.ource.nosp@m.forg.nosp@m.e.net
Version
2.5
Date
2008-2017
Precondition
Warning
Bug:
Note

From the Matlab documentation:
mxDestroyArray deallocates the memory occupied by the specified mxArray. This includes:
  • Characteristics fields of the mxArray, such as size, (m and n), and type.
  • Associated data arrays, such as pr and pi for complex arrays, and ir and jc for sparse arrays.
  • Fields of structure arrays.
  • Cells of cell arrays.
Do not call mxDestroyArray on an mxArray:
  • you return in a left-side argument of a MEX-file.
  • returned by the mxGetField or mxGetFieldByNumber functions.
  • returned by the mxGetCell function.

Poorly the documentation is missing the issue, whether a NULL pointer may be passed or not. For sure a self implementation will be used.

Definition in file utils.hpp.

Function Documentation

◆ utils_destroy_array()

void utils_destroy_array ( mxArray *&  pmxarr)

Freeing memory allocated by mxCreateNumericMatrix() or mxCreateNumericArray().

Parameters
[in]pmxarrMemory pointer or NULL

Memory pointer pmxarr is set to NULL after deallocation.

Definition at line 302 of file utils.hpp.

Referenced by BDC_pack_time_func(), BDC_ratio_func(), BDC_unpack_time_func(), Mksqlite::createResultColNameMatrix(), ValueMex::GetString(), have_serialize(), and MD5_func().

+ Here is the caller graph for this function:

◆ utils_elbytes()

size_t utils_elbytes ( mxClassID  classID)

Get the size of one element in bytes.

Parameters
[in]classIDclass ID
Returns
size of one element in bytes

Definition at line 75 of file utils.hpp.

Referenced by tagNativeArray::CreateArray(), and TBHData< HeaderBaseType >::getDataSize().

+ Here is the caller graph for this function:

◆ utils_free_ptr()

template<class T >
void utils_free_ptr ( T *&  pmxarr)

Freeing memory allocated by mxAlloc() or mxRealloc()

Parameters
[in]pmxarrMemory pointer or NULL

Memory pointer pmxarr is set to NULL after deallocation.

Definition at line 322 of file utils.hpp.

References MEM_FREE.

Referenced by ValueSQL::Destroy(), MD5_func(), regex_func(), and Mksqlite::Release().

+ Here is the caller graph for this function:

◆ utils_get_cpu_time()

double utils_get_cpu_time ( )

Returns user mode time of current process in seconds.

Returns
Time in seconds

Definition at line 370 of file utils.hpp.

References utils_get_wall_time().

◆ utils_get_wall_time()

double utils_get_wall_time ( )

Returns current counter time in seconds.

Returns
Time in seconds

Definition at line 350 of file utils.hpp.

Referenced by utils_get_cpu_time().

+ Here is the caller graph for this function:

◆ utils_getString()

char * utils_getString ( const mxArray *  str)

Copy string characters into allocated memory.

Not to use with multibyte strings!

Parameters
strMATLAB char array
Returns
Pointer to allocated string

Definition at line 52 of file utils.hpp.

References MEM_ALLOC.

◆ utils_latin2utf()

int utils_latin2utf ( const unsigned char *  s,
unsigned char *  buffer = NULL 
)

Convert char string to UTF-8 string.

Parameters
[in]sinput string
[out]bufferoptional pointer to where the string should be written (NULL allowed)
Returns
always the count of bytes written (or needed) to convert input string (including NUL)

Definition at line 171 of file utils.hpp.

Referenced by Mksqlite::cmdHandleSQLStatement(), SQLstackitem::openDb(), and regex_func().

+ Here is the caller graph for this function:

◆ utils_strlwr()

char * utils_strlwr ( char *  str)

Change string to lowercase (inplace)

Parameters
strString
Returns
String

Definition at line 253 of file utils.hpp.

◆ utils_strnewdup()

char * utils_strnewdup ( const char *  s,
int  flagConvertUTF8 
)

duplicate a string and recode from UTF8 to char due to flag flagConvertUTF8

Parameters
[in]sinput string
[in]flagConvertUTF8String s expected UTF8 encoded, if flag is set
Returns
pointer to created duplicate (allocator MEM_ALLOC) and must be freed with MEM_FREE

Definition at line 211 of file utils.hpp.

References MEM_ALLOC, and utils_utf2latin().

Referenced by SQLiface::fetch(), MD5_func(), and regex_func().

+ Here is the caller graph for this function:

◆ utils_utf2latin()

int utils_utf2latin ( const unsigned char *  s,
unsigned char *  buffer = NULL 
)

Convert UTF-8 string to char string.

Parameters
[in]sinput string UTF8 encoded
[out]bufferoptional pointer to where the string should be written (NULL allowed)
Returns
always the count of bytes written (or needed) to convert input string (including NUL)

Definition at line 133 of file utils.hpp.

Referenced by utils_strnewdup().

+ Here is the caller graph for this function: