Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JGroup< T > Struct Template Reference

Auxiliary class for a fixed group of objects. More...

#include <JGroup.hh>

Public Member Functions

const T & operator() (const int index) const
 Get object at given index in group.
 
int operator() (const T &object) const
 Get index of given objec in group.
 

Static Public Member Functions

static const JGroupgetInstance ()
 Get unique instance.
 

Static Public Attributes

static const int size = sizeof(JGroup<T>::group) / sizeof(JGroup<T>::group[0])
 Number of objects.
 

Private Member Functions

 JGroup ()
 Default constructor.
 
const double group []
 

Static Private Attributes

static const T group []
 actual group
 

Detailed Description

template<class T>
struct JLANG::JGroup< T >

Auxiliary class for a fixed group of objects.

A group should be defined as follows:

  template<>
  const XXX JGroup<XXX>::group[]  =  {
    XXX(...),
    XXX(...),
    ...
    XXX(...)
  };

Definition at line 31 of file JGroup.hh.

Constructor & Destructor Documentation

◆ JGroup()

template<class T >
JLANG::JGroup< T >::JGroup ( )
inlineprivate

Default constructor.

Definition at line 36 of file JGroup.hh.

37 {}

Member Function Documentation

◆ getInstance()

template<class T >
static const JGroup & JLANG::JGroup< T >::getInstance ( )
inlinestatic

Get unique instance.

Definition at line 51 of file JGroup.hh.

52 {
53 static const JGroup object;
54
55 return object;
56 }
JGroup()
Default constructor.
Definition JGroup.hh:36

◆ operator()() [1/2]

template<class T >
const T & JLANG::JGroup< T >::operator() ( const int index) const
inline

Get object at given index in group.

Parameters
indexindex
Returns
object

Definition at line 65 of file JGroup.hh.

66 {
67 if (index >= 0 && index < size)
68 return this->group[index];
69 else
70 THROW(JIndexOutOfRange, "JGroup::operator() " << index);
71 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static const int size
Number of objects.
Definition JGroup.hh:45
static const T group[]
actual group
Definition JGroup.hh:39

◆ operator()() [2/2]

template<class T >
int JLANG::JGroup< T >::operator() ( const T & object) const
inline

Get index of given objec in group.

Parameters
objectobject
Returns
index (-1 if object not found)

Definition at line 80 of file JGroup.hh.

81 {
82 for (int i = 0; i != size; ++i) {
83 if (this->group[i] == object) {
84 return i;
85 }
86 }
87
88 return -1;
89 }

◆ group()

const double JLANG::JGroup< double >::group
private

Definition at line 14 of file JGroup.cc.

14 {
15 0.0,
16 1.0,
17 2.0,
18 3.0
19 };

Member Data Documentation

◆ group

template<class T >
const T JLANG::JGroup< T >::group[]
staticprivate

actual group

Definition at line 39 of file JGroup.hh.

◆ size

template<class T >
const int JLANG::JGroup< T >::size = sizeof(JGroup<T>::group) / sizeof(JGroup<T>::group[0])
static

Number of objects.

Definition at line 45 of file JGroup.hh.


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