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.
5 #ifndef Location_INCLUDED
6 #define Location_INCLUDED 1
22 namespace SP_NAMESPACE {
27 class InputSourceOrigin;
35 class SP_API Origin : public Resource {
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;
50 class SP_API 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_;
67 ConstPtr<Origin> origin_;
71 class SP_API ExternalInfo {
74 virtual ~ExternalInfo();
77 class SP_API 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);
92 RefEndType refEndType_;
96 struct SP_API InputSourceOriginNamedCharRef {
97 InputSourceOriginNamedCharRef() { }
98 ~InputSourceOriginNamedCharRef() { }
99 Index replacementIndex;
100 size_t origNameOffset;
102 NamedCharRef::RefEndType refEndType;
105 class SP_API InputSourceOrigin : public Origin {
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;
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
129 // a delimiter specified in bracketed text
131 class SP_API BracketOrigin : public Origin {
133 enum Position { open, close };
134 BracketOrigin(const Location &, Position);
135 const Location &parent() const;
136 Boolean inBracketedTextOpenDelim() const;
137 Boolean inBracketedTextCloseDelim() const;
143 class SP_API ReplacementOrigin : public Origin {
145 ReplacementOrigin(const Location &, Char origChar);
146 const Location &parent() const;
147 Boolean origChars(const Char *&) const;
153 class SP_API MultiReplacementOrigin : public Origin {
155 MultiReplacementOrigin(const Location &, StringC &origChars);
156 const Location &parent() const;
157 Boolean origChars(const Char *&) const;
164 Index NamedCharRef::refStartIndex() const
166 return refStartIndex_;
170 NamedCharRef::RefEndType NamedCharRef::refEndType() const
176 const StringC &NamedCharRef::origName() const
182 const ExternalInfo *InputSourceOrigin::externalInfo() const
184 return externalInfo_.pointer();
191 #endif /* not Location_INCLUDED */