All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Tokenizer::Token Class Reference

Definition of the sub-class Token. More...

#include <GaudiKernel/Tokenizer.h>

Collaboration diagram for Tokenizer::Token:

Public Member Functions

 Token (const Token &copy)
 Copy constructor. More...
 
 Token ()
 Standard constructor. More...
 
void make (const std::string &s, long st, const char *delim, const char *tagBegin, const char *tagEnd, const char *eq, const char *valBegin, const char *valEnd)
 Create token from string. More...
 
virtual ~Token ()
 Standard Destructor. More...
 
Tokenoperator= (const Token &copy)
 Assignment operator. More...
 
bool operator== (const Token &copy) const
 
long length () const
 Total token length. More...
 
const std::string & tag () const
 Acces tag value. More...
 
const std::string & value () const
 Access value. More...
 
void resolveValue ()
 Resolve value from environment. More...
 

Private Attributes

long m_length
 Toke length. More...
 
std::string m_tag
 Tag variable. More...
 
std::string m_value
 Value variable. More...
 

Detailed Description

Definition of the sub-class Token.

Definition at line 28 of file Tokenizer.h.

Constructor & Destructor Documentation

Tokenizer::Token::Token ( const Token copy)
inline

Copy constructor.

Definition at line 37 of file Tokenizer.h.

37  : m_length(copy.m_length), m_tag(copy.m_tag), m_value(copy.m_value) {
38  }
std::string m_value
Value variable.
Definition: Tokenizer.h:34
long m_length
Toke length.
Definition: Tokenizer.h:30
std::string m_tag
Tag variable.
Definition: Tokenizer.h:32
Tokenizer::Token::Token ( )
inline

Standard constructor.

Definition at line 40 of file Tokenizer.h.

40  : m_length(0) {
41  }
long m_length
Toke length.
Definition: Tokenizer.h:30
virtual Tokenizer::Token::~Token ( )
inlinevirtual

Standard Destructor.

Definition at line 45 of file Tokenizer.h.

45  {
46  }

Member Function Documentation

long Tokenizer::Token::length ( ) const
inline

Total token length.

Definition at line 54 of file Tokenizer.h.

54  {
55  return m_length;
56  }
long m_length
Toke length.
Definition: Tokenizer.h:30
void Tokenizer::Token::make ( const std::string &  s,
long  st,
const char *  delim,
const char *  tagBegin,
const char *  tagEnd,
const char *  eq,
const char *  valBegin,
const char *  valEnd 
)

Create token from string.

Definition at line 60 of file Tokenizer.cpp.

60  {
61  long lenTagBeg = ::strlen(tagBeg);
62  long lenTagEnd = ::strlen(tagEnd);
63  long lenValBeg = ::strlen(valBeg);
64  long lenValEnd = ::strlen(valEnd);
65  long lenDelim = ::strlen(delim);
66  long lenEq = ::strlen(eq);
67  long slen = s.length();
68  long start = st;
69  while(::strncmp(s.c_str()+start,delim,lenDelim)==0) start += lenDelim;
70  long posTag = (lenTagBeg>0) ? s.find(tagBeg, start) + lenTagBeg : start;
71  long posDelim = s.find(delim,posTag) > 0 ? s.find(delim,posTag) : slen;
72  long posEq = s.find(eq, posTag) > 0 ? s.find(eq, posTag) : posDelim-posTag;
73  long lenTag = (lenTagEnd>0) ? s.find(tagEnd, posTag)-posTag : (posEq>0) ? (posEq>posTag) ? posEq-posTag : posDelim-posTag : posDelim;
74  posEq = s.find(eq, posTag+lenTag+lenTagEnd)+lenEq;
75  long posVal = (lenValBeg>0) ? s.find(valBeg, posEq)+lenValBeg : posEq;
76  posDelim = (lenDelim>0) ? s.find(delim, posVal+lenValBeg) : slen;
77  long lenVal = (lenValEnd>0) ? s.find(valEnd, posVal)-posVal : ((posDelim>=0) ? posDelim : slen)-posVal;
78 
79  m_tag = m_value = "";
80  // Ooops: Valid tag found:
81  if ( start >= 0 && posTag >= 0 ) {
82  m_tag = s.substr(posTag, lenTag);
83  m_length = posTag+m_tag.length()+lenTagEnd-st;
84  }
85  // Ooops: there is also a value:
86  if ( posVal >= 0 && lenVal >= 0 ) {
87  m_value = s.substr(posVal, lenVal);
88  m_length = posVal+m_value.length()+lenValEnd-st;
89  }
90  while(::strncmp(s.c_str()+start+m_length,delim,lenDelim)==0) m_length += lenDelim;
91 }
std::string m_value
Value variable.
Definition: Tokenizer.h:34
long m_length
Toke length.
Definition: Tokenizer.h:30
std::string m_tag
Tag variable.
Definition: Tokenizer.h:32
string s
Definition: gaudirun.py:210
tuple start
Definition: IOTest.py:88
Tokenizer::Token & Tokenizer::Token::operator= ( const Token copy)

Assignment operator.

Definition at line 21 of file Tokenizer.cpp.

21  {
22  m_length=copy.m_length;
23  m_tag=copy.m_tag;
24  m_value=copy.m_value;
25  return *this;
26 }
std::string m_value
Value variable.
Definition: Tokenizer.h:34
long m_length
Toke length.
Definition: Tokenizer.h:30
std::string m_tag
Tag variable.
Definition: Tokenizer.h:32
bool Tokenizer::Token::operator== ( const Token copy) const
inline

Definition at line 50 of file Tokenizer.h.

50  {
51  return m_tag == copy.m_tag && m_value == copy.m_value && m_length == copy.m_length;
52  }
std::string m_value
Value variable.
Definition: Tokenizer.h:34
long m_length
Toke length.
Definition: Tokenizer.h:30
std::string m_tag
Tag variable.
Definition: Tokenizer.h:32
void Tokenizer::Token::resolveValue ( )

Resolve value from environment.

Definition at line 29 of file Tokenizer.cpp.

29  {
30  std::string res;
31  if ( System::resolveEnv(m_value, res).isSuccess() ) {
32  m_value = res;
33  }
34 }
GAUDI_API StatusCode resolveEnv(const std::string &var, std::string &res, int recusions=124)
Definition: Environment.cpp:51
std::string m_value
Value variable.
Definition: Tokenizer.h:34
const std::string& Tokenizer::Token::tag ( ) const
inline

Acces tag value.

Definition at line 58 of file Tokenizer.h.

58  {
59  return m_tag;
60  }
std::string m_tag
Tag variable.
Definition: Tokenizer.h:32
const std::string& Tokenizer::Token::value ( ) const
inline

Access value.

Definition at line 62 of file Tokenizer.h.

62  {
63  return m_value;
64  }
std::string m_value
Value variable.
Definition: Tokenizer.h:34

Member Data Documentation

long Tokenizer::Token::m_length
private

Toke length.

Definition at line 30 of file Tokenizer.h.

std::string Tokenizer::Token::m_tag
private

Tag variable.

Definition at line 32 of file Tokenizer.h.

std::string Tokenizer::Token::m_value
private

Value variable.

Definition at line 34 of file Tokenizer.h.


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