ccgl::utils_array 命名空间参考

Array related functions include vector and pointer array. 更多...

class  Array2D
 Rudimentary RAII class of 2D Array which occupy successive memory 更多...
 

函数

template<typename T , typename INI_T >
bool Initialize1DArray (int row, T *&data, INI_T init_value)
 Initialize DT_Array1D data 更多...
 
template<typename T , typename INI_T >
bool Initialize1DArray (int row, T *&data, INI_T *init_data)
 Initialize DT_Array1D data based on an existed array 更多...
 
template<typename T , typename INI_T >
bool Initialize2DArray (int row, int col, T **&data, INI_T init_value)
 Initialize DT_Array2D data 更多...
 
template<typename T , typename INI_T >
bool Initialize2DArray (int row, int col, T **&data, INI_T **init_data)
 Initialize DT_Array2D data based on an existed array The usage of const T * const * is refers to http://blog.csdn.net/pmt123456/article/details/50813564 更多...
 
template<typename T1 , typename T2 >
bool Initialize2DArray (T1 *init_data, int &rows, int &max_cols, T2 **&data)
 Initialize irregular DT_Array2D data based on an existed 1D array 更多...
 
template<typename T >
void Release1DArray (T *&data)
 Release DT_Array1D data 更多...
 
template<typename T >
void Release2DArray (T **&data)
 Release DT_Array2D data 更多...
 
template<typename T >
void BatchRelease1DArray (T *&data,...)
 Batch release of 1D array Variable arguments with the end of nullptr. 更多...
 
template<typename T >
void BatchRelease2DArray (int nrows, T **&data,...)
 Batch release of 2D array, 更多...
 
void Output1DArrayToTxtFile (int n, const float *data, const char *filename)
 Write 1D array to a file 更多...
 
void Output2DArrayToTxtFile (int rows, int cols, const float **data, const char *filename)
 Write 2D array to a file 更多...
 
template<typename T >
void Read1DArrayFromTxtFile (const char *filename, int &rows, T *&data)
 Read 1D array from file The input file should follow the format: a 1D array sized rows * 1 更多...
 
template<typename T >
void Read2DArrayFromTxtFile (const char *filename, int &rows, T **&data)
 Read 2D array from file The input file should follow the format: a 2D array sized rows * rows 更多...
 
template<typename T >
void Read2DArrayFromString (const char *s, int &rows, T **&data)
 Read 2D array from string The input string should follow the format: float value, total number is rows * rows 更多...
 
template<typename T >
bool ValueInVector (T val, const vector< T > &vec)
 If value in vector container 更多...
 
template<typename T >
void RemoveValueInVector (T val, vector< T > &vec)
 Remove value in vector container 更多...
 

详细描述

Array related functions include vector and pointer array.

函数说明

◆ BatchRelease1DArray()

template<typename T >
void ccgl::utils_array::BatchRelease1DArray ( T *&  data,
  ... 
)

Batch release of 1D array Variable arguments with the end of nullptr.

The input parameters are listed as data, data2, ... , dataN, and ended with nullptr.

Example:

BatchRelease1DArray(array1, array2, array3, nullptr);
void BatchRelease1DArray(T *&data,...)
Batch release of 1D array Variable arguments with the end of nullptr.
Definition: utils_array.h:478
警告
After batch release, the variable will not be set to nullptr. So, do not use these variables any more. BTW, this function will not cause memory leak.

USE WITH ALL CAUTIONS CLEARLY AWARED.

◆ BatchRelease2DArray()

template<typename T >
void ccgl::utils_array::BatchRelease2DArray ( int  nrows,
T **&  data,
  ... 
)

Batch release of 2D array,

参见
BatchRelease1DArray Variable arguments with the end of nullptr.

Example:

BatchRelease2DArray(rows, array1, array2, array3, nullptr);
void BatchRelease2DArray(int nrows, T **&data,...)
Batch release of 2D array,
Definition: utils_array.h:491
参数
[in]nrowsRows
[in]dataThe input parameters are listed as data, data2, ... , dataN, and ended with nullptr.
警告
USE WITH ALL CAUTIONS CLEARLY AWARED.

◆ Initialize1DArray() [1/2]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize1DArray ( int  row,
T *&  data,
INI_T *  init_data 
)

Initialize DT_Array1D data based on an existed array

参数
[in]row
[in]data
[in]init_data
返回
True if succeed, else false and the error message will print as well.

