112853Sgabeblack@google.com/***************************************************************************** 212853Sgabeblack@google.com 312853Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412853Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512853Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612853Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712853Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812853Sgabeblack@google.com License. You may obtain a copy of the License at 912853Sgabeblack@google.com 1012853Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112853Sgabeblack@google.com 1212853Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312853Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412853Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512853Sgabeblack@google.com implied. See the License for the specific language governing 1612853Sgabeblack@google.com permissions and limitations under the License. 1712853Sgabeblack@google.com 1812853Sgabeblack@google.com *****************************************************************************/ 1912853Sgabeblack@google.com 2012853Sgabeblack@google.com/***************************************************************************** 2112853Sgabeblack@google.com 2212853Sgabeblack@google.com scfx_string.h - 2312853Sgabeblack@google.com 2412853Sgabeblack@google.com Original Author: Robert Graulich, Synopsys, Inc. 2512853Sgabeblack@google.com Martin Janssen, Synopsys, Inc. 2612853Sgabeblack@google.com 2712853Sgabeblack@google.com *****************************************************************************/ 2812853Sgabeblack@google.com 2912853Sgabeblack@google.com/***************************************************************************** 3012853Sgabeblack@google.com 3112853Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3212853Sgabeblack@google.com changes you are making here. 3312853Sgabeblack@google.com 3412853Sgabeblack@google.com Name, Affiliation, Date: 3512853Sgabeblack@google.com Description of Modification: 3612853Sgabeblack@google.com 3712853Sgabeblack@google.com *****************************************************************************/ 3812853Sgabeblack@google.com// $Log: scfx_string.h,v $ 3912853Sgabeblack@google.com// Revision 1.1.1.1 2006/12/15 20:20:04 acg 4012853Sgabeblack@google.com// SystemC 2.3 4112853Sgabeblack@google.com// 4212853Sgabeblack@google.com// Revision 1.2 2006/01/03 23:18:34 acg 4312853Sgabeblack@google.com// Changed copyright to include 2006. 4412853Sgabeblack@google.com// 4512853Sgabeblack@google.com// Revision 1.1.1.1 2005/12/19 23:16:43 acg 4612853Sgabeblack@google.com// First check in of SystemC 2.1 into its own archive. 4712853Sgabeblack@google.com// 4812853Sgabeblack@google.com// Revision 1.9 2005/09/15 23:02:03 acg 4912853Sgabeblack@google.com// Added std:: prefix to appropriate methods and types to get around 5012853Sgabeblack@google.com// issues with the Edison Front End. 5112853Sgabeblack@google.com// 5212853Sgabeblack@google.com// Revision 1.8 2005/06/07 17:27:02 acg 5312853Sgabeblack@google.com// Fixed bug in scfx_string::operator += where an array reference was used 5412853Sgabeblack@google.com// rather than the [] operator. This meant that the buffer may have been 5512853Sgabeblack@google.com// accessed beyond its allocated storage. 5612853Sgabeblack@google.com// 5712853Sgabeblack@google.com 5812853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__ 5912853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__ 6012853Sgabeblack@google.com 6112853Sgabeblack@google.com#include <cstdio> 6212853Sgabeblack@google.com 6312853Sgabeblack@google.comnamespace sc_dt 6412853Sgabeblack@google.com{ 6512853Sgabeblack@google.com 6612853Sgabeblack@google.com// classes defined in this module 6712853Sgabeblack@google.comclass scfx_string; 6812853Sgabeblack@google.com 6912853Sgabeblack@google.com 7012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 7112853Sgabeblack@google.com// CLASS : scfx_string 7212853Sgabeblack@google.com// 7312853Sgabeblack@google.com// Simple string class for internal use. 7412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 7512853Sgabeblack@google.com 7612853Sgabeblack@google.comclass scfx_string 7712853Sgabeblack@google.com{ 7812853Sgabeblack@google.com void resize(std::size_t); 7912853Sgabeblack@google.com 8012853Sgabeblack@google.com public: 8112853Sgabeblack@google.com scfx_string(); 8212853Sgabeblack@google.com 8312853Sgabeblack@google.com ~scfx_string(); 8412853Sgabeblack@google.com 8512853Sgabeblack@google.com int length() const; 8612853Sgabeblack@google.com 8712853Sgabeblack@google.com void clear(); 8812853Sgabeblack@google.com 8912853Sgabeblack@google.com char & operator [] (int); 9012853Sgabeblack@google.com 9112853Sgabeblack@google.com void append(int); 9212853Sgabeblack@google.com void discard(int); 9312853Sgabeblack@google.com void remove(int); 9412853Sgabeblack@google.com 9512853Sgabeblack@google.com void operator += (char); 9612853Sgabeblack@google.com void operator += (const char *); 9712853Sgabeblack@google.com 9812853Sgabeblack@google.com operator const char * (); 9912853Sgabeblack@google.com 10012853Sgabeblack@google.com private: 10112853Sgabeblack@google.com std::size_t m_len; 10212853Sgabeblack@google.com std::size_t m_alloc; 10312853Sgabeblack@google.com char *m_buffer; 10412853Sgabeblack@google.com}; 10512853Sgabeblack@google.com 10612853Sgabeblack@google.com 10712853Sgabeblack@google.com// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 10812853Sgabeblack@google.com 10912853Sgabeblack@google.cominline void 11012853Sgabeblack@google.comscfx_string::resize(std::size_t i) 11112853Sgabeblack@google.com{ 11212853Sgabeblack@google.com do { 11312853Sgabeblack@google.com m_alloc *= 2; 11412853Sgabeblack@google.com } while (i >= m_alloc); 11512853Sgabeblack@google.com 11612853Sgabeblack@google.com char *temp = new char[m_alloc]; 11712853Sgabeblack@google.com 11812853Sgabeblack@google.com for (int j = 0; j < (int) m_len; ++j) { 11912853Sgabeblack@google.com temp[j] = m_buffer[j]; 12012853Sgabeblack@google.com } 12112853Sgabeblack@google.com temp[m_len] = 0; 12212853Sgabeblack@google.com 12312853Sgabeblack@google.com delete [] m_buffer; 12412853Sgabeblack@google.com m_buffer = temp; 12512853Sgabeblack@google.com} 12612853Sgabeblack@google.com 12712853Sgabeblack@google.cominline scfx_string::scfx_string() : 12812853Sgabeblack@google.com m_len(0), m_alloc(BUFSIZ), m_buffer(new char[m_alloc]) 12912853Sgabeblack@google.com{ 13012853Sgabeblack@google.com m_buffer[m_len] = 0; 13112853Sgabeblack@google.com} 13212853Sgabeblack@google.com 13312853Sgabeblack@google.cominline scfx_string::~scfx_string() { delete [] m_buffer; } 13412853Sgabeblack@google.com 13512853Sgabeblack@google.cominline int scfx_string::length() const { return m_len; } 13612853Sgabeblack@google.com 13712853Sgabeblack@google.cominline void 13812853Sgabeblack@google.comscfx_string::clear() 13912853Sgabeblack@google.com{ 14012853Sgabeblack@google.com m_len = 0; 14112853Sgabeblack@google.com m_buffer[m_len] = 0; 14212853Sgabeblack@google.com} 14312853Sgabeblack@google.com 14412853Sgabeblack@google.cominline char & 14512853Sgabeblack@google.comscfx_string::operator [] (int i) 14612853Sgabeblack@google.com{ 14712853Sgabeblack@google.com if (i >= (int)m_alloc) { 14812853Sgabeblack@google.com resize(i); 14912853Sgabeblack@google.com } 15012853Sgabeblack@google.com return m_buffer[i]; 15112853Sgabeblack@google.com} 15212853Sgabeblack@google.com 15312853Sgabeblack@google.cominline void 15412853Sgabeblack@google.comscfx_string::append(int n) 15512853Sgabeblack@google.com{ 15612853Sgabeblack@google.com m_len += n; 15712853Sgabeblack@google.com m_buffer[m_len] = 0; 15812853Sgabeblack@google.com} 15912853Sgabeblack@google.com 16012853Sgabeblack@google.cominline void 16112853Sgabeblack@google.comscfx_string::discard(int n) 16212853Sgabeblack@google.com{ 16312853Sgabeblack@google.com m_len -= n; 16412853Sgabeblack@google.com m_buffer[m_len] = 0; 16512853Sgabeblack@google.com} 16612853Sgabeblack@google.com 16712853Sgabeblack@google.cominline void 16812853Sgabeblack@google.comscfx_string::remove(int i) 16912853Sgabeblack@google.com{ 17012853Sgabeblack@google.com for (int j = i + 1; j < (int)m_len; ++j) 17112853Sgabeblack@google.com m_buffer[j - 1] = m_buffer[j]; 17212853Sgabeblack@google.com --m_len; 17312853Sgabeblack@google.com m_buffer[m_len] = 0; 17412853Sgabeblack@google.com} 17512853Sgabeblack@google.com 17612853Sgabeblack@google.cominline void 17712853Sgabeblack@google.comscfx_string::operator += (char c) 17812853Sgabeblack@google.com{ 17912853Sgabeblack@google.com this->operator [] (m_len) = c; 18012853Sgabeblack@google.com m_len++; 18112853Sgabeblack@google.com this->operator [] (m_len) = 0; 18212853Sgabeblack@google.com} 18312853Sgabeblack@google.com 18412853Sgabeblack@google.cominline void 18512853Sgabeblack@google.comscfx_string::operator += (const char *s) 18612853Sgabeblack@google.com{ 18712853Sgabeblack@google.com while (*s) 18812853Sgabeblack@google.com (*this) += *s++; 18912853Sgabeblack@google.com} 19012853Sgabeblack@google.com 19112853Sgabeblack@google.cominline scfx_string::operator const char * () 19212853Sgabeblack@google.com{ 19312853Sgabeblack@google.com m_buffer[m_len] = 0; 19412853Sgabeblack@google.com return m_buffer; 19512853Sgabeblack@google.com} 19612853Sgabeblack@google.com 19712853Sgabeblack@google.com} // namespace sc_dt 19812853Sgabeblack@google.com 19912853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__ 200