File indexing completed on 2024-05-12 16:28:58

0001 /* POLE - Portable C++ library to access OLE Storage
0002    Copyright (C) 2002-2005 Ariya Hidayat <ariya@kde.org>
0003 
0004    Redistribution and use in source and binary forms, with or without
0005    modification, are permitted provided that the following conditions
0006    are met:
0007    * Redistributions of source code must retain the above copyright notice,
0008      this list of conditions and the following disclaimer.
0009    * Redistributions in binary form must reproduce the above copyright notice,
0010      this list of conditions and the following disclaimer in the documentation
0011      and/or other materials provided with the distribution.
0012    * Neither the name of the authors nor the names of its contributors may be
0013      used to endorse or promote products derived from this software without
0014      specific prior written permission.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
0026    THE POSSIBILITY OF SUCH DAMAGE.
0027 */
0028 
0029 #ifndef POLE_H
0030 #define POLE_H
0031 
0032 #include <string>
0033 #include <list>
0034 
0035 namespace POLE
0036 {
0037 
0038 class StorageIO;
0039 class Stream;
0040 class StreamIO;
0041 
0042 class Storage
0043 {
0044     friend class Stream;
0045     friend class StreamOut;
0046 
0047 public:
0048 
0049     // for Storage::result()
0050     enum { Ok, OpenFailed, NotOLE, BadOLE, UnknownError };
0051 
0052     /**
0053      * Constructs a storage with name filename.
0054      **/
0055     explicit Storage(const char* filename);
0056 
0057     /**
0058      * Destroys the storage.
0059      **/
0060     ~Storage();
0061 
0062     /**
0063      * Opens the storage. Returns true if no error occurs.
0064      **/
0065     bool open();
0066 
0067     /**
0068      * Closes the storage.
0069      **/
0070     void close();
0071 
0072     /**
0073      * Returns the error code of last operation.
0074      **/
0075     int result();
0076 
0077     /**
0078      * Finds all stream and directories in given path.
0079      **/
0080     std::list<std::string> entries(const std::string& path = "/");
0081 
0082     /**
0083      * Returns true if specified entry name is a directory.
0084      */
0085     bool isDirectory(const std::string& name);
0086 
0087 private:
0088     StorageIO* io;
0089 
0090     // no copy or assign
0091     Storage(const Storage&);
0092     Storage& operator=(const Storage&);
0093 
0094 };
0095 
0096 class Stream
0097 {
0098     friend class Storage;
0099     friend class StorageIO;
0100 
0101 public:
0102 
0103     /**
0104      * Creates a new stream.
0105      */
0106     // name must be absolute, e.g "/Workbook"
0107     Stream(Storage* storage, const std::string& name);
0108 
0109     /**
0110      * Destroys the stream.
0111      */
0112     ~Stream();
0113 
0114     /**
0115      * Returns the full stream name.
0116      */
0117     std::string fullName();
0118 
0119     /**
0120      * Returns the stream size.
0121      **/
0122     unsigned long size();
0123 
0124     /**
0125      * Returns the current read/write position.
0126      **/
0127     unsigned long tell();
0128 
0129     /**
0130      * Sets the read/write position.
0131      **/
0132     void seek(unsigned long pos);
0133 
0134     /**
0135      * Reads a byte.
0136      **/
0137     int getch();
0138 
0139     /**
0140      * Reads a block of data.
0141      **/
0142     unsigned long read(unsigned char* data, unsigned long maxlen);
0143 
0144     /**
0145      * Returns true if the read/write position is past the file.
0146      **/
0147     bool eof();
0148 
0149     /**
0150      * Returns true whenever error occurs.
0151      **/
0152     bool fail();
0153 
0154 private:
0155     StreamIO* io;
0156 
0157     // no copy or assign
0158     Stream(const Stream&);
0159     Stream& operator=(const Stream&);
0160 };
0161 
0162 }
0163 
0164 #endif // POLE_H