From: <ro...@us...> - 2008-06-27 17:49:29
|
Revision: 1890 http://nscldaq.svn.sourceforge.net/nscldaq/?rev=1890&view=rev Author: ron-fox Date: 2008-06-27 10:49:36 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Add CInvalidArgumentException - good compilation. Modified Paths: -------------- trunk/nextgen/base/exception/Makefile.am Added Paths: ----------- trunk/nextgen/base/exception/CInvalidArgumentException.cpp trunk/nextgen/base/exception/CInvalidArgumentException.h Property Changed: ---------------- trunk/nextgen/base/exception/ Property changes on: trunk/nextgen/base/exception ___________________________________________________________________ Name: svn:ignore + .deps .libs Added: trunk/nextgen/base/exception/CInvalidArgumentException.cpp =================================================================== --- trunk/nextgen/base/exception/CInvalidArgumentException.cpp (rev 0) +++ trunk/nextgen/base/exception/CInvalidArgumentException.cpp 2008-06-27 17:49:36 UTC (rev 1890) @@ -0,0 +1,120 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ +#include <config.h> +#include "CInvalidArgumentException.h" + +using namespace std; + +//////////////////////////////////////////////////////////////////////////////// +// +// Implementation of constructors and other canonical operations. +// + +/*! + * \param argument - The texulized version of the bad argument. + * \param whybad - The reason the argument is bad. + * \param wasdoing - Context information about what was happening when the + * exception was thrown. + */ +CInvalidArgumentException::CInvalidArgumentException(std::string argument, + std::string whybad, + std::string wasDoing) : + CException(wasDoing), + m_valuePassed(argument), + m_whyBad(whybad) +{} +/*! + * Copy construction + * \param rhs Object from which a new copy is constructed. + */ +CInvalidArgumentException::CInvalidArgumentException(const CInvalidArgumentException& rhs) : + CException(rhs), + m_valuePassed(rhs.m_valuePassed), + m_whyBad(rhs.m_whyBad) +{} +/*! + * Destructor just needs to chain to the base class. + */ +CInvalidArgumentException::~CInvalidArgumentException() +{} + +/*! + * Assignement from rhs. + * \param rhs - The object that will be assigned into *this. + * \return CInvalidArgumentException& + * \retval *this + */ +CInvalidArgumentException& +CInvalidArgumentException::operator=(const CInvalidArgumentException& rhs) +{ + if (this != &rhs) { + CException::operator=(rhs); + m_valuePassed = rhs.m_valuePassed; + m_whyBad = rhs.m_whyBad; + } + return *this; +} +/*! + * \param rhs - Object compared for equality with *this. + * \return int + * \retval 1 - Equal. + * \retval 0 - Not equal. + */ +int +CInvalidArgumentException::operator==(const CInvalidArgumentException& rhs) const +{ + return ((CException::operator==(rhs)) && + (m_valuePassed == rhs.m_valuePassed) && + (m_whyBad == rhs.m_whyBad)); +} +/*! + * Inequality is the logical inverse of equality. + * \param rhs - Object being compared to *this. + * \return int + * \retval !operator==(rhs) + */ +int +CInvalidArgumentException::operator!=(const CInvalidArgumentException& rhs) const +{ + return !(*this == rhs); +} +//////////////////////////////////////////////////////////////////////////////// +// +// Operations on the object. +// +/*! + * \return const char* + * \retval A human readable string that describes the error that caused the + * exception to be thrown. + */ +const char* +CInvalidArgumentException::ReasonText() const +{ + // We will build up the string in m_reason which is mutable. + // for exactly this purpose. + // There is a presumption that only one thread will be catching a specific + // object at a time which is not unreasonable. + + m_reason = "Invalid Argument: "; + m_reason += m_valuePassed; + m_reason + " "; + m_reason += m_whyBad; + m_reason += " while "; + m_reason += WasDoing(); + + return m_reason.c_str(); + +} Added: trunk/nextgen/base/exception/CInvalidArgumentException.h =================================================================== --- trunk/nextgen/base/exception/CInvalidArgumentException.h (rev 0) +++ trunk/nextgen/base/exception/CInvalidArgumentException.h 2008-06-27 17:49:36 UTC (rev 1890) @@ -0,0 +1,58 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +#ifndef __CINVALIDARGUMENTEXCEPTION_H +#define __CINVALIDARGUMENTEXCEPTION_H + +#ifndef __EXCEPTION_H +#include <Exception.h> +#endif + +/*! + * This class is ressponsible for reporting exceptions that + * occur because some function (member or otherwise) has been passed an invalid + * argument of some sort. + * + * To use this exception type, the thrower must be able to create a textual + * equivalent of the bad argument, a string that describes why the argument + * is bad as well as supplying the usual context string. + */ +class CInvalidArgumentException : public CException +{ + // Member data (private) +private: + std::string m_valuePassed; + std::string m_whyBad; + mutable std::string m_reason; + + // Constructors and the various canonicals. + +public: + CInvalidArgumentException(std::string argument, std::string whybad, + std::string wasDoing); + CInvalidArgumentException(const CInvalidArgumentException& rhs); + virtual ~CInvalidArgumentException(); + + CInvalidArgumentException& operator=(const CInvalidArgumentException& rhs); + int operator==(const CInvalidArgumentException& rhs) const; + int operator!=(const CInvalidArgumentException& rhs) const; + + // Operations that make this an exception class: + + virtual const char* ReasonText() const; +}; + +#endif Modified: trunk/nextgen/base/exception/Makefile.am =================================================================== --- trunk/nextgen/base/exception/Makefile.am 2008-06-27 14:01:40 UTC (rev 1889) +++ trunk/nextgen/base/exception/Makefile.am 2008-06-27 17:49:36 UTC (rev 1890) @@ -2,11 +2,11 @@ libException_la_SOURCES = ErrnoException.cpp Exception.cpp \ RangeError.cpp StreamIOError.cpp \ StateException.cpp URIFormatException.cpp \ - MonitorException.cpp + MonitorException.cpp CInvalidArgumentException.cpp include_HEADERS = ErrnoException.h Exception.h StreamIOError.h \ RangeError.h StateException.h URIFormatException.h \ - MonitorException.h + MonitorException.h CInvalidArgumentException.h libException_la_LDFLAGS = -version-info $(SOVERSION) \ -Wl,"-rpath-link=$(libdir)" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |