TCLAP/include/tclap/ArgException.h
2004-09-07 18:24:48 +00:00

110 lines
2.3 KiB
C++

/******************************************************************************
*
* file: ArgException.h
*
* Copyright (c) 2003, Michael E. Smoot .
* All rights reverved.
*
* See the file COPYING in the top directory of this distribution for
* more information.
*
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef __ARG_EXCEPTION_H__
#define __ARG_EXCEPTION_H__
#include <string>
namespace TCLAP {
/**
* A simple class that defines and argument exception. Should be caught
* whenever a CmdLine is created and parsed.
*/
class ArgException
{
public:
/**
* Constructor.
* \param text - The text of the exception.
* \param id - The text identifying the argument source
* of the exception.
*/
ArgException( const std::string& text = "undefined exception",
const std::string& id = "undefined" )
: _errorText(text), _argId( id ) {};
/**
* Copy constructor.
* \param e - The ArgException that will be copied.
*/
ArgException(const ArgException& e)
: _errorText(e._errorText), _argId(e._argId) {};
/**
* Destructor.
*/
~ArgException() {};
/**
* Assignment operator.
* \param e - The ArgException that will be assigned
* to this.
*/
ArgException& operator=( const ArgException& e )
{
if ( this != &e )
{
_errorText = e._errorText;
_argId = e._argId;
}
return *this;
};
/**
* Returns the error text.
*/
std::string error() { return ( _errorText ); };
/**
* Returns the argument id.
*/
std::string argId()
{
if ( _argId == "undefined" )
return " ";
else
return ( "Argument: " + _argId );
};
private:
/**
* The text of the exception message.
*/
std::string _errorText;
/**
* The argument related to this exception.
*/
std::string _argId;
};
}
#endif