summaryrefslogtreecommitdiff
path: root/ace/Env_Value_T.h
blob: 7af97e76b59a9e3ba2882d03fa48220bfda209da (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* This may look like C, but it's really -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    ACE
// 
// = DESCRIPTION
//    Template to encapsulate getting a value from an environment variable
//    and using a supplied default value if not in the environment.
//
// = AUTHOR
//    Chris Cleeland (derived from work by Carlos O'Ryan)
// 
// ============================================================================

#if !defined (ACE_ENV_VALUE_T_H)
#define ACE_ENV_VALUE_T_H

template <class T>
class ACE_Env_Value
{
  // = TITLE
  //    Enviroment Variable Value
  //
  // = DESCRIPTION
  //    Reads a variable from the user enviroment, providing a default
  //    value.
  //
  // = AUTHOR
  //    Chris Cleeland, Carlos O'Ryan
public:
  ACE_Env_Value (void);
  // Default constructor which isn't bound to a specific environment
  // variable name or a default value.  Before being useful it must
  // <open()>ed.
  
  ACE_Env_Value (const char *varname,
                 const T &vardefault);
  // Constructor that calls <open>.
  
  ~ACE_Env_Value (void);
  // Destroy the value.

  operator T (void);
  // Returns the value as type T.

  void open (const char *varname, const T &defval);
  // The constructor, read <varname> from the enviroment, using
  // <vardefault> as its value if it is not defined.

  const char *varname (void) const;
  // Returns the name of the variable being tracked.

private:
  ACE_UNIMPLEMENTED_FUNC (ACE_Env_Value (const ACE_Env_Value &))
  ACE_UNIMPLEMENTED_FUNC (ACE_Env_Value &operator= (const ACE_Env_Value &))
  // Disallow copying and assignment.

  void fetch_value (void);
  
  const char *varname_;
  T value_;
};

template <class T> void ACE_Convert (const char *s, T &t);
// Function to convert a string <s> into type <T>.

#if defined (__ACE_INLINE__)
#include "ace/Env_Value_T.i"
#endif /* __ACE_INLINE__ */

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Env_Value_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Env_Value_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* ACE_ENV_VALUE_T_H */