Skip to content

File GCUtilities.h

File List > include > SpinGenApi > GCUtilities.h

Go to the documentation of this file

//=============================================================================
// Copyright (c) 2026 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================

#ifndef SPINNAKER_GENICAM_GCUTILITIES_H_
#define SPINNAKER_GENICAM_GCUTILITIES_H_

#include "SpinnakerPlatform.h"
#include "GCTypes.h"
#include "GCString.h"
#include "GCStringVector.h"

#if defined(_WIN32)
#include <windows.h>
#endif

#if defined(UNDER_RTSS)
#define USE_TEMP_CACHE_FILE 0
#else
#define USE_TEMP_CACHE_FILE 1
#endif // defined(UNDER_RTSS)

#if defined(UNDER_RTSS)
#define USE_TEMP_CACHE_FILE 0
#else
#define USE_TEMP_CACHE_FILE 1
#endif // defined(UNDER_RTSS)

#if defined(_MSC_VER)
#if defined(_WIN64)
#define PLATFORM_NAME "Win64_x64"
#else
#define PLATFORM_NAME "Win32_i86"
#endif
#elif defined(__GNUC__)
#define GENICAM_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if defined(__LP64__)
#if defined(__linux__)
#define PLATFORM_NAME "Linux64_x64"
#elif defined(__APPLE__)
#define PLATFORM_NAME "Maci64_x64"
#else
#error Unknown Platform
#endif
#else
#if defined(__linux__)
#define PLATFORM_NAME "Linux32_i86"
#elif defined(__APPLE__)
#define PLATFORM_NAME "Maci64_x64"
#elif defined(VXWORKS)
#define PLATFORM_NAME "VxWorks_PPC"
#else
#error Unknown Platform
#endif
#endif
#else
#error Unknown Platform
#endif

#ifndef GC_COUNTOF
#define GC_COUNTOF(arr) (sizeof(arr) / sizeof(arr)[0])
#endif

namespace Spinnaker
{
    namespace GenICam
    {
        template <typename Td, typename Ts> inline Td INTEGRAL_CAST2(Ts s);

        template <typename T> inline T INTEGRAL_CAST(int64_t ll);

        SPINNAKER_API bool DoesEnvironmentVariableExist(const Spinnaker::GenICam::gcstring& VariableName);

        SPINNAKER_API gcstring GetValueOfEnvironmentVariable(const gcstring& VariableName);

        SPINNAKER_API bool GetValueOfEnvironmentVariable(const gcstring& VariableName, gcstring& VariableContent);

#if defined(UNDER_RTSS)
        SPINNAKER_API bool DoesFileExist(const gcstring& FilePath);
#endif // defined(UNDER_RTSS)

        SPINNAKER_API gcstring UrlEncode(const gcstring& Input);

        SPINNAKER_API gcstring UrlDecode(const gcstring& Input);

        SPINNAKER_API void ReplaceEnvironmentVariables(gcstring& Buffer, bool ReplaceBlankBy20 = false);

        SPINNAKER_API gcstring GetGenICamCacheFolder(void);

        SPINNAKER_API gcstring GetGenICamLogConfig(void);

        SPINNAKER_API gcstring GetGenICamCLProtocolFolder(void);

        SPINNAKER_API void SetGenICamCacheFolder(const gcstring& path);

        SPINNAKER_API void SetGenICamLogConfig(const gcstring& path);

        SPINNAKER_API void SetGenICamCLProtocolFolder(const gcstring& path);

        SPINNAKER_API void Tokenize(
            const gcstring& str,             
            gcstring_vector& tokens,         
            const gcstring& delimiters = " " 
        );

        SPINNAKER_API void GetFiles(
            const gcstring& FileTemplate, 
            gcstring_vector& FileNames,   
            const bool DirectoriesOnly =
                false); 
        SPINNAKER_API gcstring GetModulePathFromFunction(void* pFunction);

    } // namespace GenICam
} // namespace Spinnaker

#define GENICAM_UNUSED(unused_var) ((void)(unused_var))

#if !defined(GENICAM_DEPRECATED)
#if defined(__GNUC__) && (__GNUC__ >= 3) && defined(__GNUC_MINOR__) &&                                                 \
    (__GNUC_MINOR__ >= 1) // is at least GCC 3.1 compiler?
#define GENICAM_DEPRECATED(FUNCTION) FUNCTION __attribute__((deprecated))
#elif defined(_MSC_VER) && (_MSC_VER >= 1300) // is at least VC 2003 compiler?
#define GENICAM_DEPRECATED(FUNCTION) __declspec(deprecated) FUNCTION
#else
#define GENICAM_DEPRECATED(FUNCTION) FUNCTION
#endif // compiler check
#endif // #if !defined(GENICAM_DEPRECATED)

//
//    Useful to create pragma message output reconized by VisualStudio
//
//    Usage:
//       #pragma message ( __ERR__ "Invalid DLL ABI" )
//
// Message formater
#define _TO_STRING(__stN) #__stN
#ifndef EXPAND_TO_STRINGISE
#define EXPAND_TO_STRINGISE(__stN) _TO_STRING(__stN)
#endif
#define __LINE_STR__               EXPAND_TO_STRINGISE(__LINE__)
#define __LOCATION__               __FILE__ "(" __LINE_STR__ ")"
#define __OUTPUT_FORMATER__(_type) __LOCATION__ " : " _type " : "

// Message types
#define __WARN__ __OUTPUT_FORMATER__("WARNING")
#define __ERR__  __OUTPUT_FORMATER__("ERROR")
#define __TODO__ __OUTPUT_FORMATER__("TBD")

#endif // SPINNAKER_GENICAM_GCUTILITIES_H_