NCBI C++ ToolKit
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

Search Toolkit Book for CArgs

CArgs --. More...

#include <corelib/ncbiargs.hpp>

+ Collaboration diagram for CArgs:

List of all members.

Public Member Functions

 CArgs (void)
 Constructor.
 ~CArgs (void)
 Destructor.
bool Exist (const string &name) const
 Check existence of argument description.
const CArgValueoperator[] (const string &name) const
 Get value of argument by name.
size_t GetNExtra (void) const
 Get the number of unnamed positional (a.k.a. extra) args.
const CArgValueoperator[] (size_t idx) const
 Return N-th extra arg value, N = 1 to GetNExtra().
vector< CRef< CArgValue > > GetAll (void) const
 Get all available arguments.
stringPrint (string &str) const
 Print (append) all arguments to the string "str" and return "str".
void Add (CArgValue *arg, bool update=false, bool add_value=false)
 Add new argument name and value.
bool IsEmpty (void) const
 Check if there are no arguments in this container.
void Remove (const string &name)
 Remove argument of name "name".
void Reset (void)
 Remove all arguments.
string GetCommand (void) const
 Get current command.

Protected Member Functions

CArgsSetCommand (const string &command)
 Set current command.

Private Types

typedef set< CRef< CArgValue > > TArgs
 Type for arguments.
typedef TArgs::iterator TArgsI
 Type for iterator.
typedef TArgs::const_iterator TArgsCI
 Type for const iterator.

Private Member Functions

TArgsCI x_Find (const string &name) const
 Find argument value with name "name".
TArgsI x_Find (const string &name)

Private Attributes

TArgs m_Args
 Assoc. map of arguments' name/value.
size_t m_nExtra
 Cached # of unnamed positional arguments.
string m_Command

Friends

class CCommandArgDescriptions

Detailed Description

CArgs --.

Defines parsed arguments.

Argument values are obtained from the unprocessed command-line arguments (via CNcbiArguments) and then verified and processed according to the argument descriptions defined by user in "CArgDescriptions".

NOTE: the extra arguments can be accessed using virtual names: "#1", "#2", "#3", ..., "#<GetNExtra()>" in the order of insertion (by method Add).

Definition at line 354 of file ncbiargs.hpp.


Member Typedef Documentation

typedef set< CRef<CArgValue> > CArgs::TArgs [private]

Type for arguments.

Definition at line 436 of file ncbiargs.hpp.

Type for const iterator.

Definition at line 438 of file ncbiargs.hpp.

typedef TArgs::iterator CArgs::TArgsI [private]

Type for iterator.

Definition at line 437 of file ncbiargs.hpp.


Constructor & Destructor Documentation

CArgs::CArgs ( void  )

Constructor.

Definition at line 1640 of file ncbiargs.cpp.

References m_nExtra.

CArgs::~CArgs ( void  )

Destructor.

Definition at line 1646 of file ncbiargs.cpp.


Member Function Documentation

void CArgs::Add ( CArgValue arg,
bool  update = false,
bool  add_value = false 
)

Add new argument name and value.

Throw an exception if the "name" is not an empty string, and if there is an argument with this name already and "update" parameter is not set.

HINT: Use empty "name" to add extra (unnamed) args, and they will be automagically assigned with the virtual names: "#1", "#2", "#3", etc.

Parameters:
argargument value added to the collection
updatewhen TRUE and argument already exists it will be replaced when FALSE throws an exception
add_valuewhen TRUE and argument already exists the value is added to the string list (multiple argument)

Definition at line 1789 of file ncbiargs.cpp.

References _ASSERT, CArgValue::AsString(), set< Key, Compare >::end(), CArgValue::GetName(), set< Key, Compare >::insert(), m_Args, CArgValue::m_Name, m_nExtra, NCBI_THROW, Remove(), s_ComposeNameExtra(), CArgValue::SetOrdinalPosition(), CArgValue::SetStringList(), set< Key, Compare >::size(), CArgDescriptions::VerifyName(), and x_Find().

