ProteoWizard
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pwiz::minimxml::SAXParser::Handler::Attributes Class Reference

#include <SAXParser.hpp>

Classes

class  attribute
 

Public Types

typedef std::vector< attributeattribute_list
 

Public Member Functions

 Attributes (const char *_source_text, size_t _source_text_len, bool _autoUnescape)
 
 Attributes ()
 
 Attributes (saxstring &str, bool _autoUnescape)
 
 ~Attributes ()
 
 Attributes (const Attributes &rhs)
 
Attributesoperator= (const Attributes &rhs)
 
void test_invariant () const
 
const char * getTagName () const
 
const char * getTextBuffer () const
 
size_t getSize () const
 
attribute_list::const_iterator begin () const
 
attribute_list::const_iterator end () const
 
attribute_list::const_iterator find (const std::string &name) const
 
const attributefindAttributeByName (const char *name) const
 
const char * findValueByName (const char *name, XMLUnescapeBehavior_t Unescape=XMLUnescapeDefault) const
 

Protected Member Functions

void setParserIndex ()
 
PWIZ_API_DECL void parseAttributes (std::string::size_type &index) const
 
void access () const
 

Protected Attributes

char * textbuff
 
size_t size
 
size_t index
 
size_t index_end
 
bool autoUnescape
 
bool managemem
 
bool firstread
 
attribute_list attrs
 

Detailed Description

Definition at line 351 of file SAXParser.hpp.

Member Typedef Documentation

◆ attribute_list

Definition at line 523 of file SAXParser.hpp.

Constructor & Destructor Documentation

◆ Attributes() [1/4]

pwiz::minimxml::SAXParser::Handler::Attributes::Attributes ( const char *  _source_text,
size_t  _source_text_len,
bool  _autoUnescape 
)
inline

◆ Attributes() [2/4]

pwiz::minimxml::SAXParser::Handler::Attributes::Attributes ( )
inline

Definition at line 368 of file SAXParser.hpp.

368 :
369 index(0),index_end(0),autoUnescape(false),firstread(true),attrs()
370 {
371 size=0;
372 textbuff = NULL;
373 managemem = true;
374 test_invariant(); // everything correct?
375 };

References managemem, size, test_invariant(), and textbuff.

◆ Attributes() [3/4]

pwiz::minimxml::SAXParser::Handler::Attributes::Attributes ( saxstring str,
bool  _autoUnescape 
)
inline

Definition at line 376 of file SAXParser.hpp.

376 :
377 index(0),index_end(0),autoUnescape(_autoUnescape),firstread(true),attrs()
378 {
379 textbuff = str.data();
380 size=str.length();
381 managemem = false; // we don't have to free this
382 setParserIndex(); // ready for eventual parsing
383 test_invariant(); // everything correct?
384 };

References pwiz::minimxml::SAXParser::saxstring::data(), pwiz::minimxml::SAXParser::saxstring::length(), managemem, setParserIndex(), size, test_invariant(), and textbuff.

◆ ~Attributes()

pwiz::minimxml::SAXParser::Handler::Attributes::~Attributes ( )
inline

Definition at line 385 of file SAXParser.hpp.

386 {
387 if (managemem)
388 free(textbuff);
389 }

References managemem, and textbuff.

◆ Attributes() [4/4]

pwiz::minimxml::SAXParser::Handler::Attributes::Attributes ( const Attributes rhs)
inline

Definition at line 390 of file SAXParser.hpp.

391 {
392 textbuff = NULL;
393 *this = rhs;
394 }

References textbuff.

Member Function Documentation

◆ operator=()

Attributes & pwiz::minimxml::SAXParser::Handler::Attributes::operator= ( const Attributes rhs)
inline

Definition at line 395 of file SAXParser.hpp.

