Source

lrc / src / StatusCodes.hxx

Full commit
//      StatusCodes.hxx
//
//      Copyright 2011 Andreas Tscharner <andy@vis.ethz.ch>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU Lesser General Public License as
//      published by the Free Software Foundation; either version 3 of the
//      License, or (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU Lesser General Public
//      License along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


/*! \file StatusCodes.hxx
 *
 * This file contains a number of defines that are used as status (success,
 * warning or error) codes and a few inline functions for better handling
 * these codes
 *
 * \author Andreas Tscharner
 * \date 2011-09-04
 */


#ifndef __STATUSCODES_HXX__
#define __STATUSCODES_HXX__


// Success codes are >= 0
#define NO_ERROR       0               //!< No error, everything OK

// Warnings are < 0 and > -1000
#define WARNING_BASE                  0               //!< Base value for all warning codes
#define WARNING_DOUBLE_RESOURCE_ID    WARNING_BASE-1  //!< The resource ID appears more than once

// Errors are < -1000
#define ERROR_BASE -1000               //!< Base value for all error codes

// File errors
#define ERROR_FILE_OPEN      ERROR_BASE-1   //!< An error occurred while opening the file
#define ERROR_FILE_NOT_FOUND ERROR_BASE-2   //!< The desired file could not be found
#define ERROR_FILE_READ      ERROR_BASE-3   //!< An error occurred while reading the file
#define ERROR_FILE_WRITE     ERROR_BASE-4   //!< An error occurred while writing the file

// Parsing errors
#define ERROR_PARSE ERROR_BASE-10           //!< An error occurred while parsing the file

// Compression/Encryption errors
#define ERROR_COMPRESSION_NOT_AVAILABLE     ERROR_BASE-20  //!< The desired compression is not available
#define ERROR_ENCRYPTION_NOT_AVAILABLE      ERROR_BASE-21  //!< The desired encryption is not available
#define ERROR_COMPRESSION_COMPRESS          ERROR_BASE-22  //!< An error occurred while compressing
#define ERROR_COMPRESSION_DECOMPRESS        ERROR_BASE-23  //!< An error occurred while decompressing
#define ERROR_ENCRYPTION_ENCRYPT            ERROR_BASE-24  //!< An error occurred while encrypting
#define ERROR_ENCRYPTION_DECRYPT            ERROR_BASE-25  //!< An error occurred while decrypting

// General errors
#define ERROR_INVALID_PARAMETER        ERROR_BASE-100      //!< The provided parameter was illegal
#define ERROR_NOT_ENOUGH_MEMORY        ERROR_BASE-101      //!< Not enough memory available for this action


// Inline functions
/*! \brief Check for NO_ERROR
 *
 * Small inline function to check if the given parameter is NO_ERROR
 *
 * \param[in] c Value to check
 *
 * \retval true Value is NO_ERROR
 * \retval false Value is not NO_ERROR
 */
inline bool no_error(int c) { return c==NO_ERROR; };
/*! \brief Check for success
 *
 * Small inline function to check if the given parameter means success, e.g.
 * is greater than NO_ERROR
 *
 * \param[in] c Value to check
 *
 * \retval true Value means success
 * \retval false Value means warning or error
 */
inline bool success(int c) { return c>=NO_ERROR; };

/*! \brief Check for warning
 *
 * Small inline function to check if the given parameter stands for a
 * warning
 *
 * \param[in] c Value to check
 *
 * \retval true Value is a warning code
 * \retval false Value stands for success or error
 */
inline bool is_warning(int c) { return (c < NO_ERROR) && (c > ERROR_BASE); };

/*! \brief Check for error
 *
 * Small inline function to check if the given parameter stands for an error
 *
 * \param[in] c Value to check
 *
 * \retval true Value is an error code
 * \retval false Value stands for warning or success
 */
inline bool is_error(int c) { return c < ERROR_BASE; };


#endif /* __STATUSCODES_HXX__ */