"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/include/CodingSystem.h" (5 Nov 2005, 2461 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "CodingSystem.h" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 1994 James Clark
    2 // See the file COPYING for copying permission.
    3 
    4 #ifndef CodingSystem_INCLUDED
    5 #define CodingSystem_INCLUDED 1
    6 
    7 #ifdef __GNUG__
    8 #pragma interface
    9 #endif
   10 
   11 #include "types.h"
   12 #include "Boolean.h"
   13 #include "StringC.h"
   14 #include "OutputByteStream.h"
   15 
   16 #include <stddef.h>
   17 
   18 
   19 #ifdef SP_NAMESPACE
   20 namespace SP_NAMESPACE {
   21 #endif
   22 
   23 class SP_API Decoder {
   24 public:
   25   Decoder(unsigned minBytesPerChar = 1);
   26   virtual ~Decoder();
   27   virtual size_t decode(Char *, const char *, size_t, const char **) = 0;
   28   virtual Boolean convertOffset(unsigned long &offset) const;
   29   // Decoder assumes that for every decoded Char there must be at least
   30   // minBytesPerChar bytes
   31   unsigned minBytesPerChar() const;
   32 protected:
   33   unsigned minBytesPerChar_;
   34 };
   35 
   36 
   37 class SP_API Encoder {
   38 public:
   39   class SP_API Handler {
   40   public:
   41     virtual ~Handler();
   42     virtual void handleUnencodable(Char, OutputByteStream *) = 0;
   43   };
   44   Encoder();
   45   virtual ~Encoder();
   46   virtual void output(const Char *, size_t, OutputByteStream *) = 0;
   47   // This outputs a byte order mark with Unicode.
   48   virtual void startFile(OutputByteStream *);
   49   virtual void output(Char *, size_t, OutputByteStream *);
   50   virtual void setUnencodableHandler(Handler *);
   51   virtual void handleUnencodable(Char, OutputByteStream *);
   52 };
   53 
   54 class SP_API RecoveringEncoder : public Encoder {
   55 public:
   56   RecoveringEncoder();
   57   void setUnencodableHandler(Handler *);
   58   void handleUnencodable(Char, OutputByteStream *);
   59 private:
   60   Handler *unencodableHandler_;
   61 };
   62 
   63 class SP_API InputCodingSystem {
   64 public:
   65   virtual ~InputCodingSystem();
   66   // one of these has to be overwritten
   67   virtual Decoder *makeDecoder() const { return makeDecoder(1); } 
   68   virtual Decoder *makeDecoder(Boolean lsbFirst) const { return makeDecoder(lsbFirst,1); }
   69   virtual Decoder *makeDecoder(Boolean lsbFirst, Boolean lswFirst) const { return makeDecoder(); }
   70   StringC convertIn(const char *) const;
   71   virtual Boolean isIdentity() const;
   72 };
   73 
   74 class SP_API OutputCodingSystem {
   75 public:
   76   virtual ~OutputCodingSystem();
   77   virtual Encoder *makeEncoder() const = 0;
   78   virtual unsigned fixedBytesPerChar() const;
   79   String<char> convertOut(const StringC &) const;
   80 };
   81 
   82 class SP_API CodingSystem : public InputCodingSystem, public OutputCodingSystem {
   83 public:
   84   inline ~CodingSystem() {}
   85 };
   86 
   87 inline
   88 unsigned Decoder::minBytesPerChar() const
   89 {
   90   return minBytesPerChar_;
   91 }
   92 
   93 #ifdef SP_NAMESPACE
   94 }
   95 #endif
   96 
   97 #endif /* not CodingSystem_INCLUDED */