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