coherence/lang/Class.hpp

00001 /*
00002 * Class.hpp
00003 *
00004 * Copyright 2001-2008 by Oracle. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_CLASS_HPP
00017 #define COH_CLASS_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/abstract_spec.hpp"
00022 #include "coherence/lang/MemberView.hpp"
00023 #include "coherence/lang/Object.hpp"
00024 #include "coherence/lang/ObjectArray.hpp"
00025 
00026 #include <ostream>
00027 #include <typeinfo>
00028 
00029 COH_OPEN_NAMESPACE2(coherence,lang)
00030 
00031 
00032 /**
00033 * A Class represents a managed object implementation.
00034 *
00035 * Not all managed classes may have a corresponding Class representation.
00036 * Classes are refered to via their demangled RTTI name, for example
00037 * coherence::lang::Object.
00038 *
00039 * Classes can be loaded by name via a ClassLoader.
00040 *
00041 * @see ClassLoader
00042 *
00043 * @author mf  2008.04.03
00044 */
00045 class COH_EXPORT Class
00046     : public abstract_spec<Class>
00047     {
00048     // ----- constructors ---------------------------------------------------
00049 
00050     protected:
00051         /**
00052         * Construct a class based on a C++ type_info.
00053         *
00054         * @param info the type_info for the class represented by this Class.
00055         */
00056         Class(const std::type_info& info);
00057 
00058 
00059     // ----- Class interface ------------------------------------------------
00060 
00061     public:
00062         /**
00063         * Return the name of the class.
00064         *
00065         * @return the class name
00066         */
00067         String::View getName() const;
00068 
00069         /**
00070         * Create a new instance of the corresponding type.
00071         *
00072         * @param vaParam the object's initialization parameters
00073         *
00074         * @return a new instance of the corresponding type
00075         */
00076         virtual Object::Handle newInstance(ObjectArray::View vaParam = NULL) const = 0;
00077 
00078         /**
00079         * Return the typeinfo for the corresponding type.
00080         *
00081         * @return the typeinfo for the corresponding type
00082         */
00083         virtual const std::type_info& getTypeInfo() const = 0;
00084 
00085         /**
00086         * Return the shallow size for an instance of the class represented
00087         * by this Class.
00088         *
00089         * @return the shallow size of an instance of the represented class.
00090         */
00091         virtual size32_t getSize() const = 0;
00092 
00093 
00094     // ----- Object interface -----------------------------------------------
00095 
00096     public:
00097         /**
00098         * {@inheritDoc}
00099         */
00100         virtual bool equals(Object::View that) const;
00101 
00102         /**
00103         * {@inheritDoc}
00104         */
00105         virtual size32_t hashCode() const;
00106 
00107 
00108     // ----- static helpers -------------------------------------------------
00109 
00110     public:
00111         /**
00112         * Return the class name of the supplied Object.
00113         *
00114         * @param v  the object instance for which to obtain the class name
00115         *
00116         * @return the class name of the supplied Object
00117         */
00118         static String::View getClassName(Object::View v);
00119 
00120         /**
00121         * Return the type name of the supplied Object.
00122         *
00123         * @param info  the type id for which to obtain the type name
00124         *
00125         * @return the type name of the supplied type
00126         */
00127         static String::View getTypeName(const std::type_info& info);
00128 
00129 
00130     // ----- data members ---------------------------------------------------
00131 
00132     private:
00133         /**
00134         * The class name.
00135         */
00136         const String::View m_vsName;
00137     };
00138 
00139 COH_CLOSE_NAMESPACE2
00140 
00141 #endif // COH_CLASS_HPP
Copyright (c) 2000-2008 Oracle. All rights reserved.