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

ACE_Capabilities Class Reference

This class implement the ACE Capabilities. More...

#include <Capabilities.h>

Collaboration diagram for ACE_Capabilities:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Capabilities (void)
 The Constructor. More...

 ~ACE_Capabilities (void)
 The Destructor. More...

int getval (const ACE_TCHAR *ent, ACE_TString &val)
 Get a string entry. More...

int getval (const ACE_TCHAR *ent, int &val)
 Get an integer entry. More...

int getent (const ACE_TCHAR *fname, const ACE_TCHAR *name)
 Get the ACE_Capabilities name from FILE fname and load the associated capabitily entries in map. More...


Protected Methods

const ACE_TCHARparse (const ACE_TCHAR *buf, int &cap)
 Parse an integer property. More...

const ACE_TCHARparse (const ACE_TCHAR *buf, ACE_TString &cap)
 Parse a string property. More...

int fillent (const ACE_TCHAR *ent)
 Fill the ACE_Capabilities with description in ent. More...

int parseent (const ACE_TCHAR *name, ACE_TCHAR *line)
 Parse a cap entry. More...

int getline (FILE *fp, ACE_TString &line)
 Get a line from FILE input stream. More...

int is_entry (const ACE_TCHAR *name, const ACE_TCHAR *line)
 Is a valid entry. More...

void resetcaps (void)
 Reset the set of capabilities. More...


Private Attributes

ACE_Hash_Map_Manager< ACE_TString,
ACE_CapEntry *, ACE_Null_Mutex
caps_
 This is the set of ACE_CapEntry. More...


Detailed Description

This class implement the ACE Capabilities.

This is a container class for ACE Capabilities values. Currently exist three different capability values: <ACE_IntCapEntry> (integer), <ACE_BoolCapEntry> (bool) and <ACE_StringCapEntry> (String). An <ACE_Capabilities> is a unordered set of pair = (<String>, <ACE_CapEntry> *). Where the first component is the name of capability and the second component is a pointer to the capability value container. A <FILE> is a container for <ACE_Capabilities>, the <ACE_Capabilities> has a name in the file, as a termcap file.

Definition at line 126 of file Capabilities.h.


Constructor & Destructor Documentation

ACE_Capabilities::ACE_Capabilities void   
 

The Constructor.

Definition at line 18 of file Capabilities.cpp.

00019 {
00020 }

ACE_Capabilities::~ACE_Capabilities void   
 

The Destructor.

Definition at line 22 of file Capabilities.cpp.

References resetcaps.

00023 {
00024   this->resetcaps ();
00025 }


Member Function Documentation

int ACE_Capabilities::fillent const ACE_TCHAR   ent [protected]
 

Fill the ACE_Capabilities with description in ent.

Definition at line 112 of file Capabilities.cpp.

References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_CapEntry *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::bind, caps_, parse, and resetcaps.

Referenced by getent.

00113 {
00114   this->resetcaps ();
00115   while (*buf)
00116     {
00117       ACE_TString s;
00118       int n;
00119       ACE_TString name;
00120       ACE_CapEntry *ce;
00121 
00122       // Skip blanks
00123       while (*buf && isspace(*buf)) buf++;
00124       // If we get end of line return
00125 
00126       if (*buf == ACE_LIB_TEXT ('\0'))
00127         break;
00128 
00129       if (*buf == ACE_LIB_TEXT ('#'))
00130         {
00131           while (*buf && *buf != ACE_LIB_TEXT ('\n'))
00132             buf++;
00133           if (*buf == ACE_LIB_TEXT ('\n'))
00134             buf++;
00135           continue;
00136         }
00137       while(*buf && *buf != ACE_LIB_TEXT ('=')
00138             && *buf!= ACE_LIB_TEXT ('#')
00139             && *buf != ACE_LIB_TEXT (','))
00140         name += *buf++;
00141 
00142       // If name is null.
00143       switch (*buf)
00144         {
00145         case ACE_LIB_TEXT ('='):
00146           // String property
00147           buf = this->parse (buf + 1, s);
00148           ACE_NEW_RETURN (ce,
00149                           ACE_StringCapEntry (s),
00150                           -1);
00151           if (caps_.bind (name, ce) == -1)
00152             {
00153               delete ce;
00154               return -1;
00155             }
00156           break;
00157         case ACE_LIB_TEXT ('#'):
00158           // Integer property
00159           buf = this->parse (buf + 1, n);
00160           ACE_NEW_RETURN (ce,
00161                           ACE_IntCapEntry (n),
00162                           -1);
00163           if (caps_.bind (name, ce) == -1)
00164             {
00165               delete ce;
00166               return -1;
00167             }
00168           break;
00169         case ACE_LIB_TEXT (','):
00170           // Boolean
00171           ACE_NEW_RETURN (ce,
00172                           ACE_BoolCapEntry (1),
00173                           -1);
00174           if (caps_.bind (name, ce) == -1)
00175             {
00176               delete ce;
00177               return -1;
00178             }
00179           break;
00180         default:
00181           return 0;
00182         }
00183 
00184       if (*buf++ != ACE_LIB_TEXT (','))
00185         return -1;
00186     }
00187 
00188   return 0;
00189 }

