# PhasicFlow: src/phasicFlow/ranges/intervalRange.hpp Source File

intervalRange.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 __intervalRange_hpp__
#define __intervalRange_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
namespace pFlow
{
template<typename T>
class
intervalRange
{
protected:
T begin_;
T end_;
static inline const T maxVal = largestPositive<T>();
static inline const T minVal = largestNegative<T>();
public:
TypeInfoTemplateNV("intervalRange",T);
intervalRange(T begin, T end)
:
begin_(begin),
end_(end)
{}
intervalRange(T beginEnd, bool openEnd )
:
begin_(openEnd?beginEnd:minVal),
end_(openEnd?maxVal:beginEnd)
{}
// it should be in the form of begin:end or :end or begin:
intervalRange(const word& rangeString)
{
if(!parseRange(rangeString,begin_,end_))
{
fatalErrorInFunction<<
"bad input for the range. It should have the form of begin:end or :end or begin: \n";
fatalExit;
}
}
inline
bool isMember(T val)const
{
if(val<begin_ || val>end_)return false;
return true;
}
static
bool parseRange(const word& rangeString, T& begin, T& end)
{
if(std::count(
rangeString.begin(),
rangeString.end(),
':') != 1)
return false;
auto col1 = rangeString.find_first_of(":");
word beginCh;
if(col1 == 0)
{
begin = minVal;
}
else
{
auto beginCh = rangeString.substr(0,col1);
if(!readValue(beginCh,begin))return false;
}
if(col1 == rangeString.size())
{
end = maxVal;
}
else
{
auto endCh = rangeString.substr(col1+1);
if(!readValue(endCh, end))return false;
}
return true;
}
};
}
#endif //__stridedRange_hpp__
count
auto count(const Vector< T, Allocator > &vec, const T &val)
pFlow::intervalRange::parseRange
static bool parseRange(const word &rangeString, T &begin, T &end)
Definition: intervalRange.hpp:80
pFlow::readValue
bool readValue(const word &w, real &val)
Definition: bTypesFunctions.hpp:140
pFlow::intervalRange::intervalRange
intervalRange(T begin, T end)
Definition: intervalRange.hpp:48
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::intervalRange::isMember
bool isMember(T val) const
Definition: intervalRange.hpp:73
types.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::intervalRange::begin_
T begin_
Definition: intervalRange.hpp:38
pFlow::intervalRange::intervalRange
intervalRange(T beginEnd, bool openEnd)
Definition: intervalRange.hpp:54
pFlow
Definition: demComponent.hpp:28
pFlow::intervalRange::intervalRange
intervalRange(const word &rangeString)
Definition: intervalRange.hpp:61
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::intervalRange::end_
T end_
Definition: intervalRange.hpp:40
pFlow::intervalRange
Definition: intervalRange.hpp:33
TypeInfoTemplateNV
#define TypeInfoTemplateNV(tName, Type)
Definition: typeInfo.hpp:89
typeInfo.hpp