Reactions  0.1.2
Handling reaction trees and decays
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
reactions::database::database< Element, NameField, IdField > Class Template Referenceabstract

Base database class. More...

#include <database.hpp>

Inheritance diagram for reactions::database::database< Element, NameField, IdField >:
Inheritance graph
[legend]
Collaboration diagram for reactions::database::database< Element, NameField, IdField >:
Collaboration graph
[legend]

Classes

class  cache
 Cache of elements. More...
 

Public Types

using element_type = Element
 

Public Member Functions

virtual ~database ()
 
std::vector< element_typeall_elements () const
 All the elements in the database file. More...
 
void clear_cache ()
 Clear the cache, removing also user-registered elements. More...
 
void disable_cache ()
 Disable the cache. More...
 
void enable_cache ()
 
std::string const & get_database_path () const
 Get the path to the database file. More...
 
template<class... Args>
void register_element (Args &&...args)
 Register a new element. More...
 
void set_database_path (std::string const &s)
 
virtual element_type operator() (int id) const =0
 Create an element accessing by ID. More...
 
virtual element_type operator() (std::string const &str) const =0
 Create an element accessing by name. More...
 

Protected Member Functions

std::ifstream open_database () const
 Open the database. More...
 
std::streampos skip_commented_lines (std::ifstream &file) const
 Skip lines with comments (preceeded by *) More...
 
template<std::size_t I>
bool read_field (typename element_type::base_type &tuple, std::string const &line) const
 Read a field with the given index from a line. More...
 
template<std::size_t... I>
bool read_line (typename element_type::base_type &tuple, std::string const &line, std::index_sequence< I... >) const
 Read all the fields from a line. More...
 
bool read_line (typename element_type::base_type &tuple, std::string const &line) const
 Read all the fields from a line. More...
 
element_type read_element (std::string const &line) const
 Advance to the next element in the file and read it. More...
 
template<class Field , class T >
element_type access (T const &v) const
 Access an element using the field accessor. More...
 
 database (std::string &&db)
 
 database (database &&)=delete
 
 database (database const &)=delete
 
void operator= (database &&)=delete
 
void operator= (database const &)=delete
 

Protected Attributes

std::string m_db
 Path to the database file. More...
 
class reactions::database::database::cache m_cache
 

Detailed Description

template<class Element, class NameField, class IdField>
class reactions::database::database< Element, NameField, IdField >

Base database class.

Member Typedef Documentation

◆ element_type

template<class Element, class NameField, class IdField>
using reactions::database::database< Element, NameField, IdField >::element_type = Element

Constructor & Destructor Documentation

◆ ~database()

template<class Element, class NameField, class IdField>
virtual reactions::database::database< Element, NameField, IdField >::~database ( )
inlinevirtual

◆ database() [1/3]

template<class Element, class NameField, class IdField>
reactions::database::database< Element, NameField, IdField >::database ( std::string &&  db)
inlineprotected

◆ database() [2/3]

template<class Element, class NameField, class IdField>
reactions::database::database< Element, NameField, IdField >::database ( database< Element, NameField, IdField > &&  )
protecteddelete

◆ database() [3/3]

template<class Element, class NameField, class IdField>
reactions::database::database< Element, NameField, IdField >::database ( database< Element, NameField, IdField > const &  )
protecteddelete

Member Function Documentation

◆ access()

template<class Element, class NameField, class IdField>
template<class Field , class T >
element_type reactions::database::database< Element, NameField, IdField >::access ( T const &  v) const
inlineprotected

Access an element using the field accessor.

◆ all_elements()

template<class Element, class NameField, class IdField>
std::vector<element_type> reactions::database::database< Element, NameField, IdField >::all_elements ( ) const
inline

All the elements in the database file.

Calling this function does not alter the cache. If the cache is enabled a copy of its content is returned. If not, elements are read from the database file.

This function returns the elements in the database and those registered by the user.

◆ clear_cache()

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::clear_cache ( )
inline

Clear the cache, removing also user-registered elements.

◆ disable_cache()

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::disable_cache ( )
inline

Disable the cache.

◆ enable_cache()

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::enable_cache ( )
inline

◆ get_database_path()

template<class Element, class NameField, class IdField>
std::string const& reactions::database::database< Element, NameField, IdField >::get_database_path ( ) const
inline

Get the path to the database file.

◆ open_database()

template<class Element, class NameField, class IdField>
std::ifstream reactions::database::database< Element, NameField, IdField >::open_database ( ) const
inlineprotected

Open the database.

Cache for elements loaded from the database or registered by the user

◆ operator()() [1/2]

template<class Element, class NameField, class IdField>
virtual element_type reactions::database::database< Element, NameField, IdField >::operator() ( int  id) const
pure virtual

Create an element accessing by ID.

Implemented in reactions::pdg_database, and reactions::nubase_database.

◆ operator()() [2/2]

template<class Element, class NameField, class IdField>
virtual element_type reactions::database::database< Element, NameField, IdField >::operator() ( std::string const &  str) const
pure virtual

Create an element accessing by name.

Implemented in reactions::pdg_database, and reactions::nubase_database.

◆ operator=() [1/2]

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::operator= ( database< Element, NameField, IdField > &&  )
protecteddelete

◆ operator=() [2/2]

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::operator= ( database< Element, NameField, IdField > const &  )
protecteddelete

◆ read_element()

template<class Element, class NameField, class IdField>
element_type reactions::database::database< Element, NameField, IdField >::read_element ( std::string const &  line) const
inlineprotected

Advance to the next element in the file and read it.

◆ read_field()

template<class Element, class NameField, class IdField>
template<std::size_t I>
bool reactions::database::database< Element, NameField, IdField >::read_field ( typename element_type::base_type &  tuple,
std::string const &  line 
) const
inlineprotected

Read a field with the given index from a line.

◆ read_line() [1/2]

template<class Element, class NameField, class IdField>
template<std::size_t... I>
bool reactions::database::database< Element, NameField, IdField >::read_line ( typename element_type::base_type &  tuple,
std::string const &  line,
std::index_sequence< I... >   
) const
inlineprotected

Read all the fields from a line.

◆ read_line() [2/2]

template<class Element, class NameField, class IdField>
bool reactions::database::database< Element, NameField, IdField >::read_line ( typename element_type::base_type &  tuple,
std::string const &  line 
) const
inlineprotected

Read all the fields from a line.

◆ register_element()

template<class Element, class NameField, class IdField>
template<class... Args>
void reactions::database::database< Element, NameField, IdField >::register_element ( Args &&...  args)
inline

Register a new element.

The new element must have a name and a ID that does not clash with any of the database used.

◆ set_database_path()

template<class Element, class NameField, class IdField>
void reactions::database::database< Element, NameField, IdField >::set_database_path ( std::string const &  s)
inline

◆ skip_commented_lines()

template<class Element, class NameField, class IdField>
std::streampos reactions::database::database< Element, NameField, IdField >::skip_commented_lines ( std::ifstream file) const
inlineprotected

Skip lines with comments (preceeded by *)

Member Data Documentation

◆ m_cache

template<class Element, class NameField, class IdField>
class reactions::database::database::cache reactions::database::database< Element, NameField, IdField >::m_cache
protected

◆ m_db

template<class Element, class NameField, class IdField>
std::string reactions::database::database< Element, NameField, IdField >::m_db
protected

Path to the database file.


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