Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JSelector< JKey_t, JBase_t > Class Template Reference

Template selector class. More...

#include <JSelector.hh>

Inheritance diagram for JTOOLS::JSelector< JKey_t, JBase_t >:
std::map< JKey_t, JAutoElement< JBase_t > >

Public Types

typedef std::map< JKey_t, JAutoElement< JBase_t > > map_type
 
typedef map_type::const_iterator const_iterator
 
typedef map_type::iterator iterator
 
typedef JLANG::JClass< JKey_t >::argument_type argument_type
 
typedef map_type::value_type value_type
 

Public Member Functions

 JSelector ()
 Default constructor.
 
template<class JDerived_t >
void insert (argument_type key, JType< JDerived_t > type)
 Insert data type at given key.
 
template<class JDerived_t >
void insert (argument_type key)
 Insert data type at given key.
 
template<class JDerived_t >
void insert (argument_type key, JDerived_t *p)
 Insert data type at given key.
 
JKey_t getKey () const
 Get key.
 
bool is_valid (argument_type key) const
 Check validy of given key.
 
bool is_valid () const
 Check validy of selected key.
 
JBase_t & get (argument_type key) const
 Get the object corresponding to the given key.
 
JBase_t & get () const
 Get the object corresponding to the selected key.
 

Protected Attributes

JLANG::JParameter< JKey_t > key
 

Friends

std::istream & operator>> (std::istream &in, JSelector< JKey_t, JBase_t > &selector)
 Read selector from input stream.
 
std::ostream & operator<< (std::ostream &out, const JSelector< JKey_t, JBase_t > &selector)
 Write selector to output stream.
 

Detailed Description

template<class JKey_t, class JBase_t>
class JTOOLS::JSelector< JKey_t, JBase_t >

Template selector class.

This class can be used to set up a list of keys that are mapped to handlers which create new objects by stream input operations.

Definition at line 275 of file JTools/JSelector.hh.

Member Typedef Documentation

◆ map_type

template<class JKey_t , class JBase_t >
std::map<JKey_t, JAutoElement<JBase_t> > JTOOLS::JSelector< JKey_t, JBase_t >::map_type

Definition at line 280 of file JTools/JSelector.hh.

◆ const_iterator

template<class JKey_t , class JBase_t >
map_type::const_iterator JTOOLS::JSelector< JKey_t, JBase_t >::const_iterator

Definition at line 281 of file JTools/JSelector.hh.

◆ iterator

template<class JKey_t , class JBase_t >
map_type::iterator JTOOLS::JSelector< JKey_t, JBase_t >::iterator

Definition at line 282 of file JTools/JSelector.hh.

◆ argument_type

template<class JKey_t , class JBase_t >
JLANG::JClass<JKey_t>::argument_type JTOOLS::JSelector< JKey_t, JBase_t >::argument_type

Definition at line 283 of file JTools/JSelector.hh.

◆ value_type

template<class JKey_t , class JBase_t >
map_type::value_type JTOOLS::JSelector< JKey_t, JBase_t >::value_type

Definition at line 284 of file JTools/JSelector.hh.

Constructor & Destructor Documentation

◆ JSelector()

template<class JKey_t , class JBase_t >
JTOOLS::JSelector< JKey_t, JBase_t >::JSelector ( )
inline

Default constructor.

Definition at line 290 of file JTools/JSelector.hh.

290 :
291 map_type()
292 {}
std::map< JKey_t, JAutoElement< JBase_t > > map_type

Member Function Documentation

◆ insert() [1/3]

template<class JKey_t , class JBase_t >
template<class JDerived_t >
void JTOOLS::JSelector< JKey_t, JBase_t >::insert ( argument_type key,
JType< JDerived_t > type )
inline

Insert data type at given key.

Parameters
keykey
typedata type

Definition at line 302 of file JTools/JSelector.hh.

303 {
304 map_type::insert(value_type(key, JAutoElement<JBase_t>(type)));
305 }
map_type::value_type value_type
JLANG::JParameter< JKey_t > key

◆ insert() [2/3]

template<class JKey_t , class JBase_t >
template<class JDerived_t >
void JTOOLS::JSelector< JKey_t, JBase_t >::insert ( argument_type key)
inline

Insert data type at given key.

Parameters
keykey

Definition at line 314 of file JTools/JSelector.hh.

315 {
316 insert(key, JType<JDerived_t>());
317 }
void insert(argument_type key, JType< JDerived_t > type)
Insert data type at given key.

