FLAME  devel
 All Classes Functions Variables Typedefs Enumerations Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Machine Struct Reference

The core simulate Machine engine. More...

#include <base.h>

Inherits noncopyable.

Public Types

typedef p_elements_t::iterator iterator
 Beamline element iterator.
 
typedef
p_elements_t::const_iterator 
const_iterator
 Beamline element iterator (const version)
 
typedef value_proxy_iterator
< p_lookup_t::iterator > 
lookup_iterator
 iterator for use with equal_range() and equal_range_type()
 

Public Member Functions

 Machine (const Config &c)
 Construct a new Machine. More...
 
void propagate (StateBase *S, size_t start=0, size_t max=-1) const
 Pass the given bunch State through this Machine. More...
 
StateBaseallocState (const Config &c) const
 Allocate (with "operator new") an appropriate State object. More...
 
StateBaseallocState () const
 
const Configconf () const
 Fetch Config used to construct this Machine.
 
void reconfigure (size_t idx, const Config &c)
 Change the configuration of a single element. More...
 
const std::string & simtype () const
 Return the sim_type string found during construction.
 
std::ostream * trace () const
 The current tracing stream, or NULL.
 
void set_trace (std::ostream *v)
 Assign new tracing stream. More...
 
size_t size () const
 
ElementVoidoperator[] (size_t i)
 Access a beamline element.
 
const ElementVoidoperator[] (size_t i) const
 Access a beamline element.
 
ElementVoidat (size_t i)
 Access a beamline element.
 
const ElementVoidat (size_t i) const
 Access a beamline element.
 
iterator begin ()
 Points to the first element.
 
const_iterator begin () const
 Points to the first element.
 
iterator end ()
 Points just after the last element.
 
const_iterator end () const
 Points just after the last element.
 
ElementVoidfind (const std::string &name, size_t nth=0)
 
std::pair< lookup_iterator,
lookup_iterator
all_range ()
 
std::pair< lookup_iterator,
lookup_iterator
equal_range (const std::string &name)
 
std::pair< lookup_iterator,
lookup_iterator
equal_range_type (const std::string &name)
 

Static Public Member Functions

template<typename State >
static void registerState (const char *name)
 Register a new State with the simulation framework. More...
 
template<typename Element >
static void registerElement (const char *sname, const char *ename)
 Register a new Element type with the simulation framework. More...
 
static void registeryCleanup ()
 Discard all registered State and Element type information. More...
 
static void set_logger (const boost::shared_ptr< Logger > &p)
 

Static Public Attributes

static int log_detail = FLAME_WARN
 

Friends

std::ostream & operator<< (std::ostream &, const Machine &m)
 

Detailed Description

The core simulate Machine engine.

Provides std::vector<ElementVoid*>-like access to individual elements

Note
A Machine instance is reentrant, but not thread-safe. Any thread may create a Machine at any time. However, each instance should be accessed by a single thread.

Definition at line 230 of file base.h.

Constructor & Destructor Documentation

Machine::Machine ( const Config c)

Construct a new Machine.

Parameters
cA Config instance, such as that returned by GLPSParser::parse_file().

Definition at line 80 of file base.cpp.

Member Function Documentation

StateBase * Machine::allocState ( const Config c) const

Allocate (with "operator new") an appropriate State object.

Parameters
cConfiguration describing the initial state
Returns
A pointer to the new state (never NULL). The caller takes responsibility for deleteing.
Exceptions
std::exceptionsub-classes for various errors, mostly incorrect Config.

Definition at line 186 of file base.cpp.

StateBase* Machine::allocState ( ) const
inline

Allocate new State with empty Config Equivalent to allocState(Config())

Definition at line 261 of file base.h.

std::pair<lookup_iterator, lookup_iterator> Machine::equal_range ( const std::string &  name)
inline

Return a pair of iterators for the sequence [first, second) of those elements with the given name.

Definition at line 370 of file base.h.

std::pair<lookup_iterator, lookup_iterator> Machine::equal_range_type ( const std::string &  name)
inline

Return a pair of iterators for the sequence [first, second) of those elements with the given type name.

Definition at line 379 of file base.h.

ElementVoid* Machine::find ( const std::string &  name,
size_t  nth = 0 
)
inline

Find the nth element with the given name

Returns
NULL on failure A convienence wrapper around equal_range().

Definition at line 349 of file base.h.

void Machine::propagate ( StateBase S,
size_t  start = 0,
size_t  max = -1 
) const

Pass the given bunch State through this Machine.

Parameters
SThe initial state, will be updated with the final state
startThe index of the first Element the state will pass through
maxThe maximum number of elements through which the state will be passed
Exceptions
std::exceptionsub-classes for various errors. If an exception is thrown then the state of S is undefined.

Definition at line 167 of file base.cpp.

void Machine::reconfigure ( size_t  idx,
const Config c 
)

Change the configuration of a single element.

Parameters
idxThe index of this element
cThe new Config

Triggers re-construction of a single element. An optimization to avoid the overhead of reconstructing the entire Machine to change a single element.

Machine M(...);
assert(M.size()>5);
Config e5conf(M[5]->conf());

Definition at line 191 of file base.cpp.

template<typename Element >
static void Machine::registerElement ( const char *  sname,
const char *  ename 
)
inlinestatic

Register a new Element type with the simulation framework.

Add a new element to an existing sim_type (see registerState()).

Parameters
snameA sim_type name
enameThe new element type name
Exceptions
std::logic_errorif sname has not been registered, or if ename is already registered
Note
This method may be called from any thread at any time.

Definition at line 474 of file base.h.

template<typename State >
static void Machine::registerState ( const char *  name)
inlinestatic

Register a new State with the simulation framework.

The first step to adding a new sim_type.

Parameters
nameThe new sim_type name
Exceptions
std::logic_errorif name is already registered
Note
This method may be called from any thread at any time.
struct MyState : public StateBase { ... };
void myReg() {
Machine::registerState<MyState>("mysimtype");
...

Definition at line 457 of file base.h.

void Machine::registeryCleanup ( )
static

Discard all registered State and Element type information.

Clears all previous registerations made by registerState() and registerElement().

Suggested use case is to call just before process exit so that valgrind doesn't flag these as leaks

Note
This method may be called from any thread at any time.

Definition at line 242 of file base.cpp.

void Machine::set_trace ( std::ostream *  v)
inline

Assign new tracing stream.

Parameters
vnew stream or NULL to clear

The trace stream will be written to during Machine::propagate() as a debugging aid.

Definition at line 298 of file base.h.

size_t Machine::size ( ) const
inline
Returns
Number of beamline elements

Definition at line 319 of file base.h.


The documentation for this struct was generated from the following files: