Skip to content

Commit 82898d7

Browse files
committed
Changed classes inherited from std::string from is-a to has-a std::string.
* Removed std::string base class for SDAI_String and SDAI_Binary. * Added necessary std::string interface functions to SDAI_String and SDAI_Binary. * Removed msvc specific code from sdaiString.h
1 parent 09f3472 commit 82898d7

File tree

7 files changed

+89
-34
lines changed

7 files changed

+89
-34
lines changed

src/cldai/sdaiBinary.cc

Lines changed: 24 additions & 1 deletion
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( 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+
1526
SDAI_Binary & SDAI_Binary::operator= ( const char * s ) {
16-
std::string::operator= ( 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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
* and is not subject to copyright.
1515
*/
1616

17-
class SCL_DAI_EXPORT SDAI_Binary : public std::string {
18-
public:
17+
class SCL_DAI_EXPORT SDAI_Binary {
18+
private:
19+
std::string content;
20+
public:
1921

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

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

30+
void clear( void );
31+
bool empty( void ) const;
32+
const char * c_str( void ) const;
3233
// format for STEP
3334
const char * asStr() const {
3435
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
string s = ToExpressStr( in, err );
49-
operator+= ( s );
81+
content += s;
5082

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

src/cldai/sdaiString.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@
1313

1414
#include <scl_export.h>
1515

16-
/*
17-
* In MSVC2010 std::string::npos is no longer exported from it's libraries.
18-
* This might be a bug but following code make sure the member is known
19-
* and fixes the linker issue for this symbol.
20-
*/
21-
#if defined(__MSVC__) && _MSC_VER == 1600 /* MSVC2010 version */
22-
const std::string::size_type std::string::npos = size_t(-1);
23-
#endif
24-
25-
class SCL_DAI_EXPORT SDAI_String : public std::string {
16+
class SCL_DAI_EXPORT SDAI_String {
17+
private:
18+
std::string content;
2619
public:
2720

2821
//constructor(s) & destructor
29-
SDAI_String( const char * str = 0, int max = 0 ) : std::string( str, max ) { }
30-
SDAI_String( const std::string & s ) : std::string( s ) { }
31-
SDAI_String( const SDAI_String & s ) : std::string( s ) { }
32-
~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 );
3326

3427
// operators
3528
SDAI_String & operator= ( const char * s );
36-
29+
bool operator== ( const char * s ) const;
30+
31+
void clear( void );
32+
bool empty( void ) const;
33+
const char * c_str( void ) const;
3734
// format for STEP
3835
const char * asStr( std::string & s ) const {
3936
return s.c_str();

src/clstepcore/read_func.cc

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

566566
case '\0': // problem in input ?
@@ -591,7 +591,7 @@ Severity SkipInstance( istream & in, std::string & inst ) {
591591
case '\'': // get past the string
592592
in.putback( c );
593593
tmp.STEPread( in, &errs );
594-
inst.append( tmp );
594+
inst.append( tmp.c_str() );
595595

596596
break;
597597

src/clutils/errordesc.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ ErrorDescriptor::ErrorDescriptor( Severity s, DebugLevel d ) : _severity( s ) {
130130
if( d != DEBUG_OFF ) {
131131
_debug_level = d;
132132
}
133-
_userMsg.clear();
134-
_detailMsg.clear();
133+
}
134+
135+
ErrorDescriptor::~ErrorDescriptor( void ) {
135136
}
136137

137138
void ErrorDescriptor::UserMsg( const char * msg ) {

src/clutils/errordesc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,17 @@ enum DebugLevel {
5757
******************************************************************/
5858

5959
class SCL_UTILS_EXPORT ErrorDescriptor {
60-
protected:
60+
private:
61+
std::string _userMsg, _detailMsg;
62+
protected:
6163
Severity _severity;
6264

6365
static DebugLevel _debug_level;
6466
static ostream * _out; // note this will not be persistent
65-
66-
std::string _userMsg, _detailMsg;
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)