Logo Search packages:      
Sourcecode: passwordmaker-cli version File versions  Download package

ArgException.h

/****************************************************************************** 
 * 
 *  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 TCLAP_ARG_EXCEPTION_H
#define TCLAP_ARG_EXCEPTION_H

#include <string>
#include <exception>

namespace TCLAP {

/**
 * A simple class that defines and argument exception.  Should be caught
 * whenever a CmdLine is created and parsed.
 */
00035 class ArgException : public std::exception
{
      public:
      
            /**
             * Constructor.
             * \param text - The text of the exception.
             * \param id - The text identifying the argument source.
             * \param td - Text describing the type of ArgException it is.
             * of the exception.
             */
00046             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)
            { } 
            
            /**
             * Destructor.
             */
00058             virtual ~ArgException() throw() { }

            /**
             * Returns the error text.
             */
00063             std::string error() const { return ( _errorText ); }

            /**
             * Returns the argument id.
             */
00068             std::string argId() const  
            { 
                  if ( _argId == "undefined" )
                        return " ";
                  else
                        return ( "Argument: " + _argId ); 
            }

            /**
             * Returns the arg id and error text. 
             */
00079             const char* what() const throw() 
            {
                  std::string ex = _argId + " -- " + _errorText;
                  return ex.c_str();
            }

            /**
             * Returns the type of the exception.  Used to explain and distinguish
             * between different child exceptions.
             */
00089             std::string typeDescription() const
            {
                  return _typeDescription; 
            }


      private:

            /**
             * The text of the exception message.
             */
00100             std::string _errorText;

            /**
             * The argument related to this exception.
             */
00105             std::string _argId;

            /**
             * Describes the type of the exception.  Used to distinguish
             * between different child exceptions.
             */
00111             std::string _typeDescription;

};

/**
 * Thrown from within the child Arg classes when it fails to properly
 * parse the argument it has been passed.
 */
00119 class ArgParseException : public ArgException
{ 
      public:
            /**
             * Constructor.
             * \param text - The text of the exception.
             * \param id - The text identifying the argument source 
             * of the exception.
             */
00128             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." ))
                  { }
};

/**
 * Thrown from CmdLine when the arguments on the command line are not
 * properly specified, e.g. too many arguments, required argument missing, etc.
 */
00141 class CmdLineParseException : public ArgException
{
      public:
            /**
             * Constructor.
             * \param text - The text of the exception.
             * \param id - The text identifying the argument source 
             * of the exception.
             */
00150             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." ))
            { }
};

/**
 * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. 
 * same flag as another Arg, same name, etc.
 */
00165 class SpecificationException : public ArgException
{
      public:
            /**
             * Constructor.
             * \param text - The text of the exception.
             * \param id - The text identifying the argument source 
             * of the exception.
             */
00174             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 TCLAP

#endif


Generated by  Doxygen 1.6.0   Back to index