int ACE_Capabilities::getent const ACE_TCHAR   fname,
const ACE_TCHAR   name
 

Get the ACE_Capabilities name from FILE fname and load the associated capabitily entries in map.

Definition at line 304 of file Capabilities.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_String_Base< char >::c_str, ACE_OS::fclose, fillent, ACE_OS::fopen, getline, is_empty, is_entry, is_line, and LM_ERROR.

00305 {
00306   FILE *fp = ACE_OS::fopen (fname, ACE_LIB_TEXT ("r"));
00307 
00308   if (fp == 0)
00309     ACE_ERROR_RETURN ((LM_ERROR,
00310                        ACE_LIB_TEXT ("Can't open %s file\n"),
00311                        fname),
00312                       -1);
00313 
00314   int done;
00315   ACE_TString line;
00316 
00317   while (!(done = (this->getline (fp, line) == -1))
00318          && is_empty (line.c_str ()))
00319     continue;
00320 
00321   while (!done)
00322     {
00323       ACE_TString newline;
00324       ACE_TString description;
00325 
00326       while (!(done = (this->getline (fp, newline) == -1)))
00327         if (is_line (newline.c_str ()))
00328           description += newline;
00329         else
00330           break;
00331 
00332       if (this->is_entry (name, line.c_str()))
00333         {
00334           ACE_OS::fclose (fp);
00335           return this->fillent (description.c_str ());
00336         }
00337 
00338       line = newline;
00339       while (!done && is_empty (line.c_str ()))
00340         done = this->getline (fp, line) == -1;
00341     }
00342 
00343   ACE_OS::fclose (fp);
00344   return -1;
00345 }

int ACE_Capabilities::getline FILE *    fp,
ACE_TString   line
[protected]
 

Get a line from FILE input stream.

Definition at line 227 of file Capabilities.cpp.

References ACE_LIB_TEXT, ACE_String_Base< char >::length, and ACE_String_Base< char >::set.

Referenced by getent.

00228 {
00229   int ch;
00230 
00231   line.set (0, 0);
00232 
00233   while ((ch = fgetc (fp)) != EOF && ch != ACE_LIB_TEXT ('\n'))
00234     line += (ACE_TCHAR) ch;
00235 
00236   if (ch == EOF && line.length () == 0)
00237     return -1;
00238   else
00239     return 0;
00240 }

int ACE_Capabilities::getval const ACE_TCHAR   ent,
int &    val
 

Get an integer entry.

Definition at line 259 of file Capabilities.cpp.

References ACE_TCHAR, caps_, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_CapEntry *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, ACE_BoolCapEntry::getval, and ACE_IntCapEntry::getval.

00260 {
00261   ACE_CapEntry *cap;
00262   if (caps_.find (keyname, cap) == -1)
00263     return -1;
00264 
00265   ACE_IntCapEntry *icap =
00266     ACE_dynamic_cast (ACE_IntCapEntry *, cap);
00267   if (icap != 0)
00268     {
00269       val = icap->getval ();
00270       return 0;
00271     }
00272 
00273   ACE_BoolCapEntry *bcap =
00274     ACE_dynamic_cast (ACE_BoolCapEntry *, cap);
00275 
00276   if (bcap == 0)
00277     return -1;
00278 
00279   val = bcap->getval ();
00280   return 0;
00281 }

int ACE_Capabilities::getval const ACE_TCHAR   ent,
ACE_TString   val
 

Get a string entry.

Definition at line 243 of file Capabilities.cpp.

References ACE_TCHAR, caps_, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_CapEntry *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::find, and ACE_StringCapEntry::getval.

00244 {
00245   ACE_CapEntry* cap;
00246   if (caps_.find (keyname, cap) == -1)
00247     return -1;
00248 
00249   ACE_StringCapEntry *scap =
00250     ACE_dynamic_cast (ACE_StringCapEntry *, cap);
00251   if (scap == 0)
00252     return -1;
00253 
00254   val = scap->getval ();
00255   return 0;
00256 }

int ACE_Capabilities::is_entry const ACE_TCHAR   name,
const ACE_TCHAR   line
[protected]
 

Is a valid entry.

Definition at line 192 of file Capabilities.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_TCHAR, ACE_String_Base< char >::c_str, LM_DEBUG, and ACE_OS_String::strcmp.

Referenced by getent.

