mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-10 04:41:57 -04:00
Memory allocated in _constructor is now deleted when the object is destroyed
This commit is contained in:
parent
6cd0c3db78
commit
6c06e31bb2
@ -46,26 +46,50 @@ CmdLine::CmdLine(const string& m, char delim, const string& v )
|
||||
_constructor();
|
||||
}
|
||||
|
||||
CmdLine::~CmdLine()
|
||||
{
|
||||
list<Arg*>::iterator argIter;
|
||||
list<Visitor*>::iterator visIter;
|
||||
|
||||
for(argIter = _argDeleteOnExitList.begin(); argIter != _argDeleteOnExitList.end(); ++argIter) {
|
||||
delete *argIter;
|
||||
}
|
||||
|
||||
for(visIter = _visitorDeleteOnExitList.begin(); visIter != _visitorDeleteOnExitList.end(); ++visIter) {
|
||||
delete *visIter;
|
||||
}
|
||||
}
|
||||
|
||||
void CmdLine::_constructor()
|
||||
{
|
||||
Visitor *v;
|
||||
|
||||
Arg::setDelimiter( _delimiter );
|
||||
|
||||
SwitchArg* help = new SwitchArg("h","help",
|
||||
"Displays usage information and exits.",
|
||||
false, new HelpVisitor( this ) );
|
||||
v = new HelpVisitor( this );
|
||||
SwitchArg* help = new SwitchArg("h","help",
|
||||
"Displays usage information and exits.",
|
||||
false, v);
|
||||
add( *help );
|
||||
|
||||
deleteOnExit(help);
|
||||
deleteOnExit(v);
|
||||
|
||||
v = new VersionVisitor( this );
|
||||
SwitchArg* vers = new SwitchArg("v","version",
|
||||
"Displays version information and exits.",
|
||||
false, new VersionVisitor( this ) );
|
||||
"Displays version information and exits.",
|
||||
false, v);
|
||||
add( *vers );
|
||||
deleteOnExit(vers);
|
||||
deleteOnExit(v);
|
||||
|
||||
v = new IgnoreRestVisitor();
|
||||
SwitchArg* ignore = new SwitchArg(Arg::flagStartString,
|
||||
Arg::ignoreNameString,
|
||||
"Ignores the rest of the labeled arguments following this flag.",
|
||||
false, new IgnoreRestVisitor() );
|
||||
Arg::ignoreNameString,
|
||||
"Ignores the rest of the labeled arguments following this flag.",
|
||||
false, v);
|
||||
add( *ignore );
|
||||
|
||||
deleteOnExit(ignore);
|
||||
deleteOnExit(v);
|
||||
}
|
||||
|
||||
void CmdLine::xorAdd( vector<Arg*>& ors )
|
||||
@ -223,4 +247,14 @@ bool CmdLine::_emptyCombined(const string& s)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CmdLine::deleteOnExit(Arg* ptr)
|
||||
{
|
||||
_argDeleteOnExitList.push_back(ptr);
|
||||
}
|
||||
|
||||
void CmdLine::deleteOnExit(Visitor* ptr)
|
||||
{
|
||||
_visitorDeleteOnExitList.push_back(ptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user