pdns  4.2.0-rc1
About: PowerDNS daemon - a high performance authoritative nameserver. Release candidate.
  Fossies Dox: pdns-4.2.0-rc1.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ArgvMap Class Reference

#include <arguments.hh>

Collaboration diagram for ArgvMap:

Public Types

typedef map< string, string > param_t
 use this if you need to know the content of the map More...
 

Public Member Functions

 ArgvMap ()
 
void parse (int &argc, char **argv, bool lax=false)
 use this to parse from argc and argv More...
 
void laxParse (int &argc, char **argv)
 
void preParse (int &argc, char **argv, const string &arg)
 use this to preparse a single var More...
 
bool preParseFile (const char *fname, const string &arg, const string &theDefault="")
 use this to preparse a single var in configuration More...
 
bool file (const char *fname, bool lax=false)
 Parses a file with parameters. More...
 
bool file (const char *fname, bool lax, bool included)
 
bool laxFile (const char *fname)
 
bool parseFile (const char *fname, const string &arg, bool lax)
 
bool parmIsset (const string &var)
 Checks if a parameter is set to a value. More...
 
bool mustDo (const string &var)
 if a switch is given, if we must do something (–help) More...
 
int asNum (const string &var, int def=0)
 return a variable value as a number or the default if the variable is empty More...
 
mode_t asMode (const string &var)
 return value interpreted as octal number More...
 
uid_t asUid (const string &var)
 return user id, resolves if necessary More...
 
gid_t asGid (const string &var)
 return group id, resolves if necessary More...
 
double asDouble (const string &var)
 return a variable value as a number More...
 
string & set (const string &)
 Gives a writable reference and allocates space for it. More...
 
string & set (const string &, const string &)
 Does the same but also allows one to specify a help message. More...
 
void setCmd (const string &, const string &)
 Add a command flag. More...
 
string & setSwitch (const string &, const string &)
 Add a command flag. More...
 
string helpstring (string prefix="")
 generates the –help More...
 
string configstring (bool current=false)
 generates the –mkconfig More...
 
bool contains (const string &var, const string &val)
 
bool isEmpty (const string &var)
 checks if variable has value More...
 
vector< string > list ()
 
string getHelp (const string &item)
 
const param_t::const_iterator begin ()
 iterator semantics More...
 
const param_t::const_iterator end ()
 iterator semantics More...
 
const string & operator[] (const string &)
 iterator semantics More...
 
const vector< string > & getCommands ()
 
void gatherIncludes (std::vector< std::string > &extraConfigs)
 

Private Types

typedef map< string, string > params_t
 

Private Member Functions

void parseOne (const string &unparsed, const string &parseOnly="", bool lax=false)
 

Private Attributes

params_t params
 
map< string, string > helpmap
 
map< string, string > d_typeMap
 
vector< string > d_cmds
 
std::set< string > d_cleared
 

Detailed Description

This class helps parsing argc and argv into a map of parameters. We have 3 kinds of formats:

-w this leads to a key/value pair of "w"/void

–port=25 "port"/"25"

–daemon "daemon"/void

We do not support "--port 25" syntax.

It can also read from a file. This file can contain '#' to delimit comments.

Some sample code:

R.set("port")="25"; // use this to specify default parameters
R.file("./default.conf"); // parse configuration file
R.parse(argc, argv); // read the arguments from main()
cout<<"Will we be a daemon?: "<<R.isset("daemon")<<endl;
cout<<"Our port will be "<<R["port"]<<endl;
map<string,string>::const_iterator i;
cout<<"via iterator"<<endl;
for(i=R.begin();i!=R.end();i++)
cout<<i->first<<"="<<i->second<<endl;

Definition at line 77 of file arguments.hh.

Member Typedef Documentation

◆ param_t

typedef map<string,string> ArgvMap::param_t

use this if you need to know the content of the map

Definition at line 96 of file arguments.hh.

◆ params_t

typedef map<string,string> ArgvMap::params_t
private

Definition at line 123 of file arguments.hh.

