Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

env.hpp

Go to the documentation of this file.
00001 
00002 //
00003 // Fichero            : env.hpp
00004 // Autor              : Cesar Ortiz
00005 // Fecha creacion     : 
00006 // 
00007 // Descripcion        : Propiedades de entorno
00008 //
00009 //                      Esta clase va a encapsular una serie de atributos
00010 //                      que van a ser de utilidad para las aplicaciones.
00011 //
00012 // 
00013 // Notas
00014 //    - @@ pathPrograma es erroneo se compone a partir de nombrePrograma y
00015 //           dirPrograma, lo cual no es cierto siempre.
00016 //
00018 
00019 #ifndef __ENV_H__
00020 #define __ENV_H__
00021 
00022 #include "jic/exc/excepcion.hpp"
00023 #include <string>
00024 #include <unistd.h>
00025 
00026 EXCEPCION(ExcENVNoIniciado);
00027 
00028 namespace UTIL {
00029 
00030   
00031 class ENV {
00032 public:
00033 
00034     static void inicio(int &argc, char** argv,
00035              const char* aplicacion = 0,
00036              const char* modulo = 0);
00037              
00038                  
00039     inline static const char* nombrePrograma(); //throw(ExcENVNoIniciado);    
00040     inline static const char* pathPrograma(); //throw(ExcENVNoIniciado);    
00041     inline static const char* dirPrograma(); //throw(ExcENVNoIniciado);    
00042     inline static int &argc(); //throw(ExcENVNoIniciado);    
00043     inline static char **argv(); //throw(ExcENVNoIniciado);    
00044          inline static pid_t pid(); //throw(ExcENVNoIniciado);    
00045     inline static const char* host(); //throw(ExcENVNoIniciado);    
00046     inline static const char* aplicacion(); //throw(ExcENVNoIniciado);    
00047     inline static const char* modulo(); //throw(ExcENVNoIniciado);    
00048     static const char* spid(); //throw(ExcENVNoIniciado);    
00049 
00050 private:
00051 
00052      inline static void valida(); //throw(ExcENVNoIniciado);    
00053 
00054      static int *_argc;         
00055      static char** _argv;
00056           
00057      static std::string _nombrePrograma;
00058      static std::string _dir;     
00059      static std::string _modulo;
00060      static pid_t _pid;      
00061      static std::string _host;
00062      static std::string _aplicacion;
00063      
00064      static bool _bIniciado;
00065      
00066 };
00067 
00069 
00070 void 
00071 ENV::valida() //throw(ExcENVNoIniciado)
00072 {
00073    if (! _bIniciado) 
00074    {
00075       THROW(ExcENVNoIniciado,"");
00076    }
00077 }
00078 
00079 //-----------------------------------------------------------------------------
00080 
00081 const char* 
00082 ENV::nombrePrograma() //  throw(ExcENVNoIniciado)
00083 { 
00084    valida();
00085    return _nombrePrograma.c_str(); 
00086 }
00087 
00088 //-----------------------------------------------------------------------------
00089     
00090 const char* 
00091 ENV::pathPrograma()     //  throw(ExcENVNoIniciado)
00092 {  
00093    valida();
00094    std::string sTmp = _dir + std::string("/") + _nombrePrograma;
00095         return sTmp.c_str();  
00096 }
00097 
00098 //-----------------------------------------------------------------------------
00099 
00100 const char* 
00101 ENV::dirPrograma() //  throw(ExcENVNoIniciado)
00102 { 
00103    valida();
00104    return _dir.c_str(); 
00105 }
00106 
00107 //-----------------------------------------------------------------------------
00108     
00109 int &
00110 ENV::argc() //  throw(ExcENVNoIniciado)
00111 { 
00112    valida();
00113    return *_argc; 
00114 }
00115 
00116 //-----------------------------------------------------------------------------
00117 
00118 char **
00119 ENV::argv()             //  throw(ExcENVNoIniciado)
00120 { 
00121    valida();
00122    return _argv; 
00123 }
00124 
00125 //-----------------------------------------------------------------------------
00126 
00127 pid_t 
00128 ENV::pid() //  throw(ExcENVNoIniciado)
00129 { 
00130    valida();
00131    return _pid; 
00132 }
00133 
00134 //-----------------------------------------------------------------------------
00135 
00136 const char* 
00137 ENV::host() // throw(ExcENVNoIniciado)
00138 {  
00139    valida();
00140    return _host.c_str(); 
00141 } 
00142 
00143 //-----------------------------------------------------------------------------
00144 
00145 const char* 
00146 ENV::aplicacion() // throw(ExcENVNoIniciado)
00147 { 
00148    valida();
00149    return _aplicacion.empty() ? "":_aplicacion.c_str(); 
00150 }
00151 
00152 //-----------------------------------------------------------------------------
00153 
00154 const char* 
00155 ENV::modulo() // throw(ExcENVNoIniciado)
00156 { 
00157   valida();
00158   return _modulo.empty() ?"":_modulo.c_str(); 
00159 }
00160 
00162 
00163 } // UTIL
00164 
00165 #endif
00166 

Generated on Wed Mar 5 21:31:47 2003 for JIC by doxygen1.3-rc3