Fixed typos
[ACE_TAO.git] / ACE / ace / Env_Value_T.h
blob4e268d3f933ac3185451c0b0581f891f70c91b64
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 (void);
49 /// Constructor that calls open().
50 ACE_Env_Value (const ACE_TCHAR *varname, const T &vardefault);
52 /// Destroy the value.
53 ~ACE_Env_Value (void);
55 /// Returns the value as type T.
56 operator T (void);
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 (void) const;
65 private:
66 void fetch_value (void);
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 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
82 #include "ace/Env_Value_T.cpp"
83 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
85 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
87 template <> inline void
88 ACE_Convert (const ACE_TCHAR *s, ACE_TCHAR *&v)
90 v = (ACE_TCHAR *) s;
93 template <> inline void
94 ACE_Convert (const ACE_TCHAR *s, const ACE_TCHAR *&v)
96 v = (const ACE_TCHAR *) s;
99 template <> inline void
100 ACE_Convert (const ACE_TCHAR *s, short &si)
102 si = static_cast<short> (ACE_OS::strtol (s, 0, 10));
105 template <> inline void
106 ACE_Convert (const ACE_TCHAR *s, u_short &us)
108 us = static_cast <u_short> (ACE_OS::strtol (s, 0, 10));
111 template <> inline void
112 ACE_Convert (const ACE_TCHAR *s, u_int &i)
114 i = static_cast<u_int> (ACE_OS::strtol (s, 0, 10));
117 template <> inline void
118 ACE_Convert (const ACE_TCHAR *s, long &l)
120 l = ACE_OS::strtol (s, 0, 10);
123 template <> inline void
124 ACE_Convert (const ACE_TCHAR *s, int &i)
126 i = static_cast<int> (ACE_OS::strtol (s, 0, 10));
129 template <> inline void
130 ACE_Convert (const ACE_TCHAR *s, u_long &ul)
132 ul = ACE_OS::strtoul (s, 0, 10);
135 template <> inline void
136 ACE_Convert (const ACE_TCHAR *s, double &d)
138 d = ACE_OS::strtod (s, 0);
141 // Default calls a CTOR on type T of the form 'T::T(const char*)', but
142 // users can feel free to create their own specialized conversion
143 // functions if necessary, as shown above. Note that for 'char*' the
144 // default is used because a simple cast will be performed and no
145 // conversion will be necessary.
146 template <class T> inline void
147 ACE_Convert (const ACE_TCHAR *s, T &t)
149 t = T (s);
152 ACE_END_VERSIONED_NAMESPACE_DECL
154 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
155 #pragma implementation ("Env_Value_T.cpp")
156 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
158 #include /**/ "ace/post.h"
159 #endif /* ACE_ENV_VALUE_T_H */