◆ insert() [3/3]

template<class JKey_t , class JBase_t >
template<class JDerived_t >
void JTOOLS::JSelector< JKey_t, JBase_t >::insert ( argument_type key,
JDerived_t * p )
inline

Insert data type at given key.

This object pointed to will become the default value.

Parameters
keykey
ppointer to object

Definition at line 328 of file JTools/JSelector.hh.

329 {
330 this->key = key;
331
332 map_type::insert(value_type(key, JAutoElement<JBase_t>(p)));
333 }

◆ getKey()

template<class JKey_t , class JBase_t >
JKey_t JTOOLS::JSelector< JKey_t, JBase_t >::getKey ( ) const
inline

Get key.

Returns
key

Definition at line 341 of file JTools/JSelector.hh.

342 {
343 return this->key;
344 }

◆ is_valid() [1/2]

template<class JKey_t , class JBase_t >
bool JTOOLS::JSelector< JKey_t, JBase_t >::is_valid ( argument_type key) const
inline

Check validy of given key.

Parameters
keykey
Returns
true if given key maps to a non-NULL value; else false

Definition at line 353 of file JTools/JSelector.hh.

354 {
355 const_iterator i = this->find(key);
356
357 return i != this->end() && i->second.is_valid() && i->second.get()->is_valid();
358 }
map_type::const_iterator const_iterator

◆ is_valid() [2/2]

template<class JKey_t , class JBase_t >
bool JTOOLS::JSelector< JKey_t, JBase_t >::is_valid ( ) const
inline

Check validy of selected key.

Returns
true if selected key maps to a valid object; else false

Definition at line 366 of file JTools/JSelector.hh.

367 {
368 return key.isDefined() && is_valid(key);
369 }
const bool isDefined() const
Get status of parameter.
bool is_valid() const
Check validy of selected key.

◆ get() [1/2]

template<class JKey_t , class JBase_t >
JBase_t & JTOOLS::JSelector< JKey_t, JBase_t >::get ( argument_type key) const
inline

Get the object corresponding to the given key.

Parameters
keykey
Returns
object

Definition at line 378 of file JTools/JSelector.hh.

379 {
380 const_iterator i = this->find(key);
381
382 if (i != this->end() && i->second.is_valid() && i->second.get()->is_valid())
383 return *(i->second.get()->get());
384 else
385 throw JNullPointerException("JSelecor<>: no object.");
386 }
JBase_t & get() const
Get the object corresponding to the selected key.

◆ get() [2/2]

template<class JKey_t , class JBase_t >
JBase_t & JTOOLS::JSelector< JKey_t, JBase_t >::get ( ) const
inline

Get the object corresponding to the selected key.

Returns
selected object

Definition at line 394 of file JTools/JSelector.hh.

395 {
396 if (key.isDefined())
397 return this->get(key);
398 else
399 throw JNullPointerException("JSelecor<>: no selection.");
400 }

Friends And Related Symbol Documentation

◆ operator>>

template<class JKey_t , class JBase_t >
std::istream & operator>> ( std::istream & in,
JSelector< JKey_t, JBase_t > & selector )
friend

Read selector from input stream.

Parameters
ininput stream
selectorselector
Returns
input stream

Definition at line 410 of file JTools/JSelector.hh.

411 {
412 if (in >> selector.key) {
413
414 typename JSelector<JKey_t, JBase_t>::iterator i = selector.find(selector.key);
415
416 if (i != selector.end() && i->second.is_valid())
417 in >> i->second;
418 else
419 in.setstate(std::ios_base::failbit);
420 }
421
422 return in;
423 }

◆ operator<<

template<class JKey_t , class JBase_t >
std::ostream & operator<< ( std::ostream & out,
const JSelector< JKey_t, JBase_t > & selector )
friend

Write selector to output stream.

Parameters
outoutput stream
selectorselector
Returns
output stream

Definition at line 433 of file JTools/JSelector.hh.

434 {
435 if (selector.key.isDefined()) {
436
437 typename JSelector<JKey_t, JBase_t>::const_iterator i = selector.find(selector.key);
438
439 if (i != selector.end() && i->second.is_valid()) {
440 return out << selector.key << ' ' << *(i->second);
441 }
442 }
443
444 return out;
445 }

Member Data Documentation

◆ key

template<class JKey_t , class JBase_t >
JLANG::JParameter<JKey_t> JTOOLS::JSelector< JKey_t, JBase_t >::key
protected

Definition at line 449 of file JTools/JSelector.hh.


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