Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JMultiKey< N, JKey_t > Class Template Reference

Multidimensional key. More...

#include <JMultiKey.hh>

Inheritance diagram for JTOOLS::JMultiKey< N, JKey_t >:
std::pair< JKey_t, JMultiKey< N-1, JKey_t > > JLANG::JComparable< JFirst_t, JSecond_t >

Public Types

typedef JKey_t key_type
 
typedef JMultiKey< N-1, JKey_t > mapped_type
 
typedef std::pair< key_type, mapped_typepair_type
 
typedef std::array< key_type, N > array_type
 
typedef std::conditional< std::is_const< key_type >::value, typenamestd::remove_const< key_type >::type, typenamestd::add_const< key_type >::type >::type U
 

Public Member Functions

 JMultiKey ()
 Default constructor.
 
 JMultiKey (typename JClass< mapped_type >::argument_type first, typename JClass< key_type > ::argument_type second)
 Append constructor.
 
 JMultiKey (typename JClass< key_type > ::argument_type first, typename JClass< mapped_type >::argument_type second)
 Insert constructor.
 
 JMultiKey (const JMultiKey &first, typename JClass< key_type >::argument_type second)
 Shift constructor.
 
 JMultiKey (const JMultiKey< N, U > &key)
 Copy constructor.
 
 JMultiKey (const std::array< key_type, N > &array)
 Copy constructor.
 
 operator array_type () const
 Type conversion operator.
 
bool less (const JMultiKey &key) const
 Less than method.
 
JMultiKey< N-1, key_typefront () const
 Get frontend key.
 
key_type back () const
 Get backend key.
 

Private Member Functions

template<class ... Args>
std::array< key_type, N-1 > pop_front (const key_type key, const Args &...args)
 Auxiliary method to pop front array.
 
template<size_t ... i>
std::array< key_type, N-1 > pop_front (const std::array< key_type, N > &array, const std::index_sequence< i... > &ls)
 Pop front array.
 

Static Private Member Functions

template<size_t ... i>
static array_type to_array (const key_type &key, const typename mapped_type::array_type &array, std::index_sequence< i... >)
 Auxiliary method to convert keys to array.
 

Friends

std::istream & operator>> (std::istream &in, JMultiKey &key)
 Read key from input.
 
std::ostream & operator<< (std::ostream &out, const JMultiKey &key)
 Write key to output.
 

Detailed Description

template<unsigned int N, class JKey_t>
class JTOOLS::JMultiKey< N, JKey_t >

Multidimensional key.

This class reproduces the key of a multidimensional map. The individual data members can be accessed as, e.g:

          JMultiKey<3, key_type>  key;

          key[[.second].second].first;

Definition at line 41 of file JMultiKey.hh.

Member Typedef Documentation

◆ key_type

template<unsigned int N, class JKey_t >
JKey_t JTOOLS::JMultiKey< N, JKey_t >::key_type

Definition at line 47 of file JMultiKey.hh.

◆ mapped_type

template<unsigned int N, class JKey_t >
JMultiKey<N-1, JKey_t> JTOOLS::JMultiKey< N, JKey_t >::mapped_type

Definition at line 48 of file JMultiKey.hh.

◆ pair_type

template<unsigned int N, class JKey_t >
std::pair<key_type, mapped_type> JTOOLS::JMultiKey< N, JKey_t >::pair_type

Definition at line 49 of file JMultiKey.hh.

◆ array_type

template<unsigned int N, class JKey_t >
std::array<key_type, N> JTOOLS::JMultiKey< N, JKey_t >::array_type

Definition at line 50 of file JMultiKey.hh.

◆ U

template<unsigned int N, class JKey_t >
std::conditional<std::is_const<key_type>::value,typenamestd::remove_const<key_type>::type,typenamestd::add_const<key_type>::type>::type JTOOLS::JMultiKey< N, JKey_t >::U

Definition at line 54 of file JMultiKey.hh.

Constructor & Destructor Documentation

