Filter Library | Camera | Interface Physics |
00001 /* 00002 * Common.h - common types and defines. 00003 * 00004 * This file is part of the Camera Filter Library. 00005 * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera) 00006 * 00007 * Copyright (C) 2004, Leiden Probe Microscopy. 00008 * Copyright (C) 2004, Universiteit Leiden. 00009 * 00010 * Authors: Martin J. Moene (original) 00011 * 00012 * $Id: Common.h 373 2006-03-10 11:47:06Z moene $ 00013 */ 00014 00015 #ifndef CFL_COMMON_H 00016 #define CFL_COMMON_H 00017 #define CFL_IN_COMMON_H 00018 00019 #include <cfl/config.h> // global configuration 00020 00021 /** 00022 * \addtogroup cfl_common Common 00023 * \brief common types and macro's. 00024 * 00025 * The file <tt><cfl/Common.h></tt> contains common types and macro's used 00026 * throughout the library. 00027 * 00028 * stdafx.h includes %Common.h so that this common information is available in 00029 * every source file. 00030 * 00031 * <tt>%Common.h</tt> in its turn includes the following headers: 00032 * - %Config.h to provide the global \ref cfl_configuration 00033 * - %QAFDebug.h to provide for Critical Errors Reporting with \ref cfl_assertion macros 00034 * - %PerfTimer.h to provide for \ref cfl_performance 00035 * 00036 * @{ 00037 */ 00038 00039 /** 00040 * use an otherwise unused argument or variable. 00041 */ 00042 #define CFL_USE(a) (a); 00043 00044 /** 00045 * array dimension; \deprecate replace dim() with dimensionof(). 00046 */ 00047 #define dim(a) (sizeof(a)/sizeof((a)[0])) 00048 //#define dim(a) (dimensionof(a)) 00049 00050 /** 00051 * declare a new type and its pointer, const pointer, reference, and const reference types. 00052 */ 00053 00054 #define DECLARE_TYPE( mydecl, mytype ) \ 00055 typedef mydecl mytype; \ 00056 typedef mytype * mytype ## Ptr; \ 00057 typedef const mytype * mytype ## Cptr; \ 00058 typedef mytype & mytype ## Ref; \ 00059 typedef const mytype & mytype ## Cref; 00060 00061 /** 00062 * declare class, class pointer, const pointer, class reference and const class reference types for classes. 00063 */ 00064 00065 #define DECLARE_CLASS( tag ) \ 00066 class tag; \ 00067 typedef tag * tag ## Ptr; \ 00068 typedef const tag * tag ## Cptr; \ 00069 typedef tag & tag ## Ref; \ 00070 typedef const tag & tag ## Cref; 00071 00072 00073 DECLARE_TYPE( char, Char ); ///< convenience types (e.g. CharCptr) 00074 00075 DECLARE_TYPE( double, Time ); ///< for performance measurements 00076 00077 /// @} cfl_common <<=== <<=== <<=== @} cfl_common 00078 00079 /** 00080 * Camera application registry subkey for filter settings. 00081 */ 00082 extern const char* gCflRegistrySubkey; 00083 00084 /** 00085 * \ingroup cfl_common Common 00086 * \brief algorithm performance measurement data. 00087 */ 00088 00089 struct SPerformanceTestResult 00090 { 00091 SPerformanceTestResult(); // default constructor 00092 Time timePrepare; ///< calculation before buffer handling 00093 Time timeBuffer; ///< buffer handling 00094 Time totalTime; ///< sum of above 00095 }; 00096 00097 /** 00098 * default constructor. 00099 */ 00100 00101 inline SPerformanceTestResult::SPerformanceTestResult() : 00102 timePrepare(0), timeBuffer(0), totalTime(0) 00103 { 00104 ; // do nothing 00105 } 00106 00107 /** 00108 * \ingroup cfl_common Common 00109 * \brief intermediary object type for c_str_ptr(). 00110 * 00111 * Objects of class c_str_ptr_Cwnd_proxy are used by conversion \e shim c_str_ptr() 00112 * to return a C-string (character pointer) for the specified window pointer. The 00113 * C-string only lives as long as the expression it is used in. 00114 * 00115 * So you may write: 00116 * \code 00117 * double value = _tcstod( c_str_ptr( *a_window_pointer ), NULL ); 00118 * \endcode 00119 * 00120 * But you may not write: 00121 * \code 00122 * TCHAR* pstr = c_str_ptr( *a_window_pointer ); 00123 * double value = _tcstod( pstr, NULL ); 00124 * \endcode 00125 * 00126 * The latter is invalid, because pstr is not valid anymore in the call to 00127 * _tcstod(). 00128 * 00129 * To read more about shims, see <em>Shims - A Definition</em>, by M.D. Wilson 00130 * \ref wilson_shims "[SHIMS]". 00131 * The proxy class also uses move semantics on the copy-assignment constructor. 00132 * For more information, see <em>Move Constructors</em>, by M.D. Wilson 00133 * \ref wilson_mvctor "[MVCTOR]". 00134 * 00135 * The implementation of class c_str_ptr_Cwnd_proxy and shim c_str_ptr() were 00136 * obtained from the MFCSTL library \ref mfcstl "[MFCSTL]". 00137 */ 00138 00139 class c_str_ptr_Cwnd_proxy 00140 { 00141 typedef c_str_ptr_Cwnd_proxy self; ///< this type 00142 00143 public: 00144 ~c_str_ptr_Cwnd_proxy( ); 00145 c_str_ptr_Cwnd_proxy( self &rhs ); 00146 explicit c_str_ptr_Cwnd_proxy( const CWnd& wnd ); 00147 00148 operator TCHAR*() const; 00149 00150 protected: 00151 void operator= ( self const &rhs ); ///< prevent assignemnt 00152 00153 private: 00154 TCHAR* m_buffer; ///< the character buffer 00155 }; 00156 00157 /** 00158 * destructor. 00159 */ 00160 00161 inline c_str_ptr_Cwnd_proxy::~c_str_ptr_Cwnd_proxy() 00162 { 00163 delete[] m_buffer; 00164 } 00165 00166 /** 00167 * move constructor. 00168 */ 00169 00170 inline c_str_ptr_Cwnd_proxy::c_str_ptr_Cwnd_proxy( self &rhs ) : 00171 m_buffer( rhs.m_buffer ) 00172 { 00173 rhs.m_buffer = NULL; 00174 } 00175 00176 /** 00177 * constructor. 00178 */ 00179 00180 inline c_str_ptr_Cwnd_proxy::c_str_ptr_Cwnd_proxy( const CWnd& wnd ) 00181 { 00182 int length = wnd.GetWindowTextLength(); 00183 00184 m_buffer = new TCHAR[1 + length]; 00185 00186 wnd.GetWindowText( m_buffer, length + 1 ); 00187 } 00188 00189 /** 00190 * convert to character string. 00191 */ 00192 00193 inline c_str_ptr_Cwnd_proxy::operator TCHAR*() const 00194 { 00195 return m_buffer; 00196 } 00197 00198 /* 00199 * Compiler Warning (level 4) C4239 00200 * nonstandard extension used : 'token' : conversion from 'type' to 'type' 00201 * This type conversion is not allowed by the C++ draft standard, but it is 00202 * permitted here as an extension. This warning is always followed by at least 00203 * one line of explanation describing the language rule being violated. 00204 */ 00205 00206 #pragma warning( push ) 00207 #pragma warning( disable : 4239 ) 00208 00209 /** 00210 * \ingroup cfl_common Common 00211 * \brief window text conversion shim; result can be used as TCHAR*; 00212 * see also c_str_ptr_Cwnd_proxy. 00213 */ 00214 00215 inline c_str_ptr_Cwnd_proxy c_str_ptr( const CWnd& wnd ) 00216 { 00217 return c_str_ptr_Cwnd_proxy( wnd ); 00218 } 00219 00220 #pragma warning( pop ) 00221 00222 #include <qafdebug/QafDebug.h> // for Critical Errors Reporting with QAFDebug macros 00223 #include <perftimer/PerfTimer.h> // for class CPerfTimer 00224 00225 /// @} cfl_common 00226 00227 #undef CFL_IN_COMMON_H 00228 #endif // #ifndef CFL_COMMON_H 00229 00230 /* 00231 * end of file 00232 */ 00233