dsdm: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / nsgmls / Location.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 libraries 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: Location.h /main/1 1996/07/29 16:56:22 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Location_INCLUDED
28 #define Location_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "Boolean.h"
35 #include "Ptr.h"
36 #include "Resource.h"
37 #include "Boolean.h"
38 #include "Vector.h"
39 #include "Owner.h"
40 #include "StringC.h"
41 #include "rtti.h"
42
43 #ifdef SP_NAMESPACE
44 namespace SP_NAMESPACE {
45 #endif
46
47 class ExternalInfo;
48 class EntityOrigin;
49 class InputSourceOrigin;
50 class Entity;
51 class EntityDecl;
52 class Location;
53 class Markup;
54 class Text;
55 class NamedCharRef;
56
57 class SP_API Origin : public Resource {
58 public:
59   virtual ~Origin();
60   virtual const EntityOrigin *asEntityOrigin() const;
61   virtual const InputSourceOrigin *asInputSourceOrigin() const;
62   virtual const Location &parent() const = 0;
63   virtual Index refLength() const;
64   virtual Boolean origChars(const Char *&) const;
65   virtual Boolean inBracketedTextOpenDelim() const;
66   virtual Boolean inBracketedTextCloseDelim() const;
67   virtual Boolean isNumericCharRef(const Markup *&markup) const;
68   virtual Boolean isNamedCharRef(Index ind, NamedCharRef &ref) const;
69   virtual const EntityDecl *entityDecl() const;
70 };
71
72 class SP_API Location {
73 public:
74   Location();
75   Location(Origin *, Index);
76   Location(ConstPtr<Origin>, Index);
77   void operator+=(Index i) { index_ += i; }
78   void operator-=(Index i) { index_ -= i; }
79   Index index() const { return index_; }
80   const ConstPtr<Origin> &origin() const { return origin_; }
81   void clear() { origin_.clear(); }
82   void swap(Location &to) {
83     origin_.swap(to.origin_);
84     Index tem = to.index_;
85     to.index_ = index_;
86     index_ = tem;
87   }
88 private:
89   ConstPtr<Origin> origin_;
90   Index index_;
91 };
92
93 class SP_API ExternalInfo {
94   RTTI_CLASS
95 public:
96   virtual ~ExternalInfo();
97 };
98
99 class SP_API NamedCharRef {
100 public:
101   enum RefEndType {
102     endOmitted,
103     endRE,
104     endRefc
105     };
106   NamedCharRef();
107   NamedCharRef(Index, RefEndType, const StringC &);
108   Index refStartIndex() const;
109   RefEndType refEndType() const;
110   const StringC &origName() const;
111   void set(Index, RefEndType, const Char *, size_t);
112 private:
113   Index refStartIndex_;
114   RefEndType refEndType_;
115   StringC origName_;
116 };
117
118 struct SP_API InputSourceOriginNamedCharRef {
119   InputSourceOriginNamedCharRef() { }
120   ~InputSourceOriginNamedCharRef() { }
121   Index replacementIndex;
122   size_t origNameOffset;
123   Index refStartIndex;
124   NamedCharRef::RefEndType refEndType;
125 };
126
127 class SP_API InputSourceOrigin : public Origin {
128 public:
129   InputSourceOrigin();
130   InputSourceOrigin(const Location &refLocation);
131   const Location &parent() const;
132   const ExternalInfo *externalInfo() const;
133   Offset startOffset(Index ind) const;
134   void noteCharRef(Index replacementIndex, const NamedCharRef &);
135   Boolean isNamedCharRef(Index ind, NamedCharRef &ref) const;
136   void setExternalInfo(ExternalInfo *);
137   virtual Boolean defLocation(Offset off, Location &) const;
138   virtual InputSourceOrigin *copy() const;
139   const InputSourceOrigin *asInputSourceOrigin() const;
140   virtual const StringC *entityName() const;
141 private:
142   InputSourceOrigin(const InputSourceOrigin &); // undefined
143   void operator=(const InputSourceOrigin &);    // undefined
144   size_t nPrecedingCharRefs(Index ind) const;
145   Vector<InputSourceOriginNamedCharRef> charRefs_;
146   StringC charRefOrigNames_;
147   Owner<ExternalInfo> externalInfo_; // 0 for internal entities
148   Location refLocation_;        // where referenced from
149 };
150
151 // a delimiter specified in bracketed text
152
153 class SP_API BracketOrigin : public Origin {
154 public:
155   enum Position { open, close };
156   BracketOrigin(const Location &, Position);
157   const Location &parent() const;
158   Boolean inBracketedTextOpenDelim() const;
159   Boolean inBracketedTextCloseDelim() const;
160 private:
161   Position pos_;
162   Location loc_;
163 };
164
165 class SP_API ReplacementOrigin : public Origin {
166 public:
167   ReplacementOrigin(const Location &, Char origChar);
168   const Location &parent() const;
169   Boolean origChars(const Char *&) const;
170 private:
171   Location loc_;
172   Char origChar_;
173 };
174
175 class SP_API MultiReplacementOrigin : public Origin {
176 public:
177   MultiReplacementOrigin(const Location &, StringC &origChars);
178   const Location &parent() const;
179   Boolean origChars(const Char *&) const;
180 private:
181   Location loc_;
182   StringC origChars_;
183 };
184
185 inline
186 Index NamedCharRef::refStartIndex() const
187 {
188   return refStartIndex_;
189 }
190
191 inline
192 NamedCharRef::RefEndType NamedCharRef::refEndType() const
193 {
194   return refEndType_;
195 }
196
197 inline
198 const StringC &NamedCharRef::origName() const
199 {
200   return origName_;
201 }
202
203 inline
204 const ExternalInfo *InputSourceOrigin::externalInfo() const
205 {
206   return externalInfo_.pointer();
207 }
208
209 #ifdef SP_NAMESPACE
210 }
211 #endif
212
213 #endif /* not Location_INCLUDED */