This class implement the ACE Capabilities. More...
#include <Capabilities.h>
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_TCHAR * | parse (const ACE_TCHAR *buf, int &cap) |
Parse an integer property. | |
const ACE_TCHAR * | parse (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. |
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 140 of file Capabilities.h.
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 144 of file Capabilities.h.
ACE_Capabilities::ACE_Capabilities | ( | void | ) |
ACE_Capabilities::~ACE_Capabilities | ( | void | ) |
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.
{ this->resetcaps (); while (*buf) { ACE_TString s; int n; ACE_TString name; ACE_CapEntry *ce; // Skip blanks while (*buf && ACE_OS::ace_isspace(*buf)) buf++; // If we get end of line return if (*buf == ACE_TEXT ('\0')) break; if (*buf == ACE_TEXT ('#')) { while (*buf && *buf != ACE_TEXT ('\n')) buf++; if (*buf == ACE_TEXT ('\n')) buf++; continue; } while(*buf && *buf != ACE_TEXT ('=') && *buf!= ACE_TEXT ('#') && *buf != ACE_TEXT (',')) name += *buf++; // If name is null. switch (*buf) { case ACE_TEXT ('='): // String property buf = this->parse (buf + 1, s); ACE_NEW_RETURN (ce, ACE_StringCapEntry (s), -1); if (this->caps_.bind (name, ce) == -1) { delete ce; return -1; } break; case ACE_TEXT ('#'): // Integer property buf = this->parse (buf + 1, n); ACE_NEW_RETURN (ce, ACE_IntCapEntry (n), -1); if (this->caps_.bind (name, ce) == -1) { delete ce; return -1; } break; case ACE_TEXT (','): // Boolean ACE_NEW_RETURN (ce, ACE_BoolCapEntry (1), -1); if (this->caps_.bind (name, ce) == -1) { delete ce; return -1; } break; default: return 0; } if (*buf++ != ACE_TEXT (',')) return -1; } return 0; }
Get the ACE_Capabilities name from FILE fname and load the associated capabitily entries in map.
Definition at line 312 of file Capabilities.cpp.
{ FILE *fp = ACE_OS::fopen (fname, ACE_TEXT ("r")); if (fp == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Can't open %s file\n"), fname), -1); int done; ACE_TString line; while (0 == (done = (this->getline (fp, line) == -1)) && is_empty (line.c_str ())) continue; while (!done) { ACE_TString newline; ACE_TString description; while (0 == (done = (this->getline (fp, newline) == -1))) if (is_line (newline.c_str ())) description += newline; else break; if (this->is_entry (name, line.c_str())) { ACE_OS::fclose (fp); return this->fillent (description.c_str ()); } line = newline; while (!done && is_empty (line.c_str ())) done = this->getline (fp, line) == -1; } ACE_OS::fclose (fp); return -1; }
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.
{ int ch; line.set (0, 0); while ((ch = ACE_OS::fgetc (fp)) != EOF && ch != ACE_TEXT ('\n')) line += (ACE_TCHAR) ch; if (ch == EOF && line.length () == 0) return -1; else return 0; }
int ACE_Capabilities::getval | ( | const ACE_TCHAR * | ent, | |
int & | val | |||
) |
Get an integer entry.
Definition at line 267 of file Capabilities.cpp.
{ ACE_CapEntry *cap = 0; if (this->caps_.find (keyname, cap) == -1) return -1; ACE_IntCapEntry *icap = dynamic_cast<ACE_IntCapEntry *> (cap); if (icap != 0) { val = icap->getval (); return 0; } ACE_BoolCapEntry *bcap = dynamic_cast<ACE_BoolCapEntry *> (cap); if (bcap == 0) return -1; val = bcap->getval (); return 0; }
int ACE_Capabilities::getval | ( | const ACE_TCHAR * | ent, | |
ACE_TString & | val | |||
) |
Get a string entry.
Definition at line 251 of file Capabilities.cpp.
{ ACE_CapEntry* cap = 0; if (this->caps_.find (keyname, cap) == -1) return -1; ACE_StringCapEntry *scap = dynamic_cast<ACE_StringCapEntry *> (cap); if (scap == 0) return -1; val = scap->getval (); return 0; }
Is a valid entry.
Definition at line 200 of file Capabilities.cpp.
{ for (;;) { // Skip blanks or irrelevant characters while (*line && ACE_OS::ace_isspace(*line)) ++line; // End of line reached if (*line == ACE_TEXT ('\0')) break; // Build the entry name ACE_TString nextname; while (*line && *line != ACE_TEXT ('|') && *line != ACE_TEXT (',')) nextname += *line++; // We have found the required entry? if (ACE_OS::strcmp (nextname.c_str (), name) == 0) return 1; // Skip puntuaction char if neccesary. if (*line == ACE_TEXT ('|') || *line == ACE_TEXT (',')) ++line; else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Invalid entry\n"))); break; } } return 0; }
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.
{ while (*buf != ACE_TEXT ('\0') && *buf != ACE_TEXT (',')) { if (*buf == ACE_TEXT ('\\')) { ++buf; if (*buf == ACE_TEXT ('E') || *buf == ACE_TEXT ('e')) { cap += ACE_ESC; ++buf; continue; } else if (*buf == ACE_TEXT ('r')) { cap += ACE_TEXT ('\r'); ++buf; continue; } else if (*buf == ACE_TEXT ('n')) { cap += ACE_TEXT ('\n'); ++buf; continue; } else if (*buf == ACE_TEXT ('t')) { cap += ACE_TEXT ('\t'); ++buf; continue; } else if (*buf == ACE_TEXT ('\\')) { cap += *buf++; continue; } if (ACE_OS::ace_isdigit(*buf)) { // @@ UNICODE Does this work with unicode? int oc = 0; for (int i = 0; i < 3 && *buf && ACE_OS::ace_isdigit (*buf); i++) oc = oc * 8 + (*buf++ - ACE_TEXT ('0')); cap += (ACE_TCHAR) oc; continue; } } cap += *buf++; } return buf; }
Parse an integer property.
Definition at line 91 of file Capabilities.cpp.
{ int n = 0; while (*buf && ACE_OS::ace_isdigit (*buf)) n = n * 10 + (*buf++ - ACE_TEXT ('0')); cap = n; return buf; }
Parse a cap entry.
void ACE_Capabilities::resetcaps | ( | void | ) | [protected] |
Reset the set of capabilities.
Definition at line 104 of file Capabilities.cpp.
{ for (CAPABILITIES_MAP::ITERATOR iter (this->caps_); !iter.done (); iter.advance ()) { CAPABILITIES_MAP::ENTRY *entry = 0; iter.next (entry); delete entry->int_id_; } this->caps_.close (); this->caps_.open (); }
CAPABILITIES_MAP ACE_Capabilities::caps_ [private] |
This is the set of ACE_CapEntry.
Definition at line 191 of file Capabilities.h.