Linux has the same value for ENOTSUP as another var, therefore protect one
[oweals/cde.git] / cde / programs / nsgmls / CodingSystem.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: CodingSystem.h /main/1 1996/07/29 16:48:04 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef CodingSystem_INCLUDED
28 #define CodingSystem_INCLUDED 1
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 #ifndef SP_API
35 #define SP_API
36 #endif
37
38 #include "types.h"
39 #include "Boolean.h"
40 #include "StringC.h"
41
42 #include <stddef.h>
43
44 class streambuf;
45
46 #ifdef SP_NAMESPACE
47 namespace SP_NAMESPACE {
48 #endif
49
50 class SP_API Decoder {
51 public:
52   Decoder(unsigned minBytesPerChar = 1);
53   virtual ~Decoder();
54   virtual size_t decode(Char *, const char *, size_t, const char **) = 0;
55   virtual Boolean convertOffset(unsigned long &offset) const;
56   // Decoder assumes that for every decoded Char there must be at least
57   // minBytesPerChar bytes
58   unsigned minBytesPerChar() const;
59 protected:
60   unsigned minBytesPerChar_;
61 };
62
63
64 class SP_API Encoder {
65 public:
66   class SP_API Handler {
67   public:
68     virtual void handleUnencodable(Char, streambuf *) = 0;
69   };
70   Encoder();
71   virtual ~Encoder();
72   virtual void output(const Char *, size_t, streambuf *) = 0;
73   // This outputs a byte order mark with Unicode.
74   virtual void startFile(streambuf *);
75   virtual void output(Char *, size_t, streambuf *);
76   void setUnencodableHandler(Handler *);
77 protected:
78   void handleUnencodable(Char, streambuf *);
79 private:
80   Handler *unencodableHandler_;
81 };
82
83 class SP_API InputCodingSystem {
84 public:
85   virtual ~InputCodingSystem();
86   virtual Decoder *makeDecoder() const = 0;
87   StringC convertIn(const char *) const;
88   virtual Boolean isIdentity() const;
89 };
90
91 class SP_API OutputCodingSystem {
92 public:
93   virtual ~OutputCodingSystem();
94   virtual Encoder *makeEncoder() const = 0;
95   virtual unsigned fixedBytesPerChar() const;
96   String<char> convertOut(const StringC &) const;
97 };
98
99 class SP_API CodingSystem : public InputCodingSystem, public OutputCodingSystem {
100 };
101
102 inline
103 unsigned Decoder::minBytesPerChar() const
104 {
105   return minBytesPerChar_;
106 }
107
108 inline
109 void Encoder::handleUnencodable(Char c, streambuf *sbufp)
110 {
111   if (unencodableHandler_)
112     unencodableHandler_->handleUnencodable(c, sbufp);
113 }
114
115 inline
116 void Encoder::setUnencodableHandler(Handler *handler)
117 {
118   unencodableHandler_ = handler;
119 }
120
121 #ifdef SP_NAMESPACE
122 }
123 #endif
124
125 #endif /* not CodingSystem_INCLUDED */