TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Visualization::MatPlotLib::Argument Class Reference

Argument to matplotlib. More...

#include <Argument.h>

Public Member Functions

 Argument ()
 
 Argument (const char *argument)
 
 Argument (const std::string &argument)
 
 Argument (const std::initializer_list< std::pair< std::string, std::string >> &argument)
 
const std::string & getArgumentString () const
 
const std::map< std::string, std::string > & getArgumentMap () const
 

Detailed Description

Argument to matplotlib.

The Argument is a helper class to the Plotter. It allows both strings and key-value pairs to be passed as arguments to the same function.

For example, consider the following function.

void f(const Argument &argument)

This can be called using either

f("b--");

or

f({
{"linewidth", "2"},
{"color", "blue"},
{"linestyle, "dashed"}
});

Example

#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace std;
using namespace TBTK;
using namespace Visualization::MatPlotLib;
void print(const Argument &argument){
const std::map<std::string, std::string> argumentMap
= argument.getArgumentMap();
if(argumentMap.size() == 0){
Streams::out << "\t" << argument.getArgumentString() << "\n";
}
else{
for(auto element : argumentMap){
<< "\t" << element.first
<< ": " << element.second
<< "\n";
}
}
}
int main(){
Streams::out << "Argument string:\n";
print("Argument");
Streams::out << "Argument map:\n";
print({
{"First key", "First value"},
{"Second key", "Second value"},
{"Third key", "Third value"}
});
}

Output

Argument string:
First key: First value
Second key: Second value
Third key: Third value

Constructor & Destructor Documentation

◆ Argument() [1/4]

TBTK::Visualization::MatPlotLib::Argument::Argument ( )
inline

Constructs an uninitialized Argument.

◆ Argument() [2/4]

TBTK::Visualization::MatPlotLib::Argument::Argument ( const char *  argument)
inline

Constructs an Argument from a zero terminated char*.

Parameters
argumentString representation fo the argument.

◆ Argument() [3/4]

TBTK::Visualization::MatPlotLib::Argument::Argument ( const std::string &  argument)
inline

Constructs an Argument from a string.

Parameters
argumentString representation fo the argument.

◆ Argument() [4/4]

TBTK::Visualization::MatPlotLib::Argument::Argument ( const std::initializer_list< std::pair< std::string, std::string >> &  argument)
inline

Constructs an Argument from a list of key-value pairs.

Member Function Documentation

◆ getArgumentMap()

const std::map< std::string, std::string > & TBTK::Visualization::MatPlotLib::Argument::getArgumentMap ( ) const
inline

Get the argument map.

◆ getArgumentString()

const std::string & TBTK::Visualization::MatPlotLib::Argument::getArgumentString ( ) const
inline

Get the argument string.


The documentation for this class was generated from the following file:
Streams.h
Streams for TBTK output.
TBTK::Visualization::MatPlotLib::Argument::Argument
Argument()
Definition: Argument.h:89
TBTK::Initialize
void Initialize()
Argument.h
Argument to matplotlib.
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
TBTK.h
TBTK initialization.