Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / Element.C
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 // $TOG: Element.C /main/5 1998/04/17 11:48:25 mgreess $
24 #include <iostream>
25 using namespace std;
26 #include <stdlib.h>
27 #include "StyleSheetExceptions.h"
28 #include "Element.h"
29 #include "AttributeList.h"
30
31 // /////////////////////////////////////////////////////////////////////////
32 // Element
33 // /////////////////////////////////////////////////////////////////////////
34
35 #define OLIAS_SIBLING_INFO "LAST"
36
37
38 Element::Element(const Element& element) 
39 :
40   f_gi(element.f_gi),
41   f_sibling_number(element.f_sibling_number),
42   f_attributes(element.f_attributes),
43   f_olias_attributes(element.f_olias_attributes),
44   f_freeAttrLists(false),
45   f_relative_sibling_number(element.f_relative_sibling_number),
46   f_last_child(element.f_last_child),
47   f_relatively_last_child(element.f_relatively_last_child)
48
49 {
50 }
51
52 Element::Element(const Symbol&  gi,
53                  unsigned int   sibling_number,
54                  AttributeList *attlist,
55                  AttributeList *olias_attributes,
56                  unsigned int  relative_sibling_number
57
58                 )
59 : f_gi(gi),
60   f_sibling_number(sibling_number),
61   f_attributes(attlist),
62   f_olias_attributes(olias_attributes),
63   f_freeAttrLists(true),
64   f_relative_sibling_number(relative_sibling_number)
65 {
66     f_last_child = 0;
67     f_relatively_last_child = 0;
68
69     Symbol name(gSymTab->intern(OLIAS_SIBLING_INFO));
70     const Attribute* x = get_olias_attribute(name);
71
72         if ( x && x -> value() ) {
73             int code = atoi(x -> value());
74             switch (code) {
75                case 0:
76                f_last_child = 0;
77                f_relatively_last_child = 0;
78                break;
79              case 1:
80                f_last_child = 0;
81                f_relatively_last_child = 1;
82                break;
83              case 2:
84                f_last_child = 1;
85                f_relatively_last_child = 1;
86                break;
87              default:
88                throw(CASTEXCEPT Exception());
89             }
90        }
91 }
92
93 Element::~Element()
94 {
95   if ( f_freeAttrLists == true ) {
96      delete f_olias_attributes;
97      delete f_attributes;
98   }
99 }
100
101
102 const Attribute *
103 Element::get_attribute(const Symbol &name) const
104 {
105   if (f_attributes)
106     return f_attributes->lookup(name);
107
108   return 0 ;
109 }
110
111 const Attribute *
112 Element::get_olias_attribute(const Symbol &name) const
113 {
114   if (f_olias_attributes)
115     return f_olias_attributes->lookup(name);
116   
117   return 0 ;
118 }
119
120 ostream &
121 Element::print(ostream &o) const
122 {
123   o << '<' << f_gi ;
124
125 #ifdef SIBLING_DEBUG
126   o << "[" << this->f_sibling_number << "]";
127   o << "[" << this->f_relative_sibling_number<< "]";
128   o << "[" << this-> f_last_child << "]";
129   o << "[" << this-> f_relatively_last_child<< "]";
130 #endif
131
132   if (f_attributes)
133     o << *f_attributes ;
134
135   if (f_olias_attributes)
136     o << " #" << *f_olias_attributes ;
137
138   o << '>' ;
139
140   return o;
141 }