# common.h

Go to the documentation of this file.
00001 /*
00002  * common.h
00003  *
00004  * Copyright 2002,2008,2009  Thomas A. Vaughan
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Most wavepacket programs use this header first for common definitions.
00032  */
00033
00034 #ifndef WAVEPACKET_COMMON_H__
00035 #define WAVEPACKET_COMMON_H__
00036
00037
00038 /// \ingroup wavepacket_top
00039 /*@{*/
00040
00041 ////////////////////////////////////////////////////////////////////////////////
00042 ///
00043 /// \defgroup   common Wavepacket Common Headers
00044 ///
00046 /// used to include and declare the lowest-level of expected system APIs.
00047 ///
00048 ////////////////////////////////////////////////////////////////////////////////
00049 /*@{*/
00050
00051
00052 // includes --------------------------------------------------------------------
00053 #include <stdint.h>
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057
00058 #include <string>
00059 #include <vector>
00060 #include <map>
00061 #include <set>
00062
00063
00064 // function parameter decoration
00065 #define IN      /* does nothing */
00066 #define OUT     /* does nothing */
00067 #define IO      /* does nothing */
00068
00069
00070 // basic types
00071
00072 /// basic (unsigned) 8-bit type
00073 typedef unsigned char byte_t;
00074
00075 /// basic (unsigned) 16-bit type
00076 typedef uint16_t word_t;
00077
00078 /// basic (unsigned) 32-bit type
00079 typedef uint32_t dword_t;
00080
00081 /// basic (unsigned) 64-bit type
00082 typedef uint64_t qword_t;
00083
00084
00085 // strings and collections of strings
00086 typedef std::vector<std::string> VecString;
00087 typedef std::set<std::string> SetString;
00088 typedef std::map<std::string, std::string> Dictionary;
00089
00090
00091 #define DPRINTF(args...)                                                \
00092         {                                                               \
00093                 fprintf(stderr, __FILE__ "(%d): ", __LINE__);           \
00094                 fprintf(stderr, args);                                  \
00095                 fprintf(stderr, "\n");                                  \
00096         }
00097
00098 // there can be a lot of debug statements *after* the assertion failure,
00099 // so this text needs to be pretty visible.
00100 #define ASSERT(exp, args...)                                            \
00101         {                                                               \
00102                 if (!(exp)) {                                           \
00103                         DPRINTF("************************************");\
00104                         DPRINTF("ASSERTION FAILURE: %s", #exp );        \
00105                         DPRINTF(args);                                  \
00106                         DPRINTF("************************************");\
00107                         int * pv = NULL;                                \
00108                         *pv = 5;                                        \
00109                 }                                                       \
00110         }
00111
00112 //                      exit(EXIT_FAILURE);
00113
00114 #define IMPLIES(x,y,args...) ASSERT((!(x)) || (y), args)
00115
00116
00117 // alloca() function
00118 #ifndef alloca
00119 #define alloca __builtin_alloca
00120 #endif  // alloca
00121
00122
00123 // include the exception header
00124 #include "wave_ex.h"
00125
00126
00127 // very common enums
00128
00129 /// used to specify object creation behavior
00130 enum eCreateFlag {
00131         eCreateIfNotExists      = 1, ///< yes, create if not there
00132         eNullIfNotExists        = 0, ///< no, return null or error
00133         eErrorIfNotExists       = 0  ///< same as above
00134 };
00135
00136
00137
00138 #endif  // WAVEPACKET_COMMON_H__
00139