TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Range Class Reference

One-dimensional range. More...

#include <Range.h>

Inheritance diagram for TBTK::Range:
TBTK::Serializable

Public Member Functions

 Range (double lowerBound, double upperBound, unsigned int resolution, bool includeLowerBound=true, bool includeUpperBound=true)
 
 Range (const std::string &serialization, Mode mode)
 
unsigned int getResolution () const
 
double operator[] (unsigned int n) const
 
virtual std::string serialize (Mode mode) const
 
- Public Member Functions inherited from TBTK::Serializable
template<>
std::string serialize (const bool &data, Mode mode)
 
template<>
std::string serialize (const double &data, Mode mode)
 
template<>
std::string serialize (const std::complex< double > &data, Mode mode)
 
template<>
std::string serialize (const int &data, Mode mode)
 
template<>
std::string serialize (const unsigned int &data, Mode mode)
 
template<>
std::string serialize (const SpinMatrix &data, Mode mode)
 
template<>
std::string serialize (const Statistics &data, Mode mode)
 
template<>
std::string serialize (const std::vector< std::complex< double >> &data, Mode mode)
 
template<>
int deserialize (const std::string &serialization, Mode mode)
 
template<>
unsigned int deserialize (const std::string &serialization, Mode mode)
 
template<>
double deserialize (const std::string &serialization, Mode mode)
 
template<>
std::complex< double > deserialize (const std::string &serialization, Mode mode)
 
template<>
SpinMatrix deserialize (const std::string &serialization, Mode mode)
 
template<>
Statistics deserialize (const std::string &serialization, Mode mode)
 
template<>
std::vector< std::complex< double > > deserialize (const std::string &serialization, Mode mode)
 

Additional Inherited Members

- Public Types inherited from TBTK::Serializable
enum  Mode { Debug, Binary, XML, JSON }
 
- Static Public Member Functions inherited from TBTK::Serializable
static bool hasID (const std::string &serialization, Mode mode)
 
static std::string getID (const std::string &serialization, Mode mode)
 
static std::string extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode)
 
- Static Protected Member Functions inherited from TBTK::Serializable
static bool validate (const std::string &serialization, const std::string &id, Mode mode)
 
static std::string getContent (const std::string &serialization, Mode mode)
 
static std::vector< std::string > split (const std::string &content, Mode mode)
 
template<typename DataType >
static std::enable_if<!std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static std::enable_if< std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static DataType deserialize (const std::string &serialization, Mode mode)
 
static std::string extract (const std::string &serialization, Mode mode, std::string component)
 

Detailed Description

One-dimensional range.

The Range can be used to define a one-dimensional interval. It has a lower and upper bound, an is resolved with a number of points. A Range is created using

Range range(LOWER_BOUND, UPPER_BOUND, RESOLUTION);

Bounds

By default the bounds are included in the Range. But it is possible to exclude one or both bounds by passing two add boolean flags to the constructor. The first and second flag indicates whether the lower and upper bounds are included, respectively.

Example

#include "TBTK/Range.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace std;
using namespace TBTK;
void print(const Range &range){
for(unsigned int n = 0; n < range.getResolution(); n++){
if(n != 0)
Streams::out << ", ";
Streams::out << range[n];
}
}
int main(){
Streams::out << "Range [-1, 1]: ";
Range range(-1, 1, 5);
print(range);
Streams::out << "\nRange (-1, 1]: ";
range = Range(-1, 1, 5, false, true);
print(range);
Streams::out << "\nRange [-1, 1): ";
range = Range(-1, 1, 5, true, false);
print(range);
Streams::out << "\nRange (-1, 1): ";
range = Range(-1, 1, 5, false, false);
print(range);
Streams::out << "\n";
}

Output

Range [-1, 1]: -1, -0.5, 0, 0.5, 1
Range (-1, 1]: -0.6, -0.2, 0.2, 0.6, 1
Range [-1, 1): -1, -0.6, -0.2, 0.2, 0.6
Range (-1, 1): -0.666667, -0.333333, -1.11022e-16, 0.333333, 0.666667

Constructor & Destructor Documentation

◆ Range() [1/2]

TBTK::Range::Range ( double  lowerBound,
double  upperBound,
unsigned int  resolution,
bool  includeLowerBound = true,
bool  includeUpperBound = true 
)

Constructor.

Parameters
lowerBoundThe lower bound of the range.
TupperBoundThe upper bound of the range.
resolutionThe number of points with which to resolve the range.
includeLowerBoundFlag indicating whether or not the lower bound should be included.
includeUpperBoundFlag indicating whether or not the upper bound should be included.

◆ Range() [2/2]

TBTK::Range::Range ( const std::string &  serialization,
Mode  mode 
)

Constructor. Constructs the Range from a serialization string.

Parameters
serializationSerialization string from which to construct the Range.
modeThe mode with which the string has been serialized.

Member Function Documentation

◆ getResolution()

unsigned int TBTK::Range::getResolution ( ) const
inline

Get resolution.

Returns
The number of points with which the range is resolved.

◆ operator[]()

double TBTK::Range::operator[] ( unsigned int  n) const
inline

Array subscript operator.

Parameters
nThe index of the entry to return.
Returns
The nth entry in the Range.

◆ serialize()

virtual std::string TBTK::Range::serialize ( Mode  mode) const
virtual

Serilaize.

Parameters
modeThe mode to use.
Returns
Serialized string representation of the Range.

Implements TBTK::Serializable.


The documentation for this class was generated from the following file: