[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Registry.h
blobb5d3b5449a5e56ea0a3c9b8e0331268aaba3f56a
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Registry.h
7 * $Id: Registry.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Irfan Pyarali (irfan@cs.wustl.edu)
11 //=============================================================================
14 #ifndef ACE_REGISTRY_H
15 #define ACE_REGISTRY_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
25 // This only works on registry-capable Win32 platforms.
27 #include "ace/Containers.h"
28 #include "ace/SString.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 /**
33 * @class ACE_Registry
35 * @brief A Name Server implementation
37 * The registry interface is inspired by the interface
38 * specified in the CORBA Naming Service Specification.
39 * The implementation is done through Win32 <Reg*> functions.
40 * Other than providing an OO wrapper for the Win32 <Reg*>
41 * functions, ACE_Registry provides an abstraction for iteration
42 * over the elements of the Registry.
44 class ACE_Export ACE_Registry
46 public:
48 /// International string
49 struct ACE_Export Name_Component
51 ACE_TString id_;
52 ACE_TString kind_;
54 bool operator== (const Name_Component &rhs) const;
55 bool operator!= (const Name_Component &rhs) const;
56 // Comparison
58 // The <id_> field is used,
59 // but the <kind_> field is currently ignored
61 /// A Name is an ordered collections of components (ids)
62 typedef ACE_Unbounded_Set<Name_Component> Name;
64 /// Separator for components in a name
65 static const ACE_TCHAR STRING_SEPARATOR[];
67 /// Convert a @a name to a @c string
68 static ACE_TString make_string (const Name &name);
70 /// Convert a @a string to a @c name
71 static Name make_name (const ACE_TString &string);
73 /// There are two types of bindings
74 enum Binding_Type {INVALID, OBJECT, CONTEXT};
76 struct ACE_Export Binding
78 /// Empty (default) constructor
79 Binding (void);
81 /// Constructor
82 /// (Name version)
83 Binding (const Name &binding_name,
84 Binding_Type binding_type);
86 /// Constructor
87 /// (String version)
88 Binding (const ACE_TString &binding_name,
89 Binding_Type binding_type);
91 bool operator== (const Binding &rhs) const;
92 bool operator!= (const Binding &rhs) const;
93 // Comparison
95 /// Name accessor
96 /// (Name version)
97 void name (Name &name);
99 /// Set Name (String version)
100 void name (ACE_TString &name);
102 /// Get Name (String version)
103 ACE_TString name (void);
105 /// Type accessor
106 Binding_Type type (void);
108 private:
109 /// A binding has a name
110 ACE_TString name_;
112 /// .... and a type
113 Binding_Type type_;
116 /// A list of bindings
117 typedef ACE_Unbounded_Set<Binding> Binding_List;
119 // Forward declaration of iterator
120 class Binding_Iterator;
123 * @class Object
125 * @brief An object representation
127 * In CORBA, all objects inherit from (CORBA::Object).
128 * For the registry, this is used as a wrapper for an
129 * instance of a built-in data type.
130 * Think about an object as being similar to a file
131 * in a file system.
133 class ACE_Export Object
135 public:
136 /// Default constructor
137 Object (void *data = 0,
138 u_long size = 0,
139 u_long type = REG_NONE);
141 /// Set data
142 void data (void *data);
144 /// Get data
145 void *data (void) const;
147 /// Set size
148 void size (u_long size);
150 /// Get size
151 u_long size (void) const;
153 /// Set type
154 void type (u_long type);
156 /// Get type
157 u_long type (void) const;
159 private:
160 /// Pointer to data
161 void *data_;
163 /// Size of the data
164 u_long size_;
166 /// Type of data
167 u_long type_;
171 * @class Naming_Context
173 * @brief An context representation
175 * Think about a context as being similar to a directory
176 * in a file system.
178 class ACE_Export Naming_Context
180 public:
181 /// Friend factory
182 friend class ACE_Predefined_Naming_Contexts;
184 enum {
185 /// Max sizes of names
186 /// (Not too sure about this value)
187 MAX_OBJECT_NAME_SIZE = BUFSIZ,
189 /// Max size of context name
190 MAX_CONTEXT_NAME_SIZE = MAXPATHLEN + 1
193 /// Empty constructor: keys will be NULL
194 Naming_Context (void);
196 /// Constructor: key_ will be set to @a key
197 Naming_Context (const HKEY &key);
199 /// Destructor will call <Naming_Context::close>.
200 ~Naming_Context (void);
202 // The following interfaces are for objects
205 * Insert @a object with @a name into @c this context.
206 * This will fail if @a name already exists
207 * (Name version)
209 int bind_new (const Name &name,
210 const Object &object);
213 * Insert @a object with @a name into @c this context
214 * This will fail if @a name already exists
215 * (String version)
217 int bind_new (const ACE_TString &name,
218 const Object &object);
221 * Insert or update @a object with @a name into @c this context
222 * This will not fail if @a name already exists
223 * (Name version)
225 int bind (const Name &name,
226 const Object &object);
229 * Insert or update <object> with @a name into @c this context
230 * This will not fail if @a name already exists
231 * (String version)
233 int bind (const ACE_TString &name,
234 const Object &object);
236 /// Update <object> with @a name in @c this context
237 /// (Name version)
238 int rebind (const Name &name,
239 const Object &object);
241 /// Update <object> with @a name in @c this context
242 int rebind (const ACE_TString &name,
243 const Object &object);
245 /// Find <object> with @a name in @c this context
246 /// (Name version)
247 int resolve (const Name &name,
248 Object &object);
250 /// Find <object> with @a name in @c this context
251 int resolve (const ACE_TString &name,
252 Object &object);
254 /// Delete object with @a name in @c this context
255 /// (Name version)
256 int unbind (const Name &name);
258 /// Delete object with @a name in @c this context
259 int unbind (const ACE_TString &name);
262 // The following interfaces are for Naming Context
264 /// Create new @c naming_context
265 int new_context (Naming_Context &naming_context);
268 * Insert <naming_context> with @a name relative to @c this context
269 * This will fail if @a name already exists
270 * (Name version)
272 int bind_new_context (const Name &name,
273 Naming_Context &naming_context,
274 u_long persistence = REG_OPTION_NON_VOLATILE,
275 u_long security_access = KEY_ALL_ACCESS,
276 LPSECURITY_ATTRIBUTES security_attributes = 0);
278 /// Insert <naming_context> with @a name relative to @c this context
279 /// This will fail if @a name already exists
280 int bind_new_context (const ACE_TString &name,
281 Naming_Context &naming_context,
282 u_long persistence = REG_OPTION_NON_VOLATILE,
283 u_long security_access = KEY_ALL_ACCESS,
284 LPSECURITY_ATTRIBUTES security_attributes = 0);
287 * Insert or update <naming_context> with @a name relative to @c this context
288 * This will not fail if @a name already exists
289 * (Name version)
291 int bind_context (const Name &name,
292 /* const */ Naming_Context &naming_context,
293 u_long persistence = REG_OPTION_NON_VOLATILE,
294 u_long security_access = KEY_ALL_ACCESS,
295 LPSECURITY_ATTRIBUTES security_attributes = 0);
297 /// Insert or update <naming_context> with @a name relative to @c this context
298 /// This will not fail if @a name already exists
299 int bind_context (const ACE_TString &name,
300 /* const */ Naming_Context &naming_context,
301 u_long persistence = REG_OPTION_NON_VOLATILE,
302 u_long security_access = KEY_ALL_ACCESS,
303 LPSECURITY_ATTRIBUTES security_attributes = 0);
305 /// Rename <naming_context> to @a name
306 /// (Name version)
307 int rebind_context (const Name &name,
308 /* const */ Naming_Context &naming_context);
310 /// Rename <naming_context> to @a name
311 int rebind_context (const ACE_TString &name,
312 /* const */ Naming_Context &naming_context);
314 /// Find <naming_context> with @a name in @c this context
315 /// (Name version)
316 int resolve_context (const Name &name,
317 Naming_Context &naming_context,
318 u_long security_access = KEY_ALL_ACCESS);
320 /// Find <naming_context> with @a name in @c this context
321 int resolve_context (const ACE_TString &name,
322 Naming_Context &naming_context,
323 u_long security_access = KEY_ALL_ACCESS);
325 /// Remove naming_context with @a name from @c this context
326 /// (Name version)
327 int unbind_context (const Name &name);
329 /// Remove naming_context with @a name from @c this context
330 int unbind_context (const ACE_TString &name);
332 /// Same as <unbind_context> with @c this as naming_context
333 int destroy (void);
336 * listing function: iterator creator
337 * This is useful when there are many objects and contexts
338 * in @c this context and you only want to look at a few entries
339 * at a time
341 int list (u_long how_many,
342 Binding_List &list,
343 Binding_Iterator &iterator);
345 /// listing function: iterator creator
346 /// This gives back a listing of all entries in @c this context.
347 int list (Binding_List &list);
349 // Some other necessary functions which are
350 // not part of the CORBA interface
352 /// Sync content of context to disk
353 int flush (void);
355 /// Close the handle of the context
356 /// @note <close> does not call <flush>
357 int close (void);
359 // Accessors
361 /// Get key
362 HKEY key (void);
364 // void parent (HKEY parent);
365 /// Get parent
366 HKEY parent (void);
368 /// Get name
369 /// (Name version)
370 void name (Name &name);
372 /// Set name (String version)
373 void name (ACE_TString &name);
375 /// Get name (String version)
376 ACE_TString name (void);
378 protected:
379 /// Set key
380 void key (HKEY key);
382 /// Set parent
383 void parent (HKEY parent);
385 /// Set name
386 /// (Name version)
387 void name (const Name &name);
389 /// Set name
390 /// (String version)
391 void name (const ACE_TString &name);
393 private:
394 /// Disallow copy constructors
395 Naming_Context (const Naming_Context &rhs);
397 /// Disallow assignment
398 const Naming_Context &operator= (const Naming_Context &rhs);
400 /// Key for self
401 HKEY key_;
403 /// Key for parent
404 HKEY parent_key_;
406 /// Name of self
407 ACE_TString name_;
411 * @class Binding_Iterator
413 * @brief An iterator
415 * Useful when iteratorating over a few entries at a time
417 class ACE_Export Binding_Iterator
419 public:
420 /// Friend factory
421 friend class Naming_Context;
423 /// Default constructor
424 Binding_Iterator (void);
426 /// Next entry
427 int next_one (Binding &binding);
429 /// Next <how_many> entries
430 int next_n (u_long how_many,
431 Binding_List &list);
433 /// Cleanup
434 int destroy (void);
436 /// Reset the internal state of the iterator
437 void reset (void);
439 /// Get naming_context that the iterator is iterating over
440 Naming_Context &naming_context (void);
442 private:
444 /// Set naming_context that the iterator is iterating over
445 void naming_context (Naming_Context& naming_context);
447 /// Reference to context
448 Naming_Context *naming_context_;
450 public:
451 // This should really be private
452 // But the compiler is broken
455 * @class Iteration_State
457 * Base class for state
459 class ACE_Export Iteration_State
461 public:
462 /// Constructor
463 Iteration_State ();
465 /// Set the iterator reference.
466 void iterator (Binding_Iterator *iterator);
468 /// Next <how_many> entries
469 virtual int next_n (u_long how_many,
470 Binding_List &list) = 0;
472 /// Reset state
473 void reset (void);
475 protected:
476 /// Pointer to parent iterator
477 Binding_Iterator *parent_;
479 u_long index_;
482 private:
483 class ACE_Export Object_Iteration : public Iteration_State
485 /// Next <how_many> entries
486 int next_n (u_long how_many,
487 Binding_List &list);
490 class ACE_Export Context_Iteration : public Iteration_State
492 public:
493 /// Next @a how_many entries
494 int next_n (u_long how_many,
495 Binding_List &list);
498 class ACE_Export Iteration_Complete : public Iteration_State
500 public:
501 /// Next @a how_many entries
502 int next_n (u_long how_many,
503 Binding_List &list);
506 /// Friend states
507 friend class Iteration_State;
508 friend class Object_Iteration;
509 friend class Context_Iteration;
510 friend class Iteration_Complete;
512 /// Instances of all states
513 Object_Iteration object_iteration_;
514 Context_Iteration context_iteration_;
515 Iteration_Complete iteration_complete_;
517 /// Pointer to current state
518 Iteration_State *current_enumeration_;
520 /// Set current_enumeration
521 void current_enumeration (Iteration_State& current_enumeration);
523 /// Get current_enumeration
524 Iteration_State &current_enumeration (void);
529 * @class ACE_Predefined_Naming_Contexts
531 * @brief A factory for predefined registries, which exist by default
532 * on Win32 platforms
534 * This factory can connect to both local and remote
535 * predefined registries.
537 class ACE_Export ACE_Predefined_Naming_Contexts
539 public:
541 * Factory method for connecting to predefined registries. This
542 * method works for both remote and local machines. However, for
543 * remote machines, HKEY_CLASSES_ROOT and HKEY_CURRENT_USER types
544 * are not allowed
546 static int connect (ACE_Registry::Naming_Context &naming_context,
547 HKEY predefined = HKEY_LOCAL_MACHINE,
548 const ACE_TCHAR *machine_name = 0);
550 private:
551 /// Check if @a machine_name is the local host
552 static int is_local_host (const ACE_TCHAR *machine_name);
555 ACE_END_VERSIONED_NAMESPACE_DECL
557 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
558 #include /**/ "ace/post.h"
559 #endif /* ACE_REGISTRY_H */