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