char_stack.h
Upload User: zhongxx05
Upload Date: 2007-06-06
Package Size: 33641k
Code Size: 3k
Category:

Symbian

Development Platform:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #ifndef CHAR_STACK_H
  36. #define CHAR_STACK_H
  37. /*
  38.  * CharStack :
  39.  * This is a utility class to help with parsing tasks. It allows you
  40.  * to accumulate characters into a buffer without having to worry about
  41.  * buffer allocation issues.
  42.  */
  43. class CharStack {
  44. public:
  45.     CharStack(int buf_len = 64);
  46.     ~CharStack();
  47.     char& operator*();
  48.     CharStack& operator++();
  49.     void operator++(int);
  50.     const char* Finish();
  51.     int Length() const;
  52.     void Reset();
  53.     const char* StrSep(const char* str, const char* sep);
  54. private:
  55.     CharStack(const CharStack&); // don't implement
  56.     CharStack& operator=(const CharStack&);
  57.     char* NewBuf();
  58.     int m_Len;
  59.     char* m_pBuf;
  60.     char* m_pCur;
  61. };
  62. inline 
  63. CharStack::CharStack(int buflen) :  
  64.     m_Len(buflen),
  65.     m_pBuf(0),
  66.     m_pCur(0)
  67. {
  68.     NewBuf();
  69. }
  70. inline 
  71. CharStack::~CharStack()
  72. {
  73.     delete [] m_pBuf;
  74.     m_pBuf = 0;
  75.     m_Len = 0;
  76.     m_pCur = 0;
  77. }
  78. inline 
  79. char& CharStack::operator*()
  80. {
  81.     return m_pCur - m_pBuf < m_Len ? *m_pCur : *NewBuf();
  82. }
  83. inline 
  84. CharStack& CharStack::operator++()
  85. {
  86.     ++m_pCur;
  87.     return *this;
  88. }
  89. inline 
  90. void CharStack::operator++(int)
  91. {
  92.     m_pCur++;
  93. }
  94. inline 
  95. int CharStack::Length() const
  96. {
  97.     return m_pCur - m_pBuf;
  98. }
  99. inline 
  100. void CharStack::Reset()
  101. {
  102.     m_pCur = m_pBuf;
  103. }
  104. inline 
  105. const char* CharStack::Finish()
  106. {
  107.     if (m_pCur - m_pBuf >= m_Len)
  108.  NewBuf();
  109.     *m_pCur = 0;
  110.     return m_pBuf;
  111. }
  112. #endif /* CHAR_STACK_H */