Skip to content

Commit 7f6dee7

Browse files
author
Nicholas Reed
committed
Remove P21CommentRep() and move p21Comment string to stack to simplify things. SCL git 219957d.
1 parent b234662 commit 7f6dee7

File tree

4 files changed

+24
-49
lines changed

4 files changed

+24
-49
lines changed

src/cleditor/STEPfile.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ void STEPfile::WriteHeader( ostream & out ) {
15201520
***************************/
15211521
void STEPfile::WriteHeaderInstance( SDAI_Application_instance * obj, ostream & out ) {
15221522
std::string tmp;
1523-
if( obj->P21CommentRep() ) {
1523+
if( !obj->P21Comment().empty() ) {
15241524
out << obj->P21Comment();
15251525
}
15261526
out << StrToUpper( obj->EntityName(), tmp ) << "(";

src/clstepcore/STEPcomplex.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ STEPcomplex::STEPread_error( char c, int index, istream & in ) {
538538
// original names but not according to their renamed names (DAR 6/5/97).
539539
void
540540
STEPcomplex::STEPwrite( ostream & out, const char * currSch, int writeComment ) {
541-
if( writeComment && p21Comment && !p21Comment->empty() ) {
541+
if( writeComment && !p21Comment.empty() ) {
542542
out << p21Comment;
543543
}
544544
out << "#" << STEPfile_id << "=(";

src/clstepcore/sdaiApplication_instance.cc

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ SDAI_Application_instance NilSTEPentity;
3030
**/
3131

3232
SDAI_Application_instance::SDAI_Application_instance()
33-
: _cur( 0 ), STEPfile_id( 0 ), p21Comment( 0 ), headMiEntity( 0 ), nextMiEntity( 0 ),
33+
: _cur( 0 ), STEPfile_id( 0 ), headMiEntity( 0 ), nextMiEntity( 0 ),
3434
_complex( 0 ) {
3535
}
3636

3737
SDAI_Application_instance::SDAI_Application_instance( int fileid, int complex )
38-
: _cur( 0 ), STEPfile_id( fileid ), p21Comment( 0 ),
39-
headMiEntity( 0 ), nextMiEntity( 0 ), _complex( complex ) {
38+
: _cur( 0 ), STEPfile_id( fileid ), headMiEntity( 0 ), nextMiEntity( 0 ), _complex( complex ) {
4039
}
4140

4241
SDAI_Application_instance::~SDAI_Application_instance() {
@@ -51,8 +50,6 @@ SDAI_Application_instance::~SDAI_Application_instance() {
5150
delete nextMiEntity;
5251
}
5352

54-
delete p21Comment;
55-
5653
/*
5754
// this is not necessary since each will call delete on its
5855
// own nextMiEntity - DAS
@@ -88,34 +85,20 @@ SDAI_Application_instance * SDAI_Application_instance::Replicate() {
8885
}
8986
}
9087

91-
void SDAI_Application_instance::AddP21Comment( const char * s, int replace ) {
88+
void SDAI_Application_instance::AddP21Comment( const char * s, bool replace ) {
9289
if( replace ) {
93-
delete p21Comment;
94-
p21Comment = 0;
90+
p21Comment.clear();
9591
}
96-
if( s ) {
97-
if( !p21Comment ) {
98-
p21Comment = new std::string( "" );
99-
} else {
100-
p21Comment->clear();
101-
}
102-
p21Comment->append( s );
92+
if (s) {
93+
p21Comment += s;
10394
}
10495
}
10596

106-
void SDAI_Application_instance::AddP21Comment( std::string & s, int replace ) {
97+
void SDAI_Application_instance::AddP21Comment( const std::string & s, bool replace ) {
10798
if( replace ) {
108-
delete p21Comment;
109-
p21Comment = 0;
110-
}
111-
if( !s.empty() ) {
112-
if( !p21Comment ) {
113-
p21Comment = new std::string( "" );
114-
} else {
115-
p21Comment->clear();
116-
}
117-
p21Comment->append( const_cast<char *>( s.c_str() ) );
99+
p21Comment.clear();
118100
}
101+
p21Comment += s;
119102
}
120103

121104
void SDAI_Application_instance::STEPwrite_reference( ostream & out ) {
@@ -324,8 +307,8 @@ void SDAI_Application_instance::beginSTEPwrite( ostream & out ) {
324307
void SDAI_Application_instance::STEPwrite( ostream & out, const char * currSch,
325308
int writeComments ) {
326309
std::string tmp;
327-
if( writeComments && p21Comment && !p21Comment->empty() ) {
328-
out << p21Comment->c_str();
310+
if( writeComments && !p21Comment.empty() ) {
311+
out << p21Comment;
329312
}
330313
out << "#" << STEPfile_id << "=" << StrToUpper( EntityName( currSch ), tmp )
331314
<< "(";
@@ -392,8 +375,8 @@ void SDAI_Application_instance::WriteValuePairs( ostream & out,
392375
// out << eDesc->QualifiedName(s) << endl;
393376

394377
std::string tmp, tmp2;
395-
if( writeComments && p21Comment && !p21Comment->empty() ) {
396-
out << p21Comment->c_str();
378+
if( writeComments && !p21Comment.empty() ) {
379+
out << p21Comment;
397380
}
398381
if( mixedCase ) {
399382
out << "#" << STEPfile_id << " "

src/clstepcore/sdaiApplication_instance.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class SDAI_Application_instance : public SDAI_DAObject_SDAI {
2222

2323
public:
2424
STEPattributeList attributes;
25-
int STEPfile_id;
25+
int STEPfile_id;
2626
ErrorDescriptor _error;
27-
std::string * p21Comment;
27+
std::string p21Comment;
2828
// registry additions
2929
EntityDescriptor * eDesc;
3030

@@ -35,9 +35,9 @@ class SDAI_Application_instance : public SDAI_DAObject_SDAI {
3535
** and head points at the root SDAI_Application_instance of the primary inheritance
3636
** path (the one that is the root of the leaf entity).
3737
*/
38-
SDAI_Application_instance * headMiEntity;
38+
SDAI_Application_instance * headMiEntity;
3939
/// these form a chain of other entity parents for multiple inheritance
40-
SDAI_Application_instance * nextMiEntity;
40+
SDAI_Application_instance * nextMiEntity;
4141

4242
protected:
4343
int _complex;
@@ -58,22 +58,14 @@ class SDAI_Application_instance : public SDAI_DAObject_SDAI {
5858
return STEPfile_id;
5959
}
6060

61-
void AddP21Comment( std::string & s, int replace = 1 );
62-
void AddP21Comment( const char * s, int replace = 1 );
61+
void AddP21Comment( const std::string & s, bool replace = true );
62+
void AddP21Comment( const char * s, bool replace = true );
6363
void DeleteP21Comment() {
64-
delete p21Comment;
65-
p21Comment = 0;
64+
p21Comment = "";
6665
}
6766

68-
// guaranteed a string (may be null string)
69-
const char * P21Comment() {
70-
return ( p21Comment ? const_cast<char *>( p21Comment->c_str() ) : "" );
71-
}
72-
// returns null if no comment exists
73-
// Note: Jul-24-2011, confirm that we want to change p21Comment->rep() to
74-
// const_cast<char *>(p21Comment->c_str())
75-
const char * P21CommentRep() {
76-
return ( p21Comment ? const_cast<char *>( p21Comment->c_str() ) : 0 );
67+
std::string P21Comment() const {
68+
return p21Comment;
7769
}
7870

7971
const char * EntityName( const char * schnm = NULL ) const;

0 commit comments

Comments
 (0)