Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
JMATH::JTrigonometric Class Reference

Trigonometric function object for sin and cos. More...

#include <JTrigonometric.hh>

Public Types

typedef double(* pF) (double)
 Type definition of pointer to trigonometric function. More...
 

Public Member Functions

 JTrigonometric (pF f1, const double factor=1.0)
 Constructor. More...
 
double getValue (const double x) const
 Function value. More...
 
double getDerivative (const double x) const
 Derivative value. More...
 
double getIntegral (const double x) const
 Integral value. More...
 
double operator() (const double x) const
 Function value. More...
 
JTrigonometric getDerivative () const
 Derivative function. More...
 
JTrigonometric getIntegral () const
 Integral function. More...
 

Protected Attributes

pF f1
 
double factor
 

Friends

std::istream & operator>> (std::istream &in, JTrigonometric &object)
 Read trigonometric from input. More...
 
std::ostream & operator<< (std::ostream &out, const JTrigonometric &object)
 Write trigonometric to output. More...
 

Detailed Description

Trigonometric function object for sin and cos.

Evaluation of function, derivative and integral values.

Definition at line 28 of file JTrigonometric.hh.

Member Typedef Documentation

◆ pF

typedef double(* JMATH::JTrigonometric::pF) (double)

Type definition of pointer to trigonometric function.

Definition at line 33 of file JTrigonometric.hh.

Constructor & Destructor Documentation

◆ JTrigonometric()

JMATH::JTrigonometric::JTrigonometric ( pF  f1,
const double  factor = 1.0 
)
inline

Constructor.

Parameters
f1pointer to function
factormultiplication factor

Definition at line 42 of file JTrigonometric.hh.

43  {
44  if (f1 != sin && f1 != cos) {
45  THROW(JException, "Invalid trigonometric function.");
46  }
47 
48  this->f1 = f1;
49  this->factor = factor;
50  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712

Member Function Documentation

◆ getValue()

double JMATH::JTrigonometric::getValue ( const double  x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 59 of file JTrigonometric.hh.

60  {
61  return factor * f1(x);
62  }

◆ getDerivative() [1/2]

double JMATH::JTrigonometric::getDerivative ( const double  x) const
inline

Derivative value.

Parameters
xabscissa value
Returns
derivative value

Definition at line 71 of file JTrigonometric.hh.

72  {
73  return getDerivative().getValue(x);
74  }
JTrigonometric getDerivative() const
Derivative function.
double getValue(const double x) const
Function value.

◆ getIntegral() [1/2]

double JMATH::JTrigonometric::getIntegral ( const double  x) const
inline

Integral value.

Parameters
xabscissa value
Returns
integral value

Definition at line 83 of file JTrigonometric.hh.

84  {
85  return getIntegral().getValue(x);
86  }
JTrigonometric getIntegral() const
Integral function.

◆ operator()()

double JMATH::JTrigonometric::operator() ( const double  x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 95 of file JTrigonometric.hh.

96  {
97  return getValue(x);
98  }

◆ getDerivative() [2/2]

JTrigonometric JMATH::JTrigonometric::getDerivative ( ) const
inline

Derivative function.

Returns
derivative function

Definition at line 106 of file JTrigonometric.hh.

107  {
108  if (f1 == sin)
109  return JTrigonometric(cos, +factor);
110  else if (f1 == cos)
111  return JTrigonometric(sin, -factor);
112  else
113  THROW(JException, "Invalid trigonometric function.");
114  }
JTrigonometric(pF f1, const double factor=1.0)
Constructor.

◆ getIntegral() [2/2]

JTrigonometric JMATH::JTrigonometric::getIntegral ( ) const
inline

Integral function.

Returns
integral function

Definition at line 122 of file JTrigonometric.hh.

123  {
124  if (f1 == sin)
125  return JTrigonometric(cos, -factor);
126  else if (f1 == cos)
127  return JTrigonometric(sin, +factor);
128  else
129  THROW(JException, "Invalid trigonometric function.");
130  }

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JTrigonometric object 
)
friend

Read trigonometric from input.

Parameters
ininput stream
objecttrigonometric
Returns
input stream

Definition at line 140 of file JTrigonometric.hh.

141  {
142  std::string buffer;
143 
144  if (in >> object.factor >> buffer) {
145  if (buffer == "sin")
146  object.f1 = sin;
147  else if (buffer == "cos")
148  object.f1 = cos;
149  else
150  THROW(JException, "Invalid trigonometric function.");
151  }
152 
153  return in;
154  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JTrigonometric object 
)
friend

Write trigonometric to output.

Parameters
outoutput stream
objecttrigonometric
Returns
output stream

Definition at line 164 of file JTrigonometric.hh.

165  {
166  out << object.factor;
167 
168  if (object.f1 == sin)
169  out << ' ' << "sin";
170  else if (object.f1 == cos)
171  out << ' ' << "cos";
172  else
173  THROW(JException, "Invalid trigonometric function.");
174 
175  return out;
176  }

Member Data Documentation

◆ f1

pF JMATH::JTrigonometric::f1
protected

Definition at line 179 of file JTrigonometric.hh.

◆ factor

double JMATH::JTrigonometric::factor
protected

Definition at line 180 of file JTrigonometric.hh.


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