00001 /* 00002 * Copyright (c) 2005 Palmsource, Inc. 00003 * 00004 * This software is licensed as described in the file LICENSE, which 00005 * you should have received as part of this distribution. The terms 00006 * are also available at http://www.openbinder.org/license.html. 00007 * 00008 * This software consists of voluntary contributions made by many 00009 * individuals. For the exact contribution history, see the revision 00010 * history and logs, available at http://www.openbinder.org 00011 */ 00012 00013 #ifndef _B_XML2_DATA_SOURCE_H 00014 #define _B_XML2_DATA_SOURCE_H 00015 00016 #include <support/IByteStream.h> 00017 #include <support/SupportDefs.h> 00018 #include <stdio.h> 00019 00020 #if _SUPPORTS_NAMESPACE 00021 namespace palmos { 00022 namespace xml { 00023 using namespace support; 00024 #endif 00025 00026 // BXMLDataSource 00027 // ===================================================================== 00028 // Allows you to get some data to parse with minimal copying 00029 class BXMLDataSource 00030 { 00031 public: 00032 // GetNextBuffer is the same idea as DataIO, except it doesn't require 00033 // a data copy. It will be provided with a buffer in *data, so if you 00034 // have to copy data, then copy into that, but if you have your own 00035 // buffer, then just replace *data with your pointer. 00036 // You should return how much data there is in size, and 00037 // if this is the last iteration, then return a non-zero value in done. 00038 virtual status_t GetNextBuffer(size_t * size, uint8_t ** data, int * done) = 0; 00039 virtual ~BXMLDataSource(); 00040 }; 00041 00042 00043 00044 // BXMLIByteInputSource 00045 // ===================================================================== 00046 // Subclass of BBXMLDataSource that uses an IByteInput to get the data 00047 class BXMLIByteInputSource : public BXMLDataSource 00048 { 00049 public: 00050 BXMLIByteInputSource(const sptr<IByteInput>& data); 00051 virtual ~BXMLIByteInputSource(); 00052 virtual status_t GetNextBuffer(size_t * size, uint8_t ** data, int * done); 00053 00054 private: 00055 00056 sptr<IByteInput> _data; 00057 }; 00058 00059 00060 00061 // BXMLBufferSource 00062 // ===================================================================== 00063 // Subclass of BBXMLDataSource that uses a buffer you give it to get the data 00064 class BXMLBufferSource : public BXMLDataSource 00065 { 00066 public: 00067 // If len < 0, it is null terminated, so do strlen 00068 BXMLBufferSource(const char * buffer, int32_t len = -1); 00069 virtual ~BXMLBufferSource(); 00070 virtual status_t GetNextBuffer(size_t * size, uint8_t ** data, int * done); 00071 00072 private: 00073 // Illegal 00074 BXMLBufferSource(); 00075 BXMLBufferSource(const BXMLBufferSource & copy); 00076 const char * _data; 00077 int32_t _length; 00078 }; 00079 00080 00081 // BXMLfstreamSource 00082 // ===================================================================== 00083 // Subclass of BBXMLDataSource that uses a buffer you give it to get the data 00084 class BXMLfstreamSource : public BXMLDataSource 00085 { 00086 public: 00087 // If len < 0, it is null terminated, so do strlen 00088 BXMLfstreamSource(FILE *file); 00089 virtual ~BXMLfstreamSource(); 00090 virtual status_t GetNextBuffer(size_t * size, uint8_t ** data, int * done); 00091 00092 private: 00093 // Illegal 00094 BXMLfstreamSource(); 00095 BXMLfstreamSource(const BXMLBufferSource & copy); 00096 FILE *m_file; 00097 }; 00098 00099 00100 00101 #if _SUPPORTS_NAMESPACE 00102 }; // namespace xml 00103 }; // namespace palmos 00104 #endif 00105 00106 #endif // _B_XML2_DATA_SOURCE_H