# PhasicFlow: src/phasicFlow/containers/List/List/List.hpp Source File

List.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __List_hpp__
#define __List_hpp__
#include <list>
#include "types.hpp"
#include "typeInfo.hpp"
#include "uniquePtr.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
namespace pFlow
{
template<
typename T
> class List
:
public std::list<T, std::allocator<T> >
{
public:
using ListType = List<T>;
using listType = std::list<T,std::allocator<T>>;
using iterator = typename listType::iterator;
using constIterator = typename listType::const_iterator;
using reference = typename listType::reference;
using constReference= typename listType::const_reference;
using initList = typename std::initializer_list<T>;
using valueType = T;
protected:
// position of ith element
auto pos(size_t i);
// position of ith element
const auto pos(size_t i)const;
static inline size_t getListStride(const size_t& len)
{
size_t stride = 1;
if( len < 6 )
stride = len;
else if( len <16 )
stride = 3;
else if( len < 31)
stride = 2;
else
stride = 1;
return stride;
}
public:
// - Type info
TypeInfoTemplateNV("List", T);
// - empty list
List()
{}
// - list with length len
List(size_t len)
:
listType(len)
{}
// - list with length len and value
List(size_t len, const T& value)
:
listType(len, value)
{}
// - construct from initList
List(initList lst)
:
listType(lst)
{}
// - copy construct
List(const List& src):
listType(src)
{}
// - move construct
List( List && mv)
:
listType(std::move(mv))
{}
// - copy assignment
ListType& operator=(const ListType& rhs)
{
listType::operator=(rhs);
return *this;
}
// - move assignment
ListType& operator=(ListType&& rhs)
{
listType::operator=(std::move(rhs));
return *this;
}
uniquePtr<ListType> clone()const{
return makeUnique<ListType>(*this);
}
ListType* clonePtr()const{
return new ListType(*this);
}
// - destructor
~List()
{
listType::clear();
}
// - counts elements based on a given value
int32 countElement(const T& elm) const;
// - size of container
size_t size()const;
// - access to ith element
// fatal exit if out of range
T& operator[](size_t i);
// - const access to ith element
// fatal exit if our of range
const T& operator[](size_t i)const;
// - find the position of the first element with value val
// cend() if not found
constIterator find(const T& val) const;
// - find the position of the first element with value val
// end() if not found
iterator find(const T& val);
// - find the index of the first element with value val
// -1 if not found
int32 findi(const T& val) const;
// - search for element, if finds it,
// return true, otherwise false
bool search(const T& val) const;
// - set ith element with copy
// fatal error if out of range
void set(size_t i, const T& val);
// - set ith element with move operation
// fatal error if out of range
void set(size_t i, T&& val);
// - write to oStream
bool writeList(iOstream& os) const;
// - read from iStream
bool readList(iIstream& is);
bool read(iIstream& is)
{
return readList(is);
}
bool write(iOstream& os)const
{
return writeList(os);
}
};
template<typename T>
iOstream& operator << (iOstream& os, const List<T>& lst );
template<typename T>
iIstream& operator >>(iIstream& is, List<T>& lst);
using int64List = List<int64>;
using int32List = List<int32>;
using int16List = List<int16>;
using int8List = List<int8>;
using labelList = List<label>;
using uint32List = List<uint32>;
using realList = List<real>;
using realx3List = List<realx3>;
using realx3x3List = List<realx3x3>;
using boolList = List<bool>;
using wordList = List<word>;
} // pFlow
#include "ListI.hpp"
#endif //__List_hpp__
pFlow::List::clonePtr
ListType * clonePtr() const
Definition: List.hpp:146
pFlow::List
Definition: List.hpp:39
pFlow::List< word >::initList
typename std::initializer_list< word > initList
Definition: List.hpp:58
pFlow::List::List
List(size_t len, const T &value)
Definition: List.hpp:104
iIstream.hpp
pFlow::List::set
void set(size_t i, const T &val)
Definition: ListI.hpp:128
types.hpp
pFlow::List::List
List(const List &src)
Definition: List.hpp:117
pFlow::List::search
bool search(const T &val) const
Definition: ListI.hpp:118
pFlow::List::operator=
ListType & operator=(const ListType &rhs)
Definition: List.hpp:128
pFlow::List::find
constIterator find(const T &val) const
Definition: ListI.hpp:92
pFlow::List::operator=
ListType & operator=(ListType &&rhs)
Definition: List.hpp:135
pFlow::List::List
List(initList lst)
Definition: List.hpp:110
pFlow::List::read
bool read(iIstream &is)
Definition: List.hpp:206
pFlow::List::countElement
int32 countElement(const T &elm) const
Definition: ListI.hpp:58
pFlow::List< word >::valueType
word valueType
Definition: List.hpp:60
pFlow
Definition: demComponent.hpp:28
ListI.hpp
pFlow::List::clone
uniquePtr< ListType > clone() const
Definition: List.hpp:142
pFlow::List::findi
int32 findi(const T &val) const
Definition: ListI.hpp:109
uniquePtr.hpp
pFlow::List::TypeInfoTemplateNV
TypeInfoTemplateNV("List", T)
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::List::ListType
List< T > ListType
Definition: List.hpp:46
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::List::write
bool write(iOstream &os) const
Definition: List.hpp:211
pFlow::List::pos
auto pos(size_t i)
Definition: ListI.hpp:23
pFlow::List::List
List(List &&mv)
Definition: List.hpp:122
pFlow::List< word >::iterator
typename listType::iterator iterator
Definition: List.hpp:50
pFlow::List::getListStride
static size_t getListStride(const size_t &len)
Definition: List.hpp:71
pFlow::List< word >::reference
typename listType::reference reference
Definition: List.hpp:54
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::List< word >::constReference
typename listType::const_reference constReference
Definition: List.hpp:56
pFlow::List::writeList
bool writeList(iOstream &os) const
Definition: ListI.hpp:144
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::List::size
size_t size() const
Definition: ListI.hpp:66
pFlow::List::readList
bool readList(iIstream &is)
Definition: ListI.hpp:178
pFlow::List::operator[]
T & operator[](size_t i)
Definition: ListI.hpp:73
typeInfo.hpp
pFlow::List::List
List(size_t len)
Definition: List.hpp:98
pFlow::List< word >::listType
std::list< word, std::allocator< word > > listType
Definition: List.hpp:48
iOstream.hpp
pFlow::List::~List
~List()
Definition: List.hpp:152
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::List< word >::constIterator
typename listType::const_iterator constIterator
Definition: List.hpp:52
pFlow::List::List
List()
Definition: List.hpp:94