◆ JMultiKey() [1/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( )
inline

Default constructor.

Definition at line 59 of file JMultiKey.hh.

59 :
60 pair_type()
61 {}
std::pair< key_type, mapped_type > pair_type
Definition JMultiKey.hh:49

◆ JMultiKey() [2/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( typename JClass< mapped_type >::argument_type first,
typename JClass< key_type > ::argument_type second )
inline

Append constructor.

The secondary key is appended to the end of the primary keys.

Parameters
firstprimary keys
secondsecondary key

Definition at line 71 of file JMultiKey.hh.

72 :
73 pair_type(first.first, mapped_type(first, second))
74 {}
JMultiKey< N-1, JKey_t > mapped_type
Definition JMultiKey.hh:48

◆ JMultiKey() [3/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( typename JClass< key_type > ::argument_type first,
typename JClass< mapped_type >::argument_type second )
inline

Insert constructor.

The primary key is inserted at the start of the secondary keys.

Parameters
firstprimary key
secondsecondary keys

Definition at line 84 of file JMultiKey.hh.

85 :
86 pair_type(first, second)
87 {}

◆ JMultiKey() [4/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( const JMultiKey< N, JKey_t > & first,
typename JClass< key_type >::argument_type second )
inline

Shift constructor.

The first of the primary keys is removed and the secondary key is appended to the end of the remainder of the primary keys.

Parameters
firstprimary keys
secondsecondary key

Definition at line 97 of file JMultiKey.hh.

97 :
98 JMultiKey(first.second, second)
99 {}
JMultiKey()
Default constructor.
Definition JMultiKey.hh:59

◆ JMultiKey() [5/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( const JMultiKey< N, U > & key)
inline

Copy constructor.

Parameters
keykey

Definition at line 107 of file JMultiKey.hh.

107 :
108 pair_type(key.first, key.second)
109 {}

◆ JMultiKey() [6/6]

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::JMultiKey ( const std::array< key_type, N > & array)
inline

Copy constructor.

Parameters
arrayarray

Definition at line 117 of file JMultiKey.hh.

117 :
118 pair_type(array[0], pop_front(array, std::make_index_sequence<N>{}))
119 {}
std::array< key_type, N-1 > pop_front(const key_type key, const Args &...args)
Auxiliary method to pop front array.
Definition JMultiKey.hh:229

Member Function Documentation

◆ operator array_type()

template<unsigned int N, class JKey_t >
JTOOLS::JMultiKey< N, JKey_t >::operator array_type ( ) const
inline

Type conversion operator.

Returns
array

Definition at line 127 of file JMultiKey.hh.

128 {
129 return to_array(this->first, this->second, std::make_index_sequence<N-1>{});
130 }
static array_type to_array(const key_type &key, const typename mapped_type::array_type &array, std::index_sequence< i... >)
Auxiliary method to convert keys to array.
Definition JMultiKey.hh:214

◆ less()

template<unsigned int N, class JKey_t >
bool JTOOLS::JMultiKey< N, JKey_t >::less ( const JMultiKey< N, JKey_t > & key) const
inline

Less than method.

Parameters
keykey
Returns
true if this key less than given key; else false

Definition at line 139 of file JMultiKey.hh.

140 {
141 if (this->first == key.first)
142 return this->second.less(key.second);
143 else
144 return this->first < key.first;
145 }

◆ front()

template<unsigned int N, class JKey_t >
JMultiKey< N-1, key_type > JTOOLS::JMultiKey< N, JKey_t >::front ( ) const
inline

Get frontend key.

Returns
frontend key

Definition at line 153 of file JMultiKey.hh.

154 {
155 return JMultiKey<0, key_type>::front(*this);
156 }
JMultiKey< N-1, key_type > front() const
Get frontend key.
Definition JMultiKey.hh:153

◆ back()

template<unsigned int N, class JKey_t >
key_type JTOOLS::JMultiKey< N, JKey_t >::back ( ) const
inline

Get backend key.

Returns
backend key

Definition at line 164 of file JMultiKey.hh.

165 {
166 return this->second.back();
167 }

◆ to_array()

template<unsigned int N, class JKey_t >
template<size_t ... i>
static array_type JTOOLS::JMultiKey< N, JKey_t >::to_array ( const key_type & key,
const typename mapped_type::array_type & array,
std::index_sequence< i... >  )
inlinestaticprivate

Auxiliary method to convert keys to array.

Parameters
keykey
arrayarray
Returns
array

Definition at line 214 of file JMultiKey.hh.

217 {
218 return {key, array[i]...};
219 }

◆ pop_front() [1/2]

template<unsigned int N, class JKey_t >
template<class ... Args>
std::array< key_type, N-1 > JTOOLS::JMultiKey< N, JKey_t >::pop_front ( const key_type key,
const Args &... args )
inlineprivate

Auxiliary method to pop front array.

Parameters
keykey
argsvalues

Definition at line 229 of file JMultiKey.hh.

230 {
231 return std::array<key_type, N-1>({args...});
232 }

◆ pop_front() [2/2]

template<unsigned int N, class JKey_t >
template<size_t ... i>
std::array< key_type, N-1 > JTOOLS::JMultiKey< N, JKey_t >::pop_front ( const std::array< key_type, N > & array,
const std::index_sequence< i... > & ls )
inlineprivate

Pop front array.

Parameters
arrayarray
lsindices of array

Definition at line 242 of file JMultiKey.hh.

243 {
244 return pop_front(array[i]...);
245 }

Friends And Related Symbol Documentation

◆ operator>>

template<unsigned int N, class JKey_t >
std::istream & operator>> ( std::istream & in,
JMultiKey< N, JKey_t > & key )
friend

Read key from input.

Parameters
ininput stream
keykey
Returns
input stream

Definition at line 177 of file JMultiKey.hh.

178 {
179 in >> key.first;
180 in >> key.second;
181
182 return in;
183 }

◆ operator<<

template<unsigned int N, class JKey_t >
std::ostream & operator<< ( std::ostream & out,
const JMultiKey< N, JKey_t > & key )
friend

Write key to output.

Parameters
outoutput stream
keykey
Returns
output stream

Definition at line 193 of file JMultiKey.hh.

194 {
195 const JFormat format(out, getFormat< JMultiKey<0, key_type> >(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
196
197 out << format << key.first;
198 out << ' ';
199 out << key.second;
200
201 return out;
202 }
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636

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