SpeciesHandler.C 5.03 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// SpeciesHandler.C
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
6 7 8
// $Id: SpeciesHandler.C,v 1.2 2004-09-14 22:24:11 fgygi Exp $

#if USE_XERCES
Francois Gygi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

#include "SpeciesHandler.h"
#include "Species.h"
#include "StrX.h"
using namespace xercesc;
#include <iostream>
#include <sstream>
#include <cassert>
using namespace std;

////////////////////////////////////////////////////////////////////////////////
SpeciesHandler::SpeciesHandler(Species& sp) : 
  sp_(sp) {}

////////////////////////////////////////////////////////////////////////////////
SpeciesHandler::~SpeciesHandler() {}

////////////////////////////////////////////////////////////////////////////////
void SpeciesHandler::startElement(const XMLCh* const uri,
  const XMLCh* const localname, const XMLCh* const qname,
  const Attributes& attributes)
{  
  // cout << " SpeciesHandler::startElement " << StrX(qname) << endl;
  
  string locname(XMLString::transcode(localname));
  
  if ( locname == "species" )
  {
    // check for the case where the species is a link to another uri
    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
      string attrname(XMLString::transcode(attributes.getLocalName(index)));
      if ( attrname == "name")
      {
        current_name = StrX(attributes.getValue(index)).localForm();
        sp_.name_ = current_name;
      }
      else if ( attrname == "href" )
      {
        current_href = StrX(attributes.getValue(index)).localForm();
        cout << " SpeciesHandler: found xlink in species definition" << endl
           << " name=" << current_name << " href=" << current_href
           << endl;
        sp_.uri_ = current_href;
      }
    }
  }
  else if ( locname == "projector" )
  {
    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
      string attrname(XMLString::transcode(attributes.getLocalName(index)));
      if ( attrname == "l")
      {
        current_l = atoi(StrX(attributes.getValue(index)).localForm());
      }
      else if ( attrname == "size" )
      {
        current_size = atoi(StrX(attributes.getValue(index)).localForm());
      }
    }
  }
}

////////////////////////////////////////////////////////////////////////////////
void SpeciesHandler::endElement(const XMLCh* const uri,
  const XMLCh* const localname, const XMLCh* const qname, string& content)
{
  string locname(XMLString::transcode(localname));
  istringstream stst(content);
  // cout << " SpeciesHandler::endElement " << StrX(qname) 
  //      << " content=" << string(content,0,20) << endl;

  if ( locname == "description")
  {
    // reject ambiguous case where both the href and the definition are given
    if ( current_href != "" )
    {
      cout << " SpeciesHandler: ambiguous definition: uri=" 
           << StrX(uri) << endl
           << " using local definition (href: " << current_href << " ignored)"
           << endl;
    }
    sp_.description_ = content;
  }
  else if ( locname == "atomic_number" )
  {
    stst >> sp_.atomic_number_;
  }
  else if ( locname == "mass" )
  {
    stst >> sp_.mass_;
  }
  else if ( locname == "symbol" )
  {
    stst >> skipws >> sp_.symbol_;
  }
  else if ( locname == "valence_charge" )
  {
    stst >> sp_.zval_;
  }
  else if ( locname == "lmax" )
  {
    stst >> sp_.lmax_;
  }
  else if ( locname == "llocal" )
  {
    stst >> sp_.llocal_;
  }
  else if ( locname == "nquad" )
  {
    stst >> sp_.nquad_;
  }
  else if ( locname == "rquad" )
  {
    stst >> sp_.rquad_;
  }
  else if ( locname == "mesh_spacing" )
  {
    stst >> sp_.deltar_;
  }
  else if ( locname == "radial_potential" )
  {
    if ( current_l+1  > sp_.vps_.size() )
    {
      sp_.vps_.resize(current_l+1);
      sp_.phi_.resize(current_l+1);
    }
    sp_.vps_[current_l].resize(current_size);
    for ( int i = 0; i < current_size; i++ )
      stst >> sp_.vps_[current_l][i];
  }
  else if ( locname == "radial_function" )
  {
    sp_.phi_[current_l].resize(current_size);
    for ( int i = 0; i < current_size; i++ )
      stst >> sp_.phi_[current_l][i];
  }
}

////////////////////////////////////////////////////////////////////////////////
StructureHandler* SpeciesHandler::startSubHandler(const XMLCh* const uri,
    const XMLCh* const localname, const XMLCh* const qname, 
    const Attributes& attributes)
{
  // check if element qname can be processed by another StructureHandler
  // If it can, return a pointer to the StructureHandler, otherwise return 0
  // cout << " SpeciesHandler::startSubHandler " << StrX(qname) << endl;
  return 0;
}

////////////////////////////////////////////////////////////////////////////////
void SpeciesHandler::endSubHandler(const XMLCh* const uri,
    const XMLCh* const localname, const XMLCh* const qname, 
    const StructureHandler* const subHandler)
{
  // cout << " SpeciesHandler::endSubHandler " << StrX(qname) << endl;
  // if any StructureHandler was created by startSubHandler, delete it
  // delete subHandler;
}
      
Francois Gygi committed
172
#endif