Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
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. More...
 
template<class JDerived_t >
void insert (argument_type key, JType< JDerived_t > type)
 Insert data type at given key. More...
 
template<class JDerived_t >
void insert (argument_type key)
 Insert data type at given key. More...
 
template<class JDerived_t >
void insert (argument_type key, JDerived_t *p)
 Insert data type at given key. More...
 
JKey_t getKey () const
 Get key. More...
 
bool is_valid (argument_type key) const
 Check validy of given key. More...
 
bool is_valid () const
 Check validy of selected key. More...
 
JBase_t & get (argument_type key) const
 Get the object corresponding to the given key. More...
 
JBase_t & get () const
 Get the object corresponding to the selected key. More...
 

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. More...
 
std::ostream & operator<< (std::ostream &out, const JSelector< JKey_t, JBase_t > &selector)
 Write selector to output stream. More...
 

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

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

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

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

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

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

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

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

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

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

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

Constructor & Destructor Documentation

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

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
Handler class for automatic pointer.
JLANG::JParameter< JKey_t > key
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.
JLANG::JParameter< JKey_t > key
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  }
map_type::value_type value_type
Handler class for automatic pointer.
JLANG::JParameter< JKey_t > key
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  }
JLANG::JParameter< JKey_t > key
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
JLANG::JParameter< JKey_t > key
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  }
bool is_valid() const
Check validy of selected key.
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:134
JLANG::JParameter< JKey_t > key
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  }
map_type::const_iterator const_iterator
JLANG::JParameter< JKey_t > key
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  }
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:134
JLANG::JParameter< JKey_t > key

Friends And Related Function Documentation

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  }
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
bool is_valid(argument_type key) const
Check validy of given key.
map_type::iterator iterator
JLANG::JParameter< JKey_t > key
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  }
map_type::const_iterator const_iterator
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:134
bool is_valid(argument_type key) const
Check validy of given key.
JLANG::JParameter< JKey_t > key

Member Data Documentation

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: