00001 /* 00002 * Binary.hpp 00003 * 00004 * Copyright (c) 2000, 2014, 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_BINARY_HPP 00017 #define COH_BINARY_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/AbstractOctetArrayReadBuffer.hpp" 00022 #include "coherence/io/ReadBuffer.hpp" 00023 #include "coherence/util/BinaryWriteBuffer.hpp" 00024 00025 COH_OPEN_NAMESPACE2(coherence,util) 00026 00027 using coherence::io::AbstractOctetArrayReadBuffer; 00028 using coherence::io::ReadBuffer; 00029 00030 00031 /** 00032 * A thread-safe immutable binary object. 00033 * 00034 * @author jh 2008.05.29 00035 */ 00036 class COH_EXPORT Binary 00037 : public cloneable_spec<Binary, 00038 extends<AbstractOctetArrayReadBuffer> > 00039 { 00040 friend class factory<Binary>; 00041 00042 // ----- constructors --------------------------------------------------- 00043 00044 private: 00045 /** 00046 * Default constructor for a Binary object. Supports deserialization. 00047 * 00048 * @since Coherence 3.7.1 00049 */ 00050 Binary(); 00051 00052 /** 00053 * Construct a Binary object from a portion of an octet Array. 00054 * 00055 * @param vab an Array of octets; must not be NULL 00056 * @param of the offset into the octet Array 00057 * @param cb the number of octets to extract or npos for 00058 * (vab->length - of) 00059 * 00060 * @throws IndexOutOfBoundsException if <code>of + cb</code> is 00061 * larger than <code>vab->length</code> 00062 * @throws NullPointerException if <code>vab</code> is 00063 * <code>NULL</code> 00064 */ 00065 Binary(Array<octet_t>::View vab, size32_t of = 0, size32_t cb = npos); 00066 00067 /** 00068 * Construct a Binary object from a BinaryWriteBuffer. 00069 * 00070 * @param vBuf a BinaryWriteBuffer to construct this Binary object from 00071 * 00072 * @since Coherence 3.7.1 00073 */ 00074 Binary(BinaryWriteBuffer::View vBuf); 00075 00076 /** 00077 * Copy constructor. 00078 */ 00079 Binary(const Binary& that); 00080 00081 00082 // ----- Binary interface ----------------------------------------------- 00083 00084 public: 00085 /** 00086 * Calculate the partition ID to which the specified Binary should be 00087 * naturally assigned. This calculation should not be applied to 00088 * Binary objects decorated with artificially assigned partitions. 00089 * 00090 * The resulting partition ID will be in the range [0..cPartitions). 00091 * 00092 * @param cPartitions the partition count 00093 * 00094 * @return the partition that the this Binary is naturally assigned to 00095 * 00096 * @since Coherence 3.7.1 00097 */ 00098 virtual int32_t calculateNaturalPartition(int32_t cPartitions) const; 00099 00100 00101 // ----- Object interface ----------------------------------------------- 00102 00103 public: 00104 /** 00105 * {@inheritDoc} 00106 */ 00107 virtual size32_t hashCode() const; 00108 00109 /** 00110 * {@inheritDoc} 00111 */ 00112 virtual bool equals(Object::View v) const; 00113 00114 /** 00115 * {@inheritDoc} 00116 */ 00117 virtual bool isImmutable() const; 00118 00119 /** 00120 * {@inheritDoc} 00121 */ 00122 virtual void toStream(std::ostream& out) const; 00123 00124 00125 // ----- internal methods ----------------------------------------------- 00126 00127 protected: 00128 /** 00129 * {@inheritDoc} 00130 */ 00131 virtual void updateLength(size32_t cb); 00132 00133 /** 00134 * {@inheritDoc} 00135 */ 00136 virtual ReadBuffer::View instantiateReadBuffer(size32_t of, 00137 size32_t cb) const; 00138 }; 00139 00140 COH_CLOSE_NAMESPACE2 00141 00142 #endif // COH_BINARY_HPP