Program Listing for File arg_exception.hpp

Return to documentation for file (/tmp/ws/src/ecl_core/ecl_command_line/include/ecl/command_line/arg_exception.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef TCLAP_ARG_EXCEPTION_H
#define TCLAP_ARG_EXCEPTION_H

#include <string>
#include <exception>

namespace ecl {


class ArgException : public std::exception
{
    public:

        ArgException( const std::string& text = "undefined exception",
                      const std::string& id = "undefined",
                      const std::string& td = "Generic ArgException")
            : std::exception(),
              _errorText(text),
              _argId( id ),
              _typeDescription(td)
        { }

        virtual ~ArgException() throw() { }

        std::string error() const { return ( _errorText ); }

        std::string argId() const
        {
            if ( _argId == "undefined" )
                return " ";
            else
                return ( "Argument: " + _argId );
        }

        const char* what() const throw()
        {
            static std::string ex;
            ex = _argId + " -- " + _errorText;
            return ex.c_str();
        }

        std::string typeDescription() const
        {
            return _typeDescription;
        }


    private:

        std::string _errorText;

        std::string _argId;

        std::string _typeDescription;

};

class ArgParseException : public ArgException
{
    public:
        ArgParseException( const std::string& text = "undefined exception",
                           const std::string& id = "undefined" )
            : ArgException( text,
                            id,
                            std::string( "Exception found while parsing " ) +
                            std::string( "the value the Arg has been passed." ))
            { }
};

class CmdLineParseException : public ArgException
{
    public:
        CmdLineParseException( const std::string& text = "undefined exception",
                               const std::string& id = "undefined" )
            : ArgException( text,
                            id,
                            std::string( "Exception found when the values ") +
                            std::string( "on the command line do not meet ") +
                            std::string( "the requirements of the defined ") +
                            std::string( "Args." ))
        { }
};

class SpecificationException : public ArgException
{
    public:
        SpecificationException( const std::string& text = "undefined exception",
                                const std::string& id = "undefined" )
            : ArgException( text,
                            id,
                            std::string("Exception found when an Arg object ")+
                            std::string("is improperly defined by the ") +
                            std::string("developer." ))
        { }

};

} // namespace ecl


#endif