QMCPACK
XmlNode Class Reference
+ Collaboration diagram for XmlNode:

Public Types

using attrpair = std::pair< std::string, std::string >
 

Public Member Functions

std::string getName () const
 
template<typename T >
void setName (const T &val)
 
int getAttributeIndex (const std::string &name, int strict=0) const
 
template<typename T >
void getAttribute (const std::string &name, T &result) const
 
template<typename T >
void getAttribute (const char *name, T &result) const
 
std::string getAttribute (const std::string &name) const
 
std::string getAttribute (const char *name) const
 
std::string getAttribute (int index) const
 
std::string getAttributeName (int index) const
 
int getNumAttributes () const
 
template<typename T , typename TT >
void addAttribute (const T &n, const TT &v)
 
template<typename T >
void addYesNoAttribute (const T &n, int i)
 
template<typename T >
void getValue (T &result) const
 
template<typename T >
void getValue (std::vector< T > &result) const
 
std::string getValue () const
 
int getValueSize () const
 
template<typename T >
void setValue (const T &v)
 
int getNumChildren () const
 
int getChildIndex (const std::string &name, int strict=0) const
 
XmlNodegetChild (const std::string &name)
 
const XmlNodegetChild (const std::string &name) const
 
const XmlNodegetChild (int i) const
 
XmlNodegetChild (int i)
 
XmlNodeaddChild (const XmlNode &nd)
 
XmlNodeaddChild ()
 
template<typename T , typename TT >
void addParameterChild (const T &n, const TT &v)
 
template<typename T >
void addYesNoParameterChild (const T &n, int v)
 
 XmlNode ()
 
 XmlNode (std::istream *stream, int start=0, bool deferValue=false)
 
 XmlNode (const XmlStream &xstream, std::istream *const stream, int start, bool deferValue=false)
 
 XmlNode (const XmlNode &c)
 
void write (std::ostream &os, int indentLevel=0) const
 
std::string getString (int indentLevel=0) const
 

Private Member Functions

void readToString (std::string &s) const
 
void createFromStream (const XmlStream &stream, int start=0, bool deferValue=true)
 
std::string getInStr (int is) const
 
std::string trimWhitespace (const std::string &str) const
 
size_t getPosNextLiveChar (const std::string &str, char c) const
 
void getNextKeyVal (std::string &contentstr, std::string &key, std::string &val) const
 
void handleTagString (const XmlStream &xs, int loc)
 

Private Attributes

bool isSelfClosing_
 
std::string name_
 
std::vector< attrpairattributes_
 
bool valInline_
 
std::string value_
 
bool valueDeferred_
 
std::streampos podStart_
 
std::streampos podEnd_
 
std::vector< XmlNodechildren_
 
std::istream * stream_
 

Detailed Description

Definition at line 81 of file XmlRep.h.

Member Typedef Documentation

◆ attrpair

using attrpair = std::pair<std::string, std::string>

Definition at line 84 of file XmlRep.h.

Constructor & Destructor Documentation

◆ XmlNode() [1/4]

XmlNode ( )
inline

Definition at line 164 of file XmlRep.h.

References isSelfClosing_, valInline_, and valueDeferred_.

164  : stream_(NULL)
165  {
166  isSelfClosing_ = false;
167  valueDeferred_ = false;
168  valInline_ = false;
169  }
bool isSelfClosing_
Definition: XmlRep.h:88
std::istream * stream_
Definition: XmlRep.h:98
bool valInline_
Definition: XmlRep.h:91
bool valueDeferred_
Definition: XmlRep.h:93

◆ XmlNode() [2/4]

XmlNode ( std::istream *  stream,
int  start = 0,
bool  deferValue = false 
)

◆ XmlNode() [3/4]

XmlNode ( const XmlStream xstream,
std::istream *const  stream,
int  start,
bool  deferValue = false 
)

Definition at line 722 of file XmlRep.cpp.

References createFromStream().

722  : stream_(_stream)
723 {
724  createFromStream(xstream, start, deferValue);
725 }
std::istream * stream_
Definition: XmlRep.h:98
void createFromStream(const XmlStream &stream, int start=0, bool deferValue=true)
Definition: XmlRep.cpp:727

◆ XmlNode() [4/4]

XmlNode ( const XmlNode c)

Definition at line 701 of file XmlRep.cpp.

References attributes_, children_, isSelfClosing_, name_, podEnd_, podStart_, valInline_, value_, and valueDeferred_.

