appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::cmd::CmdFormDef Class Reference

Compiled command form defintion class. More...

#include <CmdFormDef.h>

Public Member Functions

 CmdFormDef ()
 Default constructor.
 
 CmdFormDef (const std::string &strSyntax)
 Initialization constructor.
 
 CmdFormDef (const CmdFormDef &src)
 Copy constructor. More...
 
virtual ~CmdFormDef ()
 Destructor.
 
CmdFormDefoperator= (const CmdFormDef &rhs)
 Assignment operator. More...
 
bool isDefined () const
 
int getParentCmdUid () const
 Get parent command's unique id. More...
 
int getIndex () const
 Get forms's index. More...
 
std::string getSyntax () const
 Get form's extended usage syntax.
 
const CmdArgDefat (const int nIndex) const
 Get form's argument at index. More...
 
const CmdArgDefoperator[] (const int nIndex) const
 Index operator. More...
 
int numOfArgs () const
 Get the total number of arguments. More...
 
int numOfRequiredArgs () const
 Get the total number of required arguments. More...
 
int numOfOptionalArgs () const
 Get the total number of optional arguments. More...
 

Protected Member Functions

void reset ()
 Reset form definition to pre-compiled state.
 
void setParent (const int nCmdUid)
 Set parent's command id. More...
 
void setIndex (const int nIndex)
 Set forms's index. More...
 
void setSyntax (const std::string &strSyntax)
 Set command's extended usage syntax. More...
 
void pushArg (CmdArgDef &argdef)
 Push argument to end of argument list. More...
 
CmdArgDefargAt (const int nIndex)
 Get form's modifiable argument at index. More...
 
CmdArgDeflastArg ()
 Get the last pushed argument. More...
 

Protected Attributes

int m_nCmdUid
 parent command's unique id
 
int m_nIndex
 forms index
 
std::string m_strSyntax
 command extened usage syntax
 
ArgDefVec m_argDefs
 command argument definitions
 
int m_nArgcReq
 number of required arguments
 
int m_nArgcOpt
 number of optional arguments
 

Friends

class CmdDef
 
class CommandLine
 
std::ostream & operator<< (std::ostream &os, const CmdFormDef &formdef)
 Insert object into output stream. More...
 

Detailed Description

Compiled command form defintion class.

Definition at line 91 of file CmdFormDef.h.

Constructor & Destructor Documentation

CmdFormDef::CmdFormDef ( const CmdFormDef src)

Copy constructor.

Parameters
srcSource object.

Definition at line 113 of file CmdFormDef.cxx.

References m_argDefs, m_nArgcOpt, m_nArgcReq, m_nCmdUid, m_nIndex, and m_strSyntax.

114 {
115  m_nCmdUid = src.m_nCmdUid;
116  m_nIndex = src.m_nIndex;
117  m_strSyntax = src.m_strSyntax;
118  m_argDefs = src.m_argDefs;
119  m_nArgcReq = src.m_nArgcReq;
120  m_nArgcOpt = src.m_nArgcOpt;
121 }
std::string m_strSyntax
command extened usage syntax
Definition: CmdFormDef.h:251
int m_nIndex
forms index
Definition: CmdFormDef.h:250
int m_nCmdUid
parent command&#39;s unique id
Definition: CmdFormDef.h:249
int m_nArgcReq
number of required arguments
Definition: CmdFormDef.h:253
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int m_nArgcOpt
number of optional arguments
Definition: CmdFormDef.h:254

Member Function Documentation

CmdArgDef & CmdFormDef::argAt ( const int  nIndex)
protected

Get form's modifiable argument at index.

Protected version of at().

Parameters
nIndexArgument index.
Returns
Command argument definition reference.

Definition at line 188 of file CmdFormDef.cxx.

References rnr::cmd::noargdef.

Referenced by rnr::cmd::CommandLine::rlArgDefs().

189 {
190  if( (nIndex >= 0) && (nIndex < m_argDefs.size()) )
191  {
192  return m_argDefs[nIndex];
193  }
194  else
195  {
196  return noargdef;
197  }
198 }
static CmdArgDef noargdef
constant "no arg def" argument definition
Definition: CmdFormDef.cxx:86
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
const CmdArgDef & CmdFormDef::at ( const int  nIndex) const

Get form's argument at index.

Parameters
nIndexArgument index.
Returns
Command argument definition reference.