00193 {
00194   for (;;)
00195     {
00196       // Skip blanks or irrelevant characters
00197       while (*line && isspace(*line))
00198         line++;
00199 
00200       // End of line reached
00201       if (*line == ACE_LIB_TEXT ('\0'))
00202         break;
00203 
00204       // Build the entry name
00205       ACE_TString nextname;
00206       while (*line && *line != ACE_LIB_TEXT ('|') && *line != ACE_LIB_TEXT (','))
00207         nextname += *line++;
00208 
00209       // We have found the required entry?
00210       if (ACE_OS::strcmp (nextname.c_str (), name) == 0)
00211         return 1;
00212 
00213       // Skip puntuaction char if neccesary.
00214       if (*line == ACE_LIB_TEXT ('|') || *line == ACE_LIB_TEXT (','))
00215         line++;
00216       else
00217         {
00218           ACE_DEBUG ((LM_DEBUG,
00219                       ACE_LIB_TEXT ("Invalid entry\n")));
00220           break;
00221         }
00222     }
00223   return 0;
00224 }

const ACE_TCHAR * ACE_Capabilities::parse const ACE_TCHAR   buf,
ACE_TString   cap
[protected]
 

Parse a string property.

Definition at line 28 of file Capabilities.cpp.

References ACE_ESC, ACE_LIB_TEXT, and ACE_TCHAR.

00029 {
00030   while (*buf != ACE_LIB_TEXT ('\0') && *buf != ACE_LIB_TEXT (','))
00031     {
00032       if (*buf == ACE_LIB_TEXT ('\\'))
00033         {
00034           buf++;
00035           if (*buf == ACE_LIB_TEXT ('E') || *buf == ACE_LIB_TEXT ('e'))
00036             {
00037               cap += ACE_ESC;
00038               buf++;
00039               continue;
00040             }
00041           else if (*buf == ACE_LIB_TEXT ('r'))
00042             {
00043               cap += ACE_LIB_TEXT ('\r');
00044               buf++;
00045               continue;
00046             }
00047           else if (*buf == ACE_LIB_TEXT ('n'))
00048             {
00049               cap += ACE_LIB_TEXT ('\n');
00050               buf++;
00051               continue;
00052             }
00053           else if (*buf == ACE_LIB_TEXT ('t'))
00054             {
00055               cap += ACE_LIB_TEXT ('\t');
00056               buf++;
00057               continue;
00058             }
00059           else if (*buf == ACE_LIB_TEXT ('\\'))
00060             {
00061               cap += *buf++;
00062               continue;
00063             }
00064           if (isdigit(*buf))
00065             {
00066               // @@ UNICODE Does this work with unicode?
00067               int oc = 0;
00068               for (int i = 0;
00069                    i < 3 && *buf && isdigit (*buf);
00070                    i++)
00071                 oc = oc * 8 + (*buf++ - ACE_LIB_TEXT ('0'));
00072 
00073               cap += (ACE_TCHAR) oc;
00074               continue;
00075             }
00076         }
00077       cap += *buf++;
00078     }
00079   return buf;
00080 }

const ACE_TCHAR * ACE_Capabilities::parse const ACE_TCHAR   buf,
int &    cap
[protected]
 

Parse an integer property.

Definition at line 83 of file Capabilities.cpp.

References ACE_LIB_TEXT, and ACE_TCHAR.

Referenced by fillent.

00084 {
00085   int n = 0;
00086 
00087   while (*buf && isdigit (*buf))
00088     n = n * 10 + (*buf++ - ACE_LIB_TEXT ('0'));
00089 
00090   cap = n;
00091 
00092   return buf;
00093 }

int ACE_Capabilities::parseent const ACE_TCHAR   name,
ACE_TCHAR   line
[protected]
 

Parse a cap entry.

void ACE_Capabilities::resetcaps void    [protected]
 

Reset the set of capabilities.

Definition at line 96 of file Capabilities.cpp.

References ACE_Hash_Map_Iterator_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::advance, caps_, ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_CapEntry *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::close, ACE_Hash_Map_Iterator_Base_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::done, ACE_Hash_Map_Entry::int_id_, ACE_Hash_Map_Iterator_Base_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::next, and ACE_Hash_Map_Manager_Ex< ACE_TString, ACE_CapEntry *, ACE_Hash< ACE_TString >, ACE_Equal_To< ACE_TString >, ACE_Null_Mutex >::open.

Referenced by fillent, and ~ACE_Capabilities.

00097 {
00098   for (ACE_Hash_Map_Iterator<ACE_TString, ACE_CapEntry *, ACE_Null_Mutex> iter (caps_);
00099        !iter.done ();
00100        iter.advance ())
00101     {
00102       ACE_Hash_Map_Entry<ACE_TString,ACE_CapEntry*> *entry;
00103       iter.next (entry);
00104       delete entry->int_id_;
00105     }
00106 
00107   caps_.close ();
00108   caps_.open ();
00109 }


Member Data Documentation

ACE_Hash_Map_Manager<ACE_TString, ACE_CapEntry *, ACE_Null_Mutex> ACE_Capabilities::caps_ [private]
 

This is the set of ACE_CapEntry.

Definition at line 172 of file Capabilities.h.

Referenced by fillent, getval, and resetcaps.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:46:32 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002