00001 /* 00002 * BinaryWriteBuffer.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_BINARY_WRITE_BUFFER_HPP 00017 #define COH_BINARY_WRITE_BUFFER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/OctetArrayWriteBuffer.hpp" 00022 00023 COH_OPEN_NAMESPACE2(coherence,util) 00024 00025 using coherence::io::OctetArrayWriteBuffer; 00026 00027 class Binary; 00028 00029 00030 /** 00031 * A WriteBuffer implementation whose primary purpose is to be used to create 00032 * Binary objects. 00033 * 00034 * @author phf 2011.03.11 00035 * 00036 * @since Coherence 3.7.1 00037 */ 00038 class COH_EXPORT BinaryWriteBuffer 00039 : public class_spec<BinaryWriteBuffer, 00040 extends<OctetArrayWriteBuffer> > 00041 { 00042 friend class factory<BinaryWriteBuffer>; 00043 00044 // ----- handle definitions --------------------------------------------- 00045 00046 public: 00047 /** 00048 * Binary View definition. 00049 */ 00050 typedef TypedHandle<const Binary> BinaryView; 00051 00052 00053 // ----- constructors --------------------------------------------------- 00054 00055 protected: 00056 /** 00057 * Construct a BinaryWriteBuffer with a certain initial capacity. 00058 * 00059 * @param cbCap initial capacity 00060 */ 00061 BinaryWriteBuffer(size32_t cbCap); 00062 00063 /** 00064 * Construct a BinaryWriteBuffer with a certain initial capacity and a 00065 * certain maximum capacity. 00066 * 00067 * @param cbCap initial capacity 00068 * @param cbMax maximum capacity 00069 * 00070 * @throws IllegalArgumentException if <tt>cbCap</tt> is greater 00071 * than <tt>cbMax</tt> 00072 */ 00073 BinaryWriteBuffer(size32_t cbCap, size32_t cbMax); 00074 00075 00076 // ----- WriteBuffer interface ------------------------------------------ 00077 00078 public: 00079 /** 00080 * {@inheritDoc} 00081 */ 00082 virtual BinaryView toBinary() const; 00083 00084 00085 // ----- internal ------------------------------------------------------- 00086 00087 protected: 00088 /** 00089 * Obtain the internal octet array that this WriteBuffer uses. 00090 * 00091 * Intended for use only by Binary. 00092 * 00093 * @return the actual octet array that this WriteBuffer uses 00094 */ 00095 virtual Array<octet_t>::View getInternalOctetArray() const; 00096 00097 /** 00098 * Validate the ranges for the passed bounds and make sure that the 00099 * underlying array is big enough to handle them. 00100 * 00101 * Note: This method prevents all modifications from occurring once the 00102 * BinaryWriteBuffer has supplied its octet array to a Binary object. 00103 * 00104 * @param of the offset that data is about to be written to 00105 * @param cb the length of the data that is about to be written 00106 */ 00107 virtual void checkBounds(size32_t of, size32_t cb); 00108 00109 00110 // ----- data members --------------------------------------------------- 00111 00112 private: 00113 /** 00114 * Indicator that no more modifications are permitted. 00115 */ 00116 bool mutable m_fReadOnly; 00117 00118 00119 // ----- friends -------------------------------------------------------- 00120 00121 friend class Binary; 00122 }; 00123 00124 COH_CLOSE_NAMESPACE2 00125 00126 #endif // COH_BINARY_WRITE_BUFFER_HPP