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

Compiled command definition class. More...

#include <CmdDef.h>

Public Member Functions

 CmdDef ()
 Default constructor.
 
 CmdDef (const CmdDef &src)
 Copy constructor. More...
 
virtual ~CmdDef ()
 Destructor.
 
CmdDefoperator= (const CmdDef &rhs)
 Assignment operator. More...
 
bool isDefined () const
 
int getUid () const
 Get command's unique id. More...
 
const std::string & getName () const
 Return command's name. More...
 
const std::string & getSyntax () const
 Return command's syntax usage. More...
 
const std::string & getSynopsis () const
 Return command's synopsis. More...
 
const std::string & getLongDesc () const
 Return command's long description. More...
 
int numOfForms () const
 Get the total number command forms. More...
 
const CmdFormDefat (const int nIndex) const
 Get command form at index. More...
 
const CmdFormDefoperator[] (const int nIndex) const
 Index operator. More...
 

Protected Member Functions

void reset ()
 Reset command definition to pre-compiled state.
 
void setUid (const int uid)
 Set command's unique id. More...
 
void setName (const std::string &strName)
 Set command's name. More...
 
void pushForm (CmdFormDef &formdef)
 Push new command form to end of form list. More...
 
CmdFormDefformAt (const int nIndex)
 Get command modifiable form at index. More...
 
void addHelp (const char *sSynopsis, const char *sLongDesc)
 Add help to command. More...
 
void addHelp (const std::string &strSynopsis, const std::string &strLongDesc)
 

Protected Attributes

int m_nUid
 command unique id
 
std::string m_strName
 command name
 
std::string m_strSyntax
 parsable command extended usage syntax
 
std::string m_strSynopsis
 short command synopsis
 
std::string m_strLongDesc
 long command description
 
CmdFormDefVec m_formDefs
 vector of command forms
 

Friends

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

Detailed Description

Compiled command definition class.

Definition at line 88 of file CmdDef.h.

Constructor & Destructor Documentation

CmdDef::CmdDef ( const CmdDef src)

Copy constructor.

Parameters
srcSource object.

Definition at line 102 of file CmdDef.cxx.

References m_formDefs, m_nUid, m_strLongDesc, m_strName, m_strSynopsis, and m_strSyntax.

103 {
104  m_nUid = src.m_nUid;
105  m_strName = src.m_strName;
106  m_strSyntax = src.m_strSyntax;
109  m_formDefs = src.m_formDefs;
110 }
std::string m_strSynopsis
short command synopsis
Definition: CmdDef.h:231
int m_nUid
command unique id
Definition: CmdDef.h:228
std::string m_strLongDesc
long command description
Definition: CmdDef.h:232
std::string m_strName
command name
Definition: CmdDef.h:229
std::string m_strSyntax
parsable command extended usage syntax
Definition: CmdDef.h:230
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233

Member Function Documentation

void CmdDef::addHelp ( const char *  sSynopsis,
const char *  sLongDesc 
)
protected

Add help to command.

Parameters
sSynopsisShort command synopsis.
sLongDescLong command description.
strSynopsisShort command synopsis.
strLongDescLong command description.

Definition at line 152 of file CmdDef.cxx.

153 {
154  string strSynopsis(sSynopsis != NULL? sSynopsis: "");
155  string strLongDesc(sLongDesc != NULL? sLongDesc: "");
156 
157  addHelp(strSynopsis, strLongDesc);
158 }
void addHelp(const char *sSynopsis, const char *sLongDesc)
Add help to command.
Definition: CmdDef.cxx:152
const CmdFormDef & CmdDef::at ( const int  nIndex) const

Get command form at index.

Parameters
nIndexForm's index.
Returns
Command form definition reference.

Definition at line 175 of file CmdDef.cxx.

References rnr::cmd::noformdef.

Referenced by rnr::cmd::CommandLine::matchCommand(), rnr::cmd::CommandLine::numOfArgs(), numOfForms(), rnr::cmd::CommandLine::numOfOptionalArgs(), rnr::cmd::CommandLine::numOfRequiredArgs(), and operator[]().

176 {
177  if( (nIndex >= 0) && (nIndex < m_formDefs.size()) )
178  {
179  return m_formDefs[nIndex];
180  }
181  else
182  {
183  return noformdef;
184  }
185 }
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233
static CmdFormDef noformdef
constant "no form def" form definition
Definition: CmdDef.cxx:88
CmdFormDef & CmdDef::formAt ( const int  nIndex)
protected

Get command modifiable form at index.

Protected version of at().

Parameters
nIndexForm's index.
Returns
Command form definition reference.

Definition at line 187 of file CmdDef.cxx.

References rnr::io::deltaindent(), rnr::io::indent(), m_formDefs, m_nUid, m_strLongDesc, m_strName, m_strSynopsis, m_strSyntax, rnr::cmd::noformdef, numOfForms(), and operator<<().

Referenced by rnr::cmd::CommandLine::compile(), and rnr::cmd::CommandLine::match().

188 {
189  if( (nIndex >= 0) && (nIndex < m_formDefs.size()) )
190  {
191  return m_formDefs[nIndex];
192  }
193  else
194  {
195  return noformdef;
196  }
197 }
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233
static CmdFormDef noformdef
constant "no form def" form definition
Definition: CmdDef.cxx:88
const std::string& rnr::cmd::CmdDef::getLongDesc ( ) const
inline