◆ Initialize1DArray() [2/2]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize1DArray ( int  row,
T *&  data,
INI_T  init_value 
)

Initialize DT_Array1D data

参数
[in]row
[in]data
[in]init_value
返回
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [1/3]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize2DArray ( int  row,
int  col,
T **&  data,
INI_T **  init_data 
)

Initialize DT_Array2D data based on an existed array The usage of const T * const * is refers to http://blog.csdn.net/pmt123456/article/details/50813564

参数
[in]row
[in]col
[in]data
[in]init_datadimension MUST BE (row, col)
返回
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [2/3]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize2DArray ( int  row,
int  col,
T **&  data,
INI_T  init_value 
)

Initialize DT_Array2D data

The 2D array are created in a successive memory.

  1. Create a 1D array of row data pointers with the length of row
  2. Create a 1D array of data pool with the length of row * col
  3. Iteratively point row pointers to appropriate positions in data pool

Refers to https://stackoverflow.com/a/21944048/4837280

参数
[in]row
[in]col
[in]data
[in]init_value
返回
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [3/3]

template<typename T1 , typename T2 >
bool ccgl::utils_array::Initialize2DArray ( T1 *  init_data,
int &  rows,
int &  max_cols,
T2 **&  data 
)

Initialize irregular DT_Array2D data based on an existed 1D array

参数
[in]init_dataInitial 1D array
[out]rowsRows count
[out]max_colsMaximum cols count
[out]dataIrregular 2D array
返回
True if succeed, else false and the error message will print as well.

◆ Output1DArrayToTxtFile()

void ccgl::utils_array::Output1DArrayToTxtFile ( int  n,
const float *  data,
const char *  filename 
)

Write 1D array to a file

参见
Read1DArrayFromTxtFile(), Read2DArrayFromTxtFile(), Output2DArrayToTxtFile()
参数
[in]n,data,filename

◆ Output2DArrayToTxtFile()

void ccgl::utils_array::Output2DArrayToTxtFile ( int  rows,
int  cols,
const float **  data,
const char *  filename 
)

Write 2D array to a file

参见
Read1DArrayFromTxtFile(), Read2DArrayFromTxtFile(), Output1DArrayToTxtFile()
参数
[in]rows,cols,data,filename

◆ Read1DArrayFromTxtFile()

template<typename T >
void ccgl::utils_array::Read1DArrayFromTxtFile ( const char *  filename,
int &  rows,
T *&  data 
)

Read 1D array from file The input file should follow the format: a 1D array sized rows * 1

The size of data is rows

参见
Read2DArrayFromTxtFile(), Output1DArrayToTxtFile(), Output2DArrayToTxtFile()
参数
[in]filename
[out]rows,data

◆ Read2DArrayFromString()

template<typename T >
void ccgl::utils_array::Read2DArrayFromString ( const char *  s,
int &  rows,
T **&  data 
)

Read 2D array from string The input string should follow the format: float value, total number is rows * rows

The size of data is rows * (rows + 1), the first element of each row is the rows.

参数
[in]s
[out]rows,data

◆ Read2DArrayFromTxtFile()

template<typename T >
void ccgl::utils_array::Read2DArrayFromTxtFile ( const char *  filename,
int &  rows,
T **&  data 
)

Read 2D array from file The input file should follow the format: a 2D array sized rows * rows

The size of data is rows * (rows + 1), the first element of each row is the rows

参见
Read1DArrayFromTxtFile(), Output1DArrayToTxtFile(), Output2DArrayToTxtFile()
参数
[in]filename
[out]rows,data

◆ Release1DArray()

template<typename T >
void ccgl::utils_array::Release1DArray ( T *&  data)

Release DT_Array1D data

参数
[in]data

◆ Release2DArray()

template<typename T >
void ccgl::utils_array::Release2DArray ( T **&  data)

Release DT_Array2D data

参数
[in]data

◆ RemoveValueInVector()

template<typename T >
void ccgl::utils_array::RemoveValueInVector ( val,
vector< T > &  vec 
)

Remove value in vector container

参数
[in]valValue to be removed, e.g., a int, or float
[in]vecVector container, data type is consistent with val

◆ ValueInVector()

template<typename T >
bool ccgl::utils_array::ValueInVector ( val,
const vector< T > &  vec 
)

If value in vector container

参数
[in]valValue, e.g., a int, or float
[in]vecVector container, data type is consistent with val
返回
True if val is in vec, otherwise False