GCUtilities.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //-----------------------------------------------------------------------------
  2. // (c) 2005 by Basler Vision Technologies
  3. // Section: Vision Components
  4. // Project: GenICam
  5. // Author: Fritz Dierks
  6. // $Header$
  7. // License: This file is published under the license of the EMVA GenICam Standard Group.
  8. // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
  9. // If for some reason you are missing this file please contact the EMVA or visit the website
  10. // (http://www.genicam.org) for a full copy.
  11. //
  12. // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
  13. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  14. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  15. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
  16. // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  21. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  22. // POSSIBILITY OF SUCH DAMAGE.
  23. //-----------------------------------------------------------------------------
  24. /*!
  25. \file
  26. \brief GenICam common utilities
  27. \ingroup Base_PublicUtilities
  28. */
  29. #ifndef GENAPI_GENAPIUTILITIES_DEF_H_
  30. #define GENAPI_GENAPIUTILITIES_DEF_H_
  31. #if defined (_WIN32)
  32. # include <windows.h>
  33. #endif
  34. #include <GenICamVersion.h>
  35. #include <Base/GCTypes.h>
  36. #include <Base/GCString.h>
  37. #include <Base/GCStringVector.h>
  38. #include <Base/GCException.h>
  39. #include <Base/GCLinkage.h>
  40. #if defined(UNDER_RTSS)
  41. #include <Base/GCRTSSUtilities.h>
  42. #endif // defined(UNDER_RTSS)
  43. #if defined(UNDER_RTSS)
  44. #define USE_TEMP_CACHE_FILE 0
  45. #else
  46. #define USE_TEMP_CACHE_FILE 1
  47. #endif // defined(UNDER_RTSS)
  48. #if defined(UNDER_RTSS)
  49. #define USE_TEMP_CACHE_FILE 0
  50. #else
  51. #define USE_TEMP_CACHE_FILE 1
  52. #endif // defined(UNDER_RTSS)
  53. #if defined (_MSC_VER)
  54. # if defined (_WIN64)
  55. # define PLATFORM_NAME "Win64_x64"
  56. # else
  57. # define PLATFORM_NAME "Win32_i86"
  58. # endif
  59. #elif defined (__GNUC__)
  60. # define GENICAM_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  61. # if defined (__LP64__)
  62. # if defined (__linux__)
  63. # define PLATFORM_NAME "Linux64_x64"
  64. # elif defined (__APPLE__)
  65. # define PLATFORM_NAME "Maci64_x64"
  66. # else
  67. # error Unknown Platform
  68. # endif
  69. # else
  70. # if defined (__linux__)
  71. # define PLATFORM_NAME "Linux32_i86"
  72. # elif defined (__APPLE__)
  73. # error Unsupported Platform
  74. # elif defined (VXWORKS)
  75. # define PLATFORM_NAME "VxWorks_PPC"
  76. # else
  77. # error Unknown Platform
  78. # endif
  79. # endif
  80. #else
  81. # error Unknown Platform
  82. #endif
  83. #ifndef GC_COUNTOF
  84. # define GC_COUNTOF(arr) (sizeof (arr) / sizeof (arr)[0] )
  85. #endif
  86. namespace GENICAM_NAMESPACE
  87. {
  88. //! This verifies at runtime if there was no loss of data if an type Ts (e.g. int64t) was downcast
  89. //! to type Td (e.g. int32_t)
  90. template<typename Td, typename Ts>
  91. inline Td INTEGRAL_CAST2( Ts s )
  92. {
  93. const Td d = static_cast<Td>( s );
  94. if ( static_cast<Ts>( d ) != s ){
  95. throw RUNTIME_EXCEPTION("INTEGRAL_CAST failed");
  96. }
  97. return d;
  98. }
  99. //! This verifies at runtime if there was no loss of data if an int64_t was downcast
  100. //! to type T (e.g. int32_t)
  101. template<typename T>
  102. inline T INTEGRAL_CAST( int64_t ll )
  103. {
  104. return INTEGRAL_CAST2<T, int64_t>( ll );
  105. }
  106. //! Returns true if an environment variable exists
  107. GCBASE_API bool DoesEnvironmentVariableExist( const gcstring &VariableName );
  108. //! Retrieve the value of an environment variable
  109. //! \throw runtime_exception if not found
  110. GCBASE_API gcstring GetValueOfEnvironmentVariable( const gcstring &VariableName );
  111. //! Retrieve the value of an environment variable
  112. //! \return true if environment variable was found, otherwise false
  113. GCBASE_API bool GetValueOfEnvironmentVariable(const gcstring &VariableName, gcstring &VariableContent );
  114. #if defined(UNDER_RTSS)
  115. //! Returns true if a file exists
  116. GCBASE_API bool DoesFileExist( const gcstring &FilePath );
  117. #endif // defined(UNDER_RTSS)
  118. //! Converts \ to / and replaces all unsafe characters by their %xx equivalent
  119. //! \ingroup Base_PublicUtilities
  120. GCBASE_API gcstring UrlEncode(const GENICAM_NAMESPACE::gcstring& Input);
  121. //! Replaces %xx escapes by their char equivalent
  122. //! \ingroup Base_PublicUtilities
  123. GCBASE_API GENICAM_NAMESPACE::gcstring UrlDecode(const GENICAM_NAMESPACE::gcstring& Input);
  124. //! Replaces $(ENVIRONMENT_VARIABLES) in a string and replace ' ' with %20
  125. //! \ingroup Base_PublicUtilities
  126. GCBASE_API void ReplaceEnvironmentVariables(gcstring &Buffer, bool ReplaceBlankBy20 = false);
  127. //! Retrieve the path of the GenICam cache folder
  128. /*! The path to the cache folder can be stored by calling SetGenICamCacheFolder().
  129. If GetGenICamCacheFolder() is called before SetGenICamCacheFolder(), it will return
  130. the value of environment variable GENICAM_CACHE_Vx_y. If this environment variable does
  131. not exist, an exception will be thrown.
  132. */
  133. GCBASE_API gcstring GetGenICamCacheFolder(void);
  134. //! Retrieve the path of the GenICam logging properties file
  135. /*! The path to the logging properties file can be stored by calling SetGenICamLogConfig().
  136. If GetGenICamLogConfig() is called before SetGenICamLogConfig(), it will return
  137. the value of environment variable GENICAM_LOG_CONFIG_Vx_y. If this environment variable does
  138. not exist, an exception will be thrown.
  139. */
  140. GCBASE_API gcstring GetGenICamLogConfig(void);
  141. //! Retrieve the path of the CLProtocol folder
  142. /*! The path to the CLProtocol folder can be stored by calling SetGenICamCLProtocolFolder().
  143. If GetGenICamCLProtocolFolder() is called before SetGenICamCLProtocolFolder(), it will return
  144. the value of environment variable GENICAM_CLPROTOCOL. If this environment variable does
  145. not exist, an exception will be thrown.
  146. */
  147. GCBASE_API gcstring GetGenICamCLProtocolFolder(void);
  148. //! Stores the path of the GenICam cache folder
  149. GCBASE_API void SetGenICamCacheFolder(const gcstring& path);
  150. //! Stores the path of the GenICam logging properties file
  151. GCBASE_API void SetGenICamLogConfig(const gcstring& path);
  152. //! Stores the path of the CLProtocol folder
  153. GCBASE_API void SetGenICamCLProtocolFolder(const gcstring& path);
  154. //! splits str input string into a list of tokens using the delimiter
  155. GCBASE_API void Tokenize(
  156. const gcstring& str, //!< string to be split
  157. gcstring_vector& tokens, //!< result of the splitting operation
  158. const gcstring& delimiters = " " //!< delimiters for the splitting
  159. );
  160. //! Gets a list of files or directories matching a given FileTemplate
  161. GCBASE_API void GetFiles(
  162. const gcstring &FileTemplate, //!> The file template. Can contain environment variables.
  163. gcstring_vector &FileNames, //!> A list of files matching the file template
  164. const bool DirectoriesOnly = false ); //!> true = only subdirectories (ex . and ..) are retrieved; false = only files are retrieved
  165. //! Gets the full path to the module (DLL/SO) containing the given \a pFunction; empty string if not found.
  166. GCBASE_API gcstring GetModulePathFromFunction(void *pFunction);
  167. }
  168. #define GENICAM_UNUSED(unused_var) ((void)(unused_var))
  169. #if !defined(GENICAM_DEPRECATED)
  170. # if defined(__GNUC__) && (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 1) // is at least GCC 3.1 compiler?
  171. # define GENICAM_DEPRECATED(FUNCTION) FUNCTION __attribute__ ((deprecated))
  172. # elif defined(_MSC_VER) && (_MSC_VER >= 1300) // is at least VC 2003 compiler?
  173. # define GENICAM_DEPRECATED(FUNCTION) __declspec(deprecated) FUNCTION
  174. # else
  175. # define GENICAM_DEPRECATED(FUNCTION) FUNCTION
  176. # endif // compiler check
  177. #endif // #if !defined(GENICAM_DEPRECATED)
  178. ///////////////////////////////////////////////////////////////////////////////
  179. //
  180. // Useful to create pragma message output recognized by VisualStudio
  181. //
  182. // Usage:
  183. // #pragma message ( __ERR__ "Invalid DLL ABI" )
  184. //
  185. ///////////////////////////////////////////////////////////////////////////////
  186. // Message formatter
  187. #define _TO_STRING( __stN ) #__stN
  188. #define EXPAND_TO_STRINGISE( __stN ) _TO_STRING( __stN )
  189. #define __LINE_STR__ EXPAND_TO_STRINGISE(__LINE__)
  190. #define __LOCATION__ __FILE__ "(" __LINE_STR__ ")"
  191. #define __OUTPUT_FORMATER__(_type) __LOCATION__ " : " _type " : "
  192. // Message types
  193. #define __WARN__ __OUTPUT_FORMATER__("WARNING")
  194. #define __ERR__ __OUTPUT_FORMATER__("ERROR")
  195. #define __TODO__ __OUTPUT_FORMATER__("TBD")
  196. #endif // GENAPI_GENAPIUTILITIES_DEF_H_