395 {
396 size = rhs.size;
397 index = rhs.index;
398 index_end = rhs.index_end; // string bounds for attribute parsing
399 autoUnescape = rhs.autoUnescape; // do XML escape of attribute?
400 firstread = rhs.firstread; // may change during const access
401 if (managemem)
402 textbuff = (char *)realloc(textbuff,size+1);
403 else
404 textbuff = (char *)malloc(size+1);
405 managemem = true; // we need to free textbuff at dtor
406 memcpy(textbuff,rhs.textbuff,size+1);
407 attrs.resize(rhs.attrs.size());
408 // now fix up the char ptrs to point to our copy of attribute list
409 for (size_t n=attrs.size();n--;)
410 {
411 attrs[n].name = ((char *)textbuff)+(rhs.attrs[n].getName()-rhs.getTextBuffer());
412 attrs[n].value = ((char *)textbuff)+(rhs.attrs[n].getValuePtr()-rhs.getTextBuffer());
413 }
414 test_invariant(); // everything correct?
415 return *this;
416 }

References attrs, autoUnescape, firstread, getTextBuffer(), index, index_end, managemem, size, test_invariant(), and textbuff.

◆ test_invariant()

void pwiz::minimxml::SAXParser::Handler::Attributes::test_invariant ( ) const
inline

Definition at line 418 of file SAXParser.hpp.

419 {
420#ifdef _DEBUG
421 for (size_t n=attrs.size();n--;)
422 {
423 assert(textbuff != NULL);
424 assert(attrs[n].name>textbuff);
425 assert(attrs[n].value>attrs[n].name);
426 assert(attrs[n].value<textbuff+size);
427 if (n)
428 assert(attrs[n].name>attrs[n-1].value);
429 }
430#endif
431 }

References attrs, size, and textbuff.

Referenced by access(), Attributes(), Attributes(), Attributes(), getTagName(), getTextBuffer(), operator=(), and setParserIndex().

◆ getTagName()

const char * pwiz::minimxml::SAXParser::Handler::Attributes::getTagName ( ) const
inline

Definition at line 433 of file SAXParser.hpp.

434 { // work area contains tag name
435 test_invariant(); // everything correct?
436 return textbuff+('/'==*textbuff);
437 }

References test_invariant(), and textbuff.

◆ getTextBuffer()

const char * pwiz::minimxml::SAXParser::Handler::Attributes::getTextBuffer ( ) const
inline

Definition at line 438 of file SAXParser.hpp.

439 { // return pointer to our work area
440 test_invariant(); // everything correct?
441 return textbuff;
442 }

References test_invariant(), and textbuff.

Referenced by operator=().

◆ getSize()

size_t pwiz::minimxml::SAXParser::Handler::Attributes::getSize ( ) const
inline

Definition at line 443 of file SAXParser.hpp.

444 {
445 return size;
446 }

References size.

◆ setParserIndex()

void pwiz::minimxml::SAXParser::Handler::Attributes::setParserIndex ( )
inlineprotected

Definition at line 455 of file SAXParser.hpp.

456 {
457 // on entry, buffer has form "foo bar="baz" or maybe "foo/"
458 const char *c = textbuff;
459 while (*c && !strchr(" \n\r\t/",*c)) c++;
460 size_t indexNameEnd = c-textbuff;
461 while (*c && strchr(" \n\r\t",*c)) c++;
462 textbuff[indexNameEnd] = 0; // nullterm the name
463 index = c-textbuff; // should point to bar
464 index_end = size;
465 test_invariant(); // everything correct?
466 }

References index, index_end, size, test_invariant(), and textbuff.

Referenced by Attributes(), and Attributes().

◆ begin()

attribute_list::const_iterator pwiz::minimxml::SAXParser::Handler::Attributes::begin ( ) const
inline

Definition at line 527 of file SAXParser.hpp.

528 {
529 access(); // have we actually parsed the attributes text yet?
530 return attrs.begin();
531 }

References access(), and attrs.

Referenced by find(), and PrintEventHandler::startElement().

◆ end()

attribute_list::const_iterator pwiz::minimxml::SAXParser::Handler::Attributes::end ( ) const
inline

Definition at line 532 of file SAXParser.hpp.

533 {
534 access(); // have we actually parsed the attributes text yet?
535 return attrs.end();
536 }

References access(), and attrs.

Referenced by find(), readAttribute(), and PrintEventHandler::startElement().

◆ find()

attribute_list::const_iterator pwiz::minimxml::SAXParser::Handler::Attributes::find ( const std::string &  name) const
inline

Definition at line 537 of file SAXParser.hpp.

