112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_string.h -- Implementation of a simple string class.
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Stan Y. Liao, Synopsys, Inc.
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de  CHANGE LOG AT END OF FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de// $Log: sc_string.h,v $
3012027Sjungma@eit.uni-kl.de// Revision 1.3  2011/08/26 20:46:19  acg
3112027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
3212027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
3312027Sjungma@eit.uni-kl.de//
3412027Sjungma@eit.uni-kl.de#ifndef SC_STRING_H
3512027Sjungma@eit.uni-kl.de#define SC_STRING_H
3612027Sjungma@eit.uni-kl.de
3712027Sjungma@eit.uni-kl.de
3812027Sjungma@eit.uni-kl.de#include "sysc/utils/sc_iostream.h"
3912027Sjungma@eit.uni-kl.de#include "sysc/utils/sc_report.h"
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.denamespace sc_dt {
4212027Sjungma@eit.uni-kl.de	class sc_string_old;
4312027Sjungma@eit.uni-kl.de}
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.de#ifdef SC_USE_SC_STRING_OLD
4612027Sjungma@eit.uni-kl.de	typedef sc_dt::sc_string_old sc_string;
4712027Sjungma@eit.uni-kl.de#endif
4812027Sjungma@eit.uni-kl.de#ifdef SC_USE_STD_STRING
4912027Sjungma@eit.uni-kl.de	typedef ::std::string sc_string;
5012027Sjungma@eit.uni-kl.de#endif
5112027Sjungma@eit.uni-kl.de
5212027Sjungma@eit.uni-kl.denamespace sc_dt {
5312027Sjungma@eit.uni-kl.de
5412027Sjungma@eit.uni-kl.de// forward class declarations
5512027Sjungma@eit.uni-kl.declass sc_string_rep;
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.de// friend operator declarations
5812027Sjungma@eit.uni-kl.desc_string_old operator + ( const char* s, const sc_string_old& t );
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.de
6112027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
6212027Sjungma@eit.uni-kl.de//  CLASS : sc_string
6312027Sjungma@eit.uni-kl.de//
6412027Sjungma@eit.uni-kl.de//  String class (yet another).
6512027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
6612027Sjungma@eit.uni-kl.de
6712027Sjungma@eit.uni-kl.declass sc_string_old
6812027Sjungma@eit.uni-kl.de{
6912027Sjungma@eit.uni-kl.de    friend systemc_ostream& operator << (systemc_ostream& os, const sc_string_old& a);
7012027Sjungma@eit.uni-kl.de    friend systemc_istream& operator >> ( systemc_istream& is, sc_string_old& a );
7112027Sjungma@eit.uni-kl.de
7212027Sjungma@eit.uni-kl.depublic:
7312027Sjungma@eit.uni-kl.de
7412027Sjungma@eit.uni-kl.de    //  constructors
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.de    explicit sc_string_old( int size = 16 );
7712027Sjungma@eit.uni-kl.de    sc_string_old( const char* s );
7812027Sjungma@eit.uni-kl.de    sc_string_old( const char* s, int n ); // get first n chars from the string
7912027Sjungma@eit.uni-kl.de    sc_string_old( const sc_string_old& s );
8012027Sjungma@eit.uni-kl.de
8112027Sjungma@eit.uni-kl.de
8212027Sjungma@eit.uni-kl.de    // destructor
8312027Sjungma@eit.uni-kl.de
8412027Sjungma@eit.uni-kl.de    ~sc_string_old();
8512027Sjungma@eit.uni-kl.de
8612027Sjungma@eit.uni-kl.de
8712027Sjungma@eit.uni-kl.de    // concatenation and assignment
8812027Sjungma@eit.uni-kl.de
8912027Sjungma@eit.uni-kl.de    sc_string_old& operator = ( const char* s );
9012027Sjungma@eit.uni-kl.de    sc_string_old& operator = ( const sc_string_old& s );
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de    sc_string_old& operator += ( const char* s );
9312027Sjungma@eit.uni-kl.de    sc_string_old& operator += ( char c );
9412027Sjungma@eit.uni-kl.de    sc_string_old& operator += ( const sc_string_old& s );
9512027Sjungma@eit.uni-kl.de
9612027Sjungma@eit.uni-kl.de    sc_string_old operator + ( const char* s ) const;
9712027Sjungma@eit.uni-kl.de    sc_string_old operator + ( char c ) const;
9812027Sjungma@eit.uni-kl.de    sc_string_old operator + ( const sc_string_old& s ) const;
9912027Sjungma@eit.uni-kl.de
10012027Sjungma@eit.uni-kl.de    friend sc_string_old operator + ( const char* s, const sc_string_old& t );
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de
10312027Sjungma@eit.uni-kl.de    // returns substring [first,last]
10412027Sjungma@eit.uni-kl.de
10512027Sjungma@eit.uni-kl.de    sc_string_old substr( int first, int last ) const;
10612027Sjungma@eit.uni-kl.de
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de    // string comparison operators
10912027Sjungma@eit.uni-kl.de
11012027Sjungma@eit.uni-kl.de    bool operator == ( const char* s ) const;
11112027Sjungma@eit.uni-kl.de    bool operator != ( const char* s ) const;
11212027Sjungma@eit.uni-kl.de    bool operator <  ( const char* s ) const;
11312027Sjungma@eit.uni-kl.de    bool operator <= ( const char* s ) const;
11412027Sjungma@eit.uni-kl.de    bool operator >  ( const char* s ) const;
11512027Sjungma@eit.uni-kl.de    bool operator >= ( const char* s ) const;
11612027Sjungma@eit.uni-kl.de    bool operator == ( const sc_string_old& s ) const;
11712027Sjungma@eit.uni-kl.de    bool operator != ( const sc_string_old& s ) const;
11812027Sjungma@eit.uni-kl.de    bool operator <  ( const sc_string_old& s ) const;
11912027Sjungma@eit.uni-kl.de    bool operator <= ( const sc_string_old& s ) const;
12012027Sjungma@eit.uni-kl.de    bool operator >  ( const sc_string_old& s ) const;
12112027Sjungma@eit.uni-kl.de    bool operator >= ( const sc_string_old& s ) const;
12212027Sjungma@eit.uni-kl.de
12312027Sjungma@eit.uni-kl.de    //
12412027Sjungma@eit.uni-kl.de    // returns length of the string (excluding trailing \0)
12512027Sjungma@eit.uni-kl.de    //
12612027Sjungma@eit.uni-kl.de    int length() const;
12712027Sjungma@eit.uni-kl.de
12812027Sjungma@eit.uni-kl.de    //
12912027Sjungma@eit.uni-kl.de    // returns c-style string
13012027Sjungma@eit.uni-kl.de    //
13112027Sjungma@eit.uni-kl.de    const char* c_str() const;
13212027Sjungma@eit.uni-kl.de    //
13312027Sjungma@eit.uni-kl.de    // returns c-style string
13412027Sjungma@eit.uni-kl.de    //
13512027Sjungma@eit.uni-kl.de    operator const char*() const;
13612027Sjungma@eit.uni-kl.de    //
13712027Sjungma@eit.uni-kl.de    // returns character at "index" position
13812027Sjungma@eit.uni-kl.de    //
13912027Sjungma@eit.uni-kl.de    char operator[](int index) const;
14012027Sjungma@eit.uni-kl.de    //
14112027Sjungma@eit.uni-kl.de    // l-value subscript
14212027Sjungma@eit.uni-kl.de    //
14312027Sjungma@eit.uni-kl.de    char& operator[](int index);
14412027Sjungma@eit.uni-kl.de
14512027Sjungma@eit.uni-kl.de    // formatted string (see printf description)
14612027Sjungma@eit.uni-kl.de    static sc_string_old to_string(const char* format, ...);
14712027Sjungma@eit.uni-kl.de    //
14812027Sjungma@eit.uni-kl.de    //       conveniece formatting functions for common types
14912027Sjungma@eit.uni-kl.de    //       e.g. sc_string_old("a=%d, s is %s").fmt(1).fmt("string")
15012027Sjungma@eit.uni-kl.de    //       should produce: a=1, s is string
15112027Sjungma@eit.uni-kl.de    //       it should be safe: if less arguments specified
15212027Sjungma@eit.uni-kl.de    //       it should print %specifier; extra arguments should be ignored
15312027Sjungma@eit.uni-kl.de    // TODO: if the type of the argument is incompatible with format
15412027Sjungma@eit.uni-kl.de    //       specifier it should be ignored
15512027Sjungma@eit.uni-kl.de    //
15612027Sjungma@eit.uni-kl.de    // must have it inlined because of some compilers
15712027Sjungma@eit.uni-kl.de    template<class T> sc_string_old& fmt(const T& t)
15812027Sjungma@eit.uni-kl.de	{
15912027Sjungma@eit.uni-kl.de	    // search %
16012027Sjungma@eit.uni-kl.de	    int index;
16112027Sjungma@eit.uni-kl.de	    int last_char = length()-1;
16212027Sjungma@eit.uni-kl.de	    sc_string_old temp(*this);
16312027Sjungma@eit.uni-kl.de	    do
16412027Sjungma@eit.uni-kl.de	    {
16512027Sjungma@eit.uni-kl.de		index = temp.pos("%");
16612027Sjungma@eit.uni-kl.de		if(index == last_char)
16712027Sjungma@eit.uni-kl.de		    return *this;
16812027Sjungma@eit.uni-kl.de		temp = substr(index,last_char);
16912027Sjungma@eit.uni-kl.de	    } while(temp[0] != '%');
17012027Sjungma@eit.uni-kl.de	    int f_len = (int)temp.fmt_length(); // length of format field
17112027Sjungma@eit.uni-kl.de	    temp = to_string(substr(0,index+f_len-1).c_str(),t);
17212027Sjungma@eit.uni-kl.de	    return (*this) = temp + substr(index+f_len,last_char);
17312027Sjungma@eit.uni-kl.de	}
17412027Sjungma@eit.uni-kl.de    sc_string_old& fmt(const sc_string_old& s);
17512027Sjungma@eit.uni-kl.de    //
17612027Sjungma@eit.uni-kl.de    // find position of substring in this string
17712027Sjungma@eit.uni-kl.de    // returns -1 if not found
17812027Sjungma@eit.uni-kl.de    //
17912027Sjungma@eit.uni-kl.de    int pos(const sc_string_old& sub_string)const;
18012027Sjungma@eit.uni-kl.de    //
18112027Sjungma@eit.uni-kl.de    // remove "count" characters from "index"
18212027Sjungma@eit.uni-kl.de    //
18312027Sjungma@eit.uni-kl.de    sc_string_old& remove(unsigned index, unsigned length);
18412027Sjungma@eit.uni-kl.de    //
18512027Sjungma@eit.uni-kl.de    // insert "substring" before "index"
18612027Sjungma@eit.uni-kl.de    //
18712027Sjungma@eit.uni-kl.de    sc_string_old& insert(const sc_string_old& sub_string, unsigned index);
18812027Sjungma@eit.uni-kl.de    //
18912027Sjungma@eit.uni-kl.de    // returns true if the character at byte index in this string matches
19012027Sjungma@eit.uni-kl.de    // any character in the delimiters string
19112027Sjungma@eit.uni-kl.de    //
19212027Sjungma@eit.uni-kl.de    bool is_delimiter(const sc_string_old& str, unsigned index)const;
19312027Sjungma@eit.uni-kl.de    //
19412027Sjungma@eit.uni-kl.de    // returns true if string contains the character
19512027Sjungma@eit.uni-kl.de    //
19612027Sjungma@eit.uni-kl.de    bool contains(char c)const;
19712027Sjungma@eit.uni-kl.de    //
19812027Sjungma@eit.uni-kl.de    // produce upper case string from this one
19912027Sjungma@eit.uni-kl.de    //
20012027Sjungma@eit.uni-kl.de    sc_string_old uppercase()const;
20112027Sjungma@eit.uni-kl.de    //
20212027Sjungma@eit.uni-kl.de    // produce lower case string from this one
20312027Sjungma@eit.uni-kl.de    //
20412027Sjungma@eit.uni-kl.de    sc_string_old lowercase()const;
20512027Sjungma@eit.uni-kl.de    //
20612027Sjungma@eit.uni-kl.de    // legacy methods
20712027Sjungma@eit.uni-kl.de    //
20812027Sjungma@eit.uni-kl.de    static sc_string_old make_str(long n);
20912027Sjungma@eit.uni-kl.de    void set( int index, char c );
21012027Sjungma@eit.uni-kl.de    int cmp( const char* s ) const;
21112027Sjungma@eit.uni-kl.de    int cmp( const sc_string_old& s ) const;
21212027Sjungma@eit.uni-kl.de
21312027Sjungma@eit.uni-kl.de
21412027Sjungma@eit.uni-kl.de    void print( systemc_ostream& os = ::std::cout ) const;
21512027Sjungma@eit.uni-kl.de
21612027Sjungma@eit.uni-kl.deprivate:
21712027Sjungma@eit.uni-kl.de
21812027Sjungma@eit.uni-kl.de    sc_string_old( sc_string_rep* r );
21912027Sjungma@eit.uni-kl.de
22012027Sjungma@eit.uni-kl.de    sc_string_rep* rep;
22112027Sjungma@eit.uni-kl.de
22212027Sjungma@eit.uni-kl.de    void test(int position)const;
22312027Sjungma@eit.uni-kl.de    unsigned fmt_length()const;
22412027Sjungma@eit.uni-kl.de};
22512027Sjungma@eit.uni-kl.de
22612027Sjungma@eit.uni-kl.de
22712027Sjungma@eit.uni-kl.de// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
22812027Sjungma@eit.uni-kl.de
22912027Sjungma@eit.uni-kl.deinline
23012027Sjungma@eit.uni-kl.desystemc_ostream&
23112027Sjungma@eit.uni-kl.deoperator << ( systemc_ostream& os, const sc_string_old& a )
23212027Sjungma@eit.uni-kl.de{
23312027Sjungma@eit.uni-kl.de    a.print( os );
23412027Sjungma@eit.uni-kl.de    return os;
23512027Sjungma@eit.uni-kl.de}
23612027Sjungma@eit.uni-kl.de
23712027Sjungma@eit.uni-kl.de} // namespace sc_dt
23812027Sjungma@eit.uni-kl.de
23912027Sjungma@eit.uni-kl.de// Revision 1.2  2011/02/18 20:38:44  acg
24012027Sjungma@eit.uni-kl.de//  Andy Goodrich: Updated Copyright notice.
24112027Sjungma@eit.uni-kl.de//
24212027Sjungma@eit.uni-kl.de// Revision 1.1.1.1  2006/12/15 20:20:06  acg
24312027Sjungma@eit.uni-kl.de// SystemC 2.3
24412027Sjungma@eit.uni-kl.de//
24512027Sjungma@eit.uni-kl.de// Revision 1.4  2006/05/08 17:50:51  acg
24612027Sjungma@eit.uni-kl.de//   Andy Goodrich: added David Long's forward declarations for friend
24712027Sjungma@eit.uni-kl.de//   functions, methods, and operators to keep the Microsoft compiler happy.
24812027Sjungma@eit.uni-kl.de//
24912027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:53:11  acg
25012027Sjungma@eit.uni-kl.de// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
25112027Sjungma@eit.uni-kl.de// the source.
25212027Sjungma@eit.uni-kl.de//
25312027Sjungma@eit.uni-kl.de
25412027Sjungma@eit.uni-kl.de#endif
255