Constructor & Destructor Documentation

◆ ArgvMap()

ArgvMap::ArgvMap ( )

Definition at line 287 of file arguments.cc.

Member Function Documentation

◆ asDouble()

double ArgvMap::asDouble ( const string &  var)

return a variable value as a number

Definition at line 266 of file arguments.cc.

References arg(), params, and parmIsset().

◆ asGid()

gid_t ArgvMap::asGid ( const string &  var)

return group id, resolves if necessary

Definition at line 196 of file arguments.cc.

References arg(), params, and parmIsset().

◆ asMode()

mode_t ArgvMap::asMode ( const string &  var)

return value interpreted as octal number

Definition at line 180 of file arguments.cc.

References arg(), params, and parmIsset().

◆ asNum()

◆ asUid()

uid_t ArgvMap::asUid ( const string &  var)

return user id, resolves if necessary

Definition at line 217 of file arguments.cc.

References arg(), params, and parmIsset().

◆ begin()

const ArgvMap::param_t::const_iterator ArgvMap::begin ( )

iterator semantics

Definition at line 38 of file arguments.cc.

References params.

◆ configstring()

string ArgvMap::configstring ( bool  current = false)

generates the –mkconfig

Definition at line 144 of file arguments.cc.

References d_typeMap, helpmap, and params.

Referenced by DLCurrentConfigHandler(), and main().

◆ contains()

bool ArgvMap::contains ( const string &  var,
const string &  val 
)

Definition at line 93 of file arguments.cc.

References params, and stringtok().

Referenced by PacketHandler::trySuperMasterSynchronous().

◆ end()

const ArgvMap::param_t::const_iterator ArgvMap::end ( )

iterator semantics

Definition at line 43 of file arguments.cc.

References params.

◆ file() [1/2]

bool ArgvMap::file ( const char *  fname,
bool  lax,
bool  included 
)

◆ file() [2/2]

bool ArgvMap::file ( const char *  fname,
bool  lax = false 
)

Parses a file with parameters.

Definition at line 431 of file arguments.cc.

Referenced by BOOST_AUTO_TEST_CASE(), file(), laxFile(), and main().

◆ gatherIncludes()

void ArgvMap::gatherIncludes ( std::vector< std::string > &  extraConfigs)

Definition at line 461 of file arguments.cc.

References Logger::Error, g_log, and params.

Referenced by file().

◆ getCommands()

const vector< string > & ArgvMap::getCommands ( )

Definition at line 357 of file arguments.cc.

References d_cmds.

Referenced by main().

◆ getHelp()

string ArgvMap::getHelp ( const string &  item)

Definition at line 66 of file arguments.cc.

References helpmap.

Referenced by AuthWebServer::printargs().

◆ helpstring()

string ArgvMap::helpstring ( string  prefix = "")

generates the –help

Definition at line 111 of file arguments.cc.

References d_typeMap, helpmap, and prefix.

Referenced by loadMainConfig(), and main().

◆ isEmpty()

bool ArgvMap::isEmpty ( const string &  var)

checks if variable has value

Definition at line 259 of file arguments.cc.

References arg(), params, and parmIsset().

Referenced by apiServerZones(), createZone(), and DNSBackend::getSOA().

◆ laxFile()

bool ArgvMap::laxFile ( const char *  fname)
inline

Definition at line 91 of file arguments.hh.

References file().

Referenced by loadMainConfig(), and main().

◆ laxParse()

void ArgvMap::laxParse ( int &  argc,
char **  argv 
)
inline
Parameters
argvuse this to parse from argc and argv

Definition at line 82 of file arguments.hh.

References parse().

Referenced by main().

◆ list()

vector< string > ArgvMap::list ( )

Definition at line 58 of file arguments.cc.

References params.

Referenced by apiServerConfig(), and AuthWebServer::printargs().

◆ mustDo()

◆ operator[]()

const string & ArgvMap::operator[] ( const string &  arg)

iterator semantics

Definition at line 172 of file arguments.cc.

References arg(), params, and parmIsset().

