C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/lang/Class.hpp

00001 /*
00002  * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
00003  *
00004  * Licensed under the Universal Permissive License v 1.0 as shown at
00005  * http://oss.oracle.com/licenses/upl.
00006  */
00007 #ifndef COH_CLASS_HPP
00008 #define COH_CLASS_HPP
00009 
00010 #include "coherence/lang/compatibility.hpp"
00011 
00012 #include "coherence/lang/abstract_spec.hpp"
00013 #include "coherence/lang/AnnotatedElement.hpp"
00014 #include "coherence/lang/FinalView.hpp"
00015 #include "coherence/lang/FinalHandle.hpp"
00016 #include "coherence/lang/Method.hpp"
00017 #include "coherence/lang/Object.hpp"
00018 #include "coherence/lang/ObjectArray.hpp"
00019 #include "coherence/lang/String.hpp"
00020 
00021 
00022 #include <typeinfo>
00023 
00024 COH_OPEN_NAMESPACE2(coherence,lang)
00025 
00026 
00027 /**
00028 * A Class represents a managed object implementation.
00029 *
00030 * Not all managed classes may have a corresponding Class representation.
00031 * Classes are referred to via their demangled RTTI name, for example
00032 * coherence::lang::Object.
00033 *
00034 * Classes can be loaded by name via a ClassLoader.
00035 *
00036 * @see ClassLoader
00037 *
00038 * @author mf  2008.04.03
00039 */
00040 class COH_EXPORT Class
00041     : public abstract_spec<Class,
00042           extends<AnnotatedElement> >
00043     {
00044     // ----- constructors ---------------------------------------------------
00045 
00046     protected:
00047         /**
00048         * Construct a class based on a C++ type_info.
00049         *
00050         * @param info the type_info for the class represented by this Class.
00051         */
00052         Class(const std::type_info& info);
00053 
00054     private:
00055         /**
00056         * Blocked copy constructor
00057         */
00058         Class(const Class&);
00059 
00060 
00061     // ----- Class interface ------------------------------------------------
00062 
00063     public:
00064         /**
00065         * Return the name of the class.
00066         *
00067         * @return the class name
00068         */
00069         virtual String::View getName() const;
00070 
00071         /**
00072         * Returns the simple name of the underlying class as given in the
00073         * source code.
00074         *
00075         * If a simple name cannot be determined, the full name from
00076         * getName() will be returned.
00077         *
00078         * @return the simple name of the underlying class
00079         *
00080         * @since 12.2.1.3
00081         */
00082         virtual String::View getSimpleName() const;
00083 
00084         /**
00085         * Create a new instance of the corresponding type.
00086         *
00087         * @param vaParam the object's initialization parameters
00088         *
00089         * @return a new instance of the corresponding type
00090         */
00091         virtual Object::Handle newInstance(ObjectArray::View vaParam = NULL) const;
00092 
00093         /**
00094         * Return the typeinfo for the corresponding type.
00095         *
00096         * @return the typeinfo for the corresponding type
00097         */
00098         virtual const std::type_info& getTypeInfo() const = 0;
00099 
00100         /**
00101         * Return the shallow size for an instance of the class represented
00102         * by this Class.
00103         *
00104         * @return the shallow size of an instance of the represented class.
00105         */
00106         virtual size32_t getSize() const = 0;
00107 
00108         /**
00109         * Return whether the passed in Object is an instance of class represented
00110         * by this Class.
00111         *
00112         * @param v  the object to test
00113         *
00114         * @return whether the passed in Object is an instance of class represented
00115         * by this Class.
00116         *
00117         * @since Coherence 3.7
00118         */
00119         virtual bool isInstance(Object::View v) const = 0;
00120 
00121         /**
00122          * Return true if the class represented by this object is the same
00123          * Class or a super class or super interface of the specified class.
00124          *
00125          * @param vClass  the class to test
00126          *
00127          * @return true if the specified class "extends" the class represented
00128          *         by this object.
00129          */
00130         virtual bool isAssignableFrom(Class::View vClass) const = 0;
00131 
00132         /**
00133          * Register a method with this class.
00134          *
00135          * @param vMethod  the method to register
00136          *
00137          * @since Coherence 3.7.1
00138          */
00139         virtual Class::Handle declare(Method::View vMethod);
00140 
00141         /**
00142          * Return the declared method of the specified name and parameters.
00143          *
00144          * The method is supplied with an array of either parameters or
00145          * parameter types expressed as Class::View objects.  If non-Class
00146          * objects are provided then this method will search for a Method
00147          * which can accept those parameters directly.  If Class objects are
00148          * provided then this method will search for a Method which takes
00149          * the specified type, or a superclass.
00150          *
00151          * @param vsName    the method name
00152          * @param vaParams  the method parameters or types
00153          * @param nMod      the modifiers to match
00154          * @param fThrow    false to return NULL rather then throw on failure
00155          *
00156          * @return the Method
00157          *
00158          * @throw NoSuchMethodException if the method is not found and fThrow == true
00159          *
00160          * @since Coherence 3.7.1
00161          */
00162         virtual Method::View getDeclaredMethod(String::View vsName,
00163                 ObjectArray::View vaParams = NULL, int32_t nMod = 0,
00164                 bool fThrow = true) const;
00165 
00166         /**
00167          * Return an array containing all the Methods declared on this Class.
00168          *
00169          * @return the declared methods
00170          *
00171          * @since Coherence 3.7.1
00172          */
00173         virtual ObjectArray::View getDeclaredMethods() const;
00174 
00175         /**
00176          * Return the method of the specified name and parameters which is
00177          * either declared or inherited by this class.
00178          *
00179          * The method is supplied with an array of either parameters or
00180          * parameter types expressed as Class::View objects.  If non-Class
00181          * objects are provided then this method will search for a Method
00182          * which can accept those parameters directly.  If Class objects are
00183          * provided then this method will search for a Method which takes
00184          * the specified type, or a superclass.
00185          *
00186          * @param vsName    the method name
00187          * @param vaParams  the method parameters or types
00188          * @param nMod      the modifiers to match
00189          * @param fThrow    false to return NULL rather then throw on failure
00190          *
00191          * @return the Method
00192          *
00193          * @throw NoSuchMethodException if the method is not found and fThrow == true
00194          *
00195          * @since Coherence 3.7.1
00196          */
00197         virtual Method::View getMethod(String::View vsName,
00198                 ObjectArray::View vaParams = NULL, int32_t nMod = 0,
00199                 bool fThrow = true) const;
00200 
00201         /**
00202          * Return an array containing all the Methods declared on and inherited
00203          * by this Class.
00204          *
00205          * @return the declared methods
00206          *
00207          * @since Coherence 3.7.1
00208          */
00209         virtual ObjectArray::View getMethods() const;
00210 
00211         /**
00212          * Return the superclass of this class, or NULL if this class an
00213          * interface or top level class.
00214          *
00215          * @return the superclass
00216          *
00217          * @throws ClassNotFoundException if the superclass is not registered
00218          *
00219          * @since Coherence 3.7.1
00220          */
00221         virtual Class::View getSuperclass() const = 0;
00222 
00223         /**
00224          * Return an array of Class::View objects representing the interfaces
00225          * which the Class directly implements.
00226          *
00227          * Any interfaces not registered with the ClassLoader will be left
00228          * out of the array.
00229          *
00230          * @return the array of Class::Views representing the interfaces
00231          *
00232          * @since Coherence 3.7.1
00233          */
00234         virtual ObjectArray::View getInterfaces() const = 0;
00235 
00236         /**
00237          * Add the specified Annotation to the element.
00238          *
00239          * @param vAnnontation  the annotation
00240          *
00241          * @return this object
00242          */
00243         virtual Class::Handle annotate(Annotation::View vAnnontation);
00244 
00245 
00246     // ----- AnnotatedElement interface -------------------------------------
00247 
00248     public:
00249         /**
00250          * {@inheritDoc}
00251          */
00252         virtual AnnotatedElement::View getSuperelement() const;
00253 
00254 
00255     // ----- Object interface -----------------------------------------------
00256 
00257     public:
00258         /**
00259         * {@inheritDoc}
00260         */
00261         virtual bool equals(Object::View that) const;
00262 
00263         /**
00264         * {@inheritDoc}
00265         */
00266         virtual size32_t hashCode() const;
00267 
00268 
00269     // ----- static helpers -------------------------------------------------
00270 
00271     public:
00272         /**
00273         * Return the class name of the supplied Object.
00274         *
00275         * @param v  the object instance for which to obtain the class name
00276         *
00277         * @return the class name of the supplied Object
00278         */
00279         static String::View getClassName(Object::View v);
00280 
00281         /**
00282         * Returns the simple name of the underlying class of the
00283         * supplied Object as given in the code.
00284         *
00285         * If a simple name cannot be determined, the full name from
00286         * getClassName() will be returned.
00287         *
00288         * @param v  the object instance for which to obtain the name
00289         *
00290         * @return the simple name of the underlying class
00291         *
00292         * @since 12.2.1.3
00293         */
00294         static String::View getSimpleClassName(Object::View v);
00295 
00296         /**
00297          * Returns the std::type_info for the supplied Object.
00298          *
00299          * @param v  the object instance for which to obtain the type info
00300          *
00301          * @return the std::type_info for the supplied Object
00302          *
00303          * @since 12.2.1
00304          */
00305         static const std::type_info& getTypeInfo(Object::View v);
00306 
00307         /**
00308         * Return the type name of the supplied type id.
00309         *
00310         * @param info  the type id for which to obtain the type name
00311         *
00312         * @return the type name of the supplied type
00313         */
00314         static String::View getTypeName(const std::type_info& info);
00315 
00316         /**
00317         * Returns the simple name of the underlying class of the
00318         * supplied type as given in the code.
00319         *
00320         * If a simple name cannot be determined, the full name from
00321         * getTypeInfo() will be returned.
00322         *
00323         * @param info  the type id for which to obtain the name
00324         *
00325         * @return the simple name of the underlying class
00326         *
00327         * @since 12.2.1.3
00328         */
00329         static String::View getSimpleTypeName(const std::type_info& info);
00330 
00331         /**
00332         * Compare two Objects for type equality.
00333         *
00334         * @param v1  the first Object
00335         * @param v2  the second Object
00336         *
00337         * @return  <tt>true</tt> iff v1 and v2 are the same type
00338         *
00339         * @since 12.2.1
00340         */
00341         static bool typeEquals(Object::View v1, Object::View v2);
00342 
00343 
00344     // ----- data members ---------------------------------------------------
00345 
00346     private:
00347         /**
00348         * The class name.
00349         */
00350         FinalView<String> f_vsName;
00351 
00352         /**
00353         * Reference to a Map of method names to a List of Method objects.
00354         */
00355         MemberHandle<Object> m_hMapMethods;
00356     };
00357 
00358 COH_CLOSE_NAMESPACE2
00359 
00360 #endif // COH_CLASS_HPP
Copyright © 2000, 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.