2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $XConsortium: FeatureSet.cc /main/5 1996/08/05 16:18:55 cde-hal $
27 #include "FeatureValue.h"
28 #include "StyleSheetExceptions.h"
31 unsigned int FeatureSet::f_print_indent_level = 0 ;
33 ostream &operator << (ostream &o, const FeatureSet &f)
38 FeatureSet::~FeatureSet()
40 clearAndDestroy(); // clean up memory
43 FeatureSet::FeatureSet()
47 FeatureSet::FeatureSet(const FeatureSet &orig_set)
50 CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*) &orig_set) ;
52 // make a copy of each item and add it to our list
54 append(new Feature(*next.key()));
59 FeatureSet::evaluate() const
61 // I do not yet understand how this evaluate is working well. - TK
63 fprintf(stderr, "(DEBUG) FeatureSet::evaluate() called.\n");
65 return evaluate(new FeatureSet);
69 FeatureSet::evaluate(FeatureSet *result_set) const
72 CC_TPtrSlistIterator<Feature> next(*(FeatureSet*)this);
74 // cause each feature to evaluate itself
80 value = next.key()->evaluate();
81 result_set->append(new Feature(next.key()->name(),
87 catch_noarg(badEvaluationException)
90 /* do nothing...we just ignore any that will not evaluate */
98 FeatureSet::FeatureSet(const FeatureSet &base,
99 const FeatureSet &mixin)
101 Feature dummy = Feature(gSymTab->intern("FAMILY"),0);
102 int contains_family = mixin.contains(&dummy);
104 // first duplicate the baseline
105 CC_TPtrSlistIterator<Feature> base_i(*(CC_TPtrSlist<Feature>*)&base) ;
107 // make a copy of each item and add it to our list
109 if (! (contains_family &&
110 base_i.key()->name() == gSymTab->intern("FAMILY")))
111 append(new Feature(*base_i.key()));
114 // now merge in mixin
116 CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)&mixin);
120 if (next.key()->name() == gSymTab->intern("FAMILY"))
121 append(new Feature(*next.key()));
123 Feature* mfeature = 0;
124 mfeature = find(next.key());
126 cout << "Merging: \n" << *next.key() << endl << "into:" << endl;
128 cout << *mfeature << endl;
130 cout << "(nil)" << endl;
133 mfeature->merge(*next.key()); // merge it if already exists
135 append(new Feature(*next.key())); // else add it if not there
141 FeatureSet::print(ostream &o) const
143 // cast to non-const to get iterator
144 CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)this);
146 for (int i = 0 ; i < f_print_indent_level; i++)
151 f_print_indent_level++;
155 for (int i = 0 ; i < f_print_indent_level; i++)
157 o << *next.key() << endl ;
160 --f_print_indent_level;
161 for (i = 0 ; i < f_print_indent_level ; i++)
170 FeatureSet::add(Feature *f)
177 FeatureSet::operator==(const FeatureSet &fs) const
183 FeatureSet::lookup(const Symbol *symbol) const
185 return lookup(*symbol);
189 FeatureSet::lookup(const Symbol &name) const
191 Feature tmp(name, 0);
197 FeatureSet::lookup(const char *name) const
199 Feature tmp(gSymTab->intern(name),0);
204 FeatureSet::deep_lookup(const char *first_name ...) const
206 const Feature *feature = lookup(first_name);
211 const FeatureSet *featureset = 0;
214 va_start(ap, first_name);
219 const char *p = va_arg(ap, char*);
223 if (feature->value()->type() != FeatureValue::featureset)
229 featureset = ((const FeatureValueFeatureSet *)feature->value())->value();
231 feature = featureset->lookup(p);
244 FeatureSet::deep_lookup(const Symbol *first_name ...) const
246 const Feature *feature = lookup(*first_name);
251 const FeatureSet *featureset = 0;
254 va_start(ap, first_name);
259 const Symbol *sym = va_arg(ap, const Symbol *);
263 if (feature->value()->type() != FeatureValue::featureset)
269 featureset = ((const FeatureValueFeatureSet *)feature->value())->value();
271 feature = featureset->lookup(*sym);
284 FeatureSet::deep_lookup(const dlist_array<Symbol> &vec) const
286 unsigned int index = 0;
287 const Feature *feature = lookup(*vec[index++]);
291 const FeatureSet *set = 0;
293 unsigned int entries = vec.entries();
294 for (; index < entries ; index++ )
296 if (feature->value()->type() != FeatureValue::featureset)
299 set = ((const FeatureValueFeatureSet *)feature->value())->value();
300 feature = set->lookup(*vec[index++]);
309 FeatureSet::removeFeature(const char *first_name ...)
311 const Feature *feature = lookup(first_name);
316 FeatureSet *featureset = this;
319 va_start(ap, first_name);
324 const char *p = va_arg(ap, char*);
328 if (feature->value()->type() != FeatureValue::featureset)
334 featureset = (FeatureSet*)
335 (((const FeatureValueFeatureSet *)feature->value())->value());
337 feature = featureset->lookup(p);
347 delete (featureset -> remove((Feature *)feature));