701  : stream_(c.stream_)
702 {
704  name_ = c.name_;
707  value_ = c.value_;
709  podStart_ = c.podStart_;
710  podEnd_ = c.podEnd_;
711  children_ = c.children_;
712 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::streampos podStart_
Definition: XmlRep.h:95
bool isSelfClosing_
Definition: XmlRep.h:88
std::istream * stream_
Definition: XmlRep.h:98
std::string value_
Definition: XmlRep.h:92
std::vector< XmlNode > children_
Definition: XmlRep.h:97
bool valInline_
Definition: XmlRep.h:91
std::string name_
Definition: XmlRep.h:89
std::streampos podEnd_
Definition: XmlRep.h:96
bool valueDeferred_
Definition: XmlRep.h:93

Member Function Documentation

◆ addAttribute()

void addAttribute ( const T &  n,
const TT &  v 
)

Definition at line 252 of file XmlRep.h.

References attributes_, and qmcplusplus::n.

Referenced by addParameterChild().

253 {
254  std::stringstream ss1;
255  ss1 << n;
256  std::stringstream ss2;
257  ss2 << v;
258  attrpair ap(ss1.str(), ss2.str());
259  attributes_.push_back(ap);
260 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::pair< std::string, std::string > attrpair
Definition: XmlRep.h:84

◆ addChild() [1/2]

XmlNode & addChild ( const XmlNode nd)

Definition at line 541 of file XmlRep.cpp.

References children_.

542 {
543  children_.push_back(nd);
544  return children_.back();
545 }
std::vector< XmlNode > children_
Definition: XmlRep.h:97

◆ addChild() [2/2]

XmlNode & addChild ( )

Definition at line 547 of file XmlRep.cpp.

References children_.

Referenced by addParameterChild().

548 {
549  XmlNode nd;
550  children_.push_back(nd);
551  return children_.back();
552 }
Definition: XmlRep.h:81
std::vector< XmlNode > children_
Definition: XmlRep.h:97

◆ addParameterChild()

void addParameterChild ( const T &  n,
const TT &  v 
)

Definition at line 281 of file XmlRep.h.

References addAttribute(), addChild(), qmcplusplus::n, setName(), setValue(), and valInline_.

Referenced by addYesNoParameterChild().

282 {
283  XmlNode nd;
284  nd.setName("parameter");
285  nd.addAttribute("name", n);
286  nd.valInline_ = true;
287  nd.setValue(v);
288  addChild(nd);
289 }
XmlNode & addChild()
Definition: XmlRep.cpp:547
Definition: XmlRep.h:81
void setValue(const T &v)
Definition: XmlRep.h:243
void setName(const T &val)
Definition: XmlRep.h:183
bool valInline_
Definition: XmlRep.h:91
void addAttribute(const T &n, const TT &v)
Definition: XmlRep.h:252

◆ addYesNoAttribute()

void addYesNoAttribute ( const T &  n,
int  i 
)

Definition at line 263 of file XmlRep.h.

References attributes_, and qmcplusplus::n.

264 {
265  std::stringstream ss;
266  ss << n;
267  attrpair ap;
268  ap.first = ss.str();
269  if (i == 0)
270  {
271  ap.second = "no";
272  }
273  else
274  {
275  ap.second = "yes";
276  }
277  attributes_.push_back(ap);
278 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::pair< std::string, std::string > attrpair
Definition: XmlRep.h:84

◆ addYesNoParameterChild()

void addYesNoParameterChild ( const T &  n,
int  v 
)

Definition at line 292 of file XmlRep.h.

References addParameterChild(), and qmcplusplus::n.

293 {
294  std::string vstr;
295  if (v == 0)
296  {
297  vstr = "no";
298  }
299  else
300  {
301  vstr = "yes";
302  }
303  addParameterChild(n, vstr);
304 }
void addParameterChild(const T &n, const TT &v)
Definition: XmlRep.h:281

◆ createFromStream()

void createFromStream ( const XmlStream stream,
int  start = 0,
bool  deferValue = true 
)
private

Definition at line 727 of file XmlRep.cpp.

References children_, XmlStream::elements, XmlStream::findChildElements(), handleTagString(), isSelfClosing_, podEnd_, podStart_, readToString(), selfClosing, stream_, valInline_, value_, and valueDeferred_.

Referenced by XmlNode().

728 {
729  valueDeferred_ = deferValue;
730  valInline_ = false;
731 
732  // this will populate the name and attributes
733  handleTagString(xstream, start);
734  tagType tt = xstream.elements[start].type;
735  if (tt == tagType::selfClosing)
736  {
737  // if self closing, then there is not POD and we are at the end
738  isSelfClosing_ = true;
739  }
740  else
741  {
742  // otherwise need to look for POD and subtags
743  isSelfClosing_ = false;
744 
745  vector<int> childIndices;
746  int podIndex = -1;
747  xstream.findChildElements(start, childIndices, podIndex);
748 
749  // if no children, try to put and POD inline
750  if (childIndices.size() == 0)
751  {
752  valInline_ = true;
753  }
754  else
755  {
756  valInline_ = false;
757  }
758 
759  // deal with POD if it exists
760  if (podIndex > 0)
761  {
762  podStart_ = xstream.elements[podIndex].startLoc;
763  podEnd_ = xstream.elements[podIndex].endLoc;
764  if (valueDeferred_ == false)
765  {
766  valueDeferred_ = true;
768  valueDeferred_ = false;
769  }
770  }
771 
772  // now sequentially create XmlNodes from subelements and add them to children vector
773  for (int i = 0; i < childIndices.size(); i++)
774  {
775  XmlNode child(xstream, this->stream_, childIndices[i], valueDeferred_);
776  children_.push_back(child);
777  }
778  }
779 }
void handleTagString(const XmlStream &xs, int loc)
Definition: XmlRep.cpp:566
Definition: XmlRep.h:81
std::streampos podStart_
Definition: XmlRep.h:95
bool isSelfClosing_
Definition: XmlRep.h:88
std::istream * stream_
Definition: XmlRep.h:98
tagType
Definition: XmlRep.h:24
std::string value_
Definition: XmlRep.h:92
std::vector< XmlNode > children_
Definition: XmlRep.h:97
bool valInline_
Definition: XmlRep.h:91
std::streampos podEnd_
Definition: XmlRep.h:96
void readToString(std::string &s) const
Definition: XmlRep.cpp:396
bool valueDeferred_
Definition: XmlRep.h:93

◆ getAttribute() [1/5]

void getAttribute ( const std::string &  name,
T &  result 
) const

Definition at line 191 of file XmlRep.h.

References attributes_, and getAttributeIndex().

Referenced by getAttribute(), EshdfFile::handleDensity(), EshdfFile::processKPts(), EshdfFile::readInEigFcn(), EshdfFile::writeQboxAtoms(), EshdfFile::writeQboxElectrons(), EshdfFile::writeQboxSupercell(), EshdfFile::writeQEAtoms(), and EshdfFile::writeQEBoilerPlate().

192 {
193  std::string value = attributes_[getAttributeIndex(name, 1)].second;
194  std::stringstream ss(value);
195  ss >> result;
196 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
int getAttributeIndex(const std::string &name, int strict=0) const
Definition: XmlRep.cpp:482

◆ getAttribute() [2/5]

void getAttribute ( const char *  name,
T &  result 
) const

Definition at line 199 of file XmlRep.h.

References getAttribute().

200 {
201  std::string sname(name);
202  return getAttribute(sname, result);
203 }
void getAttribute(const std::string &name, T &result) const
Definition: XmlRep.h:191

◆ getAttribute() [3/5]

string getAttribute ( const std::string &  name) const

Definition at line 513 of file XmlRep.cpp.

References attributes_, and getAttributeIndex().

513 { return attributes_[getAttributeIndex(name, 1)].second; }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
int getAttributeIndex(const std::string &name, int strict=0) const
Definition: XmlRep.cpp:482

◆ getAttribute() [4/5]

string getAttribute ( const char *  name) const

Definition at line 515 of file XmlRep.cpp.

References getAttribute().

516 {
517  string sname(name);
518  return getAttribute(sname);
519 }
void getAttribute(const std::string &name, T &result) const
Definition: XmlRep.h:191

◆ getAttribute() [5/5]

string getAttribute ( int  index) const

Definition at line 502 of file XmlRep.cpp.

References attributes_, and name_.

503 {
504  if (index < 0 || index >= attributes_.size())
505  {
506  cerr << "in XmlNode with name: " << name_ << ", requested attribute with index " << index
507  << ", but this index is not present." << endl;
508  exit(1);
509  }
510  return attributes_[index].second;
511 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::string name_
Definition: XmlRep.h:89

◆ getAttributeIndex()

int getAttributeIndex ( const std::string &  name,
int  strict = 0 
) const

Definition at line 482 of file XmlRep.cpp.

References attributes_, and name_.

Referenced by getAttribute(), and EshdfFile::writeQboxElectrons().

483 {
484  int index = -1;
485  for (int i = 0; i < attributes_.size(); i++)
486  {
487  if (attributes_[i].first == attrName)
488  {
489  index = i;
490  }
491  }
492  if (strict != 0 && index < 0)
493  {
494  cerr << "In XmlNode with name: " << name_ << ", could not find index for attribute with name: " << attrName << endl;
495  exit(1);
496  }
497  return index;
498 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::string name_
Definition: XmlRep.h:89

◆ getAttributeName()

string getAttributeName ( int  index) const

Definition at line 500 of file XmlRep.cpp.

References attributes_.

500 { return attributes_[index].first; }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90

◆ getChild() [1/4]

◆ getChild() [2/4]

const XmlNode & getChild ( const std::string &  name) const

Definition at line 460 of file XmlRep.cpp.

References getChild(), and getChildIndex().

460 { return getChild(getChildIndex(name, 1)); }
int getChildIndex(const std::string &name, int strict=0) const
Definition: XmlRep.cpp:440
XmlNode & getChild(const std::string &name)
Definition: XmlRep.cpp:458

◆ getChild() [3/4]

const XmlNode & getChild ( int  i) const

Definition at line 472 of file XmlRep.cpp.

References children_, and getNumChildren().

473 {
474  if (i < 0 || i >= children_.size())
475  {
476  cerr << "Asked to get child node: " << i << ", but there are only " << getNumChildren() << "nodes" << endl;
477  exit(1);
478  }
479  return children_[i];
480 }
std::vector< XmlNode > children_
Definition: XmlRep.h:97
int getNumChildren() const
Definition: XmlRep.h:150

◆ getChild() [4/4]

XmlNode & getChild ( int  i)

Definition at line 462 of file XmlRep.cpp.

References children_, and getNumChildren().

463 {
464  if (i < 0 || i >= children_.size())
465  {
466  cerr << "Asked to get child node: " << i << ", but there are only " << getNumChildren() << "nodes" << endl;
467  exit(1);
468  }
469  return children_[i];
470 }
std::vector< XmlNode > children_
Definition: XmlRep.h:97
int getNumChildren() const
Definition: XmlRep.h:150

◆ getChildIndex()

int getChildIndex ( const std::string &  name,
int  strict = 0 
) const

Definition at line 440 of file XmlRep.cpp.

References children_, getName(), and name_.

Referenced by getChild().

441 {
442  int index = -1;
443  for (int i = 0; i < children_.size(); i++)
444  {
445  if (children_[i].getName() == childName)
446  {
447  index = i;
448  }
449  }
450  if (strict != 0 && index < 0)
451  {
452  cerr << "In XmlNode with name: " << name_ << ", could not find index for child with name: " << childName << endl;
453  exit(1);
454  }
455  return index;
456 }
std::string getName() const
Definition: XmlRep.h:114
std::vector< XmlNode > children_
Definition: XmlRep.h:97
std::string name_
Definition: XmlRep.h:89

◆ getInStr()

std::string getInStr ( int  is) const
private

Definition at line 647 of file XmlRep.cpp.

Referenced by getString().

648 {
649  std::stringstream ss;
650  for (int i = 0; i < is; i++)
651  {
652  ss << " ";
653  }
654  return ss.str();
655 }

◆ getName()

std::string getName ( ) const
inline

◆ getNextKeyVal()

void getNextKeyVal ( std::string &  contentstr,
std::string &  key,
std::string &  val 
) const
private

Definition at line 600 of file XmlRep.cpp.

References getPosNextLiveChar(), and trimWhitespace().

Referenced by handleTagString().

601 {
602  size_t breakone = getPosNextLiveChar(contentstr, '=');
603 
604  key = contentstr.substr(0, breakone);
605  key = trimWhitespace(key);
606  //cout << "in getNextKeyVal, key = \'" << key << "\'" << endl;
607  contentstr = contentstr.substr(breakone + 1);
608 
609  size_t firstquote = getPosNextLiveChar(contentstr, '\"');
610  if (firstquote == string::npos)
611  {
612  firstquote = getPosNextLiveChar(contentstr, '\'');
613  }
614  contentstr = contentstr.substr(firstquote + 1);
615  size_t secondquote = getPosNextLiveChar(contentstr, '\"');
616  if (secondquote == string::npos)
617  {
618  secondquote = getPosNextLiveChar(contentstr, '\'');
619  }
620  val = contentstr.substr(0, secondquote);
621  val = trimWhitespace(val);
622 
623  contentstr = contentstr.substr(secondquote + 1);
624 }
size_t getPosNextLiveChar(const std::string &str, char c) const
Definition: XmlRep.cpp:626
std::string trimWhitespace(const std::string &str) const
Definition: XmlRep.cpp:555

◆ getNumAttributes()

int getNumAttributes ( ) const
inline

Definition at line 133 of file XmlRep.h.

References attributes_.

133 { return attributes_.size(); }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90

◆ getNumChildren()

int getNumChildren ( ) const
inline

Definition at line 150 of file XmlRep.h.

References children_.

Referenced by getChild(), EshdfFile::handleSpinGroup(), EshdfFile::processKPts(), EshdfFile::writeQboxAtoms(), EshdfFile::writeQboxElectrons(), and EshdfFile::writeQEAtoms().

150 { return children_.size(); }
std::vector< XmlNode > children_
Definition: XmlRep.h:97

◆ getPosNextLiveChar()

size_t getPosNextLiveChar ( const std::string &  str,
char  c 
) const
private

Definition at line 626 of file XmlRep.cpp.

Referenced by getNextKeyVal().

627 {
628  size_t index = string::npos;
629  if (str[0] == c)
630  {
631  index = 0;
632  }
633  else
634  {
635  for (int i = 1; i < str.size(); i++)
636  {
637  if (str[i] == c && str[i - 1] != '\\')
638  {
639  index = i;
640  break;
641  }
642  }
643  }
644  return index;
645 }

◆ getString()

string getString ( int  indentLevel = 0) const

Definition at line 663 of file XmlRep.cpp.

References attributes_, children_, getInStr(), getValue(), getValueSize(), isSelfClosing_, name_, and valInline_.

Referenced by write().

664 {
665  stringstream ss;
666  ss << getInStr(indentLevel);
667  ss << "<" << name_;
668 
669  for (int i = 0; i < attributes_.size(); i++)
670  {
671  ss << " " << attributes_[i].first << "=\"" << attributes_[i].second << "\"";
672  }
673  if (isSelfClosing_ == 1)
674  {
675  ss << "/>" << endl;
676  return ss.str();
677  }
678  else
679  {
680  ss << ">";
681  }
682  if (valInline_)
683  {
684  ss << getValue() << "</" << name_ << ">" << endl;
685  }
686  else
687  {
688  ss << endl;
689  for (int i = 0; i < children_.size(); i++)
690  {
691  ss << children_[i].getString(indentLevel + 2);
692  }
693 
694  if (getValueSize() > 0)
695  ss << getInStr(indentLevel + 2) << getValue() << endl;
696  ss << getInStr(indentLevel) << "</" << name_ << ">" << endl;
697  }
698  return ss.str();
699 }
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::string getValue() const
Definition: XmlRep.cpp:521
int getValueSize() const
Definition: XmlRep.cpp:532
bool isSelfClosing_
Definition: XmlRep.h:88
std::string getInStr(int is) const
Definition: XmlRep.cpp:647
std::vector< XmlNode > children_
Definition: XmlRep.h:97
bool valInline_
Definition: XmlRep.h:91
std::string name_
Definition: XmlRep.h:89

◆ getValue() [1/3]

void getValue ( T &  result) const

Definition at line 206 of file XmlRep.h.

References readToString(), value_, and valueDeferred_.

Referenced by EshdfFile::getOccupation(), EshdfFile::getPtvs(), EshdfFile::handleDensity(), EshdfFile::processKPts(), EshdfFile::readInEigFcn(), EshdfFile::writeQboxAtoms(), EshdfFile::writeQboxBoilerPlate(), EshdfFile::writeQEAtoms(), EshdfFile::writeQEElectrons(), and EshdfFile::writeQESupercell().

207 {
208  if (valueDeferred_)
209  {
210  std::string val;
211  readToString(val);
212  std::stringstream ss(val);
213  ss >> result;
214  }
215  else
216  {
217  std::stringstream ss(value_);
218  ss >> result;
219  }
220 }
std::string value_
Definition: XmlRep.h:92
void readToString(std::string &s) const
Definition: XmlRep.cpp:396
bool valueDeferred_
Definition: XmlRep.h:93

◆ getValue() [2/3]

void getValue ( std::vector< T > &  result) const

Definition at line 222 of file XmlRep.h.

References readToString(), value_, and valueDeferred_.

223 {
224  std::stringstream ss;
225  if (valueDeferred_)
226  {
227  std::string val;
228  readToString(val);
229  ss << val;
230  }
231  else
232  {
233  ss << value_;
234  }
235  T temp;
236  while (ss >> temp)
237  {
238  result.push_back(temp);
239  }
240 }
std::string value_
Definition: XmlRep.h:92
void readToString(std::string &s) const
Definition: XmlRep.cpp:396
bool valueDeferred_
Definition: XmlRep.h:93

◆ getValue() [3/3]

std::string getValue ( ) const

Definition at line 521 of file XmlRep.cpp.

References readToString(), value_, and valueDeferred_.

Referenced by getString().

522 {
523  if (valueDeferred_)
524  {
525  std::string val;
526  readToString(val);
527  return val;
528  }
529  return value_;
530 }
std::string value_
Definition: XmlRep.h:92
void readToString(std::string &s) const
Definition: XmlRep.cpp:396
bool valueDeferred_
Definition: XmlRep.h:93

◆ getValueSize()

int getValueSize ( ) const

Definition at line 532 of file XmlRep.cpp.

References podEnd_, podStart_, value_, and valueDeferred_.

Referenced by getString().

533 {
534  if (valueDeferred_)
535  {
536  return (podEnd_ - podStart_);
537  }
538  return value_.size();
539 }
std::streampos podStart_
Definition: XmlRep.h:95
std::string value_
Definition: XmlRep.h:92
std::streampos podEnd_
Definition: XmlRep.h:96
bool valueDeferred_
Definition: XmlRep.h:93

◆ handleTagString()

void handleTagString ( const XmlStream xs,
int  loc 
)
private

Definition at line 566 of file XmlRep.cpp.

References attributes_, XmlStream::elements, getNextKeyVal(), XmlStream::getTag(), isSelfClosing_, XmlElement::name, name_, selfClosing, trimWhitespace(), and XmlElement::type.

Referenced by createFromStream().

567 {
568  const XmlElement& elem = xs.elements[loc];
569  name_ = elem.name;
570  string tagstr = xs.getTag(elem);
571  if (elem.type == tagType::selfClosing)
572  {
573  isSelfClosing_ = true;
574  }
575  else
576  {
577  isSelfClosing_ = false;
578  }
579 
580  // take everything after the name
581  string decliningstring = tagstr.substr(tagstr.find(name_) + name_.size() + 1);
582 
583  // remove trailing > or /> if appropriate and trim whitespace from left and right ends
584  int numToRemove = 1;
585  if (isSelfClosing_)
586  {
587  numToRemove++;
588  }
589  decliningstring = decliningstring.substr(0, decliningstring.size() - numToRemove);
590  decliningstring = trimWhitespace(decliningstring);
591 
592  while (decliningstring.size() > 1)
593  {
594  attrpair att;
595  getNextKeyVal(decliningstring, att.first, att.second);
596  attributes_.push_back(att);
597  }
598 }
void getNextKeyVal(std::string &contentstr, std::string &key, std::string &val) const
Definition: XmlRep.cpp:600
std::vector< attrpair > attributes_
Definition: XmlRep.h:90
std::vector< XmlElement > elements
Definition: XmlRep.h:75
std::string trimWhitespace(const std::string &str) const
Definition: XmlRep.cpp:555
bool isSelfClosing_
Definition: XmlRep.h:88
std::pair< std::string, std::string > attrpair
Definition: XmlRep.h:84
std::string name
Definition: XmlRep.h:39
tagType type
Definition: XmlRep.h:40
std::string name_
Definition: XmlRep.h:89
std::string getTag(const XmlElement &e) const
Definition: XmlRep.cpp:384

◆ readToString()

void readToString ( std::string &  s) const
private

Definition at line 396 of file XmlRep.cpp.

References podEnd_, podStart_, qmcplusplus::Units::time::s, stream_, value_, and valueDeferred_.

Referenced by createFromStream(), and getValue().

397 {
398  if (valueDeferred_)
399  {
400  std::streampos curLoc = stream_->tellg();
401 
402  s.resize(podEnd_ - podStart_);
403  stream_->seekg(podStart_);
404  stream_->read(s.data(), podEnd_ - podStart_);
405 
406  // go back to current place in the stream
407  stream_->seekg(curLoc);
408 
409  // now strip out any xml comments
410  std::stringstream ss;
411  int commentStart = -1;
412  int commentEnd = 0;
413 
414  // if we find a comment, will put everything but the comments in ss
415  while (s.find("<!--", commentEnd) != string::npos)
416  {
417  commentStart = s.find("<!--", commentEnd);
418  ss << s.substr(commentEnd, commentStart - commentEnd);
419  commentEnd = s.find("-->", commentStart);
420  }
421  // this means we didn't find a comment, so the string s is OK to return
422  if (commentStart == -1)
423  {
424  return;
425  }
426  else
427  {
428  // we found comments and we're putting everything after the last comment in ss
429  ss << s.substr(commentEnd + 3, s.size() - commentEnd - 3);
430  }
431  s = ss.str();
432  }
433  else
434  {
435  s = value_;
436  }
437 }
std::streampos podStart_
Definition: XmlRep.h:95
std::istream * stream_
Definition: XmlRep.h:98
std::string value_
Definition: XmlRep.h:92
std::streampos podEnd_
Definition: XmlRep.h:96
bool valueDeferred_
Definition: XmlRep.h:93

◆ setName()

void setName ( const T &  val)

Definition at line 183 of file XmlRep.h.

References name_.

Referenced by addParameterChild().

184 {
185  std::stringstream ss;
186  ss << val;
187  name_ = ss.str();
188 }
std::string name_
Definition: XmlRep.h:89

◆ setValue()

void setValue ( const T &  v)

Definition at line 243 of file XmlRep.h.

References value_, and valueDeferred_.

Referenced by addParameterChild().

244 {
245  valueDeferred_ = false;
246  std::stringstream ss;
247  ss << v;
248  value_ = ss.str();
249 }
std::string value_
Definition: XmlRep.h:92
bool valueDeferred_
Definition: XmlRep.h:93

◆ trimWhitespace()

string trimWhitespace ( const std::string &  str) const
private

Definition at line 555 of file XmlRep.cpp.

Referenced by getNextKeyVal(), and handleTagString().

556 {
557  size_t first = str.find_first_not_of(" \n\t\v\f\r");
558  if (string::npos == first)
559  {
560  return string("");
561  }
562  size_t last = str.find_last_not_of(" \n\t\v\f\r");
563  return str.substr(first, (last - first + 1));
564 }

◆ write()

void write ( std::ostream &  os,
int  indentLevel = 0 
) const

Definition at line 657 of file XmlRep.cpp.

References getString().

658 {
659  string str = getString(indentLevel);
660  os << str;
661 }
std::string getString(int indentLevel=0) const
Definition: XmlRep.cpp:663

Member Data Documentation

◆ attributes_

◆ children_

std::vector<XmlNode> children_
private

◆ isSelfClosing_

bool isSelfClosing_
private

Definition at line 88 of file XmlRep.h.

Referenced by createFromStream(), getString(), handleTagString(), and XmlNode().

◆ name_

std::string name_
private

◆ podEnd_

std::streampos podEnd_
private

Definition at line 96 of file XmlRep.h.

Referenced by createFromStream(), getValueSize(), readToString(), and XmlNode().

◆ podStart_

std::streampos podStart_
private

Definition at line 95 of file XmlRep.h.

Referenced by createFromStream(), getValueSize(), readToString(), and XmlNode().

◆ stream_

std::istream* stream_
private

Definition at line 98 of file XmlRep.h.

Referenced by createFromStream(), and readToString().

◆ valInline_

bool valInline_
private

Definition at line 91 of file XmlRep.h.

Referenced by addParameterChild(), createFromStream(), getString(), and XmlNode().

◆ value_

std::string value_
private

Definition at line 92 of file XmlRep.h.

Referenced by createFromStream(), getValue(), getValueSize(), readToString(), setValue(), and XmlNode().

◆ valueDeferred_

bool valueDeferred_
private

Definition at line 93 of file XmlRep.h.

Referenced by createFromStream(), getValue(), getValueSize(), readToString(), setValue(), and XmlNode().


The documentation for this class was generated from the following files: