GenApi 3.5.1
GCUtilities.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// (c) 2005 by Basler Vision Technologies
3// Author: Fritz Dierks
4//
5// License: This file is published under the license of the EMVA GenICam Standard Group.
6// A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
7// If for some reason you are missing this file please contact the EMVA or visit the website
8// (http://www.genicam.org) for a full copy.
9//
10// THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
11// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
12// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
14// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
15// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
17// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20// POSSIBILITY OF SUCH DAMAGE.
21//
22//-----------------------------------------------------------------------------
29#ifndef GENAPI_GENAPIUTILITIES_DEF_H_
30#define GENAPI_GENAPIUTILITIES_DEF_H_
31
32#if defined (_WIN32)
33# include <windows.h>
34#endif
35
36#include <GenICamVersion.h>
37
38#include <Base/GCTypes.h>
39#include <Base/GCString.h>
40#include <Base/GCStringVector.h>
41#include <Base/GCException.h>
42#include <Base/GCLinkage.h>
43
44#if defined(UNDER_RTSS)
46#endif // defined(UNDER_RTSS)
47
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
54#if defined(UNDER_RTSS)
55#define USE_TEMP_CACHE_FILE 0
56#else
57#define USE_TEMP_CACHE_FILE 1
58#endif // defined(UNDER_RTSS)
59
60#if defined (_MSC_VER)
61# if defined (_WIN64)
62# define PLATFORM_NAME "Win64_x64"
63# else
64# define PLATFORM_NAME "Win32_i86"
65# endif
66#elif defined (__GNUC__)
67# define GENICAM_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
68# if defined (__linux__)
69# if defined(__x86_64) || defined(__x86_64__) || defined(__amd64)
70# define PLATFORM_NAME "Linux64_x64"
71# elif defined(__i386) || defined(__i386__)
72# define PLATFORM_NAME "Linux32_i86"
73# elif defined(__arm__) || defined(__TARGET_ARCH_ARM)
74# define PLATFORM_NAME "Linux32_ARMhf"
75# elif defined(__AARCH64EL__) || defined(__AARCH64_CMODEL_SMALL__)
76# define PLATFORM_NAME "Linux64_ARM"
77# endif
78# elif defined (__APPLE__)
79# if defined (__LP64__)
80# define PLATFORM_NAME "Maci64_x64"
81# else
82# error Unsupported Platform
83# endif
84# else
85# error Unknown Platform
86# endif
87#else
88# error Unknown Platform
89#endif
90
91#ifndef GC_COUNTOF
92# define GC_COUNTOF(arr) (sizeof (arr) / sizeof (arr)[0] )
93#endif
94
95namespace GENICAM_NAMESPACE
96{
99 template<typename Td, typename Ts>
100 inline Td INTEGRAL_CAST2( Ts s )
101 {
102 const Td d = static_cast<Td>( s );
103 if ( static_cast<Ts>( d ) != s ){
104 throw RUNTIME_EXCEPTION("INTEGRAL_CAST failed");
105 }
106 return d;
107 }
108
111 template<typename T>
112 inline T INTEGRAL_CAST( int64_t ll )
113 {
114 return INTEGRAL_CAST2<T, int64_t>( ll );
115 }
116
118 GCBASE_API bool GetCacheFileDirectory(gcstring &CacheFileDirectory);
119
121 GCBASE_API bool HasValidLength(const gcstring &FileName);
122
124 GCBASE_API bool HasValidExtension(const gcstring &FileName);
125
126 // Returns the cache file names in the given cache directory
127 GCBASE_API void GetCandidateCacheFilePaths(gcstring_vector &CacheFileNames, const gcstring &CacheFileDirectory); //
128
129 // Returns the message that corresponds to the last error
130 GCBASE_API void GetLastErrorMessage(gcstring &Message);
131
133 GCBASE_API bool DoesEnvironmentVariableExist( const gcstring &VariableName );
134
137 GCBASE_API gcstring GetValueOfEnvironmentVariable( const gcstring &VariableName );
138
141 GCBASE_API bool GetValueOfEnvironmentVariable(const gcstring &VariableName, gcstring &VariableContent );
142
143#if defined(UNDER_RTSS)
145 GCBASE_API bool DoesFileExist( const gcstring &FilePath );
146#endif // defined(UNDER_RTSS)
147
151
155
158 GCBASE_API void ReplaceEnvironmentVariables(gcstring &Buffer, bool ReplaceBlankBy20 = false);
159
160
162
168
170
176
178
184
186 GCBASE_API void SetGenICamCacheFolder(const gcstring& path);
187
189 GCBASE_API void SetGenICamLogConfig(const gcstring& path);
190
192 GCBASE_API void SetGenICamCLProtocolFolder(const gcstring& path);
193
195 GCBASE_API void Tokenize(
196 const gcstring& str,
197 gcstring_vector& tokens,
198 const gcstring& delimiters = " "
199 );
200
202 GCBASE_API void GetFiles(
203 const gcstring &FileTemplate,
204 gcstring_vector &FileNames,
205 const bool DirectoriesOnly = false );
206
208 GCBASE_API gcstring GetModulePathFromFunction(void *pFunction);
209}
210
211#define GENICAM_UNUSED(unused_var) ((void)(unused_var))
212
213#if !defined(GENICAM_DEPRECATED)
214# if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__ ) >= 301) // is at least GCC 3.1 compiler?
215# define GENICAM_DEPRECATED(FUNCTION) FUNCTION __attribute__ ((deprecated))
216# elif defined(_MSC_VER) && (_MSC_VER >= 1300) // is at least VC 2003 compiler?
217# define GENICAM_DEPRECATED(FUNCTION) __declspec(deprecated) FUNCTION
218# else
219# define GENICAM_DEPRECATED(FUNCTION) FUNCTION
220# endif // compiler check
221#endif // #if !defined(GENICAM_DEPRECATED)
222
223
225//
226// Useful to create pragma message output recognized by VisualStudio
227//
228// Usage:
229// #pragma message ( __ERR__ "Invalid DLL ABI" )
230//
232// Message formatter
233#define _TO_STRING( __stN ) #__stN
234#define EXPAND_TO_STRINGISE( __stN ) _TO_STRING( __stN )
235#define __LINE_STR__ EXPAND_TO_STRINGISE(__LINE__)
236#define __LOCATION__ __FILE__ "(" __LINE_STR__ ")"
237#define __OUTPUT_FORMATER__(_type) __LOCATION__ " : " _type " : "
238
239// Message types
240#define __WARN__ __OUTPUT_FORMATER__("WARNING")
241#define __ERR__ __OUTPUT_FORMATER__("ERROR")
242#define __TODO__ __OUTPUT_FORMATER__("TBD")
243
244#endif // GENAPI_GENAPIUTILITIES_DEF_H_
Standard GenICam Exceptions.
GenICam RTSS utilities.
Portable string vector implementation.
Portable string implementation.
Platform-dependent type definitions.
T INTEGRAL_CAST(int64_t ll)
Definition GCUtilities.h:112
GCBASE_API bool HasValidLength(const gcstring &FileName)
Returns the truth value for the proposition: The given file name has the valid length.
GCBASE_API gcstring GetValueOfEnvironmentVariable(const gcstring &VariableName)
GCBASE_API gcstring GetModulePathFromFunction(void *pFunction)
‍true = only subdirectories (ex . and ..) are retrieved; false = only files are retrieved
Td INTEGRAL_CAST2(Ts s)
Definition GCUtilities.h:100
GCBASE_API bool HasValidExtension(const gcstring &FileName)
Returns the truth value for the proposition: The given file has the valid file extension.
GCBASE_API void Tokenize(const gcstring &str, gcstring_vector &tokens, const gcstring &delimiters=" ")
splits str input string into a list of tokens using the delimiter
GCBASE_API gcstring GetGenICamCacheFolder(void)
Retrieve the path of the GenICam cache folder.
GCBASE_API void SetGenICamCLProtocolFolder(const gcstring &path)
Stores the path of the CLProtocol folder.
GCBASE_API void SetGenICamCacheFolder(const gcstring &path)
Stores the path of the GenICam cache folder.
GCBASE_API gcstring GetGenICamCLProtocolFolder(void)
Retrieve the path of the CLProtocol folder.
GCBASE_API bool DoesEnvironmentVariableExist(const gcstring &VariableName)
Returns true if an environment variable exists.
GCBASE_API void SetGenICamLogConfig(const gcstring &path)
Stores the path of the GenICam logging properties file.
GCBASE_API bool GetCacheFileDirectory(gcstring &CacheFileDirectory)
Returns the directory where cache files are located.
GCBASE_API gcstring GetGenICamLogConfig(void)
Retrieve the path of the GenICam logging properties file.
GCBASE_API void GetFiles(const gcstring &FileTemplate, gcstring_vector &FileNames, const bool DirectoriesOnly=false)
Gets a list of files or directories matching a given FileTemplate.
A string class which is a clone of std::string.
Definition GCString.h:51
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition GCException.h:246
GCBASE_API void ReplaceEnvironmentVariables(gcstring &Buffer, bool ReplaceBlankBy20=false)
GCBASE_API GENICAM_NAMESPACE::gcstring UrlDecode(const GENICAM_NAMESPACE::gcstring &Input)
GCBASE_API gcstring UrlEncode(const GENICAM_NAMESPACE::gcstring &Input)