12#ifndef BELFEM_CL_CELL_HPP
13#define BELFEM_CL_CELL_HPP
16#include <initializer_list>
43 template<
typename T >
50 std::vector< T > mCell;
63 Cell(
const std::size_t aReserve )
65 mCell.reserve( aReserve );
68 Cell(
const std::size_t aSize,
const T aInitializationValue )
70 mCell.resize( aSize, aInitializationValue );
75 Cell(
const std::initializer_list< T > & aInitList ) :
100 if (
this != &other )
112 if (
this != &other )
114 mCell = std::move( other.mCell );
153 const std::vector< T > &
163 ->
decltype( mCell[ aIndex ] )
166 "Cell index out of bounds: %lu (expect < %lu)",
167 (
long unsigned int)aIndex,
168 (
long unsigned int)mCell.size() );
169 return mCell[ aIndex ];
177 ->
decltype( mCell[ aIndex ] )
180 "Cell index out of bounds: %lu (expect < %lu)",
181 (
long unsigned int)aIndex,
182 (
long unsigned int)mCell.size() );
183 return mCell[ aIndex ];
201 mCell.resize( aSize );
209 mCell.resize( aSize, aValue );
215 begin() ->
decltype( mCell.begin() )
217 return mCell.begin();
223 end() ->
decltype( mCell.end() )
233 return mCell.begin();
259 mCell.reserve( aSize );
267 mCell.push_back( aValue );
275 mCell.push_back( std::move( aValue ) );
280 template<
typename... Args >
284 mCell.emplace_back( std::forward< Args >( args )... );
292 T aPop = std::move( mCell.back() );
303 mCell.shrink_to_fit();
311#if !defined( NDEBUG ) || defined( DEBUG )
312 return mCell.at( 0 );
323#if !defined( NDEBUG ) || defined( DEBUG )
324 return mCell.at( 0 );
335#if !defined( NDEBUG ) || defined( DEBUG )
336 return mCell.at( mCell.size()-1 );
338 return mCell[ mCell.size()-1 ];
347#if !defined( NDEBUG ) || defined( DEBUG )
348 return mCell.at( mCell.size()-1 );
350 return mCell[ mCell.size()-1 ];
362 mCell.swap( other.mCell );
370 return mCell.empty();
378 return mCell.capacity();
384 insert(
typename std::vector< T >::const_iterator pos,
const T &
value )
385 ->
decltype( mCell.insert( pos,
value ) )
387 return mCell.insert( pos,
value );
393 insert(
typename std::vector< T >::const_iterator pos, T &&
value )
394 ->
decltype( mCell.insert( pos, std::move(
value ) ) )
396 return mCell.insert( pos, std::move(
value ) );
402 erase(
typename std::vector< T >::const_iterator pos )
403 ->
decltype( mCell.erase( pos ) )
405 return mCell.erase( pos );
415 typename std::vector< T >::const_iterator
last )
416 ->
decltype( mCell.erase(
first,
last ) )
424 print(
const std::string aLabel=
"" )
const ;
429 template<
typename T >
435 std::sort( tVec.begin(), tVec.end() );
440 template<
typename T,
class C >
446 if( aNumberOfItems==0 )
448 std::sort( tVec.begin(), tVec.end(), aComp );
452 std::sort( tVec.begin(), tVec.begin()+aNumberOfItems, aComp );
460 template<
typename T >
466 std::sort( tVec.begin(), tVec.end() );
468 tVec.erase( std::unique( tVec.begin(), tVec.end() ), tVec.end() );
477 template<
typename T >
481 auto tIterator = std::lower_bound( aCell.
vector_data().begin(),
485 && ! ( aMember < *tIterator ),
486 "member not found in cell (is the cell sorted and unique?)" );
493 template<
typename T >
499 std::reverse( tVec.begin(), tVec.end() );
504 template<
typename T >
519 template<
typename T >
527 std::make_move_iterator(aSource.
vector_data().begin()),
528 std::make_move_iterator(aSource.
vector_data().end()));
538 template<
typename T >
549#pragma clang diagnostic push
550#pragma clang diagnostic ignored "-Wformat-security"
552#pragma GCC diagnostic push
553#pragma GCC diagnostic ignored "-Wformat"
556#pragma warning disable 1595
559 template <
typename T >
void
562 FILE * tOutFile = stdout;
564 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
570 for(
uint i=0; i< tLength; ++i )
573 std::ostringstream tStream;
574 tStream << tThis( i );
575 fprintf( tOutFile,
"%s; ", tStream.str().c_str() );
579 fprintf( tOutFile,
"...\n" );
583 fprintf( tOutFile,
"];\n" );
594 FILE * tOutFile = stdout;
596 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
602 for(
uint i=0; i< tLength; ++i )
605 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
610 fprintf( tOutFile,
"...\n" );
614 fprintf( tOutFile,
"];\n" );
620#pragma clang diagnostic pop
622#pragma GCC diagnostic pop
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
A bounds-checked wrapper around std::vector.
Definition cl_Cell.hpp:45
T pop()
Definition cl_Cell.hpp:290
Cell(const Cell< T > &other)
Definition cl_Cell.hpp:83
auto begin() const -> decltype(mCell.begin())
Definition cl_Cell.hpp:231
void print(const std::string aLabel="") const
Definition cl_Cell.hpp:560
bool empty() const
Definition cl_Cell.hpp:368
void set_size(const size_t aSize)
New elements are value-initialized ( zero for arithmetic T, nullptr for pointers ).
Definition cl_Cell.hpp:199
Cell(const std::initializer_list< T > &aInitList)
Definition cl_Cell.hpp:75
T & first()
Definition cl_Cell.hpp:309
size_t size() const
Definition cl_Cell.hpp:189
auto erase(typename std::vector< T >::const_iterator pos) -> decltype(mCell.erase(pos))
Definition cl_Cell.hpp:402
void swap(Cell< T > &other) noexcept
Swap contents with another Cell.
Definition cl_Cell.hpp:360
void emplace(Args &&... args)
Definition cl_Cell.hpp:282
const T & last() const
Definition cl_Cell.hpp:345
size_t capacity() const
Definition cl_Cell.hpp:376
void clear()
Empties the Cell.
Definition cl_Cell.hpp:249
auto begin() -> decltype(mCell.begin())
Definition cl_Cell.hpp:215
void set_size(const size_t aSize, const T &aValue)
Definition cl_Cell.hpp:207
Cell(Cell< T > &&other) noexcept
Definition cl_Cell.hpp:90
Cell< T > & operator=(const Cell< T > &other)
Definition cl_Cell.hpp:98
T & last()
Definition cl_Cell.hpp:333
const T * data() const
Definition cl_Cell.hpp:136
auto end() -> decltype(mCell.end())
Definition cl_Cell.hpp:223
std::vector< T > & vector_data()
The underlying vector.
Definition cl_Cell.hpp:146
auto insert(typename std::vector< T >::const_iterator pos, T &&value) -> decltype(mCell.insert(pos, std::move(value)))
Definition cl_Cell.hpp:393
auto insert(typename std::vector< T >::const_iterator pos, const T &value) -> decltype(mCell.insert(pos, value))
Definition cl_Cell.hpp:384
Cell< T > & operator=(Cell< T > &&other) noexcept
Definition cl_Cell.hpp:110
Cell(const std::size_t aReserve)
Creates an empty Cell with capacity for aReserve elements.
Definition cl_Cell.hpp:63
void push(const T &aValue)
Definition cl_Cell.hpp:265
auto end() const -> decltype(mCell.end())
Definition cl_Cell.hpp:239
void reserve(const size_t aSize)
Definition cl_Cell.hpp:257
void shrink_to_fit()
Definition cl_Cell.hpp:301
const T & first() const
Definition cl_Cell.hpp:321
const std::vector< T > & vector_data() const
Definition cl_Cell.hpp:154
T * data()
Returns a borrowed pointer into contiguous storage, possibly nullptr when the Cell is empty ( test si...
Definition cl_Cell.hpp:129
auto operator()(size_t aIndex) -> decltype(mCell[aIndex])
Definition cl_Cell.hpp:162
Cell(const std::size_t aSize, const T aInitializationValue)
Definition cl_Cell.hpp:68
void push(T &&aValue)
Definition cl_Cell.hpp:273
auto erase(typename std::vector< T >::const_iterator first, typename std::vector< T >::const_iterator last) -> decltype(mCell.erase(first, last))
Erase range of elements.
Definition cl_Cell.hpp:414
auto operator()(size_t aIndex) const -> decltype(mCell[aIndex])
Definition cl_Cell.hpp:176
Definition cl_Cell.cpp:19
void error_out_of_bounds(const index_t aI, const index_t aN)
Definition cl_Cell.cpp:21
USER GUIDES:
Definition cl_Capacitor.cpp:16
void reverse(Cell< T > &aCell)
Definition cl_Cell.hpp:495
void append(Cell< T > &aA, const Cell< T > &aB)
Definition cl_Cell.hpp:506
std::pair< real, unit > value
Definition typedefs.hpp:73
void swap(Cell< T > &aA, Cell< T > &aB) noexcept
Swap specialization for Cell.
Definition cl_Cell.hpp:540
unsigned int uint
Definition typedefs.hpp:30
void unique(Cell< T > &aCell)
Sorts aCell in place and removes the duplicates.
Definition cl_Cell.hpp:462
index_t find_index_in_unique_cell(const Cell< T > &aCell, const T &aMember)
returns the position of a member inside a cell.
Definition cl_Cell.hpp:479
void sort(Cell< T > &aCell)
Definition cl_Cell.hpp:431
uint32_t index_t
Definition typedefs.hpp:52
void append_move(Cell< T > &aTarget, Cell< T > &aSource)
Definition cl_Cell.hpp:521