|
CIntegerString class |
Pipelines v2.0 |
|
Description |
The CIntegerString class object is used by the ParseForIntegerString() and ConvertToInteger() functions to;
extract an integer string from your stage command argument and convert it to an
integer value, respectively. You need not be concerned with the actual format
of the string specified; the ParseForIntegerString() function, which determines
this format automatically; extracts the string and stores it in the m_pszTarget
buffer. ConvertToInteger()
converts this string to an integer value and stores the result in the m_lResult member.
|
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 CIntegerString{ public: CIntegerString( CProcess &a_Process ) : m_Process( a_Process ), m_bRequired( false ), m_nReturnCode( _RC_SUCCESS_ ), m_pszSource( NULL ), m_pszTarget( NULL ), m_bSigned( false ), m_dwMinUnsignedValue( 1 ), m_dwMaxUnsignedValue( _MAX_INT_ ), m_lMinSignedValue( -( ( signed )_MAX_INT_ ) ), m_lMaxSignedValue( -1 ), m_lResult( 0 ), m_bSkipLeading( true ), m_szLeadingDelim( " \n\t" ), m_bSkipTrailing( true ), m_szTrailingDelim( " \n\t" ), m_bIntegerRange( false ) {} void Reset( void ) { m_bRequired = false; m_bSigned = false; m_dwMinUnsignedValue = 1; m_dwMaxUnsignedValue = _MAX_INT_; m_lMinSignedValue = -( ( signed )_MAX_INT_ ); m_lMaxSignedValue = -1; m_bSkipLeading = true; m_szLeadingDelim = " \n\t"; m_bSkipTrailing = true; m_szTrailingDelim = m_szLeadingDelim; m_bIntRange = false; } CProcess &m_Process; bool m_bRequired; int m_nReturnCode; const char **m_pszSource; CString *m_pszTarget; bool m_bSigned; DWORD m_dwMinUnsignedValue; DWORD m_dwMaxUnsignedValue; long m_lMinSignedValue; long m_lMaxSignedValue; long m_lResult; bool m_bSkipLeading; CString m_szLeadingDelim; bool m_bSkipTrailing; CString m_szTrailingDelim; bool m_bIntegerRange;};
|
Member variables |
|
● |
CProcess &m_Process [in] Your
CStage (*this ) pointer. |
|
● |
bool m_bRequired [in,opt] Set
this option to true if the string
is a required stage command argument and must be present, otherwise false; which indicates that the string
is an optional argument and may or may not be present. |
|
● |
int m_nReturnCode [out] The
returncode set by the function which uses this object. |
|
● |
const char **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 string. |
|
● |
bool m_bSigned [in,opt] Set
this option to true if the string
can represent a signed number. |
|
● |
long m_dwMinUnsignedValue [in,opt] The
minimum required unsigned value. The ConvertToInteger() function will verify
that the value of the integer is not less than this lower minimum value. |
|
● |
long m_dwMaxUnsignedValue [in,opt] The
maximum allowed unsigned value. The ConvertToInteger() function will verify
that the value of the integer is no greater than this upper maximum value. |
|
● |
long m_lMinSignedValue [in,opt] The
minimum required signed value. The ConvertToInteger() function will verify
that the value of the integer is no less than this lower minimum value. |
|
● |
long m_lMaxSignedValue [in,opt] The
maximum allowed signed value. The ConvertToInteger() function will verify that
the value of the integer is no greater than this upper maximum value. |
|
● |
long m_lResult [out] The
resulting integer value. |
|
● |
bool m_bSkipLeading [in,opt] Set
this option to true if leading
delimiters are to be skipped. |
|
● |
CString m_szLeadingDelim [in,opt] A list
of characters; any of which are considered to be leading delimiters. By
default; the list contains a space, a tab character and new-line character. |
|
● |
bool m_bSkipTrailing [in,opt] Set
this option to true if trailing
delimiters are to be skipped. |
|
● |
CString m_szTrailingDelim [in,opt] A list
of characters; any of which are considered to be trailing delimiters. By
default; the list contains a space, a tab character and a new-line character. |
|
● |
bool m_bIntegerRange [in,opt]
Set this option to true if the
string is part of an integer range specification. |
|
Member functions |
CIntegerString::CIntegerString( _in CProcess &a_Process ); |
|
● |
Purpose Use
CIntegerString() to create an integer string parser object. The
CIntegerString class object is used by the ParseForIntegerString() and ConvertToInteger()
functions to extract an integer string from your stage command argument and
convert this string to an integer value, respectively. Initialise the members
as you require and call ParseForIntegerString() followed by
ConvertToInteger(). The resulting (long) integer value is stored in the m_lResult member. |
||
|
● |
Parameters |
||
|
|
|
||
|
● |
Returns n/a |
||
|
● |
Messages None |
||
|
● |
Usage To extract an
integer string from your stage command argument and convert it to an integer
value: bool CMyStage::Initialise( void ) { // Access the manager.CStageManager *pManager = Manager(); // Access my stage. CStage *pStage = pManager->GetStage( *this ); ... // Point to my command argument. const char *pszArgument = pStage->Argument(); // My stage requires an unsigned integer in the range 1 to 10, // as its command argument. CString szString; CIntegerString *pIntString = new CIntegerString( *this );pIntString->m_bRequired = true; pIntString->m_pszSource = &pszArgument; pIntString->m_pszTarget = &szString; pIntString->m_dwMinUnsignedValue = 1; pIntString->m_dwMaxUnsignedValue = 10; // Extract the string. if( !pManager->ParseForIntegerString( pIntString ) ) return( false ); // Convert the string to an integer value. if( !pManager->ConvertToInteger( pIntString ) ) return( false ); // The integer value specified in the stage command argument is now// in the pIntString->m_lResult member varaible. ... return( true );} |
void CIntegerString::Reset( void ); |
|
● |
Purpose Use Reset() to reset the default extraction settings. The
function will reset the extraction switches and re-initialise the delimiter
definitions with their default values, but, leaving the m_Process and m_pszSource
members unchanged; you can re-use a CIntegerString parser object when
extracting integer string arguments, one after another. |
||
|
● |
Parameters
|
||
|
● |
Returns
|
||
|
● |
Messages None |
||
|
● |
Usage The Reset() function clears the CIntegerString class object’s extraction settings, but leaves the m_Process and m_pszSource members unchanged; which means that you only need provide these values the first time that you use the object. The m_pszSource member (common to all the parsing class types; CIntegerString, CCharacterString, etc..) automatically keeps track of your stage command argument pointer. Provided that you use the ParseFor…() functions to extract tokens, strings and ranges from your stage command argument; the m_pszSource member will always be pointing to the next stage command argument position. bool CMyStage::Initialise( void ) { // Access the manager.CStageManager *pManager = Manager(); // Access my stage. CStage *pStage = pManager->GetStage( *this ); ... // Point to my command argument. const char *pszArgument = pStage->Argument(); // My stage requires two integer values, both unsigned; the first is in // the range: 1 to 10, the second is optional and in the range 1 to _MAX_INT_. CString szString; CIntegerString *pIntString = new CIntegerString( *this );pIntString->m_bRequired = true; pIntString->m_pszSource = &pszArgument; pIntString->m_pszTarget = &szString; pIntString->m_dwMinUnsignedValue = 1; pIntString->m_dwMaxUnsignedValue = 10; // Extract the string. if( !pManager->ParseForIntegerString( pIntString ) ) return( false ); // Convert the string to an integer ( long ) value. if( !pManager->ConvertToInteger( pIntString ) ) return( false ); long lResult1 = pIntString->m_lResult; ... // Resetting the object; restores its default values. pIntString->Reset(); // Extract the string. if( !pManager->ParseForIntegerString( pIntString ) ) return( false ); // Convert the string to an integer ( long ) value. if( !pManager->ConvertToInteger( pIntString ) ) return( false ); long lResult2 = pIntString->m_lResult; ... return( true );} |
|
|