Definition at line 176 of file CmdFormDef.cxx.

References rnr::cmd::noargdef.

Referenced by getSyntax(), rnr::cmd::CommandLine::matchCommand(), rnr::cmd::CommandLine::matchCommandForm(), and operator[]().

177 {
178  if( (nIndex >= 0) && (nIndex < m_argDefs.size()) )
179  {
180  return m_argDefs[nIndex];
181  }
182  else
183  {
184  return noargdef;
185  }
186 }
static CmdArgDef noargdef
constant "no arg def" argument definition
Definition: CmdFormDef.cxx:86
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int rnr::cmd::CmdFormDef::getIndex ( ) const
inline

Get forms's index.

Returns
Zero based index.

Definition at line 152 of file CmdFormDef.h.

References m_nIndex.

Referenced by rnr::cmd::CommandLine::compile(), rnr::cmd::CommandLine::matchCommandForm(), rnr::cmd::CommandLine::parseArgv0(), and rnr::cmd::CommandLine::parseSyntax().

153  {
154  return m_nIndex;
155  }
int m_nIndex
forms index
Definition: CmdFormDef.h:250
int rnr::cmd::CmdFormDef::getParentCmdUid ( ) const
inline

Get parent command's unique id.

Returns
Unique id.

Definition at line 142 of file CmdFormDef.h.

References m_nCmdUid.

Referenced by rnr::cmd::CommandLine::matchCommandForm().

143  {
144  return m_nCmdUid;
145  }
int m_nCmdUid
parent command&#39;s unique id
Definition: CmdFormDef.h:249
CmdArgDef & CmdFormDef::lastArg ( )
protected

Get the last pushed argument.

Returns
Argument definition reference.

Definition at line 200 of file CmdFormDef.cxx.

References rnr::io::deltaindent(), rnr::io::indent(), m_argDefs, m_nCmdUid, m_nIndex, m_strSyntax, rnr::cmd::noargdef, numOfArgs(), numOfOptionalArgs(), numOfRequiredArgs(), and operator<<().

Referenced by rnr::cmd::CommandLine::parseArgv0(), rnr::cmd::CommandLine::parseLiteralArg(), rnr::cmd::CommandLine::parseOptionalArgList(), rnr::cmd::CommandLine::parseVariableArg(), and rnr::cmd::CommandLine::parseXorListArg().

201 {
202  return m_argDefs.empty()? noargdef: m_argDefs.back();
203 }
static CmdArgDef noargdef
constant "no arg def" argument definition
Definition: CmdFormDef.cxx:86
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int rnr::cmd::CmdFormDef::numOfArgs ( ) const
inline

Get the total number of arguments.

The first argument (argv0) is the command.

Returns
Number of arguments.

Definition at line 195 of file CmdFormDef.h.

References m_argDefs.

Referenced by lastArg(), rnr::cmd::CommandLine::matchCommandForm(), rnr::cmd::CommandLine::numOfArgs(), rnr::cmd::CommandLine::parseLiteralArg(), rnr::cmd::CommandLine::parseSyntax(), rnr::cmd::CommandLine::parseXorListArg(), and rnr::cmd::CommandLine::rlArgDefs().

196  {
197  return (int)m_argDefs.size();
198  }
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int rnr::cmd::CmdFormDef::numOfOptionalArgs ( ) const
inline

Get the total number of optional arguments.

Optional arguments start at argument index numOfRequiredArgs().

Returns
Number of arguments.

Definition at line 221 of file CmdFormDef.h.

References m_nArgcOpt, and operator<<.

Referenced by lastArg(), and rnr::cmd::CommandLine::numOfOptionalArgs().

222  {
223  return m_nArgcOpt;
224  }
int m_nArgcOpt
number of optional arguments
Definition: CmdFormDef.h:254
int rnr::cmd::CmdFormDef::numOfRequiredArgs ( ) const
inline

Get the total number of required arguments.

The required number includes the command argv0.

Required arguments start at argument index 0.

Returns
Number of arguments.

Definition at line 209 of file CmdFormDef.h.

References m_nArgcReq.

Referenced by lastArg(), rnr::cmd::CommandLine::matchCommandForm(), and rnr::cmd::CommandLine::numOfRequiredArgs().

210  {
211  return m_nArgcReq;
212  }
int m_nArgcReq
number of required arguments
Definition: CmdFormDef.h:253
CmdFormDef & CmdFormDef::operator= ( const CmdFormDef rhs)

