xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/include/Location.h (revision 0:68f95e015346)
1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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   virtual Boolean defLocation(Offset off, const Origin *&, Index &) const;
49   virtual const Markup *markup() const;
50   virtual const Entity *entity() const;
51   virtual const ExternalInfo *externalInfo() const;
52   virtual Offset startOffset(Index ind) const;
53   const StringC *entityName() const;
54 };
55 
56 class SP_API ProxyOrigin : public Origin {
57 public:
58   ProxyOrigin(const Origin *origin);
59   const EntityOrigin *asEntityOrigin() const;
60   const InputSourceOrigin *asInputSourceOrigin() const;
61   const Location &parent() const;
62   Index refLength() const;
63   Boolean origChars(const Char *&) const;
64   Boolean inBracketedTextOpenDelim() const;
65   Boolean inBracketedTextCloseDelim() const;
66   Boolean isNumericCharRef(const Markup *&markup) const;
67   Boolean isNamedCharRef(Index ind, NamedCharRef &ref) const;
68   const EntityDecl *entityDecl() const;
69   Boolean defLocation(Offset off, const Origin *&, Index &) const;
70   const Markup *markup() const;
71   const Entity *entity() const;
72   const ExternalInfo *externalInfo() const;
73   Offset startOffset(Index ind) const;
74 private:
75   const Origin *origin_;
76 };
77 
78 class SP_API Location {
79 public:
80   Location();
81   Location(Origin *, Index);
82   Location(ConstPtr<Origin>, Index);
83   void operator+=(Index i) { index_ += i; }
84   void operator-=(Index i) { index_ -= i; }
index()85   Index index() const { return index_; }
origin()86   const ConstPtr<Origin> &origin() const { return origin_; }
clear()87   void clear() { origin_.clear(); }
swap(Location & to)88   void swap(Location &to) {
89     origin_.swap(to.origin_);
90     Index tem = to.index_;
91     to.index_ = index_;
92     index_ = tem;
93   }
94 private:
95   ConstPtr<Origin> origin_;
96   Index index_;
97 };
98 
99 class SP_API ExternalInfo {
100   RTTI_CLASS
101 public:
102   virtual ~ExternalInfo();
103 };
104 
105 class SP_API NamedCharRef {
106 public:
107   enum RefEndType {
108     endOmitted,
109     endRE,
110     endRefc
111     };
112   NamedCharRef();
113   NamedCharRef(Index, RefEndType, const StringC &);
114   Index refStartIndex() const;
115   RefEndType refEndType() const;
116   const StringC &origName() const;
117   void set(Index, RefEndType, const Char *, size_t);
118 private:
119   Index refStartIndex_;
120   RefEndType refEndType_;
121   StringC origName_;
122 };
123 
124 struct SP_API InputSourceOriginNamedCharRef {
125   Index replacementIndex;
126   size_t origNameOffset;
127   Index refStartIndex;
128   NamedCharRef::RefEndType refEndType;
129 };
130 
131 class SP_API InputSourceOrigin : public Origin {
132 public:
133   virtual void noteCharRef(Index replacementIndex, const NamedCharRef &) = 0;
134   virtual void setExternalInfo(ExternalInfo *) = 0;
135   virtual InputSourceOrigin *copy() const = 0;
136   static InputSourceOrigin *make();
137   static InputSourceOrigin *make(const Location &refLocation);
138 };
139 
140 // a delimiter specified in bracketed text
141 
142 class SP_API BracketOrigin : public Origin {
143 public:
144   enum Position { open, close };
145   BracketOrigin(const Location &, Position);
146   const Location &parent() const;
147   Boolean inBracketedTextOpenDelim() const;
148   Boolean inBracketedTextCloseDelim() const;
149 private:
150   Position pos_;
151   Location loc_;
152 };
153 
154 class SP_API ReplacementOrigin : public Origin {
155 public:
156   ReplacementOrigin(const Location &, Char origChar);
157   const Location &parent() const;
158   Boolean origChars(const Char *&) const;
159 private:
160   Location loc_;
161   Char origChar_;
162 };
163 
164 class SP_API MultiReplacementOrigin : public Origin {
165 public:
166   MultiReplacementOrigin(const Location &, StringC &origChars);
167   const Location &parent() const;
168   Boolean origChars(const Char *&) const;
169 private:
170   Location loc_;
171   StringC origChars_;
172 };
173 
174 inline
refStartIndex()175 Index NamedCharRef::refStartIndex() const
176 {
177   return refStartIndex_;
178 }
179 
180 inline
refEndType()181 NamedCharRef::RefEndType NamedCharRef::refEndType() const
182 {
183   return refEndType_;
184 }
185 
186 inline
origName()187 const StringC &NamedCharRef::origName() const
188 {
189   return origName_;
190 }
191 
192 #ifdef SP_NAMESPACE
193 }
194 #endif
195 
196 #endif /* not Location_INCLUDED */
197