00001 /* 00002 * Primitive.hpp 00003 * 00004 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 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_PRIMITIVE_HPP 00017 #define COH_PRIMITIVE_HPP 00018 00019 #include "coherence/lang/compatibility.hpp" 00020 00021 #include "coherence/lang/abstract_spec.hpp" 00022 #include "coherence/lang/Comparable.hpp" 00023 #include "coherence/lang/Object.hpp" 00024 #include "coherence/lang/String.hpp" 00025 00026 00027 00028 COH_OPEN_NAMESPACE2(coherence,lang) 00029 00030 00031 /** 00032 * Template class which converts primitive data types into immutable managed 00033 * objects. 00034 * 00035 * @author jh/mf 2007.07.05 00036 */ 00037 template<class T> 00038 class COH_EXPORT Primitive 00039 : public abstract_spec<Primitive<T>, 00040 extends<Object>, 00041 implements<Comparable> > 00042 { 00043 // ----- typedefs ------------------------------------------------------- 00044 00045 public: 00046 /** 00047 * The boxed primitive type. 00048 */ 00049 typedef T BoxedType; 00050 00051 00052 // ----- constructors --------------------------------------------------- 00053 00054 protected: 00055 /** 00056 * @internal 00057 */ 00058 Primitive(const T& value = 0); 00059 00060 /** 00061 * Copy constructor. 00062 */ 00063 Primitive(const Primitive<T>& that); 00064 00065 00066 // ----- Primitive interface -------------------------------------------- 00067 00068 public: 00069 /** 00070 * Return the primitive value. 00071 * 00072 * @return the primitive value 00073 */ 00074 virtual T getValue() const; 00075 00076 /** 00077 * Return the primitive value 00078 * 00079 * @return The primitive value 00080 */ 00081 operator T() const; 00082 00083 /** 00084 * Return the primitive representation of a String. 00085 * 00086 * @param vs the String to covert to a primitive type 00087 * @param nPrecision the (optional) precision, if applicable, of 00088 * the primitive type 00089 * 00090 * @return the primitive representation of the string 00091 * 00092 * @throws IllegalArgumentException if the supplied String is not 00093 * convertible to the primitive type. NULL is considered an 00094 * illegal argument except for the bool type, where it 00095 * results in a bool(false). 00096 */ 00097 static T parse(String::View vs, size_t nPrecision = 0); 00098 00099 00100 // ----- Comparable interface ------------------------------------------- 00101 00102 public: 00103 /** 00104 * {@inheritDoc} 00105 */ 00106 virtual int32_t compareTo(Object::View v) const; 00107 00108 00109 // ----- Object interface ----------------------------------------------- 00110 00111 public: 00112 /** 00113 * {@inheritDoc} 00114 */ 00115 virtual bool equals(Object::View v) const; 00116 00117 /** 00118 * {@inheritDoc} 00119 */ 00120 virtual size32_t hashCode() const; 00121 00122 /** 00123 * @return true 00124 */ 00125 virtual bool isImmutable() const; 00126 00127 /** 00128 * {@inheritDoc} 00129 */ 00130 virtual TypedHandle<const String> toString() const; 00131 00132 00133 // ----- data members --------------------------------------------------- 00134 00135 protected: 00136 /** 00137 * The wrapped primitive value. 00138 */ 00139 T m_value; 00140 }; 00141 00142 COH_CLOSE_NAMESPACE2 00143 00144 #endif // COH_PRIMITIVE_HPP