Fixed build when OSG_ENVVAR_SUPPORTED is disabled and quietened down warnings using OSG_UNUSED* macros

This commit is contained in:
Robert Osfield 2018-05-10 18:58:29 +01:00
parent b1daa6a693
commit be363ef8d4
3 changed files with 22 additions and 1 deletions

View File

@ -56,6 +56,13 @@
#endif #endif
#endif #endif
// helper macro's for quieten unused variable warnings
#define OSG_UNUSED(VAR) (void)(VAR)
#define OSG_UNUSED2(VAR1, VAR2) (void)(VAR1); (void)(VAR2);
#define OSG_UNUSED3(VAR1, VAR2, VAR3) (void)(VAR1); (void)(VAR2); (void)(VAR2);
#define OSG_UNUSED4(VAR1, VAR2, VAR3, VAR4) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4);
#define OSG_UNUSED5(VAR1, VAR2, VAR3, VAR4, VAR5) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4); (void)(VAR5);
/** /**
\namespace osg \namespace osg

View File

@ -30,6 +30,8 @@ extern OSG_EXPORT int osg_system(const char* str);
#ifdef __cplusplus #ifdef __cplusplus
#include <string>
#if defined(OSG_ENVVAR_SUPPORTED) #if defined(OSG_ENVVAR_SUPPORTED)
#include <stdlib.h> #include <stdlib.h>
#include <sstream> #include <sstream>
@ -47,10 +49,15 @@ inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4
inline std::string getEnvVar(const char* name) inline std::string getEnvVar(const char* name)
{ {
#ifdef OSG_ENVVAR_SUPPORTED
std::string value; std::string value;
const char* ptr = getenv(name); const char* ptr = getenv(name);
if (ptr) value.assign(ptr, getClampedLength(ptr)); if (ptr) value.assign(ptr, getClampedLength(ptr));
return value; return value;
#else
OSG_UNUSED(name);
return std::string();
#endif
} }
@ -65,6 +72,7 @@ inline bool getEnvVar(const char* name, T& value)
str >> value; str >> value;
return !str.fail(); return !str.fail();
#else #else
OSG_UNUSED2(name, value);
return false; return false;
#endif #endif
} }
@ -79,6 +87,7 @@ inline bool getEnvVar(const char* name, std::string& value)
value.assign(ptr, getClampedLength(ptr)); value.assign(ptr, getClampedLength(ptr));
return true; return true;
#else #else
OSG_UNUSED2(name, value);
return false; return false;
#endif #endif
} }
@ -94,6 +103,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2)
str >> value1 >> value2; str >> value1 >> value2;
return !str.fail(); return !str.fail();
#else #else
OSG_UNUSED3(name, value1, value2);
return false; return false;
#endif #endif
} }
@ -109,6 +119,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3)
str >> value1 >> value2 >> value3; str >> value1 >> value2 >> value3;
return !str.fail(); return !str.fail();
#else #else
OSG_UNUSED4(name, value1, value2, value3);
return false; return false;
#endif #endif
} }
@ -124,6 +135,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3, T4&
str >> value1 >> value2 >> value3 >> value4; str >> value1 >> value2 >> value3 >> value4;
return !str.fail(); return !str.fail();
#else #else
OSG_UNUSED5(name, value1, value2, value3, value4);
return false; return false;
#endif #endif
} }

View File

@ -33,6 +33,8 @@ int osg_system(const char* command)
#else // use tranditional C sysmtem call for osg_system implementation #else // use tranditional C sysmtem call for osg_system implementation
#include <stdlib.h>
int osg_system(const char* command) int osg_system(const char* command)
{ {
return system(command); return system(command);