• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

ByteStream.h

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: ByteStream.h,v 1.11 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifndef _BYTESTREAM_H
00058 #define _BYTESTREAM_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065 
00102 
00103 
00104 #include "Arrays.h"
00105 #include <stdio.h>
00106 
00107 #ifdef HAVE_NAMESPACES
00108 namespace DJVU {
00109 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00110 }
00111 #endif
00112 #endif
00113 
00114 class GURL;
00115 class GUTF8String;
00116 class GNativeString;
00117 
00129 class ByteStream : public GPEnabled
00130 {
00131 public:
00132   class Stdio;
00133   class Static;
00134   class Memory;
00135   class Wrapper;
00136   enum codepage_type {RAW,AUTO,NATIVE,UTF8} cp;
00137 
00142 public:
00144   virtual ~ByteStream();
00156   virtual size_t read(void *buffer, size_t size);
00166   virtual size_t write(const void *buffer, size_t size);
00169   virtual long tell(void) const  = 0;
00192   virtual int seek(long offset, int whence = SEEK_SET, bool nothrow=false);
00197   virtual void flush(void);
00199 
00204 public:
00212   size_t readall(void *buffer, size_t size);
00219   size_t writall(const void *buffer, size_t size);
00228   size_t copy(ByteStream &bsfrom, size_t size=0);
00232   GP<ByteStream> duplicate(const size_t size=0) const;
00234   size_t format(const char *fmt, ... );
00236   int scanf(const char *fmt, ... );
00238   size_t writestring(const GUTF8String &s);
00240   size_t writestring(const GNativeString &s);
00243   void formatmessage( const char *fmt, ... );
00245   void writemessage( const char *message );
00247   void write8 (unsigned int card8);
00251   void write16(unsigned int card16);
00255   void write24(unsigned int card24);
00259   void write32(unsigned int card32);
00261   unsigned int read8 ();
00265   unsigned int read16();
00269   unsigned int read24();
00273   unsigned int read32();
00277   virtual int size(void) const;
00279   TArray<char> get_data(void);
00283   virtual size_t readat(void *buffer, size_t sz, int pos);
00285   virtual bool is_static(void) const { return false; }
00287 protected:
00288   ByteStream(void) : cp(AUTO) {};
00289 private:
00290   // Cancel C++ default stuff
00291   ByteStream(const ByteStream &);
00292   ByteStream & operator=(const ByteStream &);
00293 public:
00299   static GP<ByteStream> create(void);
00303   static GP<ByteStream> create(void const * const buffer, const size_t size);
00313   static GP<ByteStream> create(
00314     const GURL &url, char const * const mode);
00316   static GP<ByteStream> create( char const * const mode);
00317 
00322   static GP<ByteStream> create(
00323     const int fd, char const * const mode, const bool closeme);
00324 
00329   static GP<ByteStream> create(
00330     FILE * const f, char const * const mode, const bool closeme);
00337   static GP<ByteStream> create_static(
00338     void const * const buffer, const size_t size);
00339   
00341   static GP<ByteStream> get_stdin(char const * const mode=0);
00342   static GP<ByteStream> get_stdout(char const * const mode=0);  
00343   static GP<ByteStream> get_stderr(char const * const mode=0);
00344 
00346   static const char *EndOfFile;
00348   GNativeString getAsNative(void);
00350   GUTF8String getAsUTF8(void);
00351 };
00352 
00353 inline size_t
00354 ByteStream::readat(void *buffer, size_t sz, int pos)
00355 {
00356   size_t retval;
00357   long tpos=tell();
00358   seek(pos, SEEK_SET, true);
00359   retval=readall(buffer,sz);
00360   seek(tpos, SEEK_SET, true);
00361   return retval;
00362 }
00363 
00364 inline int
00365 ByteStream::size(void) const
00366 {
00367   ByteStream *bs=const_cast<ByteStream *>(this);
00368   int bsize=(-1);
00369   long pos=tell();
00370   if(bs->seek(0,SEEK_END,true))
00371   {
00372     bsize=(int)tell();
00373     (void)(bs->seek(pos,SEEK_SET,false));
00374   }
00375   return bsize;
00376 }
00377 
00381 class ByteStream::Wrapper : public ByteStream
00382 {
00383 protected:
00384   GP<ByteStream> gbs;
00385   ByteStream *bs;
00386   Wrapper(void) : bs(0) {}
00387   Wrapper(const GP<ByteStream> &xbs) : gbs(xbs), bs(xbs) {}
00388 public:
00389   ~Wrapper();
00390   ByteStream * operator & () const {return bs;}
00391   ByteStream * operator & () {return bs;}
00392   virtual size_t read(void *buffer, size_t size)
00393     { return bs->read(buffer,size); }
00394   virtual size_t write(const void *buffer, size_t size)
00395     { return bs->write(buffer,size); }
00396   virtual long tell(void) const
00397     { return bs->tell(); }
00398   virtual int seek(long offset, int whence = SEEK_SET, bool nothrow=false)
00399     { return bs->seek(offset,whence,nothrow); }
00400   virtual void flush(void)
00401     { bs->flush(); }
00402 };
00403 
00404 
00406 
00407 // ------------ THE END
00408 
00409 #ifdef HAVE_NAMESPACES
00410 }
00411 # ifndef NOT_USING_DJVU_NAMESPACE
00412 using namespace DJVU;
00413 # endif
00414 #endif
00415 #endif
00416 

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal