#include <coherence/lang/Primitive.hpp>
Inherits Object, and Comparable.
Public Types | |||||||
typedef spec::Handle | Handle | ||||||
Primitive<T> Handle definition. | |||||||
typedef spec::View | View | ||||||
Primitive<T> View definition. | |||||||
typedef spec::Holder | Holder | ||||||
Primitive<T> Holder definition. | |||||||
typedef T | BoxedType | ||||||
The boxed primitive type. | |||||||
Public Member Functions | |||||||
virtual T | getValue () const | ||||||
Return the primitive value. | |||||||
operator T () const | |||||||
Return the primitive value. | |||||||
virtual int32_t | compareTo (Object::View v) const | ||||||
Compare this object with the specified object for order. Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.
It is strongly recommended, but not strictly required, that
| |||||||
virtual bool | equals (Object::View v) const | ||||||
Return true iff the specified Object is "equal" to this Object. This method implements an equivalence relation on Objects:
The default implementation is a reference equality comparison.
| |||||||
virtual size32_t | hashCode () const | ||||||
Return a hash code value for the Object. This method is supported for the benefit of hash-based containers.
The general contract of
The default implementation is identity based.
| |||||||
virtual bool | isImmutable () const | ||||||
| |||||||
virtual TypedHandle < const String > | toString () const | ||||||
Output a human-readable description of this Object to the given stream. Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override. coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.
Object::View vKey = ... Object::View vValue = ... std::cout << vKey << " = " << vValue << std::endl; String::View vs = COH_TO_STRING(vKey << " = " << vValue); The COH_TO_STRING macro is also the most common way to implement the toString method. For example:
virtual TypedHandle<const String> Person::toString() const { return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN); }
| |||||||
Static Public Member Functions | |||||||
static T | parse (String::View vs, size_t nPrecision=0) | ||||||
Return the primitive representation of a String. | |||||||
Protected Member Functions | |||||||
Primitive (const Primitive< T > &that) | |||||||
Copy constructor. | |||||||
Protected Attributes | |||||||
T | m_value | ||||||
The wrapped primitive value. |
virtual T getValue | ( | ) | const [virtual] |
Return the primitive value.
operator T | ( | ) | const |
Return the primitive value.
static T parse | ( | String::View | vs, | |
size_t | nPrecision = 0 | |||
) | [static] |
Return the primitive representation of a String.
vs | the String to covert to a primitive type | |
nPrecision | the (optional) precision, if applicable, of the primitive type |
IllegalArgumentException | if the supplied String is not convertible to the primitive type. NULL is considered an illegal argument except for the bool type, where it results in a bool(false). |