Environment.hh 1.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
// (C) Copyright 2015 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#ifndef BASE_ENVIRONMENT_HH_INCLUDED
#define BASE_ENVIRONMENT_HH_INCLUDED

#include <string>

namespace System {
namespace Environment {

/*! 
Get the value of an environment variable. This wraps around getenv() in
a portable, secure (and in future) thread-safe way. If the variable is 
undefined, return an empty string.

Returns false if the variable is undefined, the input string is unchanged.
*/
bool variable(const char* _vrbl_name, std::string& _str);

//! Same as above, but returns an empty string if the variable is undefined.
inline std::string variable(const char* _vrbl_name)
{
  std::string vrbl;
  variable(_vrbl_name, vrbl);
  return vrbl;
}

//! Same as above, but returns a default string if the variable is undefined.
inline std::string variable(const char* _vrbl_name, const char* _vrbl_dflt)
{
  std::string vrbl(_vrbl_dflt);
  variable(_vrbl_name, vrbl);
  return vrbl;
}

}//namespace Environment 
}//namespace System

#endif//REFORM_ENVIRONMENT_HH_INCLUDED