Fix dttypes for BSD systems
[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 #if defined(linux) || defined(CSRG_BASED)
45 #include <streambuf>
46 using namespace std;
47 #else
48 class streambuf;
49 #endif
50
51 #ifdef SP_NAMESPACE
52 namespace SP_NAMESPACE {
53 #endif
54
55 class SP_API Decoder {
56 public:
57   Decoder(unsigned minBytesPerChar = 1);
58   virtual ~Decoder();
59   virtual size_t decode(Char *, const char *, size_t, const char **) = 0;
60   virtual Boolean convertOffset(unsigned long &offset) const;
61   // Decoder assumes that for every decoded Char there must be at least
62   // minBytesPerChar bytes
63   unsigned minBytesPerChar() const;
64 protected:
65   unsigned minBytesPerChar_;
66 };
67
68
69 class SP_API Encoder {
70 public:
71   class SP_API Handler {
72   public:
73     virtual void handleUnencodable(Char, streambuf *) = 0;
74   };
75   Encoder();
76   virtual ~Encoder();
77   virtual void output(const Char *, size_t, streambuf *) = 0;
78   // This outputs a byte order mark with Unicode.
79   virtual void startFile(streambuf *);
80   virtual void output(Char *, size_t, streambuf *);
81   void setUnencodableHandler(Handler *);
82 protected:
83   void handleUnencodable(Char, streambuf *);
84 private:
85   Handler *unencodableHandler_;
86 };
87
88 class SP_API InputCodingSystem {
89 public:
90   virtual ~InputCodingSystem();
91   virtual Decoder *makeDecoder() const = 0;
92   StringC convertIn(const char *) const;
93   virtual Boolean isIdentity() const;
94 };
95
96 class SP_API OutputCodingSystem {
97 public:
98   virtual ~OutputCodingSystem();
99   virtual Encoder *makeEncoder() const = 0;
100   virtual unsigned fixedBytesPerChar() const;
101   String<char> convertOut(const StringC &) const;
102 };
103
104 class SP_API CodingSystem : public InputCodingSystem, public OutputCodingSystem {
105 };
106
107 inline
108 unsigned Decoder::minBytesPerChar() const
109 {
110   return minBytesPerChar_;
111 }
112
113 inline
114 void Encoder::handleUnencodable(Char c, streambuf *sbufp)
115 {
116   if (unencodableHandler_)
117     unencodableHandler_->handleUnencodable(c, sbufp);
118 }
119
120 inline
121 void Encoder::setUnencodableHandler(Handler *handler)
122 {
123   unencodableHandler_ = handler;
124 }
125
126 #ifdef SP_NAMESPACE
127 }
128 #endif
129
130 #endif /* not CodingSystem_INCLUDED */