XLL+ Class Library (6.3)

matrix<T>::add_row() Example

CopyC++
// Function:    TestMatrixAddRow 
// Returns:     LPXLOPER 
// Description: Add a row to a matrix 
 
//{{XLP_SRC(TestMatrixAddRow) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN3(TestMatrixAddRow, TestMatrixAddRow_4, TestMatrixAddRow_12, 
    "RJ", "UJ", L"TestMatrixAddRow", 0, L"RowsToAdd", 0, L"Example", 0, L"Add "
    L"a row to a matrix", 0, L"Number of rows to add\0", 0, 0, L"{TestMatrixAd"
    L"dRow,,,Add a row to a matrix,Example,1,128,U,{{0,{RowsToAdd,Int,0,,Numbe"
    L"r of rows to add,,,,}}},{},3,,0,0}", 1)
CXlOper* TestMatrixAddRow_Impl(CXlOper&, long);

extern "C" __declspec(dllexport)
LPXLOPER12 TestMatrixAddRow_12(long RowsToAdd)
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(TestMatrixAddRow_Impl(xloResult, RowsToAdd));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 TestMatrixAddRow_4(long RowsToAdd)
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(TestMatrixAddRow_Impl(xloResult, RowsToAdd));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret4();
}

CXlOper* TestMatrixAddRow_Impl(CXlOper& xloResult, long RowsToAdd)
{
    // End of generated code 
//}}XLP_SRC 
 
    if ( RowsToAdd <= 0 )
        xloResult = xlerrNA;
    else
    {
        // Construct a matrix with 3 columns and no rows
        xlp::matrix<double> mat;
        mat.resize(0, 3);

        // An array of data to be added 
        double adNew[3] = { 1.0, 2.0, 3.0 };

        // Add the new row RowsToAdd times 
        for ( long i = 0; i < RowsToAdd; i++ )
            mat.add_row(adNew);

        // Copy the results to output
        xloResult = mat;
    }

    return xloResult.Ret();
}

Uses

matrix<T>::add_row