00001 /* 00002 * Primitive.hpp 00003 * 00004 * Copyright (c) 2000, 2013, 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 #include <ostream> 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 * 00088 * @return the primitive representation of the string 00089 * 00090 * @throws IllegalArgumentException if the supplied String is not 00091 * convertible to the primitive type. NULL is considered an 00092 * illegal argument except for the bool type, where it 00093 * results in a bool(false). 00094 */ 00095 static T parse(String::View vs); 00096 00097 00098 // ----- Comparable interface ------------------------------------------- 00099 00100 public: 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual int32_t compareTo(Object::View v) const; 00105 00106 00107 // ----- Object interface ----------------------------------------------- 00108 00109 public: 00110 /** 00111 * {@inheritDoc} 00112 */ 00113 virtual bool equals(Object::View v) const; 00114 00115 /** 00116 * {@inheritDoc} 00117 */ 00118 virtual size32_t hashCode() const; 00119 00120 /** 00121 * @return true 00122 */ 00123 virtual bool isImmutable() const; 00124 00125 /** 00126 * @return true 00127 */ 00128 virtual void toStream(std::ostream& out) const; 00129 00130 00131 // ----- data members --------------------------------------------------- 00132 00133 protected: 00134 /** 00135 * The wrapped primitive value. 00136 */ 00137 T m_value; 00138 }; 00139 00140 COH_CLOSE_NAMESPACE2 00141 00142 #endif // COH_PRIMITIVE_HPP