diff --git a/lib/ecl/well_segment_collection.cpp b/lib/ecl/well_segment_collection.cpp index 8da80cca75..102ab5f41b 100644 --- a/lib/ecl/well_segment_collection.cpp +++ b/lib/ecl/well_segment_collection.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -33,58 +35,61 @@ struct well_segment_collection_struct { - int_vector_type * segment_index_map; - vector_type * __segment_storage; + std::vector segment_index_map; + std::vector __segment_storage; }; well_segment_collection_type * well_segment_collection_alloc(void) { - well_segment_collection_type * segment_collection = (well_segment_collection_type*)util_malloc( sizeof * segment_collection ); - - segment_collection->__segment_storage = vector_alloc_new(); - segment_collection->segment_index_map = int_vector_alloc( 0 , -1 ); + well_segment_collection_type * segment_collection = new well_segment_collection_type(); return segment_collection; } void well_segment_collection_free(well_segment_collection_type * segment_collection ) { - vector_free( segment_collection->__segment_storage ); - int_vector_free( segment_collection->segment_index_map ); - free( segment_collection ); + for (int i = 0; i < static_cast(segment_collection->__segment_storage.size()); i++) + well_segment_free( segment_collection->__segment_storage[i] ); + delete segment_collection; } int well_segment_collection_get_size( const well_segment_collection_type * segment_collection ) { - return vector_get_size( segment_collection->__segment_storage ); + return segment_collection->__segment_storage.size(); } void well_segment_collection_add( well_segment_collection_type * segment_collection , well_segment_type * segment) { int segment_id = well_segment_get_id( segment ); - int current_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); - if (current_index >= 0) - vector_iset_owned_ref( segment_collection->__segment_storage , current_index , segment , well_segment_free__); + int current_index = -1; + if (segment_id < static_cast(segment_collection->segment_index_map.size())) + current_index = segment_collection->segment_index_map[segment_id]; + if (current_index >= 0) { + well_segment_free( segment_collection->__segment_storage[current_index] ); + segment_collection->__segment_storage[current_index] = segment; + } else { - int new_index = vector_get_size(segment_collection->__segment_storage); - vector_append_owned_ref( segment_collection->__segment_storage , segment , well_segment_free__); - if (segment_id >= int_vector_size(segment_collection->segment_index_map)) - int_vector_resize(segment_collection->segment_index_map, segment_id+1, -1); - int_vector_iset( segment_collection->segment_index_map , segment_id , new_index); + int new_index = segment_collection->__segment_storage.size(); + segment_collection->__segment_storage.push_back( segment ); + if ( segment_id >= static_cast(segment_collection->segment_index_map.size()) ) + segment_collection->segment_index_map.resize(segment_id+1, -1); + segment_collection->segment_index_map[segment_id] = new_index; } } well_segment_type * well_segment_collection_iget( const well_segment_collection_type * segment_collection , int index) { - return (well_segment_type*)vector_iget( segment_collection->__segment_storage , index ); + return segment_collection->__segment_storage[ index ]; } well_segment_type * well_segment_collection_get( const well_segment_collection_type * segment_collection , int segment_id) { - int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); + int internal_index = -1; + if (segment_id < static_cast(segment_collection->segment_index_map.size())) + internal_index = segment_collection->segment_index_map[segment_id]; if (internal_index >= 0) return well_segment_collection_iget( segment_collection , internal_index ); else @@ -93,7 +98,9 @@ well_segment_type * well_segment_collection_get( const well_segment_collection_t bool well_segment_collection_has_segment( const well_segment_collection_type * segment_collection , int segment_id) { - int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); + int internal_index = -1; + if (segment_id < static_cast(segment_collection->segment_index_map.size())) + internal_index = segment_collection->segment_index_map[segment_id]; if (internal_index >= 0) return true; else @@ -135,8 +142,8 @@ int well_segment_collection_load_from_kw( well_segment_collection_type * segment void well_segment_collection_link(const well_segment_collection_type * segment_collection) { - int index; - for (index = 0; index < vector_get_size( segment_collection->__segment_storage); index++) { + size_t index; + for (index = 0; index < segment_collection->__segment_storage.size(); index++) { well_segment_type * segment = well_segment_collection_iget( segment_collection , index ); int outlet_segment_id = well_segment_get_outlet_id( segment ); if (!well_segment_nearest_wellhead(segment)) {