This is Unofficial EPICS BASE Doxygen Site
epics::pvAccess::Configuration Class Referenceabstract

#include "configuration.h"

+ Inheritance diagram for epics::pvAccess::Configuration:

Public Types

typedef std::set< std::string > keys_t
 

Public Member Functions

 POINTER_DEFINITIONS (Configuration)
 
 Configuration ()
 
virtual ~Configuration ()=0
 
bool getPropertyAsBoolean (const std::string &name, const bool defaultValue) const
 
epics::pvData::int32 getPropertyAsInteger (const std::string &name, const epics::pvData::int32 defaultValue) const
 
float getPropertyAsFloat (const std::string &name, const float defaultValue) const
 
double getPropertyAsDouble (const std::string &name, const double defaultValue) const
 
std::string getPropertyAsString (const std::string &name, const std::string &defaultValue) const
 
bool getPropertyAsAddress (const std::string &name, osiSockAddr *addr) const
 
bool hasProperty (const std::string &name) const
 
keys_t keys () const
 

Protected Member Functions

virtual bool tryGetPropertyAsString (const std::string &name, std::string *val) const =0
 
virtual void addKeys (keys_t &) const
 

Friends

class ConfigurationStack
 

Detailed Description

Configuration

Definition at line 45 of file configuration.h.

Member Typedef Documentation

typedef std::set<std::string> epics::pvAccess::Configuration::keys_t

Definition at line 117 of file configuration.h.

Constructor & Destructor Documentation

epics::pvAccess::Configuration::Configuration ( )
inline

Definition at line 51 of file configuration.h.

51 {}
epics::pvAccess::Configuration::~Configuration ( )
pure virtual

Definition at line 29 of file configuration.cpp.

29 {}

Member Function Documentation

virtual void epics::pvAccess::Configuration::addKeys ( keys_t ) const
inlineprotectedvirtual

Definition at line 131 of file configuration.h.

131 {}
bool epics::pvAccess::Configuration::getPropertyAsAddress ( const std::string &  name,
osiSockAddr addr 
) const

Fetch and parse as a socket address and port number (address family set accordingly). At present only numeric addresses are parsed (eg. "127.0.0.1:4242").

The storage pointed to be addr should be initialized with a default value, or zeroed.

Parameters
namename of the environment variable to return. addr pointer to the address struct to be filled in
Returns
true if addr now contains an address, false otherwise

Definition at line 84 of file configuration.cpp.

85 {
86  unsigned short dftport=0;
87  if(addr->sa.sa_family==AF_INET)
88  dftport = ntohs(addr->ia.sin_port);
89 
90  std::string val(getPropertyAsString(name, ""));
91 
92  if(val.empty()) return false;
93 
94  memset(addr, 0, sizeof(*addr));
95  addr->ia.sin_family = AF_INET;
96  if(aToIPAddr(val.c_str(), dftport, &addr->ia))
97  return false;
98  return true;
99 }
LIBCOM_API int epicsStdCall aToIPAddr(const char *pAddrString, unsigned short defaultPort, struct sockaddr_in *pIP)
Definition: aToIPAddr.c:78
struct sockaddr sa
Definition: osiSock.h:158
struct sockaddr_in ia
Definition: osiSock.h:157
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
bool epics::pvAccess::Configuration::getPropertyAsBoolean ( const std::string &  name,
const bool  defaultValue 
) const

Get the environment variable specified by name or return default value if it does not exist.

Parameters
namename of the environment variable to return.
defualtValuedefault value to return if environment variable does not exists.
Returns
environment variable value as bool or default value if it does not exist.

Definition at line 31 of file configuration.cpp.

32 {
33  string value = getPropertyAsString(name, defaultValue ? "1" : "0");
34  std::transform(value.begin(), value.end(), value.begin(), ::tolower);
35 
36  bool isTrue = (value == "1") || (value == "true") || (value == "yes");
37  if (isTrue)
38  return true;
39 
40  bool isFalse = (value == "0") || (value == "false") || (value == "no");
41  if (isFalse)
42  return false;
43 
44  // invalid value
45  return defaultValue;
46 }
Definition: link.h:174
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
double epics::pvAccess::Configuration::getPropertyAsDouble ( const std::string &  name,
const double  defaultValue 
) const

Get the environment variable specified by name or return default value if it does not exist.

Parameters
namename of the environment variable to return.
defualtValuedefault value to return if environment variable does not exists.
Returns
environment variable value as double or default value if it does not exist.

Definition at line 66 of file configuration.cpp.

67 {
68  try {
69  return castUnsafe<double>(getPropertyAsString(name, ""));
70  } catch(std::runtime_error&) {
71  return defaultValue;
72  }
73 }
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
float epics::pvAccess::Configuration::getPropertyAsFloat ( const std::string &  name,
const float  defaultValue 
) const

Get the environment variable specified by name or return default value if it does not exist.

Parameters
namename of the environment variable to return.
defualtValuedefault value to return if environment variable does not exists.
Returns
environment variable value as float or default value if it does not exist.

Definition at line 57 of file configuration.cpp.

58 {
59  try {
60  return castUnsafe<float>(getPropertyAsString(name, ""));
61  } catch(std::runtime_error&) {
62  return defaultValue;
63  }
64 }
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
epics::pvData::int32 epics::pvAccess::Configuration::getPropertyAsInteger ( const std::string &  name,
const epics::pvData::int32  defaultValue 
) const

Get the environment variable specified by name or return default value if it does not exist.

Parameters
namename of the environment variable to return.
defualtValuedefault value to return if environment variable does not exists.
Returns
environment variable value as int32 or default value if it does not exist.

Definition at line 48 of file configuration.cpp.

49 {
50  try {
51  return castUnsafe<epics::pvData::int32>(getPropertyAsString(name, ""));
52  } catch(std::runtime_error&) {
53  return defaultValue;
54  }
55 }
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
std::string epics::pvAccess::Configuration::getPropertyAsString ( const std::string &  name,
const std::string &  defaultValue 
) const

Get the environment variable specified by name or return default value if it does not exist.

Parameters
namename of the environment variable to return.
defualtValuedefault value to return if environment variable does not exists.
Returns
environment variable value as std::string or default value if it does not exist.

Definition at line 75 of file configuration.cpp.

76 {
77  std::string val;
78  if(tryGetPropertyAsString(name, &val))
79  return val;
80  else
81  return defaultValue;
82 }
virtual bool tryGetPropertyAsString(const std::string &name, std::string *val) const =0
bool epics::pvAccess::Configuration::hasProperty ( const std::string &  name) const

Definition at line 101 of file configuration.cpp.

102 {
103  return tryGetPropertyAsString(name, NULL);
104 }
#define NULL
Definition: catime.c:38
virtual bool tryGetPropertyAsString(const std::string &name, std::string *val) const =0
keys_t epics::pvAccess::Configuration::keys ( ) const
inline

Return a (partial) list of available key names. Does not include key names from the ConfigurationEnviron

Definition at line 121 of file configuration.h.

122  {
123  keys_t ret;
124  addKeys(ret);
125  return ret;
126  }
std::set< std::string > keys_t
virtual void addKeys(keys_t &) const
epics::pvAccess::Configuration::POINTER_DEFINITIONS ( Configuration  )
virtual bool epics::pvAccess::Configuration::tryGetPropertyAsString ( const std::string &  name,
std::string *  val 
) const
protectedpure virtual

Friends And Related Function Documentation

friend class ConfigurationStack
friend

Definition at line 129 of file configuration.h.


The documentation for this class was generated from the following files: