Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phStandard.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifndef _PHSTANDARD_H
00027 #define _PHSTANDARD_H
00028 
00029 /* ---------------------------------------------------------------------- */
00035 /* ------------------------------------------------------------------------ */
00036 /* include the file for making VisualStudio stuff */
00037 #if defined(PHISSION_EXPORTS) && defined(_MSC_VER)
00038     #include <stdafx.h>
00039 #endif
00040 
00041 /* ---------------------------------------------------------------------- */
00042 #if defined(_MSC_VER)
00043     #if defined(PHISSION_EXPORTS)
00044         #define PHAPI(x)        x __declspec( dllexport ) 
00045         #define PHAPI_VAR(x)    __declspec( dllexport ) x 
00046         #define PHAPI_LOCAL(x)  x 
00047     #else
00048         #define PHAPI(x)        x __declspec( dllimport ) 
00049         #define PHAPI_VAR(x)    __declspec( dllimport ) x 
00050         #define PHAPI_LOCAL(x)  x 
00051     #endif
00052 #else
00053     #define PHAPI(x)        x 
00054     #define PHAPI_VAR(x)    x 
00055     #define PHAPI_LOCAL(x)  x 
00056 #endif
00057 
00058 /* ------------------------------------------------------------------------ */
00059 /*
00060 #if defined (__GNUC__) && (__STRICT_ANSI__)
00061 #undef inline
00062 #define inline __inline__
00063 #endif
00064 */
00065 
00066 /* ------------------------------------------------------------------------ */
00067 #ifndef __inline__
00068     #if defined(_MSC_VER)
00069         #define __inline__ __inline
00070     #else 
00071         #define __inline__ inline
00072     #endif
00073 #endif
00074 
00075 /* ------------------------------------------------------------------------ */
00076 #if defined(HAVE_STDIO_H)
00077     #include <stdio.h>
00078 #endif
00079 #if defined(HAVE_STDLIB_H)
00080     #include <stdlib.h>
00081 #endif
00082 #include <phStdint.h>
00083 
00084 /* ------------------------------------------------------------------------ */
00085 /* When using MINGW (-mno-cygwin), srandom/random isn't defined */
00086 #ifndef srandom
00087     #define srandom srand
00088 #endif
00089 #ifndef random
00090     #define random rand
00091 #endif
00092 
00093 /* ------------------------------------------------------------------------ *
00094  * Coding conventions (not strict, but try to be):
00095  * ------------------------------------------------------------------------ *
00096  * 0.) First, everything must begin with a 'ph' to signify it's part of 
00097  *      the library. There is old code that doesn't strictly adhere to this,
00098  *      and can be compiled back in using the phALLOW_OLD_MACROS define.
00099  *      
00100  * a.) Macros
00101  *      ph[A-Z][A-Z_]+
00102  * b.) Renamed/Wrapped commonly used functions like malloc/etc.
00103  *      ph[A-Z][a-zA-Z]+
00104  * c.) Binary (i.e. 1 or 0) macros to compile/disable features
00105  *      ph[A-Z_]+()
00106  *          The () makes sure the macro is properly defined, otherwise the 
00107  *      compiler will complain.
00108  * d.) C structs / typedefs
00109  *      ph_[a-z_]+_t for structs only
00110  *      ph_[a-z_]+ for typedefs only
00111  * e.) C functions
00112  *      ph_[a-z_]+
00113  * f.) C++ class names
00114  *      ph[A-Z][a-zA-Z]+
00115  * g.) C++ methods
00116  *      [a-z][A-Za-z]+
00117  *      First word is lower case in multi-word methods.
00118  */
00119 /* ------------------------------------------------------------------------ */
00120 /* Documentatin standards (Doxygen):
00121  *
00122  * Order of global documentation
00123  *  1.) classes & class methods
00124  *  2.) functions
00125  *  3.) defines
00126  *  4.) structs and typedefs
00127  *  5.) examples
00128  *
00129  *  1.) Methods & Functions
00130  *      RETURN
00131  *      - Must have a \return statement and \retval description if relavant
00132  *      PARAMETERS
00133  *      - If there are parameters, must have \param with [in][out][in,out]
00134  *          specifications
00135  *      BRIEFs
00136  *      - Must have a brief description whether it's public or private,
00137  *        local or global
00138  *      PRE/POST CONDITION
00139  *      - If it is an important method/function, then the \pre and \post
00140  *        conditions must be explicitly discussed
00141  *      SEE reference
00142  *      - Use \see 
00143  *  2.) Classes
00144  *      - Must have a brief and a couple sentence detailed description
00145  *      - Use \see to refer to other relavent classes
00146  *  3.) Defines
00147  *      - Every definition must be documented no matter how small
00148  *  4.) Files
00149  *      - Every file should have a \file file.x with a brief desc. 
00150  *          - after the Copyright/license notice, 
00151  *          - before any includes
00152  *          - after #ifndef header file protection directives
00153  *
00154  */
00155 /* ------------------------------------------------------------------------ */
00156 
00157 /* ------------------------------------------------------------------------ */
00158 #ifdef __cplusplus
00159 extern "C" 
00160 {
00161 #endif
00162 
00163     #define phTHREADS_EQUAL(x,y) (x == y)
00164 
00171     PHAPI(uintmax_t) phGetCurrentThreadId   ( void );
00188     PHAPI(void)      phYield                ( void );
00198     PHAPI(uintmax_t) phProcessId            ( void );
00199     
00215     PHAPI(void) phSleep ( uint32_t seconds      );
00217     PHAPI(void) phMSleep( uint32_t milliseconds );
00219     PHAPI(void) phUSleep( uint32_t microseconds );
00243     PHAPI(int) phStringCopy( const char        *string, 
00244                              const uint32_t    maxlen,
00245                              char              **copy, 
00246                              uint32_t          *copy_size,
00247                              char              *default_str );
00248 
00249 #ifdef __cplusplus
00250 } /* extern "C" { */
00251 #endif
00252 
00253 /* ------------------------------------------------------------------------ */
00258 #define phSET_MIN(a,b) if (a > b) a = b;
00263 #define phSET_MAX(a,b) if (a < b) a = b;
00264 
00275 #define phXOR_SWAP(x,y) { x = x ^ y; y = x ^ y; x = x ^ y; }
00284 #define phSWAP(a,b) { int itemp=(a);(a)=(b);(b)=itemp; }
00285 
00294 #define phCLIP(x) ((x) < 0) ? 0 : ((x) > 255) ? 255 : (x)
00295 
00310 #define phCOMP3(a,b,c,x) ((a x b) ? \
00311                                   ((b x c) ? a : ((a x c) ? a : c)) : \
00312                                   ((a x c) ? b : ((b x c) ? b : c)))
00313 
00317 #define phMIN3(a,b,c) phCOMP3(a,b,c,<)
00318 
00322 #define phMAX3(a,b,c) phCOMP3(a,b,c,>)
00323     
00328 #define phMIN(a,b) ((a < b) ? a : b)
00329 
00333 #define phMAX(a,b) ((a > b) ? a : b)
00334 
00335 
00336 /* ---------------------------------------------------------------------- */
00349 #define phSUCCESS   0
00350 
00359 #define phFAIL     -1
00360 
00361 /* ---------------------------------------------------------------------- */
00370 #define phHAVE(name) ((defined( HAVE_##name ) && ( HAVE_##name )) || \
00371                       (defined( HAVE_FUNC_##name ) && ( HAVE_FUNC_##name )))
00372 
00373 #endif /* _PHSTANDARD_H */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:02 2007 for phission by  doxygen 1.4.4