Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Env_Value_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Env_Value_T.h
00006  *
00007  *  $Id: Env_Value_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  Template to encapsulate getting a value from an environment variable
00010  *  and using a supplied default value if not in the environment.
00011  *
00012  *
00013  *  @author Chris Cleeland (derived from work by Carlos O'Ryan)
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_ENV_VALUE_T_H
00018 #define ACE_ENV_VALUE_T_H
00019 
00020 #include "ace/pre.h"
00021 
00022 #include "ace/config-all.h"
00023 
00024 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 # pragma once
00026 #endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "ace/OS.h"
00029 
00030 /**
00031  * @class ACE_Env_Value
00032  *
00033  * @brief Enviroment Variable Value
00034  *
00035  * Reads a variable from the user enviroment, providing a default
00036  * value.
00037  */
00038 template <class T>
00039 class ACE_Env_Value
00040 {
00041 public:
00042   /**
00043    * Default constructor which isn't bound to a specific environment
00044    * variable name or a default value.  Before being useful it must
00045    * <open>'d.
00046    */
00047   ACE_Env_Value (void);
00048 
00049   /// Constructor that calls <open>.
00050   ACE_Env_Value (const ACE_TCHAR *varname,
00051                  const T &vardefault);
00052 
00053   /// Destroy the value.
00054   ~ACE_Env_Value (void);
00055 
00056   /// Returns the value as type T.
00057   operator T (void);
00058 
00059   /// The constructor, read <varname> from the environment, using
00060   /// <vardefault> as its value if it is not defined.
00061   void open (const ACE_TCHAR *varname, const T &defval);
00062 
00063   /// Returns the name of the variable being tracked.
00064   const ACE_TCHAR *varname (void) const;
00065 
00066 private:
00067   /// Disallow copying and assignment.
00068   ACE_UNIMPLEMENTED_FUNC (ACE_Env_Value(const ACE_Env_Value<T> &))
00069   ACE_UNIMPLEMENTED_FUNC (ACE_Env_Value<T> operator=(const ACE_Env_Value<T> &))
00070 
00071   void fetch_value (void);
00072 
00073   const ACE_TCHAR *varname_;
00074   T value_;
00075 };
00076 
00077 template <class T> void ACE_Convert (const ACE_TCHAR *s, T &t);
00078 // Function to convert a string <s> into type <T>.
00079 
00080 #if defined (__ACE_INLINE__)
00081 #include "ace/Env_Value_T.i"
00082 #endif /* __ACE_INLINE__ */
00083 
00084 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00085 #include "ace/Env_Value_T.cpp"
00086 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00087 
00088 
00089 // Default calls a CTOR on type T of the form 'T::T(const char*)', but
00090 // users can feel free to create their own specialized conversion
00091 // functions if necessary, as shown below.  Note that for 'char*' the
00092 // default is used because a simple cast will be performed and no
00093 // conversion will be necessary.
00094 
00095 template <class T> inline void
00096 ACE_Convert (const ACE_TCHAR *s, T &t)
00097 {
00098   t = T (s);
00099 }
00100 
00101 inline void
00102 ACE_Convert (const ACE_TCHAR *s, ACE_TCHAR *&v)
00103 {
00104   v = (ACE_TCHAR *) s;
00105 }
00106 
00107 inline void
00108 ACE_Convert (const ACE_TCHAR *s, const ACE_TCHAR *&v)
00109 {
00110   v = (const ACE_TCHAR *) s;
00111 }
00112 
00113 inline void
00114 ACE_Convert (const ACE_TCHAR *s, short &si)
00115 {
00116   si = ACE_static_cast (short, ACE_OS::strtol (s, 0, 10));
00117 }
00118 
00119 inline void
00120 ACE_Convert (const ACE_TCHAR *s, u_short &us)
00121 {
00122   us = ACE_static_cast (u_short, ACE_OS::strtol (s, 0, 10));
00123 }
00124 
00125 inline void
00126 ACE_Convert (const ACE_TCHAR *s, u_int &i)
00127 {
00128   i = ACE_static_cast (u_int,
00129                        ACE_OS::strtol (s, 0, 10));
00130 }
00131 
00132 inline void
00133 ACE_Convert (const ACE_TCHAR *s, long &l)
00134 {
00135   l = ACE_OS::strtol (s, 0, 10);
00136 }
00137 
00138 inline void
00139 ACE_Convert (const ACE_TCHAR *s, int &i)
00140 {
00141   i = ACE_static_cast (int, ACE_OS::strtol (s, 0, 10));
00142 }
00143 
00144 inline void
00145 ACE_Convert (const ACE_TCHAR *s, u_long &ul)
00146 {
00147   ul = ACE_OS::strtoul (s, 0, 10);
00148 }
00149 
00150 inline void
00151 ACE_Convert (const ACE_TCHAR *s, double &d)
00152 {
00153   d = ACE_OS::strtod (s, 0);
00154 }
00155 
00156 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00157 #pragma implementation ("Env_Value_T.cpp")
00158 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00159 
00160 #include "ace/post.h"
00161 #endif /* ACE_ENV_VALUE_T_H */

Generated on Mon Jun 16 11:19:38 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002