Return command's long description.

Returns
Long description string.

Definition at line 174 of file CmdDef.h.

References m_strLongDesc.

Referenced by rnr::cmd::addons::execHelp().

175  {
176  return m_strLongDesc;
177  }
std::string m_strLongDesc
long command description
Definition: CmdDef.h:232
const std::string& rnr::cmd::CmdDef::getName ( ) const
inline

Return command's name.

Returns
Name string.

Definition at line 144 of file CmdDef.h.

References m_strName.

Referenced by rnr::cmd::CommandLine::compile(), rnr::cmd::addons::execHelp(), rnr::cmd::CommandLine::finalize(), rnr::cmd::CommandLine::matchCommand(), rnr::cmd::CommandLine::parseArgv0(), and rnr::cmd::CommandLine::parseSyntax().

145  {
146  return m_strName;
147  }
std::string m_strName
command name
Definition: CmdDef.h:229
const std::string& rnr::cmd::CmdDef::getSynopsis ( ) const
inline

Return command's synopsis.

Returns
Synopsis string.

Definition at line 164 of file CmdDef.h.

References m_strSynopsis.

Referenced by rnr::cmd::addons::execHelp().

165  {
166  return m_strSynopsis;
167  }
std::string m_strSynopsis
short command synopsis
Definition: CmdDef.h:231
const std::string& rnr::cmd::CmdDef::getSyntax ( ) const
inline

Return command's syntax usage.

Returns
Syntax string.

Definition at line 154 of file CmdDef.h.

References m_strSyntax.

Referenced by rnr::cmd::addons::execHelp().

155  {
156  return m_strSyntax;
157  }
std::string m_strSyntax
parsable command extended usage syntax
Definition: CmdDef.h:230
int rnr::cmd::CmdDef::getUid ( ) const
inline
int rnr::cmd::CmdDef::numOfForms ( ) const
inline

Get the total number command forms.

Returns
Number of forms.

Definition at line 184 of file CmdDef.h.

References at(), and m_formDefs.

Referenced by rnr::cmd::CommandLine::compile(), formAt(), and rnr::cmd::CommandLine::matchCommand().

185  {
186  return (int)m_formDefs.size();
187  }
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233
CmdDef & CmdDef::operator= ( const CmdDef rhs)

Assignment operator.

Parameters
rhsRight-hand side object.
Returns
*this

Definition at line 116 of file CmdDef.cxx.

References m_formDefs, m_nUid, m_strLongDesc, m_strName, m_strSynopsis, and m_strSyntax.

117 {
118  m_nUid = rhs.m_nUid;
119  m_strName = rhs.m_strName;
120  m_strSyntax = rhs.m_strSyntax;
123  m_formDefs = rhs.m_formDefs;
124 }
std::string m_strSynopsis
short command synopsis
Definition: CmdDef.h:231
int m_nUid
command unique id
Definition: CmdDef.h:228
std::string m_strLongDesc
long command description
Definition: CmdDef.h:232
std::string m_strName
command name
Definition: CmdDef.h:229
std::string m_strSyntax
parsable command extended usage syntax
Definition: CmdDef.h:230
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233
const CmdFormDef& rnr::cmd::CmdDef::operator[] ( const int  nIndex) const
inline

Index operator.

Get command form at index.

Parameters
nIndexArgument index.
Returns
Command form definition reference.

Definition at line 207 of file CmdDef.h.

References at(), and operator<<.

208  {
209  return at(nIndex);
210  }
const CmdFormDef & at(const int nIndex) const
Get command form at index.
Definition: CmdDef.cxx:175
void CmdDef::pushForm ( CmdFormDef formdef)
protected

Push new command form to end of form list.

Parameters
formdefCommand form definition.

Definition at line 166 of file CmdDef.cxx.

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

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

167 {
168  int nIndex = numOfForms();
169 
170  formdef.setParent(m_nUid);
171  formdef.setIndex(nIndex);
172  m_formDefs.push_back(formdef);
173 }
int m_nUid
command unique id
Definition: CmdDef.h:228
void setParent(const int nCmdUid)
Set parent&#39;s command id.
Definition: CmdFormDef.cxx:152
int numOfForms() const
Get the total number command forms.
Definition: CmdDef.h:184
void setIndex(const int nIndex)
Set forms&#39;s index.
Definition: CmdFormDef.cxx:157
CmdFormDefVec m_formDefs
vector of command forms
Definition: CmdDef.h:233
void CmdDef::setName ( const std::string &  strName)
protected

Set command's name.

Parameters
strNameName string.

Definition at line 147 of file CmdDef.cxx.

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

148 {
149  m_strName = strName;
150 }
std::string m_strName
command name
Definition: CmdDef.h:229
void CmdDef::setUid ( const int  uid)
protected

Set command's unique id.

Parameters
uidUnique id.

Definition at line 142 of file CmdDef.cxx.

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

143 {
144  m_nUid = uid;
145 }
int m_nUid
command unique id
Definition: CmdDef.h:228

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CmdDef cmddef 
)
friend

Insert object into output stream.

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

Referenced by operator[]().


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