Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes
c2_const_ptr< float_type > Class Template Reference

create a container for a c2_function which handles the reference counting.It is useful as a smart container to hold a c2_function and keep the reference count correct. The recommended way for a class to store a c2_function which is handed in from the outside is for it to have a c2_ptr member into which the passed-in function is stored. This way, when the class instance is deleted, it will automatically dereference any function which it was handed. More...

#include <c2_function.hh>

Inheritance diagram for c2_const_ptr< float_type >:
c2_ptr< float_type > c2_typed_ptr< float_type, c2_class >

Public Member Functions

 c2_const_ptr ()
 construct the container with no function More...
 
 c2_const_ptr (const c2_function< float_type > &f)
 construct the container with a pre-defined function More...
 
 c2_const_ptr (const c2_const_ptr< float_type > &src)
 copy constructor More...
 
void set_function (const c2_function< float_type > *f)
 fill the container with a new function, or clear it with a null pointer More...
 
const c2_const_ptr< float_type > & operator= (const c2_const_ptr< float_type > &f)
 fill the container from another container More...
 
const c2_function< float_type > & operator= (const c2_function< float_type > &f)
 fill the container with a function More...
 
void release_for_return () throw (c2_exception)
 release the function without destroying it, so it can be returned from a function More...
 
void unset_function (void)
 clear the function More...
 
 ~c2_const_ptr ()
 destructor More...
 
const c2_function< float_type > & get () const throw (c2_exception)
 get a reference to our owned function More...
 
const c2_function< float_type > * get_ptr () const
 get an unchecked pointer to our owned function More...
 
const c2_function< float_type > * operator-> () const
 get a checked pointer to our owned function More...
 
bool valid () const
 check if we have a valid function More...
 
 operator const c2_function< float_type > & () const
 type coercion operator which lets us use a pointer as if it were a const c2_function More...
 
float_type operator() (float_type x) const throw (c2_exception)
 convenience operator to make us look like a function More...
 
float_type operator() (float_type x, float_type *yprime, float_type *yprime2) const throw (c2_exception)
 convenience operator to make us look like a function More...
 
c2_sum_p< float_type > & operator+ (const c2_function< float_type > &rhs) const throw (c2_exception)
 factory function to create a c2_sum_p from a regular algebraic expression. More...
 
c2_diff_p< float_type > & operator- (const c2_function< float_type > &rhs) const throw (c2_exception)
 factory function to create a c2_diff_p from a regular algebraic expression. More...
 
c2_product_p< float_type > & operator* (const c2_function< float_type > &rhs) const throw (c2_exception)
 factory function to create a c2_product_p from a regular algebraic expression. More...
 
c2_ratio_p< float_type > & operator/ (const c2_function< float_type > &rhs) const throw (c2_exception)
 factory function to create a c2_ratio_p from a regular algebraic expression. More...
 
c2_composed_function_p
< float_type > & 
operator() (const c2_function< float_type > &inner) const throw (c2_exception)
 compose this function outside another. More...
 

Protected Attributes

const c2_function< float_type > * func
 

Detailed Description

template<typename float_type>
class c2_const_ptr< float_type >

create a container for a c2_function which handles the reference counting.

It is useful as a smart container to hold a c2_function and keep the reference count correct. The recommended way for a class to store a c2_function which is handed in from the outside is for it to have a c2_ptr member into which the passed-in function is stored. This way, when the class instance is deleted, it will automatically dereference any function which it was handed.

This class contains a copy constructor and operator=, to make it fairly easy to make a std::vector of these objects, and have it work as expected.

Definition at line 566 of file c2_function.hh.

Constructor & Destructor Documentation

template<typename float_type>
c2_const_ptr< float_type >::c2_const_ptr ( )
inline

construct the container with no function

Definition at line 569 of file c2_function.hh.

569 : func(0) {}
const c2_function< float_type > * func
Definition: c2_function.hh:674
template<typename float_type>
c2_const_ptr< float_type >::c2_const_ptr ( const c2_function< float_type > &  f)
inline

construct the container with a pre-defined function

Parameters
fthe function to store

Definition at line 572 of file c2_function.hh.

572  : func(0)
573  { this->set_function(&f); }
const c2_function< float_type > * func
Definition: c2_function.hh:674
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580
template<typename float_type>
c2_const_ptr< float_type >::c2_const_ptr ( const c2_const_ptr< float_type > &  src)
inline

copy constructor

Parameters
srcthe container to copy

Definition at line 576 of file c2_function.hh.

576  : func(0)
577  { this->set_function(src.get_ptr()); }
const c2_function< float_type > * func
Definition: c2_function.hh:674
const c2_function< float_type > * get_ptr() const
get an unchecked pointer to our owned function
Definition: c2_function.hh:620
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580
template<typename float_type>
c2_const_ptr< float_type >::~c2_const_ptr ( )
inline

destructor

Definition at line 611 of file c2_function.hh.

611 { this->set_function(0); }
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580

Member Function Documentation

template<typename float_type>
const c2_function<float_type>& c2_const_ptr< float_type >::get ( ) const
throw (c2_exception
)
inline

get a reference to our owned function

Definition at line 614 of file c2_function.hh.

Referenced by G4ScreenedCoulombClassicalKinematics::DoScreeningComputation(), c2_ptr< G4double >::get(), and c2_typed_ptr< float_type, c2_class >::get().

615  {
616  if(!func) throw c2_exception("c2_ptr accessed uninitialized");
617  return *func;
618  }
const c2_function< float_type > * func
Definition: c2_function.hh:674
the exception class for c2_function operations.
Definition: c2_function.hh:65
template<typename float_type>
const c2_function<float_type>* c2_const_ptr< float_type >::get_ptr ( ) const
inline

get an unchecked pointer to our owned function

Definition at line 620 of file c2_function.hh.

Referenced by c2_const_ptr< G4double >::c2_const_ptr(), and c2_const_ptr< G4double >::operator=().

620 { return func; }
const c2_function< float_type > * func
Definition: c2_function.hh:674
template<typename float_type>
c2_const_ptr< float_type >::operator const c2_function< float_type > & ( ) const
inline

type coercion operator which lets us use a pointer as if it were a const c2_function

Definition at line 628 of file c2_function.hh.

628 { return this->get(); }
template<typename float_type>
float_type c2_const_ptr< float_type >::operator() ( float_type  x) const
throw (c2_exception
)
inline

convenience operator to make us look like a function

Parameters
xthe value at which to evaluate the contained function
Returns
the evaluated function
Note
If you using this repeatedly, do const c2_function<float_type> &func=ptr; and use func(x). Calling this operator wastes some time, since it checks the validity of the pointer every time.

Definition at line 636 of file c2_function.hh.

636 { return get()(x); }
template<typename float_type>
float_type c2_const_ptr< float_type >::operator() ( float_type  x,
float_type *  yprime,
float_type *  yprime2 
) const
throw (c2_exception
)
inline

convenience operator to make us look like a function

Parameters
xthe value at which to evaluate the contained function
yprimethe derivative
yprime2the second derivative
Returns
the evaluated function
Note
If you using this repeatedly, do const c2_function<float_type> &func=ptr; and use func(x). Calling this operator wastes some time, since it checks the validity of the pointer every time.

Definition at line 645 of file c2_function.hh.

646  { return get().value_with_derivatives(x, yprime, yprime2); }
template<typename float_type>
c2_composed_function_p<float_type>& c2_const_ptr< float_type >::operator() ( const c2_function< float_type > &  inner) const
throw (c2_exception
)
inline

compose this function outside another.

Parameters
innerthe inner function
Returns
the composed function

Definition at line 670 of file c2_function.hh.

671  { return *new c2_composed_function_p<float_type>(get(), inner); }
Provides function composition (nesting)This allows evaluation of f(g(x)) where f and g are c2_functio...
Definition: c2_function.hh:79
template<typename float_type>
c2_product_p<float_type>& c2_const_ptr< float_type >::operator* ( const c2_function< float_type > &  rhs) const
throw (c2_exception
)
inline

factory function to create a c2_product_p from a regular algebraic expression.

Parameters
rhsthe right-hand term of the product
Returns
a new c2_function

Definition at line 660 of file c2_function.hh.

661  { return *new c2_product_p<float_type>(get(), rhs); }
create a c2_function which is the product of two other c2_functions.This should always be constructed...
Definition: c2_function.hh:82
template<typename float_type>
c2_sum_p<float_type>& c2_const_ptr< float_type >::operator+ ( const c2_function< float_type > &  rhs) const
throw (c2_exception
)
inline

factory function to create a c2_sum_p from a regular algebraic expression.

Parameters
rhsthe right-hand term of the sum
Returns
a new c2_function

Definition at line 650 of file c2_function.hh.

651  { return *new c2_sum_p<float_type>(get(), rhs); }
create a c2_function which is the sum of two other c2_function objects.This should always be construc...
Definition: c2_function.hh:80
template<typename float_type>
c2_diff_p<float_type>& c2_const_ptr< float_type >::operator- ( const c2_function< float_type > &  rhs) const
throw (c2_exception
)
inline

factory function to create a c2_diff_p from a regular algebraic expression.

Parameters
rhsthe right-hand term of the difference
Returns
a new c2_function

Definition at line 655 of file c2_function.hh.

656  { return *new c2_diff_p<float_type>(get(), rhs); }
create a c2_function which is the difference of two other c2_functions.This should always be construc...
Definition: c2_function.hh:81
template<typename float_type>
const c2_function<float_type>* c2_const_ptr< float_type >::operator-> ( ) const
inline

get a checked pointer to our owned function

Definition at line 622 of file c2_function.hh.

623  { return &get(); }
template<typename float_type>
c2_ratio_p<float_type>& c2_const_ptr< float_type >::operator/ ( const c2_function< float_type > &  rhs) const
throw (c2_exception
)
inline

factory function to create a c2_ratio_p from a regular algebraic expression.

Parameters
rhsthe right-hand term of the ratio (the denominator)
Returns
a new c2_function

Definition at line 665 of file c2_function.hh.

666  { return *new c2_ratio_p<float_type>(get(), rhs); }
create a c2_function which is the ratio of two other c2_functions.This should always be constructed u...
Definition: c2_function.hh:83
template<typename float_type>
const c2_const_ptr<float_type>& c2_const_ptr< float_type >::operator= ( const c2_const_ptr< float_type > &  f)
inline

fill the container from another container

Parameters
fthe container to copy

Definition at line 589 of file c2_function.hh.

590  { this->set_function(f.get_ptr()); return f; }
const c2_function< float_type > * get_ptr() const
get an unchecked pointer to our owned function
Definition: c2_function.hh:620
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580
template<typename float_type>
const c2_function<float_type>& c2_const_ptr< float_type >::operator= ( const c2_function< float_type > &  f)
inline

fill the container with a function

Parameters
fthe function

Definition at line 593 of file c2_function.hh.

594  { this->set_function(&f); return f; }
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580
template<typename float_type>
void c2_const_ptr< float_type >::release_for_return ( )
throw (c2_exception
)
inline

release the function without destroying it, so it can be returned from a function

This is usually the very last line of a function before the return statement, so that any exceptions that happen during execution of the function will cause proper cleanup. Once the function has been released from its container this way, it is an orhpaned object until the caller claims it, so it could get lost if an exception happens.

Definition at line 601 of file c2_function.hh.

Referenced by LJZBLScreening().

602  {
603  if(func) func->release_ownership_for_return();
604  func=0;
605  }
const c2_function< float_type > * func
Definition: c2_function.hh:674
template<typename float_type>
void c2_const_ptr< float_type >::set_function ( const c2_function< float_type > *  f)
inline

fill the container with a new function, or clear it with a null pointer

Parameters
fthe function to store, releasing any previously held function

Definition at line 580 of file c2_function.hh.

Referenced by c2_const_ptr< G4double >::c2_const_ptr(), c2_ptr< G4double >::c2_ptr(), c2_typed_ptr< float_type, c2_class >::c2_typed_ptr(), c2_const_ptr< G4double >::operator=(), c2_ptr< G4double >::operator=(), c2_typed_ptr< float_type, c2_class >::operator=(), c2_const_ptr< G4double >::unset_function(), and c2_const_ptr< G4double >::~c2_const_ptr().

581  {
582  if(func) func->release_ownership();
583  func=f;
584  if(func) func->claim_ownership();
585  }
const c2_function< float_type > * func
Definition: c2_function.hh:674
template<typename float_type>
void c2_const_ptr< float_type >::unset_function ( void  )
inline

clear the function

Any attempt to use this c2_plugin_function_p throws an exception if the saved function is cleared.

Definition at line 609 of file c2_function.hh.

609 { this->set_function(0); }
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
Definition: c2_function.hh:580
template<typename float_type>
bool c2_const_ptr< float_type >::valid ( ) const
inline

check if we have a valid function

Definition at line 625 of file c2_function.hh.

625 { return func != 0; }
const c2_function< float_type > * func
Definition: c2_function.hh:674

Field Documentation

template<typename float_type>
const c2_function<float_type>* c2_const_ptr< float_type >::func
protected

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