CExtractRange class

Pipelines v1.6

 

Member variables, Member functions

Home

 

Description

 

The CExtractRange class object is used by the ExtractColumnRange(), ExtractWordRange() and ExtractFieldRange() functions to isolate and extract a range of columns, words or fields, from an input stream record. You need not be concerned with the actual format of the range specified; the extract functions; which determine this format automatically, store the extracted range/substring at the address specified in the CExtractRange member m_pszTarget.

 

During the initialisation phase of your stage; in or via a call from your stages’ Initialise() function; you first make a call to the ParseForIntegerRange() function which will parse out and record the values of the starting and ending positions of the type of range that you want to extract from your input stream records. Next, during your stages’ runtime phase you pre-fill the CExtractRange object with those starting and ending range values and then call the appropriate extraction routine; ExtractColumnRange(), ExtractWordRange() and ExtractFieldRange().

 

The CExtractRange class member settings control how the runtime Extract…Range() functions operate; the CExtractRange class member variables define; delimiters, whether the functions should provide an extracted input record range/substring and the resolved/relative from and to range column positions.

 

Definition

 

The following class definition is an edited version; it details only those members which are accessible and of use to you. In addition; any examples that may be shown are only intended as a demonstration of how certain functions might be used, they do not represent best practice nor do they take into account the scope and de-allocation of class objects.

 

class CExtractRange
{
    public:
 
    CExtractRange( void ) : m_pszSource( NULL ),
                            m_pszTarget( NULL ),
                            m_szDelimiter( " \n\t" ),
                            m_lFrom( -1 ),
                            m_lTo( -1 ),
                            m_bExtractRange( true ),
                            m_bResolveRange( false ) {}
 
    CString *m_pszSource;
    CString *m_pszTarget;
    CString m_szDelimiter;
    long m_lFrom;
    long m_lTo;
    bool m_bExtractRange;
    bool m_bResolveRange;
};

 

Member variables

 

    

CString *m_pszSource

[in,out] The address of a pointer to your stage command argument.

 

    

CString *m_pszTarget

[in,out] The address of a CString buffer in which to store the extracted range of columns, words or fields.

 

    

CString m_szDelimiter

[in,opt] A list of characters; any of which are considered to be a word or field range delimiter. By default; the list contains a space, a tab character and a new-line character.

 

    

long m_lFrom

[int,opt] The starting column, word or field of the specified range.

 

    

long m_lTo

[in,opt] The ending column, word or field of the specified range, inclusive.

 

    

bool m_bExtractRange

[in,opt] Set this option to true; if the ExtractColumnRange(), ExtractWordRange() and ExtractFieldRange() functions are to extract the range from the location specified by the member variable m_pszSource and store the extracted string in the buffer pointed to by member variable m_pszTarget.

 

    

bool m_bResolveRange

[in,opt] Set this option to true; if the ExtractColumnRange(), ExtractWordRange() and ExtractFieldRange() functions are to fill/overwrite the m_lFrom and m_lTo members with the actual (resolved) starting and ending columns (inclusive) of the specified range.

 

Member functions

 

 
CExtractRange::CExtractRange( void );
 

 

    

Purpose

Use CExtractRange() to create an extract range parser object.

 

The CExtractRange class object is used by the ExtractColumnRange(), ExtractWordRange() and ExtractFieldRange() functions to isolate and extract a range of columns, words or fields, from an input stream record. Simply initialise the members as you require and call the appropriate function to extract the required range.

 

    

Parameters

 

void

 

    

Returns

n/a

 

    

Messages

None

 

    

Usage

The following example stage class, Initialise() and Go() functions; show how you might parse for and extract a column range from your input stream records and write the resolved range/substring to your primary output stream.

 

class CMyStage : virtual public CProcess
{
    public:
        CMyStage( CStageInitInfo *a_pInfo );
        virtual ~CMyStage( void );
 
        virtual bool Initialise( void );
        // Kickoff this worker thread.
        virtual DWORD Go( void );
 
    private:
        CStageManager *m_pManager;
        CStage *m_pStage
 
        // Define parser objects.
        CIntegerRange *m_pIntegerRange;
 
        CString m_szRecord;
 
    ...    
};
 
bool CMyStage::Initialise( void )
{
    // Access the manager.
    m_pManager = Manager();
    // Access my stage.
    m_pStage = m_pManager->GetStage( *this );
 
    ...
 
    CString szToken;
    // Access my argument.
    const char *pszArgument = m_pStage->Argument();
 
    // Extract a required, signed integer range
    m_pIntegerRange->m_pszSource = &pszArgument;
    m_pIntegerRange->m_bFromSigned = true;
    m_pIntegerRange->m_bToSigned = true;
    m_pIntegerRange->m_bRequired = true;
    // This is an input range.
    m_pIntegerRange->m_nType = eInput;
    m_pIntegerRange->m_bSkipTrailing = true;
 
    // Extract the range.
    if( !m_pManager->ParseForIntegerRange( m_pIntegerRange ) )
    {
        // As this is a required argument; the ParseForIntegerRange() function will
        // issue a console error message if the argument is badly formed or missing.
        return( false );
    }
 
    ...
 
    return( true );
}
 
DWORD CJoin::Go( void )
{
    CString szRange;
    CExtractRange *pRange = new CExtractRange;
    pRange->m_pszSource = &m_szRecord;
    pRange->m_pszTarget = &szRange;
    pRange->m_bExtractRange = true;
    pRange->m_bResolveRange = true;
    // Pre-load the beginning and ending column range values.
    pRange->m_lFrom = m_pIntegerRange->m_lFrom;
    pRange->m_lTo = m_pIntegerRange->m_lTo;
 
 
    // Access my primary output stream.
    COutStream *pPriOutStream = m_pStage->GetOutStream( 0 );
 
    // Ok, now lets read and process our input streams..
    for( ;; )
    {
 
        // Read a record from my primary input stream.
        if( !m_pManager->PeekRecord( *this, 0, &m_szRecord ) )
            break;
 
        // Extract the range/substring from our input stream records.
        m_pManager->ExtractColumnRange( pRange );
 
        // Write the record to primary output.
        if( !m_pManager->WriteRecord( *this, 0, &szRange ) )
            break;
    }
 
    return( _RC_SUCCESS_ );
}