◆ parmIsset()

bool ArgvMap::parmIsset ( const string &  var)

Checks if a parameter is set to a value.

Definition at line 292 of file arguments.cc.

References params.

Referenced by asDouble(), asGid(), asMode(), asNum(), asUid(), file(), isEmpty(), operator[](), and parseOne().

◆ parse()

void ArgvMap::parse ( int &  argc,
char **  argv,
bool  lax = false 
)

use this to parse from argc and argv

Definition at line 362 of file arguments.cc.

References d_cleared, d_cmds, and parseOne().

Referenced by laxParse(), and main().

◆ parseFile()

bool ArgvMap::parseFile ( const char *  fname,
const string &  arg,
bool  lax 
)

Definition at line 380 of file arguments.cc.

References arg(), and parseOne().

Referenced by file(), and preParseFile().

◆ parseOne()

void ArgvMap::parseOne ( const string &  unparsed,
const string &  parseOnly = "",
bool  lax = false 
)
private

Definition at line 297 of file arguments.cc.

References arg(), d_cleared, d_cmds, params, and parmIsset().

Referenced by parse(), parseFile(), and preParse().

◆ preParse()

void ArgvMap::preParse ( int &  argc,
char **  argv,
const string &  arg 
)

use this to preparse a single var

Definition at line 371 of file arguments.cc.

References arg(), and parseOne().

◆ preParseFile()

bool ArgvMap::preParseFile ( const char *  fname,
const string &  arg,
const string &  theDefault = "" 
)

use this to preparse a single var in configuration

Definition at line 424 of file arguments.cc.

References arg(), params, and parseFile().

◆ set() [1/2]

string & ArgvMap::set ( const string &  var)

◆ set() [2/2]

string & ArgvMap::set ( const string &  var,
const string &  help 
)

Does the same but also allows one to specify a help message.

Definition at line 71 of file arguments.cc.

References d_typeMap, helpmap, and set().

◆ setCmd()

void ArgvMap::setCmd ( const string &  var,
const string &  help 
)

Add a command flag.

Definition at line 78 of file arguments.cc.

References d_typeMap, helpmap, and set().

Referenced by declareArguments(), loadMainConfig(), and main().

◆ setSwitch()

string & ArgvMap::setSwitch ( const string &  var,
const string &  help 
)

Add a command flag.

Definition at line 85 of file arguments.cc.

References d_typeMap, helpmap, and set().

Referenced by BOOST_AUTO_TEST_CASE(), declareArguments(), loadMainConfig(), and main().

Member Data Documentation

◆ d_cleared

std::set<string> ArgvMap::d_cleared
private

Definition at line 128 of file arguments.hh.

Referenced by parse(), and parseOne().

◆ d_cmds

vector<string> ArgvMap::d_cmds
private

Definition at line 127 of file arguments.hh.

Referenced by getCommands(), parse(), and parseOne().

◆ d_typeMap

map<string,string> ArgvMap::d_typeMap
private

Definition at line 126 of file arguments.hh.

Referenced by configstring(), helpstring(), set(), setCmd(), and setSwitch().

◆ helpmap

map<string,string> ArgvMap::helpmap
private

Definition at line 125 of file arguments.hh.

Referenced by configstring(), getHelp(), helpstring(), set(), setCmd(), and setSwitch().

◆ params


The documentation for this class was generated from the following files:
ArgvMap::parse
void parse(int &argc, char **argv, bool lax=false)
use this to parse from argc and argv
Definition: arguments.cc:362
ArgvMap::file
bool file(const char *fname, bool lax=false)
Parses a file with parameters.
Definition: arguments.cc:431
ArgvMap::set
string & set(const string &)
Gives a writable reference and allocates space for it.
Definition: arguments.cc:48
ArgvMap::end
const param_t::const_iterator end()
iterator semantics
Definition: arguments.cc:43
ArgvMap::begin
const param_t::const_iterator begin()
iterator semantics
Definition: arguments.cc:38
ArgvMap
Definition: arguments.hh:77