Assignment operator.

Parameters
rhsRight-hand side object.
Returns
*this

Definition at line 127 of file CmdFormDef.cxx.

References m_argDefs, m_nArgcOpt, m_nArgcReq, m_nCmdUid, m_nIndex, and m_strSyntax.

128 {
129  m_nCmdUid = rhs.m_nCmdUid;
130  m_nIndex = rhs.m_nIndex;
131  m_strSyntax = rhs.m_strSyntax;
132  m_argDefs = rhs.m_argDefs;
133  m_nArgcReq = rhs.m_nArgcReq;
134  m_nArgcOpt = rhs.m_nArgcOpt;
135 }
std::string m_strSyntax
command extened usage syntax
Definition: CmdFormDef.h:251
int m_nIndex
forms index
Definition: CmdFormDef.h:250
int m_nCmdUid
parent command&#39;s unique id
Definition: CmdFormDef.h:249
int m_nArgcReq
number of required arguments
Definition: CmdFormDef.h:253
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int m_nArgcOpt
number of optional arguments
Definition: CmdFormDef.h:254
const CmdArgDef& rnr::cmd::CmdFormDef::operator[] ( const int  nIndex) const
inline

Index operator.

Get form's argument at index.

Parameters
nIndexArgument index.
Returns
Command argument definition reference.

Definition at line 183 of file CmdFormDef.h.

References at().

184  {
185  return at(nIndex);
186  }
const CmdArgDef & at(const int nIndex) const
Get form&#39;s argument at index.
Definition: CmdFormDef.cxx:176
void CmdFormDef::pushArg ( CmdArgDef argdef)
protected

Push argument to end of argument list.

Parameters
argdefCommand argument definition.

Definition at line 167 of file CmdFormDef.cxx.

References rnr::cmd::CmdArgDef::setIndex(), and rnr::cmd::CmdArgDef::setParent().

Referenced by rnr::cmd::CommandLine::parseLiteralArg(), rnr::cmd::CommandLine::parseVariableArg(), and rnr::cmd::CommandLine::parseXorListArg().

168 {
169  int nIndex = numOfArgs();
170 
171  argdef.setParent(m_nCmdUid, m_nIndex);
172  argdef.setIndex(nIndex);
173  m_argDefs.push_back(argdef);
174 }
void setParent(const int nCmdUid, const int nFormIndex)
Set parent&#39;s command and form id&#39;s.
Definition: CmdArgDef.cxx:179
int m_nIndex
forms index
Definition: CmdFormDef.h:250
int m_nCmdUid
parent command&#39;s unique id
Definition: CmdFormDef.h:249
void setIndex(const int nIndex)
Set arguments&#39;s command line index.
Definition: CmdArgDef.cxx:185
ArgDefVec m_argDefs
command argument definitions
Definition: CmdFormDef.h:252
int numOfArgs() const
Get the total number of arguments.
Definition: CmdFormDef.h:195
void CmdFormDef::setIndex ( const int  nIndex)
protected

Set forms's index.

Parameters
nIndexZero based index.

Definition at line 157 of file CmdFormDef.cxx.

Referenced by rnr::cmd::CmdDef::pushForm().

158 {
159  m_nIndex = nIndex;
160 }
int m_nIndex
forms index
Definition: CmdFormDef.h:250
void CmdFormDef::setParent ( const int  nCmdUid)
protected

Set parent's command id.

Parameters
nCmdUidCommand unique id.

Definition at line 152 of file CmdFormDef.cxx.

Referenced by rnr::cmd::CmdDef::pushForm().

153 {
154  m_nCmdUid = nCmdUid;
155 }
int m_nCmdUid
parent command&#39;s unique id
Definition: CmdFormDef.h:249
void CmdFormDef::setSyntax ( const std::string &  strSyntax)
protected

Set command's extended usage syntax.

Parameters
strSyntaxSyntax string.

Definition at line 162 of file CmdFormDef.cxx.

163 {
164  m_strSyntax = strSyntax;
165 }
std::string m_strSyntax
command extened usage syntax
Definition: CmdFormDef.h:251

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CmdFormDef formdef 
)
friend

Insert object into output stream.

Parameters
osOutput stream.
formdefObject to insert.
Returns
Reference to output stream.

Referenced by numOfOptionalArgs().


The documentation for this class was generated from the following files: