summaryrefslogtreecommitdiff
path: root/ace/Capabilities.h
blob: 03fc25242e607af9723d00c4252c4f577c1a9f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file    Capabilities.h
 *
 *  $Id$
 *
 *  @author Arturo Montes <mitosys@colomsat.net.co>
 */
//=============================================================================


#ifndef ACE_CAPABILITIES_H
#define ACE_CAPABILITIES_H
#include "ace/pre.h"

#include "ace/OS.h"
#include "ace/Synch.h"
#include "ace/Hash_Map_Manager.h"
#include "ace/Containers.h"
#include "ace/SString.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

/**
 * @class ACE_CapEntry
 *
 * @brief This class is the base class for all ACE Capabilities entry
 * subclasses.
 *
 * This class is not instantiable and does not provide accessors
 * or methods.  If you want to add a new kind of attribute you
 * subclasses of this class and dynamic cast to proper subclass.
 */
class ACE_Export ACE_CapEntry
{
public:
   virtual ~ACE_CapEntry (void);

protected:
  enum
  {
    ACE_INTCAP = 0,
    ACE_STRINGCAP = 1,
    ACE_BOOLCAP = 2
  };

  ACE_CapEntry (int captype);

  int captype_;
};

/**
 * @class ACE_IntCapEntry
 *
 * @brief This class implement the ACE Integer Capability subclass.
 *
 * This is a container class for ACE Capabilities integer container
 * values.
 */
class ACE_Export ACE_IntCapEntry : public ACE_CapEntry
{
public:
  ACE_IntCapEntry (int val);
  int getval (void) const;

protected:
  int val_;
};

/**
 * @class ACE_StringCapEntry
 *
 * @brief This class implement the ACE String Capability subclass.
 *
 * This is a container class for ACE Capabilities String container
 * values.
 */
class ACE_Export ACE_StringCapEntry : public ACE_CapEntry
{
public:
  ACE_StringCapEntry (const ACE_TString &val);
  ACE_TString getval (void) const;

protected:
  ACE_TString val_;
};

/**
 * @class ACE_BoolCapEntry
 *
 * @brief This class implement the ACE Bool Capability subclass.
 *
 * This is a container class for ACE Capabilities bool container
 * values.
 */
class ACE_Export ACE_BoolCapEntry : public ACE_CapEntry
{
public:
  ACE_BoolCapEntry (int val);
  int getval (void) const;

protected:
  int val_;
};

/**
 * @class ACE_Capabilities
 *
 * @brief 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.
 */
class ACE_Export ACE_Capabilities
{
public:
  /// The Constructor
  ACE_Capabilities (void);

  /// The Destructor
  ~ACE_Capabilities(void);

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

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

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

protected:
  // Parse an integer property
  /// Parse a string property
  const ACE_TCHAR *parse (const ACE_TCHAR *buf, int &cap);

  /// Fill the ACE_Capabilities with description in ent.
  const ACE_TCHAR *parse (const ACE_TCHAR *buf, ACE_TString &cap);

  /// Parse a cap entry
  int fillent(const ACE_TCHAR *ent);

  /// Get a line from FILE input stream
  int parseent (const ACE_TCHAR *name, ACE_TCHAR *line);

  /// Is a valid entry
  int getline (FILE* fp,
               ACE_TString &line);

  /// Reset the set of capabilities
  int is_entry (const ACE_TCHAR *name, const ACE_TCHAR *line);

  /// Atributes.
  void resetcaps (void);

private:
  /// This is the set of ACE_CapEntry.
  ACE_Hash_Map_Manager<ACE_TString, ACE_CapEntry *, ACE_Null_Mutex> caps_;
};

#if defined (ACE_IS_SPLITTING)
int
is_empty (const ACE_TCHAR *line)
{
  while (*line && isspace (*line))
    line++;

  return *line == ACE_LIB_TEXT ('\0') || *line == ACE_LIB_TEXT ('#');
}

int
is_line (const ACE_TCHAR *line)
{
  while (*line && isspace (*line))
    line++;

  return *line != ACE_LIB_TEXT ('\0');
}
#endif /* ACE_IS_SPLITTING */

#if defined (__ACE_INLINE__)
#include "ace/Capabilities.i"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /* __ACE_CAPABILITIES_H__ */