[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Managed_Object.h
blobd29dc1a5432dcbba03813c965bedb671147359dc
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Managed_Object.h
7 * $Id: Managed_Object.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author David L. Levine <levine@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_MANAGED_OBJECT_H
14 #define ACE_MANAGED_OBJECT_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 #include "ace/Object_Manager.h"
25 #include "ace/Global_Macros.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 /**
30 * @class ACE_Cleanup_Adapter
32 * @brief Adapter for ACE_Cleanup objects that allows them to be readily
33 * managed by the ACE_Object_Manager.
35 * This template class adapts an object of any type to be an
36 * ACE_Cleanup object. The object can then be destroyed
37 * type-safely by the ACE_Object_Manager. This class is
38 * typically used to replace a cast; but, it's a bit cleaner and
39 * allows insertion of, say, run-time type identification
40 * internally if desired.
42 template <class TYPE>
43 class ACE_Cleanup_Adapter : public ACE_Cleanup
45 public:
46 /// Default constructor.
47 ACE_Cleanup_Adapter (void);
49 /// Virtual destructor, needed by some compilers for vtable placement.
50 virtual ~ACE_Cleanup_Adapter (void);
52 /// Accessor for contained object.
53 TYPE &object (void);
55 private:
56 ACE_UNIMPLEMENTED_FUNC (ACE_Cleanup_Adapter (const ACE_Cleanup_Adapter<TYPE> &))
57 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Cleanup_Adapter<TYPE> &))
59 /// Contained object.
60 TYPE object_;
63 /**
64 * @class ACE_Managed_Object
66 * @brief Wrapper for interface to allocate an object managed by the
67 * ACE_Object_Manager.
69 * This template class wraps an interface that is used to
70 * allocate and access an object that is managed by the
71 * ACE_Object_Manager. Because static template member functions
72 * are not supported by some compilers, it is a separate
73 * (template) class.
74 * This interface is typically used to replace a static object
75 * with one that is dynamically allocated. It helps to avoid
76 * problems with order of static object
77 * construction/destruction. Managed objects won't be allocated
78 * until needed, but should be allocated when first needed. And
79 * they are destroyed in the reverse order of construction.
80 * <get_preallocated_object> accesses a "preallocated" object,
81 * i.e., one that is identified by a value in the
82 * ACE_Object_Manager:: Preallocated_Object enum. These objects
83 * are used internally by the ACE library.
84 * Hooks are provided for the application to preallocate objects
85 * via the same mechanism.
86 * ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS can be used
87 * to define enum values;
88 * ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS can be used
89 * to define the corresponding objects. The format of the ACE
90 * internal library definitions should be followed. And
91 * similarly, ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS
92 * and ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS can be
93 * used to preallocate arrays.
94 * By default, preallocation uses dynamic allocation. The
95 * preallocated objects and arrays are allocated off the heap in
96 * the ACE_Object_Manager constructor. To statically place the
97 * preallocated objects in program global data instead of on the
98 * heap, #define ACE_HAS_STATIC_PREALLOCATION prior to building
99 * the ACE library.
101 template <class TYPE>
102 class ACE_Managed_Object
104 public:
105 static TYPE *get_preallocated_object (ACE_Object_Manager::Preallocated_Object identifier)
107 // The preallocated objects are in a separate, "read-only" array so
108 // that this function doesn't need a lock. Also, because it is
109 // intended _only_ for use with hard-code values, it performs no
110 // range checking on "id".
112 // Cast the return type of the the object pointer based
113 // on the type of the function template parameter.
114 return &((ACE_Cleanup_Adapter<TYPE> *)
115 ACE_Object_Manager::preallocated_object[identifier])->object ();
117 // Get the preallocated object identified by "id". Returns a
118 // pointer to the object. Beware: no error indication is provided,
119 // because it can _only_ be used for accessing preallocated objects.
120 // @note The function definition is inlined here so that it compiles
121 // on AIX 4.1 w/xlC v. 3.01.
123 static TYPE *get_preallocated_array (ACE_Object_Manager::Preallocated_Array identifier)
125 // The preallocated array are in a separate, "read-only" array so
126 // that this function doesn't need a lock. Also, because it is
127 // intended _only_ for use with hard-code values, it performs no
128 // range checking on "id".
130 // Cast the return type of the the object pointer based
131 // on the type of the function template parameter.
132 return &((ACE_Cleanup_Adapter<TYPE> *)
133 ACE_Object_Manager::preallocated_array[identifier])->object ();
135 // Get the preallocated array identified by "id". Returns a
136 // pointer to the array. Beware: no error indication is provided,
137 // because it can _only_ be used for accessing preallocated arrays.
138 // @note The function definition is inlined here so that it compiles
139 // on AIX 4.1 w/xlC v. 3.01.
141 protected:
143 // Disallow instantiation of this class.
144 ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object (void))
146 private:
148 ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object (const ACE_Managed_Object<TYPE> &))
149 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Managed_Object<TYPE> &))
152 ACE_END_VERSIONED_NAMESPACE_DECL
154 #if defined (__ACE_INLINE__)
155 #include "ace/Managed_Object.inl"
156 #endif /* __ACE_INLINE__ */
158 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
159 #include "ace/Managed_Object.cpp"
160 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
162 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
163 #pragma implementation ("Managed_Object.cpp")
164 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
166 #include /**/ "ace/post.h"
168 #endif /* ACE_MANAGED_OBJECT_H */