Referenced by CArgDescriptions::x_PostCheck().

bool CArgs::Exist ( const string name) const
vector< CRef< CArgValue > > CArgs::GetAll ( void  ) const

Get all available arguments.

Definition at line 1736 of file ncbiargs.cpp.

References ITERATE, and m_Args.

Referenced by CJniUtil::GetArgsFromNcbiApp(), CArgDescriptions::x_CreateArg(), and CBlastAppArgs::x_IssueWarningsForIgnoredOptions().

string CArgs::GetCommand ( void  ) const [inline]

Get current command.

See also:
CCommandArgDescriptions

Definition at line 421 of file ncbiargs.hpp.

Referenced by CNcbiApplogApp::Redirect(), and CNcbiApplogApp::Run().

size_t CArgs::GetNExtra ( void  ) const [inline]
bool CArgs::IsEmpty ( void  ) const

Check if there are no arguments in this container.

Definition at line 1827 of file ncbiargs.cpp.

References set< Key, Compare >::empty(), and m_Args.

Referenced by CArgDescriptions::x_PostCheck().

const CArgValue & CArgs::operator[] ( const string name) const

Get value of argument by name.

If the name starts with '-' (e.g. '-arg') the argument can also be found by 'arg' name if there is no another argument named 'arg'.

Throw an exception if such argument does not exist.

See also:
Exist() above.

Definition at line 1691 of file ncbiargs.cpp.

References set< Key, Compare >::end(), kMax_UInt, m_Args, m_nExtra, NCBI_THROW, s_ComposeNameExtra(), NStr::StringToUInt(), and x_Find().

const CArgValue & CArgs::operator[] ( size_t  idx) const

Return N-th extra arg value, N = 1 to GetNExtra().

Definition at line 1731 of file ncbiargs.cpp.

References s_ComposeNameExtra().

string & CArgs::Print ( string str) const
void CArgs::Remove ( const string name)

Remove argument of name "name".

Definition at line 1775 of file ncbiargs.cpp.

References set< Key, Compare >::erase(), set< Key, Compare >::find(), and m_Args.

Referenced by Add(), and CPsiBlastApp::x_RunLocalPsiBlastIterations().

void CArgs::Reset ( void  )

Remove all arguments.

Definition at line 1782 of file ncbiargs.cpp.

References set< Key, Compare >::clear(), m_Args, and m_nExtra.

CArgs* CArgs::SetCommand ( const string command) [inline, protected]

Set current command.

See also:
CCommandArgDescriptions

Definition at line 429 of file ncbiargs.hpp.

References command.

Referenced by CCommandArgDescriptions::CreateArgs().

CArgs::TArgsCI CArgs::x_Find ( const string name) const [private]

Find argument value with name "name".

Definition at line 1664 of file ncbiargs.cpp.

References set< Key, Compare >::end(), set< Key, Compare >::find(), m_Args, and s_IsArgNameChar().

Referenced by Add(), Exist(), and operator[]().

CArgs::TArgsI CArgs::x_Find ( const string name) [private]

Friends And Related Function Documentation

friend class CCommandArgDescriptions [friend]

Definition at line 447 of file ncbiargs.hpp.


Member Data Documentation

TArgs CArgs::m_Args [private]

Assoc. map of arguments' name/value.

Definition at line 440 of file ncbiargs.hpp.

Referenced by Add(), Exist(), GetAll(), IsEmpty(), operator[](), Print(), Remove(), Reset(), and x_Find().

Definition at line 442 of file ncbiargs.hpp.

size_t CArgs::m_nExtra [private]

Cached # of unnamed positional arguments.

Definition at line 441 of file ncbiargs.hpp.

Referenced by Add(), CArgs(), operator[](), and Reset().


The documentation for this class was generated from the following files:
Modified on Mon Sep 22 17:20:06 2014 by modify_doxy.py rev. 426318