Loading...
Searching...
No Matches
SystemEnvironment.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
SystemEnvironment.h
Qore Programming Language
Copyright (C) 2003 - 2022 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_SYSTEMENVIRONMENT_H
#define _QORE_SYSTEMENVIRONMENT_H
class SystemEnvironment {
friend class AtomicEnvironmentSetter;
private:
DLLLOCAL SystemEnvironment(const SystemEnvironment&);
DLLLOCAL SystemEnvironment& operator=(const SystemEnvironment&);
protected:
DLLLOCAL static int set_intern(const char *name, const char *value, bool overwrite = 1);
DLLLOCAL static class QoreString *get_intern(const char *name);
DLLLOCAL static class QoreStringNode *get_as_string_node_intern(const char *name);
DLLLOCAL static int get_intern(const char *name, class QoreString &str);
DLLLOCAL static int unset_intern(const char *name);
public:
DLLLOCAL SystemEnvironment();
DLLLOCAL ~SystemEnvironment();
DLLEXPORT static int set(const char *name, const char *value, bool overwrite = 1);
DLLEXPORT static class QoreString *get(const char *name);
DLLEXPORT static class QoreStringNode *getAsStringNode(const char *name);
DLLEXPORT static int get(const char *name, class QoreString &str);
DLLEXPORT static int unset(const char *name);
DLLEXPORT static bool valueExists(const char* name); // true if exists and is not empty
};
DLLEXPORT extern SystemEnvironment SysEnv;
class AtomicEnvironmentSetter
{
private:
DLLLOCAL AtomicEnvironmentSetter(const AtomicEnvironmentSetter&);
DLLLOCAL AtomicEnvironmentSetter& operator=(const AtomicEnvironmentSetter&);
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
public:
DLLEXPORT AtomicEnvironmentSetter();
DLLEXPORT ~AtomicEnvironmentSetter();
DLLEXPORT int set(const char *name, const char *value, bool overwrite = 1);
DLLEXPORT class QoreString *get(const char *name);
DLLEXPORT class QoreStringNode *getAsStringNode(const char *name);
DLLEXPORT int get(const char *name, class QoreString &str);
DLLEXPORT int unset(const char *name);
DLLEXPORT bool valueExists(const char* name); // true if exists and is not empty
};
#endif
AtomicEnvironmentSetter
class allowing for multiple updates to the system environment within a single lock in a thread-safe w...
Definition: SystemEnvironment.h:151
AtomicEnvironmentSetter::set
DLLEXPORT int set(const char *name, const char *value, bool overwrite=1)
sets the given environment variable to the value passed, respecting the overwrite flag
AtomicEnvironmentSetter::unset
DLLEXPORT int unset(const char *name)
unsets the given environment variable
AtomicEnvironmentSetter::valueExists
DLLEXPORT bool valueExists(const char *name)
returns true if the environment variable exists and has a value, false if not
AtomicEnvironmentSetter::get
DLLEXPORT int get(const char *name, class QoreString &str)
appends the value of the given environment variable to a QoreString, returns 0 for OK,...
AtomicEnvironmentSetter::getAsStringNode
DLLEXPORT class QoreStringNode * getAsStringNode(const char *name)
returns the value of the environment variable as a new QoreStringNode object, 0 if not present,...
AtomicEnvironmentSetter::get
DLLEXPORT class QoreString * get(const char *name)
returns the value of the environment variable as a new QoreString object, 0 if not present,...
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
SystemEnvironment
class used to safely manipulate the system environment
Definition: SystemEnvironment.h:46
SystemEnvironment::unset_intern
static DLLLOCAL int unset_intern(const char *name)
unsets the given environment variable
SystemEnvironment::getAsStringNode
static DLLEXPORT class QoreStringNode * getAsStringNode(const char *name)
returns the value of the environment variable as a new QoreStringNode object, 0 if not present,...
SystemEnvironment::valueExists
static DLLEXPORT bool valueExists(const char *name)
returns true if the environment variable exists and has a value, false if not
SystemEnvironment::get_intern
static DLLLOCAL int get_intern(const char *name, class QoreString &str)
appends the value of the given environment variable to a QoreString, returns 0 for OK,...
SystemEnvironment::set
static DLLEXPORT int set(const char *name, const char *value, bool overwrite=1)
sets the given environment variable to the value passed, respecting the overwrite flag
SystemEnvironment::unset
static DLLEXPORT int unset(const char *name)
unsets the given environment variable
SystemEnvironment::get
static DLLEXPORT int get(const char *name, class QoreString &str)
appends the value of the given environment variable to a QoreString, returns 0 for OK,...
SystemEnvironment::get_intern
static DLLLOCAL class QoreString * get_intern(const char *name)
returns the value of the environment variable as a new QoreString object, 0 if not present,...
SystemEnvironment::get
static DLLEXPORT class QoreString * get(const char *name)
returns the value of the environment variable as a new QoreString object, 0 if not present,...
SystemEnvironment::set_intern
static DLLLOCAL int set_intern(const char *name, const char *value, bool overwrite=1)
sets the given environment variable to the value passed, respecting the overwrite flag
SystemEnvironment::get_as_string_node_intern
static DLLLOCAL class QoreStringNode * get_as_string_node_intern(const char *name)
returns the value of the environment variable as a new QoreStringNode object, 0 if not present,...