| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# Tokenizer.h

Go to the documentation of this file.

    00001 //==============================================================================
    00002 // Tokenizer.h
    00003 //------------------------------------------------------------------------------
    00004 //
    00005 // Package : Kernel
    00006 //             The LHCb definition package
    00007 //
    00008 // Author  : M.Frank
    00009 //
    00010 // Changes : M.Frank ,  01/10/00: Initialil version
    00011 //
    00012 //==============================================================================
    00013 #ifndef KERNEL_TOKENIZER_H
    00014 #define KERNEL_TOKENIZER_H
    00015
    00017 #include "GaudiKernel/Kernel.h"
    00018 #include <string>
    00019 #include <vector>
    00020
    00021
    00024 class GAUDI_API Tokenizer   {
    00025 public:
    00028   class Token   {
    00030     long        m_length;
    00032     std::string m_tag;
    00034     std::string m_value;
    00035   public:
    00037     Token(const Token& copy)  : m_length(copy.m_length), m_tag(copy.m_tag), m_value(copy.m_value)  {
    00038     }
    00040     Token()  : m_length(0)  {
    00041     }
    00043     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);
    00045     virtual ~Token()    {
    00046     }
    00048     Token& operator=(const Token& copy);
    00049     // Equality operator
    00050     bool operator==(const Token& copy)    const   {
    00051       return m_tag == copy.m_tag, m_value == copy.m_value && m_length == copy.m_length;
    00052     }
    00054     long length()   const   {
    00055       return m_length;
    00056     }
    00058     const std::string& tag()   const    {
    00059       return m_tag;
    00060     }
    00062     const std::string& value()  const   {
    00063       return m_value;
    00064     }
    00066     void resolveValue();
    00067   };
    00068   typedef Token Item;
    00069   typedef std::vector<Token> Items;
    00070 protected:
    00072   Items m_tokens;
    00074   bool  m_resolve;
    00075 public:
    00077   Tokenizer() : m_resolve(false)  {}
    00079   Tokenizer(bool resolve) : m_resolve(resolve)  {}
    00081   virtual ~Tokenizer()    {
    00082     m_tokens.erase(m_tokens.begin(), m_tokens.end());
    00083   }
    00085   void analyse(const std::string& s, const char* delim, const char* tagBegin, const char* tagEnd, const char* eq, const char* valBegin, const char* valEnd);
    00087   void analyse(const std::string& s, const char* delim, const char* tag, const char* eq, const char* val)    {
    00088     analyse(s, delim, tag, tag, eq, val, val);
    00089   }
    00091   void analyse(const std::string& s, const char* delim, const char* eq, const char* val)    {
    00092     analyse(s, delim, "", "", eq, val, val);
    00093   }
    00095   void analyse(const std::string& s, const char* delim=" ", const char* eq="=")    {
    00096     analyse(s, delim, "", "", eq, "", "");
    00097   }
    00099   Items& items()    {
    00100     return m_tokens;
    00101   }
    00103   const Items& items()    const   {
    00104     return m_tokens;
    00105   }
    00106 };
    00107 #endif  // KERNEL_TOKENIZER_H