538 {
539 attribute_list::const_iterator it;
540 for (it = begin(); it != end() ; it++ )
541 {
542 if (it->matchName(name.c_str()))
543 break; // found it
544 }
545 return it;
546 }
attribute_list::const_iterator begin() const
attribute_list::const_iterator end() const

References begin(), and end().

Referenced by readAttribute().

◆ parseAttributes()

PWIZ_API_DECL void pwiz::minimxml::SAXParser::Handler::Attributes::parseAttributes ( std::string::size_type &  index) const
protected

Referenced by access().

◆ access()

void pwiz::minimxml::SAXParser::Handler::Attributes::access ( ) const
inlineprotected

Definition at line 551 of file SAXParser.hpp.

552 { // don't parse attributes until asked to
553 test_invariant(); // everything correct?
554 if (firstread) {
555 firstread = false;
557 }
558 test_invariant(); // everything correct?
559 }
PWIZ_API_DECL void parseAttributes(std::string::size_type &index) const

References firstread, index, parseAttributes(), and test_invariant().

Referenced by begin(), end(), and findAttributeByName().

◆ findAttributeByName()

const attribute * pwiz::minimxml::SAXParser::Handler::Attributes::findAttributeByName ( const char *  name) const
inline

Definition at line 562 of file SAXParser.hpp.

563 {
564 access(); // parse the buffer if we haven't already
565 for (attribute_list::const_iterator it=attrs.begin();it!=attrs.end();it++)
566 {
567 if (it->matchName(name))
568 return &(*it);
569 }
570 return NULL;
571 }

References access(), and attrs.

Referenced by findValueByName(), pwiz::minimxml::SAXParser::Handler::getAttribute(), pwiz::minimxml::SAXParser::Handler::getAttribute(), pwiz::minimxml::SAXParser::Handler::getAttribute(), and pwiz::minimxml::SAXParser::Handler::getAttribute().

◆ findValueByName()

const char * pwiz::minimxml::SAXParser::Handler::Attributes::findValueByName ( const char *  name,
XMLUnescapeBehavior_t  Unescape = XMLUnescapeDefault 
) const
inline

Definition at line 574 of file SAXParser.hpp.

575 {
576 const attribute *attr = findAttributeByName(name);
577 if (attr)
578 return attr->getValuePtr(Unescape);
579 return NULL;
580 }
const attribute * findAttributeByName(const char *name) const

References findAttributeByName(), and pwiz::minimxml::SAXParser::Handler::Attributes::attribute::getValuePtr().

Referenced by pwiz::minimxml::SAXParser::Handler::getAttribute().

Member Data Documentation

◆ textbuff

char* pwiz::minimxml::SAXParser::Handler::Attributes::textbuff
mutableprotected

◆ size

size_t pwiz::minimxml::SAXParser::Handler::Attributes::size
protected

◆ index

size_t pwiz::minimxml::SAXParser::Handler::Attributes::index
mutableprotected

Definition at line 450 of file SAXParser.hpp.

Referenced by access(), operator=(), and setParserIndex().

◆ index_end

size_t pwiz::minimxml::SAXParser::Handler::Attributes::index_end
protected

Definition at line 450 of file SAXParser.hpp.

Referenced by operator=(), and setParserIndex().

◆ autoUnescape

bool pwiz::minimxml::SAXParser::Handler::Attributes::autoUnescape
protected

Definition at line 451 of file SAXParser.hpp.

Referenced by operator=().

◆ managemem

bool pwiz::minimxml::SAXParser::Handler::Attributes::managemem
protected

Definition at line 452 of file SAXParser.hpp.

Referenced by Attributes(), Attributes(), Attributes(), operator=(), and ~Attributes().

◆ firstread

bool pwiz::minimxml::SAXParser::Handler::Attributes::firstread
mutableprotected

Definition at line 453 of file SAXParser.hpp.

Referenced by access(), and operator=().

◆ attrs

attribute_list pwiz::minimxml::SAXParser::Handler::Attributes::attrs
mutableprotected

Definition at line 525 of file SAXParser.hpp.

Referenced by begin(), end(), findAttributeByName(), operator=(), and test_invariant().


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