Skip to content

Commit bde6a38

Browse files
author
Nicholas Reed
committed
Have SDAI_String and SDAI_Binary wrap std::string rather than inherit from it. SCL git 82898d7.
1 parent e6b0942 commit bde6a38

File tree

7 files changed

+85
-20
lines changed

7 files changed

+85
-20
lines changed

src/cldai/sdaiBinary.cc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,34 @@
1212
#include <sstream>
1313
#include <sdai.h>
1414

15-
SDAI_Binary & SDAI_Binary::operator= ( const char * s ) {
16-
std::string::operator= ( s );
15+
SDAI_Binary::SDAI_Binary( const char * str, int max ) {
16+
content = std::string( str, max );
17+
}
18+
19+
SDAI_Binary::SDAI_Binary( const std::string & s ) {
20+
content = std::string( s );
21+
}
22+
23+
SDAI_Binary::~SDAI_Binary( void ) {
24+
}
25+
26+
SDAI_Binary & SDAI_Binary::operator= ( const char * s ) {
27+
content = std::string( s );
1728
return *this;
1829
}
1930

31+
void SDAI_Binary::clear( void ) {
32+
content.clear();
33+
}
34+
35+
bool SDAI_Binary::empty( void ) const {
36+
return content.empty();
37+
}
38+
39+
const char * SDAI_Binary::c_str( void ) const {
40+
return content.c_str();
41+
}
42+
2043
void SDAI_Binary::STEPwrite( ostream & out ) const {
2144
const char * str = 0;
2245
if( empty() ) {

src/cldai/sdaiBinary.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313
* and is not subject to copyright.
1414
*/
1515

16-
class SDAI_Binary : public std::string {
16+
class SCL_DAI_EXPORT SDAI_Binary {
17+
private:
18+
std::string content;
1719
public:
1820

1921
//constructor(s) & destructor
20-
SDAI_Binary ( const char * str = 0, int max = 0 )
21-
: std::string( str, max ) { }
22-
23-
SDAI_Binary ( const std::string & s ) : std::string( s ) { }
24-
25-
26-
~SDAI_Binary () { }
22+
SDAI_Binary( const char * str = 0, int max = 0 );
23+
SDAI_Binary( const std::string & s );
24+
~SDAI_Binary( void );
2725

2826
// operators
2927
SDAI_Binary & operator= ( const char * s );
3028

29+
void clear( void );
30+
bool empty( void ) const;
31+
const char * c_str( void ) const;
3132
// format for STEP
3233
const char * asStr() const {
3334
return c_str();

src/cldai/sdaiString.cc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,43 @@
1212
#include <sdai.h>
1313
#include <sstream>
1414

15+
SDAI_String::SDAI_String( const char * str, int max ) {
16+
content = std::string( str, max );
17+
}
18+
19+
SDAI_String::SDAI_String( const std::string & s ) {
20+
content = std::string( s );
21+
}
22+
23+
SDAI_String::SDAI_String( const SDAI_String & s ) {
24+
content = std::string( s.c_str() );
25+
}
26+
27+
SDAI_String::~SDAI_String( void ) {
28+
}
29+
1530
SDAI_String & SDAI_String::operator= ( const char * s ) {
16-
std::string::operator= ( s );
31+
content = std::string( s );
1732
return *this;
1833
}
1934

35+
bool SDAI_String::operator== ( const char * s ) const {
36+
return ( content == s );
37+
}
38+
39+
void SDAI_String::clear( void ) {
40+
content.clear();
41+
}
42+
43+
bool SDAI_String::empty( void ) const {
44+
return content.empty();
45+
}
46+
47+
const char * SDAI_String::c_str( void ) const {
48+
return content.c_str();
49+
}
50+
51+
2052
void SDAI_String::STEPwrite( ostream & out ) const {
2153
out << c_str();
2254
}
@@ -46,7 +78,7 @@ Severity SDAI_String::STEPread( istream & in, ErrorDescriptor * err ) {
4678

4779
// extract the string from the inputstream
4880
std::string s = GetLiteralStr( in, err );
49-
append( s );
81+
content += s;
5082

5183
// retrieve current severity
5284
Severity sev = err -> severity();

src/cldai/sdaiString.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@
1313

1414
#include <scl_export.h>
1515

16-
class SCL_DAI_EXPORT SDAI_String : public std::string {
16+
class SCL_DAI_EXPORT SDAI_String {
17+
private:
18+
std::string content;
1719
public:
1820

1921
//constructor(s) & destructor
20-
SDAI_String( const char * str = 0, int max = 0 ) : std::string( str, max )
21-
{ }
22-
SDAI_String( const std::string & s ) : std::string( s ) { }
23-
SDAI_String( const SDAI_String & s ) : std::string( s ) { }
24-
~SDAI_String() { }
22+
SDAI_String( const char * str = 0, int max = 0 );
23+
SDAI_String( const std::string & s );
24+
SDAI_String( const SDAI_String & s );
25+
~SDAI_String( void );
2526

2627
// operators
2728
SDAI_String & operator= ( const char * s );
29+
bool operator== ( const char * s ) const;
2830

31+
void clear( void );
32+
bool empty( void ) const;
33+
const char * c_str( void ) const;
2934
// format for STEP
3035
const char * asStr( std::string & s ) const {
3136
s = c_str();

src/clstepcore/read_func.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Severity FindStartOfInstance( istream & in, std::string & inst ) {
562562
case '\'': // get past the string
563563
in.putback( c );
564564
tmp.STEPread( in, &errs );
565-
inst.append( tmp );
565+
inst.append( tmp.c_str() );
566566
break;
567567

568568
case '\0': // problem in input ?
@@ -593,7 +593,7 @@ Severity SkipInstance( istream & in, std::string & inst ) {
593593
case '\'': // get past the string
594594
in.putback( c );
595595
tmp.STEPread( in, &errs );
596-
inst.append( tmp );
596+
inst.append( tmp.c_str() );
597597
break;
598598

599599
case '\0': // problem in input ?

src/clutils/errordesc.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ ErrorDescriptor::ErrorDescriptor( Severity s, DebugLevel d ) : _severity( s ) {
118118
}
119119
}
120120

121+
ErrorDescriptor::~ErrorDescriptor( void ) {
122+
}
123+
121124
void ErrorDescriptor::UserMsg( const char * msg ) {
122125
_userMsg.assign( msg );
123126
}

src/clutils/errordesc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class SCL_UTILS_EXPORT ErrorDescriptor {
6767
public:
6868
ErrorDescriptor( Severity s = SEVERITY_NULL,
6969
DebugLevel d = DEBUG_OFF );
70+
~ErrorDescriptor( void );
7071

7172
void PrintContents( ostream & out = cout ) const;
7273

0 commit comments

Comments
 (0)