1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // SampleHandler.cpp
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #include "SampleHandler.h"
20 #include "Sample.h"
21 #include "AtomSetHandler.h"
22 #include "WavefunctionHandler.h"
23 #include "StrX.h"
24 using namespace xercesc;
25 #include <iostream>
26 #include <cassert>
27 using namespace std;
28 
29 ////////////////////////////////////////////////////////////////////////////////
SampleHandler(Sample & s,DoubleMatrix & gfdata)30 SampleHandler::SampleHandler(Sample& s, DoubleMatrix& gfdata) :
31   s_(s), gfdata_(gfdata), current_gfdata_pos(0) {}
32 
33 ////////////////////////////////////////////////////////////////////////////////
~SampleHandler()34 SampleHandler::~SampleHandler() {}
35 
36 ////////////////////////////////////////////////////////////////////////////////
startElement(const XMLCh * const uri,const XMLCh * const localname,const XMLCh * const qname,const Attributes & attributes)37 void SampleHandler::startElement(const XMLCh* const uri,
38   const XMLCh* const localname, const XMLCh* const qname,
39   const Attributes& attributes)
40 {
41   // cout << " SampleHandler::startElement " << StrX(qname) << endl;
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
endElement(const XMLCh * const uri,const XMLCh * const localname,const XMLCh * const qname,string & content)45 void SampleHandler::endElement(const XMLCh* const uri,
46   const XMLCh* const localname, const XMLCh* const qname, string& content)
47 {
48   // istringstream stst(st);
49   // string locname = StrX(localname).localForm();
50   // cout << " SampleHandler::endElement " << locname << endl;
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
startSubHandler(const XMLCh * const uri,const XMLCh * const localname,const XMLCh * const qname,const Attributes & attributes)54 StructureHandler* SampleHandler::startSubHandler(const XMLCh* const uri,
55     const XMLCh* const localname, const XMLCh* const qname,
56     const Attributes& attributes)
57 {
58   // check if element qname can be processed by another StructureHandler
59   // If it can, return a pointer to the StructureHandler, otherwise return 0
60   // cout << " SampleHandler::startSubHandler " << StrX(qname) << endl;
61 
62   string qnm = StrX(qname).localForm();
63   if ( qnm == "atomset" )
64   {
65     return new AtomSetHandler(s_.atoms);
66   }
67   else if ( qnm == "wavefunction" )
68   {
69     read_wf = true;
70     return new WavefunctionHandler(s_.wf,gfdata_,current_gfdata_pos);
71   }
72   else if ( qnm == "wavefunction_velocity" )
73   {
74     read_wfv = true;
75     assert(read_wf);
76     s_.wfv = new Wavefunction(s_.wf);
77     // reset wfv to have only k=0
78     s_.wfv->reset();
79     return new WavefunctionHandler(*s_.wfv,gfdata_,current_gfdata_pos);
80   }
81   else
82   {
83     return 0;
84   }
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
endSubHandler(const XMLCh * const uri,const XMLCh * const localname,const XMLCh * const qname,const StructureHandler * const subHandler)88 void SampleHandler::endSubHandler(const XMLCh* const uri,
89     const XMLCh* const localname, const XMLCh* const qname,
90     const StructureHandler* const subHandler)
91 {
92   // cout << " SampleHandler::endSubHandler " << StrX(qname) << endl;
93   delete subHandler;
94 }
95