12#ifndef BELFEM_CL_CELL_HPP
13#define BELFEM_CL_CELL_HPP
16#include <initializer_list>
40 template<
typename T >
47 std::vector< T > mCell;
57 Cell(
const std::size_t aReserve )
59 mCell.reserve( aReserve );
62 Cell(
const std::size_t aSize,
const T aInitializationValue )
64 mCell.resize( aSize, aInitializationValue );
69 Cell(
const std::initializer_list< T > & aInitList ) :
106 if (
this != &other )
108 mCell = std::move( other.mCell );
142 const std::vector< T > &
152 ->
decltype( mCell[ aIndex ] )
155 "Cell index out of bounds: %lu (expect < %lu)",
156 (
long unsigned int)aIndex,
157 (
long unsigned int)mCell.size() );
158 return mCell[ aIndex ];
166 ->
decltype( mCell[ aIndex ] )
169 "Cell index out of bounds: %lu (expect < %lu)",
170 (
long unsigned int)aIndex,
171 (
long unsigned int)mCell.size() );
172 return mCell[ aIndex ];
191 mCell.resize( aSize );
199 mCell.resize( aSize, aValue );
205 begin() ->
decltype( mCell.begin() )
207 return mCell.begin();
213 end() ->
decltype( mCell.end() )
223 return mCell.begin();
253 mCell.reserve( aSize );
264 mCell.push_back( aValue );
275 mCell.push_back( std::move( aValue ) );
283 template<
typename... Args >
287 mCell.emplace_back( std::forward< Args >( args )... );
298 T aPop = std::move( mCell.back() );
312 mCell.shrink_to_fit();
320#if !defined( NDEBUG ) || defined( DEBUG )
321 return mCell.at( 0 );
332#if !defined( NDEBUG ) || defined( DEBUG )
333 return mCell.at( 0 );
344#if !defined( NDEBUG ) || defined( DEBUG )
345 return mCell.at( mCell.size()-1 );
347 return mCell[ mCell.size()-1 ];
356#if !defined( NDEBUG ) || defined( DEBUG )
357 return mCell.at( mCell.size()-1 );
359 return mCell[ mCell.size()-1 ];
371 mCell.swap( other.mCell );
382 return mCell.empty();
393 return mCell.capacity();
402 insert(
typename std::vector< T >::const_iterator pos,
const T &
value )
403 ->
decltype( mCell.insert( pos,
value ) )
405 return mCell.insert( pos,
value );
414 insert(
typename std::vector< T >::const_iterator pos, T &&
value )
415 ->
decltype( mCell.insert( pos, std::move(
value ) ) )
417 return mCell.insert( pos, std::move(
value ) );
426 erase(
typename std::vector< T >::const_iterator pos )
427 ->
decltype( mCell.erase( pos ) )
429 return mCell.erase( pos );
439 typename std::vector< T >::const_iterator
last )
440 ->
decltype( mCell.erase(
first,
last ) )
448 print(
const std::string aLabel=
"" )
const ;
453 template<
typename T >
461 std::sort( tVec.begin(), tVec.end() );
466 template<
typename T,
class C >
474 if( aNumberOfItems==0 )
476 std::sort( tVec.begin(), tVec.end(), aComp );
480 std::sort( tVec.begin(), tVec.begin()+aNumberOfItems, aComp );
486 template<
typename T >
494 std::sort( tVec.begin(), tVec.end() );
497 tVec.erase( std::unique( tVec.begin(), tVec.end() ), tVec.end() );
506 template<
typename T >
510 auto tIterator = std::lower_bound( aCell.
vector_data().begin(),
514 && ! ( aMember < *tIterator ),
515 "member not found in cell (is the cell sorted and unique?)" );
522 template<
typename T >
530 std::reverse( tVec.begin(), tVec.end() );
535 template<
typename T >
552 template<
typename T >
562 std::make_move_iterator(aSource.
vector_data().begin()),
563 std::make_move_iterator(aSource.
vector_data().end()));
574 template<
typename T >
585#pragma clang diagnostic push
586#pragma clang diagnostic ignored "-Wformat-security"
588#pragma GCC diagnostic push
589#pragma GCC diagnostic ignored "-Wformat"
592#pragma warning disable 1595
595 template <
typename T >
void
598 FILE * tOutFile = stdout;
600 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
606 for(
uint i=0; i< tLength; ++i )
609 std::ostringstream tStream;
610 tStream << tThis( i );
611 fprintf( tOutFile,
"%s; ", tStream.str().c_str() );
615 fprintf( tOutFile,
"...\n" );
619 fprintf( tOutFile,
"];\n" );
630 FILE * tOutFile = stdout;
632 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
638 for(
uint i=0; i< tLength; ++i )
641 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
646 fprintf( tOutFile,
"...\n" );
650 fprintf( tOutFile,
"];\n" );
656#pragma clang diagnostic pop
658#pragma GCC diagnostic pop
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
T pop()
pop an entry from the Cell
Definition cl_Cell.hpp:296
Cell(const Cell< T > &other)
Definition cl_Cell.hpp:77
auto begin() const -> decltype(mCell.begin())
Definition cl_Cell.hpp:221
void print(const std::string aLabel="") const
Definition cl_Cell.hpp:596
bool empty() const
Check if Cell is empty.
Definition cl_Cell.hpp:380
void set_size(const size_t aSize)
Definition cl_Cell.hpp:189
Cell(const std::initializer_list< T > &aInitList)
Definition cl_Cell.hpp:69
T & first()
Definition cl_Cell.hpp:318
size_t size() const
return the size of the Cell
Definition cl_Cell.hpp:181
auto erase(typename std::vector< T >::const_iterator pos) -> decltype(mCell.erase(pos))
Erase element at position.
Definition cl_Cell.hpp:426
void swap(Cell< T > &other) noexcept
Swap contents with another Cell.
Definition cl_Cell.hpp:369
void emplace(Args &&... args)
emplace an entry at the end (construct in-place)
Definition cl_Cell.hpp:285
const T & last() const
Definition cl_Cell.hpp:354
size_t capacity() const
Get capacity.
Definition cl_Cell.hpp:391
void clear()
clear the memory
Definition cl_Cell.hpp:240
auto begin() -> decltype(mCell.begin())
Definition cl_Cell.hpp:205
void set_size(const size_t aSize, const T &aValue)
Definition cl_Cell.hpp:197
Cell(Cell< T > &&other) noexcept
Definition cl_Cell.hpp:84
Cell< T > & operator=(const Cell< T > &other)
Definition cl_Cell.hpp:92
T & last()
Definition cl_Cell.hpp:342
const T * data() const
Definition cl_Cell.hpp:127
auto end() -> decltype(mCell.end())
Definition cl_Cell.hpp:213
std::vector< T > & vector_data()
Definition cl_Cell.hpp:135
auto insert(typename std::vector< T >::const_iterator pos, T &&value) -> decltype(mCell.insert(pos, std::move(value)))
Insert element at position (move version).
Definition cl_Cell.hpp:414
auto insert(typename std::vector< T >::const_iterator pos, const T &value) -> decltype(mCell.insert(pos, value))
Insert element at position (copy version).
Definition cl_Cell.hpp:402
Cell< T > & operator=(Cell< T > &&other) noexcept
Definition cl_Cell.hpp:104
Cell(const std::size_t aReserve)
Definition cl_Cell.hpp:57
void push(const T &aValue)
push an entry to the end of the cell (copy version)
Definition cl_Cell.hpp:262
auto end() const -> decltype(mCell.end())
Definition cl_Cell.hpp:229
void reserve(const size_t aSize)
reserve memory
Definition cl_Cell.hpp:251
void shrink_to_fit()
free unused memory
Definition cl_Cell.hpp:310
const T & first() const
Definition cl_Cell.hpp:330
const std::vector< T > & vector_data() const
Definition cl_Cell.hpp:143
T * data()
Definition cl_Cell.hpp:120
auto operator()(size_t aIndex) -> decltype(mCell[aIndex])
Definition cl_Cell.hpp:151
Cell(const std::size_t aSize, const T aInitializationValue)
Definition cl_Cell.hpp:62
void push(T &&aValue)
push an entry to the end of the cell (move version)
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:438
auto operator()(size_t aIndex) const -> decltype(mCell[aIndex])
Definition cl_Cell.hpp:165
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:524
void append(Cell< T > &aA, const Cell< T > &aB)
Definition cl_Cell.hpp:537
std::pair< real, unit > value
Definition typedefs.hpp:74
void swap(Cell< T > &aA, Cell< T > &aB) noexcept
Swap specialization for Cell.
Definition cl_Cell.hpp:576
unsigned int uint
Definition typedefs.hpp:30
void unique(Cell< T > &aCell)
Definition cl_Cell.hpp:488
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:508
void sort(Cell< T > &aCell)
Definition cl_Cell.hpp:455
uint32_t index_t
Definition typedefs.hpp:52
void append_move(Cell< T > &aTarget, Cell< T > &aSource)
Definition cl_Cell.hpp:554