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 Types

typedef ACE_Hash_Map_Manager_Ex<
ACE_TString, ACE_CapEntry *,
ACE_Hash< ACE_TString >,
ACE_Equal_To< ACE_TString >,
ACE_Null_Mutex
CAPABILITIES_MAP

Public Member Functions

 ACE_Capabilities (void)
 The Constructor.

 ~ACE_Capabilities (void)
 The Destructor.

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

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

int getent (const ACE_TCHAR *fname, const ACE_TCHAR *name)

Protected Member Functions

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

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

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

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

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

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

void resetcaps (void)
 Reset the set of capabilities.


Private Attributes

CAPABILITIES_MAP caps_
 This is the set of ACE_CapEntry.


Detailed Description

This class implement the ACE Capabilities.

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

Definition at line 134 of file Capabilities.h.


Member Typedef Documentation

typedef ACE_Hash_Map_Manager_Ex<ACE_TString, ACE_CapEntry *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex> ACE_Capabilities::CAPABILITIES_MAP
 

Definition at line 138 of file Capabilities.h.


Constructor & Destructor Documentation

ACE_Capabilities::ACE_Capabilities void   ) 
 

The Constructor.

Definition at line 25 of file Capabilities.cpp.

00026   : caps_ ()
00027 {
00028 }

ACE_Capabilities::~ACE_Capabilities void   ) 
 

The Destructor.

Definition at line 30 of file Capabilities.cpp.

References resetcaps().

00031 {
00032   this->resetcaps ();
00033 }


Member Function Documentation

int ACE_Capabilities::fillent const ACE_TCHAR ent  )  [protected]
 

Fill the ACE_Capabilities with description in ent.

Definition at line 120 of file Capabilities.cpp.

References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, ACE_TString, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), caps_, parse(), and resetcaps().

Referenced by getent().

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

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 312 of file Capabilities.cpp.

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

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

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

Get a line from FILE input stream.

Definition at line 235 of file Capabilities.cpp.

References ACE_LIB_TEXT, ACE_TCHAR, ACE_TString, ACE_String_Base< CHAR >::length(), and ACE_String_Base< CHAR >::set().

Referenced by getent().

00236 {
00237   int ch;
00238 
00239   line.set (0, 0);
00240 
00241   while ((ch = fgetc (fp)) != EOF && ch != ACE_LIB_TEXT ('\n'))
00242     line += (ACE_TCHAR) ch;
00243 
00244   if (ch == EOF && line.length () == 0)
00245     return -1;
00246   else
00247     return 0;
00248 }

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

Get an integer entry.

Definition at line 267 of file Capabilities.cpp.

References ACE_TCHAR, caps_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), ACE_BoolCapEntry::getval(), and ACE_IntCapEntry::getval().

00268 {
00269   ACE_CapEntry *cap = 0;
00270   if (this->caps_.find (keyname, cap) == -1)
00271     return -1;
00272 
00273   ACE_IntCapEntry *icap =
00274     dynamic_cast<ACE_IntCapEntry *> (cap);
00275   if (icap != 0)
00276     {
00277       val = icap->getval ();
00278       return 0;
00279     }
00280 
00281   ACE_BoolCapEntry *bcap =
00282     dynamic_cast<ACE_BoolCapEntry *> (cap);
00283 
00284   if (bcap == 0)
00285     return -1;
00286 
00287   val = bcap->getval ();
00288   return 0;
00289 }

int ACE_Capabilities::getval const ACE_TCHAR ent,
ACE_TString val
 

Get a string entry.

Definition at line 251 of file Capabilities.cpp.

References ACE_TCHAR, ACE_TString, caps_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), and ACE_StringCapEntry::getval().

00252 {
00253   ACE_CapEntry* cap = 0;
00254   if (this->caps_.find (keyname, cap) == -1)
00255     return -1;
00256 
00257   ACE_StringCapEntry *scap =
00258     dynamic_cast<ACE_StringCapEntry *> (cap);
00259   if (scap == 0)
00260     return -1;
00261 
00262   val = scap->getval ();
00263   return 0;
00264 }

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

Is a valid entry.

Definition at line 200 of file Capabilities.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_TCHAR, ACE_TString, ACE_String_Base< CHAR >::c_str(), LM_DEBUG, and ACE_OS::strcmp().

Referenced by getent().

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

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

Parse a string property.

Definition at line 36 of file Capabilities.cpp.

References ACE_ESC, ACE_LIB_TEXT, ACE_TCHAR, and ACE_TString.

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

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

Parse an integer property.

Definition at line 91 of file Capabilities.cpp.

References ACE_LIB_TEXT, and ACE_TCHAR.

Referenced by fillent().

00092 {
00093   int n = 0;
00094 
00095   while (*buf && isdigit (*buf))
00096     n = n * 10 + (*buf++ - ACE_LIB_TEXT ('0'));
00097 
00098   cap = n;
00099 
00100   return buf;
00101 }

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 104 of file Capabilities.cpp.

References caps_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::close(), and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::open().

Referenced by fillent(), and ~ACE_Capabilities().

00105 {
00106   for (CAPABILITIES_MAP::ITERATOR iter (this->caps_);
00107        !iter.done ();
00108        iter.advance ())
00109     {
00110       CAPABILITIES_MAP::ENTRY *entry = 0;
00111       iter.next (entry);
00112       delete entry->int_id_;
00113     }
00114 
00115   this->caps_.close ();
00116   this->caps_.open ();
00117 }


Member Data Documentation

CAPABILITIES_MAP ACE_Capabilities::caps_ [private]
 

This is the set of ACE_CapEntry.

Definition at line 185 of file Capabilities.h.

Referenced by fillent(), getval(), and resetcaps().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:20:36 2006 for ACE by doxygen 1.3.6