Replace the scl_char_str__list class with std::deque

Also use std::string in place of char * in various places
This commit is contained in:
Mark Pictor
2012-02-14 21:00:40 -05:00
parent 212c11453e
commit 3fd222218f
8 changed files with 27 additions and 179 deletions
+11 -17
View File
@@ -321,11 +321,8 @@ Interface_spec::~Interface_spec() {
//////////////////////////////////////////////////////////////////////////////
void Schema::AddFunction( const char * f ) {
if( _function_list == 0 ) {
_function_list = new scl_char_str__list;
}
_function_list->Append( ( char * )f );
void Schema::AddFunction( const std::string & f ) {
_function_list.push_back( f );
}
void Schema::AddGlobal_rule( Global_rule_ptr gr ) {
@@ -339,11 +336,8 @@ void Schema::AddGlobal_rule( Global_rule_ptr gr ) {
void Schema::global_rules_( Global_rule__set_var & grs ) {
}
void Schema::AddProcedure( const char * p ) {
if( _procedure_list == 0 ) {
_procedure_list = new scl_char_str__list;
}
_procedure_list->Append( ( char * )p );
void Schema::AddProcedure( const std::string & p ) {
_procedure_list.push_back( p );
}
/// the whole schema
@@ -368,18 +362,18 @@ void Schema::GenerateExpress( ostream & out ) const {
out << endl << ( *_global_rules )[i]->rule_text_() << endl;
}
}
if( _function_list != 0 ) {
if( !_function_list.empty() ) {
out << "(* *************FUNCTIONS************* *)" << endl;
count = _function_list->Count();
count = _function_list.size();
for( i = 0; i < count; i++ ) {
out << endl << ( *_function_list )[i] << endl;
out << endl << _function_list[i] << endl;
}
}
if( _procedure_list != 0 ) {
if( !_procedure_list.empty() ) {
out << "(* *************PROCEDURES************* *)" << endl;
count = _procedure_list->Count();
count = _procedure_list.size();
for( i = 0; i < count; i++ ) {
out << endl << ( *_procedure_list )[i] << endl;
out << endl << _procedure_list[i] << endl;
}
}
out << endl << "END_SCHEMA;" << endl;
@@ -1221,7 +1215,7 @@ Global_rule::Global_rule()
: _entities( 0 ), _where_rules( 0 ), _parent_schema( 0 ) {
}
Global_rule::Global_rule( const char * n, Schema_ptr parent_sch, const char * rt )
Global_rule::Global_rule( const char * n, Schema_ptr parent_sch, const std::string & rt )
: _name( n ), _entities( 0 ), _where_rules( 0 ), _parent_schema( parent_sch ),
_rule_text( rt ) {
}
+11 -9
View File
@@ -15,6 +15,9 @@
#include <scl_export.h>
#include <sdai.h>
#include <deque>
#include <string>
typedef SDAI_Application_instance * ( * Creator )() ;
enum AttrType_Enum {
@@ -29,7 +32,6 @@ enum AttrType_Enum {
#include <baseType.h>
#include <dictdefs.h>
#include <Str.h>
#include <scl_char_str_list.h>
// defined and created in Registry.inline.cc
extern SCL_CORE_EXPORT const TypeDescriptor * t_sdaiINTEGER;
@@ -520,7 +522,7 @@ class SCL_CORE_EXPORT Global_rule : public Dictionary_instance {
std::string _rule_text; // non-SDAI
Global_rule();
Global_rule( const char * n, Schema_ptr parent_sch, const char * rt );
Global_rule( const char * n, Schema_ptr parent_sch, const std::string & rt );
Global_rule( Global_rule & ); // not fully implemented
virtual ~Global_rule();
@@ -660,8 +662,8 @@ class SCL_CORE_EXPORT Schema : public Dictionary_instance {
// non-SDAI lists
Interface_spec__set_var _use_interface_list; // list of USE interfaces
Interface_spec__set_var _ref_interface_list; // list of REFERENCE interfaces
scl_char_str__list_var _function_list; // of EXPRESS functions
scl_char_str__list_var _procedure_list; // of EXPRESS procedures
std::deque< std::string > _function_list; // of EXPRESS functions
std::deque< std::string > _procedure_list; // of EXPRESS procedures
Global_rule__set_var _global_rules;
@@ -695,11 +697,11 @@ class SCL_CORE_EXPORT Schema : public Dictionary_instance {
return _ref_interface_list;
}
scl_char_str__list_var function_list_() {
std::deque< std::string > function_list_() {
return _function_list;
}
void AddFunction( const char * f );
void AddFunction( const std::string & f );
Global_rule__set_var global_rules_() { // const
return _global_rules;
@@ -709,11 +711,11 @@ class SCL_CORE_EXPORT Schema : public Dictionary_instance {
void global_rules_( Global_rule__set_var & grs ); // not implemented
scl_char_str__list_var procedure_list_() {
std::deque< std::string > procedure_list_() {
return _procedure_list;
}
void AddProcedure( const char * p );
void AddProcedure( const std::string & p );
EntityDescLinkNode * AddEntity( EntityDescriptor * ed ) {
return _entList.AddNode( ed );
@@ -1544,7 +1546,7 @@ class SCL_CORE_EXPORT EntityDescriptor : public TypeDescriptor {
void AddSubtype( EntityDescriptor * ed ) {
_subtypes.AddNode( ed );
}
void AddSupertype_Stmt( const char * s ) {
void AddSupertype_Stmt( const std::string & s ) {
_supertype_stmt = s;
}
const char * Supertype_Stmt() {
-6
View File
@@ -30,12 +30,6 @@ Schema::~Schema() {
if( _ref_interface_list != 0 ) {
delete _ref_interface_list;
}
if( _function_list != 0 ) {
delete _function_list;
}
if( _procedure_list != 0 ) {
delete _procedure_list;
}
if( _global_rules != 0 ) {
delete _global_rules;
}
-2
View File
@@ -7,7 +7,6 @@ set(LIBSTEPUTILS_SRCS
gennodearray.cc
scl_hash.cc
errordesc.cc
scl_char_str_list.cc
)
SET(LIBSTEPUTILS_PRIVATE_HDRS
@@ -16,7 +15,6 @@ SET(LIBSTEPUTILS_PRIVATE_HDRS
gennodearray.h
gennode.h
gennodelist.h
scl_char_str_list.h
scldir.h
scl_hash.h
stat.h
-108
View File
@@ -1,108 +0,0 @@
# include <scl_cf.h>
#include <memory.h>
#include <math.h>
#include <string.h>
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
extern "C"
{
void * memmove( void * __s1, const void * __s2, size_t __n );
}
#endif
#include <scl_char_str_list.h>
scl_char_str__list::scl_char_str__list( int defaultSize ) {
_bufsize = defaultSize;
_buf = new scl_char_str_ptr[_bufsize];
_count = 0;
}
scl_char_str__list::~scl_char_str__list() {
delete _buf;
}
void scl_char_str__list::Check( int index ) {
scl_char_str_ptr * newbuf;
if( index >= _bufsize ) {
_bufsize = ( index + 1 ) * 2;
newbuf = new scl_char_str_ptr[_bufsize];
memmove( newbuf, _buf, _count * sizeof( scl_char_str_ptr ) );
delete [] _buf;
_buf = newbuf;
}
}
void scl_char_str__list::Insert( scl_char_str_ptr v, int index ) {
scl_char_str_ptr * spot;
index = ( index < 0 ) ? _count : index;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( scl_char_str_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void scl_char_str__list::Append( scl_char_str_ptr v ) {
int index = _count;
scl_char_str_ptr * spot;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( scl_char_str_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void scl_char_str__list::Remove( int index ) {
if( 0 <= index && index < _count ) {
--_count;
scl_char_str_ptr * spot = &_buf[index];
memmove( spot, spot + 1, ( _count - index )*sizeof( scl_char_str_ptr ) );
}
}
int scl_char_str__list::Index( scl_char_str_ptr v ) {
for( int i = 0; i < _count; ++i ) {
if( _buf[i] == v ) {
return i;
}
}
return -1;
}
scl_char_str_ptr & scl_char_str__list::operator[]( int index ) {
Check( index );
// _count = max(_count, index+1);
_count = ( ( _count > index + 1 ) ? _count : ( index + 1 ) );
return _buf[index];
}
int
scl_char_str__list::Count() {
return _count;
}
void
scl_char_str__list::Clear() {
_count = 0;
}
-32
View File
@@ -1,32 +0,0 @@
#ifndef SCL_CHAR_STR_LIST_H
#define SCL_CHAR_STR_LIST_H
#include <scl_export.h>
typedef char * scl_char_str_ptr;
class SCL_UTILS_EXPORT scl_char_str__list {
public:
scl_char_str__list( int = 16 );
~scl_char_str__list();
scl_char_str_ptr & operator[]( int index );
void Insert( scl_char_str_ptr, int index );
void Append( scl_char_str_ptr );
void Remove( int index );
int Index( scl_char_str_ptr );
int Count();
void Clear();
private:
void Check( int index );
private:
scl_char_str_ptr * _buf;
int _bufsize;
int _count;
};
typedef scl_char_str__list * scl_char_str__list_ptr;
typedef scl_char_str__list_ptr scl_char_str__list_var;
#endif
+2 -2
View File
@@ -2019,7 +2019,7 @@ void ENTITYincode_print( Entity entity, FILE * file, Schema schema ) {
tmp = SUBTYPEto_string( entity->u.entity->subtype_expression );
tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) );
fprintf( file, "%s\n str.append( \")\" );\n", format_for_std_stringout( tmp, tmp2 ) );
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str.c_str() );", schema_name, ENT_PREFIX, entity_name );
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str );", schema_name, ENT_PREFIX, entity_name );
free( tmp );
free( tmp2 );
} else {
@@ -2034,7 +2034,7 @@ void ENTITYincode_print( Entity entity, FILE * file, Schema schema ) {
fprintf( file, "%s\n str.append( \")\" );\n", format_for_std_stringout( tmp, tmp2 ) );
free( tmp );
free( tmp2 );
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str.c_str() );", schema_name, ENT_PREFIX, entity_name );
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str );", schema_name, ENT_PREFIX, entity_name );
}
}
+3 -3
View File
@@ -473,7 +473,7 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
fprintf( createall, " str.clear();\n%s", format_for_std_stringout( RULEto_string( r ), tmpstr ) );
fprintf( createall,
" gr = new Global_rule(\"%s\",%s::schema, str.c_str() );\n",
" gr = new Global_rule(\"%s\",%s::schema, str );\n",
r->symbol.name, SCHEMAget_name( schema ) );
fprintf( createall,
" %s::schema->AddGlobal_rule(gr);\n", SCHEMAget_name( schema ) );
@@ -493,7 +493,7 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
fprintf( createall, " str.clear();\n%s",
format_for_std_stringout( FUNCto_string( f ), tmpstr ));
fprintf( createall,
"%s::schema->AddFunction( str.c_str() );\n",
"%s::schema->AddFunction( str );\n",
SCHEMAget_name( schema ) );
fprintf( createall, "/*\n%s\n*/\n", FUNCto_string( f ) );
}
@@ -509,7 +509,7 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
tmpstr = ( char * )malloc( sizeof( char ) * tmpstr_size );
}
fprintf( createall, " str.clear();\n%s", format_for_std_stringout( PROCto_string( p ), tmpstr ) );
fprintf( createall, " %s::schema->AddProcedure( str.c_str() );\n", SCHEMAget_name( schema ) );
fprintf( createall, " %s::schema->AddProcedure( str );\n", SCHEMAget_name( schema ) );
fprintf( createall, "/*\n%s\n*/\n", PROCto_string( p ) );
}
if( tmpstr_size > 0 ) {