Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / Group.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: Group.h /main/1 1996/07/29 16:52:34 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Group_INCLUDED
28 #define Group_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "Boolean.h"
34 #include "ContentToken.h"
35 #include "StringC.h"
36 #include "MessageArg.h"
37 #include "Owner.h"
38 #include "Syntax.h"
39 #include "Text.h"
40
41 #ifdef SP_NAMESPACE
42 namespace SP_NAMESPACE {
43 #endif
44
45 class GroupToken {
46 public:
47   GroupToken() { }
48   enum Type {
49     invalid,
50     nameToken,
51     name,
52     dataTagLiteral,             // data tag (padding) template
53     dataTagGroup,
54     elementToken,
55     modelGroup,
56     pcdata,
57     dataTagTemplateGroup
58     };
59   Type type;
60   StringC token;                // name nameToken; with substitution
61   Owner<ModelGroup> model;
62   Owner<ContentToken> contentToken; // elementToken pcdata dataTagGroup
63   Text text;
64   Vector<Text> textVector;
65 private:
66   GroupToken(const GroupToken &); // undefined
67   void operator=(const GroupToken &); // undefined
68 };
69
70 class AllowedGroupTokens {
71 public:
72   AllowedGroupTokens(GroupToken::Type,
73                      GroupToken::Type = GroupToken::invalid,
74                      GroupToken::Type = GroupToken::invalid,
75                      GroupToken::Type = GroupToken::invalid);
76   Boolean groupToken(GroupToken::Type) const;
77   // modelGroup, dataTagTemplateGroup
78   GroupToken::Type group() const;
79   GroupToken::Type nameStart() const;
80 private:
81   void allow(GroupToken::Type);
82   unsigned flags_;
83 };
84
85 struct GroupConnector {
86   enum Type {
87     andGC,
88     orGC,
89     seqGC,
90     grpcGC,
91     dtgcGC
92   };
93   Type type;
94 };
95
96 class AllowedGroupConnectors {
97 public:
98   AllowedGroupConnectors(GroupConnector::Type);
99   AllowedGroupConnectors(GroupConnector::Type, GroupConnector::Type);
100   AllowedGroupConnectors(GroupConnector::Type, GroupConnector::Type,
101                          GroupConnector::Type);
102   AllowedGroupConnectors(GroupConnector::Type, GroupConnector::Type,
103                          GroupConnector::Type, GroupConnector::Type);
104   Boolean groupConnector(GroupConnector::Type) const;
105 private:
106   void allow(GroupConnector::Type);
107   unsigned flags_;
108 };
109
110 class AllowedGroupTokensMessageArg : public MessageArg {
111 public:
112   AllowedGroupTokensMessageArg(const AllowedGroupTokens &allow,
113                                const ConstPtr<Syntax> &syntax);
114   MessageArg *copy() const;
115   void append(MessageBuilder &) const;
116 private:
117   AllowedGroupTokens allow_;
118   ConstPtr<Syntax> syntax_;
119 };
120
121 class AllowedGroupConnectorsMessageArg : public MessageArg {
122 public:
123   AllowedGroupConnectorsMessageArg(const AllowedGroupConnectors &allow,
124                                    const ConstPtr<Syntax> &syntax);
125   MessageArg *copy() const;
126   void append(MessageBuilder &) const;
127 private:
128   AllowedGroupConnectors allow_;
129   ConstPtr<Syntax> syntax_;
130 };
131
132 inline
133 Boolean AllowedGroupTokens::groupToken(GroupToken::Type i) const
134 {
135   return ((1 << i) & flags_) != 0;
136 }
137
138 inline
139 GroupToken::Type AllowedGroupTokens::group() const
140 {
141   if (groupToken(GroupToken::modelGroup))
142     return GroupToken::modelGroup;
143   else if (groupToken(GroupToken::dataTagTemplateGroup))
144     return GroupToken::dataTagTemplateGroup;
145   else
146     return GroupToken::invalid;
147 }
148
149 inline
150 GroupToken::Type AllowedGroupTokens::nameStart() const
151 {
152   if (groupToken(GroupToken::elementToken))
153     return GroupToken::elementToken;
154   else if (groupToken(GroupToken::nameToken))
155     return GroupToken::nameToken;
156   else if (groupToken(GroupToken::name))
157     return GroupToken::name;
158   else
159     return GroupToken::invalid;
160 }
161
162 inline
163 void AllowedGroupTokens::allow(GroupToken::Type t)
164 {
165   flags_ |= (1 << t);
166 }
167
168
169 inline
170 Boolean AllowedGroupConnectors::groupConnector(GroupConnector::Type c) const
171 {
172   return (flags_ & (1 << c)) != 0;
173 }
174
175 inline
176 void AllowedGroupConnectors::allow(GroupConnector::Type c)
177 {
178   flags_ |= (1 << c);
179 }
180
181
182 #ifdef SP_NAMESPACE
183 }
184 #endif
185
186 #endif /* not Group_INCLUDED */