Jpp 21.0.0-rc.3
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

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 268 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 273 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 274 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 275 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 276 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 277 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 283 of file JTools/JSelector.hh.

283 :
284 map_type()
285 {}
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 295 of file JTools/JSelector.hh.

296 {
297 map_type::insert(value_type(key, JAutoElement<JBase_t>(type)));
298 }
JParameter< JKey_t > key
map_type::value_type value_type

◆ 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 307 of file JTools/JSelector.hh.

308 {
309 insert(key, JType<JDerived_t>());
310 }
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 321 of file JTools/JSelector.hh.

322 {
323 this->key = key;
324
325 map_type::insert(value_type(key, JAutoElement<JBase_t>(p)));
326 }

◆ 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 334 of file JTools/JSelector.hh.

335 {
336 return this->key;
337 }

◆ 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 346 of file JTools/JSelector.hh.

347 {
348 const_iterator i = this->find(key);
349
350 return i != this->end() && i->second.is_valid() && i->second.get()->is_valid();
351 }
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 359 of file JTools/JSelector.hh.

360 {
361 return key.isDefined() && is_valid(key);
362 }
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 371 of file JTools/JSelector.hh.

372 {
373 const_iterator i = this->find(key);
374
375 if (i != this->end() && i->second.is_valid() && i->second.get()->is_valid())
376 return *(i->second.get()->get());
377 else
378 throw JNullPointerException("JSelecor<>: no object.");
379 }
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 387 of file JTools/JSelector.hh.

388 {
389 if (key.isDefined())
390 return this->get(key);
391 else
392 throw JNullPointerException("JSelecor<>: no selection.");
393 }

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 403 of file JTools/JSelector.hh.

404 {
405 if (in >> selector.key) {
406
407 typename JSelector<JKey_t, JBase_t>::iterator i = selector.find(selector.key);
408
409 if (i != selector.end() && i->second.is_valid())
410 in >> i->second;
411 else
412 in.setstate(std::ios_base::failbit);
413 }
414
415 return in;
416 }

◆ 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 426 of file JTools/JSelector.hh.

427 {
428 if (selector.key.isDefined()) {
429
430 typename JSelector<JKey_t, JBase_t>::const_iterator i = selector.find(selector.key);
431
432 if (i != selector.end() && i->second.is_valid()) {
433 return out << selector.key << ' ' << *(i->second);
434 }
435 }
436
437 return out;
438 }

Member Data Documentation

◆ key

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

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


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