TupleCutXML.cxx
Go to the documentation of this file.
1 
12 // for iterator member defect
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "TupleCutXML.h"
18 
19 #include "XmlController.h"
20 #include "XmlDocument.h"
21 #include "XmlElement.h"
22 
23 #include "datasrcs//TupleCut.h"
24 
25 #include <cassert>
26 
27 using namespace hippodraw;
28 
30  : BaseXML ( "TupleCut", controller ),
31  m_low ( "low" ),
32  m_high ( "high" ),
33  m_invert ( "invert" ),
34  m_column ( "column" ),
35  m_dim ( "dimension" ),
36  m_axis ( "axis" )
37 {
38 }
39 
40 XmlElement *
42 createElement ( unsigned int i, const TupleCut & cut )
43 {
45 
46  const void * addr = reinterpret_cast < const void * > ( & cut );
47  int id = m_controller -> getId ( addr );
48  setId ( *tag, id );
49 
50  tag -> setAttribute ( m_dim, -1 ); // to flag not obsolete TupleCut
51  XmlElement * element
52  = XmlController::m_xml_doc -> createElement ( "TupleCutAxis" );
53  element -> setAttribute ( m_axis, i );
54 
55  int tmp = cut.getInversion () ? 1 : 0;
56  element -> setAttribute ( m_invert, tmp );
57 
58  const Range & range = cut.getRange ();
59  element -> setAttribute ( m_low, range.low() );
60  element -> setAttribute ( m_high, range.high() );
61 
62  int col = cut.getColumn ( );
63  element -> setAttribute ( m_column, col );
64 
65  tag -> appendChild ( *element );
66  delete element;
67 
68  return tag;
69 }
70 
72 {
73  TupleCut * cut = 0; // will create one of correct dim in function below
74  setAttributes ( cut, &tag );
75 
76  return cut;
77 }
78 
81 void
85  const XmlElement * element ) const
86 {
87  int value;
88  bool ok = element->attribute ( m_invert, value );
89  if ( ok && ( value == 1 ) ) cut -> setInversion( true );
90 
91  double low = 0.0;
92  ok = element->attribute( m_low, low );
93  double high = 0.0;
94  ok = element->attribute( m_high, high );
95 
96  Range range ( low, high );
97 
98  cut->setRange( range );
99 
100  int col = -2;
101  ok = element->attribute ( m_column, col );
102  cut->setColumn( col );
103 }
104 
105 bool
107 hasMultiDimTupleCut ( const XmlElement * element ) const
108 {
109  bool yes = true;
110  int dim;
111  bool ok = element -> attribute ( m_dim, dim );
112  if ( ok && dim < 0 ) yes = false;
113 
114  return yes;
115 }
116 
117 void
119 getObjects ( const XmlElement * element, std::vector <TupleCut * > & cuts )
120 {
121  int dim;
122  bool ok = element -> attribute ( m_dim, dim );
123  if ( ! ok ) { // very old documents forgot the Y axis
124  TupleCut * cut = new TupleCut ();
125  setAxisAttributes ( cut, Axes::X, element );
126  cuts.push_back ( cut );
127  }
128  else { // multidemension style
129  XmlElement::NodeList_t nodelist;
130  element -> fillNodeList ( "TupleCutAxis", nodelist );
131  assert ( nodelist.empty () == false );
132  XmlElement::NodeList_t::const_iterator first = nodelist.begin();
133 
134  while ( first != nodelist.end() ) {
135  XmlElement * node = *first++;
136  int axis;
137  bool ok = node -> attribute ( m_axis, axis );
138  assert ( ok );
139  Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
140  TupleCut * cut = new TupleCut ();
141  setAxisAttributes ( cut, axis_t, node );
142  cuts.push_back ( cut );
143  }
144  }
145 }
146 
148  const XmlElement * element ) const
149 {
150  int dim;
151  bool ok = element->attribute ( m_dim, dim );
152 
153  if ( ! ok ) { // older documents forgot Y axis
154  cut = new TupleCut ();
155  setAxisAttributes ( cut, Axes::X, element );
156  }
157  else { // new style
158  cut = new TupleCut ( );
159  XmlElement::NodeList_t nodelist;
160  element -> fillNodeList ( "TupleCutAxis", nodelist );
161  assert ( nodelist.empty () == false );
162  XmlElement::NodeList_t::const_iterator first = nodelist.begin();
163 
164  while ( first != nodelist.end() ) {
165  XmlElement * node = *first++;
166  int axis;
167  bool ok = node -> attribute ( m_axis, axis );
168  assert ( ok );
169  Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
170  setAxisAttributes ( cut, axis_t, node );
171  }
172  }
173 }

Generated for HippoDraw Class Library by doxygen