Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Env_Value_T.h
blobe080cafcec6b84c64f308fb7338792a40aaa77e5
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Env_Value_T.h
7 * Template to encapsulate getting a value from an environment variable
8 * and using a supplied default value if not in the environment.
10 * @author Chris Cleeland (derived from work by Carlos O'Ryan)
12 //=============================================================================
14 #ifndef ACE_ENV_VALUE_T_H
15 #define ACE_ENV_VALUE_T_H
17 #include /**/ "ace/pre.h"
19 #include /**/ "ace/config-all.h"
20 #include "ace/Global_Macros.h"
21 #include "ace/OS_NS_stdlib.h"
22 #include "ace/Copy_Disabled.h"
24 #if !defined (ACE_LACKS_PRAGMA_ONCE)
25 # pragma once
26 #endif /* ACE_LACKS_PRAGMA_ONCE */
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /**
31 * @class ACE_Env_Value
33 * @brief Environment Variable Value
35 * Reads a variable from the user environment, providing a default
36 * value.
38 template <class T>
39 class ACE_Env_Value : private ACE_Copy_Disabled
41 public:
42 /**
43 * Default constructor which isn't bound to a specific environment
44 * variable name or a default value. Before being useful it must
45 * open()'d.
47 ACE_Env_Value ();
49 /// Constructor that calls open().
50 ACE_Env_Value (const ACE_TCHAR *varname, const T &vardefault);
52 /// Destroy the value.
53 ~ACE_Env_Value ();
55 /// Returns the value as type T.
56 operator T ();
58 /// The constructor, read @a varname from the environment, using
59 /// @a defval as its value if it is not defined.
60 void open (const ACE_TCHAR *varname, const T &defval);
62 /// Returns the name of the variable being tracked.
63 const ACE_TCHAR *varname () const;
65 private:
66 void fetch_value ();
68 const ACE_TCHAR *varname_;
69 T value_;
72 /// Function to convert a string @a s into type @c T.
73 template <class T> void ACE_Convert (const ACE_TCHAR *s, T &t);
75 ACE_END_VERSIONED_NAMESPACE_DECL
77 #if defined (__ACE_INLINE__)
78 #include "ace/Env_Value_T.inl"
79 #endif /* __ACE_INLINE__ */
81 #include "ace/Env_Value_T.cpp"
83 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
85 template <> inline void
86 ACE_Convert (const ACE_TCHAR *s, ACE_TCHAR *&v)
88 v = (ACE_TCHAR *) s;
91 template <> inline void
92 ACE_Convert (const ACE_TCHAR *s, const ACE_TCHAR *&v)
94 v = (const ACE_TCHAR *) s;
97 template <> inline void
98 ACE_Convert (const ACE_TCHAR *s, short &si)
100 si = static_cast<short> (ACE_OS::strtol (s, 0, 10));
103 template <> inline void
104 ACE_Convert (const ACE_TCHAR *s, u_short &us)
106 us = static_cast <u_short> (ACE_OS::strtol (s, 0, 10));
109 template <> inline void
110 ACE_Convert (const ACE_TCHAR *s, u_int &i)
112 i = static_cast<u_int> (ACE_OS::strtol (s, 0, 10));
115 template <> inline void
116 ACE_Convert (const ACE_TCHAR *s, long &l)
118 l = ACE_OS::strtol (s, 0, 10);
121 template <> inline void
122 ACE_Convert (const ACE_TCHAR *s, int &i)
124 i = static_cast<int> (ACE_OS::strtol (s, 0, 10));
127 template <> inline void
128 ACE_Convert (const ACE_TCHAR *s, u_long &ul)
130 ul = ACE_OS::strtoul (s, 0, 10);
133 template <> inline void
134 ACE_Convert (const ACE_TCHAR *s, double &d)
136 d = ACE_OS::strtod (s, 0);
139 // Default calls a CTOR on type T of the form 'T::T(const char*)', but
140 // users can feel free to create their own specialized conversion
141 // functions if necessary, as shown above. Note that for 'char*' the
142 // default is used because a simple cast will be performed and no
143 // conversion will be necessary.
144 template <class T> inline void
145 ACE_Convert (const ACE_TCHAR *s, T &t)
147 t = T (s);
150 ACE_END_VERSIONED_NAMESPACE_DECL
152 #include /**/ "ace/post.h"
153 #endif /* ACE_ENV_VALUE_T_H */