Skip to content

Commit d31b9a2

Browse files
authored
Merge pull request #2506 from JanVogelsang/refactoring-casts
Modernize the codebase - convert C-style casts to static_casts
2 parents e8932d7 + 721837a commit d31b9a2

18 files changed

Lines changed: 84 additions & 84 deletions

libnestutil/numerics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const double numerics::nan = 0.0 / 0.0;
9292
long
9393
ld_round( double x )
9494
{
95-
return ( long ) std::floor( x + 0.5 );
95+
return static_cast< long >( std::floor( x + 0.5 ) );
9696
}
9797

9898
double

libnestutil/stopwatch.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class Stopwatch
7171

7272
enum
7373
{
74-
MICROSEC = ( timeunit_t ) 1,
75-
MILLISEC = MICROSEC * ( timeunit_t ) 1000,
76-
SECONDS = MILLISEC * ( timeunit_t ) 1000,
77-
MINUTES = SECONDS * ( timeunit_t ) 60,
78-
HOURS = MINUTES * ( timeunit_t ) 60,
79-
DAYS = HOURS * ( timeunit_t ) 24
74+
MICROSEC = static_cast< timeunit_t >( 1 ),
75+
MILLISEC = MICROSEC * static_cast< timeunit_t >( 1000 ),
76+
SECONDS = MILLISEC * static_cast< timeunit_t >( 1000 ),
77+
MINUTES = SECONDS * static_cast< timeunit_t >( 60 ),
78+
HOURS = MINUTES * static_cast< timeunit_t >( 60 ),
79+
DAYS = HOURS * static_cast< timeunit_t >( 24 )
8080
};
8181

8282
static bool correct_timeunit( timeunit_t t );
@@ -222,7 +222,7 @@ nest::Stopwatch::elapsed_timestamp() const
222222
return _end - _beg + _prev_elapsed;
223223
}
224224
#else
225-
return ( timestamp_t ) 0;
225+
return static_cast< timestamp_t >( 0 );
226226
#endif
227227
}
228228

