Oracle Coherence for C++ API
Release 3.7.1.0
E22845-01
00001 /* 00002 * PofBufferReader.hpp 00003 * 00004 * Copyright (c) 2000, 2011, 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_POF_BUFFER_READER_HPP 00017 #define COH_POF_BUFFER_READER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/ReadBuffer.hpp" 00022 #include "coherence/io/pof/PofContext.hpp" 00023 #include "coherence/io/pof/PofHelper.hpp" 00024 #include "coherence/io/pof/PofReader.hpp" 00025 #include "coherence/io/pof/RawDate.hpp" 00026 #include "coherence/io/pof/RawDateTime.hpp" 00027 #include "coherence/io/pof/RawDayTimeInterval.hpp" 00028 #include "coherence/io/pof/RawTime.hpp" 00029 #include "coherence/io/pof/RawTimeInterval.hpp" 00030 #include "coherence/io/pof/RawYearMonthInterval.hpp" 00031 #include "coherence/util/Binary.hpp" 00032 #include "coherence/util/Collection.hpp" 00033 #include "coherence/util/LongArray.hpp" 00034 #include "coherence/util/Map.hpp" 00035 00036 COH_OPEN_NAMESPACE3(coherence,io,pof) 00037 00038 using coherence::io::ReadBuffer; 00039 using coherence::util::Binary; 00040 using coherence::util::Collection; 00041 using coherence::util::LongArray; 00042 using coherence::util::Map; 00043 00044 00045 /** 00046 * PofReader implementation that reads POF-encoded data from a 00047 * ReadBuffer::BufferInput. 00048 * 00049 * @author jh 2008.04.09 00050 */ 00051 class COH_EXPORT PofBufferReader 00052 : public class_spec<PofBufferReader, 00053 extends<PofHelper>, 00054 implements<PofReader> > 00055 { 00056 friend class factory<PofBufferReader>; 00057 friend class IdentityHolder; 00058 00059 // ----- constructors --------------------------------------------------- 00060 00061 protected: 00062 /** 00063 * Construct a new PofBufferReader that will read a POF stream from 00064 * the passed BufferInput object. 00065 * 00066 * @param hIn a BufferInput object 00067 * @param vCtx the PofContext 00068 * 00069 * @return the new PofBufferReader 00070 */ 00071 PofBufferReader(ReadBuffer::BufferInput::Handle hIn, 00072 PofContext::View vCtx); 00073 00074 00075 // ----- PofReader interface -------------------------------------------- 00076 00077 public: 00078 /** 00079 * {@inheritDoc} 00080 */ 00081 virtual bool readBoolean(int32_t iProp); 00082 00083 /** 00084 * {@inheritDoc} 00085 */ 00086 virtual octet_t readOctet(int32_t iProp); 00087 00088 /** 00089 * {@inheritDoc} 00090 */ 00091 virtual char16_t readChar16(int32_t iProp); 00092 00093 /** 00094 * {@inheritDoc} 00095 */ 00096 virtual int16_t readInt16(int32_t iProp); 00097 00098 /** 00099 * {@inheritDoc} 00100 */ 00101 virtual int32_t readInt32(int32_t iProp); 00102 00103 /** 00104 * {@inheritDoc} 00105 */ 00106 virtual int64_t readInt64(int32_t iProp); 00107 00108 /** 00109 * {@inheritDoc} 00110 */ 00111 virtual float32_t readFloat32(int32_t iProp); 00112 00113 /** 00114 * {@inheritDoc} 00115 */ 00116 virtual float64_t readFloat64(int32_t iProp); 00117 00118 /** 00119 * {@inheritDoc} 00120 */ 00121 virtual Array<bool>::Handle readBooleanArray(int32_t iProp); 00122 00123 /** 00124 * {@inheritDoc} 00125 */ 00126 virtual Array<octet_t>::Handle readOctetArray(int32_t iProp); 00127 00128 /** 00129 * {@inheritDoc} 00130 */ 00131 virtual Array<char16_t>::Handle readChar16Array(int32_t iProp); 00132 00133 /** 00134 * {@inheritDoc} 00135 */ 00136 virtual Array<int16_t>::Handle readInt16Array(int32_t iProp); 00137 00138 /** 00139 * {@inheritDoc} 00140 */ 00141 virtual Array<int32_t>::Handle readInt32Array(int32_t iProp); 00142 00143 /** 00144 * {@inheritDoc} 00145 */ 00146 virtual Array<int64_t>::Handle readInt64Array(int32_t iProp); 00147 00148 /** 00149 * {@inheritDoc} 00150 */ 00151 virtual Array<float32_t>::Handle readFloat32Array(int32_t iProp); 00152 00153 /** 00154 * {@inheritDoc} 00155 */ 00156 virtual Array<float64_t>::Handle readFloat64Array(int32_t iProp); 00157 00158 /** 00159 * {@inheritDoc} 00160 */ 00161 virtual Binary::View readBinary(int32_t iProp); 00162 00163 /** 00164 * {@inheritDoc} 00165 */ 00166 virtual String::View readString(int32_t iProp); 00167 00168 /** 00169 * {@inheritDoc} 00170 */ 00171 virtual RawDate::View readRawDate(int32_t iProp); 00172 00173 /** 00174 * {@inheritDoc} 00175 */ 00176 using PofHelper::readRawDate; 00177 00178 /** 00179 * {@inheritDoc} 00180 */ 00181 virtual RawTime::View readRawTime(int32_t iProp); 00182 00183 /** 00184 * {@inheritDoc} 00185 */ 00186 using PofHelper::readRawTime; 00187 00188 /** 00189 * {@inheritDoc} 00190 */ 00191 virtual RawDateTime::View readRawDateTime(int32_t iProp); 00192 00193 /** 00194 * {@inheritDoc} 00195 */ 00196 virtual RawYearMonthInterval::View readRawYearMonthInterval( 00197 int32_t iProp); 00198 00199 /** 00200 * {@inheritDoc} 00201 */ 00202 virtual RawTimeInterval::View readRawTimeInterval(int32_t iProp); 00203 00204 /** 00205 * {@inheritDoc} 00206 */ 00207 virtual RawDayTimeInterval::View readRawDayTimeInterval(int32_t iProp); 00208 00209 /** 00210 * {@inheritDoc} 00211 */ 00212 virtual Object::Holder readObject(int32_t iProp); 00213 00214 /** 00215 * {@inheritDoc} 00216 */ 00217 virtual ObjectArray::Handle readObjectArray(int32_t iProp); 00218 00219 /** 00220 * {@inheritDoc} 00221 */ 00222 virtual LongArray::View readLongArray(int32_t iProp, 00223 LongArray::Handle hla = NULL); 00224 00225 /** 00226 * {@inheritDoc} 00227 */ 00228 virtual Collection::View readCollection(int32_t iProp, 00229 Collection::Handle hCol = NULL); 00230 00231 /** 00232 * {@inheritDoc} 00233 */ 00234 virtual Map::View readMap(int32_t iProp, Map::Handle hMap = NULL); 00235 00236 /** 00237 * {@inheritDoc} 00238 */ 00239 virtual PofContext::View getPofContext() const; 00240 00241 /** 00242 * {@inheritDoc} 00243 */ 00244 virtual void setPofContext(PofContext::View vCtx); 00245 00246 /** 00247 * {@inheritDoc} 00248 */ 00249 virtual int32_t getUserTypeId() const; 00250 00251 /** 00252 * {@inheritDoc} 00253 */ 00254 virtual int32_t getVersionId() const; 00255 00256 /** 00257 * {@inheritDoc} 00258 */ 00259 virtual void registerIdentity(Object::Holder oh); 00260 00261 /** 00262 * {@inheritDoc} 00263 */ 00264 virtual PofReader::Handle createNestedPofReader(int32_t iProp); 00265 00266 /** 00267 * {@inheritDoc} 00268 */ 00269 virtual Binary::View readRemainder(); 00270 00271 00272 // ----- internal methods ----------------------------------------------- 00273 00274 protected: 00275 /** 00276 * Advance through the POF stream until the specified property is 00277 * found. If the property is found, return true, otherwise return 00278 * false and advance to the first property that follows the specified 00279 * property. 00280 * 00281 * @param iProp the index of the property to advance to 00282 * 00283 * @return true if the property is found 00284 * 00285 * @throws IllegalStateException if the POF stream has already 00286 * advanced past the desired property 00287 * @throws IOException if an I/O error occurs 00288 */ 00289 virtual bool advanceTo(int32_t iProp); 00290 00291 /** 00292 * Register the completion of the parsing of a value. 00293 * 00294 * @param iProp the property index 00295 * 00296 * @throws IOException if an I/O error occurs 00297 */ 00298 virtual void complete(int32_t iProp); 00299 00300 /** 00301 * If this parser is contextually within a user type, obtain the 00302 * parser which created this parser in order to parse the user type. 00303 * 00304 * @return the parser for the context within which this parser is 00305 * operating 00306 */ 00307 virtual PofBufferReader::Handle getParentParser(); 00308 00309 /** 00310 * If this parser is contextually within a user type, obtain the 00311 * parser which created this parser in order to parse the user type. 00312 * 00313 * @return the parser for the context within which this parser is 00314 * operating 00315 */ 00316 virtual PofBufferReader::View getParentParser() const; 00317 00318 /** 00319 * Obtain the registry for identity-reference pairs, creating it if 00320 * necessary. 00321 * 00322 * @return the identity-reference registry, never NULL 00323 */ 00324 virtual LongArray::Handle ensureReferenceRegistry(); 00325 00326 /** 00327 * Register the passed value with the passed identity. 00328 * 00329 * @param nId the identity 00330 * @param ohValue the value to register 00331 * 00332 * @throws IOException if the specified identity is already 00333 * registered with a different object 00334 */ 00335 virtual void registerIdentity(int32_t nId, Object::Holder ohValue); 00336 00337 /** 00338 * Look up the specified identity and return the object to which it 00339 * refers. 00340 * 00341 * @param nId the identity 00342 * 00343 * @return the object registered under that identity 00344 * 00345 * @throws IOException if the requested identity is not registered 00346 */ 00347 virtual Object::Holder lookupIdentity(int32_t nId); 00348 00349 /** 00350 * Read a POF value as an Object. 00351 * 00352 * @param nType the type identifier of the value 00353 * 00354 * @return an Object value 00355 * 00356 * @throws IOException if an I/O error occurs 00357 */ 00358 virtual Object::Holder readAsObject(int32_t nType); 00359 00360 /** 00361 * Read a POF value in a uniform array/map as an Object. 00362 * 00363 * @param nType the type identifier of the value 00364 * 00365 * @return an Object value 00366 * 00367 * @throws IOException if an I/O error occurs 00368 * 00369 * @since Coherence 3.7.1 00370 */ 00371 virtual Object::Holder readAsUniformObject(int32_t nType); 00372 00373 /** 00374 * Read a POF value as an Object array. 00375 * 00376 * @param nType the type identifier of the value 00377 * 00378 * @return an Object array 00379 * 00380 * @throws IOException if an I/O error occurs 00381 */ 00382 virtual ObjectArray::Handle readAsObjectArray(int32_t nType); 00383 00384 00385 // ----- data members --------------------------------------------------- 00386 00387 protected: 00388 /** 00389 * The BufferInput containing the POF stream. 00390 */ 00391 MemberHandle<ReadBuffer::BufferInput> m_hIn; 00392 00393 /** 00394 * The PofContext to use to realize user data types as objects. 00395 */ 00396 MemberView<PofContext> m_vCtx; 00397 00398 /** 00399 * Lazily-constructed mapping of identities to references. 00400 */ 00401 MemberHandle<LongArray> m_hlaRefs; 00402 }; 00403 00404 COH_CLOSE_NAMESPACE3 00405 00406 #endif // COH_POF_BUFFER_READER_HPP