nestkernel/layer_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ MaskedLayer< D >::check_mask_( Layer< D >& layer, bool allow_oversized )
382382
for ( int i = 0; i < D; ++i )
383383
{
384384
oversize |= layer.get_periodic_mask()[ i ]
385-
and ( grid_mask.get_lower_right()[ i ] - grid_mask.get_upper_left()[ i ] ) > ( int ) dims[ i ];
385+
and ( grid_mask.get_lower_right()[ i ] - grid_mask.get_upper_left()[ i ] ) > static_cast< int >( dims[ i ] );
386386
}
387387
if ( oversize )
388388
{

nestkernel/model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Model::set_threads_( size_t t )
6969
void
7070
Model::reserve_additional( size_t t, size_t n )
7171
{
72-
assert( ( size_t ) t < memory_.size() );
72+
assert( t < memory_.size() );
7373
memory_[ t ].reserve( n );
7474
}
7575

nestkernel/model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Model
255255
inline Node*
256256
Model::create( size_t t )
257257
{
258-
assert( ( size_t ) t < memory_.size() );
258+
assert( t < memory_.size() );
259259
Node* n = create_();
260260
memory_[ t ].emplace_back( n );
261261
return n;

nestkernel/model_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ size_t
366366
ModelManager::get_node_model_id( const Name name ) const
367367
{
368368
const Name model_name( name );
369-
for ( int i = 0; i < ( int ) node_models_.size(); ++i )
369+
for ( int i = 0; i < static_cast< int >( node_models_.size() ); ++i )
370370
{
371371
assert( node_models_[ i ] );
372372
if ( model_name == node_models_[ i ]->get_name() )

nestkernel/ring_buffer.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ RingBuffer::set_value( const long offs, const double v )
169169
inline double
170170
RingBuffer::get_value( const long offs )
171171
{
172-
assert( 0 <= offs and ( size_t ) offs < buffer_.size() );
173-
assert( ( long ) offs < kernel().connection_manager.get_min_delay() );
172+
assert( 0 <= offs and static_cast< size_t >( offs ) < buffer_.size() );
173+
assert( offs < kernel().connection_manager.get_min_delay() );
174174

175175
// offs == 0 is beginning of slice, but we have to
176176
// take modulo into account when indexing
@@ -183,8 +183,8 @@ RingBuffer::get_value( const long offs )
183183
inline double
184184
RingBuffer::get_value_wfr_update( const long offs )
185185
{
186-
assert( 0 <= offs and ( size_t ) offs < buffer_.size() );
187-
assert( ( long ) offs < kernel().connection_manager.get_min_delay() );
186+
assert( 0 <= offs and static_cast< size_t >( offs ) < buffer_.size() );
187+
assert( offs < kernel().connection_manager.get_min_delay() );
188188

189189
// offs == 0 is beginning of slice, but we have to
190190
// take modulo into account when indexing
@@ -198,7 +198,7 @@ RingBuffer::get_index_( const long d ) const
198198
{
199199
const long idx = kernel().event_delivery_manager.get_modulo( d );
200200
assert( 0 <= idx );
201-
assert( ( size_t ) idx < buffer_.size() );
201+
assert( static_cast< size_t >( idx ) < buffer_.size() );
202202
return idx;
203203
}
204204

@@ -258,15 +258,15 @@ class MultRBuffer
258258
inline void
259259
MultRBuffer::add_value( const long offs, const double v )
260260
{
261-
assert( 0 <= offs and ( size_t ) offs < buffer_.size() );
261+
assert( 0 <= offs and static_cast< size_t >( offs ) < buffer_.size() );
262262
buffer_[ get_index_( offs ) ] *= v;
263263
}
264264

265265
inline double
266266
MultRBuffer::get_value( const long offs )
267267
{
268-
assert( 0 <= offs and ( size_t ) offs < buffer_.size() );
269-
assert( ( long ) offs < kernel().connection_manager.get_min_delay() );
268+
assert( 0 <= offs and static_cast< size_t >( offs ) < buffer_.size() );
269+
assert( offs < kernel().connection_manager.get_min_delay() );
270270

271271
// offs == 0 is beginning of slice, but we have to
272272
// take modulo into account when indexing
@@ -280,7 +280,7 @@ inline size_t
280280
MultRBuffer::get_index_( const long d ) const
281281
{
282282
const long idx = kernel().event_delivery_manager.get_modulo( d );
283-
assert( 0 <= idx and ( size_t ) idx < buffer_.size() );
283+
assert( 0 <= idx and static_cast< size_t >( idx ) < buffer_.size() );
284284
return idx;
285285
}
286286

@@ -346,8 +346,8 @@ ListRingBuffer::append_value( const long offs, const double v )
346346
inline std::list< double >&
347347
ListRingBuffer::get_list( const long offs )
348348
{
349-
assert( 0 <= offs and ( size_t ) offs < buffer_.size() );
350-
assert( ( long ) offs < kernel().connection_manager.get_min_delay() );
349+
assert( 0 <= offs and static_cast< size_t >( offs ) < buffer_.size() );
350+
assert( offs < kernel().connection_manager.get_min_delay() );
351351

352352
// offs == 0 is beginning of slice, but we have to
353353
// take modulo into account when indexing
@@ -360,7 +360,7 @@ ListRingBuffer::get_index_( const long d ) const
360360
{
361361
const long idx = kernel().event_delivery_manager.get_modulo( d );
362362
assert( 0 <= idx );
363-
assert( ( size_t ) idx < buffer_.size() );
363+
assert( static_cast< size_t >( idx ) < buffer_.size() );
364364
return idx;
365365
}
366366

nestkernel/simulation_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ nest::SimulationManager::advance_time_()
10801080
to_do_ -= to_step_ - from_step_;
10811081

10821082
// advance clock, update modulos, slice counter only if slice completed
1083-
if ( ( long ) to_step_ == kernel().connection_manager.get_min_delay() )
1083+
if ( to_step_ == kernel().connection_manager.get_min_delay() )
10841084
{
10851085
clock_ += Time::step( kernel().connection_manager.get_min_delay() );
10861086
++slice_;
@@ -1094,7 +1094,7 @@ nest::SimulationManager::advance_time_()
10941094

10951095
long end_sim = from_step_ + to_do_;
10961096

1097-
if ( kernel().connection_manager.get_min_delay() < ( long ) end_sim )
1097+
if ( kernel().connection_manager.get_min_delay() < end_sim )
10981098
{
10991099
// update to end of time slice
11001100
to_step_ = kernel().connection_manager.get_min_delay();
@@ -1104,7 +1104,7 @@ nest::SimulationManager::advance_time_()
11041104
to_step_ = end_sim; // update to end of simulation time
11051105
}
11061106

1107-
assert( to_step_ - from_step_ <= ( long ) kernel().connection_manager.get_min_delay() );
1107+
assert( to_step_ - from_step_ <= kernel().connection_manager.get_min_delay() );
11081108
}
11091109

11101110
void

nestkernel/slice_ring_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ inline void
159159
SliceRingBuffer::add_spike( const long rel_delivery, const long stamp, const double ps_offset, const double weight )
160160
{
161161
const long idx = kernel().event_delivery_manager.get_slice_modulo( rel_delivery );
162-
assert( ( size_t ) idx < queue_.size() );
162+
assert( static_cast< size_t >( idx ) < queue_.size() );
163163
assert( ps_offset >= 0 );
164164

165165
queue_[ idx ].push_back( SpikeInfo( stamp, ps_offset, weight ) );

sli/interpret.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ SLIInterpreter::stack_backtrace( int n )
987987
{
988988
for ( int p = n - 1; p >= 0; --p )
989989
{
990-
if ( ( size_t ) p > EStack.load() )
990+
if ( static_cast< size_t >( p ) > EStack.load() )
991991
{
992992
continue;
993993
}

0 commit comments

Comments
 (0)